diff mbox series

[v1,1/2] perf lock contention: Support pre-5.14 kernels

Message ID 20230408055208.1283832-1-irogers@google.com (mailing list archive)
State Not Applicable
Delegated to: BPF
Headers show
Series [v1,1/2] perf lock contention: Support pre-5.14 kernels | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Ian Rogers April 8, 2023, 5:52 a.m. UTC
struct rq's variable __lock was renamed from lock in 5.14.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/bpf_skel/lock_contention.bpf.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Namhyung Kim April 10, 2023, 3:33 p.m. UTC | #1
Hi Ian,

On Fri, Apr 7, 2023 at 10:52 PM Ian Rogers <irogers@google.com> wrote:
>
> struct rq's variable __lock was renamed from lock in 5.14.
>
> Signed-off-by: Ian Rogers <irogers@google.com>

Thanks for fixing this.

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung


> ---
>  tools/perf/util/bpf_skel/lock_contention.bpf.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/bpf_skel/lock_contention.bpf.c b/tools/perf/util/bpf_skel/lock_contention.bpf.c
> index 23f6e63544ed..8911e2a077d8 100644
> --- a/tools/perf/util/bpf_skel/lock_contention.bpf.c
> +++ b/tools/perf/util/bpf_skel/lock_contention.bpf.c
> @@ -418,6 +418,14 @@ int contention_end(u64 *ctx)
>
>  extern struct rq runqueues __ksym;
>
> +struct rq__old {
> +       raw_spinlock_t lock;
> +} __attribute__((preserve_access_index));
> +
> +struct rq__new {
> +       raw_spinlock_t __lock;
> +} __attribute__((preserve_access_index));
> +
>  SEC("raw_tp/bpf_test_finish")
>  int BPF_PROG(collect_lock_syms)
>  {
> @@ -426,11 +434,16 @@ int BPF_PROG(collect_lock_syms)
>
>         for (int i = 0; i < MAX_CPUS; i++) {
>                 struct rq *rq = bpf_per_cpu_ptr(&runqueues, i);
> +               struct rq__new *rq_new = (void *)rq;
> +               struct rq__old *rq_old = (void *)rq;
>
>                 if (rq == NULL)
>                         break;
>
> -               lock_addr = (__u64)&rq->__lock;
> +               if (bpf_core_field_exists(rq_new->__lock))
> +                       lock_addr = (__u64)&rq_new->__lock;
> +               else
> +                       lock_addr = (__u64)&rq_old->lock;
>                 lock_flag = LOCK_CLASS_RQLOCK;
>                 bpf_map_update_elem(&lock_syms, &lock_addr, &lock_flag, BPF_ANY);
>         }
> --
> 2.40.0.577.gac1e443424-goog
>
diff mbox series

Patch

diff --git a/tools/perf/util/bpf_skel/lock_contention.bpf.c b/tools/perf/util/bpf_skel/lock_contention.bpf.c
index 23f6e63544ed..8911e2a077d8 100644
--- a/tools/perf/util/bpf_skel/lock_contention.bpf.c
+++ b/tools/perf/util/bpf_skel/lock_contention.bpf.c
@@ -418,6 +418,14 @@  int contention_end(u64 *ctx)
 
 extern struct rq runqueues __ksym;
 
+struct rq__old {
+	raw_spinlock_t lock;
+} __attribute__((preserve_access_index));
+
+struct rq__new {
+	raw_spinlock_t __lock;
+} __attribute__((preserve_access_index));
+
 SEC("raw_tp/bpf_test_finish")
 int BPF_PROG(collect_lock_syms)
 {
@@ -426,11 +434,16 @@  int BPF_PROG(collect_lock_syms)
 
 	for (int i = 0; i < MAX_CPUS; i++) {
 		struct rq *rq = bpf_per_cpu_ptr(&runqueues, i);
+		struct rq__new *rq_new = (void *)rq;
+		struct rq__old *rq_old = (void *)rq;
 
 		if (rq == NULL)
 			break;
 
-		lock_addr = (__u64)&rq->__lock;
+		if (bpf_core_field_exists(rq_new->__lock))
+			lock_addr = (__u64)&rq_new->__lock;
+		else
+			lock_addr = (__u64)&rq_old->lock;
 		lock_flag = LOCK_CLASS_RQLOCK;
 		bpf_map_update_elem(&lock_syms, &lock_addr, &lock_flag, BPF_ANY);
 	}