From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: X-Archive-Original-Message-ID: <199608010603.IAA09761@ceres.tat.physik.uni-tuebingen.de> Date: Thu, 1 Aug 1996 10:52:42 +0300 (EET DST) From: Linus Torvalds Subject: Re: scheduled memcpy In-Reply-To: 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