FROMLIST: arm64: vdso32: Use full path to Clang instead of relying on PATH
[GitHub/exynos8895/android_kernel_samsung_universal8895.git] / kernel / softirq.c
1 /*
2 * linux/kernel/softirq.c
3 *
4 * Copyright (C) 1992 Linus Torvalds
5 *
6 * Distribute under GPLv2.
7 *
8 * Rewritten. Old one was good in 2.2, but in 2.3 it was immoral. --ANK (990903)
9 */
10
11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
13 #include <linux/export.h>
14 #include <linux/kernel_stat.h>
15 #include <linux/interrupt.h>
16 #include <linux/init.h>
17 #include <linux/mm.h>
18 #include <linux/notifier.h>
19 #include <linux/percpu.h>
20 #include <linux/cpu.h>
21 #include <linux/freezer.h>
22 #include <linux/kthread.h>
23 #include <linux/rcupdate.h>
24 #include <linux/ftrace.h>
25 #include <linux/smp.h>
26 #include <linux/smpboot.h>
27 #include <linux/tick.h>
28 #include <linux/irq.h>
29 #include <linux/exynos-ss.h>
30
31 #define CREATE_TRACE_POINTS
32 #include <trace/events/irq.h>
33
34 #include <linux/nmi.h>
35
36 /*
37 - No shared variables, all the data are CPU local.
38 - If a softirq needs serialization, let it serialize itself
39 by its own spinlocks.
40 - Even if softirq is serialized, only local cpu is marked for
41 execution. Hence, we get something sort of weak cpu binding.
42 Though it is still not clear, will it result in better locality
43 or will not.
44
45 Examples:
46 - NET RX softirq. It is multithreaded and does not require
47 any global serialization.
48 - NET TX softirq. It kicks software netdevice queues, hence
49 it is logically serialized per device, but this serialization
50 is invisible to common code.
51 - Tasklets: serialized wrt itself.
52 */
53
54 #ifndef __ARCH_IRQ_STAT
55 irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
56 EXPORT_SYMBOL(irq_stat);
57 #endif
58
59 static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
60
61 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
62
63 const char * const softirq_to_name[NR_SOFTIRQS] = {
64 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
65 "TASKLET", "SCHED", "HRTIMER", "RCU"
66 };
67
68 /*
69 * we cannot loop indefinitely here to avoid userspace starvation,
70 * but we also don't want to introduce a worst case 1/HZ latency
71 * to the pending events, so lets the scheduler to balance
72 * the softirq load for us.
73 */
74 static void wakeup_softirqd(void)
75 {
76 /* Interrupts are disabled: no need to stop preemption */
77 struct task_struct *tsk = __this_cpu_read(ksoftirqd);
78
79 if (tsk && tsk->state != TASK_RUNNING)
80 wake_up_process(tsk);
81 }
82
83 /*
84 * preempt_count and SOFTIRQ_OFFSET usage:
85 * - preempt_count is changed by SOFTIRQ_OFFSET on entering or leaving
86 * softirq processing.
87 * - preempt_count is changed by SOFTIRQ_DISABLE_OFFSET (= 2 * SOFTIRQ_OFFSET)
88 * on local_bh_disable or local_bh_enable.
89 * This lets us distinguish between whether we are currently processing
90 * softirq and whether we just have bh disabled.
91 */
92
93 /*
94 * This one is for softirq.c-internal use,
95 * where hardirqs are disabled legitimately:
96 */
97 #ifdef CONFIG_TRACE_IRQFLAGS
98 void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)
99 {
100 unsigned long flags;
101
102 WARN_ON_ONCE(in_irq());
103
104 raw_local_irq_save(flags);
105 /*
106 * The preempt tracer hooks into preempt_count_add and will break
107 * lockdep because it calls back into lockdep after SOFTIRQ_OFFSET
108 * is set and before current->softirq_enabled is cleared.
109 * We must manually increment preempt_count here and manually
110 * call the trace_preempt_off later.
111 */
112 __preempt_count_add(cnt);
113 /*
114 * Were softirqs turned off above:
115 */
116 if (softirq_count() == (cnt & SOFTIRQ_MASK))
117 trace_softirqs_off(ip);
118 raw_local_irq_restore(flags);
119
120 if (preempt_count() == cnt) {
121 #ifdef CONFIG_DEBUG_PREEMPT
122 current->preempt_disable_ip = get_parent_ip(CALLER_ADDR1);
123 #endif
124 trace_preempt_off(CALLER_ADDR0, get_parent_ip(CALLER_ADDR1));
125 }
126 }
127 EXPORT_SYMBOL(__local_bh_disable_ip);
128 #endif /* CONFIG_TRACE_IRQFLAGS */
129
130 static void __local_bh_enable(unsigned int cnt)
131 {
132 WARN_ON_ONCE(!irqs_disabled());
133
134 if (softirq_count() == (cnt & SOFTIRQ_MASK))
135 trace_softirqs_on(_RET_IP_);
136 preempt_count_sub(cnt);
137 }
138
139 /*
140 * Special-case - softirqs can safely be enabled in
141 * cond_resched_softirq(), or by __do_softirq(),
142 * without processing still-pending softirqs:
143 */
144 void _local_bh_enable(void)
145 {
146 WARN_ON_ONCE(in_irq());
147 __local_bh_enable(SOFTIRQ_DISABLE_OFFSET);
148 }
149 EXPORT_SYMBOL(_local_bh_enable);
150
151 void __local_bh_enable_ip(unsigned long ip, unsigned int cnt)
152 {
153 WARN_ON_ONCE(in_irq() || irqs_disabled());
154 #ifdef CONFIG_TRACE_IRQFLAGS
155 local_irq_disable();
156 #endif
157 /*
158 * Are softirqs going to be turned on now:
159 */
160 if (softirq_count() == SOFTIRQ_DISABLE_OFFSET)
161 trace_softirqs_on(ip);
162 /*
163 * Keep preemption disabled until we are done with
164 * softirq processing:
165 */
166 preempt_count_sub(cnt - 1);
167
168 if (unlikely(!in_interrupt() && local_softirq_pending())) {
169 /*
170 * Run softirq if any pending. And do it in its own stack
171 * as we may be calling this deep in a task call stack already.
172 */
173 do_softirq();
174 }
175
176 preempt_count_dec();
177 #ifdef CONFIG_TRACE_IRQFLAGS
178 local_irq_enable();
179 #endif
180 preempt_check_resched();
181 }
182 EXPORT_SYMBOL(__local_bh_enable_ip);
183
184 /*
185 * We restart softirq processing for at most MAX_SOFTIRQ_RESTART times,
186 * but break the loop if need_resched() is set or after 2 ms.
187 * The MAX_SOFTIRQ_TIME provides a nice upper bound in most cases, but in
188 * certain cases, such as stop_machine(), jiffies may cease to
189 * increment and so we need the MAX_SOFTIRQ_RESTART limit as
190 * well to make sure we eventually return from this method.
191 *
192 * These limits have been established via experimentation.
193 * The two things to balance is latency against fairness -
194 * we want to handle softirqs as soon as possible, but they
195 * should not be able to lock up the box.
196 */
197 #define MAX_SOFTIRQ_TIME msecs_to_jiffies(2)
198 #define MAX_SOFTIRQ_RESTART 10
199
200 #ifdef CONFIG_TRACE_IRQFLAGS
201 /*
202 * When we run softirqs from irq_exit() and thus on the hardirq stack we need
203 * to keep the lockdep irq context tracking as tight as possible in order to
204 * not miss-qualify lock contexts and miss possible deadlocks.
205 */
206
207 static inline bool lockdep_softirq_start(void)
208 {
209 bool in_hardirq = false;
210
211 if (trace_hardirq_context(current)) {
212 in_hardirq = true;
213 trace_hardirq_exit();
214 }
215
216 lockdep_softirq_enter();
217
218 return in_hardirq;
219 }
220
221 static inline void lockdep_softirq_end(bool in_hardirq)
222 {
223 lockdep_softirq_exit();
224
225 if (in_hardirq)
226 trace_hardirq_enter();
227 }
228 #else
229 static inline bool lockdep_softirq_start(void) { return false; }
230 static inline void lockdep_softirq_end(bool in_hardirq) { }
231 #endif
232
233 asmlinkage __visible void __softirq_entry __do_softirq(void)
234 {
235 unsigned long end = jiffies + MAX_SOFTIRQ_TIME;
236 unsigned long old_flags = current->flags;
237 int max_restart = MAX_SOFTIRQ_RESTART;
238 struct softirq_action *h;
239 bool in_hardirq;
240 __u32 pending;
241 int softirq_bit;
242
243 /*
244 * Mask out PF_MEMALLOC s current task context is borrowed for the
245 * softirq. A softirq handled such as network RX might set PF_MEMALLOC
246 * again if the socket is related to swap
247 */
248 current->flags &= ~PF_MEMALLOC;
249
250 pending = local_softirq_pending();
251 account_irq_enter_time(current);
252
253 __local_bh_disable_ip(_RET_IP_, SOFTIRQ_OFFSET);
254 in_hardirq = lockdep_softirq_start();
255
256 restart:
257 /* Reset the pending bitmask before enabling irqs */
258 set_softirq_pending(0);
259
260 local_irq_enable();
261
262 h = softirq_vec;
263
264 while ((softirq_bit = ffs(pending))) {
265 unsigned int vec_nr;
266 int prev_count;
267
268 h += softirq_bit - 1;
269
270 vec_nr = h - softirq_vec;
271 prev_count = preempt_count();
272
273 kstat_incr_softirqs_this_cpu(vec_nr);
274
275 trace_softirq_entry(vec_nr);
276 exynos_ss_irq(ESS_FLAG_SOFTIRQ, h->action, irqs_disabled(), ESS_FLAG_IN);
277 sl_softirq_entry(softirq_to_name[vec_nr], h->action);
278 h->action(h);
279 sl_softirq_exit();
280 exynos_ss_irq(ESS_FLAG_SOFTIRQ, h->action, irqs_disabled(), ESS_FLAG_OUT);
281 trace_softirq_exit(vec_nr);
282 if (unlikely(prev_count != preempt_count())) {
283 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
284 vec_nr, softirq_to_name[vec_nr], h->action,
285 prev_count, preempt_count());
286 preempt_count_set(prev_count);
287 }
288 h++;
289 pending >>= softirq_bit;
290 }
291
292 rcu_bh_qs();
293 local_irq_disable();
294
295 pending = local_softirq_pending();
296 if (pending) {
297 if (time_before(jiffies, end) && !need_resched() &&
298 --max_restart)
299 goto restart;
300
301 wakeup_softirqd();
302 }
303
304 lockdep_softirq_end(in_hardirq);
305 account_irq_exit_time(current);
306 __local_bh_enable(SOFTIRQ_OFFSET);
307 WARN_ON_ONCE(in_interrupt());
308 tsk_restore_flags(current, old_flags, PF_MEMALLOC);
309 }
310
311 asmlinkage __visible void do_softirq(void)
312 {
313 __u32 pending;
314 unsigned long flags;
315
316 if (in_interrupt())
317 return;
318
319 local_irq_save(flags);
320
321 pending = local_softirq_pending();
322
323 if (pending)
324 do_softirq_own_stack();
325
326 local_irq_restore(flags);
327 }
328
329 /*
330 * Enter an interrupt context.
331 */
332 void irq_enter(void)
333 {
334 rcu_irq_enter();
335 if (is_idle_task(current) && !in_interrupt()) {
336 /*
337 * Prevent raise_softirq from needlessly waking up ksoftirqd
338 * here, as softirq will be serviced on return from interrupt.
339 */
340 local_bh_disable();
341 tick_irq_enter();
342 _local_bh_enable();
343 }
344
345 __irq_enter();
346 }
347
348 static inline void invoke_softirq(void)
349 {
350 if (!force_irqthreads) {
351 #ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK
352 /*
353 * We can safely execute softirq on the current stack if
354 * it is the irq stack, because it should be near empty
355 * at this stage.
356 */
357 __do_softirq();
358 #else
359 /*
360 * Otherwise, irq_exit() is called on the task stack that can
361 * be potentially deep already. So call softirq in its own stack
362 * to prevent from any overrun.
363 */
364 do_softirq_own_stack();
365 #endif
366 } else {
367 wakeup_softirqd();
368 }
369 }
370
371 static inline void tick_irq_exit(void)
372 {
373 #ifdef CONFIG_NO_HZ_COMMON
374 int cpu = smp_processor_id();
375
376 /* Make sure that timer wheel updates are propagated */
377 if ((idle_cpu(cpu) && !need_resched()) || tick_nohz_full_cpu(cpu)) {
378 if (!in_interrupt())
379 tick_nohz_irq_exit();
380 }
381 #endif
382 }
383
384 /*
385 * Exit an interrupt context. Process softirqs if needed and possible:
386 */
387 void irq_exit(void)
388 {
389 #ifndef __ARCH_IRQ_EXIT_IRQS_DISABLED
390 local_irq_disable();
391 #else
392 WARN_ON_ONCE(!irqs_disabled());
393 #endif
394
395 account_irq_exit_time(current);
396 preempt_count_sub(HARDIRQ_OFFSET);
397 if (!in_interrupt() && local_softirq_pending())
398 invoke_softirq();
399
400 tick_irq_exit();
401 rcu_irq_exit();
402 trace_hardirq_exit(); /* must be last! */
403 }
404
405 /*
406 * This function must run with irqs disabled!
407 */
408 inline void raise_softirq_irqoff(unsigned int nr)
409 {
410 __raise_softirq_irqoff(nr);
411
412 /*
413 * If we're in an interrupt or softirq, we're done
414 * (this also catches softirq-disabled code). We will
415 * actually run the softirq once we return from
416 * the irq or softirq.
417 *
418 * Otherwise we wake up ksoftirqd to make sure we
419 * schedule the softirq soon.
420 */
421 if (!in_interrupt())
422 wakeup_softirqd();
423 }
424
425 void raise_softirq(unsigned int nr)
426 {
427 unsigned long flags;
428
429 local_irq_save(flags);
430 raise_softirq_irqoff(nr);
431 local_irq_restore(flags);
432 }
433
434 void __raise_softirq_irqoff(unsigned int nr)
435 {
436 trace_softirq_raise(nr);
437 or_softirq_pending(1UL << nr);
438 }
439
440 void open_softirq(int nr, void (*action)(struct softirq_action *))
441 {
442 softirq_vec[nr].action = action;
443 }
444
445 /*
446 * Tasklets
447 */
448 struct tasklet_head {
449 struct tasklet_struct *head;
450 struct tasklet_struct **tail;
451 };
452
453 static DEFINE_PER_CPU(struct tasklet_head, tasklet_vec);
454 static DEFINE_PER_CPU(struct tasklet_head, tasklet_hi_vec);
455
456 void __tasklet_schedule(struct tasklet_struct *t)
457 {
458 unsigned long flags;
459
460 local_irq_save(flags);
461 t->next = NULL;
462 *__this_cpu_read(tasklet_vec.tail) = t;
463 __this_cpu_write(tasklet_vec.tail, &(t->next));
464 raise_softirq_irqoff(TASKLET_SOFTIRQ);
465 local_irq_restore(flags);
466 }
467 EXPORT_SYMBOL(__tasklet_schedule);
468
469 void __tasklet_hi_schedule(struct tasklet_struct *t)
470 {
471 unsigned long flags;
472
473 local_irq_save(flags);
474 t->next = NULL;
475 *__this_cpu_read(tasklet_hi_vec.tail) = t;
476 __this_cpu_write(tasklet_hi_vec.tail, &(t->next));
477 raise_softirq_irqoff(HI_SOFTIRQ);
478 local_irq_restore(flags);
479 }
480 EXPORT_SYMBOL(__tasklet_hi_schedule);
481
482 void __tasklet_hi_schedule_first(struct tasklet_struct *t)
483 {
484 BUG_ON(!irqs_disabled());
485
486 t->next = __this_cpu_read(tasklet_hi_vec.head);
487 __this_cpu_write(tasklet_hi_vec.head, t);
488 __raise_softirq_irqoff(HI_SOFTIRQ);
489 }
490 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
491
492 static void tasklet_action(struct softirq_action *a)
493 {
494 struct tasklet_struct *list;
495
496 local_irq_disable();
497 list = __this_cpu_read(tasklet_vec.head);
498 __this_cpu_write(tasklet_vec.head, NULL);
499 __this_cpu_write(tasklet_vec.tail, this_cpu_ptr(&tasklet_vec.head));
500 local_irq_enable();
501
502 while (list) {
503 struct tasklet_struct *t = list;
504
505 list = list->next;
506
507 if (tasklet_trylock(t)) {
508 if (!atomic_read(&t->count)) {
509 if (!test_and_clear_bit(TASKLET_STATE_SCHED,
510 &t->state))
511 BUG();
512 exynos_ss_irq(ESS_FLAG_SOFTIRQ_TASKLET,
513 t->func, irqs_disabled(), ESS_FLAG_IN);
514 sl_softirq_entry(softirq_to_name[TASKLET_SOFTIRQ], t->func);
515 t->func(t->data);
516 sl_softirq_exit();
517 exynos_ss_irq(ESS_FLAG_SOFTIRQ_TASKLET,
518 t->func, irqs_disabled(), ESS_FLAG_OUT);
519 tasklet_unlock(t);
520 continue;
521 }
522 tasklet_unlock(t);
523 }
524
525 local_irq_disable();
526 t->next = NULL;
527 *__this_cpu_read(tasklet_vec.tail) = t;
528 __this_cpu_write(tasklet_vec.tail, &(t->next));
529 __raise_softirq_irqoff(TASKLET_SOFTIRQ);
530 local_irq_enable();
531 }
532 }
533
534 static void tasklet_hi_action(struct softirq_action *a)
535 {
536 struct tasklet_struct *list;
537
538 local_irq_disable();
539 list = __this_cpu_read(tasklet_hi_vec.head);
540 __this_cpu_write(tasklet_hi_vec.head, NULL);
541 __this_cpu_write(tasklet_hi_vec.tail, this_cpu_ptr(&tasklet_hi_vec.head));
542 local_irq_enable();
543
544 while (list) {
545 struct tasklet_struct *t = list;
546
547 list = list->next;
548
549 if (tasklet_trylock(t)) {
550 if (!atomic_read(&t->count)) {
551 if (!test_and_clear_bit(TASKLET_STATE_SCHED,
552 &t->state))
553 BUG();
554 exynos_ss_irq(ESS_FLAG_SOFTIRQ_HI_TASKLET,
555 t->func, irqs_disabled(), ESS_FLAG_IN);
556 sl_softirq_entry(softirq_to_name[HI_SOFTIRQ], t->func);
557 t->func(t->data);
558 sl_softirq_exit();
559 exynos_ss_irq(ESS_FLAG_SOFTIRQ_HI_TASKLET,
560 t->func, irqs_disabled(), ESS_FLAG_OUT);
561 tasklet_unlock(t);
562 continue;
563 }
564 tasklet_unlock(t);
565 }
566
567 local_irq_disable();
568 t->next = NULL;
569 *__this_cpu_read(tasklet_hi_vec.tail) = t;
570 __this_cpu_write(tasklet_hi_vec.tail, &(t->next));
571 __raise_softirq_irqoff(HI_SOFTIRQ);
572 local_irq_enable();
573 }
574 }
575
576 void tasklet_init(struct tasklet_struct *t,
577 void (*func)(unsigned long), unsigned long data)
578 {
579 t->next = NULL;
580 t->state = 0;
581 atomic_set(&t->count, 0);
582 t->func = func;
583 t->data = data;
584 }
585 EXPORT_SYMBOL(tasklet_init);
586
587 void tasklet_kill(struct tasklet_struct *t)
588 {
589 if (in_interrupt())
590 pr_notice("Attempt to kill tasklet from interrupt\n");
591
592 while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
593 do {
594 yield();
595 } while (test_bit(TASKLET_STATE_SCHED, &t->state));
596 }
597 tasklet_unlock_wait(t);
598 clear_bit(TASKLET_STATE_SCHED, &t->state);
599 }
600 EXPORT_SYMBOL(tasklet_kill);
601
602 /*
603 * tasklet_hrtimer
604 */
605
606 /*
607 * The trampoline is called when the hrtimer expires. It schedules a tasklet
608 * to run __tasklet_hrtimer_trampoline() which in turn will call the intended
609 * hrtimer callback, but from softirq context.
610 */
611 static enum hrtimer_restart __hrtimer_tasklet_trampoline(struct hrtimer *timer)
612 {
613 struct tasklet_hrtimer *ttimer =
614 container_of(timer, struct tasklet_hrtimer, timer);
615
616 tasklet_hi_schedule(&ttimer->tasklet);
617 return HRTIMER_NORESTART;
618 }
619
620 /*
621 * Helper function which calls the hrtimer callback from
622 * tasklet/softirq context
623 */
624 static void __tasklet_hrtimer_trampoline(unsigned long data)
625 {
626 struct tasklet_hrtimer *ttimer = (void *)data;
627 enum hrtimer_restart restart;
628
629 restart = ttimer->function(&ttimer->timer);
630 if (restart != HRTIMER_NORESTART)
631 hrtimer_restart(&ttimer->timer);
632 }
633
634 /**
635 * tasklet_hrtimer_init - Init a tasklet/hrtimer combo for softirq callbacks
636 * @ttimer: tasklet_hrtimer which is initialized
637 * @function: hrtimer callback function which gets called from softirq context
638 * @which_clock: clock id (CLOCK_MONOTONIC/CLOCK_REALTIME)
639 * @mode: hrtimer mode (HRTIMER_MODE_ABS/HRTIMER_MODE_REL)
640 */
641 void tasklet_hrtimer_init(struct tasklet_hrtimer *ttimer,
642 enum hrtimer_restart (*function)(struct hrtimer *),
643 clockid_t which_clock, enum hrtimer_mode mode)
644 {
645 hrtimer_init(&ttimer->timer, which_clock, mode);
646 ttimer->timer.function = __hrtimer_tasklet_trampoline;
647 tasklet_init(&ttimer->tasklet, __tasklet_hrtimer_trampoline,
648 (unsigned long)ttimer);
649 ttimer->function = function;
650 }
651 EXPORT_SYMBOL_GPL(tasklet_hrtimer_init);
652
653 void __init softirq_init(void)
654 {
655 int cpu;
656
657 for_each_possible_cpu(cpu) {
658 per_cpu(tasklet_vec, cpu).tail =
659 &per_cpu(tasklet_vec, cpu).head;
660 per_cpu(tasklet_hi_vec, cpu).tail =
661 &per_cpu(tasklet_hi_vec, cpu).head;
662 }
663
664 open_softirq(TASKLET_SOFTIRQ, tasklet_action);
665 open_softirq(HI_SOFTIRQ, tasklet_hi_action);
666 }
667
668 static int ksoftirqd_should_run(unsigned int cpu)
669 {
670 return local_softirq_pending();
671 }
672
673 static void run_ksoftirqd(unsigned int cpu)
674 {
675 local_irq_disable();
676 if (local_softirq_pending()) {
677 /*
678 * We can safely run softirq on inline stack, as we are not deep
679 * in the task stack here.
680 */
681 __do_softirq();
682 local_irq_enable();
683 cond_resched_rcu_qs();
684 return;
685 }
686 local_irq_enable();
687 }
688
689 #ifdef CONFIG_HOTPLUG_CPU
690 /*
691 * tasklet_kill_immediate is called to remove a tasklet which can already be
692 * scheduled for execution on @cpu.
693 *
694 * Unlike tasklet_kill, this function removes the tasklet
695 * _immediately_, even if the tasklet is in TASKLET_STATE_SCHED state.
696 *
697 * When this function is called, @cpu must be in the CPU_DEAD state.
698 */
699 void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu)
700 {
701 struct tasklet_struct **i;
702
703 BUG_ON(cpu_online(cpu));
704 BUG_ON(test_bit(TASKLET_STATE_RUN, &t->state));
705
706 if (!test_bit(TASKLET_STATE_SCHED, &t->state))
707 return;
708
709 /* CPU is dead, so no lock needed. */
710 for (i = &per_cpu(tasklet_vec, cpu).head; *i; i = &(*i)->next) {
711 if (*i == t) {
712 *i = t->next;
713 /* If this was the tail element, move the tail ptr */
714 if (*i == NULL)
715 per_cpu(tasklet_vec, cpu).tail = i;
716 return;
717 }
718 }
719 BUG();
720 }
721
722 static void takeover_tasklets(unsigned int cpu)
723 {
724 /* CPU is dead, so no lock needed. */
725 local_irq_disable();
726
727 /* Find end, append list for that CPU. */
728 if (&per_cpu(tasklet_vec, cpu).head != per_cpu(tasklet_vec, cpu).tail) {
729 *__this_cpu_read(tasklet_vec.tail) = per_cpu(tasklet_vec, cpu).head;
730 this_cpu_write(tasklet_vec.tail, per_cpu(tasklet_vec, cpu).tail);
731 per_cpu(tasklet_vec, cpu).head = NULL;
732 per_cpu(tasklet_vec, cpu).tail = &per_cpu(tasklet_vec, cpu).head;
733 }
734 raise_softirq_irqoff(TASKLET_SOFTIRQ);
735
736 if (&per_cpu(tasklet_hi_vec, cpu).head != per_cpu(tasklet_hi_vec, cpu).tail) {
737 *__this_cpu_read(tasklet_hi_vec.tail) = per_cpu(tasklet_hi_vec, cpu).head;
738 __this_cpu_write(tasklet_hi_vec.tail, per_cpu(tasklet_hi_vec, cpu).tail);
739 per_cpu(tasklet_hi_vec, cpu).head = NULL;
740 per_cpu(tasklet_hi_vec, cpu).tail = &per_cpu(tasklet_hi_vec, cpu).head;
741 }
742 raise_softirq_irqoff(HI_SOFTIRQ);
743
744 local_irq_enable();
745 }
746 #endif /* CONFIG_HOTPLUG_CPU */
747
748 static int cpu_callback(struct notifier_block *nfb, unsigned long action,
749 void *hcpu)
750 {
751 switch (action) {
752 #ifdef CONFIG_HOTPLUG_CPU
753 case CPU_DEAD:
754 case CPU_DEAD_FROZEN:
755 takeover_tasklets((unsigned long)hcpu);
756 break;
757 #endif /* CONFIG_HOTPLUG_CPU */
758 }
759 return NOTIFY_OK;
760 }
761
762 static struct notifier_block cpu_nfb = {
763 .notifier_call = cpu_callback
764 };
765
766 static struct smp_hotplug_thread softirq_threads = {
767 .store = &ksoftirqd,
768 .thread_should_run = ksoftirqd_should_run,
769 .thread_fn = run_ksoftirqd,
770 .thread_comm = "ksoftirqd/%u",
771 };
772
773 static __init int spawn_ksoftirqd(void)
774 {
775 register_cpu_notifier(&cpu_nfb);
776
777 BUG_ON(smpboot_register_percpu_thread(&softirq_threads));
778
779 return 0;
780 }
781 early_initcall(spawn_ksoftirqd);
782
783 /*
784 * [ These __weak aliases are kept in a separate compilation unit, so that
785 * GCC does not inline them incorrectly. ]
786 */
787
788 int __init __weak early_irq_init(void)
789 {
790 return 0;
791 }
792
793 int __init __weak arch_probe_nr_irqs(void)
794 {
795 return NR_IRQS_LEGACY;
796 }
797
798 int __init __weak arch_early_irq_init(void)
799 {
800 return 0;
801 }
802
803 unsigned int __weak arch_dynirq_lower_bound(unsigned int from)
804 {
805 return from;
806 }