From patchwork Thu Apr 6 21:06:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 13204240 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 7ED64C77B6F for ; Thu, 6 Apr 2023 21:06:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236566AbjDFVGS (ORCPT ); Thu, 6 Apr 2023 17:06:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230013AbjDFVGR (ORCPT ); Thu, 6 Apr 2023 17:06:17 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 427CF7695; Thu, 6 Apr 2023 14:06:16 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id qe8-20020a17090b4f8800b0023f07253a2cso41834170pjb.3; Thu, 06 Apr 2023 14:06:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680815176; x=1683407176; 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=DQHjim2b0yMTMa0pJ6UBA3m+CHWny/YWANmbBtZt/VM=; b=VJC8IjaH64njjW79hVKy3WUlQE+qs67A8DgvPgWdg+fdPxoCQL8sTRdBSOwtiiJlw1 NSccr1HtapFBT5boikl6arLPOKUBtD8i6HHSN5Aq4n0JBq8INbKGx+IaL5G5lUst87a2 6EYfPaN+smv1uCm7n4AftMapRl4qwE3VuO80+hsJiQN73Rkx22tUEyfMirf9td+/oxXd DIiMGWvsplboqLPbaujoN280Dm2GYLMlUni5904K+n0BQLIAturPR/Jpc+0fzWEqhTZt iTs/YASBsrLbFcFfisVXXd06RlWSzl820JK7wyXmJe2zuYo4uoEvR3zfIyQWm/24kNdV Ss/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680815176; x=1683407176; 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=DQHjim2b0yMTMa0pJ6UBA3m+CHWny/YWANmbBtZt/VM=; b=dIcNPBwLFctdfCNHdJ5bgrOrGX0JFBdt3Jx7Spj9MVjv5lnnWXEM8L1omy7fSZRcHD N+En6Gb0Cq+D63vdQqyRBuRm00/7sbIlTR8GAqsweR+4bUSsQeHKD9xI4Qkh6XTrhjV8 yAxI/FTVuaejKpurMu5Fy8F/jGbzhMMmzvH/od937DcRKdMFcY6YUos4Ic4VOiRt7elt aGtiwGW2oNn8C4+w1mP2Guc5qgAfu7YmgNAbR+RgWvjMeJRqIGBHFt8If1TPQyCQKlVN COQxhnf6nLBcr6vShl6lUMCjqEjZ3h7idNRtfjrbS6UOak6uRth4Yi9z4LnT8PHdlFwJ d8Ow== X-Gm-Message-State: AAQBX9dV3oQM4NZKXVGAxkNLW5lgCPCCBR60HJvBm33roGFMNEZ1Iv4F 4/37j7hZRbVGrF0ulDi5VZcslDu5SbI= X-Google-Smtp-Source: AKy350bkl6KvaHqRNVvsSFqVI3904a3o+yyENiSBlqxPNU+GN5i85yZhFAWLOSogZJ8Ue/5/Y1MnlA== X-Received: by 2002:a17:902:da8d:b0:19d:af20:3fe8 with SMTP id j13-20020a170902da8d00b0019daf203fe8mr639149plx.21.1680815175598; Thu, 06 Apr 2023 14:06:15 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2d4:203:3301:38fe:e39e:3d51]) by smtp.gmail.com with ESMTPSA id g5-20020a170902868500b001a0667822c8sm1777837plo.94.2023.04.06.14.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 14:06:15 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Song Liu , Hao Luo , bpf@vger.kernel.org, Juri Lelli Subject: [PATCH 1/7] perf lock contention: Simplify parse_lock_type() Date: Thu, 6 Apr 2023 14:06:05 -0700 Message-Id: <20230406210611.1622492-2-namhyung@kernel.org> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230406210611.1622492-1-namhyung@kernel.org> References: <20230406210611.1622492-1-namhyung@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org The get_type_flag() should check both str and name fields in the lock_type_table so that it can find the appropriate flag without retrying with ':R' or ':W' suffix from the caller. Also fix a typo in the rt-mutex. Signed-off-by: Namhyung Kim --- tools/perf/builtin-lock.c | 43 ++++++++------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 32ec58fb80e4..695ce6bd64f7 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1557,7 +1557,7 @@ static const struct { { LCB_F_SPIN | LCB_F_WRITE, "rwlock:W", "rwlock" }, { LCB_F_READ, "rwsem:R", "rwsem" }, { LCB_F_WRITE, "rwsem:W", "rwsem" }, - { LCB_F_RT, "rt=mutex", "rt-mutex" }, + { LCB_F_RT, "rt-mutex", "rt-mutex" }, { LCB_F_RT | LCB_F_READ, "rwlock-rt:R", "rwlock-rt" }, { LCB_F_RT | LCB_F_WRITE, "rwlock-rt:W", "rwlock-rt" }, { LCB_F_PERCPU | LCB_F_READ, "pcpu-sem:R", "percpu-rwsem" }, @@ -1596,6 +1596,10 @@ static unsigned int get_type_flag(const char *str) if (!strcmp(lock_type_table[i].name, str)) return lock_type_table[i].flags; } + for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) { + if (!strcmp(lock_type_table[i].str, str)) + return lock_type_table[i].flags; + } return UINT_MAX; } @@ -2121,46 +2125,15 @@ static int parse_lock_type(const struct option *opt __maybe_unused, const char * unsigned int flags = get_type_flag(tok); if (flags == -1U) { - char buf[32]; - - if (strchr(tok, ':')) - continue; - - /* try :R and :W suffixes for rwlock, rwsem, ... */ - scnprintf(buf, sizeof(buf), "%s:R", tok); - flags = get_type_flag(buf); - if (flags != UINT_MAX) { - if (!add_lock_type(flags)) { - ret = -1; - break; - } - } - - scnprintf(buf, sizeof(buf), "%s:W", tok); - flags = get_type_flag(buf); - if (flags != UINT_MAX) { - if (!add_lock_type(flags)) { - ret = -1; - break; - } - } - continue; + pr_err("Unknown lock flags: %s\n", tok); + ret = -1; + break; } if (!add_lock_type(flags)) { ret = -1; break; } - - if (!strcmp(tok, "mutex")) { - flags = get_type_flag("mutex-spin"); - if (flags != UINT_MAX) { - if (!add_lock_type(flags)) { - ret = -1; - break; - } - } - } } free(s); From patchwork Thu Apr 6 21:06:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 13204241 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 6DC76C76196 for ; Thu, 6 Apr 2023 21:06:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237263AbjDFVGT (ORCPT ); Thu, 6 Apr 2023 17:06:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjDFVGS (ORCPT ); Thu, 6 Apr 2023 17:06:18 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 594D67683; Thu, 6 Apr 2023 14:06:17 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id le6so38592683plb.12; Thu, 06 Apr 2023 14:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680815177; x=1683407177; 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=dQ3pP06/vkhTaryl+NLjH5tImeyj0o8TuktuLvogXTQ=; b=J0OSbxA45dv3BUhE6KsxYmllTmH7ivCr2Ee8Fn/cQtIk3VXC/p4+42kd9bohqzPWVa j1OL5n33OkXr9qoMN2YKGwpBKAUnIb19Z+zHziZddNwUWXc5oQzRkcL5dVW/TOdbDqyx o7DUcn0AMFMVVquO+8HhoQfQHprTg6ioKqdaQQfPxxwbdVAdAkhEzvqk6ANUAbRCUgk7 iDZ02bvbf/rROuDkrPGBV4Eu3W/Xm5IaBaNY/dm4ZuwTIFABTJGsC6l2e8HLzbf43Iyu nxyzfOtk8V7iyuZU1zI1i1maGnBnGzF6miq6JUY7ICqNHEbya+uZOsK6+bbP92eVE8BK AN2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680815177; x=1683407177; 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=dQ3pP06/vkhTaryl+NLjH5tImeyj0o8TuktuLvogXTQ=; b=IVmdY4it2YgE5n5UtfNUB4QsTsbx7hR2D3trJtXJipJmXNZH7j6d7lNjPrnJAlKhAD CwNb0F0u2DWiEdX0yG8vYhvjgEY4nFld3jlUHxmbXg0Chj6BNWzhujc8vgXTPfcphcwR AynXlO9jqMiUo0Q6SiX5oQOu7wSNqzipKjeTpIVCEnNVBwT2QaKTDTUo9PuFfs5VxDKL oVS9as0Cb7W7jRV25s9vSKOD5w7iu9AbrfPJEr0CPKQhSOGjnQy7Jen4YAwWY9ADleqR /66GyAqQNbzPidNoCGa31Vxg8JLydD+npL287NtOUOSVFXC5APPu40Djne+cA8b/YCUr vggQ== X-Gm-Message-State: AAQBX9ee3Yr3RJgbHAx5bJOjLqwKQHh1ky+VGJpVrNdf5HXAbZT1Z1vq SXEngcwxybCRXtleNKAMtks= X-Google-Smtp-Source: AKy350YOjUfdcnsjqf+TP1sVZ4kWr7vIbNmeF513W2HYDOvcepZSYYh1e1yJx+UqlvwEG2L7D9gtbw== X-Received: by 2002:a17:902:c613:b0:1a1:b440:3773 with SMTP id r19-20020a170902c61300b001a1b4403773mr409103plr.27.1680815176746; Thu, 06 Apr 2023 14:06:16 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2d4:203:3301:38fe:e39e:3d51]) by smtp.gmail.com with ESMTPSA id g5-20020a170902868500b001a0667822c8sm1777837plo.94.2023.04.06.14.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 14:06:16 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Song Liu , Hao Luo , bpf@vger.kernel.org, Juri Lelli Subject: [PATCH 2/7] perf lock contention: Use -M for --map-nr-entries Date: Thu, 6 Apr 2023 14:06:06 -0700 Message-Id: <20230406210611.1622492-3-namhyung@kernel.org> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230406210611.1622492-1-namhyung@kernel.org> References: <20230406210611.1622492-1-namhyung@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Users often want to change the map size, let's add a short option (-M) for that. Signed-off-by: Namhyung Kim --- tools/perf/Documentation/perf-lock.txt | 1 + tools/perf/builtin-lock.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentation/perf-lock.txt index 37aae194a2a1..b5e5d088d51c 100644 --- a/tools/perf/Documentation/perf-lock.txt +++ b/tools/perf/Documentation/perf-lock.txt @@ -155,6 +155,7 @@ CONTENTION OPTIONS --tid=:: Record events on existing thread ID (comma separated list). +-M:: --map-nr-entries=:: Maximum number of BPF map entries (default: 10240). diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 695ce6bd64f7..ef56bf90058d 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -2294,7 +2294,7 @@ int cmd_lock(int argc, const char **argv) "Trace on existing process id"), OPT_STRING(0, "tid", &target.tid, "tid", "Trace on existing thread id (exclusive to --pid)"), - OPT_CALLBACK(0, "map-nr-entries", &bpf_map_entries, "num", + OPT_CALLBACK('M', "map-nr-entries", &bpf_map_entries, "num", "Max number of BPF map entries", parse_map_entry), OPT_CALLBACK(0, "max-stack", &max_stack_depth, "num", "Set the maximum stack depth when collecting lopck contention, " From patchwork Thu Apr 6 21:06:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 13204242 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 B104AC77B6E for ; Thu, 6 Apr 2023 21:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237369AbjDFVGV (ORCPT ); Thu, 6 Apr 2023 17:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237133AbjDFVGT (ORCPT ); Thu, 6 Apr 2023 17:06:19 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABBEC8A51; Thu, 6 Apr 2023 14:06:18 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id p3-20020a17090a74c300b0023f69bc7a68so41851980pjl.4; Thu, 06 Apr 2023 14:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680815178; x=1683407178; 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=zxgVwiXvPJlNQaBMQo/Fw6ZQAn8/5u3aWEkaLTlJ8CU=; b=GPg6on8Y7wICuJC6Y8Yy09cCC7BXBxhXNQJKNIBSxkW+EK2MzySsLg9arYaqG4SqYl K4hy2H6oisP/93sUeLh0zv8A8LvhaYXpOBcznkiv506kVZIAIEv9ggrmztaBRGCVekdW 2C4EkJgp7WaX5E1dI4lQaxdmNlmPoOQnXLT+PlgNHMaIf+J2bu5NvTwtV4Sqe1GnunrK jzgOKCZyC6/ols+Kwi3Z8pCrs8zHrKqxctEHGXS+E5zzSb8RSB7CgUrmZ5+eG2evHQFm o6Q/15MlUptNRyjVczPF7r9EKq4YqdSCSpYJgeBSq71CDxCeP14XtzXaNO1m5HlJIrN/ lzbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680815178; x=1683407178; 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=zxgVwiXvPJlNQaBMQo/Fw6ZQAn8/5u3aWEkaLTlJ8CU=; b=EP5feL0ib6QEp6PQBV++/6Za9+ov7yA84VaCvJ9TtIGmd7nLN3k3q48u1Cfi1gGaaJ 4IAx81O5C1oK0lGGaMUq83opNg1TO9p/rxZVS22JVNI5nAzUh0mb6zfC+rbUFgZj1UOn BNhG4fLXdOVDCe3Wlb9qPqsqNCUSUzI8+1erQMiqQ5L6BU/rFYSUV9BgJ9RRDJ0dInZl CeXpR8t0gUPdimUpCHoWZ1JzDxJ8X2wGWn8UZGmioQkK5R/VqNG38ZnEa6ulSnWZi6cX 8SYcMg7OErtPt836oSGOhsH0qQc7miqXz4rk2lCazUEVjBusW69+OPVYwG2/BRyyfG6e +8lw== X-Gm-Message-State: AAQBX9feH1DT8XC2oqxI1i8I+GZgD1Gv2QZxWEYKbeXCqv7SKDaWNy9R mL5Ukn5/9VnQSXm6ebml9rc= X-Google-Smtp-Source: AKy350bjW0oXlp9NKLeowSyWW9oHMCv07TYsBSV9lHFASWNW0gpeNrkPIWh52Tofm9GqKD2IPk6icw== X-Received: by 2002:a17:902:ce88:b0:19e:2fb0:a5d9 with SMTP id f8-20020a170902ce8800b0019e2fb0a5d9mr7367025plg.32.1680815177855; Thu, 06 Apr 2023 14:06:17 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2d4:203:3301:38fe:e39e:3d51]) by smtp.gmail.com with ESMTPSA id g5-20020a170902868500b001a0667822c8sm1777837plo.94.2023.04.06.14.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 14:06:17 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Song Liu , Hao Luo , bpf@vger.kernel.org, Juri Lelli Subject: [PATCH 3/7] perf lock contention: Update default map size to 16384 Date: Thu, 6 Apr 2023 14:06:07 -0700 Message-Id: <20230406210611.1622492-4-namhyung@kernel.org> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230406210611.1622492-1-namhyung@kernel.org> References: <20230406210611.1622492-1-namhyung@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org The BPF hash map will align the map size to a power of 2. So 10k would be 16k anyway. Let's have the actual size to avoid confusions. Signed-off-by: Namhyung Kim --- tools/perf/Documentation/perf-lock.txt | 3 ++- tools/perf/builtin-lock.c | 2 +- tools/perf/util/bpf_skel/lock_contention.bpf.c | 5 +---- tools/perf/util/bpf_skel/lock_data.h | 3 +++ 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentation/perf-lock.txt index b5e5d088d51c..6e5ba3cd2b72 100644 --- a/tools/perf/Documentation/perf-lock.txt +++ b/tools/perf/Documentation/perf-lock.txt @@ -157,7 +157,8 @@ CONTENTION OPTIONS -M:: --map-nr-entries=:: - Maximum number of BPF map entries (default: 10240). + Maximum number of BPF map entries (default: 16384). + This will be aligned to a power of 2. --max-stack=:: Maximum stack depth when collecting lock contention (default: 8). diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index ef56bf90058d..9b92c7a5aefb 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -60,7 +60,7 @@ static bool show_thread_stats; static bool show_lock_addrs; static bool show_lock_owner; static bool use_bpf; -static unsigned long bpf_map_entries = 10240; +static unsigned long bpf_map_entries = MAX_ENTRIES; static int max_stack_depth = CONTENTION_STACK_DEPTH; static int stack_skip = CONTENTION_STACK_SKIP; static int print_nr_entries = INT_MAX / 2; diff --git a/tools/perf/util/bpf_skel/lock_contention.bpf.c b/tools/perf/util/bpf_skel/lock_contention.bpf.c index 3f4ee3992e81..f9d2d792ccc8 100644 --- a/tools/perf/util/bpf_skel/lock_contention.bpf.c +++ b/tools/perf/util/bpf_skel/lock_contention.bpf.c @@ -7,9 +7,6 @@ #include "lock_data.h" -/* default buffer size */ -#define MAX_ENTRIES 10240 - /* for collect_lock_syms(). 4096 was rejected by the verifier */ #define MAX_CPUS 1024 @@ -63,7 +60,7 @@ struct { __uint(type, BPF_MAP_TYPE_HASH); __uint(key_size, sizeof(__u64)); __uint(value_size, sizeof(__u32)); - __uint(max_entries, 16384); + __uint(max_entries, MAX_ENTRIES); } lock_syms SEC(".maps"); struct { diff --git a/tools/perf/util/bpf_skel/lock_data.h b/tools/perf/util/bpf_skel/lock_data.h index 1ba61cb4d480..260062a9f2ab 100644 --- a/tools/perf/util/bpf_skel/lock_data.h +++ b/tools/perf/util/bpf_skel/lock_data.h @@ -15,6 +15,9 @@ struct contention_task_data { char comm[TASK_COMM_LEN]; }; +/* default buffer size */ +#define MAX_ENTRIES 16384 + /* * Upper bits of the flags in the contention_data are used to identify * some well-known locks which do not have symbols (non-global locks). From patchwork Thu Apr 6 21:06:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 13204244 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 5B310C7618D for ; Thu, 6 Apr 2023 21:06:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238280AbjDFVGa (ORCPT ); Thu, 6 Apr 2023 17:06:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237338AbjDFVGU (ORCPT ); Thu, 6 Apr 2023 17:06:20 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88E649012; Thu, 6 Apr 2023 14:06:19 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id ja10so38616005plb.5; Thu, 06 Apr 2023 14:06:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680815179; x=1683407179; 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=EyYImB6w0gbLwOhqAGS6GeXGg4AcAsKtDrgZnurJMx8=; b=o6bX848aRmyvy3jboloj4EINCdFM9X5H44+UT55eIy4lYVFD88bhmTKFsn24uW084j YP49XfOAgZEmV73Lm0KBL/EhxndEe8naLFw6gRNhLyzqqjqr2yqSx6I7naOfHik/YIu5 JelIwU24eYT73Rg7L/AGXxdeqFKBYLAzxZRxFPMqkqtpEYvrSmmd6MF+lOrDPhMosMPL 2DurjLQytI3KC40hYTLXtyEZ0otFFP3T65jXPwdZL/1cNKTripGwXI65PH9NgIxQS/pV mseQYMTXyuTWqgrIEPsvew1VQBb5s1PWLlcrprRv14na3FiknV0Vk0mMI6YQTHuy94W/ Jwfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680815179; x=1683407179; 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=EyYImB6w0gbLwOhqAGS6GeXGg4AcAsKtDrgZnurJMx8=; b=8LHFx0+pUmA5g3NGp2Lo3gtHRlRl75OVdFjmUrSSHwg/p7mixON2yeWD8mvaIisoAz CPBkPoHA7hh6+Ss4312nvYIk5y5c455fJHD2VxsFAMRGWmDnclN2MZIRbNGTcP3OrYfM vl0F3T9dNxIL1JPcVo1ZICJP/Eyz9d9WM5aVKgnAe9uEr+8LEhMarlfAXiC/UWf2Z9eM z0pM5+9yDjEvn8mV0kObPWIlBgIM+qM8kCIK40rhMSnjdzPToDObk0hKCTu9R+axhsu7 8L2j1zvtB5popmV8ODyDf7V1iPVDXPrQ0p6BhOjD20Y8CsozRKYN0hz1rrJW5zwgyV/a B5tg== X-Gm-Message-State: AAQBX9ced3jC3ekgrzo0U5xow7E3MQhD0ZN+D96eit4Ao8HprC0KVP47 AaJ9b2vwO+gceVT0yw/ncxA= X-Google-Smtp-Source: AKy350bhzJ+y82FJXwFNvJ56CllVZBUkuGPJvHxLb8UujQn2wqPWcuTPV2Tq+HRvAUhf4zVt7tAcRw== X-Received: by 2002:a17:903:11d0:b0:1a1:bff4:4a06 with SMTP id q16-20020a17090311d000b001a1bff44a06mr531968plh.24.1680815178970; Thu, 06 Apr 2023 14:06:18 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2d4:203:3301:38fe:e39e:3d51]) by smtp.gmail.com with ESMTPSA id g5-20020a170902868500b001a0667822c8sm1777837plo.94.2023.04.06.14.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 14:06:18 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Song Liu , Hao Luo , bpf@vger.kernel.org, Juri Lelli Subject: [PATCH 4/7] perf lock contention: Add data failure stat Date: Thu, 6 Apr 2023 14:06:08 -0700 Message-Id: <20230406210611.1622492-5-namhyung@kernel.org> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230406210611.1622492-1-namhyung@kernel.org> References: <20230406210611.1622492-1-namhyung@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org It's possible to fail to update the data when the lock_stat map is full. We should check that case and show the number at the end. $ sudo ./perf lock con -ablv -E3 -- ./perf bench sched messaging ... contended total wait max wait avg wait address symbol 6157 208.48 ms 69.29 us 33.86 us ffff934c001c1f00 (spinlock) 4030 72.04 ms 61.84 us 17.88 us ffff934c000415c0 (spinlock) 3201 50.30 ms 47.73 us 15.71 us ffff934c2eead850 (spinlock) === output for debug === bad: 0, total: 13388 bad rate: 0.00 % histogram of failure reasons task: 0 stack: 0 time: 0 data: 0 <----- added Signed-off-by: Namhyung Kim --- tools/perf/builtin-lock.c | 4 +++- tools/perf/util/bpf_lock_contention.c | 1 + tools/perf/util/bpf_skel/lock_contention.bpf.c | 4 +++- tools/perf/util/lock-contention.h | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 9b92c7a5aefb..01b318d6c80a 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1626,7 +1626,7 @@ static void sort_contention_result(void) static void print_bpf_events(int total, struct lock_contention_fails *fails) { /* Output for debug, this have to be removed */ - int broken = fails->task + fails->stack + fails->time; + int broken = fails->task + fails->stack + fails->time + fails->data; if (quiet || total == 0 || (broken == 0 && verbose <= 0)) return; @@ -1640,7 +1640,9 @@ static void print_bpf_events(int total, struct lock_contention_fails *fails) pr_info(" %10s: %d\n", "task", fails->task); pr_info(" %10s: %d\n", "stack", fails->stack); pr_info(" %10s: %d\n", "time", fails->time); + pr_info(" %10s: %d\n", "data", fails->data); } + static void print_contention_result(struct lock_contention *con) { struct lock_stat *st; diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lock_contention.c index 8a5d0eb44189..0071058ac3d2 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -262,6 +262,7 @@ int lock_contention_read(struct lock_contention *con) con->fails.task = skel->bss->task_fail; con->fails.stack = skel->bss->stack_fail; con->fails.time = skel->bss->time_fail; + con->fails.data = skel->bss->data_fail; stack_trace = zalloc(stack_size); if (stack_trace == NULL) diff --git a/tools/perf/util/bpf_skel/lock_contention.bpf.c b/tools/perf/util/bpf_skel/lock_contention.bpf.c index f9d2d792ccc8..cb87c98e5340 100644 --- a/tools/perf/util/bpf_skel/lock_contention.bpf.c +++ b/tools/perf/util/bpf_skel/lock_contention.bpf.c @@ -124,6 +124,7 @@ int aggr_mode; int task_fail; int stack_fail; int time_fail; +int data_fail; static inline int can_record(u64 *ctx) { @@ -380,7 +381,8 @@ int contention_end(u64 *ctx) if (aggr_mode == LOCK_AGGR_ADDR) first.flags |= check_lock_type(pelem->lock, pelem->flags); - bpf_map_update_elem(&lock_stat, &key, &first, BPF_NOEXIST); + if (bpf_map_update_elem(&lock_stat, &key, &first, BPF_NOEXIST) < 0) + __sync_fetch_and_add(&data_fail, 1); bpf_map_delete_elem(&tstamp, &pid); return 0; } diff --git a/tools/perf/util/lock-contention.h b/tools/perf/util/lock-contention.h index 10c28302420c..3ed1cad370fc 100644 --- a/tools/perf/util/lock-contention.h +++ b/tools/perf/util/lock-contention.h @@ -126,6 +126,7 @@ struct lock_contention_fails { int task; int stack; int time; + int data; }; struct lock_contention { From patchwork Thu Apr 6 21:06:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 13204243 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 12A9CC77B6C for ; Thu, 6 Apr 2023 21:06:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238250AbjDFVG3 (ORCPT ); Thu, 6 Apr 2023 17:06:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237423AbjDFVGV (ORCPT ); Thu, 6 Apr 2023 17:06:21 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A36A4A260; Thu, 6 Apr 2023 14:06:20 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id le6so38592767plb.12; Thu, 06 Apr 2023 14:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680815180; x=1683407180; 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=DBFoBGUsZtlCcm49brE9d8NiEeIvmudl2UdEa0t2qso=; b=agxBXqMPB/e8EYldOhlAOsV8F6tqYhE7pZcY/TWW31wuXDzifZpFbENCmm7aHmI0g3 gxAi/X2i7e7RmvfDBhvBgIppvqNxNAwLrREkDWokcirragWlNN+C2sT36H+FQrHDKBnM oK0JZ+HhWP93N3b4NPBsnIZ9Ri6XSNC6OzRAqwQwn15XdBLhy95A8Ce1ffohCJLTIhd4 aiiAKTgJYQ4ZnFlR6hqVIVsKb8JHsJCgI47EvKjR1Hu1UlJKydniagF4DGeoUvyp+cr1 V/iB5lZ9BHtzjIJS6UXAPDQ970wjqTN9oShZY7oR4IMqwSK66rDfwfJte27A1xyLynDt nGEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680815180; x=1683407180; 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=DBFoBGUsZtlCcm49brE9d8NiEeIvmudl2UdEa0t2qso=; b=fmKiWTn0lror1qA0/0UBUYhcax7t0GyTWj8aXXUCiMdu8sGzQj4UYE51El5sY7JRqi Cm6wnBQwXmEJU07dbpb82GqeYNtjrLUxChuA+PzeRy0fUtnHgywkS4N58jEqt5/5yaum KI66W2FOnll4iKhMIi/Ap9fMmtUFVYsih9NnulWKDB3b94zXMaUhFS8avURdkGEWz/xw FeEFEcnUuTW1USPjwAFd2stQDe9g56qiKNFWlCgctmu+lWA0ggQrnajxi/JVEHZyE889 AJiHLxqxcl1bbG/nXSyCfMMLL5VWBn2kWl7gypiGDb83oWzhROVEbH3nx+eG36T+KYXV 96Lg== X-Gm-Message-State: AAQBX9f5aISsjc2A9e6ALtCakV2DyXMYkIlb2L+uYnHQmfGiaE4hHAhb rm71osooHNzuf7clFFJ3LZg= X-Google-Smtp-Source: AKy350Ze+6gZk1BaxaSYW8bkYftz9rPkwzzOL2VoXpz5toX8VbJiZko1fPZvg8bpc2UXwiWvr/nYsg== X-Received: by 2002:a17:902:e1c1:b0:1a1:ad52:4060 with SMTP id t1-20020a170902e1c100b001a1ad524060mr438506pla.20.1680815180302; Thu, 06 Apr 2023 14:06:20 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2d4:203:3301:38fe:e39e:3d51]) by smtp.gmail.com with ESMTPSA id g5-20020a170902868500b001a0667822c8sm1777837plo.94.2023.04.06.14.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 14:06:19 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Song Liu , Hao Luo , bpf@vger.kernel.org, Juri Lelli Subject: [PATCH 5/7] perf lock contention: Update total/bad stats for hidden entries Date: Thu, 6 Apr 2023 14:06:09 -0700 Message-Id: <20230406210611.1622492-6-namhyung@kernel.org> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230406210611.1622492-1-namhyung@kernel.org> References: <20230406210611.1622492-1-namhyung@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org When -E option is used, it only prints the given number of entries but the event stat at the end should have the numbers for entire entries. Likewise, -S option will hide entries that don't have the named function in the callstack. Also update event stat for them. Signed-off-by: Namhyung Kim --- tools/perf/builtin-lock.c | 11 +++++++++++ tools/perf/util/bpf_lock_contention.c | 4 +++- tools/perf/util/lock-contention.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 01b318d6c80a..7742fa255c44 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1726,6 +1726,17 @@ static void print_contention_result(struct lock_contention *con) break; } + if (print_nr_entries) { + /* update the total/bad stats */ + while ((st = pop_from_result())) { + total += use_bpf ? st->nr_contended : 1; + if (st->broken) + bad++; + } + } + /* some entries are collected but hidden by the callstack filter */ + total += con->nr_filtered; + if (use_bpf) print_bpf_events(total, &con->fails); else diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lock_contention.c index 0071058ac3d2..ea4f697d2a9f 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -299,8 +299,10 @@ int lock_contention_read(struct lock_contention *con) if (con->save_callstack) { bpf_map_lookup_elem(stack, &key.stack_id, stack_trace); - if (!match_callstack_filter(machine, stack_trace)) + if (!match_callstack_filter(machine, stack_trace)) { + con->nr_filtered += data.count; goto next; + } } switch (con->aggr_mode) { diff --git a/tools/perf/util/lock-contention.h b/tools/perf/util/lock-contention.h index 3ed1cad370fc..fa16532c971c 100644 --- a/tools/perf/util/lock-contention.h +++ b/tools/perf/util/lock-contention.h @@ -141,6 +141,7 @@ struct lock_contention { int stack_skip; int aggr_mode; int owner; + int nr_filtered; bool save_callstack; }; From patchwork Thu Apr 6 21:06:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 13204245 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 3D3EFC77B6C for ; Thu, 6 Apr 2023 21:06:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239329AbjDFVGo (ORCPT ); Thu, 6 Apr 2023 17:06:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238328AbjDFVGb (ORCPT ); Thu, 6 Apr 2023 17:06:31 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 353F7AD32; Thu, 6 Apr 2023 14:06:22 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id mp3-20020a17090b190300b0023fcc8ce113so44074894pjb.4; Thu, 06 Apr 2023 14:06:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680815181; x=1683407181; 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=+oGWEwUsmNiSPPHrbfPC0Zq8RGaKBQeVwXfJ92f5QoA=; b=Av3kyPRaWD7g+IfiQO95Qo5AbZAQDecvzwhdF2lP/wjwe36R+Fu0PjqnBf40rp6zjV pffgCHVFK5VsoTIIiqtgDmKHQmEZ/RkrY7Jt2mui4GVt6eNr64/Iad/64GhoZwBz9sZ5 t3lIoFZW5J7Up7/makzmGQITsAO0VFZQOFYLUzlMGfkrLZt60K1k0EmXAtqOqSObIP+x rAlEwQhalQBVZCf/+OSkWh7ZjWhMUs5+pXg8jJbzl598mG5wrW61e/0K19TwyXN5dGi3 d5obuR1PteRpbAvpFKhhvhMwROovzE6s1HlRTE4xpOOBm+gqOZ1rXp3kSqJgtwpjsv/t v65Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680815181; x=1683407181; 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=+oGWEwUsmNiSPPHrbfPC0Zq8RGaKBQeVwXfJ92f5QoA=; b=uI/4MS4UWsSKQGKGGJwx9G8lK9z7anXSFC0CYeVgBP4sHqWfhDgelt9HdnC3xRCrPR fnOvgO3lZsvTTeKdkRghM+Nunsanos0OtnvHYY18RX4pnmy7jN73AYUOowos0LMv/8bG /yVVz3GoTXagdFtssObivIMtN09GExtsvK4mzkzIbe3wATQPOYUOMdD7ZO6nVNvqHKw5 z21mbBf4LTEy65crkIRM6TqIoraEGSYjmcKuv96llDj36XJQoQuEYpPcpyBwqtzxY1Cp eQ9HLRu38lM0wywK4EYjtSM3omi68s7HuXVKceA1owt1omd9hmQ8qHPpxEjQ2XJsfimE lj5g== X-Gm-Message-State: AAQBX9fh4GBm9X65citvR7p54NMuWw7FtztoX4xgnExMuFYpHsxPRhEC JDNGr706JvVvEYVI1xaWJFQ= X-Google-Smtp-Source: AKy350ZB4HscvPM8esmdseMigs9caiqrUqjFaExGuvuITawy8IzOx2Foz8hF1bHFGpyHNLdFUwfgbg== X-Received: by 2002:a17:902:c643:b0:1a2:57c4:2a7a with SMTP id s3-20020a170902c64300b001a257c42a7amr353257pls.29.1680815181405; Thu, 06 Apr 2023 14:06:21 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2d4:203:3301:38fe:e39e:3d51]) by smtp.gmail.com with ESMTPSA id g5-20020a170902868500b001a0667822c8sm1777837plo.94.2023.04.06.14.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 14:06:21 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Song Liu , Hao Luo , bpf@vger.kernel.org, Juri Lelli Subject: [PATCH 6/7] perf lock contention: Revise needs_callstack() condition Date: Thu, 6 Apr 2023 14:06:10 -0700 Message-Id: <20230406210611.1622492-7-namhyung@kernel.org> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230406210611.1622492-1-namhyung@kernel.org> References: <20230406210611.1622492-1-namhyung@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org It needs callstacks for two reasons: * for stack aggregation mode, the map key is the stack id and it can also show the full stack traces when -v is used * for other aggregation modes, the stack filter can be used to limit lock contentions from known call paths The -v option is meaningful (in terms of stack trace) only for stack aggregation mode, so it should not set the save_callstack for other mode like with -t or -l options. I've noticed this with the following command line: $ sudo ./perf lock con -ablv -E 3 -M 16 -- ./perf bench sched messaging ... contended total wait max wait avg wait address symbol 88 4.59 ms 108.07 us 52.13 us ffff935757f46ec0 (spinlock) 33 905.22 us 73.67 us 27.43 us ffff935757f41700 (spinlock) 28 703.69 us 79.28 us 25.13 us ffff938a3d9b0c80 rq_lock (spinlock) === output for debug === bad: 12272, total: 12421 bad rate: 98.80 % histogram of failure reasons task: 8285 stack: 3987 <---------- here time: 0 data: 0 It should not have any failure on stacks since it doesn't use it. No functional change intended. Signed-off-by: Namhyung Kim --- tools/perf/builtin-lock.c | 2 +- tools/perf/util/bpf_lock_contention.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 7742fa255c44..4e24351b18bd 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -77,7 +77,7 @@ static enum lock_aggr_mode aggr_mode = LOCK_AGGR_ADDR; static bool needs_callstack(void) { - return verbose > 0 || !list_empty(&callstack_filters); + return !list_empty(&callstack_filters); } static struct thread_stat *thread_stat_find(u32 tid) diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lock_contention.c index ea4f697d2a9f..9e20fa8ade09 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -346,7 +346,7 @@ int lock_contention_read(struct lock_contention *con) if (data.count) st->avg_wait_time = data.total_time / data.count; - if (con->save_callstack) { + if (con->aggr_mode == LOCK_AGGR_CALLER && verbose > 0) { st->callstack = memdup(stack_trace, stack_size); if (st->callstack == NULL) break; From patchwork Thu Apr 6 21:06:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 13204246 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 4F22FC77B6E for ; Thu, 6 Apr 2023 21:06:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239878AbjDFVGq (ORCPT ); Thu, 6 Apr 2023 17:06:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237801AbjDFVGd (ORCPT ); Thu, 6 Apr 2023 17:06:33 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 779E39753; Thu, 6 Apr 2023 14:06:23 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id v9so2339243pjk.0; Thu, 06 Apr 2023 14:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680815182; x=1683407182; 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=7I+ZTLBAAWmNlN+JBk4TipMBC8vuk1wOji+jyAsKtTA=; b=g4JIygxRKGw+RQeL1AkR1lDj7TucctKNv+PWq71gm17icpuIeT3xmoTuugrHOLcNr0 ORQKJuJ2IVmfYcVCXque1deeq+sB83xaNjsybbNsXrMaGS8MT5otHkBuREnwaW3Y2BPp IEYNGklF4PxLGGX26J+uBP+kmBL5dbuxPTudwSIDknQ0AFQrgzl9UKVP8+xdx23dCTo7 2Z6etn1aXcN6VKa8s1Sw1XMy/aQZE6lp/tWtioVC3FOx5JoS+nhGVJZepj3hhskselX0 Zs4WbVQz24EsYhJXDzcjngDMH3hqMGXGNwItuHOaVg6eTgkhu6zHcUleKquXWZ7+NOqJ vHYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680815182; x=1683407182; 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=7I+ZTLBAAWmNlN+JBk4TipMBC8vuk1wOji+jyAsKtTA=; b=SPSjbwSpKUSkkAvJoCHSLmgCfV72gPBXWX8o1ZQUbscxf7LIp4MpPZZ0kr7aBZPUfu iFyDthWqyWYxwvpiWBV91c8S3hKHfQaxnTQnyi+JpXk7xYv/D/JpNJv0/mop9puF/x8+ 88OwTkXwZb67Aq4clgILA+Mz4gcC/XQ92ph/h5DtbGTQ1ZP9SPt9/+LguYOfvKd9MFTX qxX2WaXMDSDOguihiQBu/j9kl80WWBYGkAnC/W7iJVvCHwHN9DX+5KCtXaFrmpprYFF1 +4Ktr5Kq5YtNJlbz8ntrjYoXQ0Xsp6pVeRNcIWvGz4Mn8bSe5Tv+nSzqy0/rSrpruZLo MW5A== X-Gm-Message-State: AAQBX9c96CYVtNcIytT9ChVWetMs7Ph77rORX/160MMUQCljM64clDJ6 DrBMjccMjvhXrYo7Mr6/Cug= X-Google-Smtp-Source: AKy350b/GP3jdpKFEr7S9KLbbSe9aStLqLmug61iMLgZK620loW/KsTQWHA0VyNjlF5dIGCgY0lrDQ== X-Received: by 2002:a17:903:64c:b0:1a4:fcc9:ec61 with SMTP id kh12-20020a170903064c00b001a4fcc9ec61mr479341plb.5.1680815182514; Thu, 06 Apr 2023 14:06:22 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2d4:203:3301:38fe:e39e:3d51]) by smtp.gmail.com with ESMTPSA id g5-20020a170902868500b001a0667822c8sm1777837plo.94.2023.04.06.14.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 14:06:22 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Song Liu , Hao Luo , bpf@vger.kernel.org, Juri Lelli Subject: [PATCH 7/7] perf lock contention: Do not try to update if hash map is full Date: Thu, 6 Apr 2023 14:06:11 -0700 Message-Id: <20230406210611.1622492-8-namhyung@kernel.org> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230406210611.1622492-1-namhyung@kernel.org> References: <20230406210611.1622492-1-namhyung@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org It doesn't delete data in the task_data and lock_stat maps. The data is kept there until it's consumed by userspace at the end. But it calls bpf_map_update_elem() again and again, and the data will be discarded if the map is full. This is not good. Worse, in the bpf_map_update_elem(), it keeps trying to get a new node even if the map was full. I guess it makes sense if it deletes some node like in the tstamp map (that's why I didn't make the change there). In a pre-allocated hash map, that means it'd iterate all CPU to check the freelist. And it has a bad performance impact on large machines. I've checked it on my 64 CPU machine with this. $ perf bench sched messaging -g 1000 # Running 'sched/messaging' benchmark: # 20 sender and receiver processes per group # 1000 groups == 40000 processes run Total time: 2.825 [sec] And I used the task mode, so that it can guarantee the map is full. The default map entry size is 16K and this workload has 40K tasks. Before: $ sudo ./perf lock con -abt -E3 -- perf bench sched messaging -g 1000 # Running 'sched/messaging' benchmark: # 20 sender and receiver processes per group # 1000 groups == 40000 processes run Total time: 11.299 [sec] contended total wait max wait avg wait pid comm 19284 3.51 s 3.70 ms 181.91 us 1305863 sched-messaging 243 84.09 ms 466.67 us 346.04 us 1336608 sched-messaging 177 66.35 ms 12.08 ms 374.88 us 1220416 node For some reason, it didn't report the data failures. But you can see the total time in the workload is increased a lot (2.8 -> 11.3). If it fails early when the map is full, it goes back to normal. After: $ sudo ./perf lock con -abt -E3 -- perf bench sched messaging -g 1000 # Running 'sched/messaging' benchmark: # 20 sender and receiver processes per group # 1000 groups == 40000 processes run Total time: 3.044 [sec] contended total wait max wait avg wait pid comm 18743 591.92 ms 442.96 us 31.58 us 1431454 sched-messaging 51 210.64 ms 207.45 ms 4.13 ms 1468724 sched-messaging 81 68.61 ms 65.79 ms 847.07 us 1463183 sched-messaging === output for debug === bad: 1164137, total: 2253341 bad rate: 51.66 % histogram of failure reasons task: 0 stack: 0 time: 0 data: 1164137 Signed-off-by: Namhyung Kim --- .../perf/util/bpf_skel/lock_contention.bpf.c | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/bpf_skel/lock_contention.bpf.c b/tools/perf/util/bpf_skel/lock_contention.bpf.c index cb87c98e5340..23f6e63544ed 100644 --- a/tools/perf/util/bpf_skel/lock_contention.bpf.c +++ b/tools/perf/util/bpf_skel/lock_contention.bpf.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "lock_data.h" @@ -126,6 +127,9 @@ int stack_fail; int time_fail; int data_fail; +int task_map_full; +int data_map_full; + static inline int can_record(u64 *ctx) { if (has_cpu) { @@ -177,11 +181,12 @@ static inline int update_task_data(struct task_struct *task) return -1; p = bpf_map_lookup_elem(&task_data, &pid); - if (p == NULL) { + if (p == NULL && !task_map_full) { struct contention_task_data data = {}; BPF_CORE_READ_STR_INTO(&data.comm, task, comm); - bpf_map_update_elem(&task_data, &pid, &data, BPF_NOEXIST); + if (bpf_map_update_elem(&task_data, &pid, &data, BPF_NOEXIST) == -E2BIG) + task_map_full = 1; } return 0; @@ -370,6 +375,12 @@ int contention_end(u64 *ctx) data = bpf_map_lookup_elem(&lock_stat, &key); if (!data) { + if (data_map_full) { + bpf_map_delete_elem(&tstamp, &pid); + __sync_fetch_and_add(&data_fail, 1); + return 0; + } + struct contention_data first = { .total_time = duration, .max_time = duration, @@ -377,12 +388,17 @@ int contention_end(u64 *ctx) .count = 1, .flags = pelem->flags, }; + int err; if (aggr_mode == LOCK_AGGR_ADDR) first.flags |= check_lock_type(pelem->lock, pelem->flags); - if (bpf_map_update_elem(&lock_stat, &key, &first, BPF_NOEXIST) < 0) + err = bpf_map_update_elem(&lock_stat, &key, &first, BPF_NOEXIST); + if (err < 0) { + if (err == -E2BIG) + data_map_full = 1; __sync_fetch_and_add(&data_fail, 1); + } bpf_map_delete_elem(&tstamp, &pid); return 0; }