A hack to help filter idle time from perf-report

上级 60503d75
...@@ -185,6 +185,7 @@ void sampstart(void); ...@@ -185,6 +185,7 @@ void sampstart(void);
int sampintr(struct trapframe*); int sampintr(struct trapframe*);
void sampdump(void); void sampdump(void);
void sampconf(void); void sampconf(void);
void sampidle(bool);
// sched.cc // sched.cc
void addrun(struct proc *); void addrun(struct proc *);
......
...@@ -9,6 +9,7 @@ struct sampconf { ...@@ -9,6 +9,7 @@ struct sampconf {
#define NTRACE 4 #define NTRACE 4
struct pmuevent { struct pmuevent {
u8 idle:1;
u64 rip; u64 rip;
uptr trace[NTRACE]; uptr trace[NTRACE];
}; };
......
...@@ -93,10 +93,12 @@ idleloop(void) ...@@ -93,10 +93,12 @@ idleloop(void)
mtstart(idleloop, myproc()); mtstart(idleloop, myproc());
sti(); sti();
sampidle(true);
for (;;) { for (;;) {
acquire(&myproc()->lock); acquire(&myproc()->lock);
myproc()->set_state(RUNNABLE); myproc()->set_state(RUNNABLE);
sched(); sched();
sampidle(true);
finishzombies(); finishzombies();
......
...@@ -26,6 +26,7 @@ struct pmu pmu; ...@@ -26,6 +26,7 @@ struct pmu pmu;
struct pmulog { struct pmulog {
u64 count; u64 count;
u64 capacity; u64 capacity;
u8 idle:1; // Currently idle?
struct pmuevent *event; struct pmuevent *event;
__padout__; __padout__;
} __mpalign__; } __mpalign__;
...@@ -71,6 +72,12 @@ sampdump(void) ...@@ -71,6 +72,12 @@ sampdump(void)
} }
void void
sampidle(bool b)
{
pmulog[myid()].idle = b;
}
void
sampconf(void) sampconf(void)
{ {
pushcli(); pushcli();
...@@ -105,6 +112,7 @@ samplog(struct trapframe *tf) ...@@ -105,6 +112,7 @@ samplog(struct trapframe *tf)
e = &l->event[l->count]; e = &l->event[l->count];
e->idle = l->idle;
e->rip = tf->rip; e->rip = tf->rip;
getcallerpcs((void*)tf->rbp, e->trace, NELEM(e->trace)); getcallerpcs((void*)tf->rbp, e->trace, NELEM(e->trace));
l->count++; l->count++;
......
...@@ -71,6 +71,8 @@ sched(void) ...@@ -71,6 +71,8 @@ sched(void)
release(&myproc()->lock); release(&myproc()->lock);
return; return;
} }
} else {
sampidle(false);
} }
if (next->get_state() != RUNNABLE) if (next->get_state() != RUNNABLE)
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "include/sampler.h" #include "include/sampler.h"
static bool stacktrace_mode = true; static bool stacktrace_mode = true;
static bool ignoreidle_mode = false;
static void __attribute__((noreturn)) static void __attribute__((noreturn))
edie(const char* errstr, ...) edie(const char* errstr, ...)
...@@ -199,8 +200,8 @@ print_entry(Addr2line &addr2line, int count, struct pmuevent *e) ...@@ -199,8 +200,8 @@ print_entry(Addr2line &addr2line, int count, struct pmuevent *e)
char *file; char *file;
int line; int line;
addr2line.lookup(e->rip, &func, &file, &line); addr2line.lookup(e->rip, &func, &file, &line);
printf("%-10u %016"PRIx64" %s:%u %s\n", printf("%-8u %4s %016"PRIx64" %s:%u %s\n",
count, e->rip, file, line, func); count, e->idle?"idle":"", e->rip, file, line, func);
free(func); free(func);
free(file); free(file);
...@@ -211,7 +212,7 @@ print_entry(Addr2line &addr2line, int count, struct pmuevent *e) ...@@ -211,7 +212,7 @@ print_entry(Addr2line &addr2line, int count, struct pmuevent *e)
if (e->trace[i] == 0) if (e->trace[i] == 0)
break; break;
addr2line.lookup(e->trace[i], &func, &file, &line); addr2line.lookup(e->trace[i], &func, &file, &line);
printf(" %016"PRIx64" %s:%u %s\n", printf(" %016"PRIx64" %s:%u %s\n",
e->trace[i], file, line, func); e->trace[i], file, line, func);
free(func); free(func);
free(file); free(file);
...@@ -264,6 +265,8 @@ main(int ac, char **av) ...@@ -264,6 +265,8 @@ main(int ac, char **av)
p = (struct pmuevent*)(x + header->cpu[i].offset); p = (struct pmuevent*)(x + header->cpu[i].offset);
q = (struct pmuevent*)(x + header->cpu[i].offset + header->cpu[i].size); q = (struct pmuevent*)(x + header->cpu[i].offset + header->cpu[i].size);
for (; p < q; p++) { for (; p < q; p++) {
if (ignoreidle_mode && p->idle)
continue;
auto it = map.find(p); auto it = map.find(p);
if (it == map.end()) if (it == map.end())
map[p] = 1; map[p] = 1;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论