Cleanup the code a bit before reworking it completely.

Signed-off-by: Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/cpu/perf_event_intel_uncore.c |   71 +++++++++++++-------------
 1 file changed, 36 insertions(+), 35 deletions(-)

--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
@@ -791,10 +791,8 @@ static void __init uncore_type_exit(stru
 
 static void __init uncore_types_exit(struct intel_uncore_type **types)
 {
-       int i;
-
-       for (i = 0; types[i]; i++)
-               uncore_type_exit(types[i]);
+       while (*types)
+               uncore_type_exit(*types++);
 }
 
 static int __init uncore_type_init(struct intel_uncore_type *type)
@@ -898,9 +896,11 @@ static int uncore_pci_probe(struct pci_d
         * some device types. Hence PCI device idx would be 0 for all devices.
         * So increment pmu pointer to point to an unused array element.
         */
-       if (boot_cpu_data.x86_model == 87)
+       if (boot_cpu_data.x86_model == 87) {
                while (pmu->func_id >= 0)
                        pmu++;
+       }
+
        if (pmu->func_id < 0)
                pmu->func_id = pdev->devfn;
        else
@@ -1158,44 +1158,45 @@ static int uncore_cpu_prepare(int cpu, i
        return 0;
 }
 
-static void
-uncore_change_context(struct intel_uncore_type **uncores, int old_cpu, int 
new_cpu)
+static void uncore_change_type_ctx(struct intel_uncore_type *type, int old_cpu,
+                                  int new_cpu)
 {
-       struct intel_uncore_type *type;
-       struct intel_uncore_pmu *pmu;
+       struct intel_uncore_pmu *pmu = type->pmus;
        struct intel_uncore_box *box;
-       int i, j;
+       int i;
 
-       for (i = 0; uncores[i]; i++) {
-               type = uncores[i];
-               for (j = 0; j < type->num_boxes; j++) {
-                       pmu = &type->pmus[j];
-                       if (old_cpu < 0)
-                               box = uncore_pmu_to_box(pmu, new_cpu);
-                       else
-                               box = uncore_pmu_to_box(pmu, old_cpu);
-                       if (!box)
-                               continue;
+       for (i = 0; i < type->num_boxes; i++, pmu++) {
+               if (old_cpu < 0)
+                       box = uncore_pmu_to_box(pmu, new_cpu);
+               else
+                       box = uncore_pmu_to_box(pmu, old_cpu);
+               if (!box)
+                       continue;
+
+               if (old_cpu < 0) {
+                       WARN_ON_ONCE(box->cpu != -1);
+                       box->cpu = new_cpu;
+                       continue;
+               }
 
-                       if (old_cpu < 0) {
-                               WARN_ON_ONCE(box->cpu != -1);
-                               box->cpu = new_cpu;
-                               continue;
-                       }
+               WARN_ON_ONCE(box->cpu != old_cpu);
+               box->cpu = -1;
+               if (new_cpu < 0)
+                       continue;
 
-                       WARN_ON_ONCE(box->cpu != old_cpu);
-                       if (new_cpu >= 0) {
-                               uncore_pmu_cancel_hrtimer(box);
-                               perf_pmu_migrate_context(&pmu->pmu,
-                                               old_cpu, new_cpu);
-                               box->cpu = new_cpu;
-                       } else {
-                               box->cpu = -1;
-                       }
-               }
+               uncore_pmu_cancel_hrtimer(box);
+               perf_pmu_migrate_context(&pmu->pmu, old_cpu, new_cpu);
+               box->cpu = new_cpu;
        }
 }
 
+static void uncore_change_context(struct intel_uncore_type **uncores,
+                                 int old_cpu, int new_cpu)
+{
+       while (*uncores)
+               uncore_change_type_ctx(*uncores++, old_cpu, new_cpu);
+}
+
 static void uncore_event_exit_cpu(int cpu)
 {
        int i, phys_id, target;


Reply via email to