From: Linus Torvalds <torvalds@cs.Helsinki.FI>
Subject: Re: scheduled memcpy
Date: Thu, 1 Aug 1996 10:52:42 +0300 (EET DST) [thread overview]
Message-ID: <d8574f14d2d5cded460c5fb72cc1c624.axp-list@archive.invalid> (raw)
In-Reply-To: <m0ul9Fj-0001uTC@atheist.tamu.edu>
On Tue, 30 Jul 1996, Richard Henderson wrote:
>
> While waiting for glibc to build today, I was playing with the memcpy
> Martin Ostermann posted earlier this month. Following is a more-or-less
> directly translated version of same that has been hand-scheduled for the ev5.
Umm. This does a load from the destination for the first quad-word, even
if the source and destination are both aligned. That's ok if the
destination is cached, but it's _horrible_ if the destination isn't
cached and we're doing a small structure copy of just one or two
quadwords.
And that's actually one of the normal cases for kernel->user copies:
aligned quadwords, small areas.
Your timings have probably been done with cached destinations, right? One
of the most important cases is when the destination is _not_ cached. Note
that if you do mamcpy's in a loop for timing, then you never see the not
cached case, because the first memcpy will bring the thing into the cache
due to the cache load..
Counting cycles is worthless if you do a cache miss, because the cache
miss will take a lot longer than the whole copy would have..
That said, this _does_ look a lot better than my original code, and I'd
be more than happy to use it. However, I would be even happier if you'd
take these kinds of things into account too. And making sure the data
cache is cold for the destination is horribly hard. But I'd be very
interested indeed in timings for "cold cache".
Look out when timing stuff like this: you want to prime the destination to
make sure we don't get a page fault when writing to it, but at the same time
you want to make sure the destination isn't in the cache, so you probably
have to do something like this:
#define cache_size (4*1024*1024)
/* allocate the virtual addresses */
dest = align_alloc(size, destalignment);
source = align_alloc(size, srcalignment);
cache_flush = malloc(cache_size * 2);
/* allocate all the physical pages */
memset(cache_flush, 0, cache_size * 2);
memset(dest, 0 size);
memset(src, 0, size);
/* flush the cache */
memcpy(cache_flush, cache_flush+cache_size, cache_size);
memcpy(cache_flush+cache_size, cache_flush, cache_size);
__asm__("imb"); /* icache flush */
/* do the actual timings */
start = rpcc();
memcpy(dest, src, size);
end = rpcc();
printf("cold case: %d cycles\n", end-start);
Those kinds of "worst-case" numbers would be interesting. The cached
cases are important too, but not _just_ the cached cases, please..
(Oh, the above assumes that you have enough memory so that you don't
start swapping in the cache flush part, that would make the final memcpy
numbers test something else altogether ;-)
Linus
--
To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null
next parent reply other threads:[~1996-08-01 7:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <m0ul9Fj-0001uTC@atheist.tamu.edu>
1996-08-01 7:52 ` Linus Torvalds [this message]
1996-08-01 16:19 scheduled memcpy David Mosberger-Tang
[not found] <Pine.LNX.3.91.960801111059.10002F-100000@linux.cs.Helsinki.FI>
1996-08-01 14:32 ` Richard Henderson
1996-08-02 7:05 ` Linus Torvalds
1996-08-02 7:16 ` Linus Torvalds
[not found] <m0ulGrr-0001uLC@atheist.tamu.edu>
1996-08-01 8:19 ` Linus Torvalds
[not found] <199607311356.PAA16694@oscar.comnets.rwth-aachen.de>
1996-07-31 19:40 ` Harald Koenig
1996-07-31 19:40 ` Harald Koenig
1996-07-31 19:40 ` Harald Koenig
1996-07-31 19:40 ` Harald Koenig
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox