RE: Add prefetch switch stack hook in scheduler function

Chen, Kenneth W
2005-07-29T07:22:43Z

Ingo Molnar wrote on Friday, July 29, 2005 12:05 AM
> --- linux.orig/kernel/sched.c
> +++ linux/kernel/sched.c
> @@ -2869,7 +2869,14 @@ go_idle:
> * its thread_info, its kernel stack and mm:
> */
> prefetch(next->thread_info);
> - prefetch(kernel_stack(next));
> + /*
> + * Prefetch (at least) a cacheline below the current
> + * kernel stack (in expectation of any new task touching
> + * the stack at least minimally), and a cacheline above
> + * the stack:
> + */
> + prefetch_range(kernel_stack(next) - MIN_KERNEL_STACK_FOOTPRINT,
> + MIN_KERNEL_STACK_FOOTPRINT + L1_CACHE_BYTES);
> prefetch(next->mm);

Doctor, it still hurts :-(

On ia64, we have two kernel stacks, one for outgoing task, and one for
incoming task. for outgoing task, we haven't called switch_to() yet.
So the switch stack structure for 'current' will be allocated immediately
below current 'sp' pointer. For the incoming task, it was fully ctx'ed out
previously, so switch stack structure is immediate above kernel_stack(next).
It Would be beneficial to prefetch both stacks.