diff --git a/examples/cgroup-rstat-flushing.bpf.c b/examples/cgroup-rstat-flushing.bpf.c index 29ccd78e..5277b433 100644 --- a/examples/cgroup-rstat-flushing.bpf.c +++ b/examples/cgroup-rstat-flushing.bpf.c @@ -45,6 +45,13 @@ struct { __type(value, u64); } cgroup_rstat_locked_yield SEC(".maps"); +/* Per cgroup level lock contended counter */ +struct { + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __uint(max_entries, MAX_CGRP_LEVELS + 1); + __type(key, u32); + __type(value, u64); +} cgroup_rstat_lock_contended SEC(".maps"); /** Measurement#1: lock rates * ========================= @@ -76,6 +83,20 @@ int BPF_PROG(rstat_locked, struct cgroup *cgrp, int cpu, bool contended) (*cnt)++; } + /* What cgrp level is interesting, but I didn't manage to encode it in + * above counters. As contended case is the most interesting, have + * level counter for contended. + */ + if (contended) { + u32 level = cgrp->level; + + if (level > MAX_CGRP_LEVELS) + level = MAX_CGRP_LEVELS; + + read_array_ptr(&cgroup_rstat_lock_contended, &level, cnt); + (*cnt)++; + } + return 0; } diff --git a/examples/cgroup-rstat-flushing.yaml b/examples/cgroup-rstat-flushing.yaml index fe166061..5fb8eb17 100644 --- a/examples/cgroup-rstat-flushing.yaml +++ b/examples/cgroup-rstat-flushing.yaml @@ -21,4 +21,11 @@ metrics: size: 4 decoders: # contended boolean converted to 0 and 1 - name: uint + - name: cgroup_rstat_lock_contended + help: Lock contention counters per cgroup level + labels: + - name: level + size: 4 + decoders: + - name: uint