[PATCH v17 26/47] dept: print staged wait's stacktrace on report

Byungchul Park
2025-10-02T08:13:54Z

Currently, print nothing about what event wakes up in report. However,
it makes hard to interpret dept's report.

Make it print wait's stacktrace that the event wakes up.

Signed-off-by: Byungchul Park <byungchul@sk.com>
---
include/linux/dept.h | 5 ++++
include/linux/sched.h | 2 ++
kernel/dependency/dept.c | 59 ++++++++++++++++++++++++++++++++++------
3 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/include/linux/dept.h b/include/linux/dept.h
index 236e4f06e5c8..b6dc4ff19537 100644
--- a/include/linux/dept.h
+++ b/include/linux/dept.h
@@ -227,6 +227,11 @@ struct dept_ecxt {
*/
unsigned long event_ip;
struct dept_stack *event_stack;
+
+ /*
+ * wait that this event ttwu
+ */
+ struct dept_stack *ewait_stack;
};
};
};
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 95b1450f22fa..a01c10f28dfd 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -868,6 +868,7 @@ struct dept_task {
const char *stage_w_fn;
unsigned long stage_ip;
bool stage_timeout;
+ struct dept_stack *stage_wait_stack;
arch_spinlock_t stage_lock;

/*
@@ -909,6 +910,7 @@ struct dept_task {
.stage_w_fn = NULL, \
.stage_ip = 0UL, \
.stage_timeout = false, \
+ .stage_wait_stack = NULL, \
.stage_lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED,\
.missing_ecxt = 0, \
.hardirqs_enabled = false, \
diff --git a/kernel/dependency/dept.c b/kernel/dependency/dept.c
index f928c12111fe..1c6eb0a6d0a6 100644
--- a/kernel/dependency/dept.c
+++ b/kernel/dependency/dept.c
@@ -523,6 +523,7 @@ static void initialize_ecxt(struct dept_ecxt *e)
e->enirqf = 0UL;
e->event_ip = 0UL;
e->event_stack = NULL;
+ e->ewait_stack = NULL;
}
SET_CONSTRUCTOR(ecxt, initialize_ecxt);

@@ -578,6 +579,8 @@ static void destroy_ecxt(struct dept_ecxt *e)
put_stack(e->ecxt_stack);
if (e->event_stack)
put_stack(e->event_stack);
+ if (e->ewait_stack)
+ put_stack(e->ewait_stack);
}
SET_DESTRUCTOR(ecxt, destroy_ecxt);

@@ -794,6 +797,11 @@ static void print_dep(struct dept_dep *d)

pr_warn("[E] %s(%s:%d):\n", e_fn, fc_n, fc->sub_id);
print_ip_stack(e->event_ip, e->event_stack);
+
+ if (valid_stack(e->ewait_stack)) {
+ pr_warn("(wait to wake up)\n");
+ print_ip_stack(0, e->ewait_stack);
+ }
}

if (!irqf) {
@@ -807,6 +815,11 @@ static void print_dep(struct dept_dep *d)

pr_warn("[E] %s(%s:%d):\n", e_fn, fc_n, fc->sub_id);
print_ip_stack(e->event_ip, e->event_stack);
+
+ if (valid_stack(e->ewait_stack)) {
+ pr_warn("(wait to wake up)\n");
+ print_ip_stack(0, e->ewait_stack);
+ }
}
}

@@ -1657,7 +1670,8 @@ static void add_wait(struct dept_class *c, unsigned long ip,

static struct dept_ecxt_held *add_ecxt(struct dept_map *m,
struct dept_class *c, unsigned long ip, const char *c_fn,
- const char *e_fn, int sub_l)
+ const char *e_fn, int sub_l,
+ struct dept_stack *ewait_stack)
{
struct dept_task *dt = dept_task();
struct dept_ecxt_held *eh;
@@ -1691,6 +1705,7 @@ static struct dept_ecxt_held *add_ecxt(struct dept_map *m,
e->class = get_class(c);
e->ecxt_ip = ip;
e->ecxt_stack = ip ? get_current_stack() : NULL;
+ e->ewait_stack = ewait_stack ? get_stack(ewait_stack) : NULL;
e->event_fn = e_fn;
e->ecxt_fn = c_fn;

@@ -1797,7 +1812,7 @@ static int find_hist_pos(unsigned int wg)

static void do_event(struct dept_map *m, struct dept_map *real_m,
struct dept_class *c, unsigned int wg, unsigned long ip,
- const char *e_fn)
+ const char *e_fn, struct dept_stack *ewait_stack)
{
struct dept_task *dt = dept_task();
struct dept_wait_hist *wh;
@@ -1825,7 +1840,7 @@ static void do_event(struct dept_map *m, struct dept_map *real_m,
*/
if (find_ecxt_pos(real_m, c, false) != -1)
return;
- eh = add_ecxt(m, c, 0UL, NULL, e_fn, 0);
+ eh = add_ecxt(m, c, 0UL, NULL, e_fn, 0, ewait_stack);

if (!eh)
return;
@@ -2360,7 +2375,8 @@ static void __dept_wait(struct dept_map *m, unsigned long w_f,
*/
static void __dept_event(struct dept_map *m, struct dept_map *real_m,
unsigned long e_f, unsigned long ip, const char *e_fn,
- bool sched_map, unsigned int wg)
+ bool sched_map, unsigned int wg,
+ struct dept_stack *ewait_stack)
{
struct dept_class *c;
struct dept_key *k;
@@ -2382,7 +2398,7 @@ static void __dept_event(struct dept_map *m, struct dept_map *real_m,
c = check_new_class(&m->map_key, k, sub_id(m, e), m->name, sched_map);

if (c)
- do_event(m, real_m, c, wg, ip, e_fn);
+ do_event(m, real_m, c, wg, ip, e_fn, ewait_stack);
}

void dept_wait(struct dept_map *m, unsigned long w_f,
@@ -2498,6 +2514,9 @@ static void __dept_clean_stage(struct dept_task *dt)
dt->stage_w_fn = NULL;
dt->stage_ip = 0UL;
dt->stage_timeout = false;
+ if (dt->stage_wait_stack)
+ put_stack(dt->stage_wait_stack);
+ dt->stage_wait_stack = NULL;
}

void dept_clean_stage(void)
@@ -2561,6 +2580,14 @@ void dept_request_event_wait_commit(void)

wg = next_wgen();
WRITE_ONCE(dt->stage_m.wgen, wg);
+
+ /*
+ * __schedule() can be hit multiple times between
+ * dept_stage_wait() and dept_clean_stage(). In that case,
+ * keep the first stacktrace only. That's enough.
+ */
+ if (!dt->stage_wait_stack)
+ dt->stage_wait_stack = get_current_stack();
arch_spin_unlock(&dt->stage_lock);

__dept_wait(&dt->stage_m, 1UL, ip, w_fn, 0, true, sched_map, timeout);
@@ -2579,6 +2606,7 @@ void dept_ttwu_stage_wait(struct task_struct *requestor, unsigned long ip)
struct dept_map m;
struct dept_map *real_m;
bool sched_map;
+ struct dept_stack *ewait_stack;

if (unlikely(!dept_working()))
return;
@@ -2597,6 +2625,10 @@ void dept_ttwu_stage_wait(struct task_struct *requestor, unsigned long ip)
m = dt_req->stage_m;
sched_map = dt_req->stage_sched_map;
real_m = dt_req->stage_real_m;
+ ewait_stack = dt_req->stage_wait_stack;
+ if (ewait_stack)
+ get_stack(ewait_stack);
+
__dept_clean_stage(dt_req);
arch_spin_unlock(&dt_req->stage_lock);

@@ -2607,8 +2639,12 @@ void dept_ttwu_stage_wait(struct task_struct *requestor, unsigned long ip)
if (!m.keys)
goto exit;

- __dept_event(&m, real_m, 1UL, ip, "try_to_wake_up", sched_map, m.wgen);
+ __dept_event(&m, real_m, 1UL, ip, "try_to_wake_up", sched_map,
+ m.wgen, ewait_stack);
exit:
+ if (ewait_stack)
+ put_stack(ewait_stack);
+
dept_exit(flags);
}

@@ -2688,7 +2724,7 @@ void dept_map_ecxt_modify(struct dept_map *m, unsigned long e_f,
k = m->keys ?: &m->map_key;
c = check_new_class(&m->map_key, k, sub_id(m, new_e), m->name, false);

- if (c && add_ecxt(m, c, new_ip, new_c_fn, new_e_fn, new_sub_l))
+ if (c && add_ecxt(m, c, new_ip, new_c_fn, new_e_fn, new_sub_l, NULL))
goto exit;

/*
@@ -2740,7 +2776,7 @@ void dept_ecxt_enter(struct dept_map *m, unsigned long e_f, unsigned long ip,
k = m->keys ?: &m->map_key;
c = check_new_class(&m->map_key, k, sub_id(m, e), m->name, false);

- if (c && add_ecxt(m, c, ip, c_fn, e_fn, sub_l))
+ if (c && add_ecxt(m, c, ip, c_fn, e_fn, sub_l, NULL))
goto exit;
missing_ecxt:
dt->missing_ecxt++;
@@ -2840,7 +2876,7 @@ void dept_event(struct dept_map *m, unsigned long e_f,

flags = dept_enter();

- __dept_event(m, m, e_f, ip, e_fn, false, READ_ONCE(*wg_p));
+ __dept_event(m, m, e_f, ip, e_fn, false, READ_ONCE(*wg_p), NULL);

/*
* Keep the map diabled until the next sleep.
@@ -2912,6 +2948,11 @@ void dept_task_exit(struct task_struct *t)
dt->stack = NULL;
}

+ if (dt->stage_wait_stack) {
+ put_stack(dt->stage_wait_stack);
+ dt->stage_wait_stack = NULL;
+ }
+
for (i = 0; i < dt->ecxt_held_pos; i++) {
if (dt->ecxt_held[i].class) {
put_class(dt->ecxt_held[i].class);
--
2.17.1