Re: Add prefetch switch stack hook in scheduler function

Ingo Molnar
2005-07-29T08:35:58Z

* Chen, Kenneth W <kenneth.w.chen@intel.com> wrote:

> Ingo Molnar wrote on Friday, July 29, 2005 12:07 AM
> > the patch below unrolls the prefetch_range() loop manually, for up to 5
> > cachelines prefetched. This patch, ontop of the 4 previous patches,
> > should generate similar code to the assembly code in your original
> > patch. The full patch-series is:
>
> It generate slight different code because previous patch asks for a little
> over 5 cache lines worth of bytes and it always go to the for loop.

ok - fix below. But i'm not that sure we want to unroll a 6-instruction
loop, and it's getting a bit ugly. (Also, it would be nice to have a gcc
extension for loops that says 'always unroll up to N entries'.)

Ingo

----
unroll the prefetch loop some more.

Signed-off-by: Ingo Molnar <mingo@elte.hu>

include/linux/prefetch.h | 16 ++++++++++++++++
1 files changed, 16 insertions(+)

Index: linux-prefetch-task/include/linux/prefetch.h
=================================--- linux-prefetch-task.orig/include/linux/prefetch.h
+++ linux-prefetch-task/include/linux/prefetch.h
@@ -87,6 +87,14 @@ static inline void prefetch_range(void *
prefetch(cp + 2*PREFETCH_STRIDE);
prefetch(cp + 3*PREFETCH_STRIDE);
prefetch(cp + 4*PREFETCH_STRIDE);
+ }
+ else if (len <= 6*PREFETCH_STRIDE) {
+ prefetch(cp);
+ prefetch(cp + PREFETCH_STRIDE);
+ prefetch(cp + 2*PREFETCH_STRIDE);
+ prefetch(cp + 3*PREFETCH_STRIDE);
+ prefetch(cp + 4*PREFETCH_STRIDE);
+ prefetch(cp + 5*PREFETCH_STRIDE);
} else
for (; cp < end; cp += PREFETCH_STRIDE)
prefetch(cp);
@@ -125,6 +133,14 @@ static inline void prefetchw_range(void
prefetchw(cp + 2*PREFETCH_STRIDE);
prefetchw(cp + 3*PREFETCH_STRIDE);
prefetchw(cp + 4*PREFETCH_STRIDE);
+ }
+ else if (len <= 6*PREFETCH_STRIDE) {
+ prefetchw(cp);
+ prefetchw(cp + PREFETCH_STRIDE);
+ prefetchw(cp + 2*PREFETCH_STRIDE);
+ prefetchw(cp + 3*PREFETCH_STRIDE);
+ prefetchw(cp + 4*PREFETCH_STRIDE);
+ prefetchw(cp + 5*PREFETCH_STRIDE);
} else
for (; cp < end; cp += PREFETCH_STRIDE)
prefetchw(cp);