Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1267175rdb; Sat, 7 Oct 2023 22:50:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHltCb7/sk78y19JacMGvduZXBrMRc1gEbGRXvE9o7vmPSX/OapIn+i901/afPd6PVLJ88E X-Received: by 2002:a05:6808:2395:b0:3a7:2d4c:5d4e with SMTP id bp21-20020a056808239500b003a72d4c5d4emr15952329oib.7.1696744202343; Sat, 07 Oct 2023 22:50:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696744202; cv=none; d=google.com; s=arc-20160816; b=KgTH0Mq6XzN+bdp6zrdoWeQ8/TyZD37jQknpFjG3So5LI7ezcsFmx7tJ4VspC817Nw kZdEEV83qJ6D4Ntgyh0tAoOSO9UR55ZfAdzKHa6PJrzHNcLeccK7BvWwLr2ixFHX+iYY M93sSuuPwX9v5gf+28EeJ8hL0J58FlMm3Dyn5V52ks04FE6bC+OR+1DhQsZqRuNMzy5J e3po6pZiZV/P4HUllBaV5UIrD1uQY4yOmMoEMIOgqA0OBPhg+xSK4fIGBJypk6EqYi/j dQ0w1EM0H/bQ3Zex5/r5hrs4FFvaQVQ/Y372LSIKex8D/JL9NURWUKgWhFrpCTjZsjQw 06gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=qmckUo2kxmgR0QPkcDBpxhLAcGtDz//RWcNxyOELw/4=; fh=dhjwgYxwF7jbY2R8CJpNGSjGAAcV3P1rGHcNz0cZE0I=; b=pDD4Egkyz49ohjq69ZMgdMz86e99RrpgV4fPnYaXQOgu7l07rL0SpqrnLi9YhBVf1e hVjLwtO7RUsIH2PPKm6YaB4juHLkOj4mtuLHd0JId8+82vmot+T4+HeJxOEannN9WhXC k0P+Iea6fuVCZTGPKTXlb/0n0ws/9vMIS+iBqso2/x/1CrvHnYUny+WclPuNoRhNsrQb l6w4V3ehME7MJ91lplGfZNjZ01e5h58Rm0GZc6JqmP15Suqq7yHx4/XGIdddxGkbIix8 OcR2JKaOveG/8ug7T1rPduSk9xpyG7eOad8To1afWcR6TwZnBqhpfSf82d9j0BOGC6AO 793Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qBuEEuHd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id x69-20020a638648000000b005859cea158fsi6972115pgd.207.2023.10.07.22.50.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 22:50:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qBuEEuHd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 0E552803FC2B; Sat, 7 Oct 2023 22:50:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344392AbjJHFtl (ORCPT + 99 others); Sun, 8 Oct 2023 01:49:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344363AbjJHFtk (ORCPT ); Sun, 8 Oct 2023 01:49:40 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7DE792 for ; Sat, 7 Oct 2023 22:49:38 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-5068b69f4aeso3615e87.0 for ; Sat, 07 Oct 2023 22:49:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696744177; x=1697348977; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=qmckUo2kxmgR0QPkcDBpxhLAcGtDz//RWcNxyOELw/4=; b=qBuEEuHds1Ed7ADQIKclf8weFscpwvbZFDM9mpzXxeqOxZs790btWhn0dzCnE2OJdc t84wDNFMmFs7m8JnKO0kExkk+9+ciIFc8qlLnK2/ck5dEUgp8qGmS+RNER0eO0HUiDcQ Q8gkI7rdu/QXAPIB+zjaDv5U4Iz0NaUIQeNjmdueQIGNPae0TKFjN/5SkLCRpOY+ocFr hSJdEt1KlM6xj2fPJPeIsXw9HSLTSQnTjmXZs/RkMRVAUUwFVW3tmEIkRkYDeM2ckJTV 5guTs++qywO340yKAgMRJmvP6r2u+T24K3FpO4sbO12/9Fc8NPz1PZVXzzN+m1XUUCAy SR7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696744177; x=1697348977; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qmckUo2kxmgR0QPkcDBpxhLAcGtDz//RWcNxyOELw/4=; b=kvD68qsrN4ww5cAgbU5JrqwGcROBv3bVN6GpPuQ2LStX3qNkErHOu46KEvheH9jyWD pNo6s4Fap/87sxOCf6OBkTGP1mKg+OkrwkIpGersXVJ84KUvLqaWRa9BLwG8OGS658cK eRiGO7bom28xEZuqxfx1pOBIKJlxfLVuWaU2dcekFa+unaY9hSDeHc5PKi3HDU62EKO0 TVqzJevWAsawxeRRMELBOLR856Iewo2jLD8dWBd5fshk+onImEAkdZEwkDsfc1hCE//g kUCvKOLQUkme7a5No69w9892dtI8d5nIIbj/eWOCqtx3246T+Thc7IWJmmU8KvtRWjnh jOvw== X-Gm-Message-State: AOJu0YyuD0S0N5wo6EfZQqyOi04auCX0ufgzaS/fQYUCfDBz3Ufu+0aH uyB3h6lbn+KErKUNKV7h6opjoUq2T9gwFb7za07xjQ== X-Received: by 2002:a05:6512:484:b0:4fe:ffbc:ac98 with SMTP id v4-20020a056512048400b004feffbcac98mr191130lfq.4.1696744176773; Sat, 07 Oct 2023 22:49:36 -0700 (PDT) MIME-Version: 1.0 References: <20231007021326.4156714-1-irogers@google.com> <20231007021326.4156714-7-irogers@google.com> <39b28ad5-8086-76ed-a4c6-bfc8271d226b@huawei.com> In-Reply-To: <39b28ad5-8086-76ed-a4c6-bfc8271d226b@huawei.com> From: Ian Rogers Date: Sat, 7 Oct 2023 22:49:25 -0700 Message-ID: Subject: Re: [PATCH v1 6/7] perf pmu-events: Remember the events and metrics table To: Yang Jihong Cc: Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Thomas Richter , Ravi Bangoria , Kajol Jain , Jing Zhang , Kan Liang , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sat, 07 Oct 2023 22:50:00 -0700 (PDT) On Sat, Oct 7, 2023 at 8:39=E2=80=AFPM Yang Jihong = wrote: > > Hello, > > On 2023/10/7 10:13, Ian Rogers wrote: > > strcmp_cpuid_str performs regular expression comparisons. Avoid > > repeated computation of the table by remembering the table in a > > static. > > > > Signed-off-by: Ian Rogers > > --- > > tools/perf/pmu-events/jevents.py | 48 +++++++++++++++++++------------= - > > 1 file changed, 28 insertions(+), 20 deletions(-) > > > > diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/j= events.py > > index fd009752b427..8d8d5088c53c 100755 > > --- a/tools/perf/pmu-events/jevents.py > > +++ b/tools/perf/pmu-events/jevents.py > > @@ -978,28 +978,32 @@ int pmu_metrics_table__for_each_metric(const stru= ct pmu_metrics_table *table, > > > > const struct pmu_events_table *perf_pmu__find_events_table(struct per= f_pmu *pmu) > > { > > - const struct pmu_events_table *table =3D NULL; > > - char *cpuid =3D perf_pmu__getcpuid(pmu); > > + static const struct pmu_events_table *table; > > size_t i; > > > > - /* on some platforms which uses cpus map, cpuid can be NULL fo= r > > - * PMUs other than CORE PMUs. > > - */ > > - if (!cpuid) > > - return NULL; > > - > > - i =3D 0; > > - for (;;) { > > - const struct pmu_events_map *map =3D &pmu_events_map[i= ++]; > > - if (!map->arch) > > - break; > > - > > - if (!strcmp_cpuid_str(map->cpuid, cpuid)) { > > - table =3D &map->event_table; > > - break; > > + if (!table) { > If there is no matched table in pmu_events_map, > perf_pmu__find_events_table() will enter this branch for repeated search > each time. > Or do we need to use another variable to indicate whether the search has > been performed? Agreed, the behavior will match the existing behavior. Longer term I want to remove this code. Do you have a scenario we should optimize for here? Thanks, Ian > Thanks, > Yang