hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/kernel/irq_work.c
....@@ -18,37 +18,11 @@
1818 #include <linux/cpu.h>
1919 #include <linux/notifier.h>
2020 #include <linux/smp.h>
21
-#include <linux/smpboot.h>
22
-#include <linux/interrupt.h>
2321 #include <asm/processor.h>
2422
2523
2624 static DEFINE_PER_CPU(struct llist_head, raised_list);
2725 static DEFINE_PER_CPU(struct llist_head, lazy_list);
28
-static DEFINE_PER_CPU(struct task_struct *, irq_workd);
29
-
30
-static void wake_irq_workd(void)
31
-{
32
- struct task_struct *tsk = __this_cpu_read(irq_workd);
33
-
34
- if (!llist_empty(this_cpu_ptr(&lazy_list)) && tsk)
35
- wake_up_process(tsk);
36
-}
37
-
38
-#ifdef CONFIG_SMP
39
-static void irq_work_wake(struct irq_work *entry)
40
-{
41
- wake_irq_workd();
42
-}
43
-
44
-static DEFINE_PER_CPU(struct irq_work, irq_work_wakeup) =
45
- IRQ_WORK_INIT_HARD(irq_work_wake);
46
-#endif
47
-
48
-static int irq_workd_should_run(unsigned int cpu)
49
-{
50
- return !llist_empty(this_cpu_ptr(&lazy_list));
51
-}
5226
5327 /*
5428 * Claim the entry so that no one else will poke at it.
....@@ -78,29 +52,15 @@
7852 /* Enqueue on current CPU, work must already be claimed and preempt disabled */
7953 static void __irq_work_queue_local(struct irq_work *work)
8054 {
81
- struct llist_head *list;
82
- bool rt_lazy_work = false;
83
- bool lazy_work = false;
84
- int work_flags;
85
-
86
- work_flags = atomic_read(&work->flags);
87
- if (work_flags & IRQ_WORK_LAZY)
88
- lazy_work = true;
89
- else if (IS_ENABLED(CONFIG_PREEMPT_RT) &&
90
- !(work_flags & IRQ_WORK_HARD_IRQ))
91
- rt_lazy_work = true;
92
-
93
- if (lazy_work || rt_lazy_work)
94
- list = this_cpu_ptr(&lazy_list);
95
- else
96
- list = this_cpu_ptr(&raised_list);
97
-
98
- if (!llist_add(&work->llnode, list))
99
- return;
100
-
10155 /* If the work is "lazy", handle it from next tick if any */
102
- if (!lazy_work || tick_nohz_tick_stopped())
103
- arch_irq_work_raise();
56
+ if (atomic_read(&work->flags) & IRQ_WORK_LAZY) {
57
+ if (llist_add(&work->llnode, this_cpu_ptr(&lazy_list)) &&
58
+ tick_nohz_tick_stopped())
59
+ arch_irq_work_raise();
60
+ } else {
61
+ if (llist_add(&work->llnode, this_cpu_ptr(&raised_list)))
62
+ arch_irq_work_raise();
63
+ }
10464 }
10565
10666 /* Enqueue the irq work @work on the current CPU */
....@@ -142,28 +102,10 @@
142102 if (cpu != smp_processor_id()) {
143103 /* Arch remote IPI send/receive backend aren't NMI safe */
144104 WARN_ON_ONCE(in_nmi());
145
-
146
- /*
147
- * On PREEMPT_RT the items which are not marked as
148
- * IRQ_WORK_HARD_IRQ are added to the lazy list and a HARD work
149
- * item is used on the remote CPU to wake the thread.
150
- */
151
- if (IS_ENABLED(CONFIG_PREEMPT_RT) &&
152
- !(atomic_read(&work->flags) & IRQ_WORK_HARD_IRQ)) {
153
-
154
- if (!llist_add(&work->llnode, &per_cpu(lazy_list, cpu)))
155
- goto out;
156
-
157
- work = &per_cpu(irq_work_wakeup, cpu);
158
- if (!irq_work_claim(work))
159
- goto out;
160
- }
161
-
162105 __smp_call_single_queue(cpu, &work->llnode);
163106 } else {
164107 __irq_work_queue_local(work);
165108 }
166
-out:
167109 preempt_enable();
168110
169111 return true;
....@@ -178,8 +120,9 @@
178120 raised = this_cpu_ptr(&raised_list);
179121 lazy = this_cpu_ptr(&lazy_list);
180122
181
- if (llist_empty(raised) && llist_empty(lazy))
182
- return false;
123
+ if (llist_empty(raised) || arch_irq_work_has_interrupt())
124
+ if (llist_empty(lazy))
125
+ return false;
183126
184127 /* All work should have been flushed before going offline */
185128 WARN_ON_ONCE(cpu_is_offline(smp_processor_id()));
....@@ -210,10 +153,6 @@
210153 */
211154 flags &= ~IRQ_WORK_PENDING;
212155 (void)atomic_cmpxchg(&work->flags, flags, flags & ~IRQ_WORK_BUSY);
213
-
214
- if ((IS_ENABLED(CONFIG_PREEMPT_RT) && !irq_work_is_hard(work)) ||
215
- !arch_irq_work_has_interrupt())
216
- rcuwait_wake_up(&work->irqwait);
217156 }
218157
219158 static void irq_work_run_list(struct llist_head *list)
....@@ -221,12 +160,7 @@
221160 struct irq_work *work, *tmp;
222161 struct llist_node *llnode;
223162
224
- /*
225
- * On PREEMPT_RT IRQ-work which is not marked as HARD will be processed
226
- * in a per-CPU thread in preemptible context. Only the items which are
227
- * marked as IRQ_WORK_HARD_IRQ will be processed in hardirq context.
228
- */
229
- BUG_ON(!irqs_disabled() && !IS_ENABLED(CONFIG_PREEMPT_RT));
163
+ BUG_ON(!irqs_disabled());
230164
231165 if (llist_empty(list))
232166 return;
....@@ -243,10 +177,7 @@
243177 void irq_work_run(void)
244178 {
245179 irq_work_run_list(this_cpu_ptr(&raised_list));
246
- if (!IS_ENABLED(CONFIG_PREEMPT_RT))
247
- irq_work_run_list(this_cpu_ptr(&lazy_list));
248
- else
249
- wake_irq_workd();
180
+ irq_work_run_list(this_cpu_ptr(&lazy_list));
250181 }
251182 EXPORT_SYMBOL_GPL(irq_work_run);
252183
....@@ -256,11 +187,7 @@
256187
257188 if (!llist_empty(raised) && !arch_irq_work_has_interrupt())
258189 irq_work_run_list(raised);
259
-
260
- if (!IS_ENABLED(CONFIG_PREEMPT_RT))
261
- irq_work_run_list(this_cpu_ptr(&lazy_list));
262
- else
263
- wake_irq_workd();
190
+ irq_work_run_list(this_cpu_ptr(&lazy_list));
264191 }
265192
266193 /*
....@@ -270,42 +197,8 @@
270197 void irq_work_sync(struct irq_work *work)
271198 {
272199 lockdep_assert_irqs_enabled();
273
- might_sleep();
274
-
275
- if ((IS_ENABLED(CONFIG_PREEMPT_RT) && !irq_work_is_hard(work)) ||
276
- !arch_irq_work_has_interrupt()) {
277
- rcuwait_wait_event(&work->irqwait, !irq_work_is_busy(work),
278
- TASK_UNINTERRUPTIBLE);
279
- return;
280
- }
281200
282201 while (atomic_read(&work->flags) & IRQ_WORK_BUSY)
283202 cpu_relax();
284203 }
285204 EXPORT_SYMBOL_GPL(irq_work_sync);
286
-
287
-static void run_irq_workd(unsigned int cpu)
288
-{
289
- irq_work_run_list(this_cpu_ptr(&lazy_list));
290
-}
291
-
292
-static void irq_workd_setup(unsigned int cpu)
293
-{
294
- sched_set_fifo_low(current);
295
-}
296
-
297
-static struct smp_hotplug_thread irqwork_threads = {
298
- .store = &irq_workd,
299
- .setup = irq_workd_setup,
300
- .thread_should_run = irq_workd_should_run,
301
- .thread_fn = run_irq_workd,
302
- .thread_comm = "irq_work/%u",
303
-};
304
-
305
-static __init int irq_work_init_threads(void)
306
-{
307
- if (IS_ENABLED(CONFIG_PREEMPT_RT))
308
- BUG_ON(smpboot_register_percpu_thread(&irqwork_threads));
309
- return 0;
310
-}
311
-early_initcall(irq_work_init_threads);