I3 sched tweaks...
Subsystems (3)
PATCH 1/1 I3 sched tweaks...
This one actually compiles(!!):
1) Comment about RT event id removed (no longer relevent).
2) Order by address, delete rq_cpu().
3) lock_task_rq returns the rq, rather than assigning it, for clarity.
4) scheduler_tick needs no args (p is always equal to current).
5) Unused max_rq_len() function deleted.
include/linux/sched.h +1 -1
@@ -146,7 +146,7 @@extern void update_process_times (int user);extern void update_one_process (task_t *p,unsigned long user,unsigned long system,int cpu); -extern void scheduler_tick (task_t *p); +extern void scheduler_tick (void );#define MAX_SCHEDULE_TIMEOUT LONG_MAXextern signed long FASTCALL (schedule_timeout (signed long timeout));
kernel/fork.c +1 -1
@@ -704,7 +704,7 @@* runqueue lock is not a problem. */ current->time_slice =1 ; -scheduler_tick (current); +scheduler_tick (); } p->sleep_timestamp = jiffies;__restore_flags (flags);
kernel/sched.c +22 -35
132 lines not on this page · raw message
kernel/timer.c +1 -1
@@ -594,7 +594,7 @@if (local_bh_count (cpu) ||local_irq_count (cpu) >1 ) kstat.per_cpu_system[cpu] += system; } -scheduler_tick (p); +scheduler_tick (); }/*
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Ingo Molnar
maintainerQuoted 3 lines · Rusty Russell
1) Comment about RT event id removed (no longer relevent).
2) Order by address, deleterq_cpu().
3)lock_task_rqreturns the rq, rather than assigning it, for clarity.
ok.
Quoted 1 line
4)
scheduler_tickneeds no args (p is always equal to current).
i have not taken this part. We have 'current' calculated in update_process_times(), so why not pass it along to the scheduler_tick() function?
Quoted 1 line
5) Unused
max_rq_len()function deleted.
ok.
Ingo
Ingo Molnar
maintainerQuoted 2 lines
3)
lock_task_rqreturns the rq, rather than assigning it, for clarity.
i've made it an inline function instead of a macro.
Ingo
In message <Pine.LNX.4.33.0201160412180.24929-100000@devserv.devel.redhat.com> you write:
Quoted 5 lines
Quoted 1 line
4)
scheduler_tickneeds no args (p is always equal to current).i have not taken this part. We have 'current' calculated in
update_process_times(), so why not pass it along to thescheduler_tick()function?
Because it's redundant. It's *always* p == current (and the code assumes this!), but I had to grep the callers to find out.
Moreover, the function doesn't make *sense* if p != current...
Quoted 3 lines
Quoted 1 line
3)
lock_task_rqreturns the rq, rather than assigning it, for clarity.i've made it an inline function instead of a macro.
I thought of that, but assumed you had a good reason for making it a macro in the first place...
Thanks!
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Quoted 8 lines · Rusty Russell
Quoted 5 lines
Quoted 1 line
4)
scheduler_tickneeds no args (p is always equal to current).i have not taken this part. We have 'current' calculated in
update_process_times(), so why not pass it along to thescheduler_tick()function?Because it's redundant. It's *always* p == current (and the code assumes this!), but I had to grep the callers to find out.
we pass pointers across functions regularly, even if the pointer could be calculated within the function. We do this in the timer code too. It's slightly cheaper to pass an already existing (calculated) 'current' pointer over to another function, instead of calculating it once more in that function. This will be especially true once we make 'current' a tiny bit more expensive (Alan's kernel stack coloring rewrite will do that i think, it will be one more instruction to get 'current'.)
Quoted 1 line
Moreover, the function doesn't make *sense* if p != current...
yes - would it be perhaps cleaner then to name the variable 'this_task' or something like that?
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
3)
lock_task_rqreturns the rq, rather than assigning it, for clarity.i've made it an inline function instead of a macro.
I thought of that, but assumed you had a good reason for making it a macro in the first place...
no good reason, the macro started out being simple, but then grew in size significantly, as the sophistication and correctness of the O(1) scheduler improved ;-)
Ingo
Quoted 7 lines · Ingo Molnar
we pass pointers across functions regularly, even if the pointer could be calculated within the function. We do this in the timer code too. It's slightly cheaper to pass an already existing (calculated) 'current' pointer over to another function, instead of calculating it once more in that function. This will be especially true once we make 'current' a tiny bit more expensive (Alan's kernel stack coloring rewrite will do that i think, it will be one more instruction to get 'current'.)
Maybe we should benchmark it? It is very easy to calculate current.
Certainly I see the benefit if we start coloring the pointer (it adds 2 instructions I believe) but let's make sure it is worth passing another 32-bit argument. It could very well be, schedule_tick is called enough...
Quoted 4 lines
Quoted 1 line
Moreover, the function doesn't make *sense* if p != current...
yes - would it be perhaps cleaner then to name the variable '
this_task' or something like that?
Yes, good idea.
Robert Love
Quoted 10 lines · Robert Love
Quoted 7 lines · Ingo Molnar
we pass pointers across functions regularly, even if the pointer could be calculated within the function. We do this in the timer code too. It's slightly cheaper to pass an already existing (calculated) 'current' pointer over to another function, instead of calculating it once more in that function. This will be especially true once we make 'current' a tiny bit more expensive (Alan's kernel stack coloring rewrite will do that i think, it will be one more instruction to get 'current'.)
Quoted 6 lines
Maybe we should benchmark it? It is very easy to calculate current.
Certainly I see the benefit if we start coloring the pointer (it adds 2 instructions I believe) but let's make sure it is worth passing another 32-bit argument. It could very well be,
schedule_tickis called enough...
Don't forget that, in non-x86 land, current tends to be just kept in a register. No computations required. Certainly passing it around on, e.g. mips is a clear loss.
-Justin
Quoted 3 lines · Justin Carlson
Don't forget that, in non-x86 land, current tends to be just kept in a register. No computations required. Certainly passing it around on, e.g. mips is a clear loss.
current is stored in a register (esp) in x86, too. This is why I cautioned that looking up current was cheap -- I think every sane arch stores current in some fast access way. That's why it is a macro -- it is assembly code to quickly snag the address.
So is passing current still worth it?
Robert Love
Quoted 1 line · Robert Love
current is stored in a register (esp) in x86, too. [...]
it's stored in a register, but then it also needs to do some more work to get at the true pointer. The typical way to load 'current' on x86 into %eax:
b8 00 e0 ff ff mov $0xffffe000,%eax
21 e0 and %esp,%eax7 bytes icache footprint.
while the cost of moving an already calculated 'current' pointer to the stack is:
50 push %eax
1 byte instruction.
and in addition, consider that for larger functions, the 'current' value will be moved to a gcc spill register anyway, it will end up looking like this:
b8 00 e0 ff ff mov $0xffffe000,%edi
21 e0 and %esp,%edi
89 7c 24 14 mov %edi,0x14(%esp,1)while in the function-call variant the pointer is on the stack already, so accessing it is easy:
89 7c 24 14 mov 0x10(%esp,1), %eax
so on x86, considering the sched_tick() case, it's slightly faster to pass the argument. But there isnt any big difference.
but add an instruction or two to the 'current' calculation method, and the icache footprint and actual overhead will be more clearly in favor of function calls.
i agree that on architectures where 'current' is stored in a register it's better to use 'current' explicitly.
Ingo
In article <1011216429.1083.95.camel@phantasy> you write:
| On Wed, 2002-01-16 at 16:19, Justin Carlson wrote: | | > Don't forget that, in non-x86 land, current tends to be just kept in a | > register. No computations required. Certainly passing it around on, | > e.g. mips is a clear loss. | | current is stored in a register (esp) in x86, too. This is why I | cautioned that looking up current was cheap -- I think every sane arch | stores current in some fast access way. That's why it is a macro -- it | is assembly code to quickly snag the address. | | So is passing current still worth it?
It sounds as if it may be one of those "it depends" things, but if
current is not calculated the exact same way in all places... people talk about coloring (or colouring in Canada) and several other things I forget, it's sort of nice to be sure it's calculated just once, and that if the calculation becomes more expensive in the future that the tradeoff between passing and calculating won't change.
I guess passing is safer for the future and of a known cost.
Signature · 3 lines
bill davidsen <[email protected]> CTO, TMR Associates, Inc Doing interesting things with little computers since 1979.
Quoted 4 lines · Ingo Molnar
It's
slightly cheaper to pass an already existing (calculated) 'current' pointer over to another function, instead of calculating it once more in that function.
On x86 that's true; many other architectures - alpha, ia64, m68k, mips, mips64, parisc, ppc, ppc64, sparc, sparc64 - keep current in a register already and thus it is slightly more expensive to pass it as a parameter instead of just using current in the function.
Either way surely the cost is tiny, and the maintainability considerations should prevail. Having a function which takes a task_struct * parameter which _has_ to be current sounds to me like an invitation for somebody to get it wrong down the track.
Paul.
In message <[email protected]> you
write:
Quoted 9 lines · Rusty Russell
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
4)
scheduler_tickneeds no args (p is always equal to current).i have not taken this part. We have 'current' calculated in
update_process_times(), so why not pass it along to thescheduler_tick()function?
Quoted 5 lines
Quoted 2 lines
Because it's redundant. It's *always* p == current (and the code assumes this!), but I had to grep the callers to find out.
we pass pointers across functions regularly, even if the pointer could be calculated within the function. We do this in the timer code too.
Look at it semantically: scheduler_tick() is just a function called regularly for scheduler maintenance. It might need the CPU number, the runqueue length, or phase of the moon: the caller shouldn't care.
If it was a static fn, maybe this optimization makes sense. But it's an interface wart, and the "optimization" is utterly marginal anyway.
That said, I never would have sent such a trivial patch by itself: I can't believe how many keystrokes were wasted over this issue!
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.