smp: Single IPI cleanups
Subsystems (4)
cover smp: Single IPI cleanups
Hi,
Here is a batch of cleanups on the generic single IPI code. I've gathered a few patches from Jan, split up some, and added a few more so that __smp_call_function_single() becomes less obscure.
Comments?
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
core/ipi-rfc
Thanks,
Frederic
---
Frederic Weisbecker (6):
block: Remove useless IPI struct initialization
smp: Consolidate the various smp_call_function_single() declensions
smp: Move __smp_call_function_single() below its safe version
watchdog: Simplify a little the IPI call
smp: Remove wait argument from __smp_call_function_single()
smp: Enhance and precise the role & requirements of __smp_call_function_single()
Jan Kara (5):
block: Stop abusing csd.list for fifo_time
block: Stop abusing rq->csd.list in blk-softirq
smp: Iterate functions through llist_for_each_entry_safe()
smp: Remove unused list_head from csd
smp: Teach __smp_call_function_single() to check for offline cpus
block/blk-mq.c | 2 +- block/blk-softirq.c | 19 ++++--- block/cfq-iosched.c | 8 +-- block/deadline-iosched.c | 8 +-- drivers/block/null_blk.c | 2 +- drivers/cpuidle/coupled.c | 2 +- include/linux/blkdev.h | 1 + include/linux/elevator.h | 11 +--- include/linux/smp.h | 8 +-- kernel/sched/core.c | 2 +- kernel/smp.c | 139 ++++++++++++++++++++++------------------------ kernel/up.c | 4 +- kernel/watchdog.c | 3 +- net/core/dev.c | 2 +- 14 files changed, 97 insertions(+), 114 deletions(-)
PATCH 1/11 block: Stop abusing csd.list for fifo_time
From: Jan Kara <[email protected]>
Block layer currently abuses rq->csd.list.next for storing fifo_time. That is a terrible hack and completely unnecessary as well. Union achieves the same space saving in a cleaner way.
--- block/cfq-iosched.c | 8 ++++---- block/deadline-iosched.c | 8 ++++---- include/linux/blkdev.h | 1 + include/linux/elevator.h | 6 ------ 4 files changed, 9 insertions(+), 14 deletions(-)
block/cfq-iosched.c +4 -4
@@ -2367,10 +2367,10 @@ cfq_merged_requests(struct request_queue *q, struct request *rq,* reposition in fifo if next is older than rq */ if (!list_empty (&rq->queuelist) && !list_empty (&next->queuelist) && -time_before (rq_fifo_time (next),rq_fifo_time (rq)) && +time_before (next->fifo_time, rq->fifo_time) && cfqq ==RQ_CFQQ (next)) {list_move (&rq->queuelist, &next->queuelist); -rq_set_fifo_time (rq,rq_fifo_time (next)); + rq->fifo_time = next->fifo_time; }if (cfqq->next_rq == next)
@@ -2814,7 +2814,7 @@ static struct request *cfq_check_fifo(struct cfq_queue *cfqq)return NULL ; rq =rq_entry_fifo (cfqq->fifo.next); -if (time_before (jiffies,rq_fifo_time (rq))) +if (time_before (jiffies, rq->fifo_time)) rq =NULL ;cfq_log_cfqq (cfqq->cfqd, cfqq,"fifo=%p" , rq);
@@ -3927,7 +3927,7 @@ static void cfq_insert_request(struct request_queue *q, struct request *rq)cfq_log_cfqq (cfqd, cfqq,"insert_request" );cfq_init_prio_data (cfqq,RQ_CIC (rq)); -rq_set_fifo_time (rq, jiffies + cfqd->cfq_fifo_expire[rq_is_sync (rq)]); + rq->fifo_time = jiffies + cfqd->cfq_fifo_expire[rq_is_sync (rq)];list_add_tail (&rq->queuelist, &cfqq->fifo);cfq_add_rq_rb (rq); cfqg_stats_update_io_add(RQ_CFQG(rq), cfqd->serving_group,
block/deadline-iosched.c +4 -4
@@ -106,7 +106,7 @@ deadline_add_request(struct request_queue *q, struct request *rq)/* * set expire time and add to fifo list */ -rq_set_fifo_time (rq, jiffies + dd->fifo_expire[data_dir]); + rq->fifo_time = jiffies + dd->fifo_expire[data_dir];list_add_tail (&rq->queuelist, &dd->fifo_list[data_dir]); }
@@ -174,9 +174,9 @@ deadline_merged_requests(struct request_queue *q, struct request *req,* and move into next position (next will be deleted) in fifo */ if (!list_empty (&req->queuelist) && !list_empty (&next->queuelist)) { -if (time_before (rq_fifo_time (next),rq_fifo_time (req))) { +if (time_before (next->fifo_time, req->fifo_time)) {list_move (&req->queuelist, &next->queuelist); -rq_set_fifo_time (req,rq_fifo_time (next)); + req->fifo_time = next->fifo_time; } }
@@ -230,7 +230,7 @@ static inline int deadline_check_fifo(struct deadline_data *dd, int ddir)/* * rq is expired! */ -if (time_after_eq (jiffies,rq_fifo_time (rq))) +if (time_after_eq (jiffies, rq->fifo_time))return 1 ;return 0 ;
include/linux/blkdev.h +1 -0
@@ -99,6 +99,7 @@ struct request {union {struct call_single_data csd;struct work_struct mq_flush_data; +unsigned long fifo_time; };struct request_queue *q;
include/linux/elevator.h +0 -6
@@ -202,12 +202,6 @@ enum {#define rq_end_sector (rq) (blk_rq_pos(rq) + blk_rq_sectors(rq))#define rb_entry_rq (node) rb_entry((node), struct request, rb_node) -/* -* Hack to reuse the csd.list list_head as the fifo time holder while -* the request is in the io scheduler. Saves an unsigned long in rq. -*/ -#define rq_fifo_time (rq) ((unsigned long) (rq)->csd.list.next) -#define rq_set_fifo_time (rq,exp) ((rq)->csd.list.next = (void *) (exp))#define rq_entry_fifo (ptr) list_entry((ptr), struct request, queuelist)#define rq_fifo_clear (rq) do { \ list_del_init(&(rq)->queuelist); \
Signature · 1 line
1.8.3.1
PATCH 2/11 block: Remove useless IPI struct initialization
In reply to Frederic Weisbeckerrq_fifo_clear() reset the csd.list through INIT_LIST_HEAD for no clear purpose. The csd.list doesn't need to be initialized as a list head because it's only ever used as a list node.
Lets remove this useless initialization.
--- include/linux/elevator.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
include/linux/elevator.h +1 -4
@@ -203,10 +203,7 @@ enum {#define rb_entry_rq (node) rb_entry((node), struct request, rb_node)#define rq_entry_fifo (ptr) list_entry((ptr), struct request, queuelist) -#define rq_fifo_clear (rq) do { \ - list_del_init(&(rq)->queuelist); \ - INIT_LIST_HEAD(&(rq)->csd.list); \ - } while (0) +#define rq_fifo_clear (rq) list_del_init(&(rq)->queuelist)#else /* CONFIG_BLOCK */
Signature · 1 line
1.8.3.1
Re: [PATCH 02/11] block: Remove useless IPI struct initialization
Quoted 4 lines · Frederic Weisbecker
rq_fifo_clear()reset the csd.list throughINIT_LIST_HEADfor no clear purpose. The csd.list doesn't need to be initialized as a list head because it's only ever used as a list node.
Quoted 8 lines
Lets remove this useless initialization.
Cc Andrew Morton <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jan Kara <[email protected]>Cc Jens Axboe <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>
Looks good. You can add:
Honza
Quoted 23 lines
--- include/linux/elevator.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)include/linux/elevator.h +1
-4@@ -203,10 +203,7 @@ enum {#define rb_entry_rq (node) rb_entry((node), struct request, rb_node)#define rq_entry_fifo (ptr) list_entry((ptr), struct request, queuelist) -#define rq_fifo_clear (rq) do { \ - list_del_init(&(rq)->queuelist); \ - INIT_LIST_HEAD(&(rq)->csd.list); \ - } while (0) +#define rq_fifo_clear (rq) list_del_init(&(rq)->queuelist)#else /* CONFIG_BLOCK */ Signature · 1 line
1.8.3.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH 3/11 block: Stop abusing rq->csd.list in blk-softirq
In reply to Frederic WeisbeckerFrom: Jan Kara <[email protected]>
Abusing rq->csd.list for a list of requests to complete is rather ugly. We use rq->queuelist instead which is much cleaner. It is safe because queuelist is used by the block layer only for requests waiting to be submitted to a device. Thus it is unused when irq reports the request IO is finished.
--- block/blk-softirq.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
block/blk-softirq.c +11 -6
@@ -30,8 +30,8 @@ static void blk_done_softirq(struct softirq_action *h)while (!list_empty (&local_list)) {struct request *rq; - rq = list_entry(local_list.next, struct request, csd.list); -list_del_init (&rq->csd.list); + rq = list_entry(local_list.next, struct request, queuelist); +list_del_init (&rq->queuelist); rq->q->softirq_done_fn (rq); } }
@@ -45,9 +45,14 @@ static void trigger_softirq(void *data)local_irq_save (flags); list =this_cpu_ptr (&blk_cpu_done); -list_add_tail (&rq->csd.list, list); +/* +* We reuse queuelist for a list of requests to process. Since the +* queuelist is used by the block layer only for requests waiting to be +* submitted to the device it is unused now. +*/ +list_add_tail (&rq->queuelist, list); -if (list->next == &rq->csd.list) +if (list->next == &rq->queuelist)raise_softirq_irqoff (BLOCK_SOFTIRQ );local_irq_restore (flags);
@@ -136,7 +141,7 @@ void __blk_complete_request(struct request *req)struct list_head *list; do_local: list =this_cpu_ptr (&blk_cpu_done); -list_add_tail (&req->csd.list, list); +list_add_tail (&req->queuelist, list);/* * if the list only contains our just added request,
@@ -144,7 +149,7 @@ do_local:* entries there, someone already raised the irq but it * hasn't run yet. */ -if (list->next == &req->csd.list) +if (list->next == &req->queuelist)raise_softirq_irqoff (BLOCK_SOFTIRQ ); }else if (raise_blk_irq (ccpu, req)) goto do_local;
Signature · 1 line
1.8.3.1
PATCH 4/11 smp: Iterate functions through llist_for_each_entry_safe()
In reply to Frederic WeisbeckerFrom: Jan Kara <[email protected]>
The IPI function llist iteration is open coded. Lets simplify this with using an llist iterator.
Also we want to keep the iteration safe against possible csd.llist->next value reuse from the IPI handler. At least the block subsystem used to do such things so lets stay careful and use llist_for_each_entry_safe().
--- kernel/smp.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
kernel/smp.c +3 -9
@@ -151,7 +151,8 @@ static void generic_exec_single(int cpu, struct call_single_data *csd, int wait)*/ void generic_smp_call_function_single_interrupt (void ) { -struct llist_node *entry, *next; +struct llist_node *entry; +struct call_single_data *csd, *csd_next;/* * Shouldn't receive this interrupt on a cpu that is not yet online.
@@ -161,16 +162,9 @@ void generic_smp_call_function_single_interrupt(void) entry =llist_del_all (&__get_cpu_var (call_single_queue)); entry =llist_reverse_order (entry); -while (entry) { -struct call_single_data *csd; - - next = entry->next; - - csd = llist_entry(entry, struct call_single_data, llist); +llist_for_each_entry_safe (csd, csd_next, entry, llist) { csd->func (csd->info);csd_unlock (csd); - - entry = next; } }
Signature · 1 line
1.8.3.1
PATCH 5/11 smp: Remove unused list_head from csd
In reply to Frederic WeisbeckerFrom: Jan Kara <[email protected]>
Now that we got rid of all the remaining code which fiddled with csd.list, lets remove it.
--- include/linux/smp.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
include/linux/smp.h +1 -4
@@ -17,10 +17,7 @@ extern void cpu_idle(void);typedef void (*smp_call_func_t )(void *info);struct call_single_data { -union { -struct list_head list; -struct llist_node llist; - }; +struct llist_node llist;smp_call_func_t func;void *info;u16 flags;
Signature · 1 line
1.8.3.1
PATCH 6/11 smp: Teach __smp_call_function_single() to check for offline cpus
In reply to Frederic WeisbeckerFrom: Jan Kara <[email protected]>
Align __smp_call_function_single() with smp_call_function_single() so that it also checks whether requested cpu is still online.
--- include/linux/smp.h | 3 +-- kernel/smp.c | 11 +++++++---- kernel/up.c | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-)
include/linux/smp.h +1 -2
@@ -50,8 +50,7 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info), smp_call_func_t func, void *info, bool wait, gfp_t gfp_flags); -void __smp_call_function_single (int cpuid,struct call_single_data *data, -int wait); +int __smp_call_function_single (int cpu,struct call_single_data *csd,int wait);#ifdef CONFIG_SMP
kernel/smp.c +7 -4
@@ -276,18 +276,18 @@ EXPORT_SYMBOL_GPL(smp_call_function_any);/** * __smp_call_function_single(): Run a function on a specific CPU * @cpu: The CPU to run on. -* @data: Pre-allocated and setup data structure +* @csd: Pre-allocated and setup data structure * @wait: If true, wait until function has completed on specified CPU. * * Like smp_call_function_single(), but allow caller to pass in a * pre-allocated data structure. Useful for embedding @data inside * other structures, for instance. */ -void __smp_call_function_single (int cpu,struct call_single_data *csd, -int wait) +int __smp_call_function_single (int cpu,struct call_single_data *csd,int wait) {unsigned int this_cpu;unsigned long flags; +int err =0 ; this_cpu =get_cpu ();/*
@@ -303,11 +303,14 @@ void __smp_call_function_single(int cpu, struct call_single_data *csd,local_irq_save (flags); csd->func (csd->info);local_irq_restore (flags); - }else { + }else if ((unsigned )cpu < nr_cpu_ids &&cpu_online (cpu)) {csd_lock (csd);generic_exec_single (cpu, csd, wait); + }else { + err = -ENXIO ;/* CPU not online */ }put_cpu (); +return err; }EXPORT_SYMBOL_GPL (__smp_call_function_single);
kernel/up.c +3 -2
@@ -22,14 +22,15 @@ int smp_call_function_single(int cpu, void (*func) (void *info), void *info, }EXPORT_SYMBOL (smp_call_function_single); -void __smp_call_function_single (int cpu,struct call_single_data *csd, -int wait) +int __smp_call_function_single (int cpu,struct call_single_data *csd, +int wait) {unsigned long flags;local_irq_save (flags); csd->func (csd->info);local_irq_restore (flags); +return 0 ; }EXPORT_SYMBOL (__smp_call_function_single);
Signature · 1 line
1.8.3.1
PATCH 7/11 smp: Consolidate the various smp_call_function_single() declensions
In reply to Frederic Weisbecker__smp_call_function_single() and smp_call_function_single() share some code that can be factorized: execute inline when the target is local, check if the target is online, lock the csd, call generic_exec_single().
Lets move the common parts to generic_exec_single().
--- kernel/smp.c | 80 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 41 deletions(-)
kernel/smp.c +39 -41
@@ -117,13 +117,43 @@ static void csd_unlock(struct call_single_data *csd) csd->flags &= ~CSD_FLAG_LOCK ; } +static DEFINE_PER_CPU_SHARED_ALIGNED(struct call_single_data, csd_data); +/* * Insert a previously allocated call_single_data element * for execution on the given CPU. data must already have * ->func, ->info, and ->flags set. */ -static void generic_exec_single (int cpu,struct call_single_data *csd,int wait) +static int generic_exec_single (int cpu,struct call_single_data *csd, +smp_call_func_t func,void *info,int wait) { +struct call_single_data csd_stack = { .flags =0 }; +unsigned long flags; + + +if (cpu ==smp_processor_id ()) { +local_irq_save (flags); +func (info); +local_irq_restore (flags); +return 0 ; + } + + +if ((unsigned )cpu >= nr_cpu_ids || !cpu_online (cpu)) +return -ENXIO ; + + +if (!csd) { + csd = &csd_stack; +if (!wait) + csd = &__get_cpu_var (csd_data); + } + +csd_lock (csd); + + csd->func = func; + csd->info = info; +if (wait) csd->flags |=CSD_FLAG_WAIT ;
@@ -143,6 +173,8 @@ static void generic_exec_single(int cpu, struct call_single_data *csd, int wait)if (wait)csd_lock_wait (csd); + +return 0 ; }/*
@@ -168,8 +200,6 @@ void generic_smp_call_function_single_interrupt(void) } } -static DEFINE_PER_CPU_SHARED_ALIGNED(struct call_single_data, csd_data); -/* * smp_call_function_single - Run a function on a specific CPU * @func: The function to run. This must be fast and non-blocking.
@@ -181,12 +211,8 @@ static DEFINE_PER_CPU_SHARED_ALIGNED(struct call_single_data, csd_data);int smp_call_function_single (int cpu,smp_call_func_t func,void *info,int wait) { -struct call_single_data d = { - .flags =0 , - }; -unsigned long flags;int this_cpu; -int err =0 ; +int err;/* * prevent preemption and reschedule on another processor,
@@ -203,26 +229,7 @@ int smp_call_function_single(int cpu, smp_call_func_t func, void *info,WARN_ON_ONCE (cpu_online (this_cpu) &&irqs_disabled () && !oops_in_progress); -if (cpu == this_cpu) { -local_irq_save (flags); -func (info); -local_irq_restore (flags); - }else { -if ((unsigned )cpu < nr_cpu_ids &&cpu_online (cpu)) { -struct call_single_data *csd = &d; - -if (!wait) - csd = &__get_cpu_var (csd_data); - -csd_lock (csd); - - csd->func = func; - csd->info = info; -generic_exec_single (cpu, csd, wait); - }else { - err = -ENXIO ;/* CPU not online */ - } - } + err =generic_exec_single (cpu,NULL , func, info, wait);put_cpu ();
@@ -285,9 +292,8 @@ EXPORT_SYMBOL_GPL(smp_call_function_any);*/ int __smp_call_function_single (int cpu,struct call_single_data *csd,int wait) { -unsigned int this_cpu; -unsigned long flags;int err =0 ; +int this_cpu; this_cpu =get_cpu ();/*
@@ -296,20 +302,12 @@ int __smp_call_function_single(int cpu, struct call_single_data *csd, int wait)* send smp call function interrupt to this cpu and as such deadlocks * can't happen. */ -WARN_ON_ONCE (cpu_online (smp_processor_id ()) && wait &&irqs_disabled () +WARN_ON_ONCE (cpu_online (this_cpu) && wait &&irqs_disabled () && !oops_in_progress); -if (cpu == this_cpu) { -local_irq_save (flags); - csd->func (csd->info); -local_irq_restore (flags); - }else if ((unsigned )cpu < nr_cpu_ids &&cpu_online (cpu)) { -csd_lock (csd); -generic_exec_single (cpu, csd, wait); - }else { - err = -ENXIO ;/* CPU not online */ - } + err =generic_exec_single (cpu, csd, csd->func, csd->info, wait);put_cpu (); +return err; }EXPORT_SYMBOL_GPL (__smp_call_function_single);
Signature · 1 line
1.8.3.1
Re: [PATCH 07/11] smp: Consolidate the various smp_call_function_single() declensions
Quoted 5 lines · Frederic Weisbecker
__smp_call_function_single()andsmp_call_function_single()share some code that can be factorized: execute inline when the target is local, check if the target is online, lock the csd, callgeneric_exec_single().Lets move the common parts to
generic_exec_single().
The patch looks good. You can add:
Honza
Quoted 158 lines
Cc Andrew Morton <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jan Kara <[email protected]>Cc Jens Axboe <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>--- kernel/smp.c | 80 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 41 deletions(-)kernel/smp.c +39
-41@@ -117,13 +117,43 @@ static void csd_unlock(struct call_single_data *csd) csd->flags &= ~CSD_FLAG_LOCK ; } +static DEFINE_PER_CPU_SHARED_ALIGNED(struct call_single_data, csd_data); +/* * Insert a previously allocated call_single_data element * for execution on the given CPU. data must already have * ->func, ->info, and ->flags set. */ -static void generic_exec_single (int cpu,struct call_single_data *csd,int wait) +static int generic_exec_single (int cpu,struct call_single_data *csd, +smp_call_func_t func,void *info,int wait) { +struct call_single_data csd_stack = { .flags =0 }; +unsigned long flags; + + +if (cpu ==smp_processor_id ()) { +local_irq_save (flags); +func (info); +local_irq_restore (flags); +return 0 ; + } + + +if ((unsigned )cpu >= nr_cpu_ids || !cpu_online (cpu)) +return -ENXIO ; + + +if (!csd) { + csd = &csd_stack; +if (!wait) + csd = &__get_cpu_var (csd_data); + } + +csd_lock (csd); + + csd->func = func; + csd->info = info; +if (wait) csd->flags |=CSD_FLAG_WAIT ;@@ -143,6 +173,8 @@ static void generic_exec_single(int cpu, struct call_single_data *csd, int wait)if (wait)csd_lock_wait (csd); + +return 0 ; }/* @@ -168,8 +200,6 @@ void generic_smp_call_function_single_interrupt(void) } } -static DEFINE_PER_CPU_SHARED_ALIGNED(struct call_single_data, csd_data); -/* * smp_call_function_single - Run a function on a specific CPU * @func: The function to run. This must be fast and non-blocking. @@ -181,12 +211,8 @@ static DEFINE_PER_CPU_SHARED_ALIGNED(struct call_single_data, csd_data);int smp_call_function_single (int cpu,smp_call_func_t func,void *info,int wait) { -struct call_single_data d = { - .flags =0 , - }; -unsigned long flags;int this_cpu; -int err =0 ; +int err;/* * prevent preemption and reschedule on another processor, @@ -203,26 +229,7 @@ int smp_call_function_single(int cpu, smp_call_func_t func, void *info,WARN_ON_ONCE (cpu_online (this_cpu) &&irqs_disabled () && !oops_in_progress); -if (cpu == this_cpu) { -local_irq_save (flags); -func (info); -local_irq_restore (flags); - }else { -if ((unsigned )cpu < nr_cpu_ids &&cpu_online (cpu)) { -struct call_single_data *csd = &d; - -if (!wait) - csd = &__get_cpu_var (csd_data); - -csd_lock (csd); - - csd->func = func; - csd->info = info; -generic_exec_single (cpu, csd, wait); - }else { - err = -ENXIO ;/* CPU not online */ - } - } + err =generic_exec_single (cpu,NULL , func, info, wait);put_cpu ();@@ -285,9 +292,8 @@ EXPORT_SYMBOL_GPL(smp_call_function_any);*/ int __smp_call_function_single (int cpu,struct call_single_data *csd,int wait) { -unsigned int this_cpu; -unsigned long flags;int err =0 ; +int this_cpu; this_cpu =get_cpu ();/* @@ -296,20 +302,12 @@ int __smp_call_function_single(int cpu, struct call_single_data *csd, int wait)* send smp call function interrupt to this cpu and as such deadlocks * can't happen. */ -WARN_ON_ONCE (cpu_online (smp_processor_id ()) && wait &&irqs_disabled () +WARN_ON_ONCE (cpu_online (this_cpu) && wait &&irqs_disabled () && !oops_in_progress); -if (cpu == this_cpu) { -local_irq_save (flags); - csd->func (csd->info); -local_irq_restore (flags); - }else if ((unsigned )cpu < nr_cpu_ids &&cpu_online (cpu)) { -csd_lock (csd); -generic_exec_single (cpu, csd, wait); - }else { - err = -ENXIO ;/* CPU not online */ - } + err =generic_exec_single (cpu, csd, csd->func, csd->info, wait);put_cpu (); +return err; }EXPORT_SYMBOL_GPL (__smp_call_function_single);Signature · 1 line
1.8.3.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH 8/11 smp: Move __smp_call_function_single() below its safe version
In reply to Frederic WeisbeckerMove this function closer to __smp_call_function_single(). These functions have very similar behavior and should be displayed in the same block for clarity.
--- kernel/smp.c | 64 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 32 deletions(-)
kernel/smp.c +32 -32
@@ -237,6 +237,38 @@ int smp_call_function_single(int cpu, smp_call_func_t func, void *info, }EXPORT_SYMBOL (smp_call_function_single); +/** +* __smp_call_function_single(): Run a function on a specific CPU +* @cpu: The CPU to run on. +* @csd: Pre-allocated and setup data structure +* @wait: If true, wait until function has completed on specified CPU. +* +* Like smp_call_function_single(), but allow caller to pass in a +* pre-allocated data structure. Useful for embedding @data inside +* other structures, for instance. +*/ +int __smp_call_function_single (int cpu,struct call_single_data *csd,int wait) +{ +int err =0 ; +int this_cpu; + + this_cpu =get_cpu (); +/* +* Can deadlock when called with interrupts disabled. +* We allow cpu's that are not yet online though, as no one else can +* send smp call function interrupt to this cpu and as such deadlocks +* can't happen. +*/ +WARN_ON_ONCE (cpu_online (this_cpu) && wait &&irqs_disabled () + && !oops_in_progress); + + err =generic_exec_single (cpu, csd, csd->func, csd->info, wait); +put_cpu (); + +return err; +} +EXPORT_SYMBOL_GPL (__smp_call_function_single); +/* * smp_call_function_any - Run a function on any of the given cpus * @mask: The mask of cpus it can run on.
@@ -281,38 +313,6 @@ call:EXPORT_SYMBOL_GPL (smp_call_function_any);/** -* __smp_call_function_single(): Run a function on a specific CPU -* @cpu: The CPU to run on. -* @csd: Pre-allocated and setup data structure -* @wait: If true, wait until function has completed on specified CPU. -* -* Like smp_call_function_single(), but allow caller to pass in a -* pre-allocated data structure. Useful for embedding @data inside -* other structures, for instance. -*/ -int __smp_call_function_single (int cpu,struct call_single_data *csd,int wait) -{ -int err =0 ; -int this_cpu; - - this_cpu =get_cpu (); -/* -* Can deadlock when called with interrupts disabled. -* We allow cpu's that are not yet online though, as no one else can -* send smp call function interrupt to this cpu and as such deadlocks -* can't happen. -*/ -WARN_ON_ONCE (cpu_online (this_cpu) && wait &&irqs_disabled () - && !oops_in_progress); - - err =generic_exec_single (cpu, csd, csd->func, csd->info, wait); -put_cpu (); - -return err; -} -EXPORT_SYMBOL_GPL (__smp_call_function_single); - -/** * smp_call_function_many(): Run a function on a set of other CPUs. * @mask: The set of cpus to run on (only runs on online subset). * @func: The function to run. This must be fast and non-blocking.
Signature · 1 line
1.8.3.1
Re: [PATCH 08/11] smp: Move __smp_call_function_single() below its safe version
Quoted 3 lines · Frederic Weisbecker
Move this function closer to
__smp_call_function_single(). These functions have very similar behavior and should be displayed in the same block for clarity.
Whatever :). You can add:
Honza
Quoted 96 lines
Cc Andrew Morton <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jan Kara <[email protected]>Cc Jens Axboe <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>--- kernel/smp.c | 64 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 32 deletions(-)kernel/smp.c +32
-32@@ -237,6 +237,38 @@ int smp_call_function_single(int cpu, smp_call_func_t func, void *info, }EXPORT_SYMBOL (smp_call_function_single); +/** +* __smp_call_function_single(): Run a function on a specific CPU +* @cpu: The CPU to run on. +* @csd: Pre-allocated and setup data structure +* @wait: If true, wait until function has completed on specified CPU. +* +* Like smp_call_function_single(), but allow caller to pass in a +* pre-allocated data structure. Useful for embedding @data inside +* other structures, for instance. +*/ +int __smp_call_function_single (int cpu,struct call_single_data *csd,int wait) +{ +int err =0 ; +int this_cpu; + + this_cpu =get_cpu (); +/* +* Can deadlock when called with interrupts disabled. +* We allow cpu's that are not yet online though, as no one else can +* send smp call function interrupt to this cpu and as such deadlocks +* can't happen. +*/ +WARN_ON_ONCE (cpu_online (this_cpu) && wait &&irqs_disabled () + && !oops_in_progress); + + err =generic_exec_single (cpu, csd, csd->func, csd->info, wait); +put_cpu (); + +return err; +} +EXPORT_SYMBOL_GPL (__smp_call_function_single); +/* * smp_call_function_any - Run a function on any of the given cpus * @mask: The mask of cpus it can run on. @@ -281,38 +313,6 @@ call:EXPORT_SYMBOL_GPL (smp_call_function_any);/** -* __smp_call_function_single(): Run a function on a specific CPU -* @cpu: The CPU to run on. -* @csd: Pre-allocated and setup data structure -* @wait: If true, wait until function has completed on specified CPU. -* -* Like smp_call_function_single(), but allow caller to pass in a -* pre-allocated data structure. Useful for embedding @data inside -* other structures, for instance. -*/ -int __smp_call_function_single (int cpu,struct call_single_data *csd,int wait) -{ -int err =0 ; -int this_cpu; - - this_cpu =get_cpu (); -/* -* Can deadlock when called with interrupts disabled. -* We allow cpu's that are not yet online though, as no one else can -* send smp call function interrupt to this cpu and as such deadlocks -* can't happen. -*/ -WARN_ON_ONCE (cpu_online (this_cpu) && wait &&irqs_disabled () - && !oops_in_progress); - - err =generic_exec_single (cpu, csd, csd->func, csd->info, wait); -put_cpu (); - -return err; -} -EXPORT_SYMBOL_GPL (__smp_call_function_single); - -/** * smp_call_function_many(): Run a function on a set of other CPUs. * @mask: The set of cpus to run on (only runs on online subset). * @func: The function to run. This must be fast and non-blocking. Signature · 1 line
1.8.3.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH 9/11 watchdog: Simplify a little the IPI call
In reply to Frederic WeisbeckerIn order to remotely restart the watchdog hrtimer, update_timers() allocates a csd on the stack and pass it to __smp_call_function_single().
There is no partcular need, however, for a specific csd here. Lets simplify that a little by calling smp_call_function_single() which can already take care of the csd allocation by itself.
--- kernel/watchdog.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/watchdog.c +1 -2
@@ -505,7 +505,6 @@ static void restart_watchdog_hrtimer(void *info)static void update_timers (int cpu) { -struct call_single_data data = {.func = restart_watchdog_hrtimer};/* * Make sure that perf event counter will adopt to a new * sampling period. Updating the sampling period directly would
@@ -515,7 +514,7 @@ static void update_timers(int cpu)* might be late already so we have to restart the timer as well. */ watchdog_nmi_disable (cpu); -__smp_call_function_single (cpu, &data,1 ); +smp_call_function_single (cpu, restart_watchdog_hrtimer,NULL ,1 );watchdog_nmi_enable (cpu); }
Signature · 1 line
1.8.3.1
Re: [PATCH 09/11] watchdog: Simplify a little the IPI call
Quoted 7 lines · Frederic Weisbecker
In order to remotely restart the watchdog hrtimer,
update_timers()allocates a csd on the stack and pass it to__smp_call_function_single().There is no partcular need, however, for a specific csd here. Lets simplify that a little by calling
smp_call_function_single()which can already take care of the csd allocation by itself.
Quoted 9 lines
Cc Andrew Morton <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Don Zickus <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jan Kara <[email protected]>Cc Jens Axboe <[email protected]>Cc Michal Hocko <[email protected]>Cc Srivatsa S. Bhat <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>
Looks good to me.
Quoted 28 lines
--- kernel/watchdog.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/watchdog.c +1
-2@@ -505,7 +505,6 @@ static void restart_watchdog_hrtimer(void *info)static void update_timers (int cpu) { -struct call_single_data data = {.func = restart_watchdog_hrtimer};/* * Make sure that perf event counter will adopt to a new * sampling period. Updating the sampling period directly would @@ -515,7 +514,7 @@ static void update_timers(int cpu)* might be late already so we have to restart the timer as well. */ watchdog_nmi_disable (cpu); -__smp_call_function_single (cpu, &data,1 ); +smp_call_function_single (cpu, restart_watchdog_hrtimer,NULL ,1 );watchdog_nmi_enable (cpu); }Signature · 1 line
1.8.3.1
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH 09/11] watchdog: Simplify a little the IPI call
In reply to Frederic WeisbeckerQuoted 6 lines · Frederic Weisbecker
In order to remotely restart the watchdog hrtimer,
update_timers()allocates a csd on the stack and pass it to__smp_call_function_single().There is no partcular need, however, for a specific csd here. Lets simplify that a little by calling
smp_call_function_single()which can already take care of the csd allocation by itself.
Sounds simple enough.
Quoted 38 lines
Cc Andrew Morton <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Don Zickus <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jan Kara <[email protected]>Cc Jens Axboe <[email protected]>Cc Michal Hocko <[email protected]>Cc Srivatsa S. Bhat <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>--- kernel/watchdog.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/watchdog.c +1
-2@@ -505,7 +505,6 @@ static void restart_watchdog_hrtimer(void *info)static void update_timers (int cpu) { -struct call_single_data data = {.func = restart_watchdog_hrtimer};/* * Make sure that perf event counter will adopt to a new * sampling period. Updating the sampling period directly would @@ -515,7 +514,7 @@ static void update_timers(int cpu)* might be late already so we have to restart the timer as well. */ watchdog_nmi_disable (cpu); -__smp_call_function_single (cpu, &data,1 ); +smp_call_function_single (cpu, restart_watchdog_hrtimer,NULL ,1 );watchdog_nmi_enable (cpu); }Signature · 1 line
1.8.3.1
PATCH 10/11 smp: Remove wait argument from __smp_call_function_single()
In reply to Frederic WeisbeckerThe main point of calling __smp_call_function_single() is to send an IPI in a pure asynchronous way. By embedding a csd in an object, a caller can send the IPI without waiting for a previous one to complete as is required by smp_call_function_single() for example. As such, sending this kind of IPI can be safe even when irqs are disabled.
This flexibility comes at the expense of the caller who then needs to synchronize the csd lifecycle by himself and make sure that IPIs on a single csd are serialized.
This is how __smp_call_function_single() works when wait = 0 and this usecase is relevant.
Now there don't seem to be any usecase with wait = 1 that can't be covered by smp_call_function_single() instead, which is safer. Lets look at the two possible scenario:
1) The user calls __smp_call_function_single(wait = 1) on a csd embedded in an object. It looks like a nice and convenient pattern at the first sight because we can then retrieve the object from the IPI handler easily.
But actually it is a waste of memory space in the object since the csd can be allocated from the stack by smp_call_function_single(wait = 1) and the object can be passed an the IPI argument.
Besides that, embedding the csd in an object is more error prone because the caller must take care of the serialization of the IPIs for this csd.
2) The user calls __smp_call_function_single(wait = 1) on a csd that is allocated on the stack. It's ok but smp_call_function_single() can do it as well and it already takes care of the allocation on the stack. Again it's more simple and less error prone.
Therefore, using the underscore prepend API version with wait = 1 is a bad pattern and a sign that the caller can do safer and more simple.
There was a single user of that which has just been converted. So lets remove this option to discourage further users.
--- block/blk-mq.c | 2 +- block/blk-softirq.c | 2 +- drivers/block/null_blk.c | 2 +- drivers/cpuidle/coupled.c | 2 +- include/linux/smp.h | 2 +- kernel/sched/core.c | 2 +- kernel/smp.c | 19 ++++--------------- kernel/up.c | 3 +-- net/core/dev.c | 2 +- 9 files changed, 12 insertions(+), 24 deletions(-)
block/blk-mq.c +1 -1
@@ -363,7 +363,7 @@ void blk_mq_end_io(struct request *rq, int error) rq->csd.func = blk_mq_end_io_remote; rq->csd.info = rq; rq->csd.flags =0 ; -__smp_call_function_single (ctx->cpu, &rq->csd,0 ); +__smp_call_function_single (ctx->cpu, &rq->csd); }else {__blk_mq_end_io (rq, error); }
block/blk-softirq.c +1 -1
@@ -70,7 +70,7 @@ static int raise_blk_irq(int cpu, struct request *rq) data->info = rq; data->flags =0 ; -__smp_call_function_single (cpu, data,0 ); +__smp_call_function_single (cpu, data);return 0 ; }
drivers/block/null_blk.c +1 -1
@@ -255,7 +255,7 @@ static void null_cmd_end_ipi(struct nullb_cmd *cmd)if (llist_add (&cmd->ll_list, &cq->list)) { data->func = null_ipi_cmd_end_io; data->flags =0 ; -__smp_call_function_single (cpu, data,0 ); +__smp_call_function_single (cpu, data); }put_cpu ();
drivers/cpuidle/coupled.c +1 -1
@@ -323,7 +323,7 @@ static void cpuidle_coupled_poke(int cpu)struct call_single_data *csd = &per_cpu (cpuidle_coupled_poke_cb, cpu);if (!cpumask_test_and_set_cpu (cpu, &cpuidle_coupled_poke_pending)) -__smp_call_function_single (cpu, csd,0 ); +__smp_call_function_single (cpu, csd); }/**
include/linux/smp.h +1 -1
@@ -50,7 +50,7 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info), smp_call_func_t func, void *info, bool wait, gfp_t gfp_flags); -int __smp_call_function_single (int cpu,struct call_single_data *csd,int wait); +int __smp_call_function_single (int cpu,struct call_single_data *csd);#ifdef CONFIG_SMP
kernel/sched/core.c +1 -1
@@ -432,7 +432,7 @@ void hrtick_start(struct rq *rq, u64 delay)if (rq ==this_rq ()) {__hrtick_restart (rq); }else if (!rq->hrtick_csd_pending) { -__smp_call_function_single (cpu_of (rq), &rq->hrtick_csd,0 ); +__smp_call_function_single (cpu_of (rq), &rq->hrtick_csd); rq->hrtick_csd_pending =1 ; } }
kernel/smp.c +4 -15
@@ -241,29 +241,18 @@ EXPORT_SYMBOL(smp_call_function_single);* __smp_call_function_single(): Run a function on a specific CPU * @cpu: The CPU to run on. * @csd: Pre-allocated and setup data structure -* @wait: If true, wait until function has completed on specified CPU. * * Like smp_call_function_single(), but allow caller to pass in a * pre-allocated data structure. Useful for embedding @data inside * other structures, for instance. */ -int __smp_call_function_single (int cpu,struct call_single_data *csd,int wait) +int __smp_call_function_single (int cpu,struct call_single_data *csd) {int err =0 ; -int this_cpu; - this_cpu =get_cpu (); -/* -* Can deadlock when called with interrupts disabled. -* We allow cpu's that are not yet online though, as no one else can -* send smp call function interrupt to this cpu and as such deadlocks -* can't happen. -*/ -WARN_ON_ONCE (cpu_online (this_cpu) && wait &&irqs_disabled () - && !oops_in_progress); - - err =generic_exec_single (cpu, csd, csd->func, csd->info, wait); -put_cpu (); +preempt_disable (); + err =generic_exec_single (cpu, csd, csd->func, csd->info,0 ); +preempt_enable ();return err; }
kernel/up.c +1 -2
@@ -22,8 +22,7 @@ int smp_call_function_single(int cpu, void (*func) (void *info), void *info, }EXPORT_SYMBOL (smp_call_function_single); -int __smp_call_function_single (int cpu,struct call_single_data *csd, -int wait) +int __smp_call_function_single (int cpu,struct call_single_data *csd) {unsigned long flags;
net/core/dev.c +1 -1
@@ -4129,7 +4129,7 @@ static void net_rps_action_and_irq_enable(struct softnet_data *sd)if (cpu_online (remsd->cpu))__smp_call_function_single (remsd->cpu, - &remsd->csd,0 ); + &remsd->csd); remsd = next; } }else
Signature · 1 line
1.8.3.1
Re: [PATCH 10/11] smp: Remove wait argument from __smp_call_function_single()
Might be worth to give the function a saner name than just the __-prefix if you touch all callers anyway.
Re: [PATCH 10/11] smp: Remove wait argument from __smp_call_function_single()
Quoted 3 lines · Christoph Hellwig
Might be worth to give the function a saner name than just the __-prefix if you touch all callers anyway.
Good point. How about smp_call_function_single_async() ?
Re: [PATCH 10/11] smp: Remove wait argument from __smp_call_function_single()
Quoted 1 line · Frederic Weisbecker
Good point. How about
smp_call_function_single_async()?
Fine with me.
PATCH 11/11 smp: Enhance and precise the role & requirements of __smp_call_function_single()
In reply to Frederic WeisbeckerBe more specific on the description of __smp_call_function_single(). It's actually not that much about just being able to embed a csd in an object.
--- kernel/smp.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
kernel/smp.c +11 -4
@@ -238,13 +238,20 @@ int smp_call_function_single(int cpu, smp_call_func_t func, void *info,EXPORT_SYMBOL (smp_call_function_single);/** -* __smp_call_function_single(): Run a function on a specific CPU +* __smp_call_function_single(): Run an asynchronous function on a +* specific CPU. * @cpu: The CPU to run on. * @csd: Pre-allocated and setup data structure * -* Like smp_call_function_single(), but allow caller to pass in a -* pre-allocated data structure. Useful for embedding @data inside -* other structures, for instance. +* Like smp_call_function_single(), but the call is asynchonous and +* can thus be done from contexts with disabled interrupts. +* +* The caller passes his own pre-allocated data structure +* (ie: embedded in an object) and is responsible for synchronizing it +* such that the IPIs performed on the @csd are strictly serialized. +* +* NOTE: Be careful, there is unfortunately no current debugging facility to +* validate the correctness of this serialization. */ int __smp_call_function_single (int cpu,struct call_single_data *csd) {
Signature · 1 line
1.8.3.1