lockstat tweaks

上级 34b8eecf
......@@ -24,7 +24,7 @@ stats(void)
if (fd < 0)
die("lockstat: open failed");
printf(1, "## name cycles acquires\n");
printf(1, "## name acquires locking locked\n");
while (1) {
r = read(fd, &ls, sz);
if (r < 0)
......@@ -34,13 +34,16 @@ stats(void)
if (r != sz)
die("lockstat: unexpected read");
u64 cycles = 0, acquires = 0;
u64 acquires = 0, locking = 0, locked = 0;
for (int i = 0; i < NCPU; i++) {
cycles += ls.cpu[i].cycles;
acquires += ls.cpu[i].acquires;
locking += ls.cpu[i].locking;
locked += ls.cpu[i].locked;
}
printf(1, "%s %lu %lu\n", ls.name, cycles, acquires);
if (acquires > 0)
printf(1, "%s %lu %lu %lu\n",
ls.name, acquires, locking, locked);
}
}
......
......@@ -2,7 +2,10 @@
struct cpulockstat {
u64 acquires;
u64 cycles;
u64 locking;
u64 locked;
u64 locking_ts;
u64 locked_ts;
__padout__;
} __mpalign__;
......
......@@ -13,6 +13,12 @@
#if LOCKSTAT
static int lockstat_enable;
static inline struct cpulockstat *
mylockstat(struct spinlock *lk)
{
return &lk->stat->s.cpu[cpunum()];
}
#endif
static inline void
......@@ -25,6 +31,11 @@ locking(struct spinlock *lk)
}
#endif
#if LOCKSTAT
if (lockstat_enable && lk->stat != NULL)
mylockstat(lk)->locking_ts = rdtsc();
#endif
mtlock(lk);
}
......@@ -41,7 +52,9 @@ locked(struct spinlock *lk)
#if LOCKSTAT
if (lockstat_enable && lk->stat != NULL) {
lk->stat->s.cpu[cpunum()].acquires++;
struct cpulockstat *s = mylockstat(lk);
s->acquires++;
s->locked_ts = rdtsc();
}
#endif
}
......@@ -62,6 +75,15 @@ releasing(struct spinlock *lk)
lk->pcs[0] = 0;
lk->cpu = 0;
#endif
#if LOCKSTAT
if (lockstat_enable && lk->stat != NULL) {
struct cpulockstat *s = mylockstat(lk);
u64 ts = rdtsc();
s->locking += ts - s->locking_ts;
s->locked += ts - s->locked_ts;
}
#endif
}
// Check whether this cpu is holding the lock.
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论