From nobody Wed Apr 8 20:03:33 2026 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 356A4C38A02 for ; Fri, 28 Oct 2022 18:01:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229973AbiJ1SBr (ORCPT ); Fri, 28 Oct 2022 14:01:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbiJ1SBg (ORCPT ); Fri, 28 Oct 2022 14:01:36 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B918320FB19; Fri, 28 Oct 2022 11:01:34 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id f23so5485763plr.6; Fri, 28 Oct 2022 11:01:34 -0700 (PDT) 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=NmGyjkUI3Jx6s05ye5A4TzB4tPD0VcBwkqsa8EyR1XQ=; b=hD6Z0lr0qNzTb/h7xWEEo4kab7blvNR1dkhEaQcP+TQbguozLm/pd3/Wt/YmB4P7VN zVIhEM+5h48c3QkGE9zQvi9LVupqNaK2dYG+Fjcj3Pr7aL4ezJQvVeYbhMFgLxrVws4k +/U90S2XvRrJ/fjOz5Aj6jOZ/7czeOddZDXBXn/Si6nlOVhVnCIDgVibEdsBpWXxKKUu SSE/mFx6NJ3+KSrlM0jnpeBc9ltZsFAL+diDGr6YfNqElfMWiWPcZRC9WYXolLcGNZgW ppVj33Jp3cZ/d+WH9MrzS683eYX9A93CeqZWkFOY1saHh6BMkN5Marchffqlr3qop3zp IF5g== 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=NmGyjkUI3Jx6s05ye5A4TzB4tPD0VcBwkqsa8EyR1XQ=; b=NCkPKbE+jacPLisBJQAxuiH964muzLFrpXZGN0zp8pgn1cntnFw5bJS5pYROn5H+pn 9ssnONagho2m3f1NijusOS3W2mG924YxjW6NK0bmHC+2+VALwV8f5QWMfG5MBh6rMl1D 5qiN4WqhMxNMqFE10wUMNXjZC2IDY2o8C6m0FPBlOupGxTe4Saq8PSquGICsdcTAWaqz zZHkBeShxaLdxuI1ZZY/5D4mOpvb3PCO0s/HajvAYK2FqJdSu6Twkbbh6sUwHUhwm8LQ nE5KHbh8by1iLRGRLrxzhXaTc6c5lq6oO31baHhW01dTZ1/iOOHjWjV6WvtJRJATRTB9 iS2Q== X-Gm-Message-State: ACrzQf11HOA4z6M7N9ZNJ2i08yr4rh5R7NAr12ezDYcRBy/EWdxwcvpa Hr2b2XZKFWo4PM2cgP65IbI= X-Google-Smtp-Source: AMsMyM6oJIlbvojF6YXXEDr6isWduRhmVUwWJu6d5tRV2QMhZqYRLjbfnnA7R2sf/n2tVE8xjtvFVw== X-Received: by 2002:a17:90b:4f4a:b0:20c:64e2:2bee with SMTP id pj10-20020a17090b4f4a00b0020c64e22beemr18093806pjb.32.1666980093820; Fri, 28 Oct 2022 11:01:33 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:976f:f075:7c14:87a2]) by smtp.gmail.com with ESMTPSA id n3-20020a170903110300b00186b86ed450sm3400236plh.156.2022.10.28.11.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 11:01:32 -0700 (PDT) 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 Subject: [PATCH 1/4] perf lock contention: Fix memory sanitizer issue Date: Fri, 28 Oct 2022 11:01:25 -0700 Message-Id: <20221028180128.3311491-2-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221028180128.3311491-1-namhyung@kernel.org> References: <20221028180128.3311491-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 msan reported a use-of-uninitialized-value warning for the struct lock_contention_data in lock_contention_read(). While it'd be filled by bpf_map_lookup_elem(), let's just initialize it to silence the warning. =3D=3D12524=3D=3DWARNING: MemorySanitizer: use-of-uninitialized-value #0 0x562b0f16b1cd in lock_contention_read util/bpf_lock_contention.c:139= :7 #1 0x562b0ef65ec6 in __cmd_contention builtin-lock.c:1737:3 #2 0x562b0ef65ec6 in cmd_lock builtin-lock.c:1992:8 #3 0x562b0ee7f50b in run_builtin perf.c:322:11 #4 0x562b0ee7efc1 in handle_internal_command perf.c:376:8 #5 0x562b0ee7e1e9 in run_argv perf.c:420:2 #6 0x562b0ee7e1e9 in main perf.c:550:3 #7 0x7f065f10e632 in __libc_start_main (/usr/lib64/libc.so.6+0x61632) #8 0x562b0edf2fa9 in _start (perf+0xfa9) SUMMARY: MemorySanitizer: use-of-uninitialized-value (perf+0xe15160) in l= ock_contention_read Signed-off-by: Namhyung Kim --- tools/perf/util/bpf_lock_contention.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lo= ck_contention.c index fc4d613cb979..06466da792e4 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -110,7 +110,7 @@ int lock_contention_read(struct lock_contention *con) { int fd, stack; s32 prev_key, key; - struct lock_contention_data data; + struct lock_contention_data data =3D {}; struct lock_stat *st; struct machine *machine =3D con->machine; u64 stack_trace[con->max_stack]; --=20 2.38.1.273.g43a17bfeac-goog From nobody Wed Apr 8 20:03:33 2026 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 A0BE3C38A02 for ; Fri, 28 Oct 2022 18:01:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229993AbiJ1SBx (ORCPT ); Fri, 28 Oct 2022 14:01:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230018AbiJ1SBg (ORCPT ); Fri, 28 Oct 2022 14:01:36 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE1DD20FB1D; Fri, 28 Oct 2022 11:01:35 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id 3-20020a17090a0f8300b00212d5cd4e5eso10527919pjz.4; Fri, 28 Oct 2022 11:01:35 -0700 (PDT) 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=RRaWyTNG36H59bEp88dgewnNjHxw44C35a4VhyGtZjQ=; b=MWTjbjOl5lZi7Xu1Znd5gj0cW3FkMbJFkKKN/mVYofTaIK7sVXhT07pR31GWyqOnl/ 9SR9oSl2m4vw2H4zyeFubiK4coIylPo2pQNNzjHz0tDkBNkP+6C/qnBqSof6VUXLPaM1 D12+rnxDSHhTSMvXTWP4wOoBjBM1Q4c0zz2zas65ePGiwPNVyeN9UfUGHLOD9IdlHKt0 mWWr0YMIXY+25RgHy0noTUbYAnCaqxJ1qDtctIxR3qCOtT7kS1SIZTRedRAHPkpUIgDa AkSKwuY3lm2Rd54tzk9rXY18qB2SzAQf0s+zdI8gEGd1SfjBhN9LNtaNocTvUlJUdDoX NbjA== 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=RRaWyTNG36H59bEp88dgewnNjHxw44C35a4VhyGtZjQ=; b=J/8IIb9V+wdyZMtqP6JaMxgUX1oP/ppuCu2p8B3u+7ygbKRhRbSKhPQ/W2wqq9dCFP 2bFWkuvjN7yPGYFDRsC/lxtSupdd4bpq2yG1DqgPwNrIsNxJ/Dd1bueuDL61akX2v+A3 hu4kx/Rkjxwznbh80BTEwlX54XYUcv83jziwSPqvkpDN1kCOA6AjznF5Bv+kAsyKa+Ix Up42Mtaqv6XgdRX/l7wOf2drt9ce0Pkcn8aYdPVVrgonPTKuWCqR6xalI7amXNvSK0k+ UjYFSZ9NdCPS0F4+1ZwCtqEKhajWJf0Cw9JgpR/NsdiohAgl4WwGPC5KQC46MjRn+Zwq IDRQ== X-Gm-Message-State: ACrzQf3jN1uCD2Rx8dBRG83/q3Yb5HkQ8YVwZ/4oazp6HkQBbAcEGFks niavH8x0MSP4o6AVTD8bCZ8= X-Google-Smtp-Source: AMsMyM6r0qYzt6JLtN3tJ9YK3WpjzmR5jceTXdkdKOG21sqTVszZBLHMDbSR/AFDINwyJMNx4Xy8+g== X-Received: by 2002:a17:902:f710:b0:184:7a4c:fdc1 with SMTP id h16-20020a170902f71000b001847a4cfdc1mr186767plo.27.1666980095311; Fri, 28 Oct 2022 11:01:35 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:976f:f075:7c14:87a2]) by smtp.gmail.com with ESMTPSA id n3-20020a170903110300b00186b86ed450sm3400236plh.156.2022.10.28.11.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 11:01:34 -0700 (PDT) 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 Subject: [PATCH 2/4] perf lock contention: Check --max-stack option Date: Fri, 28 Oct 2022 11:01:26 -0700 Message-Id: <20221028180128.3311491-3-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221028180128.3311491-1-namhyung@kernel.org> References: <20221028180128.3311491-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 --max-stack option is used to allocate the BPF stack map and stack trace array in the userspace. Check the value properly before using. Practically it cannot be greater than the sysctl_perf_event_max_stack. Signed-off-by: Namhyung Kim --- tools/perf/builtin-lock.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 9722d4ab2e55..f67db60f1de6 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -24,6 +24,7 @@ #include "util/data.h" #include "util/string2.h" #include "util/map.h" +#include "util/util.h" =20 #include #include @@ -1858,6 +1859,29 @@ static int parse_map_entry(const struct option *opt,= const char *str, return 0; } =20 +static int parse_max_stack(const struct option *opt, const char *str, + int unset __maybe_unused) +{ + unsigned long *len =3D (unsigned long *)opt->value; + long val; + char *endptr; + + errno =3D 0; + val =3D strtol(str, &endptr, 0); + if (*endptr !=3D '\0' || errno !=3D 0) { + pr_err("invalid max stack depth: %s\n", str); + return -1; + } + + if (val < 0 || val > sysctl__max_stack()) { + pr_err("invalid max stack depth: %ld\n", val); + return -1; + } + + *len =3D val; + return 0; +} + int cmd_lock(int argc, const char **argv) { const struct option lock_options[] =3D { @@ -1913,9 +1937,9 @@ int cmd_lock(int argc, const char **argv) "Trace on existing thread id (exclusive to --pid)"), OPT_CALLBACK(0, "map-nr-entries", &bpf_map_entries, "num", "Max number of BPF map entries", parse_map_entry), - OPT_INTEGER(0, "max-stack", &max_stack_depth, - "Set the maximum stack depth when collecting lock contention, " - "Default: " __stringify(CONTENTION_STACK_DEPTH)), + OPT_CALLBACK(0, "max-stack", &max_stack_depth, "num", + "Set the maximum stack depth when collecting lopck contention, " + "Default: " __stringify(CONTENTION_STACK_DEPTH), parse_max_stack), OPT_INTEGER(0, "stack-skip", &stack_skip, "Set the number of stack depth to skip when finding a lock caller, " "Default: " __stringify(CONTENTION_STACK_SKIP)), --=20 2.38.1.273.g43a17bfeac-goog From nobody Wed Apr 8 20:03:33 2026 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 B89EEECAAA1 for ; Fri, 28 Oct 2022 18:02:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230197AbiJ1SCB (ORCPT ); Fri, 28 Oct 2022 14:02:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbiJ1SBj (ORCPT ); Fri, 28 Oct 2022 14:01:39 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 936C020FB2B; Fri, 28 Oct 2022 11:01:38 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id u8-20020a17090a5e4800b002106dcdd4a0so10552262pji.1; Fri, 28 Oct 2022 11:01:38 -0700 (PDT) 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=BDQ26YrilcoiUxmd9QdQ1Dk7XFU7csSgsYNB1op6NE8=; b=SQ3Z7rvGLUrN/t+Hbqt2wDeDYS+lmrdAuACOFCN3M0r2GzZxb/crepMgS5OP/2NbkF cShzFKOVPzUVMu/4Q3R7Bz/pcOtmgyOxVgdcU+PSkvvPXf/mHjwUInz7cX/LFupYbQsF 5fgXhixo3JpdAiOIoqLKejnqonJtnoS8NuHJ8Z16m3ZpXaaFDLjXee+tNGbpTWloi/tz qYP1zAB6XKeJ8lA1jd6b3EyIYqGIPUOyP5PtS0TonCxJDzbiJqq8cVzxqQ9WKHgzdm8/ tEyKfNfcJExD656B2UX8dM/cEOY4pkLpgCRU4vC4t7G3xWFgwSZFqCym2Q/LfDnemOqf szkA== 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=BDQ26YrilcoiUxmd9QdQ1Dk7XFU7csSgsYNB1op6NE8=; b=ji/c5lZiXBorY7XHTCEpMCOUzcIOgIA5Ei1GLUbV46y5Jl2NnztKMVMe1XFviUCDOn BnAo0bWls/53Z3Mj6qZPXgr+Kku3QX0tEeezEn+QHgQ8TiKWSL0h4+ONtEwu1eDNiFEP OeHHQuFl9cVpkNG9n8lxu72Yw9ababNJThyIDzllbck2pzDrvR/g16kIW8kRlM9KcE/u J0dX72tcq7o7yoH3i3eZb4LGUMmWi+JTOIRmVvpI6jZST/GhcpmXfpw+tqLOmMZ7JQ7d sV4nKpoqrL+ry1+hLUgW74cl+xNnhmNrFdVEAiP5zOQnNKvYBHZadZ+NoTUEbuXCypLC 3NLg== X-Gm-Message-State: ACrzQf0mrUCsA/fs63fNQJ2Cgcz6jaBVgQcUGhAuk7340LcZE4W/tK/0 3TdmgA7Ur5m2Lw755i/9dwM= X-Google-Smtp-Source: AMsMyM5m9Lm/S0KoGT3x/3K7T1Jq3Rxgk521iBeyuY+kBc39zhp8SIBXmFAjnqpX4WDh/taOsk3Fiw== X-Received: by 2002:a17:902:ce0e:b0:17d:a730:3835 with SMTP id k14-20020a170902ce0e00b0017da7303835mr172589plg.131.1666980097967; Fri, 28 Oct 2022 11:01:37 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:976f:f075:7c14:87a2]) by smtp.gmail.com with ESMTPSA id n3-20020a170903110300b00186b86ed450sm3400236plh.156.2022.10.28.11.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 11:01:36 -0700 (PDT) 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 Subject: [PATCH 3/4] perf lock contention: Avoid variable length arrays Date: Fri, 28 Oct 2022 11:01:27 -0700 Message-Id: <20221028180128.3311491-4-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221028180128.3311491-1-namhyung@kernel.org> References: <20221028180128.3311491-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 msan also warns about the use of VLA for stack_trace variable. We can dynamically allocate instead. While at it, simplify the error handle a bit (and fix bugs). Signed-off-by: Namhyung Kim --- tools/perf/util/bpf_lock_contention.c | 41 ++++++++++++++++++--------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lo= ck_contention.c index 06466da792e4..0deec1178778 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -108,28 +108,36 @@ int lock_contention_stop(void) =20 int lock_contention_read(struct lock_contention *con) { - int fd, stack; + int fd, stack, err =3D 0; s32 prev_key, key; struct lock_contention_data data =3D {}; - struct lock_stat *st; + struct lock_stat *st =3D NULL; struct machine *machine =3D con->machine; - u64 stack_trace[con->max_stack]; + u64 *stack_trace; + size_t stack_size =3D con->max_stack * sizeof(*stack_trace); =20 fd =3D bpf_map__fd(skel->maps.lock_stat); stack =3D bpf_map__fd(skel->maps.stacks); =20 con->lost =3D skel->bss->lost; =20 + stack_trace =3D zalloc(stack_size); + if (stack_trace =3D=3D NULL) + return -1; + prev_key =3D 0; while (!bpf_map_get_next_key(fd, &prev_key, &key)) { struct map *kmap; struct symbol *sym; int idx =3D 0; =20 + /* to handle errors in the loop body */ + err =3D -1; + bpf_map_lookup_elem(fd, &key, &data); st =3D zalloc(sizeof(*st)); if (st =3D=3D NULL) - return -1; + break; =20 st->nr_contended =3D data.count; st->wait_time_total =3D data.total_time; @@ -163,25 +171,32 @@ int lock_contention_read(struct lock_contention *con) st->name =3D strdup(sym->name); =20 if (ret < 0 || st->name =3D=3D NULL) - return -1; + break; } else if (asprintf(&st->name, "%#lx", (unsigned long)st->addr) < 0) { - free(st); - return -1; + break; } =20 if (verbose) { - st->callstack =3D memdup(stack_trace, sizeof(stack_trace)); - if (st->callstack =3D=3D NULL) { - free(st); - return -1; - } + st->callstack =3D memdup(stack_trace, stack_size); + if (st->callstack =3D=3D NULL) + break; } =20 hlist_add_head(&st->hash_entry, con->result); prev_key =3D key; + + /* we're fine now, reset the values */ + st =3D NULL; + err =3D 0; } =20 - return 0; + free(stack_trace); + if (st) { + free(st->name); + free(st); + } + + return err; } =20 int lock_contention_finish(void) --=20 2.38.1.273.g43a17bfeac-goog From nobody Wed Apr 8 20:03:33 2026 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 6FDF3ECAAA1 for ; Fri, 28 Oct 2022 18:02:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230104AbiJ1SCF (ORCPT ); Fri, 28 Oct 2022 14:02:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230012AbiJ1SBp (ORCPT ); Fri, 28 Oct 2022 14:01:45 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24B16211290; Fri, 28 Oct 2022 11:01:40 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id e4so5416208pfl.2; Fri, 28 Oct 2022 11:01:40 -0700 (PDT) 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=bUx8fY5yV5k6b3NAzZ7ONnYGBUoPPnSRBV9IAdB2IcQ=; b=R5qTkGNPJ2owG22N7vSR56g7SchuiPlUzXI4dNN1k/rvLdTdqG4kadsZfKegVIwN3o TvJ+pVZ2pU3FtvqqRVpQ3m52vnAGIAr95xQetLdYfQ4vq28RiTHw9kdJTuDUysll5xnO 3Tos32ojE0o1gtPF2NjT8CPvwK8nzy+JcYOsS6vVJSWpMIbTbdX6T63xKsDjuBi3Kiu1 eVING4QaSDU1jdHSCxToNVDMQIros4oZD2YpJHGXTO+mfkDRwiM4NmeqUN5cSUCyrQW7 1/kY9mkFENtb2XZzYGnwY+R5EFuLHvnUUHAawQEd0e6id73h9c/3NLyUoYcwZAtB8cSw cPHA== 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=bUx8fY5yV5k6b3NAzZ7ONnYGBUoPPnSRBV9IAdB2IcQ=; b=bscsi6Us4db1wZnhialOlVVYmGLNL28PjeBy+ULBGEDa+nA6hPhf8lLHziaFvl0R6U BMgvYt1X2ocTVAa6vj37pJM4Id/PNUsepAQSzXD8++Ibu9wgwp4Fdxbq9JN5uB3mMtiA R15UCFXLG6sODhBYIWmGJB3Dg9J4PqZF2StFxWXeetGKBkegAXIB+twBNXphPJciUb6a cN5haWj1nSC9dh/y9I+5nmcX26cen/oy+ejxRdsLxGmO43IS4V3V00jYlLfSaCwg2V6F xVgZ3a27pvkuFv1rv/MBkcYxiHc61EqO7GjMtJ7DOxQzxgR7z1LlbtRxRYav9d+9HwMf dD7Q== X-Gm-Message-State: ACrzQf3+u7hfy7izE+tmR8BD8wzoZ7hBH/Wi9cm/rRKh/flH/uV5tO0x MoEAPbRo+et/IADdVYTrT8A= X-Google-Smtp-Source: AMsMyM4/4142AtL9gDKsW66R2DQwFckkQXdIqI8rIATA3ZjgBGVT7PVXnop8c1DLVI7LR3SYgeTyiQ== X-Received: by 2002:a63:1308:0:b0:440:5517:c99d with SMTP id i8-20020a631308000000b004405517c99dmr636154pgl.550.1666980100358; Fri, 28 Oct 2022 11:01:40 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:976f:f075:7c14:87a2]) by smtp.gmail.com with ESMTPSA id n3-20020a170903110300b00186b86ed450sm3400236plh.156.2022.10.28.11.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 11:01:38 -0700 (PDT) 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 , bpf@vger.kernel.org Subject: [PATCH 4/4] perf lock contention: Increase default stack skip to 4 Date: Fri, 28 Oct 2022 11:01:28 -0700 Message-Id: <20221028180128.3311491-5-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221028180128.3311491-1-namhyung@kernel.org> References: <20221028180128.3311491-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" In most configurations, it works well with skipping 4 entries by default. If some systems still have 3 BPF internal stack frames, the next frame should be in a lock function which will be skipped later when it tries to find a caller. So increasing to 4 won't affect such systems too. With --stack-skip=3D0, I can see something like this: 24 49.84 us 7.41 us 2.08 us mutex bpf_prog_e1b85= 959d520446c_contention_begin+0x12e 0xffffffffc045040e bpf_prog_e1b85959d520446c_contentio= n_begin+0x12e 0xffffffffc045040e bpf_prog_e1b85959d520446c_contentio= n_begin+0x12e 0xffffffff82ea2071 bpf_trace_run2+0x51 0xffffffff82de775b __bpf_trace_contention_begin+0xb 0xffffffff82c02045 __mutex_lock+0x245 0xffffffff82c019e3 __mutex_lock_slowpath+0x13 0xffffffff82c019c0 mutex_lock+0x20 0xffffffff830a083c kernfs_iop_permission+0x2c Cc: Song Liu Cc: bpf@vger.kernel.org Signed-off-by: Namhyung Kim --- tools/perf/util/lock-contention.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/lock-contention.h b/tools/perf/util/lock-conte= ntion.h index b8cb8830b7bc..e3c061b1795b 100644 --- a/tools/perf/util/lock-contention.h +++ b/tools/perf/util/lock-contention.h @@ -91,7 +91,7 @@ struct thread_stat { * Number of stack trace entries to skip when finding callers. * The first few entries belong to the locking implementation itself. */ -#define CONTENTION_STACK_SKIP 3 +#define CONTENTION_STACK_SKIP 4 =20 /* * flags for lock:contention_begin --=20 2.38.1.273.g43a17bfeac-goog