|
|
@@ -50,8 +50,31 @@ static struct {
|
|
|
struct process *owner;
|
|
|
unsigned int depth;
|
|
|
struct wait_queue wait;
|
|
|
+ unsigned int since; /* get_ticks_ms() when the owner took it */
|
|
|
} bkl;
|
|
|
|
|
|
+/* BKL contention, for `sched`: how often a taker had to sleep, the total
|
|
|
+ * wait, and the longest single hold with its holder (reset when printed).
|
|
|
+ * Every syscall takes the lock, so a long holder stalls ring-3 work on the
|
|
|
+ * other CPUs. */
|
|
|
+static struct {
|
|
|
+ unsigned int contended, wait_ms, hold_max_ms;
|
|
|
+ char hold_max_name[PROC_NAME_LEN];
|
|
|
+} bkl_stat;
|
|
|
+
|
|
|
+static void bkl_note_release(struct process *p)
|
|
|
+{
|
|
|
+ unsigned int held = get_ticks_ms() - bkl.since;
|
|
|
+ unsigned int i;
|
|
|
+
|
|
|
+ if (held <= bkl_stat.hold_max_ms)
|
|
|
+ return;
|
|
|
+ bkl_stat.hold_max_ms = held;
|
|
|
+ for (i = 0; i + 1 < PROC_NAME_LEN && p->name[i]; i++)
|
|
|
+ bkl_stat.hold_max_name[i] = p->name[i];
|
|
|
+ bkl_stat.hold_max_name[i] = '\0';
|
|
|
+}
|
|
|
+
|
|
|
unsigned int sched_lock_acquire(void)
|
|
|
{
|
|
|
unsigned int flags = spin_irq_save_disable();
|
|
|
@@ -389,6 +412,8 @@ void bkl_lock(void)
|
|
|
|
|
|
if (!p)
|
|
|
return;
|
|
|
+ unsigned int t0 = 0;
|
|
|
+
|
|
|
if (bkl.owner == p) {
|
|
|
bkl.depth++;
|
|
|
return;
|
|
|
@@ -398,9 +423,16 @@ void bkl_lock(void)
|
|
|
if (!bkl.owner) {
|
|
|
bkl.owner = p;
|
|
|
bkl.depth = 1;
|
|
|
+ bkl.since = get_ticks_ms();
|
|
|
+ if (t0)
|
|
|
+ bkl_stat.wait_ms += bkl.since - t0;
|
|
|
sched_lock_release(flags);
|
|
|
return;
|
|
|
}
|
|
|
+ if (!t0) {
|
|
|
+ t0 = get_ticks_ms();
|
|
|
+ bkl_stat.contended++;
|
|
|
+ }
|
|
|
sched_block_on_locked(&bkl.wait);
|
|
|
sched_lock_release(flags);
|
|
|
sched_yield();
|
|
|
@@ -419,6 +451,7 @@ void bkl_unlock(void)
|
|
|
if (bkl.depth > 1) {
|
|
|
bkl.depth--;
|
|
|
} else {
|
|
|
+ bkl_note_release(p);
|
|
|
bkl.owner = 0;
|
|
|
bkl.depth = 0;
|
|
|
wake_one_locked(&bkl.wait);
|
|
|
@@ -442,6 +475,7 @@ int bkl_trylock(void)
|
|
|
if (!bkl.owner) {
|
|
|
bkl.owner = p;
|
|
|
bkl.depth = 1;
|
|
|
+ bkl.since = get_ticks_ms();
|
|
|
sched_lock_release(flags);
|
|
|
return 1;
|
|
|
}
|
|
|
@@ -462,6 +496,7 @@ static void bkl_yield_release(void)
|
|
|
flags = sched_lock_acquire();
|
|
|
if (bkl.owner == p) {
|
|
|
p->bkl_saved = bkl.depth;
|
|
|
+ bkl_note_release(p);
|
|
|
bkl.owner = 0;
|
|
|
bkl.depth = 0;
|
|
|
wake_one_locked(&bkl.wait);
|
|
|
@@ -907,4 +942,18 @@ void sched_print(void)
|
|
|
io_putchar('.');
|
|
|
io_putchar((char)('0' + idle_pm % 10));
|
|
|
io_putstr("%\n");
|
|
|
+ /* Since the last `sched`. */
|
|
|
+ io_putstr("bkl: contended ");
|
|
|
+ sched_put_dec(bkl_stat.contended);
|
|
|
+ io_putstr(" waited ");
|
|
|
+ sched_put_dec(bkl_stat.wait_ms);
|
|
|
+ io_putstr(" ms longest hold ");
|
|
|
+ sched_put_dec(bkl_stat.hold_max_ms);
|
|
|
+ io_putstr(" ms (");
|
|
|
+ io_putstr(bkl_stat.hold_max_name[0] ? bkl_stat.hold_max_name : "-");
|
|
|
+ io_putstr(")\n");
|
|
|
+ bkl_stat.contended = 0;
|
|
|
+ bkl_stat.wait_ms = 0;
|
|
|
+ bkl_stat.hold_max_ms = 0;
|
|
|
+ bkl_stat.hold_max_name[0] = '\0';
|
|
|
}
|