Skip to content

Commit 1229735

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
perf/x86/intel/uncore: Make code more readable
Clean up the code a bit before reworking it completely. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Harish Chegondi <[email protected]> Cc: Jacob Pan <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Vince Weaver <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent a46195f commit 1229735

File tree

1 file changed

+50
-45
lines changed

1 file changed

+50
-45
lines changed

arch/x86/events/intel/uncore.c

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ u64 uncore_shared_reg_config(struct intel_uncore_box *box, int idx)
217217
return config;
218218
}
219219

220-
static void uncore_assign_hw_event(struct intel_uncore_box *box, struct perf_event *event, int idx)
220+
static void uncore_assign_hw_event(struct intel_uncore_box *box,
221+
struct perf_event *event, int idx)
221222
{
222223
struct hw_perf_event *hwc = &event->hw;
223224

@@ -312,18 +313,19 @@ static void uncore_pmu_init_hrtimer(struct intel_uncore_box *box)
312313
box->hrtimer.function = uncore_pmu_hrtimer;
313314
}
314315

315-
static struct intel_uncore_box *uncore_alloc_box(struct intel_uncore_type *type, int node)
316+
static struct intel_uncore_box *uncore_alloc_box(struct intel_uncore_type *type,
317+
int node)
316318
{
319+
int i, size, numshared = type->num_shared_regs ;
317320
struct intel_uncore_box *box;
318-
int i, size;
319321

320-
size = sizeof(*box) + type->num_shared_regs * sizeof(struct intel_uncore_extra_reg);
322+
size = sizeof(*box) + numshared * sizeof(struct intel_uncore_extra_reg);
321323

322324
box = kzalloc_node(size, GFP_KERNEL, node);
323325
if (!box)
324326
return NULL;
325327

326-
for (i = 0; i < type->num_shared_regs; i++)
328+
for (i = 0; i < numshared; i++)
327329
raw_spin_lock_init(&box->shared_regs[i].lock);
328330

329331
uncore_pmu_init_hrtimer(box);
@@ -351,7 +353,8 @@ static bool is_uncore_event(struct perf_event *event)
351353
}
352354

353355
static int
354-
uncore_collect_events(struct intel_uncore_box *box, struct perf_event *leader, bool dogrp)
356+
uncore_collect_events(struct intel_uncore_box *box, struct perf_event *leader,
357+
bool dogrp)
355358
{
356359
struct perf_event *event;
357360
int n, max_count;
@@ -412,7 +415,8 @@ uncore_get_event_constraint(struct intel_uncore_box *box, struct perf_event *eve
412415
return &type->unconstrainted;
413416
}
414417

415-
static void uncore_put_event_constraint(struct intel_uncore_box *box, struct perf_event *event)
418+
static void uncore_put_event_constraint(struct intel_uncore_box *box,
419+
struct perf_event *event)
416420
{
417421
if (box->pmu->type->ops->put_constraint)
418422
box->pmu->type->ops->put_constraint(box, event);
@@ -592,7 +596,7 @@ static void uncore_pmu_event_del(struct perf_event *event, int flags)
592596
if (event == box->event_list[i]) {
593597
uncore_put_event_constraint(box, event);
594598

595-
while (++i < box->n_events)
599+
for (++i; i < box->n_events; i++)
596600
box->event_list[i - 1] = box->event_list[i];
597601

598602
--box->n_events;
@@ -801,10 +805,8 @@ static void __init uncore_type_exit(struct intel_uncore_type *type)
801805

802806
static void __init uncore_types_exit(struct intel_uncore_type **types)
803807
{
804-
int i;
805-
806-
for (i = 0; types[i]; i++)
807-
uncore_type_exit(types[i]);
808+
for (; *types; types++)
809+
uncore_type_exit(*types);
808810
}
809811

810812
static int __init uncore_type_init(struct intel_uncore_type *type)
@@ -908,9 +910,11 @@ static int uncore_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id
908910
* some device types. Hence PCI device idx would be 0 for all devices.
909911
* So increment pmu pointer to point to an unused array element.
910912
*/
911-
if (boot_cpu_data.x86_model == 87)
913+
if (boot_cpu_data.x86_model == 87) {
912914
while (pmu->func_id >= 0)
913915
pmu++;
916+
}
917+
914918
if (pmu->func_id < 0)
915919
pmu->func_id = pdev->devfn;
916920
else
@@ -1170,44 +1174,45 @@ static int uncore_cpu_prepare(int cpu, int phys_id)
11701174
return 0;
11711175
}
11721176

1173-
static void
1174-
uncore_change_context(struct intel_uncore_type **uncores, int old_cpu, int new_cpu)
1177+
static void uncore_change_type_ctx(struct intel_uncore_type *type, int old_cpu,
1178+
int new_cpu)
11751179
{
1176-
struct intel_uncore_type *type;
1177-
struct intel_uncore_pmu *pmu;
1180+
struct intel_uncore_pmu *pmu = type->pmus;
11781181
struct intel_uncore_box *box;
1179-
int i, j;
1180-
1181-
for (i = 0; uncores[i]; i++) {
1182-
type = uncores[i];
1183-
for (j = 0; j < type->num_boxes; j++) {
1184-
pmu = &type->pmus[j];
1185-
if (old_cpu < 0)
1186-
box = uncore_pmu_to_box(pmu, new_cpu);
1187-
else
1188-
box = uncore_pmu_to_box(pmu, old_cpu);
1189-
if (!box)
1190-
continue;
1182+
int i;
11911183

1192-
if (old_cpu < 0) {
1193-
WARN_ON_ONCE(box->cpu != -1);
1194-
box->cpu = new_cpu;
1195-
continue;
1196-
}
1184+
for (i = 0; i < type->num_boxes; i++, pmu++) {
1185+
if (old_cpu < 0)
1186+
box = uncore_pmu_to_box(pmu, new_cpu);
1187+
else
1188+
box = uncore_pmu_to_box(pmu, old_cpu);
1189+
if (!box)
1190+
continue;
11971191

1198-
WARN_ON_ONCE(box->cpu != old_cpu);
1199-
if (new_cpu >= 0) {
1200-
uncore_pmu_cancel_hrtimer(box);
1201-
perf_pmu_migrate_context(&pmu->pmu,
1202-
old_cpu, new_cpu);
1203-
box->cpu = new_cpu;
1204-
} else {
1205-
box->cpu = -1;
1206-
}
1192+
if (old_cpu < 0) {
1193+
WARN_ON_ONCE(box->cpu != -1);
1194+
box->cpu = new_cpu;
1195+
continue;
12071196
}
1197+
1198+
WARN_ON_ONCE(box->cpu != old_cpu);
1199+
box->cpu = -1;
1200+
if (new_cpu < 0)
1201+
continue;
1202+
1203+
uncore_pmu_cancel_hrtimer(box);
1204+
perf_pmu_migrate_context(&pmu->pmu, old_cpu, new_cpu);
1205+
box->cpu = new_cpu;
12081206
}
12091207
}
12101208

1209+
static void uncore_change_context(struct intel_uncore_type **uncores,
1210+
int old_cpu, int new_cpu)
1211+
{
1212+
for (; *uncores; uncores++)
1213+
uncore_change_type_ctx(*uncores, old_cpu, new_cpu);
1214+
}
1215+
12111216
static void uncore_event_exit_cpu(int cpu)
12121217
{
12131218
int i, phys_id, target;
@@ -1318,8 +1323,8 @@ static int __init uncore_msr_pmus_register(void)
13181323
struct intel_uncore_type **types = uncore_msr_uncores;
13191324
int ret;
13201325

1321-
while (*types) {
1322-
ret = type_pmu_register(*types++);
1326+
for (; *types; types++) {
1327+
ret = type_pmu_register(*types);
13231328
if (ret)
13241329
return ret;
13251330
}

0 commit comments

Comments
 (0)