* Re: scheduled memcpy [not found] <m0ulGrr-0001uLC@atheist.tamu.edu> @ 1996-08-01 8:19 ` Linus Torvalds 0 siblings, 0 replies; 10+ messages in thread From: Linus Torvalds @ 1996-08-01 8:19 UTC (permalink / raw) On Tue, 30 Jul 1996, Richard Henderson wrote: > > Thanks for the tester. I compared four versions of memcpy; the one > from glibc, Linus', Martin's, and my own. If you're comparing different versions, you should make sure that you compare them with the same physical memory layout, otherwise cache effects can hide any results (unlucky placement of pages resulting in cache trashing on some runs, not on others). So you should either use the exact same binary that tests all the versions on the same memory area (with cache flushes in between tests), _or_ you'd have to do multiple runs and average them (or take the minimum value from the runs). If you're _really_ serious about this (very nice), you should probably unroll the inner loop a bit (that can help hide load latencies), and you can do stuff like pre-fetch with a "ldq_u $31,64($srcreg)" etc. Linus -- To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: scheduled memcpy
@ 1996-08-01 16:19 David Mosberger-Tang
0 siblings, 0 replies; 10+ messages in thread
From: David Mosberger-Tang @ 1996-08-01 16:19 UTC (permalink / raw)
>>>>> On Thu, 1 Aug 1996 10:52:42 +0300 (EET DST), Linus Torvalds <torvalds@cs.Helsinki.FI> said:
Linus> 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.
Linus> Umm. This does a load from the destination for the first
Linus> quad-word, even if the source and destination are both
Linus> aligned. That's ok if the destination is cached, but it's
Linus> _horrible_ if the destination isn't cached and we're doing a
Linus> small structure copy of just one or two quadwords.
Another thing to watch out for is write-after-write (WAW) conflicts.
At least on the ev4, this is very slow. Not something that normally
occurs, but if you use the Arch Ref Manual's recommended sequence to
store an unaligned quantity to an _aligned_ address, you do end up
with a WAW conflict (it works correctly, but it's quite slow). It's
not a problem with the memcpy code, but just something to watch out
for. Hmmh, did anybody write that book "Optimizing Alpha/RISC Code"
yet? ;-)
--david
--
To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null
^ permalink raw reply [flat|nested] 10+ messages in thread[parent not found: <Pine.LNX.3.91.960801111059.10002F-100000@linux.cs.Helsinki.FI>]
* Re: scheduled memcpy [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 0 siblings, 2 replies; 10+ messages in thread From: Richard Henderson @ 1996-08-01 14:32 UTC (permalink / raw) Linus wrote: > If you're _really_ serious about this (very nice), you should probably unroll > the inner loop a bit (that can help hide load latencies), and you can do > stuff like pre-fetch with a "ldq_u $31,64($srcreg)" etc. I've since unrolled the inner loops once, but it seemed to make very little difference in the timings. I'm not sure I understand the cause of this. I wouldn't have thought that the memory bug was completely saturated just with the single loop. Incidentally, "ldq_u $31, X(R)" is the universal nop -- it doesn't even get slotted. You have to use a real destination register. I've been trying to figure out how fetch and fetch_m should be used; whether it helps or hurts to do a fetch on the source as the first instruction and letting that work while I figure out if we're aligned or whatnot. The problem here is fetch talks about 512 byte aligned blocks. I'll go back and look at that code with your other suggestions in mind. r~ -- To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: scheduled memcpy 1996-08-01 14:32 ` Richard Henderson @ 1996-08-02 7:05 ` Linus Torvalds 1996-08-02 7:16 ` Linus Torvalds 1 sibling, 0 replies; 10+ messages in thread From: Linus Torvalds @ 1996-08-02 7:05 UTC (permalink / raw) On Thu, 1 Aug 1996, Richard Henderson wrote: > > Incidentally, "ldq_u $31, X(R)" is the universal nop -- it doesn't > even get slotted. You have to use a real destination register. Damn, I have my 21164 books at the university, and I'm at home now. But why do I have this belief that the behaviour of "ldq_u $31,X(R)" changed with the EV5, and prefetches from the L2 cache into the L1 cache? (You can't use a real destination register for prefetching, as that results in a memory fault if the address isn't mapped). > I've been trying to figure out how fetch and fetch_m should be > used; whether it helps or hurts to do a fetch on the source as the > first instruction and letting that work while I figure out if we're > aligned or whatnot. The problem here is fetch talks about 512 byte > aligned blocks. As far as I know, none of the current alpha machines do anything at all with fetch/fetch_m - the CPU sends out the address to the memory bus, but the external logic ignores the fetch cycles. Linus -- To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: scheduled memcpy 1996-08-01 14:32 ` Richard Henderson 1996-08-02 7:05 ` Linus Torvalds @ 1996-08-02 7:16 ` Linus Torvalds 1 sibling, 0 replies; 10+ messages in thread From: Linus Torvalds @ 1996-08-02 7:16 UTC (permalink / raw) On Thu, 1 Aug 1996, Richard Henderson wrote: > > I've since unrolled the inner loops once, but it seemed to make very > little difference in the timings. I'm not sure I understand the cause > of this. I wouldn't have thought that the memory bug was completely > saturated just with the single loop. The _memory_ bus is certainly saturated even with the single loop, and unrolling the loop shouldn't make any difference at all if you end up waiting for memory. But unrolling the loop may make some difference when the source is L1-cached, where the cache latency is just a few cycles and can be hidden by the outstanding loads on an ev5. However, in order to make any sense, unrolling probably has to be instruction-scheduled so that you do the right thing in the load delays. And there may be interesting behaviour depending on the exact details of the cache (like the cache being able to satisfy two loads at the same time as long as the loads are not to the same cache block etc - but I don't think the ev5 caches do anything like that). Linus -- To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <m0ul9Fj-0001uTC@atheist.tamu.edu>]
* Re: scheduled memcpy [not found] <m0ul9Fj-0001uTC@atheist.tamu.edu> @ 1996-08-01 7:52 ` Linus Torvalds 0 siblings, 0 replies; 10+ messages in thread From: Linus Torvalds @ 1996-08-01 7:52 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <199607311356.PAA16694@oscar.comnets.rwth-aachen.de>]
* Re: scheduled memcpy [not found] <199607311356.PAA16694@oscar.comnets.rwth-aachen.de> @ 1996-07-31 19:40 ` Harald Koenig 1996-07-31 19:40 ` Harald Koenig ` (2 subsequent siblings) 3 siblings, 0 replies; 10+ messages in thread From: Harald Koenig @ 1996-07-31 19:40 UTC (permalink / raw) > Hm, I think you used two different versions of libc for this: The > first one probably is libc/sysdeps/alpha/memcpy.S, contributed by Chris > Demetriou. I think that's the one Richard and I used for > measurements. The second looks like the one which is shipped in > RedHat's libc-0.43-1.rpm package, which uses byte transfers due to > brocken Makefiles (libc/string/memcpy.c). for D_GLIBC I just linked against libc-0.43-1.rpm with no special defines or include files. Harald -- All SCSI disks will from now on ___ _____ be required to send an email notice 0--,| /OOOOOOO\ 24 hours prior to complete hardware failure! <_/ / /OOOOOOOOOOO\ \ \/OOOOOOOOOOOOOOO\ \ OOOOOOOOOOOOOOOOO|// Harald Koenig, \/\/\/\/\/\/\/\/\/ Inst.f.Theoret.Astrophysik // / \\ \ koenig@tat.physik.uni-tuebingen.de ^^^^^ ^^^^^ -- To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: scheduled memcpy [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 3 siblings, 0 replies; 10+ messages in thread From: Harald Koenig @ 1996-07-31 19:40 UTC (permalink / raw) > Hm, I think you used two different versions of libc for this: The > first one probably is libc/sysdeps/alpha/memcpy.S, contributed by Chris > Demetriou. I think that's the one Richard and I used for > measurements. The second looks like the one which is shipped in > RedHat's libc-0.43-1.rpm package, which uses byte transfers due to > brocken Makefiles (libc/string/memcpy.c). for D_GLIBC I just linked against libc-0.43-1.rpm with no special defines or include files. Harald -- All SCSI disks will from now on ___ _____ be required to send an email notice 0--,| /OOOOOOO\ 24 hours prior to complete hardware failure! <_/ / /OOOOOOOOOOO\ \ \/OOOOOOOOOOOOOOO\ \ OOOOOOOOOOOOOOOOO|// Harald Koenig, \/\/\/\/\/\/\/\/\/ Inst.f.Theoret.Astrophysik // / \\ \ koenig@tat.physik.uni-tuebingen.de ^^^^^ ^^^^^ -- To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: scheduled memcpy [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 3 siblings, 0 replies; 10+ messages in thread From: Harald Koenig @ 1996-07-31 19:40 UTC (permalink / raw) > Hm, I think you used two different versions of libc for this: The > first one probably is libc/sysdeps/alpha/memcpy.S, contributed by Chris > Demetriou. I think that's the one Richard and I used for > measurements. The second looks like the one which is shipped in > RedHat's libc-0.43-1.rpm package, which uses byte transfers due to > brocken Makefiles (libc/string/memcpy.c). for D_GLIBC I just linked against libc-0.43-1.rpm with no special defines or include files. Harald -- All SCSI disks will from now on ___ _____ be required to send an email notice 0--,| /OOOOOOO\ 24 hours prior to complete hardware failure! <_/ / /OOOOOOOOOOO\ \ \/OOOOOOOOOOOOOOO\ \ OOOOOOOOOOOOOOOOO|// Harald Koenig, \/\/\/\/\/\/\/\/\/ Inst.f.Theoret.Astrophysik // / \\ \ koenig@tat.physik.uni-tuebingen.de ^^^^^ ^^^^^ -- To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: scheduled memcpy [not found] <199607311356.PAA16694@oscar.comnets.rwth-aachen.de> ` (2 preceding siblings ...) 1996-07-31 19:40 ` Harald Koenig @ 1996-07-31 19:40 ` Harald Koenig 3 siblings, 0 replies; 10+ messages in thread From: Harald Koenig @ 1996-07-31 19:40 UTC (permalink / raw) > Hm, I think you used two different versions of libc for this: The > first one probably is libc/sysdeps/alpha/memcpy.S, contributed by Chris > Demetriou. I think that's the one Richard and I used for > measurements. The second looks like the one which is shipped in > RedHat's libc-0.43-1.rpm package, which uses byte transfers due to > brocken Makefiles (libc/string/memcpy.c). for D_GLIBC I just linked against libc-0.43-1.rpm with no special defines or include files. Harald -- All SCSI disks will from now on ___ _____ be required to send an email notice 0--,| /OOOOOOO\ 24 hours prior to complete hardware failure! <_/ / /OOOOOOOOOOO\ \ \/OOOOOOOOOOOOOOO\ \ OOOOOOOOOOOOOOOOO|// Harald Koenig, \/\/\/\/\/\/\/\/\/ Inst.f.Theoret.Astrophysik // / \\ \ koenig@tat.physik.uni-tuebingen.de ^^^^^ ^^^^^ -- To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~1996-08-02 7:16 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <m0ulGrr-0001uLC@atheist.tamu.edu>
1996-08-01 8:19 ` scheduled memcpy Linus Torvalds
1996-08-01 16:19 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] <m0ul9Fj-0001uTC@atheist.tamu.edu>
1996-08-01 7:52 ` 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox