On Mon, Apr 05, 2021 at 08:10:58AM -0700, kan.li...@linux.intel.com wrote:
> @@ -2089,9 +2119,46 @@ static int __init init_hw_perf_events(void)
>       if (err)
>               goto out1;
>  
> -     err = perf_pmu_register(&pmu, "cpu", PERF_TYPE_RAW);
> -     if (err)
> -             goto out2;
> +     if (!is_hybrid()) {
> +             err = perf_pmu_register(&pmu, "cpu", PERF_TYPE_RAW);
> +             if (err)
> +                     goto out2;
> +     } else {
> +             u8 cpu_type = get_this_hybrid_cpu_type();
> +             struct x86_hybrid_pmu *hybrid_pmu;
> +             bool registered = false;
> +             int i;
> +
> +             if (!cpu_type && x86_pmu.get_hybrid_cpu_type)
> +                     cpu_type = x86_pmu.get_hybrid_cpu_type();
> +
> +             for (i = 0; i < x86_pmu.num_hybrid_pmus; i++) {
> +                     hybrid_pmu = &x86_pmu.hybrid_pmu[i];
> +
> +                     hybrid_pmu->pmu = pmu;
> +                     hybrid_pmu->pmu.type = -1;
> +                     hybrid_pmu->pmu.attr_update = x86_pmu.attr_update;
> +                     hybrid_pmu->pmu.capabilities |= 
> PERF_PMU_CAP_HETEROGENEOUS_CPUS;
> +
> +                     err = perf_pmu_register(&hybrid_pmu->pmu, 
> hybrid_pmu->name,
> +                                             (hybrid_pmu->cpu_type == 
> hybrid_big) ? PERF_TYPE_RAW : -1);
> +                     if (err)
> +                             continue;
> +
> +                     if (cpu_type == hybrid_pmu->cpu_type)
> +                             x86_pmu_update_cpu_context(&hybrid_pmu->pmu, 
> raw_smp_processor_id());
> +
> +                     registered = true;
> +             }
> +
> +             if (!registered) {
> +                     pr_warn("Failed to register hybrid PMUs\n");
> +                     kfree(x86_pmu.hybrid_pmu);
> +                     x86_pmu.hybrid_pmu = NULL;
> +                     x86_pmu.num_hybrid_pmus = 0;
> +                     goto out2;
> +             }

I don't think this is quite right. registered will be true even if one
fails, while I think you meant to only have it true when all (both)
types registered correctly.

> +     }
>  
>       return 0;
>  

Reply via email to