aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Murphy <robin.murphy@arm.com>2018-02-15 13:51:43 -0500
committerArnd Bergmann <arnd@arndb.de>2018-03-06 11:26:24 -0500
commit03057f2626e955ebea88a668a6d7d699f836e5c0 (patch)
tree61bae3d93516b1fc8b6e8fc181fdd43ae343beeb
parent3de6be7a3dd8934e59d85fc60a170d4ab2f0a0f2 (diff)
perf/arm-cci: Simplify CPU hotplug
Realistically, systems with multiple CCIs are unlikely to ever exist, and since the driver only actually supports a single instance anyway there's really no need to do the multi-instance hotplug state dance. Take the opportunity to simplify the hotplug-related code all over, addressing the context-migration TODO in the process for good measure. Acked-by: Punit Agrawal <punit.agrawal@arm.com> Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
-rw-r--r--drivers/perf/arm-cci.c56
1 files changed, 19 insertions, 37 deletions
diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c
index d5f8c750fd41..242623fbce1f 100644
--- a/drivers/perf/arm-cci.c
+++ b/drivers/perf/arm-cci.c
@@ -90,6 +90,7 @@ static struct cci_pmu_model cci_pmu_models[];
90struct cci_pmu { 90struct cci_pmu {
91 void __iomem *base; 91 void __iomem *base;
92 struct pmu pmu; 92 struct pmu pmu;
93 int cpu;
93 int nr_irqs; 94 int nr_irqs;
94 int *irqs; 95 int *irqs;
95 unsigned long active_irqs; 96 unsigned long active_irqs;
@@ -99,12 +100,12 @@ struct cci_pmu {
99 int num_cntrs; 100 int num_cntrs;
100 atomic_t active_events; 101 atomic_t active_events;
101 struct mutex reserve_mutex; 102 struct mutex reserve_mutex;
102 struct hlist_node node;
103 cpumask_t cpus;
104}; 103};
105 104
106#define to_cci_pmu(c) (container_of(c, struct cci_pmu, pmu)) 105#define to_cci_pmu(c) (container_of(c, struct cci_pmu, pmu))
107 106
107static struct cci_pmu *g_cci_pmu;
108
108enum cci_models { 109enum cci_models {
109#ifdef CONFIG_ARM_CCI400_PMU 110#ifdef CONFIG_ARM_CCI400_PMU
110 CCI400_R0, 111 CCI400_R0,
@@ -1325,7 +1326,6 @@ static int cci_pmu_event_init(struct perf_event *event)
1325 struct cci_pmu *cci_pmu = to_cci_pmu(event->pmu); 1326 struct cci_pmu *cci_pmu = to_cci_pmu(event->pmu);
1326 atomic_t *active_events = &cci_pmu->active_events; 1327 atomic_t *active_events = &cci_pmu->active_events;
1327 int err = 0; 1328 int err = 0;
1328 int cpu;
1329 1329
1330 if (event->attr.type != event->pmu->type) 1330 if (event->attr.type != event->pmu->type)
1331 return -ENOENT; 1331 return -ENOENT;
@@ -1352,10 +1352,9 @@ static int cci_pmu_event_init(struct perf_event *event)
1352 * the event being installed into its context, so the PMU's CPU can't 1352 * the event being installed into its context, so the PMU's CPU can't
1353 * change under our feet. 1353 * change under our feet.
1354 */ 1354 */
1355 cpu = cpumask_first(&cci_pmu->cpus); 1355 if (event->cpu < 0)
1356 if (event->cpu < 0 || cpu < 0)
1357 return -EINVAL; 1356 return -EINVAL;
1358 event->cpu = cpu; 1357 event->cpu = cci_pmu->cpu;
1359 1358
1360 event->destroy = hw_perf_event_destroy; 1359 event->destroy = hw_perf_event_destroy;
1361 if (!atomic_inc_not_zero(active_events)) { 1360 if (!atomic_inc_not_zero(active_events)) {
@@ -1382,11 +1381,7 @@ static ssize_t pmu_cpumask_attr_show(struct device *dev,
1382 struct pmu *pmu = dev_get_drvdata(dev); 1381 struct pmu *pmu = dev_get_drvdata(dev);
1383 struct cci_pmu *cci_pmu = to_cci_pmu(pmu); 1382 struct cci_pmu *cci_pmu = to_cci_pmu(pmu);
1384 1383
1385 int n = scnprintf(buf, PAGE_SIZE - 1, "%*pbl", 1384 return cpumap_print_to_pagebuf(true, buf, cpumask_of(cci_pmu->cpu));
1386 cpumask_pr_args(&cci_pmu->cpus));
1387 buf[n++] = '\n';
1388 buf[n] = '\0';
1389 return n;
1390} 1385}
1391 1386
1392static struct device_attribute pmu_cpumask_attr = 1387static struct device_attribute pmu_cpumask_attr =
@@ -1455,21 +1450,19 @@ static int cci_pmu_init(struct cci_pmu *cci_pmu, struct platform_device *pdev)
1455 return perf_pmu_register(&cci_pmu->pmu, name, -1); 1450 return perf_pmu_register(&cci_pmu->pmu, name, -1);
1456} 1451}
1457 1452
1458static int cci_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) 1453static int cci_pmu_offline_cpu(unsigned int cpu)
1459{ 1454{
1460 struct cci_pmu *cci_pmu = hlist_entry_safe(node, struct cci_pmu, node); 1455 int target;
1461 unsigned int target;
1462 1456
1463 if (!cpumask_test_and_clear_cpu(cpu, &cci_pmu->cpus)) 1457 if (!g_cci_pmu || cpu != g_cci_pmu->cpu)
1464 return 0; 1458 return 0;
1459
1465 target = cpumask_any_but(cpu_online_mask, cpu); 1460 target = cpumask_any_but(cpu_online_mask, cpu);
1466 if (target >= nr_cpu_ids) 1461 if (target >= nr_cpu_ids)
1467 return 0; 1462 return 0;
1468 /* 1463
1469 * TODO: migrate context once core races on event->ctx have 1464 perf_pmu_migrate_context(&g_cci_pmu->pmu, cpu, target);
1470 * been fixed. 1465 g_cci_pmu->cpu = target;
1471 */
1472 cpumask_set_cpu(target, &cci_pmu->cpus);
1473 return 0; 1466 return 0;
1474} 1467}
1475 1468
@@ -1706,7 +1699,7 @@ static int cci_pmu_probe(struct platform_device *pdev)
1706 raw_spin_lock_init(&cci_pmu->hw_events.pmu_lock); 1699 raw_spin_lock_init(&cci_pmu->hw_events.pmu_lock);
1707 mutex_init(&cci_pmu->reserve_mutex); 1700 mutex_init(&cci_pmu->reserve_mutex);
1708 atomic_set(&cci_pmu->active_events, 0); 1701 atomic_set(&cci_pmu->active_events, 0);
1709 cpumask_set_cpu(get_cpu(), &cci_pmu->cpus); 1702 cci_pmu->cpu = get_cpu();
1710 1703
1711 ret = cci_pmu_init(cci_pmu, pdev); 1704 ret = cci_pmu_init(cci_pmu, pdev);
1712 if (ret) { 1705 if (ret) {
@@ -1714,9 +1707,11 @@ static int cci_pmu_probe(struct platform_device *pdev)
1714 return ret; 1707 return ret;
1715 } 1708 }
1716 1709
1717 cpuhp_state_add_instance_nocalls(CPUHP_AP_PERF_ARM_CCI_ONLINE, 1710 cpuhp_setup_state_nocalls(CPUHP_AP_PERF_ARM_CCI_ONLINE,
1718 &cci_pmu->node); 1711 "perf/arm/cci:online", NULL,
1712 cci_pmu_offline_cpu);
1719 put_cpu(); 1713 put_cpu();
1714 g_cci_pmu = cci_pmu;
1720 pr_info("ARM %s PMU driver probed", cci_pmu->model->name); 1715 pr_info("ARM %s PMU driver probed", cci_pmu->model->name);
1721 return 0; 1716 return 0;
1722} 1717}
@@ -1729,19 +1724,6 @@ static struct platform_driver cci_pmu_driver = {
1729 .probe = cci_pmu_probe, 1724 .probe = cci_pmu_probe,
1730}; 1725};
1731 1726
1732static int __init cci_platform_init(void) 1727builtin_platform_driver(cci_pmu_driver);
1733{
1734 int ret;
1735
1736 ret = cpuhp_setup_state_multi(CPUHP_AP_PERF_ARM_CCI_ONLINE,
1737 "perf/arm/cci:online", NULL,
1738 cci_pmu_offline_cpu);
1739 if (ret)
1740 return ret;
1741
1742 return platform_driver_register(&cci_pmu_driver);
1743}
1744
1745device_initcall(cci_platform_init);
1746MODULE_LICENSE("GPL"); 1728MODULE_LICENSE("GPL");
1747MODULE_DESCRIPTION("ARM CCI PMU support"); 1729MODULE_DESCRIPTION("ARM CCI PMU support");