Re: Add prefetch switch stack hook in scheduler function

Ingo Molnar
2005-07-29T08:44:44Z

* Eric Dumazet <dada1@cosmosbay.com> wrote:

> Please test that len is a constant, or else the inlining is too large
> for the non constant case.

yeah. fix below.

Ingo

-----
noticed by Eric Dumazet: unrolling should be dependent on a constant
length, otherwise inlining gets too large.

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

include/linux/prefetch.h | 128 ++++++++++++++++++++++++-----------------------
1 files changed, 66 insertions(+), 62 deletions(-)

Index: linux-prefetch-task/include/linux/prefetch.h
=================================--- linux-prefetch-task.orig/include/linux/prefetch.h
+++ linux-prefetch-task/include/linux/prefetch.h
@@ -64,37 +64,39 @@ static inline void prefetch_range(void *
/*
* Unroll agressively:
*/
- if (len <= PREFETCH_STRIDE)
- prefetch(cp);
- else if (len <= 2*PREFETCH_STRIDE) {
- prefetch(cp);
- prefetch(cp + PREFETCH_STRIDE);
- }
- else if (len <= 3*PREFETCH_STRIDE) {
- prefetch(cp);
- prefetch(cp + PREFETCH_STRIDE);
- prefetch(cp + 2*PREFETCH_STRIDE);
- }
- else if (len <= 4*PREFETCH_STRIDE) {
- prefetch(cp);
- prefetch(cp + PREFETCH_STRIDE);
- prefetch(cp + 2*PREFETCH_STRIDE);
- prefetch(cp + 3*PREFETCH_STRIDE);
- }
- else if (len <= 5*PREFETCH_STRIDE) {
- prefetch(cp);
- prefetch(cp + PREFETCH_STRIDE);
- 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);
+ if (__builtin_constant_p(len) && (len <= 6*PREFETCH_STRIDE)) {
+ if (len <= PREFETCH_STRIDE)
+ prefetch(cp);
+ else if (len <= 2*PREFETCH_STRIDE) {
+ prefetch(cp);
+ prefetch(cp + PREFETCH_STRIDE);
+ }
+ else if (len <= 3*PREFETCH_STRIDE) {
+ prefetch(cp);
+ prefetch(cp + PREFETCH_STRIDE);
+ prefetch(cp + 2*PREFETCH_STRIDE);
+ }
+ else if (len <= 4*PREFETCH_STRIDE) {
+ prefetch(cp);
+ prefetch(cp + PREFETCH_STRIDE);
+ prefetch(cp + 2*PREFETCH_STRIDE);
+ prefetch(cp + 3*PREFETCH_STRIDE);
+ }
+ else if (len <= 5*PREFETCH_STRIDE) {
+ prefetch(cp);
+ prefetch(cp + PREFETCH_STRIDE);
+ 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);
@@ -110,37 +112,39 @@ static inline void prefetchw_range(void
/*
* Unroll agressively:
*/
- if (len <= PREFETCH_STRIDE)
- prefetchw(cp);
- else if (len <= 2*PREFETCH_STRIDE) {
- prefetchw(cp);
- prefetchw(cp + PREFETCH_STRIDE);
- }
- else if (len <= 3*PREFETCH_STRIDE) {
- prefetchw(cp);
- prefetchw(cp + PREFETCH_STRIDE);
- prefetchw(cp + 2*PREFETCH_STRIDE);
- }
- else if (len <= 4*PREFETCH_STRIDE) {
- prefetchw(cp);
- prefetchw(cp + PREFETCH_STRIDE);
- prefetchw(cp + 2*PREFETCH_STRIDE);
- prefetchw(cp + 3*PREFETCH_STRIDE);
- }
- else if (len <= 5*PREFETCH_STRIDE) {
- prefetchw(cp);
- prefetchw(cp + PREFETCH_STRIDE);
- 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);
+ if (__builtin_constant_p(len) && (len <= 6*PREFETCH_STRIDE)) {
+ if (len <= PREFETCH_STRIDE)
+ prefetchw(cp);
+ else if (len <= 2*PREFETCH_STRIDE) {
+ prefetchw(cp);
+ prefetchw(cp + PREFETCH_STRIDE);
+ }
+ else if (len <= 3*PREFETCH_STRIDE) {
+ prefetchw(cp);
+ prefetchw(cp + PREFETCH_STRIDE);
+ prefetchw(cp + 2*PREFETCH_STRIDE);
+ }
+ else if (len <= 4*PREFETCH_STRIDE) {
+ prefetchw(cp);
+ prefetchw(cp + PREFETCH_STRIDE);
+ prefetchw(cp + 2*PREFETCH_STRIDE);
+ prefetchw(cp + 3*PREFETCH_STRIDE);
+ }
+ else if (len <= 5*PREFETCH_STRIDE) {
+ prefetchw(cp);
+ prefetchw(cp + PREFETCH_STRIDE);
+ 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);