From patchwork Thu May 1 09:35:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 4098241 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 97EEDBFF02 for ; Thu, 1 May 2014 09:35:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B635720328 for ; Thu, 1 May 2014 09:35:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C9A8C201F4 for ; Thu, 1 May 2014 09:35:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753878AbaEAJfi (ORCPT ); Thu, 1 May 2014 05:35:38 -0400 Received: from cantor2.suse.de ([195.135.220.15]:58324 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752199AbaEAJfh (ORCPT ); Thu, 1 May 2014 05:35:37 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BEC3BAB49; Thu, 1 May 2014 09:35:36 +0000 (UTC) Date: Thu, 1 May 2014 19:35:27 +1000 From: NeilBrown To: Peter Zijlstra Cc: Ingo Molnar , Trond Myklebust , "J. Bruce Fields" , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: Re: [PATCH] SCHED: allow wait_on_bit_action functions to support a timeout. Message-ID: <20140501193527.72284b3d@notabene.brown> In-Reply-To: <20140501080430.GL11096@twins.programming.kicks-ass.net> References: <20140501124143.5712eb96@notabene.brown> <20140501080430.GL11096@twins.programming.kicks-ass.net> X-Mailer: Claws Mail 3.9.2 (GTK+ 2.24.22; x86_64-suse-linux-gnu) Mime-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, 1 May 2014 10:04:30 +0200 Peter Zijlstra wrote: > On Thu, May 01, 2014 at 12:41:43PM +1000, NeilBrown wrote: > > diff --git a/include/linux/wait.h b/include/linux/wait.h > > index 438dc6044587..162cbcde9dae 100644 > > --- a/include/linux/wait.h > > +++ b/include/linux/wait.h > > @@ -25,6 +25,7 @@ struct wait_bit_key { > > void *flags; > > int bit_nr; > > #define WAIT_ATOMIC_T_BIT_NR -1 > > + unsigned long private; > > }; > > > > struct wait_bit_queue { > > @@ -147,12 +148,12 @@ void __wake_up_sync_key(wait_queue_head_t *q, unsigned int mode, int nr, void *k > > void __wake_up_locked(wait_queue_head_t *q, unsigned int mode, int nr); > > void __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr); > > void __wake_up_bit(wait_queue_head_t *, void *, int); > > -int __wait_on_bit(wait_queue_head_t *, struct wait_bit_queue *, int (*)(void *), unsigned); > > -int __wait_on_bit_lock(wait_queue_head_t *, struct wait_bit_queue *, int (*)(void *), unsigned); > > +int __wait_on_bit(wait_queue_head_t *, struct wait_bit_queue *, int (*)(struct wait_bit_key *), unsigned); > > +int __wait_on_bit_lock(wait_queue_head_t *, struct wait_bit_queue *, int (*)(struct wait_bit_key *), unsigned); > > > Would something like: > > typedef int (*wait_bit_action_f)(struct wait_bit_key *); > > make sense? Maybe ... it would be used 12 times. I usually steer clear of typedefs, but this looks like a reasonably use-case. This is what the incremental diff would look like. I change the typedef a little because I like pointers to look like they are pointers. NeilBrown diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h index 592be588ce62..b8703ac18956 100644 --- a/include/linux/sunrpc/sched.h +++ b/include/linux/sunrpc/sched.h @@ -236,7 +236,7 @@ void * rpc_malloc(struct rpc_task *, size_t); void rpc_free(void *); int rpciod_up(void); void rpciod_down(void); -int __rpc_wait_for_completion_task(struct rpc_task *task, int (*)(struct wait_bit_key *)); +int __rpc_wait_for_completion_task(struct rpc_task *task, wait_bit_action_f *); #ifdef RPC_DEBUG struct net; void rpc_show_tasks(struct net *); diff --git a/include/linux/wait.h b/include/linux/wait.h index 4cee2b2dc26c..39b6aa4cd636 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -142,18 +142,19 @@ __remove_wait_queue(wait_queue_head_t *head, wait_queue_t *old) list_del(&old->task_list); } +typedef int wait_bit_action_f(struct wait_bit_key *); void __wake_up(wait_queue_head_t *q, unsigned int mode, int nr, void *key); void __wake_up_locked_key(wait_queue_head_t *q, unsigned int mode, void *key); void __wake_up_sync_key(wait_queue_head_t *q, unsigned int mode, int nr, void *key); void __wake_up_locked(wait_queue_head_t *q, unsigned int mode, int nr); void __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr); void __wake_up_bit(wait_queue_head_t *, void *, int); -int __wait_on_bit(wait_queue_head_t *, struct wait_bit_queue *, int (*)(struct wait_bit_key *), unsigned); -int __wait_on_bit_lock(wait_queue_head_t *, struct wait_bit_queue *, int (*)(struct wait_bit_key *), unsigned); +int __wait_on_bit(wait_queue_head_t *, struct wait_bit_queue *, wait_bit_action_f *, unsigned); +int __wait_on_bit_lock(wait_queue_head_t *, struct wait_bit_queue *, wait_bit_action_f *, unsigned); void wake_up_bit(void *, int); void wake_up_atomic_t(atomic_t *); -int out_of_line_wait_on_bit(void *, int, int (*)(struct wait_bit_key *), unsigned); -int out_of_line_wait_on_bit_lock(void *, int, int (*)(struct wait_bit_key *), unsigned); +int out_of_line_wait_on_bit(void *, int, wait_bit_action_f *, unsigned); +int out_of_line_wait_on_bit_lock(void *, int, wait_bit_action_f *, unsigned); int out_of_line_wait_on_atomic_t(atomic_t *, int (*)(atomic_t *), unsigned); wait_queue_head_t *bit_waitqueue(void *, int); @@ -926,7 +927,7 @@ wait_on_bit_io(void *word, int bit, unsigned mode) * on that signal. */ static inline int -wait_on_bit_action(void *word, int bit, int (*action)(struct wait_bit_key *), unsigned mode) +wait_on_bit_action(void *word, int bit, wait_bit_action_f *action, unsigned mode) { if (!test_bit(bit, word)) return 0; @@ -1001,7 +1002,7 @@ wait_on_bit_lock_io(void *word, int bit, unsigned mode) * the @mode allows that signal to wake the process. */ static inline int -wait_on_bit_lock_action(void *word, int bit, int (*action)(struct wait_bit_key *), unsigned mode) +wait_on_bit_lock_action(void *word, int bit, wait_bit_action_f *action, unsigned mode) { if (!test_and_set_bit(bit, word)) return 0; diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c index 738fa685fd3d..e4f90ba7b4b2 100644 --- a/kernel/sched/wait.c +++ b/kernel/sched/wait.c @@ -319,7 +319,7 @@ EXPORT_SYMBOL(wake_bit_function); */ int __sched __wait_on_bit(wait_queue_head_t *wq, struct wait_bit_queue *q, - int (*action)(struct wait_bit_key *), unsigned mode) + wait_bit_action_f *action, unsigned mode) { int ret = 0; @@ -334,7 +334,7 @@ __wait_on_bit(wait_queue_head_t *wq, struct wait_bit_queue *q, EXPORT_SYMBOL(__wait_on_bit); int __sched out_of_line_wait_on_bit(void *word, int bit, - int (*action)(struct wait_bit_key *), unsigned mode) + wait_bit_action_f *action, unsigned mode) { wait_queue_head_t *wq = bit_waitqueue(word, bit); DEFINE_WAIT_BIT(wait, word, bit); @@ -345,7 +345,7 @@ EXPORT_SYMBOL(out_of_line_wait_on_bit); int __sched __wait_on_bit_lock(wait_queue_head_t *wq, struct wait_bit_queue *q, - int (*action)(struct wait_bit_key *), unsigned mode) + wait_bit_action_f *action, unsigned mode) { do { int ret; @@ -365,7 +365,7 @@ __wait_on_bit_lock(wait_queue_head_t *wq, struct wait_bit_queue *q, EXPORT_SYMBOL(__wait_on_bit_lock); int __sched out_of_line_wait_on_bit_lock(void *word, int bit, - int (*action)(struct wait_bit_key *), unsigned mode) + wait_bit_action_f *action, unsigned mode) { wait_queue_head_t *wq = bit_waitqueue(word, bit); DEFINE_WAIT_BIT(wait, word, bit); diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c index 7b9a673c6adb..9919b94c525a 100644 --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c @@ -309,7 +309,7 @@ static int rpc_complete_task(struct rpc_task *task) * to enforce taking of the wq->lock and hence avoid races with * rpc_complete_task(). */ -int __rpc_wait_for_completion_task(struct rpc_task *task, int (*action)(struct wait_bit_key *)) +int __rpc_wait_for_completion_task(struct rpc_task *task, wait_bit_action_f *action) { if (action == NULL) action = rpc_wait_bit_killable;