lkml.org 
[lkml]   [1996]   [Apr]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Accessing Pentium MSRs
Okay, here is the promised patch. It adds the syscalls "rdmsr" and "wrmsr", 
which are wrappers around the instructions with the same names. Write access
is provided for MSRs 0x11, 0x12 and 0x13, which control the event counters,
and read access is provided for the same three plus the time stamp counter
(0x10), although the last one isn't exactly useful if you can't rely on being
the only running task.
MSR 0x11 controls the two counters. Bits 0-8 control counter 0, bits 16-24
control counter 1. The bits mean:
7/23: count in user mode
6/22: count in kernel mode (hardly useful)
5-0/21-16: select one of forty-two counters.

MSRs 0x12 and 0x13 are the counters themselves. These are 40-bit registers.

Here are some of the more interesting counters (numbers in hex):
0/1: data read/write
2: data TLB miss
3/4: data cache read/write miss
6: data cache lines written back
9: memory accesses in both pipes
A: bank conflicts (both pipes accessing the same cache area at the same time)
C: code read
D: code TLB miss
E: code cache miss
12: branches
13: BTB hits
14: taken branch or BTB hit
15: pipeline flushes
16: total instructions executed
17: instructions executed in second pipe
22: floating point operations
27: hardware interrupt

I found this information in the german computer magazine "c't". It may or
may not be accurate, but usually they know what they are talking about.
Unfortunately, I neither have a P6 nor documentation about it, or maybe I
would have tried to make this more general.
I've included a small example program that tests counters 0x16 and 0x17 to
show how to use the new syscalls. Run it a few times with or without other
processes active at the same time. The counter values should not differ by
a large amount between runs, but the cycle count will differ a lot.
Comments/suggestions are appreciated.

Bernd

begin 644 diffs.tar.gz
M'XL(`"G%;#$``^T::W/;-C)?I5^Q59N.9%$R'[(LRW4:7R+W/!>[&=N7)I=D
M.!0)6:SYT!&D927U_?;;!4CJ+<OI)#<WY<:*0.PNL-P7%H!&/H^:CCL8//EZ
MH*EJN]6")T"@+GR#UM+5-D!;,PRMI1FZAEWJ?GOO":A?4:8<$AY;$<"3*`SC
M370/X?]/@4P/C21R^N"Y07+7T)I&L[.W:T7V<-<U.NW=&Q8%S-ME01Q-FI>2
M:BVZW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