From 264cf18c04e7de2c5c4051e47b9a4c32fd6f44a1 Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Thu, 5 May 2022 17:26:13 +0800 Subject: [PATCH] schedmoni: make the runq lenth more precise. The 'nr_running' of root group is the actual runq-length. We assume that the depth of a group generally does not exceed 10. Signed-off-by: Hailong Liu --- .../sched/schedmoni/bpf/schedmoni.bpf.c | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/source/tools/monitor/sched/schedmoni/bpf/schedmoni.bpf.c b/source/tools/monitor/sched/schedmoni/bpf/schedmoni.bpf.c index 44150691..4c29af8e 100644 --- a/source/tools/monitor/sched/schedmoni/bpf/schedmoni.bpf.c +++ b/source/tools/monitor/sched/schedmoni/bpf/schedmoni.bpf.c @@ -67,6 +67,23 @@ struct { #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) #define BITS_PER_LONG 64 +#define get_current_rqlen(p) ({ \ + int len = 0; \ + struct cfs_rq *cfs; \ + struct sched_entity *se, *parent; \ + se = &p->se; \ + for (int i = 0; i < 10; i++) { \ + parent = _(se->parent); \ + if (parent) \ + se = parent; \ + else \ + break; \ + } \ + cfs = BPF_CORE_READ(se, cfs_rq); \ + len = _(cfs->nr_running); \ + len; \ +}) + #define strequal(a, pcom) ({ \ bool ret = true; \ int i; \ @@ -185,7 +202,7 @@ int raw_tracepoint__sched_wakeup(struct bpf_raw_tracepoint_args *ctx) if (!program_ready()) return 0; - runqlen = BPF_CORE_READ(p, se.cfs_rq, nr_running); + runqlen = get_current_rqlen(p); return trace_enqueue(p, runqlen); } @@ -198,7 +215,7 @@ int raw_tracepoint__sched_wakeup_new(struct bpf_raw_tracepoint_args *ctx) if (!program_ready()) return 0; - runqlen = BPF_CORE_READ(p, se.cfs_rq, nr_running); + runqlen = get_current_rqlen(p); return trace_enqueue(p, runqlen); } @@ -242,7 +259,7 @@ int handle_switch(struct trace_event_raw_sched_switch *ctx) if (prev_state == TASK_RUNNING) { unsigned int runqlen = 0; - runqlen = BPF_CORE_READ(prev, se.cfs_rq, nr_running); + runqlen = get_current_rqlen(prev); return trace_enqueue(prev, runqlen); } /* fetch timestamp and calculate delta */ -- Gitee