From nobody Thu Sep 18 04:35:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B60EC04FDE for ; Fri, 9 Dec 2022 19:07:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229821AbiLITHm (ORCPT ); Fri, 9 Dec 2022 14:07:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230108AbiLITHe (ORCPT ); Fri, 9 Dec 2022 14:07:34 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9101F269; Fri, 9 Dec 2022 11:07:32 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id gt4so4080691pjb.1; Fri, 09 Dec 2022 11:07:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=+aIrSZH4sRTZgzrgB2QgBuSdHXwS+g9LIfT5ra6cPpo=; b=dXe8IdfvQ+WkhgsDLHpK9Cf5WKvXRnGBRR7pXw9a5+4bMTBnPKDMbh1G9Cu1yIb2h0 R/4dfG3wqUM8tNQ3TyxGGPGR9oG/b9OGGXXH76vh/QODEiGyYMAlzNxVTejXPwo9JMAQ ouGk/kmcDLub+zvBHGQ9adOfc9hHXjiK6i1eYusEv+j9kWwfMj8DIPMgfaq8nNBKBdR2 CqavnjMd+bIoXuuc8vK4OqGLqrnPLdaqaLixW3u02I+TKMazu/oPnEvcyKqe+hN6SYHu N82NbB+41U8MCk5GvQ4G82S5Rn9r7Jlf5M94HhGkxdg5bOQPIAIdx8qDJWjblx84ZYTV w1Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+aIrSZH4sRTZgzrgB2QgBuSdHXwS+g9LIfT5ra6cPpo=; b=4wjvcGle6MWBAQLsJZEYqFEGYjWMVzgJBQlQErSsfyQtkRmw+g2NKkR4+pDY9ts1U3 A1yRL1i2LiXF7Hzr81JB9NQeOp6ayuI330trZCo42hybG1w3U0tFuplusAud0KCcrI2C xSx3M/DNUoUyRiL3eOdTuCwCAUfbmMvzfQOswrgEQK+S6qIQDclHmdejlTODBFrdBawr 0pKbUf9gLxMK0eRLXYElmmpydn3eelUjvByDqKdEI5xNYmat200f7AFGydGoPfazeqna Z8REdmO22pPasqvxCvTXW6OfnsapWqFmEH5PGoX93JFyvxAHCmu8mtgMWNhoiYymEKtA h+cA== X-Gm-Message-State: ANoB5ploj0zO4jThF/Klc33Tj0sKKAzq1j+v2IpqjjPC2YV3sYKwlE6b NZtMM2UI3Srn5e0pOSWTZ/k= X-Google-Smtp-Source: AA0mqf452IZZuqO+6BdXUcXpbSb7XvVI7Feo29T4TiuAtd1nvcY9yrpXmupI0HRWs4Wrtfb1tIXuDg== X-Received: by 2002:a17:90a:7646:b0:219:756b:ec1e with SMTP id s6-20020a17090a764600b00219756bec1emr6813537pjl.28.1670612851956; Fri, 09 Dec 2022 11:07:31 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:ff0:c952:d848:9e00:3cce]) by smtp.gmail.com with ESMTPSA id nd17-20020a17090b4cd100b002135de3013fsm1431432pjb.32.2022.12.09.11.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 11:07:31 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Song Liu , Blake Jones , bpf@vger.kernel.org Subject: [PATCH 1/4] perf lock contention: Add lock_data.h for common data Date: Fri, 9 Dec 2022 11:07:24 -0800 Message-Id: <20221209190727.759804-2-namhyung@kernel.org> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog In-Reply-To: <20221209190727.759804-1-namhyung@kernel.org> References: <20221209190727.759804-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Accessing BPF maps should use the same data types. Add bpf_skel/lock_data.h to define the common data structures. No functional changes. Signed-off-by: Namhyung Kim --- tools/perf/util/bpf_lock_contention.c | 19 ++++-------- .../perf/util/bpf_skel/lock_contention.bpf.c | 17 ++--------- tools/perf/util/bpf_skel/lock_data.h | 30 +++++++++++++++++++ 3 files changed, 38 insertions(+), 28 deletions(-) create mode 100644 tools/perf/util/bpf_skel/lock_data.h diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lo= ck_contention.c index f4ebb9a2e380..b6a8eb7164b3 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -12,17 +12,10 @@ #include =20 #include "bpf_skel/lock_contention.skel.h" +#include "bpf_skel/lock_data.h" =20 static struct lock_contention_bpf *skel; =20 -struct lock_contention_data { - u64 total_time; - u64 min_time; - u64 max_time; - u32 count; - u32 flags; -}; - int lock_contention_prepare(struct lock_contention *con) { int i, fd; @@ -110,8 +103,8 @@ int lock_contention_stop(void) int lock_contention_read(struct lock_contention *con) { int fd, stack, err =3D 0; - s32 prev_key, key; - struct lock_contention_data data =3D {}; + struct contention_key *prev_key, key; + struct contention_data data =3D {}; struct lock_stat *st =3D NULL; struct machine *machine =3D con->machine; u64 *stack_trace; @@ -126,8 +119,8 @@ int lock_contention_read(struct lock_contention *con) if (stack_trace =3D=3D NULL) return -1; =20 - prev_key =3D 0; - while (!bpf_map_get_next_key(fd, &prev_key, &key)) { + prev_key =3D NULL; + while (!bpf_map_get_next_key(fd, prev_key, &key)) { struct map *kmap; struct symbol *sym; int idx =3D 0; @@ -184,7 +177,7 @@ int lock_contention_read(struct lock_contention *con) } =20 hlist_add_head(&st->hash_entry, con->result); - prev_key =3D key; + prev_key =3D &key; =20 /* we're fine now, reset the values */ st =3D NULL; diff --git a/tools/perf/util/bpf_skel/lock_contention.bpf.c b/tools/perf/ut= il/bpf_skel/lock_contention.bpf.c index 9681cb59b0df..0f63cc28ccba 100644 --- a/tools/perf/util/bpf_skel/lock_contention.bpf.c +++ b/tools/perf/util/bpf_skel/lock_contention.bpf.c @@ -5,24 +5,11 @@ #include #include =20 -/* maximum stack trace depth */ -#define MAX_STACKS 8 +#include "lock_data.h" =20 /* default buffer size */ #define MAX_ENTRIES 10240 =20 -struct contention_key { - __s32 stack_id; -}; - -struct contention_data { - __u64 total_time; - __u64 min_time; - __u64 max_time; - __u32 count; - __u32 flags; -}; - struct tstamp_data { __u64 timestamp; __u64 lock; @@ -34,7 +21,7 @@ struct tstamp_data { struct { __uint(type, BPF_MAP_TYPE_STACK_TRACE); __uint(key_size, sizeof(__u32)); - __uint(value_size, MAX_STACKS * sizeof(__u64)); + __uint(value_size, sizeof(__u64)); __uint(max_entries, MAX_ENTRIES); } stacks SEC(".maps"); =20 diff --git a/tools/perf/util/bpf_skel/lock_data.h b/tools/perf/util/bpf_ske= l/lock_data.h new file mode 100644 index 000000000000..dbdf4caedc4a --- /dev/null +++ b/tools/perf/util/bpf_skel/lock_data.h @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +/* Data structures shared between BPF and tools. */ +#ifndef UTIL_BPF_SKEL_LOCK_DATA_H +#define UTIL_BPF_SKEL_LOCK_DATA_H + +struct contention_key { + s32 stack_or_task_id; +}; + +#define TASK_COMM_LEN 16 + +struct contention_task_data { + char comm[TASK_COMM_LEN]; +}; + +struct contention_data { + u64 total_time; + u64 min_time; + u64 max_time; + u32 count; + u32 flags; +}; + +enum lock_aggr_mode { + LOCK_AGGR_ADDR =3D 0, + LOCK_AGGR_TASK, + LOCK_AGGR_CALLER, +}; + +#endif /* UTIL_BPF_SKEL_LOCK_DATA_H */ --=20 2.39.0.rc1.256.g54fd8350bd-goog From nobody Thu Sep 18 04:35:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AEABC4167B for ; Fri, 9 Dec 2022 19:07:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230135AbiLITHo (ORCPT ); Fri, 9 Dec 2022 14:07:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230114AbiLITHf (ORCPT ); Fri, 9 Dec 2022 14:07:35 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D406D1012; Fri, 9 Dec 2022 11:07:33 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id 4so5887488pli.0; Fri, 09 Dec 2022 11:07:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=mwTfL0kKYTF0adsT64MgLXJKXYchBqVGT1PKMwmP0aw=; b=kezPGi3vgNhkaDI9UImYJllOrlZs9FuJL+9LAQwe30hkWzHpxkSgsaPLkkQyk+oFhf QuU8TYVwGwh4mfVU2v+jNLqjDtt+LejKzGCNwfPrg9xd6pw10u8AjazFc9DHx7TDpG4F sN13nhHzksVBEFhfc+6DxZJ9gC9+8+Gsa7nYTbDLz7DjcJFKoL/w/F0RpaOBYzq/l6YU k1xFdqiJQgs/ee1xTGtsSk6eo+sTPF8gspY+cPhnGeJuGgFHyCLYOk3XVLnFj5r6ESAA hIaS2RdSs9la2OueaYtEpaZk5EeC/uIDndl7VZX4pPIaTPSlbC1ZovUheoQF2/oRjxlF Kz1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=mwTfL0kKYTF0adsT64MgLXJKXYchBqVGT1PKMwmP0aw=; b=w7/Og49frtliqU/1sjAb7v3DgajNYsP0//1INMBy6wGeAHkGFhwrC/HUBiGLl5RZtD ph6unoEWMc17uFB3+DMTANWxQWrbV3XWKODXoZsddfg6zUnO9+qKPWg7virxCzrlARuY R9TAV3ZDpyXc4Mj8tZJtdB4vVOoreQzAeMaO4w0iOLgTbl7z21YD2GEWyOh+H3rcdF9Z WfWPuX9rjjcTqQVnENGE3og4dklmT1zvAxOWPnLSQhSWVkGqrtRS4e0UkpQAKBh+RHTX Ox8FF58kXOQWS9jLnZs4esW+P3J7sxjxVz7qbbYKU1YPCnbbHISgcce5Bc8OE4RaGmeD Kn2w== X-Gm-Message-State: ANoB5pmSQ2I9nlilmtphK6No7dQjdEXt5dzsRtwVM1U6HsiOoCypiHY1 icNt+JE6dsPBKmBE9FleRHU= X-Google-Smtp-Source: AA0mqf4ROZfFScaahkNAlZSBVfn4hJIDZE+t4RCv6Nt4d9lSbPKnhrir9X9eK3+xOwMJyAsXmPLUbg== X-Received: by 2002:a17:90a:ac07:b0:219:aa58:77ba with SMTP id o7-20020a17090aac0700b00219aa5877bamr6769116pjq.25.1670612853422; Fri, 09 Dec 2022 11:07:33 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:ff0:c952:d848:9e00:3cce]) by smtp.gmail.com with ESMTPSA id nd17-20020a17090b4cd100b002135de3013fsm1431432pjb.32.2022.12.09.11.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 11:07:33 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Song Liu , Blake Jones , bpf@vger.kernel.org Subject: [PATCH 2/4] perf lock contention: Implement -t/--threads option for BPF Date: Fri, 9 Dec 2022 11:07:25 -0800 Message-Id: <20221209190727.759804-3-namhyung@kernel.org> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog In-Reply-To: <20221209190727.759804-1-namhyung@kernel.org> References: <20221209190727.759804-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The BPF didn't show the per-thread stat properly. Use task's thread id (PI= D) as a key instead of stack_id and add a task_data map to save task comm name= s. $ sudo ./perf lock con -abt -E 5 sleep 1 contended total wait max wait avg wait pid comm 1 740.66 ms 740.66 ms 740.66 ms 1950 nv_queue 3 305.50 ms 298.19 ms 101.83 ms 1884 nvidia-m= odeset/ 1 25.14 us 25.14 us 25.14 us 2725038 EventMan= ager_De 12 23.09 us 9.30 us 1.92 us 0 swapper 1 20.18 us 20.18 us 20.18 us 2725033 EventMan= ager_De Signed-off-by: Namhyung Kim --- tools/perf/builtin-lock.c | 13 ++---- tools/perf/util/bpf_lock_contention.c | 40 ++++++++++++++++-- .../perf/util/bpf_skel/lock_contention.bpf.c | 41 +++++++++++++++++-- tools/perf/util/lock-contention.h | 1 + 4 files changed, 78 insertions(+), 17 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 15ce6358f127..6fa3cdfec5cb 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -12,6 +12,7 @@ #include "util/target.h" #include "util/callchain.h" #include "util/lock-contention.h" +#include "util/bpf_skel/lock_data.h" =20 #include #include @@ -61,11 +62,7 @@ static int max_stack_depth =3D CONTENTION_STACK_DEPTH; static int stack_skip =3D CONTENTION_STACK_SKIP; static int print_nr_entries =3D INT_MAX / 2; =20 -static enum { - LOCK_AGGR_ADDR, - LOCK_AGGR_TASK, - LOCK_AGGR_CALLER, -} aggr_mode =3D LOCK_AGGR_ADDR; +static enum lock_aggr_mode aggr_mode =3D LOCK_AGGR_ADDR; =20 static struct thread_stat *thread_stat_find(u32 tid) { @@ -1619,6 +1616,7 @@ static int __cmd_contention(int argc, const char **ar= gv) .map_nr_entries =3D bpf_map_entries, .max_stack =3D max_stack_depth, .stack_skip =3D stack_skip, + .aggr_mode =3D show_thread_stats ? LOCK_AGGR_TASK : LOCK_AGGR_CALLER, }; =20 session =3D perf_session__new(use_bpf ? NULL : &data, &eops); @@ -1691,11 +1689,6 @@ static int __cmd_contention(int argc, const char **a= rgv) if (select_key(true)) goto out_delete; =20 - if (show_thread_stats) - aggr_mode =3D LOCK_AGGR_TASK; - else - aggr_mode =3D LOCK_AGGR_CALLER; - if (use_bpf) { lock_contention_start(); if (argc) diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lo= ck_contention.c index b6a8eb7164b3..1590a9f05145 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -5,6 +5,7 @@ #include "util/map.h" #include "util/symbol.h" #include "util/target.h" +#include "util/thread.h" #include "util/thread_map.h" #include "util/lock-contention.h" #include @@ -30,10 +31,17 @@ int lock_contention_prepare(struct lock_contention *con) } =20 bpf_map__set_value_size(skel->maps.stacks, con->max_stack * sizeof(u64)); - bpf_map__set_max_entries(skel->maps.stacks, con->map_nr_entries); bpf_map__set_max_entries(skel->maps.lock_stat, con->map_nr_entries); bpf_map__set_max_entries(skel->maps.tstamp, con->map_nr_entries); =20 + if (con->aggr_mode =3D=3D LOCK_AGGR_TASK) { + bpf_map__set_max_entries(skel->maps.task_data, con->map_nr_entries); + bpf_map__set_max_entries(skel->maps.stacks, 1); + } else { + bpf_map__set_max_entries(skel->maps.task_data, 1); + bpf_map__set_max_entries(skel->maps.stacks, con->map_nr_entries); + } + if (target__has_cpu(target)) ncpus =3D perf_cpu_map__nr(evlist->core.user_requested_cpus); if (target__has_task(target)) @@ -82,7 +90,9 @@ int lock_contention_prepare(struct lock_contention *con) bpf_map_update_elem(fd, &pid, &val, BPF_ANY); } =20 + /* these don't work well if in the rodata section */ skel->bss->stack_skip =3D con->stack_skip; + skel->bss->aggr_mode =3D con->aggr_mode; =20 lock_contention_bpf__attach(skel); return 0; @@ -102,7 +112,7 @@ int lock_contention_stop(void) =20 int lock_contention_read(struct lock_contention *con) { - int fd, stack, err =3D 0; + int fd, stack, task_fd, err =3D 0; struct contention_key *prev_key, key; struct contention_data data =3D {}; struct lock_stat *st =3D NULL; @@ -112,6 +122,7 @@ int lock_contention_read(struct lock_contention *con) =20 fd =3D bpf_map__fd(skel->maps.lock_stat); stack =3D bpf_map__fd(skel->maps.stacks); + task_fd =3D bpf_map__fd(skel->maps.task_data); =20 con->lost =3D skel->bss->lost; =20 @@ -119,6 +130,13 @@ int lock_contention_read(struct lock_contention *con) if (stack_trace =3D=3D NULL) return -1; =20 + if (con->aggr_mode =3D=3D LOCK_AGGR_TASK) { + struct thread *idle =3D __machine__findnew_thread(machine, + /*pid=3D*/0, + /*tid=3D*/0); + thread__set_comm(idle, "swapper", /*timestamp=3D*/0); + } + prev_key =3D NULL; while (!bpf_map_get_next_key(fd, prev_key, &key)) { struct map *kmap; @@ -143,6 +161,22 @@ int lock_contention_read(struct lock_contention *con) =20 st->flags =3D data.flags; =20 + if (con->aggr_mode =3D=3D LOCK_AGGR_TASK) { + struct contention_task_data task; + struct thread *t; + + st->addr =3D key.stack_or_task_id; + + /* do not update idle comm which contains CPU number */ + if (st->addr) { + bpf_map_lookup_elem(task_fd, &key, &task); + t =3D __machine__findnew_thread(machine, /*pid=3D*/-1, + key.stack_or_task_id); + thread__set_comm(t, task.comm, /*timestamp=3D*/0); + } + goto next; + } + bpf_map_lookup_elem(stack, &key, stack_trace); =20 /* skip lock internal functions */ @@ -175,7 +209,7 @@ int lock_contention_read(struct lock_contention *con) if (st->callstack =3D=3D NULL) break; } - +next: hlist_add_head(&st->hash_entry, con->result); prev_key =3D &key; =20 diff --git a/tools/perf/util/bpf_skel/lock_contention.bpf.c b/tools/perf/ut= il/bpf_skel/lock_contention.bpf.c index 0f63cc28ccba..cd405adcd252 100644 --- a/tools/perf/util/bpf_skel/lock_contention.bpf.c +++ b/tools/perf/util/bpf_skel/lock_contention.bpf.c @@ -41,6 +41,13 @@ struct { __uint(max_entries, MAX_ENTRIES); } lock_stat SEC(".maps"); =20 +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __uint(key_size, sizeof(__u32)); + __uint(value_size, sizeof(struct contention_task_data)); + __uint(max_entries, MAX_ENTRIES); +} task_data SEC(".maps"); + struct { __uint(type, BPF_MAP_TYPE_HASH); __uint(key_size, sizeof(__u32)); @@ -61,6 +68,9 @@ int has_cpu; int has_task; int stack_skip; =20 +/* determine the key of lock stat */ +int aggr_mode; + /* error stat */ int lost; =20 @@ -87,6 +97,19 @@ static inline int can_record(void) return 1; } =20 +static inline void update_task_data(__u32 pid) +{ + struct contention_task_data *p; + + p =3D bpf_map_lookup_elem(&task_data, &pid); + if (p =3D=3D NULL) { + struct contention_task_data data; + + bpf_get_current_comm(data.comm, sizeof(data.comm)); + bpf_map_update_elem(&task_data, &pid, &data, BPF_NOEXIST); + } +} + SEC("tp_btf/contention_begin") int contention_begin(u64 *ctx) { @@ -115,10 +138,14 @@ int contention_begin(u64 *ctx) pelem->timestamp =3D bpf_ktime_get_ns(); pelem->lock =3D (__u64)ctx[0]; pelem->flags =3D (__u32)ctx[1]; - pelem->stack_id =3D bpf_get_stackid(ctx, &stacks, BPF_F_FAST_STACK_CMP | = stack_skip); =20 - if (pelem->stack_id < 0) - lost++; + if (aggr_mode =3D=3D LOCK_AGGR_CALLER) { + pelem->stack_id =3D bpf_get_stackid(ctx, &stacks, + BPF_F_FAST_STACK_CMP | stack_skip); + if (pelem->stack_id < 0) + lost++; + } + return 0; } =20 @@ -141,7 +168,13 @@ int contention_end(u64 *ctx) =20 duration =3D bpf_ktime_get_ns() - pelem->timestamp; =20 - key.stack_id =3D pelem->stack_id; + if (aggr_mode =3D=3D LOCK_AGGR_CALLER) { + key.stack_or_task_id =3D pelem->stack_id; + } else { + key.stack_or_task_id =3D pid; + update_task_data(pid); + } + data =3D bpf_map_lookup_elem(&lock_stat, &key); if (!data) { struct contention_data first =3D { diff --git a/tools/perf/util/lock-contention.h b/tools/perf/util/lock-conte= ntion.h index a2346875098d..47fd47fb56c1 100644 --- a/tools/perf/util/lock-contention.h +++ b/tools/perf/util/lock-contention.h @@ -117,6 +117,7 @@ struct lock_contention { int lost; int max_stack; int stack_skip; + int aggr_mode; }; =20 #ifdef HAVE_BPF_SKEL --=20 2.39.0.rc1.256.g54fd8350bd-goog From nobody Thu Sep 18 04:35:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B61CC4332F for ; Fri, 9 Dec 2022 19:07:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbiLITHt (ORCPT ); Fri, 9 Dec 2022 14:07:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230106AbiLITHi (ORCPT ); Fri, 9 Dec 2022 14:07:38 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA7582AEE; Fri, 9 Dec 2022 11:07:35 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id u5so5718057pjy.5; Fri, 09 Dec 2022 11:07:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=PjY8H+PAiusizFOCgESEpT8nPlA0MeCSIYNjtpBPi54=; b=BB9OCfif8nj6AThEtwutm8zAPoYPL/0mvBRijpK3N89uiL2xCiSZ7kLhaduq5YzDNs i80l3bPChiY56yI5oueQXVwD/Lur+XgAyv1SO1dVcUmr9JZAyTZy9U3oCfFyltmU2lLL 7M44IAK48x5Efqjys61aSwyrq9ab2eBMFh5xf/7TSo+zfwX6jSD+U2sDO6c2z10OjLJc 9fOR+//+9VnEbaEzKBsTYCstYYcMCoU8YTs6lwe/c+0N9R5AFDkgzYE69FyNO26VzBrg MduazddKc4xXWpe6QNpHBX/k5/OzIE+HkdnSzrxdCRvyqQFEi8Q7FmSgayPI5L/LhfhH UVmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=PjY8H+PAiusizFOCgESEpT8nPlA0MeCSIYNjtpBPi54=; b=szaqpY461cPlPX0cA3jX48lUjxKCJMhCPlPCEGPlDCdNkuvolpxKe4/ROIxl4Zh0r3 VhqN1kQ8TBGQPvZPEOqK1Xj4oTHKUAs83q8+AhIGCw9DZLrVS0+l27pAVgCEUKzyPOwr MUI6/eg1RV7K5joO+JdQADaJZbDMJBFLH2rQuSNlPazOK1A6K9lfR99kq6UaD9DnZiHH nEcSI71VZQevhJKMq3g7ZU4li5VQA2W8OfiX9F9nqjVlku298p+3BQgM8liXHNGcny0A sgClfYUQFWFksLbBn6Bg+6XNnKLxWCHUD8aGSNHNbu80AjF9BFgjwSEtIYjwpG/89e2s ZipA== X-Gm-Message-State: ANoB5plSxeIjxJMwFfvwauTpXlD3vkXWyYpgRp3ujT0h+0qasdx1utR3 AbxbPWGsCwCTZ8W0fkJ2wfw= X-Google-Smtp-Source: AA0mqf6YRJAEXx+NGCn2wLRqoeyRNYlgFsYtH8rRjhN9KhbZQGLv28M35T6rxk+e1Bk488OaUIKGCg== X-Received: by 2002:a05:6a20:2a8c:b0:a6:6d23:a007 with SMTP id v12-20020a056a202a8c00b000a66d23a007mr12557006pzh.42.1670612854906; Fri, 09 Dec 2022 11:07:34 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:ff0:c952:d848:9e00:3cce]) by smtp.gmail.com with ESMTPSA id nd17-20020a17090b4cd100b002135de3013fsm1431432pjb.32.2022.12.09.11.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 11:07:34 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Song Liu , Blake Jones , bpf@vger.kernel.org Subject: [PATCH 3/4] perf lock contention: Add -l/--lock-addr option Date: Fri, 9 Dec 2022 11:07:26 -0800 Message-Id: <20221209190727.759804-4-namhyung@kernel.org> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog In-Reply-To: <20221209190727.759804-1-namhyung@kernel.org> References: <20221209190727.759804-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The -l/--lock-addr option is to implement per-lock-instance contention stat using LOCK_AGGR_ADDR. It displays lock address and optionally symbol name if exists. $ sudo ./perf lock con -abl sleep 1 contended total wait max wait avg wait address sy= mbol 1 36.28 us 36.28 us 36.28 us ffff92615d6448b8 9 10.91 us 1.84 us 1.21 us ffffffffbaed50c0 rc= u_state 1 10.49 us 10.49 us 10.49 us ffff9262ac4f0c80 8 4.68 us 1.67 us 585 ns ffffffffbae07a40 ji= ffies_lock 3 3.03 us 1.45 us 1.01 us ffff9262277861e0 1 924 ns 924 ns 924 ns ffff926095ba9d20 1 436 ns 436 ns 436 ns ffff9260bfda4f60 Signed-off-by: Namhyung Kim --- tools/perf/Documentation/perf-lock.txt | 4 + tools/perf/builtin-lock.c | 84 +++++++++++++++---- tools/perf/util/bpf_lock_contention.c | 23 +++-- .../perf/util/bpf_skel/lock_contention.bpf.c | 17 +++- tools/perf/util/bpf_skel/lock_data.h | 2 +- 5 files changed, 102 insertions(+), 28 deletions(-) diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentat= ion/perf-lock.txt index 4958a1ffa1cc..38e79d45e426 100644 --- a/tools/perf/Documentation/perf-lock.txt +++ b/tools/perf/Documentation/perf-lock.txt @@ -168,6 +168,10 @@ CONTENTION OPTIONS --entries=3D:: Display this many entries. =20 +-l:: +--lock-addr:: + Show lock contention stat by address + =20 SEE ALSO -------- diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 6fa3cdfec5cb..25c0a5e5051f 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -56,6 +56,7 @@ static struct rb_root thread_stats; =20 static bool combine_locks; static bool show_thread_stats; +static bool show_lock_addrs; static bool use_bpf; static unsigned long bpf_map_entries =3D 10240; static int max_stack_depth =3D CONTENTION_STACK_DEPTH; @@ -999,13 +1000,32 @@ static int report_lock_contention_begin_event(struct= evsel *evsel, ls =3D lock_stat_find(key); if (!ls) { char buf[128]; - const char *caller =3D buf; + const char *name =3D ""; unsigned int flags =3D evsel__intval(evsel, sample, "flags"); + struct machine *machine =3D &session->machines.host; + struct map *kmap; + struct symbol *sym; + + switch (aggr_mode) { + case LOCK_AGGR_ADDR: + /* make sure it loads the kernel map to find lock symbols */ + map__load(machine__kernel_map(machine)); + + sym =3D machine__find_kernel_symbol(machine, key, &kmap); + if (sym) + name =3D sym->name; + break; + case LOCK_AGGR_CALLER: + name =3D buf; + if (lock_contention_caller(evsel, sample, buf, sizeof(buf)) < 0) + name =3D "Unknown"; + break; + case LOCK_AGGR_TASK: + default: + break; + } =20 - if (lock_contention_caller(evsel, sample, buf, sizeof(buf)) < 0) - caller =3D "Unknown"; - - ls =3D lock_stat_findnew(key, caller, flags); + ls =3D lock_stat_findnew(key, name, flags); if (!ls) return -ENOMEM; =20 @@ -1460,10 +1480,19 @@ static void print_contention_result(struct lock_con= tention *con) list_for_each_entry(key, &lock_keys, list) pr_info("%*s ", key->len, key->header); =20 - if (show_thread_stats) + switch (aggr_mode) { + case LOCK_AGGR_TASK: pr_info(" %10s %s\n\n", "pid", "comm"); - else + break; + case LOCK_AGGR_CALLER: pr_info(" %10s %s\n\n", "type", "caller"); + break; + case LOCK_AGGR_ADDR: + pr_info(" %16s %s\n\n", "address", "symbol"); + break; + default: + break; + } } =20 bad =3D total =3D printed =3D 0; @@ -1471,6 +1500,9 @@ static void print_contention_result(struct lock_conte= ntion *con) bad =3D bad_hist[BROKEN_CONTENDED]; =20 while ((st =3D pop_from_result())) { + struct thread *t; + int pid; + total +=3D use_bpf ? st->nr_contended : 1; if (st->broken) bad++; @@ -1480,18 +1512,24 @@ static void print_contention_result(struct lock_con= tention *con) pr_info(" "); } =20 - if (show_thread_stats) { - struct thread *t; - int pid =3D st->addr; - - /* st->addr contains tid of thread */ + switch (aggr_mode) { + case LOCK_AGGR_CALLER: + pr_info(" %10s %s\n", get_type_str(st), st->name); + break; + case LOCK_AGGR_TASK: + pid =3D st->addr; t =3D perf_session__findnew(session, pid); pr_info(" %10d %s\n", pid, thread__comm_str(t)); - goto next; + break; + case LOCK_AGGR_ADDR: + pr_info(" %016llx %s\n", (unsigned long long)st->addr, + st->name ? : ""); + break; + default: + break; } =20 - pr_info(" %10s %s\n", get_type_str(st), st->name); - if (verbose) { + if (aggr_mode =3D=3D LOCK_AGGR_CALLER && verbose) { struct map *kmap; struct symbol *sym; char buf[128]; @@ -1508,7 +1546,6 @@ static void print_contention_result(struct lock_conte= ntion *con) } } =20 -next: if (++printed >=3D print_nr_entries) break; } @@ -1616,7 +1653,6 @@ static int __cmd_contention(int argc, const char **ar= gv) .map_nr_entries =3D bpf_map_entries, .max_stack =3D max_stack_depth, .stack_skip =3D stack_skip, - .aggr_mode =3D show_thread_stats ? LOCK_AGGR_TASK : LOCK_AGGR_CALLER, }; =20 session =3D perf_session__new(use_bpf ? NULL : &data, &eops); @@ -1627,6 +1663,9 @@ static int __cmd_contention(int argc, const char **ar= gv) =20 con.machine =3D &session->machines.host; =20 + con.aggr_mode =3D aggr_mode =3D show_thread_stats ? LOCK_AGGR_TASK : + show_lock_addrs ? LOCK_AGGR_ADDR : LOCK_AGGR_CALLER; + /* for lock function check */ symbol_conf.sort_by_name =3D true; symbol__init(&session->header.env); @@ -1907,6 +1946,7 @@ int cmd_lock(int argc, const char **argv) "Set the number of stack depth to skip when finding a lock caller, " "Default: " __stringify(CONTENTION_STACK_SKIP)), OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functio= ns"), + OPT_BOOLEAN('l', "lock-addr", &show_lock_addrs, "show lock stats by addre= ss"), OPT_PARENT(lock_options) }; =20 @@ -1976,6 +2016,16 @@ int cmd_lock(int argc, const char **argv) argc =3D parse_options(argc, argv, contention_options, contention_usage, 0); } + + if (show_thread_stats && show_lock_addrs) { + pr_err("Cannot use thread and addr mode together\n"); + parse_options_usage(contention_usage, contention_options, + "threads", 0); + parse_options_usage(NULL, contention_options, + "lock-addr", 0); + return -1; + } + rc =3D __cmd_contention(argc, argv); } else { usage_with_options(lock_usage, lock_options); diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lo= ck_contention.c index 1590a9f05145..8e1b791dc58f 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -137,11 +137,15 @@ int lock_contention_read(struct lock_contention *con) thread__set_comm(idle, "swapper", /*timestamp=3D*/0); } =20 + /* make sure it loads the kernel map */ + map__load(maps__first(machine->kmaps)); + prev_key =3D NULL; while (!bpf_map_get_next_key(fd, prev_key, &key)) { struct map *kmap; struct symbol *sym; int idx =3D 0; + s32 stack_id; =20 /* to handle errors in the loop body */ err =3D -1; @@ -160,24 +164,31 @@ int lock_contention_read(struct lock_contention *con) st->avg_wait_time =3D data.total_time / data.count; =20 st->flags =3D data.flags; + st->addr =3D key.aggr_key; =20 if (con->aggr_mode =3D=3D LOCK_AGGR_TASK) { struct contention_task_data task; struct thread *t; - - st->addr =3D key.stack_or_task_id; + int pid =3D key.aggr_key; =20 /* do not update idle comm which contains CPU number */ if (st->addr) { - bpf_map_lookup_elem(task_fd, &key, &task); - t =3D __machine__findnew_thread(machine, /*pid=3D*/-1, - key.stack_or_task_id); + bpf_map_lookup_elem(task_fd, &pid, &task); + t =3D __machine__findnew_thread(machine, /*pid=3D*/-1, pid); thread__set_comm(t, task.comm, /*timestamp=3D*/0); } goto next; } =20 - bpf_map_lookup_elem(stack, &key, stack_trace); + if (con->aggr_mode =3D=3D LOCK_AGGR_ADDR) { + sym =3D machine__find_kernel_symbol(machine, st->addr, &kmap); + if (sym) + st->name =3D strdup(sym->name); + goto next; + } + + stack_id =3D key.aggr_key; + bpf_map_lookup_elem(stack, &stack_id, stack_trace); =20 /* skip lock internal functions */ while (machine__is_lock_function(machine, stack_trace[idx]) && diff --git a/tools/perf/util/bpf_skel/lock_contention.bpf.c b/tools/perf/ut= il/bpf_skel/lock_contention.bpf.c index cd405adcd252..11b0fc7ee53b 100644 --- a/tools/perf/util/bpf_skel/lock_contention.bpf.c +++ b/tools/perf/util/bpf_skel/lock_contention.bpf.c @@ -168,11 +168,20 @@ int contention_end(u64 *ctx) =20 duration =3D bpf_ktime_get_ns() - pelem->timestamp; =20 - if (aggr_mode =3D=3D LOCK_AGGR_CALLER) { - key.stack_or_task_id =3D pelem->stack_id; - } else { - key.stack_or_task_id =3D pid; + switch (aggr_mode) { + case LOCK_AGGR_CALLER: + key.aggr_key =3D pelem->stack_id; + break; + case LOCK_AGGR_TASK: + key.aggr_key =3D pid; update_task_data(pid); + break; + case LOCK_AGGR_ADDR: + key.aggr_key =3D pelem->lock; + break; + default: + /* should not happen */ + return 0; } =20 data =3D bpf_map_lookup_elem(&lock_stat, &key); diff --git a/tools/perf/util/bpf_skel/lock_data.h b/tools/perf/util/bpf_ske= l/lock_data.h index dbdf4caedc4a..ce71cf1a7e1e 100644 --- a/tools/perf/util/bpf_skel/lock_data.h +++ b/tools/perf/util/bpf_skel/lock_data.h @@ -4,7 +4,7 @@ #define UTIL_BPF_SKEL_LOCK_DATA_H =20 struct contention_key { - s32 stack_or_task_id; + u64 aggr_key; /* can be stack_id, pid or lock addr */ }; =20 #define TASK_COMM_LEN 16 --=20 2.39.0.rc1.256.g54fd8350bd-goog From nobody Thu Sep 18 04:35:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87D98C4332F for ; Fri, 9 Dec 2022 19:08:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbiLITIA (ORCPT ); Fri, 9 Dec 2022 14:08:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230130AbiLITHn (ORCPT ); Fri, 9 Dec 2022 14:07:43 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 474356441; Fri, 9 Dec 2022 11:07:37 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id y17so5857500plp.3; Fri, 09 Dec 2022 11:07:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=JAU/j1NdwbvUI7spTdVmLXV+d6wFoRxuKA8kjpq/0+E=; b=QYEKC//N4gfLrm8aFH4teGNGwE5UrwqLs52KyKuUT76LejDrqWmphcWaZYFyjhECA+ TZJ49uMAvsB1yPTNBuyUG7OdiLmrcImnM5gq9ZVcDTlHJJRHkh1jwHbphHNeCXGEFm3i Vkbhka5SA8PbmbmOrIhSTVUYXr6ihh3f7KiVblSLaPz32acZwxkiQBbEdptB2Ls8pg4m lubRcHW8lgwb2Jr1ri3unZ177hi94vHvw6x9wHqRLgETPZYXSJ6rWUhebYKRny4yY30O 1+BLIyvvF8AOcXq5GsfSyU2nBxtJCWlQEZwRQb+XbQcKYgxpIuYWJbmk6WK/N5rDv5Lj itdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=JAU/j1NdwbvUI7spTdVmLXV+d6wFoRxuKA8kjpq/0+E=; b=ImhZpiH2sQZ8QVM7BhuEmF28BJu/CyaoAq5yFQfQD5b53ucftGYyemJIC3CwaGIARm p5wg7alrEXWZld9w/Tpsmz3TO7c93Y5UXwKgqT+IWMacY04dwe9OFwebJi+sOzirrBis l4eTw/adeq9JcmSQSnYsvGjqAsnRn5OEG+jNwqn1V/6tjLuJZ6Le+dAbo8JNm32MwrEG xjvyEnGn3BeRFnmDNYA3vPDRct+bt9ejo/eK01g9KRDtzdZiGJHUkmCjR6y3JhDr7YAF ryKqfmqh+OR23/TWcay6nMCR4XY7sn+i0HZiXEK/lyOuXkUPxneYYvwClKB6aRMfALuN JpZg== X-Gm-Message-State: ANoB5pk9hfbnYdxQu3aM87uWdSHbRTPLqoqql8QIUNUGaZUsdiMNn+RJ /3wQz1ziT3z+3W0TeBnRQTU= X-Google-Smtp-Source: AA0mqf4IZ4uSmOpdJ4yd9rCzWpAiCyihPyyM5pmrtlLy7TzxOhoOCIg81lc5XbVmw8G+8PBjrrB6eA== X-Received: by 2002:a17:90a:8684:b0:219:68f8:7aaa with SMTP id p4-20020a17090a868400b0021968f87aaamr6785914pjn.40.1670612856682; Fri, 09 Dec 2022 11:07:36 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:ff0:c952:d848:9e00:3cce]) by smtp.gmail.com with ESMTPSA id nd17-20020a17090b4cd100b002135de3013fsm1431432pjb.32.2022.12.09.11.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 11:07:36 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Song Liu , Blake Jones , bpf@vger.kernel.org Subject: [PATCH 4/4] perf test: Update perf lock contention test Date: Fri, 9 Dec 2022 11:07:27 -0800 Message-Id: <20221209190727.759804-5-namhyung@kernel.org> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog In-Reply-To: <20221209190727.759804-1-namhyung@kernel.org> References: <20221209190727.759804-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add test cases for the task and addr aggregation modes. $ sudo ./perf test -v contention 86: kernel lock contention analysis test : --- start --- test child forked, pid 680006 Testing perf lock record and perf lock contention Testing perf lock contention --use-bpf Testing perf lock record and perf lock contention at the same time Testing perf lock contention --threads Testing perf lock contention --lock-addr test child finished with 0 ---- end ---- kernel lock contention analysis test: Ok Signed-off-by: Namhyung Kim --- tools/perf/tests/shell/lock_contention.sh | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tools/perf/tests/shell/lock_contention.sh b/tools/perf/tests/s= hell/lock_contention.sh index f7bd0d8eb5c3..cc9ceb9e19ca 100755 --- a/tools/perf/tests/shell/lock_contention.sh +++ b/tools/perf/tests/shell/lock_contention.sh @@ -77,10 +77,58 @@ test_record_concurrent() fi } =20 +test_aggr_task() +{ + echo "Testing perf lock contention --threads" + perf lock contention -i ${perfdata} -t -E 1 -q 2> ${result} + if [ $(cat "${result}" | wc -l) !=3D "1" ]; then + echo "[Fail] Recorded result count is not 1:" $(cat "${result}" | wc -l) + err=3D1 + exit + fi + + if ! perf lock con -b true > /dev/null 2>&1 ; then + return + fi + + # the perf lock contention output goes to the stderr + perf lock con -a -b -t -E 1 -q -- perf bench sched messaging > /dev/null = 2> ${result} + if [ $(cat "${result}" | wc -l) !=3D "1" ]; then + echo "[Fail] BPF result count is not 1:" $(cat "${result}" | wc -l) + err=3D1 + exit + fi +} + +test_aggr_addr() +{ + echo "Testing perf lock contention --lock-addr" + perf lock contention -i ${perfdata} -l -E 1 -q 2> ${result} + if [ $(cat "${result}" | wc -l) !=3D "1" ]; then + echo "[Fail] Recorded result count is not 1:" $(cat "${result}" | wc -l) + err=3D1 + exit + fi + + if ! perf lock con -b true > /dev/null 2>&1 ; then + return + fi + + # the perf lock contention output goes to the stderr + perf lock con -a -b -t -E 1 -q -- perf bench sched messaging > /dev/null = 2> ${result} + if [ $(cat "${result}" | wc -l) !=3D "1" ]; then + echo "[Fail] BPF result count is not 1:" $(cat "${result}" | wc -l) + err=3D1 + exit + fi +} + check =20 test_record test_bpf test_record_concurrent +test_aggr_task +test_aggr_addr =20 exit ${err} --=20 2.39.0.rc1.256.g54fd8350bd-goog