Skip to contentSkip to conversation

fix TASK_STOPPED vs TASK_NONINTERACTIVE interaction

PATCH In review Oleg Nesterov 4 participants 5 messages Sep 29, 2005 – Oct 3, 2005 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix TASK_STOPPED vs TASK_NONINTERACTIVE interaction

do_signal_stop:

	for_each_thread(t) {
		if (t->state < TASK_STOPPED)
			++sig->group_stop_count;
	}

However, TASK_NONINTERACTIVE > TASK_STOPPED, so this loop will not count TASK_INTERRUPTIBLE | TASK_NONINTERACTIVE threads.

See also wait_task_stopped(), which checks ->state > TASK_STOPPED.

include/linux/sched.h renamed from include/linux/sched.h~6_NONINT +5 -5
@@ -110,11 +110,11 @@ extern unsigned long nr_iowait(void);
 #define TASK_RUNNING		0
 #define TASK_INTERRUPTIBLE	1
 #define TASK_UNINTERRUPTIBLE	2
-#define TASK_STOPPED		4
-#define TASK_TRACED		8
-#define EXIT_ZOMBIE		16
-#define EXIT_DEAD		32
-#define TASK_NONINTERACTIVE	64
+#define TASK_NONINTERACTIVE	4
+#define TASK_STOPPED		8
+#define TASK_TRACED		16
+#define EXIT_ZOMBIE		32
+#define EXIT_DEAD		64
 
 #define __set_task_state(tsk, state_value)		\
 	do { (tsk)->state = (state_value); } while (0)
#1 lore raw
Quoted 10 lines · Oleg Nesterov

do_signal_stop:

	for_each_thread(t) {
		if (t->state < TASK_STOPPED)
			++sig->group_stop_count;
	}

However, TASK_NONINTERACTIVE > TASK_STOPPED, so this loop will not count TASK_INTERRUPTIBLE | TASK_NONINTERACTIVE threads.

Ok, I think your patch is correct (we really do try to keep an order to those task flags), but the _real_ issue is that the comparisons are bogus.

Using ">" for task states is wrong. It's a bitmask, and if you want to check multiple states, then we should just do so with

	if (t->state & (TASK_xxx | TASK_yyy | ...))

Oh, well. The inequality comparisons are shorter, and historical, so I guess it's debatable whether we should remove them all.

Linus

#2 lore raw
Quoted 7 lines · Linus Torvalds
Quoted 3 lines · Oleg Nesterov

[...]
However, TASK_NONINTERACTIVE > TASK_STOPPED, so this loop will not count TASK_INTERRUPTIBLE | TASK_NONINTERACTIVE threads.

Quoted 6 lines

[...]
Using ">" for task states is wrong. It's a bitmask, and if you want to check multiple states, then we should just do so with

	if (t->state & (TASK_xxx | TASK_yyy | ...))

Oh, well. The inequality comparisons are shorter, and historical, so I guess it's debatable whether we should remove them all.

I did a quick grep through 2.6.14-rc2 to see how many "them all" were, and the only two places I could find, where a inequality operator was being used on a task state, were this one in kernel/signal.c and another in kernel/exit.c:

./kernel/exit.c:1194: unlikely(p->state > TASK_STOPPED)

So maybe it is not so bad to just change these to a bit mask and disallow inequality comparisons in the future, if you guys feel that is the way to go...

Signature · 5 lines
Paulo Marques - www.grupopie.com

The rule is perfect: in all matters of opinion our
adversaries are insane.
Mark Twain
#3 lore raw
In reply to Linus Torvalds
Quoted 17 lines · Linus Torvalds
Quoted 10 lines · Oleg Nesterov

do_signal_stop:

      for_each_thread(t) {
              if (t->state < TASK_STOPPED)
                      ++sig->group_stop_count;
      }

However, TASK_NONINTERACTIVE > TASK_STOPPED, so this loop will not count TASK_INTERRUPTIBLE | TASK_NONINTERACTIVE threads.

Ok, I think your patch is correct (we really do try to keep an order to those task flags), but the _real_ issue is that the comparisons are bogus.

Quoted 6 lines

Using ">" for task states is wrong. It's a bitmask, and if you want to check multiple states, then we should just do so with

        if (t->state & (TASK_xxx | TASK_yyy | ...))

Oh, well. The inequality comparisons are shorter, and historical, so I

The inequality comparisons are faster or faster on some CPU. We should use it if we can keep the order IMHO.

Quoted 3 lines

guess it's debatable whether we should remove them all.

Linus

--
Coywolf Qi Hunt
http://sosdg.org/~coywolf/

#4 lore raw
Quoted 3 lines · Coywolf Qi Hunt

The inequality comparisons are faster or faster on some CPU. We should use it if we can keep the order IMHO.

Which CPU are you talking about? Inequality is almost never faster than a logical op.

Any CPU I can think of has a "and + compare against zero". x86 calls it "test", although a regular "and" will do it too. ppc has "andi.". alpha comparisons are against registers being zero or not, so again it's an "and".

And there are very few ALU's that don't do logicals (they're much simpler than an adder), although I seem to remember that the P4 was odd in that respect (with the second ALU being limited to some strange subcases).

So I don't think that ends up being a concern in real life.

Linus