public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Add prefetch switch stack hook in scheduler function
@ 2005-07-27 22:07 Chen, Kenneth W
  2005-07-27 23:13 ` Andrew Morton
  0 siblings, 1 reply; 40+ messages in thread
From: Chen, Kenneth W @ 2005-07-27 22:07 UTC (permalink / raw)
  To: 'Ingo Molnar'; +Cc: linux-kernel, linux-ia64

I would like to propose adding a prefetch switch stack hook in
the scheduler function.  For architecture like ia64, the switch
stack structure is fairly large (currently 528 bytes).  For context
switch intensive application, we found that significant amount of
cache misses occurs in switch_to() function.  The following patch
adds a hook in the schedule() function to prefetch switch stack
structure as soon as 'next' task is determined.  This allows maximum
overlap in prefetch cache lines for that structure.

Signed-off-by: Ken Chen <kenneth.w.chen@intel.com>


--- linux-2.6.12/include/linux/sched.h.orig	2005-07-27 14:43:49.321986290 -0700
+++ linux-2.6.12/include/linux/sched.h	2005-07-27 14:44:03.390345492 -0700
@@ -622,6 +622,11 @@ extern int groups_search(struct group_in
 #define GROUP_AT(gi, i) \
     ((gi)->blocks[(i)/NGROUPS_PER_BLOCK][(i)%NGROUPS_PER_BLOCK])
 
+#ifdef ARCH_HAS_PREFETCH_SWITCH_STACK
+extern void prefetch_switch_stack(struct task_struct*);
+#else
+#define prefetch_switch_stack(task)	do { } while (0)
+#endif
 
 struct audit_context;		/* See audit.c */
 struct mempolicy;
--- linux-2.6.12/kernel/sched.c.orig	2005-07-27 14:43:49.391322226 -0700
+++ linux-2.6.12/kernel/sched.c	2005-07-27 14:44:03.394251742 -0700
@@ -3044,6 +3044,7 @@ switch_tasks:
 	if (next == rq->idle)
 		schedstat_inc(rq, sched_goidle);
 	prefetch(next);
+	prefetch_switch_stack(next);
 	clear_tsk_need_resched(prev);
 	rcu_qsctr_inc(task_cpu(prev));
 


^ permalink raw reply	[flat|nested] 40+ messages in thread
* Re: Add prefetch switch stack hook in scheduler function
@ 2005-07-29 15:18 linux
  2005-07-29 15:49 ` Ingo Molnar
  0 siblings, 1 reply; 40+ messages in thread
From: linux @ 2005-07-29 15:18 UTC (permalink / raw)
  To: linux-kernel; +Cc: mingo

>  include/asm-alpha/mmu_context.h     |    6 ++++++
>  include/asm-arm/mmu_context.h       |    6 ++++++
>  include/asm-arm26/mmu_context.h     |    6 ++++++
>  include/asm-cris/mmu_context.h      |    6 ++++++
>  include/asm-frv/mmu_context.h       |    6 ++++++
>  include/asm-h8300/mmu_context.h     |    6 ++++++
>  include/asm-i386/mmu_context.h      |    6 ++++++
>  include/asm-ia64/mmu_context.h      |    6 ++++++
>  include/asm-m32r/mmu_context.h      |    6 ++++++
>  include/asm-m68k/mmu_context.h      |    6 ++++++
>  include/asm-m68knommu/mmu_context.h |    6 ++++++
>  include/asm-mips/mmu_context.h      |    6 ++++++
>  include/asm-parisc/mmu_context.h    |    6 ++++++
>  include/asm-ppc/mmu_context.h       |    6 ++++++
>  include/asm-ppc64/mmu_context.h     |    6 ++++++
>  include/asm-s390/mmu_context.h      |    6 ++++++
>  include/asm-sh/mmu_context.h        |    6 ++++++
>  include/asm-sh64/mmu_context.h      |    6 ++++++
>  include/asm-sparc/mmu_context.h     |    6 ++++++
>  include/asm-sparc64/mmu_context.h   |    6 ++++++
>  include/asm-um/mmu_context.h        |    6 ++++++
>  include/asm-v850/mmu_context.h      |    6 ++++++
>  include/asm-x86_64/mmu_context.h    |    5 +++++
>  include/asm-xtensa/mmu_context.h    |    6 ++++++
>  kernel/sched.c                      |    9 ++++++++-
>  25 files changed, 151 insertions(+), 1 deletion(-)

I think this pretty clearly points out the need for some arch-generic
infrastructure in Linux.  An awful lot of arch hooks are for one
or two architectures with some peculiarities, and the other 90% of
the implementations are identical.

For example, this is 22 repetitions of
#define MIN_KERNEL_STACK_FOOTPRINT L1_CACHE_BYTES

with one different case.

It would be awfully nice if there was a standard way to provide a default
implementation that was automatically picked up by any architecture that
didn't explicitly override it.

One possibility is to use #ifndef:

/* asm-$PLATFORM/foo.h */
#define MIN_KERNEL_STACK_FOOTPRINT IA64_SWITCH_STACK_SIZE
inline void
prefetch_task(struct task_struct const *task)
{
	...
}
#define prefetch_task prefetch_task


/* asm-generic/foo.h */
#include <asm/foo.h>

#ifndef MIN_KERNEL_STACK_FOOTPRINT
#define MIN_KERNEL_STACK_FOOTPRINT L1_CACHE_BYTES
#endif

#ifndef prefetch_task
inline void prefetch_task(struct task_struct const *task) { }
/* The #define is OPTIONAL... */
#define prefetch_task prefetch_task
#endif


But both understanding and maintaining the arch code could be
much easier if the shared parts were collapsed.  A comment in the
generic versions can explain what the assumptions are.


If there are cases where there is more than one implementation with
multiple users, it can be stuffed into a third category of headers.
E.g. <asm-generic/noiommu/foo.h> and <asm-generic/iommu/foo.h> or some
such, using the same duplicate-suppression technique and #included at
the end of <asm-$PLATFORM/foo.h>

^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2005-07-31 19:18 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-27 22:07 Add prefetch switch stack hook in scheduler function Chen, Kenneth W
2005-07-27 23:13 ` Andrew Morton
2005-07-27 23:23   ` david mosberger
2005-07-28  7:41     ` Ingo Molnar
2005-07-28  8:09       ` Keith Owens
2005-07-28  8:16         ` Ingo Molnar
2005-07-28  9:09           ` Ingo Molnar
2005-07-28 19:14             ` Chen, Kenneth W
2005-07-29  7:04               ` Ingo Molnar
2005-07-29  7:07                 ` Ingo Molnar
2005-07-29  8:30                   ` Eric Dumazet
2005-07-29  8:44                     ` Ingo Molnar
2005-07-31 16:27                     ` hashed spinlocks Daniel Walker
2005-07-31 18:46                       ` David S. Miller
2005-07-31 19:06                         ` Daniel Walker
2005-07-31 19:11                           ` David S. Miller
2005-07-31 19:16                             ` Daniel Walker
2005-07-29  8:30                   ` Add prefetch switch stack hook in scheduler function Chen, Kenneth W
2005-07-29  8:35                     ` Ingo Molnar
2005-07-29  8:39                       ` Chen, Kenneth W
2005-07-29  9:17                   ` Peter Zijlstra
2005-07-29 10:52                     ` Ingo Molnar
2005-07-29  7:22                 ` Chen, Kenneth W
2005-07-29  7:45                   ` Keith Owens
2005-07-29  8:02                     ` Chen, Kenneth W
2005-07-29  8:28                   ` Ingo Molnar
2005-07-29  9:02                     ` Russell King
2005-07-29  9:45                       ` Ingo Molnar
2005-07-29  7:38                 ` Keith Owens
2005-07-29  8:08                   ` Chen, Kenneth W
2005-07-28  8:31         ` Nick Piggin
2005-07-28  8:35           ` Ingo Molnar
2005-07-28  8:48             ` Nick Piggin
2005-07-28  9:16               ` Ingo Molnar
2005-07-28  9:19                 ` Ingo Molnar
2005-07-28  9:34                 ` Nick Piggin
2005-07-28 10:04                   ` Ingo Molnar
2005-07-28 10:29                     ` Nick Piggin
  -- strict thread matches above, loose matches on Subject: below --
2005-07-29 15:18 linux
2005-07-29 15:49 ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox