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: 80539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1312913vqo; Thu, 6 Apr 2023 14:31:54 -0700 (PDT) X-Google-Smtp-Source: AKy350bp0IRqLNTH/CFY4hISg8ukzUWJU1dsiCKHczijKkJVa3Scju8OvhzOpqX7fdtPqNpIf482 X-Received: by 2002:a17:902:b494:b0:1a1:abcc:e44e with SMTP id y20-20020a170902b49400b001a1abcce44emr514094plr.9.1680816714551; Thu, 06 Apr 2023 14:31:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680816714; cv=none; d=google.com; s=arc-20160816; b=J7+p36417Pr5lvWYdQeiAODPqiQtcWw0EQV7ewSqOZYMEo32dRWuhaCkbpEoiu6q6M gaCPM6EL69KHxR3ixWCRJ3vEEEG3MoC44s+WEbuH4AFGUzvqBV9oB379vOQpowjaT+Mj HVIdomW42STg4xbwAohb6CpVEaIcCOCQABMNjQB/kCO/NXrYUQ+VsW8EEX39eKArmG5Q VYF0rR1Umqh67BDnTvi9VtoBjqi2Ghi/sxXO9xV+FKnHPME/ZPkOyrP75qZg5Hym5JRB e2zyCc8/ZgEncunAZ8Sps9F5Bjq+8KmkxGhGo/ML0sBkVNzprLc9mX+uIJ8VozT93mV2 NB2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=DQHjim2b0yMTMa0pJ6UBA3m+CHWny/YWANmbBtZt/VM=; b=K8V1HATydwnZNS5rnTyaU0rzvDSZfmpC0c8eWU6kDqN4wEVD6mE7OmfTb1btIg6Wp5 fUUnX9kU9uG/fFE+R5AOgq5KO26wxJzL/5mghFS2HnQuFYBYe22ggCE1jPknHdVdg0Ny IoycZH5tf/B0/QpNLq/vg06R6qdRcMs1oZQ2EIcSMGEopGlsmqFNwr1K2irCje/8PoLU hjGu8pPvI7XPKuUPLfxrMwHVNQjym70LKFcyVvf0Kybyqj0JD1QqH66pFYt8dhP4spGH /xxz95X6dnn8c/kSd3YVTkTKjCG8jOO6MhuYUYY4lEGu9Dpk20h3lzWaNuu4Kg30gk62 UoBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VJC8IjaH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a65558d000000b005141972cc58si2114450pgs.280.2023.04.06.14.31.40; Thu, 06 Apr 2023 14:31:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VJC8IjaH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237172AbjDFVGT (ORCPT + 99 others); Thu, 6 Apr 2023 17:06:19 -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-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 X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762464067294121167?= X-GMAIL-MSGID: =?utf-8?q?1762464067294121167?= 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: 80537 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1311545vqo; Thu, 6 Apr 2023 14:29:12 -0700 (PDT) X-Google-Smtp-Source: AKy350YeJib8QNt+bwivLIJvynG4sYISnfulKBF7PxEJLQiGSbmVchmtaVaRFNuL0XRZzUmzVt2x X-Received: by 2002:a17:90b:3b82:b0:23a:87cf:de93 with SMTP id pc2-20020a17090b3b8200b0023a87cfde93mr30713pjb.15.1680816552077; Thu, 06 Apr 2023 14:29:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680816552; cv=none; d=google.com; s=arc-20160816; b=SLyal7792puYUOzud5DxJdHP7jhL1+6qFf3XBS+77bsyCD9s58V3vIuOyBKOYdcGEB YSrR+tGHJtWoStVgrHdbHnwwBgNCvRUD/4A2oM17gPm420SKkReUyIr6Sb3Shrpvu46O uMBc96RVDrCGP0QVFTSdULLCzXGwCOdv3tRE+Ygh70bFuhzkkjt+CCyBt3mtBQ95SyfO OeMpyRf+5KGh7QcbFZd6T7FqUFibLUbz8Ss8qQ4MOmNZqNOSfp43Yo38bPDhxGwbEeti lqull8whTF2fYrgqhZNYwfmJHznTQmQw6W4dl7jTgVs1CosvU2p6V7oTiWTirKZHm66u AHZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=dQ3pP06/vkhTaryl+NLjH5tImeyj0o8TuktuLvogXTQ=; b=cgRdJlvE6jj2VbhlYsyfBuj3XeFqtLjPzW439h4IRK2dE0TaBBGE05xsUGDSljhkPL rCZr7IobjZ8+iN3/wkIrhi9qOIBucfKlmh53GTH+U2RX3sUqxckOR+ZstvU22iQmJlYr zBYD4Tbs8kSOeVOkzpNK3wzEsQgZ3P02yzjxwM701MZScqnXRSE0sGO1RLcxpgSAXm+h HKIPTyrMH8fn7gsR9b9PhcoU/vb9W+4JydtdR1aaHrSfm0taF99unxTtMtItx6Tep3dC oOgnnJDFDmUrxse39Hyq3FOSKOEeeBWwWmot6EODNU/dgaHuA6IBRzn52xhAEvITp+pJ Z5tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=J0OSbxA4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h21-20020a17090aa89500b00236405d76basi1523148pjq.72.2023.04.06.14.28.59; Thu, 06 Apr 2023 14:29:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=J0OSbxA4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230006AbjDFVG0 (ORCPT + 99 others); Thu, 6 Apr 2023 17:06:26 -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-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 X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762463896767688342?= X-GMAIL-MSGID: =?utf-8?q?1762463896767688342?= 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: 80528 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1302916vqo; Thu, 6 Apr 2023 14:10:57 -0700 (PDT) X-Google-Smtp-Source: AKy350bENc7fDUTlvNinDn6Xbz1oT7wTN0/wFyjnByj3d1T8d9qBKdqVa6IA1VxdLR+ZXzxw570Y X-Received: by 2002:a62:3893:0:b0:594:26a7:cbd2 with SMTP id f141-20020a623893000000b0059426a7cbd2mr7467644pfa.8.1680815457676; Thu, 06 Apr 2023 14:10:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680815457; cv=none; d=google.com; s=arc-20160816; b=fwTThG+AiNbDPT+LVYD/Po0z3j7hNpMXLwUBFGbHZ+XJAQSSJ422Idmh9rm5CFLY95 RG64JVD7qTCAGR7to5WipVclrkK2svIsrecXQlEnAwdIFgGz/VRXfDgRAw20cqRT7vuq rk9bwmzpkLMgYKxh43gP80zFPz83YIYQ6K59TeXYZIkHLVOAOK+u51y/UnFFSmNZo0fY Vi5iVLAcg6XxSSTJtMri3XOxyH2xUGv/iNWFJT1WHA/SRWnqWXc9APpzly9I8Buj78NA aBf8QJaPW8vh94llm2uVb6BEwnbKqccC5iSl7cs2EvgDREcwTWU1nn0/6Wl6rb5srzeb A4LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=zxgVwiXvPJlNQaBMQo/Fw6ZQAn8/5u3aWEkaLTlJ8CU=; b=GRXAjx/iUEYQDTalyQpViY+gbH3t0oCRjpNXfPS88NKzv2mxhf9Fo+xKB3bij03LHT FsFOVxt0+OQA4wJYezVsjfNjUVc0mTBYDbibzeYX2kl2k5hS8VTuLrAjKk8KqFwBwAYW KpYjwJVrl4W9BeaRWWTqGphhSnlWcprNCAa6/C0iqcgDxdRBK5+pJSyXvT+0o87uTDYh iWF8n+MfsmmNFdw/2Wnhqsy9n7aqtK3IrjG+0Oo7PKpj8FQrZABMQA6SM0ODBGlsFBsQ MVN8k6b+fEWbv2iLJH45dc5uILDVWXNrPORIxdL+ooXd1g4gNVbQGUgfeMnte0Rjnyhq g1eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GPg6on8Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j62-20020a638041000000b00513234112b4si2105954pgd.896.2023.04.06.14.10.42; Thu, 06 Apr 2023 14:10:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GPg6on8Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238276AbjDFVGa (ORCPT + 99 others); Thu, 6 Apr 2023 17:06:30 -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-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 X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762462748977652381?= X-GMAIL-MSGID: =?utf-8?q?1762462748977652381?= 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: 80529 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1303071vqo; Thu, 6 Apr 2023 14:11:12 -0700 (PDT) X-Google-Smtp-Source: AKy350Y7DrdPbrxB3rYlxd6sF/SHWcq7i/rqW10fVi4zKyXTLA+AVc5g1Mdw020asTgDwCQbSRHf X-Received: by 2002:a05:6a20:4c9a:b0:de:5082:c9e9 with SMTP id fq26-20020a056a204c9a00b000de5082c9e9mr740138pzb.27.1680815472062; Thu, 06 Apr 2023 14:11:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680815472; cv=none; d=google.com; s=arc-20160816; b=TKREm0xx59OU97BjvHJBlBVPtfoagnbV9E68iTIfSfbHr78O0zGBUwN4xKPXsXwU15 VnBLlESad9ijNn+UxrS9brie+CHYcHe3I8ErM+KP9810vpjEGGltZ2pOEoZGCs2+Qpw+ C4i+9dYPIE1LkZwfQohoJz5uvi6UzO/uJDmQQxchLR8pZSlVk/NjgwVGNBzpZDlL6bIk Ugl08QNXO3RqObmXXOEoMluFJYpbApYpMIAMARUMWk+3otA8UvSELx6MWx2IzOcjgUNe QbsOO82Sn/6Ib2f66qzNodl5o8+eOMs6Z0tZ0MUcm08GzkOmappODl8wOuQThcpLT3KX 9NhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=EyYImB6w0gbLwOhqAGS6GeXGg4AcAsKtDrgZnurJMx8=; b=bXqpsNdUrXv1Z+F3AUHOItgcQkvpXJ+wNlzvleAN7aTuM3ULfObyVuqHQEe7kj4U0m U8byuVYQC5V8pufklwkWNHGbbV+gump+dGR9pQg7sefJ0UdXSXLYcPtPhOoschLR7q82 zOEnqip6NeqyhHhn6SO/gK/jgQxJ1m1zNZ8tud+yuHI/LFbVJgNbJJ9b25i+Tjhv+8g0 escYMuXXDOfpxIMhTTQgwkYWMUNXiaFaHGmffYTjK+CgKDGFFgCFJlWiSr8IlbkC3Ci0 tqv9m1a+ZVV1TZrbWmqiNLkQ5AE7R5eumgkNerSDBFGEfX9p9VCN4Q9CL72DC1ry/dwu FEaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=o6bX848a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e129-20020a636987000000b0050befeed875si2030117pgc.32.2023.04.06.14.11.00; Thu, 06 Apr 2023 14:11:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=o6bX848a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238598AbjDFVGi (ORCPT + 99 others); Thu, 6 Apr 2023 17:06:38 -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-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 X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762462764315082560?= X-GMAIL-MSGID: =?utf-8?q?1762462764315082560?= 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: 80530 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1303371vqo; Thu, 6 Apr 2023 14:11:45 -0700 (PDT) X-Google-Smtp-Source: AKy350aMNfXOYjaNUIYmkY74PtlMvv685pAjriOrHZ/iU5gIhtTB2og+rpKURjeNZJwylscYxSbl X-Received: by 2002:a17:906:7741:b0:931:624b:6804 with SMTP id o1-20020a170906774100b00931624b6804mr254971ejn.33.1680815504987; Thu, 06 Apr 2023 14:11:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680815504; cv=none; d=google.com; s=arc-20160816; b=mGcQqMscdNYdgAt5jxslvsQodN70t5B73FoKx90X0I6zhD1dCBlrF+wYHn2qb135DR KiGwHQhvhCDziKM/1wr8jQ80bvX6wrPI7NAHzeblq73kEGYUWZKL/Fh6xTn3C2eA5enm 7uzr3PfnwpHacxD3bL/eSdxWyB4esWrpl3hyCwhVzY7t3MqY3K+OetdhASU1ld1Eh8fU RFQO5l0u8yxnjNFse/mUuo27N0hx9mPtQ/9bK8iStO8T9pZxtZGu4JC90Di7fpK37TS9 bGxasLO2rm2KaqpKyvRbrHaIN+IeOZKOVnEdcwVPZ0cZj7FcknBuAjjvLIDD7Qd/jp8p /hkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=DBFoBGUsZtlCcm49brE9d8NiEeIvmudl2UdEa0t2qso=; b=QrFtedBYnP0IfBFXxYrhgZiFRXlP1PSki3vpffhnMKE+DZfDHbZ7HidJEhJRXnQP2D HQnEwyiUd9b7ifQFCHVavbccgcCYM7bTZmKUDkNQe9VPXbFTlKltavK0dTo1lW0VT6+C MXEfGDNFYlFqhii9wn/8mElgfXmktYLP0UBBMepoX/CWJ6EntxGMbtNs6BGv5aNtvT8O hRI9Et4/+y5iDGhUk3ygWPqVe9AlYMan8/bznT3n0RSJ4xZmQbZCTOPTUyU4QSIlEg1d OZPqE2+zvfVy0Z6MBNTOKQX7uI5dUDtsJqfYOZCT+7kbOsSNlhL1Yxm1SKciEx+D1kmA h6ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=agxBXqMP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id le12-20020a170907170c00b009232ea923a8si1811261ejc.917.2023.04.06.14.11.04; Thu, 06 Apr 2023 14:11:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=agxBXqMP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237874AbjDFVGe (ORCPT + 99 others); Thu, 6 Apr 2023 17:06:34 -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-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 X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762462799201354144?= X-GMAIL-MSGID: =?utf-8?q?1762462799201354144?= 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: 80532 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1304395vqo; Thu, 6 Apr 2023 14:13:50 -0700 (PDT) X-Google-Smtp-Source: AKy350ZgL+JKamwSa2Ch9cq45CmSthOP7GSQb2f/BMKN1uUWy5mp+0LeW+AtikMWxI83nOVddg7t X-Received: by 2002:a05:6a20:4f18:b0:ce:2fb4:5fc4 with SMTP id gi24-20020a056a204f1800b000ce2fb45fc4mr699925pzb.38.1680815630266; Thu, 06 Apr 2023 14:13:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680815630; cv=none; d=google.com; s=arc-20160816; b=buqk10jSf3DUBUkl8Ni1TOSYlf24QN0DoCq+BciyVjKopwTUayk+eN4hOVmwl+8GO1 NepGVYSXLJuBDJpOu8R7lntJ0N+gvH41mJIRjP6hMEeQh1qNW6xGG+n1b3Nm/focP5lU 7hDzmoNGuNt50QHoGO4PjWVkaJ1Acrj3rLMz3ShtdIzMY3DFzR7U++b35pghPVBVKdJk G337G2SNFb3m+qvbVU5w7+/RsiAzOFUZDD9mnZMbG+tKpRGV9vCeBPP5zAlaJQMm5rqE 6RxUJ49iZDCUinPpshEqpunrlPrEFePYtJJiMDCKZlOS7UtCvtVMuVDrp4wQ3vd+Gh1V Im4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=+oGWEwUsmNiSPPHrbfPC0Zq8RGaKBQeVwXfJ92f5QoA=; b=QJZmuHQogDEYObUgfhAXjH0/RqQZo0g9Jy3NjGemhbCpTPdHcthjjcY/iWw7Ic0K76 8C2jaC9I6cu03CNP9/h1sekmekumMjPVmGy/u/EMCzPN8BlQ1/dZOJjQMpgU7igPvqEv I6XQ7nJNWh+JkSRR24oGMsqYUNIo7Oa7S44fILmPF2HQmSPztDO+nFKPf4Ias7BBKaWH 9XWElEQhUgtlEvYR2qVnEwm77YKJJepeA3rdL+2zFhUswb0FcYvncJGS1jAmGAI807PJ Qjqzn+r/3AeFsy6LWE9z9DnUhjkYUKndHz+kdZ9U6GvQqnJWJL9CT3VkAsuyZH63hrgi O3yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Av3kyPRa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j3-20020a63e743000000b0050f79f0651fsi2086681pgk.95.2023.04.06.14.13.15; Thu, 06 Apr 2023 14:13:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Av3kyPRa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239702AbjDFVGp (ORCPT + 99 others); Thu, 6 Apr 2023 17:06:45 -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-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 X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762462929930662033?= X-GMAIL-MSGID: =?utf-8?q?1762462929930662033?= 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: 80534 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1309701vqo; Thu, 6 Apr 2023 14:24:48 -0700 (PDT) X-Google-Smtp-Source: AKy350YtpPxkgoyfp3MxUnM6sdIF/c0tZ7vLZI1953ejvNG+yHrwrsbKghhWflZbKt8SfN/l4vBC X-Received: by 2002:a17:90b:3882:b0:23b:4bf6:bbed with SMTP id mu2-20020a17090b388200b0023b4bf6bbedmr13384812pjb.24.1680816288493; Thu, 06 Apr 2023 14:24:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680816288; cv=none; d=google.com; s=arc-20160816; b=pyISCQyuAGB7Nq6RFJUV6nKYHg8Wtz4Qp66YaLzRCPzFMMoZGxfNjJJijksQG/eGOg ktROKIu1gB2bG8RPgb5l+AfAKVC4BT8f5O+rPxhWkGPC1ubVRwPDn4zB62A28bu8sale lMzG3dy8gWguxdM+qVm3sPIwq+TjwAOPJYQ5ybe3begamIEsdXvKME8PovNr9PrUJhpO qcl4qv2rF5lz82NSizRyMsDsI6kqXXqIwsyHkLtbC7iZc886Tc+JlxSCp2VbcsU5Wi4Z zPxKu2yirV6g9d3s9JrzKMFzTJnv9cou1azU6KvnhLvpnr3txk6khRJTqEYIycM8Ex2N ZK0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=7I+ZTLBAAWmNlN+JBk4TipMBC8vuk1wOji+jyAsKtTA=; b=NQdomfrVITUFSxgC34QwBqYCVxYC2ArHCGC+zF7zY0ZJ5kw4WFVmdKdbObwu7IUwoN 7PaEdBaE1FA1WGqflICyqEyx3cV4S6XkqD9vKfPZ71BDD5lV1Y8hmYOa/pCeuC8eogbL 5g/awF39HJyNr4iWiSMB92+Tu0wSZOYxv+S3xKGuJp9yvkX5EN0EDES/gbMHAJKf06Tg s6LoWOEvZt2cDFmQANadRP4p/1xQCyaLVGo4f6yUGHxKwVCsjeh0uEldUocI2OV/oD21 +Tb/p9z3D9MOyloxt4CgL/vWMk+rXt+m0PM59X5DpzOUCrjZ5joxdJiEv4w15NiOAMtu 6+Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=g4JIygxR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ml8-20020a17090b360800b0023d46505d83si4655283pjb.79.2023.04.06.14.24.25; Thu, 06 Apr 2023 14:24:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=g4JIygxR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238308AbjDFVGx (ORCPT + 99 others); Thu, 6 Apr 2023 17:06:53 -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-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 X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762463620520226530?= X-GMAIL-MSGID: =?utf-8?q?1762463620520226530?= 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; }