提交 e695136b 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Start of some sampling code.

上级 104d3497
......@@ -132,6 +132,7 @@ void lapic_tlbflush(u32);
// mp.c
extern int ncpu;
int mpbcpu(void);
// ns.c
enum {
......@@ -208,6 +209,7 @@ void migrate(struct proc *);
extern int profenable;
void profreset(void);
void profdump(void);
void profstart(void);
// rcu.c
void rcuinit(void);
......
......@@ -6,12 +6,16 @@
#include "file.h"
#include "prof.h"
#include "kernel.h"
#include "bits.h"
#include "amd64.h"
extern profctr_t sprof[];
extern profctr_t eprof[];
int profenable;
static void (*profconfig)(u64 ctr, u64 sel, u64 val);
void
profreset(void)
{
......@@ -41,3 +45,67 @@ profdump(void)
cprintf("%s %lu\n", p->name, tot/cnt);
}
}
static void
amdconfig(u64 ctr, u64 sel, u64 val)
{
writemsr(MSR_AMD_PERF_SEL0 | ctr, 0);
writemsr(MSR_AMD_PERF_CNT0 | ctr, val);
writemsr(MSR_AMD_PERF_SEL0 | ctr, sel);
}
static void
intelconfig(u64 ctr, u64 sel, u64 val)
{
writemsr(MSR_INTEL_PERF_SEL0 | ctr, 0);
writemsr(MSR_INTEL_PERF_CNT0 | ctr, val);
writemsr(MSR_INTEL_PERF_SEL0 | ctr, sel);
}
void
profstart(void)
{
u64 ctr = 0;
u64 sel = 0;
u64 val = -1000;
cprintf("profstart ...\n");
sel = 0UL << 32 |
1 << 24 |
1 << 22 |
1 << 20 |
1 << 17 |
1 << 16 |
0x00 << 8 |
0x76;
pushcli();
profconfig(ctr, sel, val);
popcli();
cprintf("rdpmc %lx\n", rdpmc(0));
}
void
initprof(void)
{
if (cpunum() == mpbcpu()) {
u32 name[4];
char *s = (char *)name;
name[3] = 0;
cpuid(0, 0, &name[0], &name[2], &name[1]);
cprintf("%s\n", s);
if (strcmp(s, "AuthenticAMD"))
profconfig = amdconfig;
else if (strcmp(s, "GenuineIntel"))
profconfig = intelconfig;
else
panic("Unknown Manufacturer");
}
// enable RDPMC at CPL > 0
u64 cr4 = rcr4();
lcr4(cr4 | CR4_PCE);
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论