Skip to content

Commit 2e702b9

Browse files
JoePerchestorvalds
authored andcommitted
softirq: use ffs() in __do_softirq()
Possible speed improvement of __do_softirq() by using ffs() instead of using a while loop with an & 1 test then single bit shift. Signed-off-by: Joe Perches <joe@perches.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a19428e commit 2e702b9

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

‎kernel/softirq.c‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ asmlinkage void __do_softirq(void)
229229
struct softirq_action *h;
230230
bool in_hardirq;
231231
__u32 pending;
232+
int softirq_bit;
232233
int cpu;
233234

234235
/*
@@ -253,30 +254,30 @@ asmlinkage void __do_softirq(void)
253254

254255
h = softirq_vec;
255256

256-
do {
257-
if (pending & 1) {
258-
unsigned int vec_nr = h - softirq_vec;
259-
int prev_count = preempt_count();
260-
261-
kstat_incr_softirqs_this_cpu(vec_nr);
262-
263-
trace_softirq_entry(vec_nr);
264-
h->action(h);
265-
trace_softirq_exit(vec_nr);
266-
if (unlikely(prev_count != preempt_count())) {
267-
printk(KERN_ERR "huh, entered softirq %u %s %p"
268-
"with preempt_count %08x,"
269-
" exited with %08x?\n", vec_nr,
270-
softirq_to_name[vec_nr], h->action,
271-
prev_count, preempt_count());
272-
preempt_count_set(prev_count);
273-
}
257+
while ((softirq_bit = ffs(pending))) {
258+
unsigned int vec_nr;
259+
int prev_count;
260+
261+
h += softirq_bit - 1;
262+
263+
vec_nr = h - softirq_vec;
264+
prev_count = preempt_count();
274265

275-
rcu_bh_qs(cpu);
266+
kstat_incr_softirqs_this_cpu(vec_nr);
267+
268+
trace_softirq_entry(vec_nr);
269+
h->action(h);
270+
trace_softirq_exit(vec_nr);
271+
if (unlikely(prev_count != preempt_count())) {
272+
printk(KERN_ERR "huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
273+
vec_nr, softirq_to_name[vec_nr], h->action,
274+
prev_count, preempt_count());
275+
preempt_count_set(prev_count);
276276
}
277+
rcu_bh_qs(cpu);
277278
h++;
278-
pending >>= 1;
279-
} while (pending);
279+
pending >>= softirq_bit;
280+
}
280281

281282
local_irq_disable();
282283

0 commit comments

Comments
 (0)