Re: [PATCH] tools/power turbostat: Allow execution to continue after perf_l2_init() failure

From: Len Brown

Date: Thu Apr 09 2026 - 15:13:54 EST


Hmm, the check of perf_model_support covers unknown CPUs.
(and this code runs fine on my Alderlake)

So the failure you see must be from the kernel perf support failing?
What is the kernel config?

thanks,
-Len

On Thu, Mar 19, 2026 at 10:04 AM David Arcari <darcari@xxxxxxxxxx> wrote:
>
> Currently, if perf_l2_init() fails turbostat exits after issuing the
> following error (which was encountered on AlderLake):
>
> turbostat: perf_l2_init(cpu0, 0x0, 0xff24) REFS: Invalid argument
>
> This occurs because perf_l2_init() calls err(). However, the code has been
> written in such a manner that it is able to perform cleanup and continue.
> Therefore, this issue can be addressed by changing the appropriate calls
> to err() to warnx().
>
> Additionally, correct the PMU type arguments passed to the warning strings
> in the ecore and lcore blocks so the logs accurately reflect the failing
> counter type.
>
> Signed-off-by: David Arcari <darcari@xxxxxxxxxx>
> Cc: Len Brown <lenb@xxxxxxxxxx>
> Cc: linux-pm@xxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> ---
> tools/power/x86/turbostat/turbostat.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
> index 1a2671c28209..f1b8059a4eec 100644
> --- a/tools/power/x86/turbostat/turbostat.c
> +++ b/tools/power/x86/turbostat/turbostat.c
> @@ -9403,13 +9403,13 @@ void perf_l2_init(void)
> if (!is_hybrid) {
> fd_l2_percpu[cpu] = open_perf_counter(cpu, perf_pmu_types.uniform, perf_model_support->first.refs, -1, PERF_FORMAT_GROUP);
> if (fd_l2_percpu[cpu] == -1) {
> - err(-1, "%s(cpu%d, 0x%x, 0x%llx) REFS", __func__, cpu, perf_pmu_types.uniform, perf_model_support->first.refs);
> + warnx("%s(cpu%d, 0x%x, 0x%llx) REFS", __func__, cpu, perf_pmu_types.uniform, perf_model_support->first.refs);
> free_fd_l2_percpu();
> return;
> }
> retval = open_perf_counter(cpu, perf_pmu_types.uniform, perf_model_support->first.hits, fd_l2_percpu[cpu], PERF_FORMAT_GROUP);
> if (retval == -1) {
> - err(-1, "%s(cpu%d, 0x%x, 0x%llx) HITS", __func__, cpu, perf_pmu_types.uniform, perf_model_support->first.hits);
> + warnx("%s(cpu%d, 0x%x, 0x%llx) HITS", __func__, cpu, perf_pmu_types.uniform, perf_model_support->first.hits);
> free_fd_l2_percpu();
> return;
> }
> @@ -9418,39 +9418,39 @@ void perf_l2_init(void)
> if (perf_pcore_set && CPU_ISSET_S(cpu, cpu_possible_setsize, perf_pcore_set)) {
> fd_l2_percpu[cpu] = open_perf_counter(cpu, perf_pmu_types.pcore, perf_model_support->first.refs, -1, PERF_FORMAT_GROUP);
> if (fd_l2_percpu[cpu] == -1) {
> - err(-1, "%s(cpu%d, 0x%x, 0x%llx) REFS", __func__, cpu, perf_pmu_types.pcore, perf_model_support->first.refs);
> + warnx("%s(cpu%d, 0x%x, 0x%llx) REFS", __func__, cpu, perf_pmu_types.pcore, perf_model_support->first.refs);
> free_fd_l2_percpu();
> return;
> }
> retval = open_perf_counter(cpu, perf_pmu_types.pcore, perf_model_support->first.hits, fd_l2_percpu[cpu], PERF_FORMAT_GROUP);
> if (retval == -1) {
> - err(-1, "%s(cpu%d, 0x%x, 0x%llx) HITS", __func__, cpu, perf_pmu_types.pcore, perf_model_support->first.hits);
> + warnx("%s(cpu%d, 0x%x, 0x%llx) HITS", __func__, cpu, perf_pmu_types.pcore, perf_model_support->first.hits);
> free_fd_l2_percpu();
> return;
> }
> } else if (perf_ecore_set && CPU_ISSET_S(cpu, cpu_possible_setsize, perf_ecore_set)) {
> fd_l2_percpu[cpu] = open_perf_counter(cpu, perf_pmu_types.ecore, perf_model_support->second.refs, -1, PERF_FORMAT_GROUP);
> if (fd_l2_percpu[cpu] == -1) {
> - err(-1, "%s(cpu%d, 0x%x, 0x%llx) REFS", __func__, cpu, perf_pmu_types.pcore, perf_model_support->second.refs);
> + warnx("%s(cpu%d, 0x%x, 0x%llx) REFS", __func__, cpu, perf_pmu_types.ecore, perf_model_support->second.refs);
> free_fd_l2_percpu();
> return;
> }
> retval = open_perf_counter(cpu, perf_pmu_types.ecore, perf_model_support->second.hits, fd_l2_percpu[cpu], PERF_FORMAT_GROUP);
> if (retval == -1) {
> - err(-1, "%s(cpu%d, 0x%x, 0x%llx) HITS", __func__, cpu, perf_pmu_types.pcore, perf_model_support->second.hits);
> + warnx("%s(cpu%d, 0x%x, 0x%llx) HITS", __func__, cpu, perf_pmu_types.ecore, perf_model_support->second.hits);
> free_fd_l2_percpu();
> return;
> }
> } else if (perf_lcore_set && CPU_ISSET_S(cpu, cpu_possible_setsize, perf_lcore_set)) {
> fd_l2_percpu[cpu] = open_perf_counter(cpu, perf_pmu_types.lcore, perf_model_support->third.refs, -1, PERF_FORMAT_GROUP);
> if (fd_l2_percpu[cpu] == -1) {
> - err(-1, "%s(cpu%d, 0x%x, 0x%llx) REFS", __func__, cpu, perf_pmu_types.pcore, perf_model_support->third.refs);
> + warnx("%s(cpu%d, 0x%x, 0x%llx) REFS", __func__, cpu, perf_pmu_types.lcore, perf_model_support->third.refs);
> free_fd_l2_percpu();
> return;
> }
> retval = open_perf_counter(cpu, perf_pmu_types.lcore, perf_model_support->third.hits, fd_l2_percpu[cpu], PERF_FORMAT_GROUP);
> if (retval == -1) {
> - err(-1, "%s(cpu%d, 0x%x, 0x%llx) HITS", __func__, cpu, perf_pmu_types.pcore, perf_model_support->third.hits);
> + warnx("%s(cpu%d, 0x%x, 0x%llx) HITS", __func__, cpu, perf_pmu_types.lcore, perf_model_support->third.hits);
> free_fd_l2_percpu();
> return;
> }
> --
> 2.53.0
>
>


--
Len Brown, Intel Open Source Technology Center