Skip to contentSkip to conversation

softirq performance fixes, cleanups, 2.4.10.

PATCH Oleg Nesterov 3 participants 3 messages Sep 27, 2001 – Sep 28, 2001

lore
Share & tools
lore
#0 lore raw

Hello.

I am trying to understand the basics of softirq handling.

It seems to me that ksoftirqd()'s loop can be cleanuped a bit with following (untested) patch on top of 2.4.10-softirq-A7.

It also removes the 'mask' variable in do_softirq().

Oleg

kernel/softirq.c renamed from kernel/softirq.c.orig +7 -12
@@ -85,7 +85,7 @@
 {
 	int max_restart = MAX_SOFTIRQ_RESTART;
 	int cpu = smp_processor_id();
-	__u32 pending, mask;
+	__u32 pending;
 	long flags;
 
 	if (in_interrupt())
@@ -98,7 +98,6 @@
 	if (pending) {
 		struct softirq_action *h;
 
-		mask = ~pending;
 		local_bh_disable();
 restart:
 		/* Reset the pending bitmask before enabling irqs */
@@ -381,26 +380,22 @@
 #endif
 
 	current->nice = 19;
-	schedule();
-	__set_current_state(TASK_INTERRUPTIBLE);
 	ksoftirqd_task(cpu) = current;
 
 	for (;;) {
-back:
+		schedule();
+		__set_current_state(TASK_INTERRUPTIBLE);
+
 		do {
 			do_softirq();
 			if (current->need_resched)
 				goto preempt;
 		} while (softirq_pending(cpu));
-		schedule();
-		__set_current_state(TASK_INTERRUPTIBLE);
-	}
 
+		continue;
 preempt:
-	__set_current_state(TASK_RUNNING);
-	schedule();
-	__set_current_state(TASK_INTERRUPTIBLE);
-	goto back;
+		__set_current_state(TASK_RUNNING);
+	}
 }
 
 static __init int spawn_ksoftirqd(void)
#1 lore raw
Quoted 12 lines · Oleg Nesterov
kernel/softirq.c renamed from kernel/softirq.c.orig +1 -1
@@ -85,7 +85,7 @@
 {
 	int max_restart = MAX_SOFTIRQ_RESTART;
 	int cpu = smp_processor_id();
-	__u32 pending, mask;
+	__u32 pending;
 	long flags;
 
 	if (in_interrupt())

kernel/softirq.c line 103

Quoted 7 lines
kernel/softirq.c renamed from kernel/softirq.c.orig +0 -1
@@ -98,7 +98,6 @@
 	if (pending) {
 		struct softirq_action *h;
 
-		mask = ~pending;
 		local_bh_disable();
 restart:
 		/* Reset the pending bitmask before enabling irqs */

correct.

kernel/softirq.c line 385

Quoted 6 lines
kernel/softirq.c renamed from kernel/softirq.c.orig +0 -2
@@ -381,26 +380,22 @@
 #endif
 
 	current->nice = 19;
-	schedule();
-	__set_current_state(TASK_INTERRUPTIBLE);

buggy (check cpus_allowed).

Quoted 13 lines
kernel/softirq.c renamed from kernel/softirq.c.orig +3 -4
 	for (;;) {
-back:
+		schedule();
+		__set_current_state(TASK_INTERRUPTIBLE);
+
 		do {
 			do_softirq();
 			if (current->need_resched)
 				goto preempt;
 		} while (softirq_pending(cpu));
-		schedule();
-		__set_current_state(TASK_INTERRUPTIBLE);
-	}

kernel/softirq.c line 399

Quoted 10 lines
kernel/softirq.c renamed from kernel/softirq.c.orig +3 -4
 
+		continue;
 preempt:
-	__set_current_state(TASK_RUNNING);
-	schedule();
-	__set_current_state(TASK_INTERRUPTIBLE);
-	goto back;
+		__set_current_state(TASK_RUNNING);
+	}
 }

you dropped Ingo's optimization (but you resurrected the strictier /proc statistics).

Andrea

#2 lore raw
In reply to Oleg Nesterov
Quoted 4 lines · Oleg Nesterov

I am trying to understand the basics of softirq handling.

It seems to me that ksoftirqd()'s loop can be cleanuped a bit with following (untested) patch on top of 2.4.10-softirq-A7.

thanks - the patch looks mostly correct.

Quoted 1 line

It also removes the 'mask' variable in do_softirq().

(right, applied.)

Review

Quoted 2 lines
(quoted diff) +0 -2
-	schedule();
-	__set_current_state(TASK_INTERRUPTIBLE);

we need a single schedule to migrate the CPU to the right CPU. Btw, it's not a big offense to run on the wrong CPU: do_softirq() will run correctly. But there wont be a ksoftirqd exeuting on the 'right' CPU (for this short amount of time until it schedules once), and we might miss a single instance of softirq processing. So it's cleaner to do a schedule() that guarantees that we migrate to the target CPU.

kernel/softirq.c line 398

Quoted 2 lines
kernel/softirq.c renamed from kernel/softirq.c.orig +2 -0
+		__set_current_state(TASK_RUNNING);
+	}

well, this basically reverts it to the original code and removes the optimization - but i dont have any strong feelings in either way. I think Andrea is right and it's more correct to set it TASK_RUNNING, for task-statistics reasons. Reverted it to the old code.

and in fact while doing that i found another bug in the old code:
TASK_INTERRUPTIBLE was set in a non-IRQ-atomic way, so theoretically it could be possible that the compiler reorders the setting of TASK_INTERRUPTIBLE and the test for softirq_pending(), and if an IRQ gets inbetween the we could miss processing softirq for 1/HZ again. Added an optimization barrier(). (SMP-consistency is not needed, since we are per-CPU.)

Ingo