From: Ed L Cashin <ecashin@uga.edu>
To: sparclinux@vger.kernel.org
Subject: using perfctr to determine cache miss rate
Date: Sat, 21 Feb 2004 03:23:47 +0000 [thread overview]
Message-ID: <87u11l6rp8.fsf@uga.edu> (raw)
Hi. I'm starting to use the sparc64-specific perfctr system call,
after reading the UltraSPARC IIi User's Manual Appendix B on
Performance Instrumentation.
What I really want to do is to find out how often loads and stores are
having to go out to RAM instead of hitting in "the cache" (any cache).
Specifically, I'm interested in whether the loads and stores in a
running userspace program are low-latency or high-latency.
I wrote the test program below, which observes the number of dcache
read misses between calls. In conjunction with the tick register, I
could efficiently estimate the miss rate on dcache reads.
Is there a way to measure the number of memory accesses (both reads
and writes) that are not hitting in any cache? It appears not to be
possible, since only two events can be observed at once, and the
events are quite specific (e.g. observing dcache write hits makes
dcache read hits unobservable).
/* main.c - try out sparc64 the kernel's performance counter exporting
*/
#include <stdio.h>
#include <stdlib.h>
#include <linux/unistd.h>
#include <asm-sparc64/perfctr.h>
#include <errno.h>
_syscall4(int, perfctr, int, opcode,
unsigned long, arg0, unsigned long, arg1, unsigned long, arg2);
unsigned long long d0; /* dc reads */
unsigned long long d1; /* dc read hits */
void usemem(void)
{
static unsigned int data[10];
int i;
for (i = 0; i < 1000; ++i) {
unsigned int n = data[random() % 10];
data[random() % 10] = n;
}
}
void test(void)
{
usemem();
printf("after usemem dc read misses:0x%016llx\n", d0 - d1);
if (perfctr(PERFCTR_READ, 0,0,0)) {
perror("read");
exit(EXIT_FAILURE);
}
}
int main(void)
{
unsigned long pcr = USR|DC_RD|DC_RD_HIT;
int i;
if (perfctr(PERFCTR_ON,
(unsigned long) &d0,
(unsigned long) &d1,
pcr)) {
perror("turn on");
exit(EXIT_FAILURE);
}
for (i = 0; i < 100; ++i)
test();
if (perfctr(PERFCTR_OFF, 0,0,0)) {
perror("turn off");
exit(EXIT_FAILURE);
}
return 0;
}
--
--Ed L Cashin | PGP public key:
ecashin@uga.edu | http://noserose.net/e/pgp/
next reply other threads:[~2004-02-21 3:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-21 3:23 Ed L Cashin [this message]
2004-02-21 3:37 ` using perfctr to determine cache miss rate David S. Miller
2004-03-02 1:28 ` Ed L Cashin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87u11l6rp8.fsf@uga.edu \
--to=ecashin@uga.edu \
--cc=sparclinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.