Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scx_layered: Add stats for XNUMA/XLLC migrations #648

Merged
merged 2 commits into from
Sep 12, 2024

Conversation

hodgesds
Copy link
Contributor

@hodgesds hodgesds commented Sep 11, 2024

Add stats for XNUMA/XLLC migrations. An example of the output is shown:

tot=  21282 local=97.47 open_idle=48.81 affn_viol= 0.00 proc=4ms
busy=  2.2 util=  166.0 load=   2039.1 fallback_cpu=  0
excl_coll=0.07 excl_preempt=0.00 excl_idle=0.05 excl_wakeup=0.04
  hodgesd  : util/frac=    5.8/  3.5 load/frac=      6.2/  0.3 tasks=   747
             tot=   4100 local=93.17 wake/exp/reenq= 6.83/ 0.00/ 0.00
             keep/max/busy= 0.02/ 0.00/ 0.00 kick= 0.00 yield/ign= 0.22/    0 
             open_idle= 0.00 mig= 7.07 xnuma_mig= 4.63 xllc_mig= 4.63 affn_viol= 0.00
             preempt/first/idle/fail= 0.00/ 0.00/ 0.00/ 0.00 min_exec= 0.00/   0.00ms
             cpus=  2 [  2,  2] 00000000 00000010 00001000
  normal   : util/frac=  160.2/ 96.5 load/frac=   2032.8/ 99.7 tasks=  4164
             tot=  17182 local=98.50 wake/exp/reenq= 1.12/ 0.38/ 0.00
             keep/max/busy= 2.27/ 0.00/ 0.00 kick= 0.38 yield/ign= 0.12/  312 
             open_idle=60.46 mig=10.01 xnuma_mig= 7.62 xllc_mig= 7.62 affn_viol= 0.00
             preempt/first/idle/fail= 0.01/ 0.00/ 0.80/ 0.32 min_exec= 0.00/   0.00ms
             cpus=  4 [  4,  4] 30000000 00000000 00000030
             excl_coll= 0.08 excl_preempt= 0.00

This was tested on a machine with two NUMA nodes and two LLCs so the xnuma_mig == xllc_mig.

s32 task_cpu = scx_bpf_task_cpu(p);

if (!(cctx = lookup_cpu_ctx(-1)) || !(tctx = lookup_task_ctx(p)) ||
!(layer = lookup_layer(tctx->layer)))
return;

if (tctx->last_cpu >= 0 && tctx->last_cpu != task_cpu)
if (tctx->last_cpu >= 0 && tctx->last_cpu != task_cpu) {
if (!(nodec = lookup_node_ctx(cctx->node_idx)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only doing the lookup for the node_ctx/cache_ctx on migration, figure it saves a few lookups.

return ret;
}

static s32 create_cache(u32 cache_id)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method probably should have existed for awhile, but I hadn't had a use for the cache_ctx yet.

Add stats for XNUMA/XLLC migrations. An example of the output is shown:
```
  hodgesd  : util/frac=    5.4/  0.1 load/frac=    301.0/  0.3 tasks=   476
             tot=   3168 local=97.82 wake/exp/reenq= 2.18/ 0.00/ 0.00
             keep/max/busy= 0.03/ 0.00/ 0.03 kick= 0.00 yield/ign= 0.09/    0
             open_idle= 0.00 mig= 6.82 xnuma_mig= 6.82 xllc_mig= 4.86 affn_viol= 0.00
             preempt/first/idle/fail= 0.00/ 0.00/ 0.00/ 0.00 min_exec= 0.00/   0.00ms
             cpus=  2 [  2,  4] 00000000 00000010 00001000
  normal   : util/frac=   28.7/  0.7 load/frac= 101704.7/ 95.8 tasks=  2450
             tot=   4660 local=99.06 wake/exp/reenq= 0.88/ 0.06/ 0.00
             keep/max/busy= 1.03/ 0.00/ 0.00 kick= 0.06 yield/ign= 0.04/  400
             open_idle=15.73 mig=23.45 xnuma_mig=23.45 xllc_mig= 3.07 affn_viol= 0.00
             preempt/first/idle/fail= 0.00/ 0.00/ 0.00/ 0.88 min_exec= 0.00/   0.00ms
             cpus=  2 [  2,  2] 00000001 00000100 00000000
             excl_coll=12.55 excl_preempt= 0.00
  random   : util/frac=    0.0/  0.0 load/frac=      0.0/  0.0 tasks=     0
             tot=      0 local= 0.00 wake/exp/reenq= 0.00/ 0.00/ 0.00
             keep/max/busy= 0.00/ 0.00/ 0.00 kick= 0.00 yield/ign= 0.00/    0
             open_idle= 0.00 mig= 0.00 xnuma_mig= 0.00 xllc_mig= 0.00 affn_viol= 0.00
             preempt/first/idle/fail= 0.00/ 0.00/ 0.00/ 0.00 min_exec= 0.00/   0.00ms
             cpus=  0 [  0,  0] 00000000 00000000 00000000
             excl_coll= 0.00 excl_preempt= 0.00
  stress-ng: util/frac= 4189.1/ 99.2 load/frac=   4200.0/  4.0 tasks=    43
             tot=     62 local= 0.00 wake/exp/reenq= 0.00/100.0/ 0.00
             keep/max/busy=2433.9/177.4/ 0.00 kick=100.0 yield/ign= 3.23/    0
             open_idle= 0.00 mig=54.84 xnuma_mig=54.84 xllc_mig=35.48 affn_viol= 0.00
             preempt/first/idle/fail= 0.00/ 0.00/ 0.00/ 0.00 min_exec= 0.00/   0.00ms
             cpus=  4 [  4,  4] 00000300 00030000 00000000
             excl_coll= 0.00 excl_preempt= 0.00
```

Signed-off-by: Daniel Hodges <[email protected]>
@@ -147,6 +144,30 @@ struct {
__uint(map_flags, 0);
} node_data SEC(".maps");

static struct node_ctx *lookup_node_ctx(u32 node)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably make this node_idx to be consistent...

Initialize the node cpumask, which was previously uninitialized causing
metric calculations to be wrong when attempting to lookup CPUs in the
node cpumask.

Signed-off-by: Daniel Hodges <[email protected]>
@hodgesds
Copy link
Contributor Author

Tested the NUMA mask with:

diff --git a/scheds/rust/scx_layered/src/bpf/main.bpf.c b/scheds/rust/scx_layered/src/bpf/main.bpf.c
index c9f2565..f548e5e 100644
--- a/scheds/rust/scx_layered/src/bpf/main.bpf.c
+++ b/scheds/rust/scx_layered/src/bpf/main.bpf.c
@@ -1214,20 +1214,21 @@ static s32 create_node(u32 node_id)
                const volatile u64 *nmask;
 
                nmask = MEMBER_VPTR(numa_cpumasks, [node_id][cpu / 64]);
                if (!nmask) {
                        scx_bpf_error("array index error");
                        ret = -ENOENT;
                        break;
                }
 
                if (*nmask & (1LLU << (cpu % 64))) {
+                       dbg("adding cpu %llu to node %llu mask", cpu, node_id);
                        bpf_cpumask_set_cpu(cpu, cpumask);
                        if (!(cctx = lookup_cpu_ctx(-1))) {
                                scx_bpf_error("cpu ctx error");
                                ret = -ENOENT;
                                break;
                        }
                        cctx->node_idx = node_id;
                }
        }

and output:

$ lscpu  |grep -i node
NUMA node(s):                         2
NUMA node0 CPU(s):                    0-19,40-59
NUMA node1 CPU(s):                    20-39,60-79
$ sudo bpftool prog trace  | grep -e 'adding' 
_layered-2146586 [012] ....1 1663887.500134: bpf_trace_printk: adding cpu 22 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500134: bpf_trace_printk: adding cpu 23 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500134: bpf_trace_printk: adding cpu 24 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500135: bpf_trace_printk: adding cpu 25 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500135: bpf_trace_printk: adding cpu 26 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500135: bpf_trace_printk: adding cpu 27 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500136: bpf_trace_printk: adding cpu 28 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500136: bpf_trace_printk: adding cpu 29 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500136: bpf_trace_printk: adding cpu 30 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500136: bpf_trace_printk: adding cpu 31 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500137: bpf_trace_printk: adding cpu 32 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500137: bpf_trace_printk: adding cpu 33 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500137: bpf_trace_printk: adding cpu 34 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500138: bpf_trace_printk: adding cpu 35 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500138: bpf_trace_printk: adding cpu 36 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500138: bpf_trace_printk: adding cpu 37 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500139: bpf_trace_printk: adding cpu 38 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500139: bpf_trace_printk: adding cpu 39 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500139: bpf_trace_printk: adding cpu 60 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500140: bpf_trace_printk: adding cpu 61 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500140: bpf_trace_printk: adding cpu 62 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500140: bpf_trace_printk: adding cpu 63 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500141: bpf_trace_printk: adding cpu 64 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500141: bpf_trace_printk: adding cpu 65 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500141: bpf_trace_printk: adding cpu 66 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500142: bpf_trace_printk: adding cpu 67 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500142: bpf_trace_printk: adding cpu 68 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500142: bpf_trace_printk: adding cpu 69 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500143: bpf_trace_printk: adding cpu 70 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500143: bpf_trace_printk: adding cpu 71 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500143: bpf_trace_printk: adding cpu 72 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500144: bpf_trace_printk: adding cpu 73 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500144: bpf_trace_printk: adding cpu 74 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500144: bpf_trace_printk: adding cpu 75 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500145: bpf_trace_printk: adding cpu 76 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500145: bpf_trace_printk: adding cpu 77 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500145: bpf_trace_printk: adding cpu 78 to node 1 mask
    scx_layered-2146586 [012] ....1 1663887.500146: bpf_trace_printk: adding cpu 79 to node 1 mask

@hodgesds hodgesds merged commit 632fcfe into sched-ext:main Sep 12, 2024
1 of 2 checks passed
@hodgesds hodgesds deleted the layered-llc-stats branch September 12, 2024 17:24
hodgesds added a commit to hodgesds/scx that referenced this pull request Sep 12, 2024
scx_layered: Add stats for XNUMA/XLLC migrations
hodgesds added a commit to hodgesds/scx that referenced this pull request Sep 12, 2024
scx_layered: Add stats for XNUMA/XLLC migrations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants