Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp27497rwl; Thu, 6 Apr 2023 14:10:07 -0700 (PDT) X-Google-Smtp-Source: AKy350bcIJ06H1HPQiAE78rpgQFwy9tbFXgoeZ6sEZj6uz/DJ130NvvxWTxCwqte16AMtwH+sDWe X-Received: by 2002:aa7:db4f:0:b0:4fa:e129:31cf with SMTP id n15-20020aa7db4f000000b004fae12931cfmr847463edt.23.1680815407205; Thu, 06 Apr 2023 14:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680815407; cv=none; d=google.com; s=arc-20160816; b=isveWP/nYGxc/ep1Q3l/NGvEK9er7BdSOLdUWWq0feZY/QMi4gvAKJ9PKdGfeFF515 ktCiFn9NX/lzMkHFaffZvAxcjyosV45pFql30SahftdjFnk1+5lAapyyU/3jKiicp3yH 2Gd4djSzya1k5hbFTIa/+sebmc80rLp2zlpWJ8u4MF/atMh/Ww93yO9GLRh38CeFkE2E /B0NsxQGwnl7XPPTePKvh5WFIkNcgJ6pd3/N8L1jDeh/Lcgih4PaNIk5Hx1ggurdG3lU /wkMbqsH4l3opnWNlmgNCCqETAVIIdH84koO8jDsQuY2pU3hTk2rVkSd62AllDM6saKu l5jg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u25-20020a05640207d900b004fcf925a8acsi1780577edy.251.2023.04.06.14.09.41; Thu, 06 Apr 2023 14:10:07 -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 S237111AbjDFVGT (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 Content-Transfer-Encoding: 8bit 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 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); -- 2.40.0.577.gac1e443424-goog