Re: [PATCH] Add memcpy_cachebypass, a copy routine that tries tokeep cache pressure down

From: Randy.Dunlap
Date: Tue Jul 11 2006 - 17:05:27 EST


On Tue, 11 Jul 2006 13:50:55 -0700 Bryan O'Sullivan wrote:

> diff -r c5610179c494 -r da0cd816c4cb include/linux/string.h
> --- a/include/linux/string.h Tue Jul 11 13:40:19 2006 -0700
> +++ b/include/linux/string.h Tue Jul 11 13:41:40 2006 -0700
> @@ -85,6 +85,7 @@ extern void * memset(void *,int,__kernel
> #ifndef __HAVE_ARCH_MEMCPY
> extern void * memcpy(void *,const void *,__kernel_size_t);
> #endif
> +extern void * memcpy_cachebypass(void *,const void *,__kernel_size_t);

space after commas, please.

> #ifndef __HAVE_ARCH_MEMMOVE
> extern void * memmove(void *,const void *,__kernel_size_t);
> #endif
> diff -r c5610179c494 -r da0cd816c4cb lib/string.c
> --- a/lib/string.c Tue Jul 11 13:40:19 2006 -0700
> +++ b/lib/string.c Tue Jul 11 13:41:40 2006 -0700
> @@ -509,6 +509,38 @@ EXPORT_SYMBOL(memcpy);
> EXPORT_SYMBOL(memcpy);
> #endif
>
> +void *memcpy_cachebypass(void *dest, const void *src, size_t count)
> + __attribute__((weak));
> +
> +/**
> + * memcpy_cachebypass - Copy one area of memory to another, if possible
> + * bypassing the CPU's cache when loading the copied-from data

Currently kernel-doc function description is limited to one line.
If you can't shorten it, just omit it completely and make it the first
paragraph after the parameters.

> + * @dest: Where to copy to
> + * @src: Where to copy from (bypassing the CPU's cache, if possible)
> + * @count: The size of the area.
> + *
> + * This memcpy-compatible routine is intended for use when the CPU
> + * only reads the source data once. It is useful when, for example, a
> + * hardware device writes to a memory region, and the CPU needs to
> + * copy this data somewhere else before working on it. In such a
> + * case, caching the source addresses only serves to evict possibly
> + * useful data that will probably have to be reloaded.
> + *
> + * An arch-specific implementation should not attempt to bypass the
> + * cache when storing to the destination, as copied data is usually
> + * accessed almost immediately after a copy finishes.
> + *
> + * This routine does not *guarantee* that the source addresses won't
> + * be cached; a user of this code must not rely on this behaviour for
> + * correctness. It should only be used in cases where it provides a
> + * measurable performance improvement.
> + */
> +void *memcpy_cachebypass(void *dest, const void *src, size_t count)
> +{
> + return memcpy(dest, src, count);
> +}
> +EXPORT_SYMBOL_GPL(memcpy_cachebypass);
> +
> #ifndef __HAVE_ARCH_MEMMOVE
> /**
> * memmove - Copy one area of memory to another

---
~Randy
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/