Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
* Strange behaviour of Alpha Floating Point Load/Stores wrt cache misses
@ 1994-03-03  2:53 Trevor Blackwell
  1994-03-03 23:32 ` Trevor Blackwell
  0 siblings, 1 reply; 4+ messages in thread
From: Trevor Blackwell @ 1994-03-03  2:53 UTC (permalink / raw)



This one really baffles me. I measure very different performance of
load and store instructions, between when I do a LDQ/STQ (load/store
quadword = 8 bytes), and LDT/SDT (load/store IEEE FP double = 8
bytes), especially when cache misses are involved. These are the same
size memory transfers, done in the same order, and I would have
expected them to perform identically. The architecture manual claims
that LDT/SDT do not do any FP work such as normalizing; they just
transfer bits between the register and memory.

[This came up because I was interested in the register save/restore
code involved in a context switch, and whether it could be optimized
by interleaving loads & stores to different cache lines, given the
Alpha's load/store buffers. It may look wierd because I messed around
with the order of load/saves to try and hit the right cache lines
early].

Look at the attached assembler file below (adapted from the AweSime
threads library). It loads and saves the registers (I changed it to
use registers $31 & $f1 for everything, so I could call it normally)

I called it from code that makes almost no (like, 1, contrived not to
alias with anything) memory references between calls, except every
fifth time it loads a 8K-long vector, to flush the cache. Something
like:

  for (i=0; i<100; i++) {
    if (i%5==0) flushData();
    timing[i] = magicSwitchTo1(area1,area2);
  }

If the #if is 1, (so it does integer and FP transfers) then a typical
timing sequence (times in clock cycles, timing with RPCC) is:

 ...
 Time = 83 (with flush)
 Time = 54 (no flush)
 Time = 66 (no flush)
 Time = 66 (no flush)
 Time = 66 (no flush)
 Time = 83 (with flush)
 Time = 54 (no flush)
 Time = 66 (no flush)
 Time = 66 (no flush)
 Time = 66 (no flush)
 ...

If the #if is 0, (integer transfers only) then I get:

 ...
 Time = 50 (with flush)
 Time = 50 (no flush)
 Time = 61 (no flush)
 Time = 61 (no flush)
 Time = 61 (no flush)
 Time = 50 (with flush)
 Time = 50 (no flush)
 Time = 61 (no flush)
 Time = 61 (no flush)
 Time = 61 (no flush)
 ...

This is totally repeatable. Email me for my complete code if you want
to play with it.

This makes absolutely no sense at all to me. Does anyone know why this
might be happening? In particular:

  - Why are FP and integer different?

  - Why do I get SHORTER times with integer only AFTER flushing the cache?

  - Why is the second time after flushing the cache short, but the
    third time longer? Is this because of something about hits on dirty
    (writeback-pending) processor cache lines?

I note that reordering the first few instructions makes a big
difference (as you might expect - you win if you can get both memory
load registers reading in cache lines simultaneously). I got the total
time down from 120 clocks to 83 clocks in the mixed integer/FP case by
putting the right things in the first 5 instructions.

I am pretty sure I am controlling for all extraneous factors. My
measurement code runs 100 times, only referencing an array where it
sticks the running time. All the code fits in the I-cache. I'm not
getting interrupts (the whole measurement takes about 10 uS, and the
effect of interrupts is real obvious when they do occur.)  The whole
shebang (code & data) fits in the off-chip B-cache, and my flush
vector should not flush the register load/store areas out of there.

Any explanations? [Whatever happened to nice, predictable CPUs, like
the 6502, where you could count your clock cycles yourself?]

--------------------------------------------------------------------------------
/* save registers from $16, load from $17 */
magicSwitchTo1:	
	.frame $30,0,$26,0
	.prologue 0

	rpcc $3

	stq	$31,32($16)
	stq	$31,104($16)
	ldq	$31,32($17)
	ldq	$31,152($17)
	
	stq	$31,40($16)
	ldq	$31,40($17)
	stq	$31,48($16)
	ldq	$31,48($17)
	stq	$31,56($16)
	ldq	$31,56($17)
	stq	$31,64($16)
	ldq	$31,64($17)
	stq	$31,72($16)
	ldq	$31,72($17)
	stq	$31,80($16)
	ldq	$31,80($17)
	stq	$31,88($16)
	ldq	$31,88($17)
	stq	$31,96($16)
	ldq	$31,96($17)

#if 1
	ldq	$31,104($17)
	stq	$31,112($16)
	ldq	$31,112($17)
	stq	$31,120($16)
	ldq	$31,120($17)
	stq	$31,128($16)
	ldq	$31,128($17)
	stq	$31,136($16)
	ldq	$31,136($17)
	stq	$31,144($16)
	ldq	$31,144($17)
	stq	$31,152($16)
#else
	ldt	$f1,104($17)
	stt	$f1,112($16)
	ldt	$f1,112($17)
	stt	$f1,120($16)
	ldt	$f1,120($17)
	stt	$f1,128($16)
	ldt	$f1,128($17)
	stt	$f1,136($16)
	ldt	$f1,136($17)
	stt	$f1,144($16)
	ldt	$f1,144($17)
	stt	$f1,152($16)
#endif
	stq	$31,24($16)
	ldq	$31,24($17)
	stq	$31,0($16)
	stq	$31,8($16)
	ldq	$31,8($17)
	ldq	$31,0($17)

	rpcc $1
	
	sll $3,32,$2
	addq $3,$2,$3
	srl $3,32,$3
	
	sll $1,32,$2
	addq $1,$2,$1
	srl $1,32,$1
	subq $1,$3,$0
	
	ret $31,($26),1

--
--
Trevor Blackwell         tlb@das.harvard.edu          (617) 495-8912
(info and words of wit in my .plan)
Disavowal: My opinions.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Strange behaviour of Alpha Floating Point Load/Stores wrt cache misses
  1994-03-03  2:53 Strange behaviour of Alpha Floating Point Load/Stores wrt cache misses Trevor Blackwell
@ 1994-03-03 23:32 ` Trevor Blackwell
  1994-03-04  1:36   ` Dirk Grunwald
  1994-03-07 14:08   ` Srinivasan Murari
  0 siblings, 2 replies; 4+ messages in thread
From: Trevor Blackwell @ 1994-03-03 23:32 UTC (permalink / raw)



> I am pretty sure I am controlling for all extraneous factors. My
> measurement code runs 100 times, only referencing an array where it
> sticks the running time. All the code fits in the I-cache. I'm not
> getting interrupts (the whole measurement takes about 10 uS, and the
> effect of interrupts is real obvious when they do occur.)  The whole
> shebang (code & data) fits in the off-chip B-cache, and my flush
> vector should not flush the register load/store areas out of there.

Well, I controlled them all except one. In order that I could call
the context switch code from a C program, I replaced the loads and
stores to all the miscellaneous registers, with loads and stores to
$31 (the one which reads as zero). It turns out that the instruction

    LDQ $31,address

is a NOP - it never actually references any memory. I am quite
surprised that it actually does this - I'm sure on a MIPS or most
other RISCs it would do the load anyway, and just let the bits fall
off the end of the wire in the register file. So that explains
everything. It even sort of suggests that this might happen in the
manual.

In fact, it appears that the way Dirk Grunwald originally wrote the
AweSime context switcher is the fastest way possible - loads and
stores interleaved.

--
--
Trevor Blackwell         tlb@das.harvard.edu          (617) 495-8912
(info and words of wit in my .plan)
Disavowal: My opinions.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Strange behaviour of Alpha Floating Point Load/Stores wrt cache misses
  1994-03-03 23:32 ` Trevor Blackwell
@ 1994-03-04  1:36   ` Dirk Grunwald
  1994-03-07 14:08   ` Srinivasan Murari
  1 sibling, 0 replies; 4+ messages in thread
From: Dirk Grunwald @ 1994-03-04  1:36 UTC (permalink / raw)


>>>>> "TB" == Trevor Blackwell <tlb@chardonnay.harvard.edu> writes:
In article <TLB.94Mar3183240@chardonnay.harvard.edu> tlb@chardonnay.harvard.edu (Trevor Blackwell) writes:
TB> In fact, it appears that the way Dirk Grunwald originally wrote
TB> the AweSime context switcher is the fastest way possible - loads
TB> and stores interleaved.
---


Phew. I think I got the original version of the alpha switching code
from David Keppel, but the version I got from him has a series of
loads followed by a series of stores.  In general, I interleave the
loads and stores because back-to-back loads always seem to cause
problems on RISC machines. Since a context switch routine doesn't do
much other than loads and stores, interleaving the loads means you
need to interleave the stores as well -- and I ordered them to take
advantage of the write-buffers on the alpha.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Strange behaviour of Alpha Floating Point Load/Stores wrt cache misses
  1994-03-03 23:32 ` Trevor Blackwell
  1994-03-04  1:36   ` Dirk Grunwald
@ 1994-03-07 14:08   ` Srinivasan Murari
  1 sibling, 0 replies; 4+ messages in thread
From: Srinivasan Murari @ 1994-03-07 14:08 UTC (permalink / raw)



In article <TLB.94Mar3183240@chardonnay.harvard.edu>,
tlb@chardonnay.harvard.edu (Trevor Blackwell) writes:
|>
|>> I am pretty sure I am controlling for all extraneous factors. My
|>> measurement code runs 100 times, only referencing an array where it
|>> sticks the running time. All the code fits in the I-cache. I'm not
|>> getting interrupts (the whole measurement takes about 10 uS, and
|>the
|>> effect of interrupts is real obvious when they do occur.)  The
|>whole
|>> shebang (code & data) fits in the off-chip B-cache, and my flush
|>> vector should not flush the register load/store areas out of there.
|>
|>Well, I controlled them all except one. In order that I could call
|>the context switch code from a C program, I replaced the loads and
|>stores to all the miscellaneous registers, with loads and stores to
|>$31 (the one which reads as zero). It turns out that the instruction
|>
|>    LDQ $31,address
|>
|>is a NOP - it never actually references any memory. I am quite
|>surprised that it actually does this - I'm sure on a MIPS or most
|>other RISCs it would do the load anyway, and just let the bits fall
|>off the end of the wire in the register file. So that explains
|>everything. It even sort of suggests that this might happen in the
|>manual.
|>
|>In fact, it appears that the way Dirk Grunwald originally wrote the
|>AweSime context switcher is the fastest way possible - loads and
|>stores interleaved.
|>
|>--
|>--
|>Trevor Blackwell         tlb@das.harvard.edu          (617) 495-8912
|>(info and words of wit in my .plan)
|>Disavowal: My opinions.
|>

As trevor correctly observed the LDQ $31, address is thrown away

From page 3-1 of the Alpha Architecture reference manual

For all cases except Unconditional branch and Jump instructions, results of
an instruction that specifies R31 as the destination operand are
discarded. Also it is UNPREDICTABLE whether the other destination
operands (implicit and explicit) are changed by the instruction. It is
implementation dependent to what extent the instruction is actually executed
once it has been fetched. It is also UNPREDICTABLE whether exceptions are
signalled during the execution of such an instruction.

I believe the DECChip 20164 discards the R31 target LDQ at the issue
stage. This would explain the anamolies you have been seeing. Try loading
your data into some register other than R31 to see more consistent behavior.

/murari


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1994-03-07 14:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-03-03  2:53 Strange behaviour of Alpha Floating Point Load/Stores wrt cache misses Trevor Blackwell
1994-03-03 23:32 ` Trevor Blackwell
1994-03-04  1:36   ` Dirk Grunwald
1994-03-07 14:08   ` Srinivasan Murari

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox