Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1646437

Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension

From Thomas Gleixner <tglx@linutronix.de>
Newsgroups linux.kernel
Subject Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Date 2017-05-21 22:40 +0200
Message-ID <tJFNU-49M-27@gated-at.bofh.it> (permalink)
References <tIxpn-5Nu-1@gated-at.bofh.it> <tIxpo-5Nu-35@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, 18 May 2017, Will Deacon wrote:
> +static void __arm_spe_pmu_dev_probe(void *info)
> +{
> +	dev_info(dev,
> +		 "probed for CPUs %*pbl [max_record_sz %u, align %u, features 0x%llx]\n",
> +		 cpumask_pr_args(&spe_pmu->supported_cpus),
> +		 spe_pmu->max_record_sz, spe_pmu->align, spe_pmu->features);

I have a hard time to spot the place which actually sets a CPU in the
supported_cpus mask. I must be missing something, but that's what grep
gives me:

+	cpumask_t				supported_cpus;
+	return cpumap_print_to_pagebuf(true, buf, &spe_pmu->supported_cpus);
+	    !cpumask_test_cpu(event->cpu, &spe_pmu->supported_cpus))
+	if (!cpumask_test_cpu(cpu, &spe_pmu->supported_cpus))
+		 cpumask_pr_args(&spe_pmu->supported_cpus),
+	if (!cpumask_test_cpu(cpu, &spe_pmu->supported_cpus))
+	if (!cpumask_test_cpu(cpu, &spe_pmu->supported_cpus))
+	cpumask_t *mask = &spe_pmu->supported_cpus;
+	if (irq_get_percpu_devid_partition(irq, &spe_pmu->supported_cpus)) {
+	cpumask_t *mask = &spe_pmu->supported_cpus;

> +static int arm_spe_pmu_dev_init(struct arm_spe_pmu *spe_pmu)
> +{
> +	int ret;
> +	cpumask_t *mask = &spe_pmu->supported_cpus;
> +
> +	/* Keep the hotplug state steady whilst we probe */
> +	get_online_cpus();
> +
> +	/* Make sure we probe the hardware on a relevant CPU */
> +	ret = smp_call_function_any(mask,  __arm_spe_pmu_dev_probe, spe_pmu, 1);

You can release the hotplug lock here again and spare all the goto magic.

> +	if (ret || !(spe_pmu->features & SPE_PMU_FEAT_DEV_PROBED)) {
> +		ret = -ENXIO;
> +		goto out_put_cpus;
> +	}
> +
> +	/* Request our PPIs (note that the IRQ is still disabled) */
> +	ret = request_percpu_irq(spe_pmu->irq, arm_spe_pmu_irq_handler, DRVNAME,
> +				 spe_pmu->handle);
> +	if (ret)
> +		goto out_put_cpus;
> +
> +	/* Setup the CPUs in our mask -- this enables the IRQ */
> +	on_each_cpu_mask(mask, __arm_spe_pmu_setup_one, spe_pmu, 1);
> +
> +	/* Register our hotplug notifier now so we don't miss any events */
> +	ret = cpuhp_state_add_instance_nocalls(arm_spe_pmu_online,
> +					       &spe_pmu->hotplug_node);

If you use cpuhp_state_add_instance() then you can spare the
on_each_cpu_mask(). The downside is that it will invoke the callback on the
non-supported CPUs as well, but you have protection in the callbacks anyway.

> +static int arm_spe_pmu_device_dt_probe(struct platform_device *pdev)
> +{
> +	int ret;
> +	struct arm_spe_pmu *spe_pmu;
> +	struct device *dev = &pdev->dev;
> +
> +	spe_pmu = devm_kzalloc(dev, sizeof(*spe_pmu), GFP_KERNEL);
> +	if (!spe_pmu) {
> +		dev_err(dev, "failed to allocate spe_pmu\n");
> +		return -ENOMEM;
> +	}
> +
> +	spe_pmu->handle = alloc_percpu(typeof(*spe_pmu->handle));
> +	if (!spe_pmu->handle)
> +		return -ENOMEM;
> +
> +	spe_pmu->pdev = pdev;
> +	platform_set_drvdata(pdev, spe_pmu);
> +
> +	ret = arm_spe_pmu_irq_probe(spe_pmu);
> +	if (ret)
> +		goto out_free_handle;
> +
> +	ret = arm_spe_pmu_dev_init(spe_pmu);
> +	if (ret)
> +		goto out_free_handle;
> +
> +	ret = arm_spe_pmu_perf_init(spe_pmu);
> +	if (ret)
> +		goto out_free_handle;

If that fails you leak the cpu hotplug instance. It's still enqueued.

> +static int arm_spe_pmu_device_remove(struct platform_device *pdev)
> +{
> +	struct arm_spe_pmu *spe_pmu = platform_get_drvdata(pdev);
> +	cpumask_t *mask = &spe_pmu->supported_cpus;
> +
> +	arm_spe_pmu_perf_destroy(spe_pmu);
> +
> +	get_online_cpus();
> +	cpuhp_state_remove_instance_nocalls(arm_spe_pmu_online,
> +					    &spe_pmu->hotplug_node);
> +	on_each_cpu_mask(mask, __arm_spe_pmu_stop_one, spe_pmu, 1);


You can spare that dance and just use cpuhp_state_remove_instance().

> +	free_percpu_irq(spe_pmu->irq, spe_pmu->handle);
> +	free_percpu(spe_pmu->handle);

Those two do not need hotplug protection.

Thanks

	tglx

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v3 0/5] Add support for the ARMv8.2 Statistical Profiling Extension Will Deacon <will.deacon@arm.com> - 2017-05-18 19:30 +0200
  [PATCH v3 3/5] perf/core: Add PERF_AUX_FLAG_COLLISION to report colliding samples Will Deacon <will.deacon@arm.com> - 2017-05-18 19:30 +0200
  [PATCH v3 1/5] genirq: export irq_get_percpu_devid_partition to modules Will Deacon <will.deacon@arm.com> - 2017-05-18 19:30 +0200
  [PATCH v3 2/5] perf/core: Export AUX buffer helpers to modules Will Deacon <will.deacon@arm.com> - 2017-05-18 19:30 +0200
  [PATCH v3 5/5] dt-bindings: Document devicetree binding for ARM SPE Will Deacon <will.deacon@arm.com> - 2017-05-18 19:30 +0200
  [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension Will Deacon <will.deacon@arm.com> - 2017-05-18 19:30 +0200
    Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical  Profiling Extension Thomas Gleixner <tglx@linutronix.de> - 2017-05-21 22:40 +0200
      Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical  Profiling Extension Will Deacon <will.deacon@arm.com> - 2017-05-22 13:10 +0200
    Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2  Statistical Profiling Extension Kim Phillips <kim.phillips@arm.com> - 2017-05-22 14:40 +0200
      Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical  Profiling Extension Mark Rutland <mark.rutland@arm.com> - 2017-05-22 14:50 +0200
        Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2  Statistical Profiling Extension Kim Phillips <kim.phillips@arm.com> - 2017-05-22 17:50 +0200
          Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical  Profiling Extension Mark Rutland <mark.rutland@arm.com> - 2017-05-22 18:30 +0200
            Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2  Statistical Profiling Extension Kim Phillips <kim.phillips@arm.com> - 2017-05-23 01:30 +0200

csiph-web