From nobody Sun Jun 14 21:38:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33118C433F5 for ; Wed, 11 May 2022 07:02:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242508AbiEKHCB (ORCPT ); Wed, 11 May 2022 03:02:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242439AbiEKHBl (ORCPT ); Wed, 11 May 2022 03:01:41 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A01735E157 for ; Wed, 11 May 2022 00:01:40 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2f8be9326fcso9704767b3.18 for ; Wed, 11 May 2022 00:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=GOl/dDyiic3CHN6RpwyPiPKb1wU0VPhBRck28P7ZCHk=; b=EnHwC10qwtnV6pxqRJcYnJ49YxvO7SNM936gaY/vUD9nwsdn7XuxHwNK64iZ+h+Fix h3I+btR3DZSQ8xyOxoxGB6qWSKczhaCoFnjdHBtUxuju4nkgOyLypfaTl6AzAjGypQMI CCIitXJUvLQc8FBX3I1njZS2zgHo0zG9ze2tgKP+0lHT2wTJJmaCX1IDzPyHTL5kSHyi 1Hmykb+40ppEPYOwmJwY6kJNOC0ibZZ+6b6gXfPAhMCyHJjsmpmMsKPBZkfj0y2wiFYJ ORhKqKt7xxIfuToMv4ERtBOfxqzWVg89x8ABummQWCwjzgxE1dYcPvbdyN4L+EcO/SPL kdUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=GOl/dDyiic3CHN6RpwyPiPKb1wU0VPhBRck28P7ZCHk=; b=scoXMcLM5HIVkBk7pyInZD5TZjdWhm/4wUmR3lKGXilatnqOJHTEG/psCOtYTyhfpL aSLEIw3iuVnFdHCdCRRxGzkPEPIgXxP5sVUEoF8RVPQSMZejPQ+8d3/d88Obu/DQBYW8 v7lfF1GRJteXhZP31/6iHCnwk78BegrpdqhUDih25MWvZGsGE5i40QmOS/In6SzATzkM XS++Tc+uDjMfcfKCEZXlmHqE/g9ZXwamVaaNGqXHi6TKTw0A8jWSAqqEXLLoxNqlnEJc nc4lBsSU5WK6SlpQe81E1Ddk/93gqtxTttrvws9ZogrqR6LlgijFleRUb+DLk/NlgFQe CKPQ== X-Gm-Message-State: AOAM533nGx30/aMrkluCr6U4ZR8SCXxbMWR7GV88Hm/kzqM2fucSIGv+ fe5ls0JiONBCPX/Sv8DVghXYjMJu0tGX X-Google-Smtp-Source: ABdhPJz6DgNH2KUDVEqruh6QTuP3eHV+0C65QhAonB7KFFGCDZ9k68xvIzb57Q2CYcotHaOjeHpkPVu6UIAq X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:b6c9:16a6:f912:39d5]) (user=irogers job=sendgmr) by 2002:a25:acd2:0:b0:645:d5c8:b837 with SMTP id x18-20020a25acd2000000b00645d5c8b837mr21754737ybd.481.1652252499791; Wed, 11 May 2022 00:01:39 -0700 (PDT) Date: Wed, 11 May 2022 00:01:27 -0700 In-Reply-To: <20220511070133.710721-1-irogers@google.com> Message-Id: <20220511070133.710721-2-irogers@google.com> Mime-Version: 1.0 References: <20220511070133.710721-1-irogers@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH 1/7] perf jevents: Append PMU description later From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Kan Liang , Andi Kleen , Zhengjun Xing , Felix Fietkau , Qi Liu , Like Xu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Nick Forrington , Kajol Jain , James Clark , Andrew Kilroy , "Paul A . Clarke" , Will Deacon , Mathieu Poirier , ananth.narayan@amd.com, ravi.bangoria@amd.com, santosh.shukla@amd.com, sandipan.das@amd.com, Caleb Biggers , Perry Taylor , Kshipra Bopardikar Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Append the PMU information from "Unit" to the description later. This avoids a problem when "Unit" appears early in a json event and the information prepends the description rather than being the expected suffix. Update the pmu-events test so that expectations now match the improved output. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.c | 8 +++++--- tools/perf/tests/pmu-events.c | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevent= s.c index 159d9eab6e79..e1f7c7afd435 100644 --- a/tools/perf/pmu-events/jevents.c +++ b/tools/perf/pmu-events/jevents.c @@ -652,9 +652,6 @@ static int json_events(const char *fn, for (s =3D je.pmu; *s; s++) *s =3D tolower(*s); } - addfield(map, &je.desc, ". ", "Unit: ", NULL); - addfield(map, &je.desc, "", je.pmu, NULL); - addfield(map, &je.desc, "", " ", NULL); } else if (json_streq(map, field, "Filter")) { addfield(map, &filter, "", "", val); } else if (json_streq(map, field, "ScaleUnit")) { @@ -697,6 +694,11 @@ static int json_events(const char *fn, addfield(map, &je.desc, " ", extra_desc, NULL); if (je.long_desc && extra_desc) addfield(map, &je.long_desc, " ", extra_desc, NULL); + if (je.pmu) { + addfield(map, &je.desc, ". ", "Unit: ", NULL); + addfield(map, &je.desc, "", je.pmu, NULL); + addfield(map, &je.desc, "", " ", NULL); + } if (filter) addfield(map, &event, ",", filter, NULL); if (msr !=3D NULL) diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 299a215eb54c..b74c6ef59e51 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -133,7 +133,7 @@ static const struct perf_pmu_test_event unc_cbo_xsnp_re= sponse_miss_eviction =3D { .event =3D { .name =3D "unc_cbo_xsnp_response.miss_eviction", .event =3D "umask=3D0x81,event=3D0x22", - .desc =3D "Unit: uncore_cbox A cross-core snoop resulted from L3 Evictio= n which misses in some processor core", + .desc =3D "A cross-core snoop resulted from L3 Eviction which misses in = some processor core. Unit: uncore_cbox ", .topic =3D "uncore", .long_desc =3D "A cross-core snoop resulted from L3 Eviction which misse= s in some processor core", .pmu =3D "uncore_cbox", @@ -147,7 +147,7 @@ static const struct perf_pmu_test_event uncore_hyphen = =3D { .event =3D { .name =3D "event-hyphen", .event =3D "umask=3D0x00,event=3D0xe0", - .desc =3D "Unit: uncore_cbox UNC_CBO_HYPHEN", + .desc =3D "UNC_CBO_HYPHEN. Unit: uncore_cbox ", .topic =3D "uncore", .long_desc =3D "UNC_CBO_HYPHEN", .pmu =3D "uncore_cbox", @@ -161,7 +161,7 @@ static const struct perf_pmu_test_event uncore_two_hyph= =3D { .event =3D { .name =3D "event-two-hyph", .event =3D "umask=3D0x00,event=3D0xc0", - .desc =3D "Unit: uncore_cbox UNC_CBO_TWO_HYPH", + .desc =3D "UNC_CBO_TWO_HYPH. Unit: uncore_cbox ", .topic =3D "uncore", .long_desc =3D "UNC_CBO_TWO_HYPH", .pmu =3D "uncore_cbox", --=20 2.36.0.512.ge40c2bad7a-goog From nobody Sun Jun 14 21:38:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7206C433FE for ; Wed, 11 May 2022 07:01:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242468AbiEKHBt (ORCPT ); Wed, 11 May 2022 03:01:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242455AbiEKHBp (ORCPT ); Wed, 11 May 2022 03:01:45 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 122545E74C for ; Wed, 11 May 2022 00:01:42 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id d188-20020a25cdc5000000b00648429e5ab9so1093719ybf.13 for ; Wed, 11 May 2022 00:01:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=p1OX+w7IK0mnK9F3eqD3DEeM7lTBarWyy9w79QDENKE=; b=FIO2yZvt1EnPVeydYIqjeebHVBci+Re90bjDH3fQ09Xb/6mSaO0ILtM7ELgkMB+eGK djqQCD/4SHfkPvwCvyouKotO5ghRj3BBtt2IeRIVETFqgQjmfZ5wTUl/WmCgOn96jm4C BSHeD7pY2bL8an1cH3ZzX7fuvlSL81HruwA9MhYXIWwkUv8lxrfiib5xyEKak+kNridm M0ytdE7SWmqVd4ukmqOONHSqrEp9uVryzpGzasL8oT8GpxDQfACNIF3ZWAHeWM810Dyf yso2qirh1NT8M7MYIfWg5AqcJpfvxlMMPc0x0cXd+9eIf0etskK/7l2WfMUKSBPDZqdN Gprg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=p1OX+w7IK0mnK9F3eqD3DEeM7lTBarWyy9w79QDENKE=; b=sWq2nuwf1qqPDcHcpn6bogr2M/Nm3uTVnPhTsgtZOLT12TeTtzYv0k/RPzmKHt42C8 4BdaxnOOhUhJ+x9ZF9zn4HYSU6O+DxRQZ8++dSpvfhFYbHWxfXFR72CCGW06PVCEHDZQ T+fzl81W0EUp2zHMVRHN4apFz/a5aJ2umsXwVvss3AJ72ufhiH/Vfe5nvfdoN1F31iM3 lZ/2WQu5/Tivr+U/lrYmiCrBal6coPIlQoh/vnQ6jHwFsFAlI1i2II1mx194t4r9LkeR qF9vuTiawU+8mlbKFIF68AyCu8niFAax3T2hjygrgOxMaMVRR6I2X0LjcPO6CQNkRCpo wCQw== X-Gm-Message-State: AOAM531eKRq2dBiAdIkANF6LWDung5Swczh0vKxrU8ZSydF9BrQClMdB UNkQJGk7EY//3Hvp/phHedOAFKf5tgUp X-Google-Smtp-Source: ABdhPJxpapPDx4GvGXc5S+8qppcE3wrnnn+RrBiK6n6ApsanFrFANYx/sXkYOA9dYCH65NvEOFC5nVmuJ5Tw X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:b6c9:16a6:f912:39d5]) (user=irogers job=sendgmr) by 2002:a25:47c1:0:b0:64a:9f13:61c7 with SMTP id u184-20020a2547c1000000b0064a9f1361c7mr18383514yba.464.1652252501992; Wed, 11 May 2022 00:01:41 -0700 (PDT) Date: Wed, 11 May 2022 00:01:28 -0700 In-Reply-To: <20220511070133.710721-1-irogers@google.com> Message-Id: <20220511070133.710721-3-irogers@google.com> Mime-Version: 1.0 References: <20220511070133.710721-1-irogers@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH 2/7] perf vendor events: Fix Alderlake metric groups From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Kan Liang , Andi Kleen , Zhengjun Xing , Felix Fietkau , Qi Liu , Like Xu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Nick Forrington , Kajol Jain , James Clark , Andrew Kilroy , "Paul A . Clarke" , Will Deacon , Mathieu Poirier , ananth.narayan@amd.com, ravi.bangoria@amd.com, santosh.shukla@amd.com, sandipan.das@amd.com, Caleb Biggers , Perry Taylor , Kshipra Bopardikar Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove unnecessary empty groups. Signed-off-by: Ian Rogers --- .../arch/x86/alderlake/adl-metrics.json | 32 ------------------- 1 file changed, 32 deletions(-) diff --git a/tools/perf/pmu-events/arch/x86/alderlake/adl-metrics.json b/to= ols/perf/pmu-events/arch/x86/alderlake/adl-metrics.json index 4d172687f936..6b24958737b5 100644 --- a/tools/perf/pmu-events/arch/x86/alderlake/adl-metrics.json +++ b/tools/perf/pmu-events/arch/x86/alderlake/adl-metrics.json @@ -477,224 +477,192 @@ { "BriefDescription": "", "MetricExpr": "CPU_CLK_UNHALTED.CORE", - "MetricGroup": " ", "MetricName": "CLKS", "Unit": "cpu_atom" }, { "BriefDescription": "", "MetricExpr": "CPU_CLK_UNHALTED.CORE_P", - "MetricGroup": " ", "MetricName": "CLKS_P", "Unit": "cpu_atom" }, { "BriefDescription": "", "MetricExpr": "5 * CPU_CLK_UNHALTED.CORE", - "MetricGroup": " ", "MetricName": "SLOTS", "Unit": "cpu_atom" }, { "BriefDescription": "Instructions Per Cycle", "MetricExpr": "INST_RETIRED.ANY / CPU_CLK_UNHALTED.CORE", - "MetricGroup": " ", "MetricName": "IPC", "Unit": "cpu_atom" }, { "BriefDescription": "Cycles Per Instruction", "MetricExpr": "CPU_CLK_UNHALTED.CORE / INST_RETIRED.ANY", - "MetricGroup": " ", "MetricName": "CPI", "Unit": "cpu_atom" }, { "BriefDescription": "Uops Per Instruction", "MetricExpr": "UOPS_RETIRED.ALL / INST_RETIRED.ANY", - "MetricGroup": " ", "MetricName": "UPI", "Unit": "cpu_atom" }, { "BriefDescription": "Percentage of total non-speculative loads wit= h a store forward or unknown store address block", "MetricExpr": "100 * LD_BLOCKS.DATA_UNKNOWN / MEM_UOPS_RETIRED.ALL= _LOADS", - "MetricGroup": "", "MetricName": "Store_Fwd_Blocks", "Unit": "cpu_atom" }, { "BriefDescription": "Percentage of total non-speculative loads wit= h a address aliasing block", "MetricExpr": "100 * LD_BLOCKS.4K_ALIAS / MEM_UOPS_RETIRED.ALL_LOA= DS", - "MetricGroup": "", "MetricName": "Address_Alias_Blocks", "Unit": "cpu_atom" }, { "BriefDescription": "Percentage of total non-speculative loads tha= t are splits", "MetricExpr": "100 * MEM_UOPS_RETIRED.SPLIT_LOADS / MEM_UOPS_RETIR= ED.ALL_LOADS", - "MetricGroup": "", "MetricName": "Load_Splits", "Unit": "cpu_atom" }, { "BriefDescription": "Instructions per Branch (lower number means h= igher occurrence rate)", "MetricExpr": "INST_RETIRED.ANY / BR_INST_RETIRED.ALL_BRANCHES", - "MetricGroup": " ", "MetricName": "IpBranch", "Unit": "cpu_atom" }, { "BriefDescription": "Instruction per (near) call (lower number mea= ns higher occurrence rate)", "MetricExpr": "INST_RETIRED.ANY / BR_INST_RETIRED.CALL", - "MetricGroup": " ", "MetricName": "IpCall", "Unit": "cpu_atom" }, { "BriefDescription": "Instructions per Load", "MetricExpr": "INST_RETIRED.ANY / MEM_UOPS_RETIRED.ALL_LOADS", - "MetricGroup": " ", "MetricName": "IpLoad", "Unit": "cpu_atom" }, { "BriefDescription": "Instructions per Store", "MetricExpr": "INST_RETIRED.ANY / MEM_UOPS_RETIRED.ALL_STORES", - "MetricGroup": " ", "MetricName": "IpStore", "Unit": "cpu_atom" }, { "BriefDescription": "Number of Instructions per non-speculative Br= anch Misprediction", "MetricExpr": "INST_RETIRED.ANY / BR_MISP_RETIRED.ALL_BRANCHES", - "MetricGroup": " ", "MetricName": "IpMispredict", "Unit": "cpu_atom" }, { "BriefDescription": "Instructions per Far Branch", "MetricExpr": "INST_RETIRED.ANY / ( BR_INST_RETIRED.FAR_BRANCH / 2= )", - "MetricGroup": " ", "MetricName": "IpFarBranch", "Unit": "cpu_atom" }, { "BriefDescription": "Ratio of all branches which mispredict", "MetricExpr": "BR_MISP_RETIRED.ALL_BRANCHES / BR_INST_RETIRED.ALL_= BRANCHES", - "MetricGroup": " ", "MetricName": "Branch_Mispredict_Ratio", "Unit": "cpu_atom" }, { "BriefDescription": "Ratio between Mispredicted branches and unkno= wn branches", "MetricExpr": "BR_MISP_RETIRED.ALL_BRANCHES / BACLEARS.ANY", - "MetricGroup": " ", "MetricName": "Branch_Mispredict_to_Unknown_Branch_Ratio", "Unit": "cpu_atom" }, { "BriefDescription": "Percentage of all uops which are ucode ops", "MetricExpr": "100 * UOPS_RETIRED.MS / UOPS_RETIRED.ALL", - "MetricGroup": " ", "MetricName": "Microcode_Uop_Ratio", "Unit": "cpu_atom" }, { "BriefDescription": "Percentage of all uops which are FPDiv uops", "MetricExpr": "100 * UOPS_RETIRED.FPDIV / UOPS_RETIRED.ALL", - "MetricGroup": " ", "MetricName": "FPDiv_Uop_Ratio", "Unit": "cpu_atom" }, { "BriefDescription": "Percentage of all uops which are IDiv uops", "MetricExpr": "100 * UOPS_RETIRED.IDIV / UOPS_RETIRED.ALL", - "MetricGroup": " ", "MetricName": "IDiv_Uop_Ratio", "Unit": "cpu_atom" }, { "BriefDescription": "Percentage of all uops which are x87 uops", "MetricExpr": "100 * UOPS_RETIRED.X87 / UOPS_RETIRED.ALL", - "MetricGroup": " ", "MetricName": "X87_Uop_Ratio", "Unit": "cpu_atom" }, { "BriefDescription": "Average Frequency Utilization relative nomina= l frequency", "MetricExpr": "CPU_CLK_UNHALTED.CORE / CPU_CLK_UNHALTED.REF_TSC", - "MetricGroup": " ", "MetricName": "Turbo_Utilization", "Unit": "cpu_atom" }, { "BriefDescription": "Fraction of cycles spent in Kernel mode", "MetricExpr": "CPU_CLK_UNHALTED.CORE:k / CPU_CLK_UNHALTED.CORE", - "MetricGroup": " ", "MetricName": "Kernel_Utilization", "Unit": "cpu_atom" }, { "BriefDescription": "Average CPU Utilization", "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC / msr@tsc@", - "MetricGroup": " ", "MetricName": "CPU_Utilization", "Unit": "cpu_atom" }, { "BriefDescription": "Estimated Pause cost. In percent", "MetricExpr": "100 * SERIALIZATION.NON_C01_MS_SCB / ( 5 * CPU_CLK_= UNHALTED.CORE )", - "MetricGroup": " ", "MetricName": "Estimated_Pause_Cost", "Unit": "cpu_atom" }, { "BriefDescription": "Cycle cost per L2 hit", "MetricExpr": "MEM_BOUND_STALLS.LOAD_L2_HIT / MEM_LOAD_UOPS_RETIRE= D.L2_HIT", - "MetricGroup": " ", "MetricName": "Cycles_per_Demand_Load_L2_Hit", "Unit": "cpu_atom" }, { "BriefDescription": "Cycle cost per LLC hit", "MetricExpr": "MEM_BOUND_STALLS.LOAD_LLC_HIT / MEM_LOAD_UOPS_RETIR= ED.L3_HIT", - "MetricGroup": " ", "MetricName": "Cycles_per_Demand_Load_L3_Hit", "Unit": "cpu_atom" }, { "BriefDescription": "Cycle cost per DRAM hit", "MetricExpr": "MEM_BOUND_STALLS.LOAD_DRAM_HIT / MEM_LOAD_UOPS_RETI= RED.DRAM_HIT", - "MetricGroup": " ", "MetricName": "Cycles_per_Demand_Load_DRAM_Hit", "Unit": "cpu_atom" }, { "BriefDescription": "Percent of instruction miss cost that hit in = the L2", "MetricExpr": "100 * MEM_BOUND_STALLS.IFETCH_L2_HIT / ( MEM_BOUND_= STALLS.IFETCH )", - "MetricGroup": " ", "MetricName": "Inst_Miss_Cost_L2Hit_Percent", "Unit": "cpu_atom" }, { "BriefDescription": "Percent of instruction miss cost that hit in = the L3", "MetricExpr": "100 * MEM_BOUND_STALLS.IFETCH_LLC_HIT / ( MEM_BOUND= _STALLS.IFETCH )", - "MetricGroup": " ", "MetricName": "Inst_Miss_Cost_L3Hit_Percent", "Unit": "cpu_atom" }, { "BriefDescription": "Percent of instruction miss cost that hit in = DRAM", "MetricExpr": "100 * MEM_BOUND_STALLS.IFETCH_DRAM_HIT / ( MEM_BOUN= D_STALLS.IFETCH )", - "MetricGroup": " ", "MetricName": "Inst_Miss_Cost_DRAMHit_Percent", "Unit": "cpu_atom" }, { "BriefDescription": "load ops retired per 1000 instruction", "MetricExpr": "1000 * MEM_UOPS_RETIRED.ALL_LOADS / INST_RETIRED.AN= Y", - "MetricGroup": " ", "MetricName": "MemLoadPKI", "Unit": "cpu_atom" }, --=20 2.36.0.512.ge40c2bad7a-goog From nobody Sun Jun 14 21:38:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DE38C433EF for ; Wed, 11 May 2022 07:02:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242504AbiEKHCO (ORCPT ); Wed, 11 May 2022 03:02:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242447AbiEKHBq (ORCPT ); Wed, 11 May 2022 03:01:46 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A0B65BE44 for ; Wed, 11 May 2022 00:01:45 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2f7c322f770so9622197b3.20 for ; Wed, 11 May 2022 00:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=3xLzWp+VN8d56IUKCn+oZgvctc6ILOg/P6G2GbPqdKc=; b=N8/Nldd50lgxa4UFpEziOLqimjwZJwjurqH31n9cYdBOi0RBAipty9Ako1bpqKqpEX 3nmNb18S9Yvbq34OwG5EVj4isGDRt9nu75YwPVXb6E93b2xCV2jcGXqvojKpN/yDfW4l pyhnuj95b3Uy9b1rmrLuzFSNGLjx2PXdQGAY+YQCZ4pAVLCCAFaOns1U4IQ+lnfALzoy zltNPdjfV05fmlZV2Tv8Q8V4A5xGNr8tNXDi1NoMTLYG2sbBXe3nyRgTxdI9FOz4Mzup yq6Mq2rzn+6NrVKeJ/hJ8wRD9FFimIeUb39l3UgOke6JB8FMseM1/8VdxYv0gf2HIjvD ZuVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=3xLzWp+VN8d56IUKCn+oZgvctc6ILOg/P6G2GbPqdKc=; b=GW+X/B6UxZU5n4Lw1UWKrIN7OXxiChAlUvm3AK0ut0KApyeQ39QdktmKyJocyKYfYb f7OlSo/rU3VYuu9lm1tRNyOva9rtY+f8XDW2GgJLeKEWU4xNIA1UiMqOF9lfTFk7FMOA nQIvWHnck+OtRGN2mN/8Ez152nn2+TQ6VBhzQt+OIajyFvLBf9RUlgTcxRWeu68bNsbX GEmH28/LDSw7HNyowcm9URBLYwa05qiORLbUYif0FmzLrQ3knCtr7lLa9xrC1qhSriIX p+AvktkFs3u6xd3X3m/c4GEe8++BfUdH3TXNVE5WsCC8AsrjBz7BKpdzMF8/T8yIKA8N u1XQ== X-Gm-Message-State: AOAM533hVmTkO+DlUbWwPboGNDzOYBBCjmUev/Cdw3bREMawVg6b4P8o yk48apsdfDvdVq0z6+VM8H8PVv7SqDg3 X-Google-Smtp-Source: ABdhPJyU0JGtkMiuWLcINboT3dByokO5rmHxkLIAGVtLVFu/F1k0AkML7xNFVmashRWlC6SkWWWwsV2ym4Mf X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:b6c9:16a6:f912:39d5]) (user=irogers job=sendgmr) by 2002:a0d:df48:0:b0:2fb:3658:38b0 with SMTP id i69-20020a0ddf48000000b002fb365838b0mr22872026ywe.508.1652252504258; Wed, 11 May 2022 00:01:44 -0700 (PDT) Date: Wed, 11 May 2022 00:01:29 -0700 In-Reply-To: <20220511070133.710721-1-irogers@google.com> Message-Id: <20220511070133.710721-4-irogers@google.com> Mime-Version: 1.0 References: <20220511070133.710721-1-irogers@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH 3/7] perf vendor events: Fix Ivytown UNC_M_ACT_COUNT.RD umask From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Kan Liang , Andi Kleen , Zhengjun Xing , Felix Fietkau , Qi Liu , Like Xu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Nick Forrington , Kajol Jain , James Clark , Andrew Kilroy , "Paul A . Clarke" , Will Deacon , Mathieu Poirier , ananth.narayan@amd.com, ravi.bangoria@amd.com, santosh.shukla@amd.com, sandipan.das@amd.com, Caleb Biggers , Perry Taylor , Kshipra Bopardikar Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The event had two umasks with the umask of 3 being correct. Note: this change wasn't automatically generated as there is no CSV for Ivytown uncore events at: https://github.com/intel/event-converter-for-linux-perf Signed-off-by: Ian Rogers --- tools/perf/pmu-events/arch/x86/ivytown/uncore-memory.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/perf/pmu-events/arch/x86/ivytown/uncore-memory.json b/to= ols/perf/pmu-events/arch/x86/ivytown/uncore-memory.json index df4b43294fa0..e8917cb59566 100644 --- a/tools/perf/pmu-events/arch/x86/ivytown/uncore-memory.json +++ b/tools/perf/pmu-events/arch/x86/ivytown/uncore-memory.json @@ -5,8 +5,7 @@ "EventCode": "0x1", "EventName": "UNC_M_ACT_COUNT.RD", "PerPkg": "1", - "UMask": "0x1", - "Umask": "0x3", + "UMask": "0x3", "Unit": "iMC" }, { --=20 2.36.0.512.ge40c2bad7a-goog From nobody Sun Jun 14 21:38:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0C31C433EF for ; Wed, 11 May 2022 07:02:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242416AbiEKHCS (ORCPT ); Wed, 11 May 2022 03:02:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242469AbiEKHBt (ORCPT ); Wed, 11 May 2022 03:01:49 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 468C17305B for ; Wed, 11 May 2022 00:01:47 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2eb7d137101so9948227b3.12 for ; Wed, 11 May 2022 00:01:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=rLCQIdDIo0hjvRjcVna27zMmwetjRkxV8oX5TRyw2qw=; b=MmpIllCb4cEgsGmk9jFaxVuPfuNP7dVZUMN6AowLxFrfOAUOuTpxMRaAM4dIiqfQJ+ hF7Mg2kFS2aDrHuSKCxlqJd9SgU68/PDP3ps6Q24winnQoTP8AMQiFXB8uPEaCh3bdNu dgD8uo7/C1WU7d3oB82rakji2NeHpoDZLmxAAkrV9H7y/AaZORTo9LbOS8H7Ck+CtIxc BcMttJ/iVmDuowEqjcs464xcnZW9n0DVUxMnFcHcNZ940TICRy1VZhEGwet4jU+3YlgH NAh9HBQsN1aEFrsrAJZjDQaIrsBp5BESIEDP0mZWWgyfq62vC8H2OGs+FG1e4R/EjG/T 70VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=rLCQIdDIo0hjvRjcVna27zMmwetjRkxV8oX5TRyw2qw=; b=vHfPzde/1IcTTL7nsx/aYcjvK6qie3yHhHYleibLW07Aqr8gU3IHkHQ9/9Z3hpsp71 EuahpKqrvFLsypt9LItcalO4+8kuydB8UdBUyUtwgs2g9Qw0fuEAGPtDHjQ0Tf/7YPO8 qw/ZRYXkFE8RzvTYPHe2pT4p4/B32OVZvldDGH+yQsZSF0bJfRSxDrR9DwyOXbig1k0d j4Mrfa6jr9JUeIMf4Epw4umTyElwB0NG1ibEIkVdRlzaxBv/YjZdXh4pTVVFO00Aw4x6 ODpLJVGAWHr7OobeATgkZ5hNEvL9EjOhimok/FZGpxKEqeHHs/eE2/GhcoQLu66n5x9Y x4Pg== X-Gm-Message-State: AOAM531rHbcRqB4NGe1JGkatElm/6ZZGFIoE++QLBEXukNbwrez/gmAT a2mZgLYJEG2i3GFlOiCvML0fRW0u/tcf X-Google-Smtp-Source: ABdhPJxdAUdl2TKac8QUPTEi0Tv90G7I07/SQAAXXHb0eqJQy5FdMT1rljNRxuHX+q7nsSy3s1YvPw4wYN4I X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:b6c9:16a6:f912:39d5]) (user=irogers job=sendgmr) by 2002:a81:1606:0:b0:2f7:d623:703 with SMTP id 6-20020a811606000000b002f7d6230703mr22911108yww.501.1652252506406; Wed, 11 May 2022 00:01:46 -0700 (PDT) Date: Wed, 11 May 2022 00:01:30 -0700 In-Reply-To: <20220511070133.710721-1-irogers@google.com> Message-Id: <20220511070133.710721-5-irogers@google.com> Mime-Version: 1.0 References: <20220511070133.710721-1-irogers@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH 4/7] perf jevents: Modify match field From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Kan Liang , Andi Kleen , Zhengjun Xing , Felix Fietkau , Qi Liu , Like Xu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Nick Forrington , Kajol Jain , James Clark , Andrew Kilroy , "Paul A . Clarke" , Will Deacon , Mathieu Poirier , ananth.narayan@amd.com, ravi.bangoria@amd.com, santosh.shukla@amd.com, sandipan.das@amd.com, Caleb Biggers , Perry Taylor , Kshipra Bopardikar Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The match_field function looks for json values to append to the event string. As the C code processes these in order the output order matches that in the json dictionary. Python json readers read the entire dictionary and lose the ordering. To make the python and C output comparable makee the C code first read the extra fields then append them to the event in an order not determined by their order in the file. Modify the pmu-events test so that test expectations match the new order. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.c | 82 ++++++++++++++++++++------------- tools/perf/tests/pmu-events.c | 24 +++++----- 2 files changed, 62 insertions(+), 44 deletions(-) diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevent= s.c index e1f7c7afd435..cee61c4ed59e 100644 --- a/tools/perf/pmu-events/jevents.c +++ b/tools/perf/pmu-events/jevents.c @@ -207,21 +207,6 @@ static struct msrmap { { NULL, NULL } }; =20 -static struct field { - const char *field; - const char *kernel; -} fields[] =3D { - { "UMask", "umask=3D" }, - { "CounterMask", "cmask=3D" }, - { "Invert", "inv=3D" }, - { "AnyThread", "any=3D" }, - { "EdgeDetect", "edge=3D" }, - { "SampleAfterValue", "period=3D" }, - { "FCMask", "fc_mask=3D" }, - { "PortMask", "ch_mask=3D" }, - { NULL, NULL } -}; - static void cut_comma(char *map, jsmntok_t *newval) { int i; @@ -233,21 +218,6 @@ static void cut_comma(char *map, jsmntok_t *newval) } } =20 -static int match_field(char *map, jsmntok_t *field, int nz, - char **event, jsmntok_t *val) -{ - struct field *f; - jsmntok_t newval =3D *val; - - for (f =3D fields; f->field; f++) - if (json_streq(map, field, f->field) && nz) { - cut_comma(map, &newval); - addfield(map, event, ",", f->kernel, &newval); - return 1; - } - return 0; -} - static struct msrmap *lookup_msr(char *map, jsmntok_t *val) { jsmntok_t newval =3D *val; @@ -581,6 +551,14 @@ static int json_events(const char *fn, jsmntok_t *precise =3D NULL; jsmntok_t *obj =3D tok++; bool configcode_present =3D false; + char *umask =3D NULL; + char *cmask =3D NULL; + char *inv =3D NULL; + char *any =3D NULL; + char *edge =3D NULL; + char *period =3D NULL; + char *fc_mask =3D NULL; + char *ch_mask =3D NULL; =20 EXPECT(obj->type =3D=3D JSMN_OBJECT, obj, "expected object"); for (j =3D 0; j < obj->size; j +=3D 2) { @@ -596,8 +574,23 @@ static int json_events(const char *fn, "Expected string value"); =20 nz =3D !json_streq(map, val, "0"); - if (match_field(map, field, nz, &event, val)) { - /* ok */ + /* match_field */ + if (json_streq(map, field, "UMask") && nz) { + addfield(map, &umask, "", "umask=3D", val); + } else if (json_streq(map, field, "CounterMask") && nz) { + addfield(map, &cmask, "", "cmask=3D", val); + } else if (json_streq(map, field, "Invert") && nz) { + addfield(map, &inv, "", "inv=3D", val); + } else if (json_streq(map, field, "AnyThread") && nz) { + addfield(map, &any, "", "any=3D", val); + } else if (json_streq(map, field, "EdgeDetect") && nz) { + addfield(map, &edge, "", "edge=3D", val); + } else if (json_streq(map, field, "SampleAfterValue") && nz) { + addfield(map, &period, "", "period=3D", val); + } else if (json_streq(map, field, "FCMask") && nz) { + addfield(map, &fc_mask, "", "fc_mask=3D", val); + } else if (json_streq(map, field, "PortMask") && nz) { + addfield(map, &ch_mask, "", "ch_mask=3D", val); } else if (json_streq(map, field, "EventCode")) { char *code =3D NULL; addfield(map, &code, "", "", val); @@ -690,6 +683,23 @@ static int json_events(const char *fn, else snprintf(buf, sizeof buf, "event=3D%#llx", eventcode); addfield(map, &event, ",", buf, NULL); + if (any) + addfield(map, &event, ",", any, NULL); + if (ch_mask) + addfield(map, &event, ",", ch_mask, NULL); + if (cmask) + addfield(map, &event, ",", cmask, NULL); + if (edge) + addfield(map, &event, ",", edge, NULL); + if (fc_mask) + addfield(map, &event, ",", fc_mask, NULL); + if (inv) + addfield(map, &event, ",", inv, NULL); + if (period) + addfield(map, &event, ",", period, NULL); + if (umask) + addfield(map, &event, ",", umask, NULL); + if (je.desc && extra_desc) addfield(map, &je.desc, " ", extra_desc, NULL); if (je.long_desc && extra_desc) @@ -718,6 +728,14 @@ static int json_events(const char *fn, je.event =3D real_event(je.name, event); err =3D func(data, &je); free_strings: + free(umask); + free(cmask); + free(inv); + free(any); + free(edge); + free(period); + free(fc_mask); + free(ch_mask); free(event); free(je.desc); free(je.name); diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index b74c6ef59e51..f13368569d8b 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -63,33 +63,33 @@ static const struct perf_pmu_test_event bp_l2_btb_corre= ct =3D { static const struct perf_pmu_test_event segment_reg_loads_any =3D { .event =3D { .name =3D "segment_reg_loads.any", - .event =3D "umask=3D0x80,period=3D200000,event=3D0x6", + .event =3D "event=3D0x6,period=3D200000,umask=3D0x80", .desc =3D "Number of segment register loads", .topic =3D "other", }, - .alias_str =3D "umask=3D0x80,period=3D0x30d40,event=3D0x6", + .alias_str =3D "event=3D0x6,period=3D0x30d40,umask=3D0x80", .alias_long_desc =3D "Number of segment register loads", }; =20 static const struct perf_pmu_test_event dispatch_blocked_any =3D { .event =3D { .name =3D "dispatch_blocked.any", - .event =3D "umask=3D0x20,period=3D200000,event=3D0x9", + .event =3D "event=3D0x9,period=3D200000,umask=3D0x20", .desc =3D "Memory cluster signals to block micro-op dispatch for any rea= son", .topic =3D "other", }, - .alias_str =3D "umask=3D0x20,period=3D0x30d40,event=3D0x9", + .alias_str =3D "event=3D0x9,period=3D0x30d40,umask=3D0x20", .alias_long_desc =3D "Memory cluster signals to block micro-op dispatch f= or any reason", }; =20 static const struct perf_pmu_test_event eist_trans =3D { .event =3D { .name =3D "eist_trans", - .event =3D "umask=3D0x0,period=3D200000,event=3D0x3a", + .event =3D "event=3D0x3a,period=3D200000,umask=3D0x0", .desc =3D "Number of Enhanced Intel SpeedStep(R) Technology (EIST) trans= itions", .topic =3D "other", }, - .alias_str =3D "umask=3D0,period=3D0x30d40,event=3D0x3a", + .alias_str =3D "event=3D0x3a,period=3D0x30d40,umask=3D0", .alias_long_desc =3D "Number of Enhanced Intel SpeedStep(R) Technology (E= IST) transitions", }; =20 @@ -132,13 +132,13 @@ static const struct perf_pmu_test_event uncore_hisi_d= drc_flux_wcmd =3D { static const struct perf_pmu_test_event unc_cbo_xsnp_response_miss_evictio= n =3D { .event =3D { .name =3D "unc_cbo_xsnp_response.miss_eviction", - .event =3D "umask=3D0x81,event=3D0x22", + .event =3D "event=3D0x22,umask=3D0x81", .desc =3D "A cross-core snoop resulted from L3 Eviction which misses in = some processor core. Unit: uncore_cbox ", .topic =3D "uncore", .long_desc =3D "A cross-core snoop resulted from L3 Eviction which misse= s in some processor core", .pmu =3D "uncore_cbox", }, - .alias_str =3D "umask=3D0x81,event=3D0x22", + .alias_str =3D "event=3D0x22,umask=3D0x81", .alias_long_desc =3D "A cross-core snoop resulted from L3 Eviction which = misses in some processor core", .matching_pmu =3D "uncore_cbox_0", }; @@ -146,13 +146,13 @@ static const struct perf_pmu_test_event unc_cbo_xsnp_= response_miss_eviction =3D { static const struct perf_pmu_test_event uncore_hyphen =3D { .event =3D { .name =3D "event-hyphen", - .event =3D "umask=3D0x00,event=3D0xe0", + .event =3D "event=3D0xe0,umask=3D0x00", .desc =3D "UNC_CBO_HYPHEN. Unit: uncore_cbox ", .topic =3D "uncore", .long_desc =3D "UNC_CBO_HYPHEN", .pmu =3D "uncore_cbox", }, - .alias_str =3D "umask=3D0,event=3D0xe0", + .alias_str =3D "event=3D0xe0,umask=3D0", .alias_long_desc =3D "UNC_CBO_HYPHEN", .matching_pmu =3D "uncore_cbox_0", }; @@ -160,13 +160,13 @@ static const struct perf_pmu_test_event uncore_hyphen= =3D { static const struct perf_pmu_test_event uncore_two_hyph =3D { .event =3D { .name =3D "event-two-hyph", - .event =3D "umask=3D0x00,event=3D0xc0", + .event =3D "event=3D0xc0,umask=3D0x00", .desc =3D "UNC_CBO_TWO_HYPH. Unit: uncore_cbox ", .topic =3D "uncore", .long_desc =3D "UNC_CBO_TWO_HYPH", .pmu =3D "uncore_cbox", }, - .alias_str =3D "umask=3D0,event=3D0xc0", + .alias_str =3D "event=3D0xc0,umask=3D0", .alias_long_desc =3D "UNC_CBO_TWO_HYPH", .matching_pmu =3D "uncore_cbox_0", }; --=20 2.36.0.512.ge40c2bad7a-goog From nobody Sun Jun 14 21:38:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FDD7C433F5 for ; Wed, 11 May 2022 07:02:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242532AbiEKHCZ (ORCPT ); Wed, 11 May 2022 03:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242464AbiEKHBv (ORCPT ); Wed, 11 May 2022 03:01:51 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76717814A9 for ; Wed, 11 May 2022 00:01:49 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id w21-20020a25df15000000b0064b401428bfso157618ybg.22 for ; Wed, 11 May 2022 00:01:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=F175yXgo6Rtn6ipswoFePtZI8wN/S86uzy4b/OfTmOQ=; b=EXbdpT9PcG4eB3kPIrbv2teFNwbXNpmiX8dkM3kQ1yREPCquNFpZnNzBahRz9kABt6 QdkkxBwkOp/IegB1bjvRv99Lq+VoZxawove3FL5r8oysNzGJVciJbE/QLuduSNc32QwN v9Ne51hTG2daZTf1XRdx5hkzc2CrAkm3PhiCNVX954CW3skXTk7p3l/kQoDVPspdU+9I iw76nLOoSA7PHYgSmihsAD5wV+EriYwARDS9nj6op9p0/6Fm+BPcpktkGQOlr/1nTf3G h9V6it0wCKzQw9yqDYp5F1olN748de7UWc9IEZgUPG2EDHZRBz6M3MH71mXeOAhWgEFX 8xYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=F175yXgo6Rtn6ipswoFePtZI8wN/S86uzy4b/OfTmOQ=; b=CR2NOUaLTHoaDzpRtLp9Mq1h3bISGkJp4cm1mHtADvkWrtxhFFNTmcc+u/8r0aqxD8 0bPrT0TmJ1IzmyFPiOAnUgFTdMUVvpYDXlLKEhp7Krlo9GdbfpfAOPRXRxTQWHXQ3TBT 3u6m1uetLyDgzS0sNPmdU6qW39obi2HmSy4BzmnKMAHz6CeHh8Mwwp7m42iYTlT6pXEJ GQBMaQSs8Tl6Y69x6CuGfyC6g97t50Z7dsaoA5LvlMTJAOygO7LjIF3tfE+w6uhtUsv4 IXRXhj1mHIxHfBmi2xOu5z9u/ba/oH+iskaQrG9Xl6AuJz8O0XZLKdMFkoTTGWvbg1FO ib4A== X-Gm-Message-State: AOAM5309XTnFBb19Q5IWSgxIxGqqdk9Xl+PF1vbKOc1s2iFV8cCPFfCf xPDhxLm3KWlG+fUYPNl7z1I7yXyeS232 X-Google-Smtp-Source: ABdhPJwZNYVDsBl8+9N5FhkPDFkHxPGoT+3pLPh3cScc8OecLSSQc57NEZw7uH2Tc4knEpw8SDlugbuv/r2c X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:b6c9:16a6:f912:39d5]) (user=irogers job=sendgmr) by 2002:a81:784a:0:b0:2f7:d9fd:396f with SMTP id t71-20020a81784a000000b002f7d9fd396fmr24451204ywc.124.1652252508559; Wed, 11 May 2022 00:01:48 -0700 (PDT) Date: Wed, 11 May 2022 00:01:31 -0700 In-Reply-To: <20220511070133.710721-1-irogers@google.com> Message-Id: <20220511070133.710721-6-irogers@google.com> Mime-Version: 1.0 References: <20220511070133.710721-1-irogers@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH 5/7] perf jevents: Add python converter script From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Kan Liang , Andi Kleen , Zhengjun Xing , Felix Fietkau , Qi Liu , Like Xu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Nick Forrington , Kajol Jain , James Clark , Andrew Kilroy , "Paul A . Clarke" , Will Deacon , Mathieu Poirier , ananth.narayan@amd.com, ravi.bangoria@amd.com, santosh.shukla@amd.com, sandipan.das@amd.com, Caleb Biggers , Perry Taylor , Kshipra Bopardikar Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" jevents.c is large, has a dependency on an old forked version of jsmn, and is challenging to work upon. A lot of jevents.c's complexity comes from needing to write json and csv parsing from first principles. In contrast python has this functionality in standard libraries and is already a build pre-requisite for tools like asciidoc (that builds all of the perf man pages). Introduce jevents.py that produces identical output to jevents.c. Add a test that runs both converter tools and validates there are no output differences. The test can be invoked with a phony build target like: make -C tools/perf jevents-py-test The python code deliberately tries to replicate the behavior of jevents.c so that the output matches and transitioning tools shouldn't introduce regressions. In some cases the code isn't as elegant as hoped, but fixing this can be done as follow up. Signed-off-by: Ian Rogers --- tools/perf/Makefile.perf | 6 + tools/perf/pmu-events/jevents-test.sh | 33 +++ tools/perf/pmu-events/jevents.py | 392 ++++++++++++++++++++++++++ 3 files changed, 431 insertions(+) create mode 100755 tools/perf/pmu-events/jevents-test.sh create mode 100755 tools/perf/pmu-events/jevents.py diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 6e5aded855cc..078f0b06f08a 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -669,6 +669,12 @@ $(JEVENTS_IN): FORCE $(JEVENTS): $(JEVENTS_IN) $(QUIET_LINK)$(HOSTCC) $(JEVENTS_IN) -o $@ =20 +JEVENTS_PY :=3D pmu-events/jevents.py +JEVENTS_PY_TEST :=3D pmu-events/jevents-test.sh +.PHONY: jevents-py-test +jevents-py-test: $(JEVENTS) + $(Q)$(call echo-cmd,gen)$(JEVENTS_PY_TEST) $(JEVENTS) $(JEVENTS_PY) pmu-e= vents/arch + $(PMU_EVENTS_IN): $(JEVENTS) FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=3Dpmu-events obj= =3Dpmu-events =20 diff --git a/tools/perf/pmu-events/jevents-test.sh b/tools/perf/pmu-events/= jevents-test.sh new file mode 100755 index 000000000000..195ec83630ad --- /dev/null +++ b/tools/perf/pmu-events/jevents-test.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +# Validate that the legacy jevents and jevents.py produce identical output. +set -e + +JEVENTS=3D"$1" +JEVENTS_PY=3D"$2" +ARCH_PATH=3D"$3" +JEVENTS_C_GENERATED=3D$(mktemp /tmp/jevents_c.XXXXX.c) +JEVENTS_PY_GENERATED=3D$(mktemp /tmp/jevents_py.XXXXX.c) + +cleanup() { + rm "$JEVENTS_C_GENERATED" "$JEVENTS_PY_GENERATED" + trap - exit term int +} +trap cleanup exit term int + +for path in "$ARCH_PATH"/* +do + arch=3D$(basename $path) + if [[ "$arch" =3D=3D "test" ]] + then + continue + fi + echo "Checking architecture: $arch" + echo "Generating using jevents.c" + "$JEVENTS" "$arch" "$ARCH_PATH" "$JEVENTS_C_GENERATED" + echo "Generating using jevents.py" + "$JEVENTS_PY" "$arch" "$ARCH_PATH" "$JEVENTS_PY_GENERATED" + echo "Diffing" + diff -u "$JEVENTS_C_GENERATED" "$JEVENTS_PY_GENERATED" +done +cleanup diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py new file mode 100755 index 000000000000..3a3d7471eb71 --- /dev/null +++ b/tools/perf/pmu-events/jevents.py @@ -0,0 +1,392 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +"""Convert directories of JSON events to C code.""" +import argparse +import csv +import json +import os +import sys +from typing import Callable + +# Global command line arguments. +args =3D None +# List of event tables generated from "/sys" directories. +sys_event_tables =3D [] +# Map from an event name to an architecture standard +# JsonEvent. Architecture standard events are in json files in the top +# f'{args.starting_dir}/{args.arch}' directory. +arch_std_events =3D dict() +# Track whether an events table is currently being defined and needs closi= ng. +close_table =3D False + + +def file_name_to_table_name(parents: list[str], dirname: str) -> str: + """Generate a C table name from directory names.""" + tblname =3D 'pme' + for p in parents: + tblname +=3D '_' + p + tblname +=3D '_' + dirname + return tblname.replace('-', '_') + + +class JsonEvent: + """Representation of an event loaded from a json file dictionary.""" + + def __init__(self, dict): + """Constructor passed the dictionary of parsed json values.""" + + def llx(x: int) -> str: + """Convert an int to a string similar to a printf modifier of %#llx.= """ + return '0' if x =3D=3D 0 else hex(x) + + def fixdesc(s: str) -> str: + """Fix formatting issue for the desc string.""" + return s.removesuffix('. ').removesuffix('. ').removesuffix('.').re= place( + '\n', '\\n').replace('\"', '\\"').replace('\r', '\\r') if s else= None + + def convert_aggr_mode(aggr_mode: str) -> str: + """Returns the aggr_mode_class enum value associated with the JSON s= tring.""" + if not aggr_mode: + return None + aggr_mode_to_enum =3D { + 'PerChip': '1', + 'PerCore': '2', + } + return aggr_mode_to_enum[aggr_mode] + + def lookup_msr(num: str) -> str: + """Converts the msr number, or first in a list to the appropriate ev= ent field.""" + if not num: + return None + msrmap =3D { + 0x3F6: 'ldlat=3D', + 0x1A6: 'offcore_rsp=3D', + 0x1A7: 'offcore_rsp=3D', + 0x3F7: 'frontend=3D', + } + return msrmap[int(num.split(',', 1)[0], 0)] + + def real_event(name: str, event: str) -> str: + """Convert well known event names to an event string otherwise use t= he event argument.""" + fixed =3D { + 'inst_retired.any': 'event=3D0xc0,period=3D2000003', + 'inst_retired.any_p': 'event=3D0xc0,period=3D2000003', + 'cpu_clk_unhalted.ref': 'event=3D0x0,umask=3D0x03,period=3D20000= 03', + 'cpu_clk_unhalted.thread': 'event=3D0x3c,period=3D2000003', + 'cpu_clk_unhalted.core': 'event=3D0x3c,period=3D2000003', + 'cpu_clk_unhalted.thread_any': 'event=3D0x3c,any=3D1,period=3D20= 00003', + } + if not name: + return None + if name.lower() in fixed: + return fixed[name.lower()] + return event + + def unit_to_pmu(unit: str) -> str: + """Convert a JSON Unit to Linux PMU name.""" + if not unit: + return None + # Comment brought over from jevents.c: + # it's not realistic to keep adding these, we need something more sc= alable ... + table =3D { + 'CBO': 'uncore_cbox', + 'QPI LL': 'uncore_qpi', + 'SBO': 'uncore_sbox', + 'iMPH-U': 'uncore_arb', + 'CPU-M-CF': 'cpum_cf', + 'CPU-M-SF': 'cpum_sf', + 'UPI LL': 'uncore_upi', + 'hisi_sicl,cpa': 'hisi_sicl,cpa', + 'hisi_sccl,ddrc': 'hisi_sccl,ddrc', + 'hisi_sccl,hha': 'hisi_sccl,hha', + 'hisi_sccl,l3c': 'hisi_sccl,l3c', + 'imx8_ddr': 'imx8_ddr', + 'L3PMC': 'amd_l3', + 'DFPMC': 'amd_df', + 'cpu_core': 'cpu_core', + 'cpu_atom': 'cpu_atom', + } + return table[unit] if unit in table else f'uncore_{unit.lower()}' + + eventcode =3D 0 + if 'EventCode' in dict: + eventcode =3D int(dict['EventCode'].split(',', 1)[0], 0) + if 'ExtSel' in dict: + eventcode |=3D int(dict['ExtSel']) << 21 + configcode =3D int(dict['ConfigCode'], 0) if 'ConfigCode' in dict else= None + self.name =3D dict['EventName'].lower() if 'EventName' in dict else No= ne + self.compat =3D dict.get('Compat') + self.desc =3D fixdesc(dict.get('BriefDescription')) + self.long_desc =3D fixdesc(dict.get('PublicDescription')) + precise =3D dict.get('PEBS') + msr =3D lookup_msr(dict.get('MSRIndex')) + msrval =3D dict.get('MSRValue') + extra_desc =3D '' + if 'Data_LA' in dict: + extra_desc +=3D ' Supports address when precise' + if 'Errata' in dict: + extra_desc +=3D '.' + if 'Errata' in dict: + extra_desc +=3D ' Spec update: ' + dict['Errata'] + self.pmu =3D unit_to_pmu(dict.get('Unit')) + filter =3D dict.get('Filter') + self.unit =3D dict.get('ScaleUnit') + self.perpkg =3D dict.get('PerPkg') + self.aggr_mode =3D convert_aggr_mode(dict.get('AggregationMode')) + self.deprecated =3D dict.get('Deprecated') + self.metric_name =3D dict.get('MetricName') + self.metric_group =3D dict.get('MetricGroup') + self.metric_constraint =3D dict.get('MetricConstraint') + self.metric_expr =3D dict.get('MetricExpr') + if self.metric_expr: + self.metric_expr =3D self.metric_expr.replace('\\', '\\\\') + arch_std =3D dict.get('ArchStdEvent') + if precise and self.desc and not '(Precise Event)' in self.desc: + extra_desc +=3D ' (Must be precise)' if precise =3D=3D '2' else (' (= Precise ' + 'event)') + event =3D f'config=3D{llx(configcode)}' if configcode is not None else= f'event=3D{llx(eventcode)}' + event_fields =3D [ + ('AnyThread', 'any=3D'), + ('PortMask', 'ch_mask=3D'), + ('CounterMask', 'cmask=3D'), + ('EdgeDetect', 'edge=3D'), + ('FCMask', 'fc_mask=3D'), + ('Invert', 'inv=3D'), + ('SampleAfterValue', 'period=3D'), + ('UMask', 'umask=3D'), + ] + for key, value in event_fields: + if key in dict and dict[key] !=3D '0': + event +=3D ',' + value + dict[key] + if filter: + event +=3D f',{filter}' + if msr: + event +=3D f',{msr}{msrval}' + if self.desc and extra_desc: + self.desc +=3D extra_desc + if self.long_desc and extra_desc: + self.long_desc +=3D extra_desc + if self.pmu: + if self.desc and not self.desc.endswith('. '): + self.desc +=3D '. ' + self.desc =3D (self.desc if self.desc else '') + ('Unit: ' + self.pm= u + ' ') + if arch_std and arch_std.lower() in arch_std_events: + event =3D arch_std_events[arch_std.lower()].event + # Copy from the architecture standard event to self for undefined fi= elds. + for attr, value in arch_std_events[arch_std.lower()].__dict__.items(= ): + if hasattr(self, attr) and not getattr(self, attr): + setattr(self, attr, value) + + self.event =3D real_event(self.name, event) + + def __repr__(self) -> str: + """String representation primarily for debugging.""" + s =3D '{\n' + for attr, value in self.__dict__.items(): + if value: + s +=3D f'\t{attr} =3D {value},\n' + return s + '}' + + def ToCString(self, topic_local: str) -> str: + """Representation of the event as a C struct initializer.""" + + def AttrString(attr: str, value: str) -> str: + return '\t.%s =3D \"%s\",\n' % (attr, value) + + def StrIfPresent(self, attr: str) -> str: + if not getattr(self, attr): + return '' + return AttrString(attr, getattr(self, attr)) + + s =3D '{\n' + for attr in ['name', 'event']: + s +=3D StrIfPresent(self, attr) + if self.desc: + s +=3D AttrString('desc', self.desc) + else: + s +=3D AttrString('desc', '(null)') + s +=3D StrIfPresent(self, 'compat') + s +=3D f'\t.topic =3D "{topic_local}",\n' + for attr in [ + 'long_desc', 'pmu', 'unit', 'perpkg', 'aggr_mode', 'metric_expr', + 'metric_name', 'metric_group', 'deprecated', 'metric_constraint' + ]: + s +=3D StrIfPresent(self, attr) + s +=3D '},\n' + return s + + +def read_json_events(path: str) -> list[JsonEvent]: + """Read json events from the specified file.""" + return json.load(open(path), object_hook=3Dlambda d: JsonEvent(d)) + +def preprocess_arch_std_files(archpath: str) -> None: + """Read in all architecture standard events.""" + global arch_std_events + for item in os.scandir(archpath): + if item.is_file() and item.name.endswith('.json'): + for event in read_json_events(item.path): + if event.name: + arch_std_events[event.name.lower()] =3D event + + +def print_events_table_prefix(tblname: str) -> None: + """Called when a new events table is started.""" + global close_table + if close_table: + raise IOError('Printing table prefix but last table has no suffix') + args.output_file.write('static const struct pmu_event %s[] =3D {\n' % tb= lname) + close_table =3D True + + +def print_events_table_entries(item: os.DirEntry, topic: str) -> None: + """Create contents of an events table.""" + if not close_table: + raise IOError('Table entries missing prefix') + for event in read_json_events(item.path): + args.output_file.write(event.ToCString(topic)) + +def print_events_table_suffix() -> None: + """Optionally close events table.""" + global close_table + if close_table: + args.output_file.write("""{ +\t.name =3D 0, +\t.event =3D 0, +\t.desc =3D 0, +}, +}; +""") + close_table =3D False + +def process_one_file(parents: list[str], item: os.DirEntry) -> None: + """Process a JSON file during the main walk.""" + global sys_event_tables + + def get_topic(topic: str) -> str: + return topic.removesuffix('.json').replace('-', ' ') + + def is_leaf_dir(path: str) -> bool: + for item in os.scandir(path): + if item.is_dir(): + return False + return True + + # model directory, reset topic + if item.is_dir() and is_leaf_dir(item.path): + print_events_table_suffix() + + tblname =3D file_name_to_table_name(parents, item.name) + if item.name =3D=3D 'sys': + sys_event_tables.append(tblname) + print_events_table_prefix(tblname) + return + + # base dir or too deep + level =3D len(parents) + if level =3D=3D 0 or level > 4: + return + + # Ignore other directories. If the file name does not have a .json + # extension, ignore it. It could be a readme.txt for instance. + if not item.is_file() or not item.name.endswith('.json'): + return + + print_events_table_entries(item, get_topic(item.name)) + + +def print_mapping_table() -> None: + """Read the mapfile and generate the struct from cpuid string to event t= able.""" + table =3D csv.reader(open(f'{args.starting_dir}/{args.arch}/mapfile.csv'= )) + args.output_file.write('const struct pmu_events_map pmu_events_map[] =3D= {\n') + first =3D True + for row in table: + # Skip the first row or any row beginning with #. + if not first and len(row) > 0 and not row[0].startswith('#'): + tblname =3D file_name_to_table_name([], row[2].replace('/', '_')) + args.output_file.write("""{ +\t.cpuid =3D \"%s\", +\t.version =3D \"%s\", +\t.type =3D \"%s\", +\t.table =3D %s +}, +""" % (row[0].replace('\\', '\\\\'), row[1], row[3], tblname)) + first =3D False + + args.output_file.write("""{ +\t.cpuid =3D "testcpu", +\t.version =3D "v1", +\t.type =3D "core", +\t.table =3D pme_test_soc_cpu, +}, +{ +\t.cpuid =3D 0, +\t.version =3D 0, +\t.type =3D 0, +\t.table =3D 0, +}, +}; +""") + + +def print_system_mapping_table() -> None: + """C struct mapping table array for tables from /sys directories.""" + args.output_file.write( + '\nconst struct pmu_sys_events pmu_sys_event_tables[] =3D {\n') + for tblname in sys_event_tables: + args.output_file.write("""\t{ +\t\t.table =3D %s, +\t\t.name =3D \"%s\", +\t}, +""" % (tblname, tblname)) + args.output_file.write("""\t{ +\t\t.table =3D 0 +\t}, +}; +""") + + +def main() -> None: + global args + + def dir_path(path: str) -> str: + """Validate path is a directory for argparse.""" + if os.path.isdir(path): + return path + else: + raise argparse.ArgumentTypeError(f'\'{path}\' is not a valid directo= ry') + + def ftw(path: str, parents: list[str], + action: Callable[[list[str], os.DirEntry], None]) -> None: + """Replicate the directory/file walking behavior of C's file tree walk= .""" + for item in os.scandir(path): + action(parents, item) + if item.is_dir(): + ftw(item.path, parents + [item.name], action) + + ap =3D argparse.ArgumentParser() + ap.add_argument('arch', help=3D'Architecture name like x86') + ap.add_argument( + 'starting_dir', + type=3Ddir_path, + help=3D'Root of tree containing architecture directories containing = json files' + ) + ap.add_argument( + 'output_file', type=3Dargparse.FileType('w'), nargs=3D'?', default= =3Dsys.stdout) + args =3D ap.parse_args() + + args.output_file.write("#include \"pmu-events/pmu-events.h\"\n") + for path in [args.arch, 'test']: + arch_path =3D f'{args.starting_dir}/{path}' + if not os.path.isdir(arch_path): + raise IOError(f'Missing architecture directory in \'{arch_path}\'') + preprocess_arch_std_files(arch_path) + ftw(arch_path, [], process_one_file) + print_events_table_suffix() + + print_mapping_table() + print_system_mapping_table() + + +if __name__ =3D=3D '__main__': + main() --=20 2.36.0.512.ge40c2bad7a-goog From nobody Sun Jun 14 21:38:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16F5FC433EF for ; Wed, 11 May 2022 07:02:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242586AbiEKHC3 (ORCPT ); Wed, 11 May 2022 03:02:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242485AbiEKHBx (ORCPT ); Wed, 11 May 2022 03:01:53 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E168703D5 for ; Wed, 11 May 2022 00:01:51 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2f4e17a5809so10221727b3.2 for ; Wed, 11 May 2022 00:01:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=VAtZjV4MJ62CuOSAHGEHWfl01nSGCCkRqsoD+ghc728=; b=OnCQy6aa/8F3IasTk+TKYBxKBcBVGA8W8D6b67uA4tnYWKRc9A/P6aNvR2d2fVPTfb ia58ba6DjAXxmJpG3FBG1ZfGjQjowinNTBNrsU3cdR+yxfddSVOQZJ7KEDHfdQrB9Anm +r7thXz8jTYOiZYiQdBJ7/b6xyzE1QTbTVjDfrDAnSh1p1uyVZFuFR9slpaGwA20FIpH Ixf6NFOEbal+tv03tjlin/C6LhZNa0xURGYplTOUF7ZtoVnDz63+Hg6P4GsOyldopsyG r5Z9K5jr74OY4nOctQv6cyJWsM0QiQ8tcg545FJhvZ07MC93vZupY1vyhAHN3MaVxyAF kG4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=VAtZjV4MJ62CuOSAHGEHWfl01nSGCCkRqsoD+ghc728=; b=ybfZJTZYpcxLIMXWG3ekXFY5J586Jm1ZqxTyaoIh2uOe2DlxBnATjCvXPa2Bl7xahJ B1Mn0x8dTX0j12z35d/WqPurYhDwOL0tbZY7bC4lcqWusaMgdCxCo9WDcKlOJoy+eKru xa2LTowuvLolkHZ3RW4Ak7vHup0dYYGg0Fz494RKAa3c3aoTRBp6/InmQDt2TuGjpORk kiMA5o5VJVTYUJtv9tpc/+1/Gz3eMz2+KQf/wcZVwpcOWtZK8TD2KPR9UKwSX5PfY3wH NtYsKnNdmb0g9ukSfSjX98eZSF4MbUWvrpm0eLDYQQ2+uocHZSFWfLw3MHuCLZsogqf2 A7EA== X-Gm-Message-State: AOAM530DvTaAXGM6QddCYgsiPIC7ciOMIU7YPChPh35Ps+t5m31YKBd/ HaQHVFgvkm9gbwmeO5TZd3jESS/xFhED X-Google-Smtp-Source: ABdhPJyOg3AbQYvg7iWNInX49t2eNCM02tWW+Uxc7y9UQkZcNbLgt4KalKmHIdtZS5kA4AYmawf2WK1fgoMX X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:b6c9:16a6:f912:39d5]) (user=irogers job=sendgmr) by 2002:a05:6902:150d:b0:649:3b56:c671 with SMTP id q13-20020a056902150d00b006493b56c671mr22326727ybu.163.1652252510705; Wed, 11 May 2022 00:01:50 -0700 (PDT) Date: Wed, 11 May 2022 00:01:32 -0700 In-Reply-To: <20220511070133.710721-1-irogers@google.com> Message-Id: <20220511070133.710721-7-irogers@google.com> Mime-Version: 1.0 References: <20220511070133.710721-1-irogers@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH 6/7] perf jevents: Switch build to use jevents.py From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Kan Liang , Andi Kleen , Zhengjun Xing , Felix Fietkau , Qi Liu , Like Xu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Nick Forrington , Kajol Jain , James Clark , Andrew Kilroy , "Paul A . Clarke" , Will Deacon , Mathieu Poirier , ananth.narayan@amd.com, ravi.bangoria@amd.com, santosh.shukla@amd.com, sandipan.das@amd.com, Caleb Biggers , Perry Taylor , Kshipra Bopardikar Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Generate pmu-events.c using jevents.py rather than the binary built from jevents.c. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/Build | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build index a055dee6a46a..ed7eabc64665 100644 --- a/tools/perf/pmu-events/Build +++ b/tools/perf/pmu-events/Build @@ -9,10 +9,11 @@ JSON =3D $(shell [ -d $(JDIR) ] && \ JDIR_TEST =3D pmu-events/arch/test JSON_TEST =3D $(shell [ -d $(JDIR_TEST) ] && \ find $(JDIR_TEST) -name '*.json') +JEVENTS_PY =3D pmu-events/jevents.py =20 # # Locate/process JSON files in pmu-events/arch/ # directory and create tables in pmu-events.c. # -$(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JSON_TEST) $(JEVENTS) - $(Q)$(call echo-cmd,gen)$(JEVENTS) $(SRCARCH) pmu-events/arch $(OUTPUT)pm= u-events/pmu-events.c $(V) +$(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JSON_TEST) $(JEVENTS_PY) + $(Q)$(call echo-cmd,gen)$(JEVENTS_PY) $(SRCARCH) pmu-events/arch $(OUTPUT= )pmu-events/pmu-events.c --=20 2.36.0.512.ge40c2bad7a-goog From nobody Sun Jun 14 21:38:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BFE4C433EF for ; Wed, 11 May 2022 07:02:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242594AbiEKHCi (ORCPT ); Wed, 11 May 2022 03:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242526AbiEKHB6 (ORCPT ); Wed, 11 May 2022 03:01:58 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49BE886AFA for ; Wed, 11 May 2022 00:01:53 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2f8bbaa6b16so9799547b3.14 for ; Wed, 11 May 2022 00:01:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=WoQc4VDjkTPfiPbo7oYX72oOpF31fHGt0/Br9kcsRT0=; b=VpVflxHWF3wG6mf+jrwniCVW1S6cAULKa+vX+2dpAwRIclVzhnd6ZSk+IIc/Ab+iCG GiqquJGrKLSMDphR5GMNVuiEuerL4/uyFWnmhyV+izFDHjN01gefScMNDfWMhV5ug9ZH IfkMO6mMEFeeh2ff+0k51PNF+wkSk1tTtLkJTiDWruHqsz9XDEZwbbTfhGPqUjX7IpE9 pdjLZs2ZDS7/sEl+kHpqTqvzIKlTRwAUF+yOl8dukJ4q+iHFPl/0WG3hVb1Q0m8olurd NIgVKA79q6QZSMdLlRsx8yo/HwjWRyXq+eFTwaMXTzXjjTKzfzvm9l71xXGl5/yNOw6b blmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=WoQc4VDjkTPfiPbo7oYX72oOpF31fHGt0/Br9kcsRT0=; b=ZrNFYEVsIkAKuXA+3uwhlGB6Up+v7V1vU/juUIff5jnKsztI77fNL6La8kwM9m2ap0 VqIxMPKf/FHqII8yIcbFrzlUVRm8CAD4SBPTvTU1iTIiSnI+VfjFibup7UnSN1nEhiAA 83nbPsjg9rwBBvOKETSh8ePygt8yuDw56aiTP+0zuF6tbFacFRMhmoOz24aHV/E+XbYY xqrzZNPIg5U9gFTkqLBRAaYT2+3R5Dwtj6OX1uH2VD729xOztGLAkh866uKtqwksIog3 tb80ja0TKItz2BDPSA/cEv4Ub4VO09pKpra/QKIG8PE9f3q2lYol3ruSvaaGJByygqbG vWQQ== X-Gm-Message-State: AOAM533lhV5ahAzWldu4XtXj5wg/xjbSIIS9jXtuS+zcBAzO4D7yyZyl sHUnCYkuA0WxHZMUuHJ32y2Bi+wHi+p7 X-Google-Smtp-Source: ABdhPJwXz5EYKTXaW0b9Pq2VdvZjkvku64mF6zTfeGuOkFP0YGi/cNC/7j5QS1vgzlZVAV7v9uFAEewfPqeJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:b6c9:16a6:f912:39d5]) (user=irogers job=sendgmr) by 2002:a81:5603:0:b0:2f8:3187:f37a with SMTP id k3-20020a815603000000b002f83187f37amr22551934ywb.255.1652252512885; Wed, 11 May 2022 00:01:52 -0700 (PDT) Date: Wed, 11 May 2022 00:01:33 -0700 In-Reply-To: <20220511070133.710721-1-irogers@google.com> Message-Id: <20220511070133.710721-8-irogers@google.com> Mime-Version: 1.0 References: <20220511070133.710721-1-irogers@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH 7/7] perf jevents: Remove jevents.c From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Kan Liang , Andi Kleen , Zhengjun Xing , Felix Fietkau , Qi Liu , Like Xu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Nick Forrington , Kajol Jain , James Clark , Andrew Kilroy , "Paul A . Clarke" , Will Deacon , Mathieu Poirier , ananth.narayan@amd.com, ravi.bangoria@amd.com, santosh.shukla@amd.com, sandipan.das@amd.com, Caleb Biggers , Perry Taylor , Kshipra Bopardikar Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove files and build rules. Remove test for comparing with jevents.py as there is no longer a binary to compare with. Signed-off-by: Ian Rogers --- tools/perf/Makefile.perf | 19 +- tools/perf/pmu-events/Build | 4 - tools/perf/pmu-events/jevents-test.sh | 33 - tools/perf/pmu-events/jevents.c | 1342 ------------------------- tools/perf/pmu-events/jsmn.h | 68 -- tools/perf/pmu-events/json.c | 162 --- tools/perf/pmu-events/json.h | 39 - 7 files changed, 1 insertion(+), 1666 deletions(-) delete mode 100755 tools/perf/pmu-events/jevents-test.sh delete mode 100644 tools/perf/pmu-events/jevents.c delete mode 100644 tools/perf/pmu-events/jsmn.h delete mode 100644 tools/perf/pmu-events/json.c delete mode 100644 tools/perf/pmu-events/json.h diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 078f0b06f08a..ff8a8b945a07 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -651,31 +651,14 @@ strip: $(PROGRAMS) $(OUTPUT)perf =20 PERF_IN :=3D $(OUTPUT)perf-in.o =20 -JEVENTS :=3D $(OUTPUT)pmu-events/jevents -JEVENTS_IN :=3D $(OUTPUT)pmu-events/jevents-in.o - PMU_EVENTS_IN :=3D $(OUTPUT)pmu-events/pmu-events-in.o =20 -export JEVENTS - build :=3D -f $(srctree)/tools/build/Makefile.build dir=3D. obj =20 $(PERF_IN): prepare FORCE $(Q)$(MAKE) $(build)=3Dperf =20 -$(JEVENTS_IN): FORCE - $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=3Dpmu-events obj= =3Djevents - -$(JEVENTS): $(JEVENTS_IN) - $(QUIET_LINK)$(HOSTCC) $(JEVENTS_IN) -o $@ - -JEVENTS_PY :=3D pmu-events/jevents.py -JEVENTS_PY_TEST :=3D pmu-events/jevents-test.sh -.PHONY: jevents-py-test -jevents-py-test: $(JEVENTS) - $(Q)$(call echo-cmd,gen)$(JEVENTS_PY_TEST) $(JEVENTS) $(JEVENTS_PY) pmu-e= vents/arch - -$(PMU_EVENTS_IN): $(JEVENTS) FORCE +$(PMU_EVENTS_IN): FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=3Dpmu-events obj= =3Dpmu-events =20 $(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) $(LIBTRACEEVENT_DYN= AMIC_LIST) diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build index ed7eabc64665..9bc81ae903ed 100644 --- a/tools/perf/pmu-events/Build +++ b/tools/perf/pmu-events/Build @@ -1,7 +1,3 @@ -hostprogs :=3D jevents - -jevents-y +=3D json.o jsmn.o jevents.o -HOSTCFLAGS_jevents.o =3D -I$(srctree)/tools/include pmu-events-y +=3D pmu-events.o JDIR =3D pmu-events/arch/$(SRCARCH) JSON =3D $(shell [ -d $(JDIR) ] && \ diff --git a/tools/perf/pmu-events/jevents-test.sh b/tools/perf/pmu-events/= jevents-test.sh deleted file mode 100755 index 195ec83630ad..000000000000 --- a/tools/perf/pmu-events/jevents-test.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) -# Validate that the legacy jevents and jevents.py produce identical output. -set -e - -JEVENTS=3D"$1" -JEVENTS_PY=3D"$2" -ARCH_PATH=3D"$3" -JEVENTS_C_GENERATED=3D$(mktemp /tmp/jevents_c.XXXXX.c) -JEVENTS_PY_GENERATED=3D$(mktemp /tmp/jevents_py.XXXXX.c) - -cleanup() { - rm "$JEVENTS_C_GENERATED" "$JEVENTS_PY_GENERATED" - trap - exit term int -} -trap cleanup exit term int - -for path in "$ARCH_PATH"/* -do - arch=3D$(basename $path) - if [[ "$arch" =3D=3D "test" ]] - then - continue - fi - echo "Checking architecture: $arch" - echo "Generating using jevents.c" - "$JEVENTS" "$arch" "$ARCH_PATH" "$JEVENTS_C_GENERATED" - echo "Generating using jevents.py" - "$JEVENTS_PY" "$arch" "$ARCH_PATH" "$JEVENTS_PY_GENERATED" - echo "Diffing" - diff -u "$JEVENTS_C_GENERATED" "$JEVENTS_PY_GENERATED" -done -cleanup diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevent= s.c deleted file mode 100644 index cee61c4ed59e..000000000000 --- a/tools/perf/pmu-events/jevents.c +++ /dev/null @@ -1,1342 +0,0 @@ -#define _XOPEN_SOURCE 500 /* needed for nftw() */ -#define _GNU_SOURCE /* needed for asprintf() */ - -/* Parse event JSON files */ - -/* - * Copyright (c) 2014, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are = met: - * - * 1. Redistributions of source code must retain the above copyright notic= e, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include /* getrlimit */ -#include /* getrlimit */ -#include -#include -#include -#include -#include "jsmn.h" -#include "json.h" -#include "pmu-events.h" - -int verbose; -char *prog; - -struct json_event { - char *name; - char *compat; - char *event; - char *desc; - char *long_desc; - char *pmu; - char *unit; - char *perpkg; - char *aggr_mode; - char *metric_expr; - char *metric_name; - char *metric_group; - char *deprecated; - char *metric_constraint; -}; - -static enum aggr_mode_class convert(const char *aggr_mode) -{ - if (!strcmp(aggr_mode, "PerCore")) - return PerCore; - else if (!strcmp(aggr_mode, "PerChip")) - return PerChip; - - pr_err("%s: Wrong AggregationMode value '%s'\n", prog, aggr_mode); - return -1; -} - -static LIST_HEAD(sys_event_tables); - -struct sys_event_table { - struct list_head list; - char *soc_id; -}; - -static void free_sys_event_tables(void) -{ - struct sys_event_table *et, *next; - - list_for_each_entry_safe(et, next, &sys_event_tables, list) { - free(et->soc_id); - free(et); - } -} - -int eprintf(int level, int var, const char *fmt, ...) -{ - - int ret; - va_list args; - - if (var < level) - return 0; - - va_start(args, fmt); - - ret =3D vfprintf(stderr, fmt, args); - - va_end(args); - - return ret; -} - -static void addfield(char *map, char **dst, const char *sep, - const char *a, jsmntok_t *bt) -{ - unsigned int len =3D strlen(a) + 1 + strlen(sep); - int olen =3D *dst ? strlen(*dst) : 0; - int blen =3D bt ? json_len(bt) : 0; - char *out; - - out =3D realloc(*dst, len + olen + blen); - if (!out) { - /* Don't add field in this case */ - return; - } - *dst =3D out; - - if (!olen) - *(*dst) =3D 0; - else - strcat(*dst, sep); - strcat(*dst, a); - if (bt) - strncat(*dst, map + bt->start, blen); -} - -static void fixname(char *s) -{ - for (; *s; s++) - *s =3D tolower(*s); -} - -static void fixdesc(char *s) -{ - char *e =3D s + strlen(s); - - /* Remove trailing dots that look ugly in perf list */ - --e; - while (e >=3D s && isspace(*e)) - --e; - if (*e =3D=3D '.') - *e =3D 0; -} - -/* Add escapes for '\' so they are proper C strings. */ -static char *fixregex(char *s) -{ - int len =3D 0; - int esc_count =3D 0; - char *fixed =3D NULL; - char *p, *q; - - /* Count the number of '\' in string */ - for (p =3D s; *p; p++) { - ++len; - if (*p =3D=3D '\\') - ++esc_count; - } - - if (esc_count =3D=3D 0) - return s; - - /* allocate space for a new string */ - fixed =3D (char *) malloc(len + esc_count + 1); - if (!fixed) - return NULL; - - /* copy over the characters */ - q =3D fixed; - for (p =3D s; *p; p++) { - if (*p =3D=3D '\\') { - *q =3D '\\'; - ++q; - } - *q =3D *p; - ++q; - } - *q =3D '\0'; - return fixed; -} - -static struct msrmap { - const char *num; - const char *pname; -} msrmap[] =3D { - { "0x3F6", "ldlat=3D" }, - { "0x1A6", "offcore_rsp=3D" }, - { "0x1A7", "offcore_rsp=3D" }, - { "0x3F7", "frontend=3D" }, - { NULL, NULL } -}; - -static void cut_comma(char *map, jsmntok_t *newval) -{ - int i; - - /* Cut off everything after comma */ - for (i =3D newval->start; i < newval->end; i++) { - if (map[i] =3D=3D ',') - newval->end =3D i; - } -} - -static struct msrmap *lookup_msr(char *map, jsmntok_t *val) -{ - jsmntok_t newval =3D *val; - static bool warned; - int i; - - cut_comma(map, &newval); - for (i =3D 0; msrmap[i].num; i++) - if (json_streq(map, &newval, msrmap[i].num)) - return &msrmap[i]; - if (!warned) { - warned =3D true; - pr_err("%s: Unknown MSR in event file %.*s\n", prog, - json_len(val), map + val->start); - } - return NULL; -} - -static struct map { - const char *json; - const char *perf; -} unit_to_pmu[] =3D { - { "CBO", "uncore_cbox" }, - { "QPI LL", "uncore_qpi" }, - { "SBO", "uncore_sbox" }, - { "iMPH-U", "uncore_arb" }, - { "CPU-M-CF", "cpum_cf" }, - { "CPU-M-SF", "cpum_sf" }, - { "UPI LL", "uncore_upi" }, - { "hisi_sicl,cpa", "hisi_sicl,cpa"}, - { "hisi_sccl,ddrc", "hisi_sccl,ddrc" }, - { "hisi_sccl,hha", "hisi_sccl,hha" }, - { "hisi_sccl,l3c", "hisi_sccl,l3c" }, - /* it's not realistic to keep adding these, we need something more scalab= le ... */ - { "imx8_ddr", "imx8_ddr" }, - { "L3PMC", "amd_l3" }, - { "DFPMC", "amd_df" }, - { "cpu_core", "cpu_core" }, - { "cpu_atom", "cpu_atom" }, - {} -}; - -static const char *field_to_perf(struct map *table, char *map, jsmntok_t *= val) -{ - int i; - - for (i =3D 0; table[i].json; i++) { - if (json_streq(map, val, table[i].json)) - return table[i].perf; - } - return NULL; -} - -#define EXPECT(e, t, m) do { if (!(e)) { \ - jsmntok_t *loc =3D (t); \ - if (!(t)->start && (t) > tokens) \ - loc =3D (t) - 1; \ - pr_err("%s:%d: " m ", got %s\n", fn, \ - json_line(map, loc), \ - json_name(t)); \ - err =3D -EIO; \ - goto out_free; \ -} } while (0) - -static char *topic; - -static char *get_topic(void) -{ - char *tp; - int i; - - /* tp is free'd in process_one_file() */ - i =3D asprintf(&tp, "%s", topic); - if (i < 0) { - pr_info("%s: asprintf() error %s\n", prog); - return NULL; - } - - for (i =3D 0; i < (int) strlen(tp); i++) { - char c =3D tp[i]; - - if (c =3D=3D '-') - tp[i] =3D ' '; - else if (c =3D=3D '.') { - tp[i] =3D '\0'; - break; - } - } - - return tp; -} - -static int add_topic(char *bname) -{ - free(topic); - topic =3D strdup(bname); - if (!topic) { - pr_info("%s: strdup() error %s for file %s\n", prog, - strerror(errno), bname); - return -ENOMEM; - } - return 0; -} - -struct perf_entry_data { - FILE *outfp; - char *topic; -}; - -static int close_table; - -static void print_events_table_prefix(FILE *fp, const char *tblname) -{ - fprintf(fp, "static const struct pmu_event %s[] =3D {\n", tblname); - close_table =3D 1; -} - -static int print_events_table_entry(void *data, struct json_event *je) -{ - struct perf_entry_data *pd =3D data; - FILE *outfp =3D pd->outfp; - char *topic_local =3D pd->topic; - - /* - * TODO: Remove formatting chars after debugging to reduce - * string lengths. - */ - fprintf(outfp, "{\n"); - - if (je->name) - fprintf(outfp, "\t.name =3D \"%s\",\n", je->name); - if (je->event) - fprintf(outfp, "\t.event =3D \"%s\",\n", je->event); - fprintf(outfp, "\t.desc =3D \"%s\",\n", je->desc); - if (je->compat) - fprintf(outfp, "\t.compat =3D \"%s\",\n", je->compat); - fprintf(outfp, "\t.topic =3D \"%s\",\n", topic_local); - if (je->long_desc && je->long_desc[0]) - fprintf(outfp, "\t.long_desc =3D \"%s\",\n", je->long_desc); - if (je->pmu) - fprintf(outfp, "\t.pmu =3D \"%s\",\n", je->pmu); - if (je->unit) - fprintf(outfp, "\t.unit =3D \"%s\",\n", je->unit); - if (je->perpkg) - fprintf(outfp, "\t.perpkg =3D \"%s\",\n", je->perpkg); - if (je->aggr_mode) - fprintf(outfp, "\t.aggr_mode =3D \"%d\",\n", convert(je->aggr_mode)); - if (je->metric_expr) - fprintf(outfp, "\t.metric_expr =3D \"%s\",\n", je->metric_expr); - if (je->metric_name) - fprintf(outfp, "\t.metric_name =3D \"%s\",\n", je->metric_name); - if (je->metric_group) - fprintf(outfp, "\t.metric_group =3D \"%s\",\n", je->metric_group); - if (je->deprecated) - fprintf(outfp, "\t.deprecated =3D \"%s\",\n", je->deprecated); - if (je->metric_constraint) - fprintf(outfp, "\t.metric_constraint =3D \"%s\",\n", je->metric_constrai= nt); - fprintf(outfp, "},\n"); - - return 0; -} - -struct event_struct { - struct list_head list; - char *name; - char *event; - char *compat; - char *desc; - char *long_desc; - char *pmu; - char *unit; - char *perpkg; - char *aggr_mode; - char *metric_expr; - char *metric_name; - char *metric_group; - char *deprecated; - char *metric_constraint; -}; - -#define ADD_EVENT_FIELD(field) do { if (je->field) { \ - es->field =3D strdup(je->field); \ - if (!es->field) \ - goto out_free; \ -} } while (0) - -#define FREE_EVENT_FIELD(field) free(es->field) - -#define TRY_FIXUP_FIELD(field) do { if (es->field && !je->field) {\ - je->field =3D strdup(es->field); \ - if (!je->field) \ - return -ENOMEM; \ -} } while (0) - -#define FOR_ALL_EVENT_STRUCT_FIELDS(op) do { \ - op(name); \ - op(event); \ - op(desc); \ - op(long_desc); \ - op(pmu); \ - op(unit); \ - op(perpkg); \ - op(aggr_mode); \ - op(metric_expr); \ - op(metric_name); \ - op(metric_group); \ - op(deprecated); \ -} while (0) - -static LIST_HEAD(arch_std_events); - -static void free_arch_std_events(void) -{ - struct event_struct *es, *next; - - list_for_each_entry_safe(es, next, &arch_std_events, list) { - FOR_ALL_EVENT_STRUCT_FIELDS(FREE_EVENT_FIELD); - list_del_init(&es->list); - free(es); - } -} - -static int save_arch_std_events(void *data __maybe_unused, struct json_eve= nt *je) -{ - struct event_struct *es; - - es =3D malloc(sizeof(*es)); - if (!es) - return -ENOMEM; - memset(es, 0, sizeof(*es)); - FOR_ALL_EVENT_STRUCT_FIELDS(ADD_EVENT_FIELD); - list_add_tail(&es->list, &arch_std_events); - return 0; -out_free: - FOR_ALL_EVENT_STRUCT_FIELDS(FREE_EVENT_FIELD); - free(es); - return -ENOMEM; -} - -static void print_events_table_suffix(FILE *outfp) -{ - fprintf(outfp, "{\n"); - - fprintf(outfp, "\t.name =3D 0,\n"); - fprintf(outfp, "\t.event =3D 0,\n"); - fprintf(outfp, "\t.desc =3D 0,\n"); - - fprintf(outfp, "},\n"); - fprintf(outfp, "};\n"); - close_table =3D 0; -} - -static struct fixed { - const char *name; - const char *event; -} fixed[] =3D { - { "inst_retired.any", "event=3D0xc0,period=3D2000003" }, - { "inst_retired.any_p", "event=3D0xc0,period=3D2000003" }, - { "cpu_clk_unhalted.ref", "event=3D0x0,umask=3D0x03,period=3D2000003" }, - { "cpu_clk_unhalted.thread", "event=3D0x3c,period=3D2000003" }, - { "cpu_clk_unhalted.core", "event=3D0x3c,period=3D2000003" }, - { "cpu_clk_unhalted.thread_any", "event=3D0x3c,any=3D1,period=3D2000003" = }, - { NULL, NULL}, -}; - -/* - * Handle different fixed counter encodings between JSON and perf. - */ -static char *real_event(const char *name, char *event) -{ - int i; - - if (!name) - return NULL; - - for (i =3D 0; fixed[i].name; i++) - if (!strcasecmp(name, fixed[i].name)) - return (char *)fixed[i].event; - return event; -} - -static int -try_fixup(const char *fn, char *arch_std, struct json_event *je, char **ev= ent) -{ - /* try to find matching event from arch standard values */ - struct event_struct *es; - - list_for_each_entry(es, &arch_std_events, list) { - if (!strcmp(arch_std, es->name)) { - FOR_ALL_EVENT_STRUCT_FIELDS(TRY_FIXUP_FIELD); - *event =3D je->event; - return 0; - } - } - - pr_err("%s: could not find matching %s for %s\n", - prog, arch_std, fn); - return -1; -} - -/* Call func with each event in the json file */ -static int json_events(const char *fn, - int (*func)(void *data, struct json_event *je), - void *data) -{ - int err; - size_t size; - jsmntok_t *tokens, *tok; - int i, j, len; - char *map; - char buf[128]; - - if (!fn) - return -ENOENT; - - tokens =3D parse_json(fn, &map, &size, &len); - if (!tokens) - return -EIO; - EXPECT(tokens->type =3D=3D JSMN_ARRAY, tokens, "expected top level array"= ); - tok =3D tokens + 1; - for (i =3D 0; i < tokens->size; i++) { - char *event =3D NULL; - char *extra_desc =3D NULL; - char *filter =3D NULL; - struct json_event je =3D {}; - char *arch_std =3D NULL; - unsigned long long eventcode =3D 0; - unsigned long long configcode =3D 0; - struct msrmap *msr =3D NULL; - jsmntok_t *msrval =3D NULL; - jsmntok_t *precise =3D NULL; - jsmntok_t *obj =3D tok++; - bool configcode_present =3D false; - char *umask =3D NULL; - char *cmask =3D NULL; - char *inv =3D NULL; - char *any =3D NULL; - char *edge =3D NULL; - char *period =3D NULL; - char *fc_mask =3D NULL; - char *ch_mask =3D NULL; - - EXPECT(obj->type =3D=3D JSMN_OBJECT, obj, "expected object"); - for (j =3D 0; j < obj->size; j +=3D 2) { - jsmntok_t *field, *val; - int nz; - char *s; - - field =3D tok + j; - EXPECT(field->type =3D=3D JSMN_STRING, tok + j, - "Expected field name"); - val =3D tok + j + 1; - EXPECT(val->type =3D=3D JSMN_STRING, tok + j + 1, - "Expected string value"); - - nz =3D !json_streq(map, val, "0"); - /* match_field */ - if (json_streq(map, field, "UMask") && nz) { - addfield(map, &umask, "", "umask=3D", val); - } else if (json_streq(map, field, "CounterMask") && nz) { - addfield(map, &cmask, "", "cmask=3D", val); - } else if (json_streq(map, field, "Invert") && nz) { - addfield(map, &inv, "", "inv=3D", val); - } else if (json_streq(map, field, "AnyThread") && nz) { - addfield(map, &any, "", "any=3D", val); - } else if (json_streq(map, field, "EdgeDetect") && nz) { - addfield(map, &edge, "", "edge=3D", val); - } else if (json_streq(map, field, "SampleAfterValue") && nz) { - addfield(map, &period, "", "period=3D", val); - } else if (json_streq(map, field, "FCMask") && nz) { - addfield(map, &fc_mask, "", "fc_mask=3D", val); - } else if (json_streq(map, field, "PortMask") && nz) { - addfield(map, &ch_mask, "", "ch_mask=3D", val); - } else if (json_streq(map, field, "EventCode")) { - char *code =3D NULL; - addfield(map, &code, "", "", val); - eventcode |=3D strtoul(code, NULL, 0); - free(code); - } else if (json_streq(map, field, "ConfigCode")) { - char *code =3D NULL; - addfield(map, &code, "", "", val); - configcode |=3D strtoul(code, NULL, 0); - free(code); - configcode_present =3D true; - } else if (json_streq(map, field, "ExtSel")) { - char *code =3D NULL; - addfield(map, &code, "", "", val); - eventcode |=3D strtoul(code, NULL, 0) << 21; - free(code); - } else if (json_streq(map, field, "EventName")) { - addfield(map, &je.name, "", "", val); - } else if (json_streq(map, field, "Compat")) { - addfield(map, &je.compat, "", "", val); - } else if (json_streq(map, field, "BriefDescription")) { - addfield(map, &je.desc, "", "", val); - fixdesc(je.desc); - } else if (json_streq(map, field, - "PublicDescription")) { - addfield(map, &je.long_desc, "", "", val); - fixdesc(je.long_desc); - } else if (json_streq(map, field, "PEBS") && nz) { - precise =3D val; - } else if (json_streq(map, field, "MSRIndex") && nz) { - msr =3D lookup_msr(map, val); - } else if (json_streq(map, field, "MSRValue")) { - msrval =3D val; - } else if (json_streq(map, field, "Errata") && - !json_streq(map, val, "null")) { - addfield(map, &extra_desc, ". ", - " Spec update: ", val); - } else if (json_streq(map, field, "Data_LA") && nz) { - addfield(map, &extra_desc, ". ", - " Supports address when precise", - NULL); - } else if (json_streq(map, field, "Unit")) { - const char *ppmu; - - ppmu =3D field_to_perf(unit_to_pmu, map, val); - if (ppmu) { - je.pmu =3D strdup(ppmu); - } else { - if (!je.pmu) - je.pmu =3D strdup("uncore_"); - addfield(map, &je.pmu, "", "", val); - for (s =3D je.pmu; *s; s++) - *s =3D tolower(*s); - } - } else if (json_streq(map, field, "Filter")) { - addfield(map, &filter, "", "", val); - } else if (json_streq(map, field, "ScaleUnit")) { - addfield(map, &je.unit, "", "", val); - } else if (json_streq(map, field, "PerPkg")) { - addfield(map, &je.perpkg, "", "", val); - } else if (json_streq(map, field, "AggregationMode")) { - addfield(map, &je.aggr_mode, "", "", val); - } else if (json_streq(map, field, "Deprecated")) { - addfield(map, &je.deprecated, "", "", val); - } else if (json_streq(map, field, "MetricName")) { - addfield(map, &je.metric_name, "", "", val); - } else if (json_streq(map, field, "MetricGroup")) { - addfield(map, &je.metric_group, "", "", val); - } else if (json_streq(map, field, "MetricConstraint")) { - addfield(map, &je.metric_constraint, "", "", val); - } else if (json_streq(map, field, "MetricExpr")) { - addfield(map, &je.metric_expr, "", "", val); - } else if (json_streq(map, field, "ArchStdEvent")) { - addfield(map, &arch_std, "", "", val); - for (s =3D arch_std; *s; s++) - *s =3D tolower(*s); - } - /* ignore unknown fields */ - } - if (precise && je.desc && !strstr(je.desc, "(Precise Event)")) { - if (json_streq(map, precise, "2")) - addfield(map, &extra_desc, " ", - "(Must be precise)", NULL); - else - addfield(map, &extra_desc, " ", - "(Precise event)", NULL); - } - if (configcode_present) - snprintf(buf, sizeof buf, "config=3D%#llx", configcode); - else - snprintf(buf, sizeof buf, "event=3D%#llx", eventcode); - addfield(map, &event, ",", buf, NULL); - if (any) - addfield(map, &event, ",", any, NULL); - if (ch_mask) - addfield(map, &event, ",", ch_mask, NULL); - if (cmask) - addfield(map, &event, ",", cmask, NULL); - if (edge) - addfield(map, &event, ",", edge, NULL); - if (fc_mask) - addfield(map, &event, ",", fc_mask, NULL); - if (inv) - addfield(map, &event, ",", inv, NULL); - if (period) - addfield(map, &event, ",", period, NULL); - if (umask) - addfield(map, &event, ",", umask, NULL); - - if (je.desc && extra_desc) - addfield(map, &je.desc, " ", extra_desc, NULL); - if (je.long_desc && extra_desc) - addfield(map, &je.long_desc, " ", extra_desc, NULL); - if (je.pmu) { - addfield(map, &je.desc, ". ", "Unit: ", NULL); - addfield(map, &je.desc, "", je.pmu, NULL); - addfield(map, &je.desc, "", " ", NULL); - } - if (filter) - addfield(map, &event, ",", filter, NULL); - if (msr !=3D NULL) - addfield(map, &event, ",", msr->pname, msrval); - if (je.name) - fixname(je.name); - - if (arch_std) { - /* - * An arch standard event is referenced, so try to - * fixup any unassigned values. - */ - err =3D try_fixup(fn, arch_std, &je, &event); - if (err) - goto free_strings; - } - je.event =3D real_event(je.name, event); - err =3D func(data, &je); -free_strings: - free(umask); - free(cmask); - free(inv); - free(any); - free(edge); - free(period); - free(fc_mask); - free(ch_mask); - free(event); - free(je.desc); - free(je.name); - free(je.compat); - free(je.long_desc); - free(extra_desc); - free(je.pmu); - free(filter); - free(je.perpkg); - free(je.aggr_mode); - free(je.deprecated); - free(je.unit); - free(je.metric_expr); - free(je.metric_name); - free(je.metric_group); - free(je.metric_constraint); - free(arch_std); - - if (err) - break; - tok +=3D j; - } - EXPECT(tok - tokens =3D=3D len, tok, "unexpected objects at end"); - err =3D 0; -out_free: - free_json(map, size, tokens); - return err; -} - -static char *file_name_to_table_name(char *fname) -{ - unsigned int i; - int n; - int c; - char *tblname; - - /* - * Ensure tablename starts with alphabetic character. - * Derive rest of table name from basename of the JSON file, - * replacing hyphens and stripping out .json suffix. - */ - n =3D asprintf(&tblname, "pme_%s", fname); - if (n < 0) { - pr_info("%s: asprintf() error %s for file %s\n", prog, - strerror(errno), fname); - return NULL; - } - - for (i =3D 0; i < strlen(tblname); i++) { - c =3D tblname[i]; - - if (c =3D=3D '-' || c =3D=3D '/') - tblname[i] =3D '_'; - else if (c =3D=3D '.') { - tblname[i] =3D '\0'; - break; - } else if (!isalnum(c) && c !=3D '_') { - pr_err("%s: Invalid character '%c' in file name %s\n", - prog, c, basename(fname)); - free(tblname); - tblname =3D NULL; - break; - } - } - - return tblname; -} - -static bool is_sys_dir(char *fname) -{ - size_t len =3D strlen(fname), len2 =3D strlen("/sys"); - - if (len2 > len) - return false; - return !strcmp(fname+len-len2, "/sys"); -} - -static void print_mapping_table_prefix(FILE *outfp) -{ - fprintf(outfp, "const struct pmu_events_map pmu_events_map[] =3D {\n"); -} - -static void print_mapping_table_suffix(FILE *outfp) -{ - /* - * Print the terminating, NULL entry. - */ - fprintf(outfp, "{\n"); - fprintf(outfp, "\t.cpuid =3D 0,\n"); - fprintf(outfp, "\t.version =3D 0,\n"); - fprintf(outfp, "\t.type =3D 0,\n"); - fprintf(outfp, "\t.table =3D 0,\n"); - fprintf(outfp, "},\n"); - - /* and finally, the closing curly bracket for the struct */ - fprintf(outfp, "};\n"); -} - -static void print_mapping_test_table(FILE *outfp) -{ - /* - * Print the terminating, NULL entry. - */ - fprintf(outfp, "{\n"); - fprintf(outfp, "\t.cpuid =3D \"testcpu\",\n"); - fprintf(outfp, "\t.version =3D \"v1\",\n"); - fprintf(outfp, "\t.type =3D \"core\",\n"); - fprintf(outfp, "\t.table =3D pme_test_soc_cpu,\n"); - fprintf(outfp, "},\n"); -} - -static void print_system_event_mapping_table_prefix(FILE *outfp) -{ - fprintf(outfp, "\nconst struct pmu_sys_events pmu_sys_event_tables[] =3D = {"); -} - -static void print_system_event_mapping_table_suffix(FILE *outfp) -{ - fprintf(outfp, "\n\t{\n\t\t.table =3D 0\n\t},"); - fprintf(outfp, "\n};\n"); -} - -static int process_system_event_tables(FILE *outfp) -{ - struct sys_event_table *sys_event_table; - - print_system_event_mapping_table_prefix(outfp); - - list_for_each_entry(sys_event_table, &sys_event_tables, list) { - fprintf(outfp, "\n\t{\n\t\t.table =3D %s,\n\t\t.name =3D \"%s\",\n\t},", - sys_event_table->soc_id, - sys_event_table->soc_id); - } - - print_system_event_mapping_table_suffix(outfp); - - return 0; -} - -static int process_mapfile(FILE *outfp, char *fpath) -{ - int n =3D 16384; - FILE *mapfp; - char *save =3D NULL; - char *line, *p; - int line_num; - char *tblname; - int ret =3D 0; - - pr_info("%s: Processing mapfile %s\n", prog, fpath); - - line =3D malloc(n); - if (!line) - return -1; - - mapfp =3D fopen(fpath, "r"); - if (!mapfp) { - pr_info("%s: Error %s opening %s\n", prog, strerror(errno), - fpath); - free(line); - return -1; - } - - print_mapping_table_prefix(outfp); - - /* Skip first line (header) */ - p =3D fgets(line, n, mapfp); - if (!p) - goto out; - - line_num =3D 1; - while (1) { - char *cpuid, *version, *type, *fname; - - line_num++; - p =3D fgets(line, n, mapfp); - if (!p) - break; - - if (line[0] =3D=3D '#' || line[0] =3D=3D '\n') - continue; - - if (line[strlen(line)-1] !=3D '\n') { - /* TODO Deal with lines longer than 16K */ - pr_info("%s: Mapfile %s: line %d too long, aborting\n", - prog, fpath, line_num); - ret =3D -1; - goto out; - } - line[strlen(line)-1] =3D '\0'; - - cpuid =3D fixregex(strtok_r(p, ",", &save)); - version =3D strtok_r(NULL, ",", &save); - fname =3D strtok_r(NULL, ",", &save); - type =3D strtok_r(NULL, ",", &save); - - tblname =3D file_name_to_table_name(fname); - fprintf(outfp, "{\n"); - fprintf(outfp, "\t.cpuid =3D \"%s\",\n", cpuid); - fprintf(outfp, "\t.version =3D \"%s\",\n", version); - fprintf(outfp, "\t.type =3D \"%s\",\n", type); - - /* - * CHECK: We can't use the type (eg "core") field in the - * table name. For us to do that, we need to somehow tweak - * the other caller of file_name_to_table(), process_json() - * to determine the type. process_json() file has no way - * of knowing these are "core" events unless file name has - * core in it. If filename has core in it, we can safely - * ignore the type field here also. - */ - fprintf(outfp, "\t.table =3D %s\n", tblname); - fprintf(outfp, "},\n"); - } - -out: - print_mapping_test_table(outfp); - print_mapping_table_suffix(outfp); - fclose(mapfp); - free(line); - return ret; -} - -/* - * If we fail to locate/process JSON and map files, create a NULL mapping - * table. This would at least allow perf to build even if we can't find/use - * the aliases. - */ -static void create_empty_mapping(const char *output_file) -{ - FILE *outfp; - - pr_info("%s: Creating empty pmu_events_map[] table\n", prog); - - /* Truncate file to clear any partial writes to it */ - outfp =3D fopen(output_file, "w"); - if (!outfp) { - perror("fopen()"); - _Exit(1); - } - - fprintf(outfp, "#include \"pmu-events/pmu-events.h\"\n"); - print_mapping_table_prefix(outfp); - print_mapping_table_suffix(outfp); - print_system_event_mapping_table_prefix(outfp); - print_system_event_mapping_table_suffix(outfp); - fclose(outfp); -} - -static int get_maxfds(void) -{ - struct rlimit rlim; - - if (getrlimit(RLIMIT_NOFILE, &rlim) =3D=3D 0) - return min(rlim.rlim_max / 2, (rlim_t)512); - - return 512; -} - -/* - * nftw() doesn't let us pass an argument to the processing function, - * so use a global variables. - */ -static FILE *eventsfp; -static char *mapfile; - -static int is_leaf_dir(const char *fpath) -{ - DIR *d; - struct dirent *dir; - int res =3D 1; - - d =3D opendir(fpath); - if (!d) - return 0; - - while ((dir =3D readdir(d)) !=3D NULL) { - if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) - continue; - - if (dir->d_type =3D=3D DT_DIR) { - res =3D 0; - break; - } else if (dir->d_type =3D=3D DT_UNKNOWN) { - char path[PATH_MAX]; - struct stat st; - - sprintf(path, "%s/%s", fpath, dir->d_name); - if (stat(path, &st)) - break; - - if (S_ISDIR(st.st_mode)) { - res =3D 0; - break; - } - } - } - - closedir(d); - - return res; -} - -static int is_json_file(const char *name) -{ - const char *suffix; - - if (strlen(name) < 5) - return 0; - - suffix =3D name + strlen(name) - 5; - - if (strncmp(suffix, ".json", 5) =3D=3D 0) - return 1; - return 0; -} - -static int preprocess_arch_std_files(const char *fpath, const struct stat = *sb, - int typeflag, struct FTW *ftwbuf) -{ - int level =3D ftwbuf->level; - int is_file =3D typeflag =3D=3D FTW_F; - - if (level =3D=3D 1 && is_file && is_json_file(fpath)) - return json_events(fpath, save_arch_std_events, (void *)sb); - - return 0; -} - -static int process_one_file(const char *fpath, const struct stat *sb, - int typeflag, struct FTW *ftwbuf) -{ - char *tblname, *bname; - int is_dir =3D typeflag =3D=3D FTW_D; - int is_file =3D typeflag =3D=3D FTW_F; - int level =3D ftwbuf->level; - int err =3D 0; - - if (level >=3D 2 && is_dir) { - int count =3D 0; - /* - * For level 2 directory, bname will include parent name, - * like vendor/platform. So search back from platform dir - * to find this. - * Something similar for level 3 directory, but we're a PMU - * category folder, like vendor/platform/cpu. - */ - bname =3D (char *) fpath + ftwbuf->base - 2; - for (;;) { - if (*bname =3D=3D '/') - count++; - if (count =3D=3D level - 1) - break; - bname--; - } - bname++; - } else - bname =3D (char *) fpath + ftwbuf->base; - - pr_debug("%s %d %7jd %-20s %s\n", - is_file ? "f" : is_dir ? "d" : "x", - level, sb->st_size, bname, fpath); - - /* base dir or too deep */ - if (level =3D=3D 0 || level > 4) - return 0; - - - /* model directory, reset topic */ - if ((level =3D=3D 1 && is_dir && is_leaf_dir(fpath)) || - (level >=3D 2 && is_dir && is_leaf_dir(fpath))) { - if (close_table) - print_events_table_suffix(eventsfp); - - /* - * Drop file name suffix. Replace hyphens with underscores. - * Fail if file name contains any alphanum characters besides - * underscores. - */ - tblname =3D file_name_to_table_name(bname); - if (!tblname) { - pr_info("%s: Error determining table name for %s\n", prog, - bname); - return -1; - } - - if (is_sys_dir(bname)) { - struct sys_event_table *sys_event_table; - - sys_event_table =3D malloc(sizeof(*sys_event_table)); - if (!sys_event_table) - return -1; - - sys_event_table->soc_id =3D strdup(tblname); - if (!sys_event_table->soc_id) { - free(sys_event_table); - return -1; - } - list_add_tail(&sys_event_table->list, - &sys_event_tables); - } - - print_events_table_prefix(eventsfp, tblname); - return 0; - } - - /* - * Save the mapfile name for now. We will process mapfile - * after processing all JSON files (so we can write out the - * mapping table after all PMU events tables). - * - */ - if (level =3D=3D 1 && is_file) { - if (!strcmp(bname, "mapfile.csv")) { - mapfile =3D strdup(fpath); - return 0; - } - if (is_json_file(bname)) - pr_debug("%s: ArchStd json is preprocessed %s\n", prog, fpath); - else - pr_info("%s: Ignoring file %s\n", prog, fpath); - return 0; - } - - /* - * If the file name does not have a .json extension, - * ignore it. It could be a readme.txt for instance. - */ - if (is_file) { - if (!is_json_file(bname)) { - pr_info("%s: Ignoring file without .json suffix %s\n", prog, - fpath); - return 0; - } - } - - if (level > 1 && add_topic(bname)) - return -ENOMEM; - - /* - * Assume all other files are JSON files. - * - * If mapfile refers to 'power7_core.json', we create a table - * named 'power7_core'. Any inconsistencies between the mapfile - * and directory tree could result in build failure due to table - * names not being found. - * - * At least for now, be strict with processing JSON file names. - * i.e. if JSON file name cannot be mapped to C-style table name, - * fail. - */ - if (is_file) { - struct perf_entry_data data =3D { - .topic =3D get_topic(), - .outfp =3D eventsfp, - }; - - err =3D json_events(fpath, print_events_table_entry, &data); - - free(data.topic); - } - - return err; -} - -#ifndef PATH_MAX -#define PATH_MAX 4096 -#endif - -/* - * Starting in directory 'start_dirname', find the "mapfile.csv" and - * the set of JSON files for the architecture 'arch'. - * - * From each JSON file, create a C-style "PMU events table" from the - * JSON file (see struct pmu_event). - * - * From the mapfile, create a mapping between the CPU revisions and - * PMU event tables (see struct pmu_events_map). - * - * Write out the PMU events tables and the mapping table to pmu-event.c. - */ -int main(int argc, char *argv[]) -{ - int rc, ret =3D 0, empty_map =3D 0; - int maxfds; - char ldirname[PATH_MAX]; - const char *arch; - const char *output_file; - const char *start_dirname; - const char *err_string_ext =3D ""; - struct stat stbuf; - - prog =3D basename(argv[0]); - if (argc < 4) { - pr_err("Usage: %s \n", prog); - return 1; - } - - arch =3D argv[1]; - start_dirname =3D argv[2]; - output_file =3D argv[3]; - - if (argc > 4) - verbose =3D atoi(argv[4]); - - eventsfp =3D fopen(output_file, "w"); - if (!eventsfp) { - pr_err("%s Unable to create required file %s (%s)\n", - prog, output_file, strerror(errno)); - return 2; - } - - sprintf(ldirname, "%s/%s", start_dirname, arch); - - /* If architecture does not have any event lists, bail out */ - if (stat(ldirname, &stbuf) < 0) { - pr_info("%s: Arch %s has no PMU event lists\n", prog, arch); - empty_map =3D 1; - goto err_close_eventsfp; - } - - /* Include pmu-events.h first */ - fprintf(eventsfp, "#include \"pmu-events/pmu-events.h\"\n"); - - /* - * The mapfile allows multiple CPUids to point to the same JSON file, - * so, not sure if there is a need for symlinks within the pmu-events - * directory. - * - * For now, treat symlinks of JSON files as regular files and create - * separate tables for each symlink (presumably, each symlink refers - * to specific version of the CPU). - */ - - maxfds =3D get_maxfds(); - rc =3D nftw(ldirname, preprocess_arch_std_files, maxfds, 0); - if (rc) - goto err_processing_std_arch_event_dir; - - rc =3D nftw(ldirname, process_one_file, maxfds, 0); - if (rc) - goto err_processing_dir; - - sprintf(ldirname, "%s/test", start_dirname); - - rc =3D nftw(ldirname, preprocess_arch_std_files, maxfds, 0); - if (rc) - goto err_processing_std_arch_event_dir; - - rc =3D nftw(ldirname, process_one_file, maxfds, 0); - if (rc) - goto err_processing_dir; - - if (close_table) - print_events_table_suffix(eventsfp); - - if (!mapfile) { - pr_info("%s: No CPU->JSON mapping?\n", prog); - empty_map =3D 1; - goto err_close_eventsfp; - } - - rc =3D process_mapfile(eventsfp, mapfile); - if (rc) { - pr_info("%s: Error processing mapfile %s\n", prog, mapfile); - /* Make build fail */ - ret =3D 1; - goto err_close_eventsfp; - } - - rc =3D process_system_event_tables(eventsfp); - fclose(eventsfp); - if (rc) { - ret =3D 1; - goto err_out; - } - - free_arch_std_events(); - free_sys_event_tables(); - free(mapfile); - return 0; - -err_processing_std_arch_event_dir: - err_string_ext =3D " for std arch event"; -err_processing_dir: - if (verbose) { - pr_info("%s: Error walking file tree %s%s\n", prog, ldirname, - err_string_ext); - empty_map =3D 1; - } else if (rc < 0) { - ret =3D 1; - } else { - empty_map =3D 1; - } -err_close_eventsfp: - fclose(eventsfp); - if (empty_map) - create_empty_mapping(output_file); -err_out: - free_arch_std_events(); - free_sys_event_tables(); - free(mapfile); - return ret; -} diff --git a/tools/perf/pmu-events/jsmn.h b/tools/perf/pmu-events/jsmn.h deleted file mode 100644 index 1bdfd55fff30..000000000000 --- a/tools/perf/pmu-events/jsmn.h +++ /dev/null @@ -1,68 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -#ifndef __JSMN_H_ -#define __JSMN_H_ - -/* - * JSON type identifier. Basic types are: - * o Object - * o Array - * o String - * o Other primitive: number, boolean (true/false) or null - */ -typedef enum { - JSMN_PRIMITIVE =3D 0, - JSMN_OBJECT =3D 1, - JSMN_ARRAY =3D 2, - JSMN_STRING =3D 3 -} jsmntype_t; - -typedef enum { - /* Not enough tokens were provided */ - JSMN_ERROR_NOMEM =3D -1, - /* Invalid character inside JSON string */ - JSMN_ERROR_INVAL =3D -2, - /* The string is not a full JSON packet, more bytes expected */ - JSMN_ERROR_PART =3D -3, - /* Everything was fine */ - JSMN_SUCCESS =3D 0 -} jsmnerr_t; - -/* - * JSON token description. - * @param type type (object, array, string etc.) - * @param start start position in JSON data string - * @param end end position in JSON data string - */ -typedef struct { - jsmntype_t type; - int start; - int end; - int size; -} jsmntok_t; - -/* - * JSON parser. Contains an array of token blocks available. Also stores - * the string being parsed now and current position in that string - */ -typedef struct { - unsigned int pos; /* offset in the JSON string */ - int toknext; /* next token to allocate */ - int toksuper; /* superior token node, e.g parent object or array */ -} jsmn_parser; - -/* - * Create JSON parser over an array of tokens - */ -void jsmn_init(jsmn_parser *parser); - -/* - * Run JSON parser. It parses a JSON data string into and array of tokens, - * each describing a single JSON object. - */ -jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, - size_t len, - jsmntok_t *tokens, unsigned int num_tokens); - -const char *jsmn_strerror(jsmnerr_t err); - -#endif /* __JSMN_H_ */ diff --git a/tools/perf/pmu-events/json.c b/tools/perf/pmu-events/json.c deleted file mode 100644 index 0544398d6e2d..000000000000 --- a/tools/perf/pmu-events/json.c +++ /dev/null @@ -1,162 +0,0 @@ -/* Parse JSON files using the JSMN parser. */ - -/* - * Copyright (c) 2014, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are = met: - * - * 1. Redistributions of source code must retain the above copyright notic= e, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "jsmn.h" -#include "json.h" -#include - - -static char *mapfile(const char *fn, size_t *size) -{ - unsigned ps =3D sysconf(_SC_PAGESIZE); - struct stat st; - char *map =3D NULL; - int err; - int fd =3D open(fn, O_RDONLY); - - if (fd < 0 && verbose > 0 && fn) { - pr_err("Error opening events file '%s': %s\n", fn, - strerror(errno)); - } - - if (fd < 0) - return NULL; - err =3D fstat(fd, &st); - if (err < 0) - goto out; - *size =3D st.st_size; - map =3D mmap(NULL, - (st.st_size + ps - 1) & ~(ps - 1), - PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); - if (map =3D=3D MAP_FAILED) - map =3D NULL; -out: - close(fd); - return map; -} - -static void unmapfile(char *map, size_t size) -{ - unsigned ps =3D sysconf(_SC_PAGESIZE); - munmap(map, roundup(size, ps)); -} - -/* - * Parse json file using jsmn. Return array of tokens, - * and mapped file. Caller needs to free array. - */ -jsmntok_t *parse_json(const char *fn, char **map, size_t *size, int *len) -{ - jsmn_parser parser; - jsmntok_t *tokens; - jsmnerr_t res; - unsigned sz; - - *map =3D mapfile(fn, size); - if (!*map) - return NULL; - /* Heuristic */ - sz =3D *size * 16; - tokens =3D malloc(sz); - if (!tokens) - goto error; - jsmn_init(&parser); - res =3D jsmn_parse(&parser, *map, *size, tokens, - sz / sizeof(jsmntok_t)); - if (res !=3D JSMN_SUCCESS) { - pr_err("%s: json error %s\n", fn, jsmn_strerror(res)); - goto error_free; - } - if (len) - *len =3D parser.toknext; - return tokens; -error_free: - free(tokens); -error: - unmapfile(*map, *size); - return NULL; -} - -void free_json(char *map, size_t size, jsmntok_t *tokens) -{ - free(tokens); - unmapfile(map, size); -} - -static int countchar(char *map, char c, int end) -{ - int i; - int count =3D 0; - for (i =3D 0; i < end; i++) - if (map[i] =3D=3D c) - count++; - return count; -} - -/* Return line number of a jsmn token */ -int json_line(char *map, jsmntok_t *t) -{ - return countchar(map, '\n', t->start) + 1; -} - -static const char * const jsmn_types[] =3D { - [JSMN_PRIMITIVE] =3D "primitive", - [JSMN_ARRAY] =3D "array", - [JSMN_OBJECT] =3D "object", - [JSMN_STRING] =3D "string" -}; - -#define LOOKUP(a, i) ((i) < (sizeof(a)/sizeof(*(a))) ? ((a)[i]) : "?") - -/* Return type name of a jsmn token */ -const char *json_name(jsmntok_t *t) -{ - return LOOKUP(jsmn_types, t->type); -} - -int json_len(jsmntok_t *t) -{ - return t->end - t->start; -} - -/* Is string t equal to s? */ -int json_streq(char *map, jsmntok_t *t, const char *s) -{ - unsigned len =3D json_len(t); - return len =3D=3D strlen(s) && !strncasecmp(map + t->start, s, len); -} diff --git a/tools/perf/pmu-events/json.h b/tools/perf/pmu-events/json.h deleted file mode 100644 index fbcd5a0590ad..000000000000 --- a/tools/perf/pmu-events/json.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef JSON_H -#define JSON_H 1 - -#include "jsmn.h" - -jsmntok_t *parse_json(const char *fn, char **map, size_t *size, int *len); -void free_json(char *map, size_t size, jsmntok_t *tokens); -int json_line(char *map, jsmntok_t *t); -const char *json_name(jsmntok_t *t); -int json_streq(char *map, jsmntok_t *t, const char *s); -int json_len(jsmntok_t *t); - -extern int verbose; - -#include - -extern int eprintf(int level, int var, const char *fmt, ...); -#define pr_fmt(fmt) fmt - -#define pr_err(fmt, ...) \ - eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__) - -#define pr_info(fmt, ...) \ - eprintf(1, verbose, pr_fmt(fmt), ##__VA_ARGS__) - -#define pr_debug(fmt, ...) \ - eprintf(2, verbose, pr_fmt(fmt), ##__VA_ARGS__) - -#ifndef roundup -#define roundup(x, y) ( \ -{ \ - const typeof(y) __y =3D y; \ - (((x) + (__y - 1)) / __y) * __y; \ -} \ -) -#endif - -#endif --=20 2.36.0.512.ge40c2bad7a-goog