History

smp: Cleanup smp_call_function*()

Get rid of the __call_single_node union and cleanup the API a little to avoid external code relying on the structure layout as much.

Peter Zijlstra committed 6 years ago

Commit 545b8c81 parent 7a9f50a13 files · +60 −94Browse files

Unified · Split

13 files
  1. arch/mips/kernel/process.c +3 −2
  2. arch/mips/kernel/smp.c +6 −19
  3. arch/s390/pci/pci_irq.c +1 −3
  4. arch/x86/kernel/cpuid.c +3 −4
  5. arch/x86/lib/msr-smp.c +3 −4
  6. block/blk-mq.c +1 −3
  7. drivers/cpuidle/coupled.c +1 −2
  8. drivers/net/ethernet/cavium/liquidio/lio_core.c +2 −7
  9. include/linux/smp.h +9 −10
  10. kernel/debug/debug_core.c +3 −3
  11. kernel/sched/core.c +2 −10
  12. kernel/smp.c +25 −25
  13. net/core/dev.c +1 −2
arch/mips/kernel/process.c+3−2
@@ -702,7 +702,6 @@ unsigned long arch_align_stack(unsigned long sp) · 701 unmodified lines
702702 return sp & ALMASK;
703703 }
704704
705−static DEFINE_PER_CPU(call_single_data_t, backtrace_csd);
706705 static struct cpumask backtrace_csd_busy;
707706
708707 static void handle_backtrace(void *info)
@@ -711,6 +710,9 @@ static void handle_backtrace(void *info) · 2 unmodified lines
711710 cpumask_clear_cpu(smp_processor_id(), &backtrace_csd_busy);
712711 }
713712
713+static DEFINE_PER_CPU(call_single_data_t, backtrace_csd) =
714+ CSD_INIT(handle_backtrace, NULL);
715+
714716 static void raise_backtrace(cpumask_t *mask)
715717 {
716718 call_single_data_t *csd;
@@ -730,7 +732,6 @@ static void raise_backtrace(cpumask_t *mask) · 13 unmodified lines
730732 }
731733
732734 csd = &per_cpu(backtrace_csd, cpu);
733− csd->func = handle_backtrace;
734735 smp_call_function_single_async(cpu, csd);
735736 }
736737 }
arch/mips/kernel/smp.c+6−19
@@ -687,36 +687,23 @@ EXPORT_SYMBOL(flush_tlb_one); · 686 unmodified lines
687687
688688 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
689689
690−static DEFINE_PER_CPU(call_single_data_t, tick_broadcast_csd);
691−
692−void tick_broadcast(const struct cpumask *mask)
693−{
694− call_single_data_t *csd;
695− int cpu;
696−
697− for_each_cpu(cpu, mask) {
698− csd = &per_cpu(tick_broadcast_csd, cpu);
699− smp_call_function_single_async(cpu, csd);
700− }
701−}
702−
703690 static void tick_broadcast_callee(void *info)
704691 {
705692 tick_receive_broadcast();
706693 }
707694
708−static int __init tick_broadcast_init(void)
695+static DEFINE_PER_CPU(call_single_data_t, tick_broadcast_csd) =
696+ CSD_INIT(tick_broadcast_callee, NULL);
697+
698+void tick_broadcast(const struct cpumask *mask)
709699 {
710700 call_single_data_t *csd;
711701 int cpu;
712702
713− for (cpu = 0; cpu < NR_CPUS; cpu++) {
703+ for_each_cpu(cpu, mask) {
714704 csd = &per_cpu(tick_broadcast_csd, cpu);
715− csd->func = tick_broadcast_callee;
705+ smp_call_function_single_async(cpu, csd);
716706 }
717−
718− return 0;
719707 }
720−early_initcall(tick_broadcast_init);
721708
722709 #endif /* CONFIG_GENERIC_CLOCKEVENTS_BROADCAST */
arch/s390/pci/pci_irq.c+1−3
@@ -178,9 +178,7 @@ static void zpci_handle_fallback_irq(void) · 177 unmodified lines
178178 if (atomic_inc_return(&cpu_data->scheduled) > 1)
179179 continue;
180180
181− cpu_data->csd.func = zpci_handle_remote_irq;
182− cpu_data->csd.info = &cpu_data->scheduled;
183− cpu_data->csd.flags = 0;
181+ INIT_CSD(&cpu_data->csd, zpci_handle_remote_irq, &cpu_data->scheduled);
184182 smp_call_function_single_async(cpu, &cpu_data->csd);
185183 }
186184 }
arch/x86/kernel/cpuid.c+3−4
@@ -74,10 +74,9 @@ static ssize_t cpuid_read(struct file *file, char __user *buf, · 73 unmodified lines
7474
7575 init_completion(&cmd.done);
7676 for (; count; count -= 16) {
77− call_single_data_t csd = {
78− .func = cpuid_smp_cpuid,
79− .info = &cmd,
80− };
77+ call_single_data_t csd;
78+
79+ INIT_CSD(&csd, cpuid_smp_cpuid, &cmd);
8180
8281 cmd.regs.eax = pos;
8382 cmd.regs.ecx = pos >> 32;
arch/x86/lib/msr-smp.c+3−4
@@ -169,12 +169,11 @@ static void __wrmsr_safe_on_cpu(void *info) · 168 unmodified lines
169169 int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h)
170170 {
171171 struct msr_info_completion rv;
172− call_single_data_t csd = {
173− .func = __rdmsr_safe_on_cpu,
174− .info = &rv,
175− };
172+ call_single_data_t csd;
176173 int err;
177174
175+ INIT_CSD(&csd, __rdmsr_safe_on_cpu, &rv);
176+
178177 memset(&rv, 0, sizeof(rv));
179178 init_completion(&rv.done);
180179 rv.msr.msr_no = msr_no;
block/blk-mq.c+1−3
@@ -671,9 +671,7 @@ bool blk_mq_complete_request_remote(struct request *rq) · 670 unmodified lines
671671 return false;
672672
673673 if (blk_mq_complete_need_ipi(rq)) {
674− rq->csd.func = __blk_mq_complete_request_remote;
675− rq->csd.info = rq;
676− rq->csd.flags = 0;
674+ INIT_CSD(&rq->csd, __blk_mq_complete_request_remote, rq);
677675 smp_call_function_single_async(rq->mq_ctx->cpu, &rq->csd);
678676 } else {
679677 if (rq->q->nr_hw_queues > 1)
drivers/cpuidle/coupled.c+1−2
@@ -674,8 +674,7 @@ have_coupled: · 673 unmodified lines
674674 coupled->refcnt++;
675675
676676 csd = &per_cpu(cpuidle_coupled_poke_cb, dev->cpu);
677− csd->func = cpuidle_coupled_handle_poke;
678− csd->info = (void *)(unsigned long)dev->cpu;
677+ INIT_CSD(csd, cpuidle_coupled_handle_poke, (void *)(unsigned long)dev->cpu);
679678
680679 return 0;
681680 }
drivers/net/ethernet/cavium/liquidio/lio_core.c+2−7
@@ -729,13 +729,8 @@ static void liquidio_napi_drv_callback(void *arg) · 728 unmodified lines
729729 droq->cpu_id == this_cpu) {
730730 napi_schedule_irqoff(&droq->napi);
731731 } else {
732− call_single_data_t *csd = &droq->csd;
733−
734− csd->func = napi_schedule_wrapper;
735− csd->info = &droq->napi;
736− csd->flags = 0;
737−
738− smp_call_function_single_async(droq->cpu_id, csd);
732+ INIT_CSD(&droq->csd, napi_schedule_wrapper, &droq->napi);
733+ smp_call_function_single_async(droq->cpu_id, &droq->csd);
739734 }
740735 }
741736
include/linux/smp.h+9−10
@@ -21,24 +21,23 @@ typedef bool (*smp_cond_func_t)(int cpu, void *info); · 20 unmodified lines
2121 * structure shares (partial) layout with struct irq_work
2222 */
2323 struct __call_single_data {
24− union {
25− struct __call_single_node node;
26− struct {
27− struct llist_node llist;
28− unsigned int flags;
29−#ifdef CONFIG_64BIT
30− u16 src, dst;
31−#endif
32− };
33− };
24+ struct __call_single_node node;
3425 smp_call_func_t func;
3526 void *info;
3627 };
3728
29+#define CSD_INIT(_func, _info) \
30+ (struct __call_single_data){ .func = (_func), .info = (_info), }
31+
3832 /* Use __aligned() to avoid to use 2 cache lines for 1 csd */
3933 typedef struct __call_single_data call_single_data_t
4034 __aligned(sizeof(struct __call_single_data));
4135
36+#define INIT_CSD(_csd, _func, _info) \
37+do { \
38+ *(_csd) = CSD_INIT((_func), (_info)); \
39+} while (0)
40+
4241 /*
4342 * Enqueue a llist_node on the call_single_queue; be very careful, read
4443 * flush_smp_call_function_queue() in detail.
kernel/debug/debug_core.c+3−3
@@ -225,8 +225,6 @@ NOKPROBE_SYMBOL(kgdb_skipexception); · 224 unmodified lines
225225 * Default (weak) implementation for kgdb_roundup_cpus
226226 */
227227
228−static DEFINE_PER_CPU(call_single_data_t, kgdb_roundup_csd);
229−
230228 void __weak kgdb_call_nmi_hook(void *ignored)
231229 {
232230 /*
@@ -241,6 +239,9 @@ void __weak kgdb_call_nmi_hook(void *ignored) · 8 unmodified lines
241239 }
242240 NOKPROBE_SYMBOL(kgdb_call_nmi_hook);
243241
242+static DEFINE_PER_CPU(call_single_data_t, kgdb_roundup_csd) =
243+ CSD_INIT(kgdb_call_nmi_hook, NULL);
244+
244245 void __weak kgdb_roundup_cpus(void)
245246 {
246247 call_single_data_t *csd;
@@ -267,7 +268,6 @@ void __weak kgdb_roundup_cpus(void) · 20 unmodified lines
267268 continue;
268269 kgdb_info[cpu].rounding_up = true;
269270
270− csd->func = kgdb_call_nmi_hook;
271271 ret = smp_call_function_single_async(cpu, csd);
272272 if (ret)
273273 kgdb_info[cpu].rounding_up = false;
kernel/sched/core.c+2−10
@@ -320,14 +320,6 @@ void update_rq_clock(struct rq *rq) · 319 unmodified lines
320320 update_rq_clock_task(rq, delta);
321321 }
322322
323−static inline void
324−rq_csd_init(struct rq *rq, call_single_data_t *csd, smp_call_func_t func)
325−{
326− csd->flags = 0;
327− csd->func = func;
328− csd->info = rq;
329−}
330−
331323 #ifdef CONFIG_SCHED_HRTICK
332324 /*
333325 * Use HR-timers to deliver accurate preemption points.
@@ -428,7 +420,7 @@ void hrtick_start(struct rq *rq, u64 delay) · 94 unmodified lines
428420 static void hrtick_rq_init(struct rq *rq)
429421 {
430422 #ifdef CONFIG_SMP
431− rq_csd_init(rq, &rq->hrtick_csd, __hrtick_start);
423+ INIT_CSD(&rq->hrtick_csd, __hrtick_start, rq);
432424 #endif
433425 hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);
434426 rq->hrtick_timer.function = hrtick;
@@ -7774,7 +7766,7 @@ void __init sched_init(void) · 7339 unmodified lines
77747766 rq->last_blocked_load_update_tick = jiffies;
77757767 atomic_set(&rq->nohz_flags, 0);
77767768
7777− rq_csd_init(rq, &rq->nohz_csd, nohz_csd_func);
7769+ INIT_CSD(&rq->nohz_csd, nohz_csd_func, rq);
77787770 #endif
77797771 #ifdef CONFIG_HOTPLUG_CPU
77807772 rcuwait_init(&rq->hotplug_wait);
kernel/smp.c+25−25
@@ -27,7 +27,7 @@ · 26 unmodified lines
2727 #include "smpboot.h"
2828 #include "sched/smp.h"
2929
30−#define CSD_TYPE(_csd) ((_csd)->flags & CSD_FLAG_TYPE_MASK)
30+#define CSD_TYPE(_csd) ((_csd)->node.u_flags & CSD_FLAG_TYPE_MASK)
3131
3232 struct call_function_data {
3333 call_single_data_t __percpu *csd;
@@ -146,7 +146,7 @@ static __always_inline bool csd_lock_wait_toolong(call_single_data_t *csd, u64 t · 112 unmodified lines
146146 bool firsttime;
147147 u64 ts2, ts_delta;
148148 call_single_data_t *cpu_cur_csd;
149− unsigned int flags = READ_ONCE(csd->flags);
149+ unsigned int flags = READ_ONCE(csd->node.u_flags);
150150
151151 if (!(flags & CSD_FLAG_LOCK)) {
152152 if (!unlikely(*bug_id))
@@ -224,14 +224,14 @@ static void csd_lock_record(call_single_data_t *csd) · 71 unmodified lines
224224
225225 static __always_inline void csd_lock_wait(call_single_data_t *csd)
226226 {
227− smp_cond_load_acquire(&csd->flags, !(VAL & CSD_FLAG_LOCK));
227+ smp_cond_load_acquire(&csd->node.u_flags, !(VAL & CSD_FLAG_LOCK));
228228 }
229229 #endif
230230
231231 static __always_inline void csd_lock(call_single_data_t *csd)
232232 {
233233 csd_lock_wait(csd);
234− csd->flags |= CSD_FLAG_LOCK;
234+ csd->node.u_flags |= CSD_FLAG_LOCK;
235235
236236 /*
237237 * prevent CPU from reordering the above assignment
@@ -243,12 +243,12 @@ static __always_inline void csd_lock(call_single_data_t *csd) · 5 unmodified lines
243243
244244 static __always_inline void csd_unlock(call_single_data_t *csd)
245245 {
246− WARN_ON(!(csd->flags & CSD_FLAG_LOCK));
246+ WARN_ON(!(csd->node.u_flags & CSD_FLAG_LOCK));
247247
248248 /*
249249 * ensure we're all done before releasing data:
250250 */
251− smp_store_release(&csd->flags, 0);
251+ smp_store_release(&csd->node.u_flags, 0);
252252 }
253253
254254 static DEFINE_PER_CPU_SHARED_ALIGNED(call_single_data_t, csd_data);
@@ -300,7 +300,7 @@ static int generic_exec_single(int cpu, call_single_data_t *csd) · 45 unmodified lines
300300 return -ENXIO;
301301 }
302302
303− __smp_call_single_queue(cpu, &csd->llist);
303+ __smp_call_single_queue(cpu, &csd->node.llist);
304304
305305 return 0;
306306 }
@@ -353,7 +353,7 @@ static void flush_smp_call_function_queue(bool warn_cpu_offline) · 46 unmodified lines
353353 * We don't have to use the _safe() variant here
354354 * because we are not invoking the IPI handlers yet.
355355 */
356− llist_for_each_entry(csd, entry, llist) {
356+ llist_for_each_entry(csd, entry, node.llist) {
357357 switch (CSD_TYPE(csd)) {
358358 case CSD_TYPE_ASYNC:
359359 case CSD_TYPE_SYNC:
@@ -378,16 +378,16 @@ static void flush_smp_call_function_queue(bool warn_cpu_offline) · 18 unmodified lines
378378 * First; run all SYNC callbacks, people are waiting for us.
379379 */
380380 prev = NULL;
381− llist_for_each_entry_safe(csd, csd_next, entry, llist) {
381+ llist_for_each_entry_safe(csd, csd_next, entry, node.llist) {
382382 /* Do we wait until *after* callback? */
383383 if (CSD_TYPE(csd) == CSD_TYPE_SYNC) {
384384 smp_call_func_t func = csd->func;
385385 void *info = csd->info;
386386
387387 if (prev) {
388− prev->next = &csd_next->llist;
388+ prev->next = &csd_next->node.llist;
389389 } else {
390− entry = &csd_next->llist;
390+ entry = &csd_next->node.llist;
391391 }
392392
393393 csd_lock_record(csd);
@@ -395,7 +395,7 @@ static void flush_smp_call_function_queue(bool warn_cpu_offline) · 1 unmodified line
395395 csd_unlock(csd);
396396 csd_lock_record(NULL);
397397 } else {
398− prev = &csd->llist;
398+ prev = &csd->node.llist;
399399 }
400400 }
401401
@@ -406,14 +406,14 @@ static void flush_smp_call_function_queue(bool warn_cpu_offline) · 4 unmodified lines
406406 * Second; run all !SYNC callbacks.
407407 */
408408 prev = NULL;
409− llist_for_each_entry_safe(csd, csd_next, entry, llist) {
409+ llist_for_each_entry_safe(csd, csd_next, entry, node.llist) {
410410 int type = CSD_TYPE(csd);
411411
412412 if (type != CSD_TYPE_TTWU) {
413413 if (prev) {
414− prev->next = &csd_next->llist;
414+ prev->next = &csd_next->node.llist;
415415 } else {
416− entry = &csd_next->llist;
416+ entry = &csd_next->node.llist;
417417 }
418418
419419 if (type == CSD_TYPE_ASYNC) {
@@ -429,7 +429,7 @@ static void flush_smp_call_function_queue(bool warn_cpu_offline) · 9 unmodified lines
429429 }
430430
431431 } else {
432− prev = &csd->llist;
432+ prev = &csd->node.llist;
433433 }
434434 }
435435
@@ -465,7 +465,7 @@ int smp_call_function_single(int cpu, smp_call_func_t func, void *info, · 29 unmodified lines
465465 {
466466 call_single_data_t *csd;
467467 call_single_data_t csd_stack = {
468− .flags = CSD_FLAG_LOCK | CSD_TYPE_SYNC,
468+ .node = { .u_flags = CSD_FLAG_LOCK | CSD_TYPE_SYNC, },
469469 };
470470 int this_cpu;
471471 int err;
@@ -502,8 +502,8 @@ int smp_call_function_single(int cpu, smp_call_func_t func, void *info, · 30 unmodified lines
502502 csd->func = func;
503503 csd->info = info;
504504 #ifdef CONFIG_CSD_LOCK_WAIT_DEBUG
505− csd->src = smp_processor_id();
506− csd->dst = cpu;
505+ csd->node.src = smp_processor_id();
506+ csd->node.dst = cpu;
507507 #endif
508508
509509 err = generic_exec_single(cpu, csd);
@@ -544,12 +544,12 @@ int smp_call_function_single_async(int cpu, call_single_data_t *csd) · 34 unmodified lines
544544
545545 preempt_disable();
546546
547− if (csd->flags & CSD_FLAG_LOCK) {
547+ if (csd->node.u_flags & CSD_FLAG_LOCK) {
548548 err = -EBUSY;
549549 goto out;
550550 }
551551
552− csd->flags = CSD_FLAG_LOCK;
552+ csd->node.u_flags = CSD_FLAG_LOCK;
553553 smp_wmb();
554554
555555 err = generic_exec_single(cpu, csd);
@@ -667,14 +667,14 @@ static void smp_call_function_many_cond(const struct cpumask *mask, · 111 unmodified lines
667667
668668 csd_lock(csd);
669669 if (wait)
670− csd->flags |= CSD_TYPE_SYNC;
670+ csd->node.u_flags |= CSD_TYPE_SYNC;
671671 csd->func = func;
672672 csd->info = info;
673673 #ifdef CONFIG_CSD_LOCK_WAIT_DEBUG
674− csd->src = smp_processor_id();
675− csd->dst = cpu;
674+ csd->node.src = smp_processor_id();
675+ csd->node.dst = cpu;
676676 #endif
677− if (llist_add(&csd->llist, &per_cpu(call_single_queue, cpu)))
677+ if (llist_add(&csd->node.llist, &per_cpu(call_single_queue, cpu)))
678678 __cpumask_set_cpu(cpu, cfd->cpumask_ipi);
679679 }
680680
net/core/dev.c+1−2
@@ -11165,8 +11165,7 @@ static int __init net_dev_init(void) · 11164 unmodified lines
1116511165 INIT_LIST_HEAD(&sd->poll_list);
1116611166 sd->output_queue_tailp = &sd->output_queue;
1116711167 #ifdef CONFIG_RPS
11168− sd->csd.func = rps_trigger_softirq;
11169− sd->csd.info = sd;
11168+ INIT_CSD(&sd->csd, rps_trigger_softirq, sd);
1117011169 sd->cpu = i;
1117111170 #endif
1117211171

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t