Skip to content
Snippets Groups Projects
  • Xu Yang's avatar
    5fe7c08e
    perf jevents: fix breakage when do perf stat on system metric · 5fe7c08e
    Xu Yang authored
    
    commit 4a159e6049f319bef6f9e6d2ccdd322f57d24830 upstream.
    
    When do perf stat on sys metric, perf tool output nothing now:
    
      $ perf stat -a -M imx95_ddr_read.all -I 1000
      $
    
    This command runs on an arm64 machine and the Soc has one DDR hw pmu
    except one armv8_cortex_a55 pmu. Their maps show as follows:
    
    const struct pmu_events_map pmu_events_map[] = {
    {
    	.arch = "arm64",
    	.cpuid = "0x00000000410fd050",
    	.event_table = {
    		.pmus = pmu_events__arm_cortex_a55,
    		.num_pmus = ARRAY_SIZE(pmu_events__arm_cortex_a55)
    	},
    	.metric_table = {
    		.pmus = NULL,
    		.num_pmus = 0
    	}
    },
    
    static const struct pmu_sys_events pmu_sys_event_tables[] = {
    {
    	.event_table = {
    		.pmus = pmu_events__freescale_imx95_sys,
    		.num_pmus = ARRAY_SIZE(pmu_events__freescale_imx95_sys)
    	},
    	.metric_table = {
    		.pmus = pmu_metrics__freescale_imx95_sys,
    		.num_pmus = ARRAY_SIZE(pmu_metrics__freescale_imx95_sys)
    	},
    	.name = "pmu_events__freescale_imx95_sys",
    },
    
    Currently, pmu_metrics_table__find() will return NULL when only do perf
    stat on sys metric. Then parse_groups() will never be called to parse
    sys metric_name, finally perf tool will exit directly. This should be a
    common problem.
    
    To fix the issue, this will keep the logic before commit f20c15d1
    ("perf pmu-events: Remember the perf_events_map for a PMU") to return a
    empty metric table rather than a NULL pointer.
    
    This should be fine since the removed part just check if the table match
    provided metric_name.  Without these code, the code in parse_groups()
    will also check the validity of metrci_name too.
    
    Fixes: f20c15d1 ("perf pmu-events: Remember the perf_events_map for a PMU")
    Reviewed-by: default avatarJames Clark <james.clark@linaro.org>
    Signed-off-by: default avatarXu Yang <xu.yang_2@nxp.com>
    Tested-by: default avatarXu Yang <xu.yang_2@nxp.com>
    Acked-by: default avatarIan Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Albert Ou <aou@eecs.berkeley.edu>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Benjamin Gray <bgray@linux.ibm.com>
    Cc: Ben Zong-You Xie <ben717@andestech.com>
    Cc: Bibo Mao <maobibo@loongson.cn>
    Cc: Clément Le Goffic <clement.legoffic@foss.st.com>
    Cc: Dima Kogan <dima@secretsauce.net>
    Cc: Dr. David Alan Gilbert <linux@treblig.org>
    Cc: Huacai Chen <chenhuacai@kernel.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: John Garry <john.g.garry@oracle.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linux.dev>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Mike Leach <mike.leach@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Palmer Dabbelt <palmer@dabbelt.com>
    Cc: Paul Walmsley <paul.walmsley@sifive.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Sandipan Das <sandipan.das@amd.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Yicong Yang <yangyicong@hisilicon.com>
    Cc: linux-arm-kernel@lists.infradead.org
    Cc: linux-riscv@lists.infradead.org
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20241107162035.52206-2-irogers@google.com
    
    
    Signed-off-by: default avatarIan Rogers <irogers@google.com>
    Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    5fe7c08e
    History
    perf jevents: fix breakage when do perf stat on system metric
    Xu Yang authored
    
    commit 4a159e6049f319bef6f9e6d2ccdd322f57d24830 upstream.
    
    When do perf stat on sys metric, perf tool output nothing now:
    
      $ perf stat -a -M imx95_ddr_read.all -I 1000
      $
    
    This command runs on an arm64 machine and the Soc has one DDR hw pmu
    except one armv8_cortex_a55 pmu. Their maps show as follows:
    
    const struct pmu_events_map pmu_events_map[] = {
    {
    	.arch = "arm64",
    	.cpuid = "0x00000000410fd050",
    	.event_table = {
    		.pmus = pmu_events__arm_cortex_a55,
    		.num_pmus = ARRAY_SIZE(pmu_events__arm_cortex_a55)
    	},
    	.metric_table = {
    		.pmus = NULL,
    		.num_pmus = 0
    	}
    },
    
    static const struct pmu_sys_events pmu_sys_event_tables[] = {
    {
    	.event_table = {
    		.pmus = pmu_events__freescale_imx95_sys,
    		.num_pmus = ARRAY_SIZE(pmu_events__freescale_imx95_sys)
    	},
    	.metric_table = {
    		.pmus = pmu_metrics__freescale_imx95_sys,
    		.num_pmus = ARRAY_SIZE(pmu_metrics__freescale_imx95_sys)
    	},
    	.name = "pmu_events__freescale_imx95_sys",
    },
    
    Currently, pmu_metrics_table__find() will return NULL when only do perf
    stat on sys metric. Then parse_groups() will never be called to parse
    sys metric_name, finally perf tool will exit directly. This should be a
    common problem.
    
    To fix the issue, this will keep the logic before commit f20c15d1
    ("perf pmu-events: Remember the perf_events_map for a PMU") to return a
    empty metric table rather than a NULL pointer.
    
    This should be fine since the removed part just check if the table match
    provided metric_name.  Without these code, the code in parse_groups()
    will also check the validity of metrci_name too.
    
    Fixes: f20c15d1 ("perf pmu-events: Remember the perf_events_map for a PMU")
    Reviewed-by: default avatarJames Clark <james.clark@linaro.org>
    Signed-off-by: default avatarXu Yang <xu.yang_2@nxp.com>
    Tested-by: default avatarXu Yang <xu.yang_2@nxp.com>
    Acked-by: default avatarIan Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Albert Ou <aou@eecs.berkeley.edu>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Benjamin Gray <bgray@linux.ibm.com>
    Cc: Ben Zong-You Xie <ben717@andestech.com>
    Cc: Bibo Mao <maobibo@loongson.cn>
    Cc: Clément Le Goffic <clement.legoffic@foss.st.com>
    Cc: Dima Kogan <dima@secretsauce.net>
    Cc: Dr. David Alan Gilbert <linux@treblig.org>
    Cc: Huacai Chen <chenhuacai@kernel.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: John Garry <john.g.garry@oracle.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linux.dev>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Mike Leach <mike.leach@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Palmer Dabbelt <palmer@dabbelt.com>
    Cc: Paul Walmsley <paul.walmsley@sifive.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Sandipan Das <sandipan.das@amd.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Yicong Yang <yangyicong@hisilicon.com>
    Cc: linux-arm-kernel@lists.infradead.org
    Cc: linux-riscv@lists.infradead.org
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20241107162035.52206-2-irogers@google.com
    
    
    Signed-off-by: default avatarIan Rogers <irogers@google.com>
    Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>