Add support for the ARMv8.2 Statistical Profiling Extension
Subsystems (4)
v3 cover Add support for the ARMv8.2 Statistical Profiling Extension
Hi all,
This is the fifth posting of the patches previously posted here:
rfcv1: http://lists.infradead.org/pipermail/linux-arm-kernel/2017-January/476450.html
rfcv2: http://lists.infradead.org/pipermail/linux-arm-kernel/2017-January/479387.html
v1: http://lists.infradead.org/pipermail/linux-arm-kernel/2017-January/483684.html v2: http://lists.infradead.org/pipermail/linux-arm-kernel/2017-April/499938.html
Changes since v2 include:
* Rebased onto v4.12-rc1, which includes some rework to AUX flag handling
* Removed VHE-dependent exclude_hv support in light of recent change to CPU PMU code [1]
The architecture documentation is available here:
and there's a high-level overview on this official ARM blog:
https://community.arm.com/processors/b/blog/posts/statistical-profiling-extension-for-armv8-a
All comments welcome,
Will
[1] http://lkml.kernel.org/r/1493742574-25955-1-git-send-email-ganapatrao.kulkarni at cavium.com
--->8
Will Deacon (5):
genirq: export irq_get_percpu_devid_partition to modules perf/core: Export AUX buffer helpers to modules
perf/core: Add PERF_AUX_FLAG_COLLISION to report colliding samples drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
dt-bindings: Document devicetree binding for ARM SPE
Documentation/devicetree/bindings/arm/spe-pmu.txt | 20 + drivers/perf/Kconfig | 8 + drivers/perf/Makefile | 1 + drivers/perf/arm_spe_pmu.c | 1246 +++++++++++++++++++++ include/uapi/linux/perf_event.h | 1 + kernel/events/ring_buffer.c | 4 + kernel/irq/irqdesc.c | 1 + 7 files changed, 1281 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/spe-pmu.txt create mode 100644 drivers/perf/arm_spe_pmu.c
Signature · 1 line
2.1.4
PATCH v3 1/5 genirq: export irq_get_percpu_devid_partition to modules
Any modular driver using cluster-affine PPIs needs to be able to call irq_get_percpu_devid_partition so that it can enable the IRQ on the correct subset of CPUs.
This patch exports the symbol so that it can be called from within a module.
--- kernel/irq/irqdesc.c | 1 + 1 file changed, 1 insertion(+)
kernel/irq/irqdesc.c +1 -0
@@ -856,6 +856,7 @@ int irq_get_percpu_devid_partition(unsigned int irq, struct cpumask *affinity)return 0 ; } +EXPORT_SYMBOL_GPL (irq_get_percpu_devid_partition);void kstat_incr_irq_this_cpu (unsigned int irq) {
Signature · 1 line
2.1.4
PATCH v3 2/5 perf/core: Export AUX buffer helpers to modules
In reply to Will DeaconPerf PMU drivers using AUX buffers cannot be built as modules unless the AUX helpers are exported.
This patch exports perf_aux_output_{begin,end,skip} and perf_get_aux to modules.
--- kernel/events/ring_buffer.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/events/ring_buffer.c +4 -0
@@ -411,6 +411,7 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,return NULL ; } +EXPORT_SYMBOL_GPL (perf_aux_output_begin);/* * Commit the data written by hardware into the ring buffer by adjusting
@@ -470,6 +471,7 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size)rb_free_aux (rb);ring_buffer_put (rb); } +EXPORT_SYMBOL_GPL (perf_aux_output_end);/* * Skip over a given number of bytes in the AUX buffer, due to, for example,
@@ -498,6 +500,7 @@ int perf_aux_output_skip(struct perf_output_handle *handle, unsigned long size)return 0 ; } +EXPORT_SYMBOL_GPL (perf_aux_output_skip);void *perf_get_aux (struct perf_output_handle *handle) {
@@ -507,6 +510,7 @@ void *perf_get_aux(struct perf_output_handle *handle)return handle->rb->aux_priv; } +EXPORT_SYMBOL_GPL (perf_get_aux);#define PERF_AUX_GFP (GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY)
Signature · 1 line
2.1.4
PATCH v3 3/5 perf/core: Add PERF_AUX_FLAG_COLLISION to report colliding samples
In reply to Will DeaconThe ARM SPE architecture permits an implementation to ignore a sample if the sample is due to be taken whilst another sample is already being produced. In this case, it is desirable to report the collision to userspace, as they may want to lower the sample period.
This patch adds a PERF_AUX_FLAG_COLLISION flag, so that such events can be relayed to userspace.
--- include/uapi/linux/perf_event.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/perf_event.h +1 -0
@@ -916,6 +916,7 @@ enum perf_callchain_context {#define PERF_AUX_FLAG_TRUNCATED 0x01/* record was truncated to fit */ #define PERF_AUX_FLAG_OVERWRITE 0x02/* snapshot from overwrite mode */ #define PERF_AUX_FLAG_PARTIAL 0x04/* record contains gaps */ +#define PERF_AUX_FLAG_COLLISION 0x08/* sample collided with another */ #define PERF_FLAG_FD_NO_GROUP (1UL << 0)#define PERF_FLAG_FD_OUTPUT (1UL << 1)
Signature · 1 line
2.1.4
PATCH v3 4/5 drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
In reply to Will DeaconThe ARMv8.2 architecture introduces the optional Statistical Profiling Extension (SPE).
SPE can be used to profile a population of operations in the CPU pipeline after instruction decode. These are either architected instructions (i.e. a dynamic instruction trace) or CPU-specific uops and the choice is fixed statically in the hardware and advertised to userspace via caps/. Sampling is controlled using a sampling interval, similar to a regular PMU counter, but also with an optional random perturbation to avoid falling into patterns where you continuously profile the same instruction in a hot loop.
After each operation is decoded, the interval counter is decremented. When it hits zero, an operation is chosen for profiling and tracked within the pipeline until it retires. Along the way, information such as TLB lookups, cache misses, time spent to issue etc is captured in the form of a sample. The sample is then filtered according to certain criteria (e.g. load latency) that can be specified in the event config (described under format/) and, if the sample satisfies the filter, it is written out to memory as a record, otherwise it is discarded. Only one operation can be sampled at a time.
The in-memory buffer is linear and virtually addressed, raising an interrupt when it fills up. The PMU driver handles these interrupts to give the appearance of a ring buffer, as expected by the AUX code.
The in-memory trace-like format is self-describing (though not parseable in reverse) and written as a series of records, with each record corresponding to a sample and consisting of a sequence of packets. These packets are defined by the architecture, although some have CPU-specific fields for recording information specific to the microarchitecture.
As a simple example, a record generated for a branch instruction may consist of the following packets:
0 (Address) : Virtual PC of the branch instruction
1 (Type) : Conditional direct branch
2 (Counter) : Number of cycles taken from Dispatch to Issue 3 (Address) : Virtual branch target + condition flags 4 (Counter) : Number of cycles taken from Dispatch to Complete 5 (Events) : Mispredicted as not-taken
6 (END) : End of record
It is also possible to toggle properties such as timestamp packets in each record.
This patch adds support for SPE in the form of a new perf driver.
--- drivers/perf/Kconfig | 8 + drivers/perf/Makefile | 1 + drivers/perf/arm_spe_pmu.c | 1246 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1255 insertions(+) create mode 100644 drivers/perf/arm_spe_pmu.c
drivers/perf/Kconfig +8 -0
@@ -42,4 +42,12 @@ config XGENE_PMU help Say y if you want to use APM X-Gene SoC performance monitors. +config ARM_SPE_PMU + tristate "Enable support for the ARMv8.2 Statistical Profiling Extension" + depends on PERF_EVENTS && ARM64 + help + Enable perf support for the ARMv8.2 Statistical Profiling + Extension, which provides periodic sampling of operations in + the CPU pipeline and reports this via the perf AUX interface. + endmenu
drivers/perf/Makefile +1 -0
@@ -3,3 +3,4 @@ obj-$(CONFIG_ARM_PMU_ACPI) += arm_pmu_acpi.o obj-$(CONFIG_QCOM_L2_PMU) += qcom_l2_pmu.o obj-$(CONFIG_QCOM_L3_PMU) += qcom_l3_pmu.o obj-$(CONFIG_XGENE_PMU) += xgene_pmu.o +obj-$(CONFIG_ARM_SPE_PMU) += arm_spe_pmu.o
drivers/perf/arm_spe_pmu.c new file +1246 -0
1,246 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v3 5/5 dt-bindings: Document devicetree binding for ARM SPE
In reply to Will DeaconThis patch documents the devicetree binding in use for ARM SPE.
--- Documentation/devicetree/bindings/arm/spe-pmu.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/spe-pmu.txt
Documentation/devicetree/bindings/arm/spe-pmu.txt new file +20 -0
@@ -0,0 +1,20 @@ +* ARMv8.2 Statistical Profiling Extension (SPE) Performance Monitor Units (PMU) + +ARMv8.2 introduces the optional Statistical Profiling Extension for collecting +performance sample data using an in-memory trace buffer. + +** SPE Required properties: + +- compatible : should be one of: + "arm,statistical-profiling-extension-v1" + +- interrupts : Exactly 1 PPI must be listed. For heterogeneous systems where + SPE is only supported on a subset of the CPUs, please consult + the arm,gic-v3 binding for details on describing a PPI partition. + +** Example: + +spe-pmu { + compatible = "arm,statistical-profiling-extension-v1"; + interrupts = <GIC_PPI 05 IRQ_TYPE_LEVEL_HIGH &part1>; +};
Signature · 1 line
2.1.4
Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
In reply to Will Deacondrivers/perf/arm_spe_pmu.c line 1028
Quoted 6 lines · Will Deacon
drivers/perf/arm_spe_pmu.c new file +6
-0+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;
drivers/perf/arm_spe_pmu.c line 1100
Quoted 10 lines
drivers/perf/arm_spe_pmu.c new file +10
-0+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.
Quoted 7 lines
drivers/perf/arm_spe_pmu.c new file +7
-0+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,
drivers/perf/arm_spe_pmu.c line 1117
Quoted 10 lines
drivers/perf/arm_spe_pmu.c new file +10
-0+ 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.
Quoted 20 lines
drivers/perf/arm_spe_pmu.c new file +20
-0+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);
drivers/perf/arm_spe_pmu.c line 1181
Quoted 10 lines
drivers/perf/arm_spe_pmu.c new file +10
-0+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.
drivers/perf/arm_spe_pmu.c line 1200
Quoted 11 lines
drivers/perf/arm_spe_pmu.c new file +11
-0+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().
drivers/perf/arm_spe_pmu.c line 1202
Quoted 2 lines
drivers/perf/arm_spe_pmu.c new file +2
-0+free_percpu_irq (spe_pmu->irq, spe_pmu->handle); +free_percpu (spe_pmu->handle);
Those two do not need hotplug protection.
Thanks
tglx
Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Hi Thomas,
Thanks for having a look at the patch. Responses inline.
Quoted 12 lines · Thomas Gleixner
drivers/perf/arm_spe_pmu.c line 1028
Quoted 6 lines · Will Deacon
drivers/perf/arm_spe_pmu.c new file +6
-0+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_cpusmask. I must be missing something, but that's what grep gives me:
drivers/perf/arm_spe_pmu.c line 1139
Quoted 9 lines
drivers/perf/arm_spe_pmu.c new file +9
-0+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)) {
That's the one ^^^. The mask is determined by the affinity of the interrupt partition.
Quoted 14 lines
(quoted diff) +1
-0+ cpumask_t *mask = &spe_pmu->supported_cpus;drivers/perf/arm_spe_pmu.c line 1100
Quoted 11 lines
drivers/perf/arm_spe_pmu.c new file +10
-0+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.
Actually, if I rework this to use cpuhp_state_add_instance instead, then I might be able to do without the hotplug lock altogether. I'll have a play.
Quoted 13 lines
Quoted 13 lines
drivers/perf/arm_spe_pmu.c new file +13
-0+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 );
Quoted 8 lines
drivers/perf/arm_spe_pmu.c line 1117
Quoted 4 lines
drivers/perf/arm_spe_pmu.c new file +4
-0+ +/* 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 theon_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.
Yes, I think that will work and I can get rid of get_online_cpus around the probing too.
Quoted 24 lines
Quoted 24 lines
drivers/perf/arm_spe_pmu.c new file +24
-0+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);
Quoted 8 lines
drivers/perf/arm_spe_pmu.c line 1181
Quoted 6 lines
drivers/perf/arm_spe_pmu.c new file +6
-0+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.
Yikes, well spotted. That will then get called with the freed spe_pmu, which will probably end badly.
Quoted 6 lines
Quoted 6 lines
drivers/perf/arm_spe_pmu.c new file +6
-0+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);
Quoted 8 lines
drivers/perf/arm_spe_pmu.c line 1200
Quoted 5 lines
drivers/perf/arm_spe_pmu.c new file +5
-0+ +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().
Thanks, I'll fix this too.
Will
Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
In reply to Will DeaconQuoted 37 lines · On Thu, 18 May 2017 18:24:32 +0100 Will Deacon <[email protected]> wrote:
drivers/perf/arm_spe_pmu.c new file +37
-0+/* Perf callbacks */ +static int arm_spe_pmu_event_init (struct perf_event *event) +{ +u64 reg; +struct perf_event_attr *attr = &event->attr; +struct arm_spe_pmu *spe_pmu =to_spe_pmu (event->pmu); + +/* This is, of course, deeply driver-specific */ +if (attr->type != event->pmu->type) +return -ENOENT ; + +if (event->cpu >=0 && + !cpumask_test_cpu (event->cpu, &spe_pmu->supported_cpus)) +return -ENOENT ; + +if (arm_spe_event_to_pmsevfr (event) &PMSEVFR_EL1_RES0 ) +return -EOPNOTSUPP ; + +if (event->hw.sample_period < spe_pmu->min_period || + event->hw.sample_period &PMSIRR_EL1_IVAL_MASK ) +return -EOPNOTSUPP ; + +if (attr->exclude_idle) +return -EOPNOTSUPP ; + +/* +* Feedback-directed frequency throttling doesn't work when we +* have a buffer of samples. We'd need to manually count the +* samples in the buffer when it fills up and adjust the event +* count to reflect that. Instead, force the user to specify a +* sample period instead. +*/ +if (attr->freq) +return -EINVAL ; + + reg =arm_spe_event_to_pmsfcr (event); + if ((reg & BIT(PMSFCR_EL1_FE_SHIFT)) &&
drivers/perf/arm_spe_pmu.c line 708
Quoted 10 lines
drivers/perf/arm_spe_pmu.c new file +10
-0+ !(spe_pmu->features & SPE_PMU_FEAT_FILT_EVT)) +return -EOPNOTSUPP ; + +if ((reg &BIT (PMSFCR_EL1_FT_SHIFT )) && + !(spe_pmu->features &SPE_PMU_FEAT_FILT_TYP )) +return -EOPNOTSUPP ; + +if ((reg &BIT (PMSFCR_EL1_FL_SHIFT )) && + !(spe_pmu->features &SPE_PMU_FEAT_FILT_LAT )) +return -EOPNOTSUPP ;
I've consistently brought up lack of proper user error messaging in all previous submissions of this driver:
Jan. 10 2017 (first RFC):
https://www.spinics.net/lists/arm-kernel/msg553322.html
Jan. 13 (second RFC):
https://patchwork.kernel.org/patch/9515967/
[I just went ahead and re-read https://lkml.org/lkml/2015/8/26/661 and still think it's not a reason to not do this]
30 Jan 2017 (first PATCH series):
https://www.spinics.net/lists/arm-kernel/msg559232.html
6 apr 2017 (PATCH v2 series):
https://lkml.org/lkml/2017/4/6/790
AFAICT, my comments hold, yet the driver still gets resubmitted without them being addressed. How do we get out of this loop?
Kim
Mark Rutland
maintainerRe: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Hi,
Quoted 13 lines · Kim Phillips
drivers/perf/arm_spe_pmu.c line 672
Quoted 11 lines · On Thu, 18 May 2017 18:24:32 +0100 Will Deacon <[email protected]> wrote:
drivers/perf/arm_spe_pmu.c new file +11
-0+/* Perf callbacks */ +static int arm_spe_pmu_event_init (struct perf_event *event) +{ +u64 reg; +struct perf_event_attr *attr = &event->attr; +struct arm_spe_pmu *spe_pmu =to_spe_pmu (event->pmu); + +/* This is, of course, deeply driver-specific */ +if (attr->type != event->pmu->type) +return -ENOENT ; +
[trimming other return sites]
Quoted 3 lines
I've consistently brought up lack of proper user error messaging in all previous submissions of this driver:
... and we've consistently explained why logging such things to dmesg by default will not fly. As before, while we call these return codes error values, they are *not* errors in the same sense as pr_err().
Quoted 2 lines
6 apr 2017 (PATCH v2 series):
https://lkml.org/lkml/2017/4/6/790
Please consult my replies to this:
https://lkml.org/lkml/2017/4/6/796
https://lkml.org/lkml/2017/4/7/246
... we can add a pr_debug() for these cases, as that will be guarded by dynamic debug, and won't be pointlessly spamming the dmesg.
Anything beyond that simply will not fly.
Quoted 2 lines
AFAICT, my comments hold, yet the driver still gets resubmitted without them being addressed. How do we get out of this loop?
We've repeatedly explained why the approach you suggest is not feasible. Perhaps you could try to explain why our approach doesn't seem feasible to you.
Thanks,
Mark.
Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Quoted 1 line · On Mon, 22 May 2017 13:44:46 +0100 Mark Rutland <[email protected]> wrote:
Hi,
Hi Mark,
Quoted 16 lines · Kim Phillips
Quoted 13 lines
drivers/perf/arm_spe_pmu.c line 672
Quoted 11 lines · On Thu, 18 May 2017 18:24:32 +0100 Will Deacon <[email protected]> wrote:
drivers/perf/arm_spe_pmu.c new file +11
-0+/* Perf callbacks */ +static int arm_spe_pmu_event_init (struct perf_event *event) +{ +u64 reg; +struct perf_event_attr *attr = &event->attr; +struct arm_spe_pmu *spe_pmu =to_spe_pmu (event->pmu); + +/* This is, of course, deeply driver-specific */ +if (attr->type != event->pmu->type) +return -ENOENT ; +[trimming other return sites]
Thanks but other conditions, such as the user specified sample period check would be more appropriate to be left in for this discussion.
Quoted 6 lines
Quoted 3 lines
I've consistently brought up lack of proper user error messaging in all previous submissions of this driver:
... and we've consistently explained why logging such things to dmesg by default will not fly. As before, while we call these return codes error values, they are *not* errors in the same sense as
pr_err().
I've expressed my disagreement to that matter here:
https://lkml.org/lkml/2017/4/7/223
yet it got no response.
Quoted 5 lines
Quoted 2 lines
6 apr 2017 (PATCH v2 series):
https://lkml.org/lkml/2017/4/6/790Please consult my replies to this:
Quoted 7 lines
https://lkml.org/lkml/2017/4/6/796
https://lkml.org/lkml/2017/4/7/246... we can add a
pr_debug()for these cases, as that will be guarded by dynamic debug, and won't be pointlessly spamming the dmesg.Anything beyond that simply will not fly.
See above; I responded to those replies, and didn't get a response. Would you care to respond to my latest reply in that thread before re-posting?
Quoted 6 lines
Quoted 2 lines
AFAICT, my comments hold, yet the driver still gets resubmitted without them being addressed. How do we get out of this loop?
We've repeatedly explained why the approach you suggest is not feasible. Perhaps you could try to explain why our approach doesn't seem feasible to you.
I don't want SPE users to have to manually instrument the driver in order to find out what it didn't like about the parameters they specified. This problem has already been reported by other early adopters. perf itself says "dmesg may provide additional information", so let's please use it.
Kim
Mark Rutland
maintainerRe: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Hi,
Quoted 19 lines · Kim Phillips
Quoted 16 lines · On Mon, 22 May 2017 13:44:46 +0100 Mark Rutland <[email protected]> wrote:
Quoted 13 lines · Kim Phillips
drivers/perf/arm_spe_pmu.c line 672
Quoted 11 lines · On Thu, 18 May 2017 18:24:32 +0100 Will Deacon <[email protected]> wrote:
drivers/perf/arm_spe_pmu.c new file +11
-0+/* Perf callbacks */ +static int arm_spe_pmu_event_init (struct perf_event *event) +{ +u64 reg; +struct perf_event_attr *attr = &event->attr; +struct arm_spe_pmu *spe_pmu =to_spe_pmu (event->pmu); + +/* This is, of course, deeply driver-specific */ +if (attr->type != event->pmu->type) +return -ENOENT ; +[trimming other return sites]
Quoted 2 lines
Thanks but other conditions, such as the user specified sample period check would be more appropriate to be left in for this discussion.
Sure, I was just trimming to a single example for brevity. I appreciate there are cases where it may not be as simple to determine the cause from userspace today.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I've consistently brought up lack of proper user error messaging in all previous submissions of this driver:
... and we've consistently explained why logging such things to dmesg by default will not fly. As before, while we call these return codes error values, they are *not* errors in the same sense as
pr_err().
Quoted 5 lines
I've expressed my disagreement to that matter here:
https://lkml.org/lkml/2017/4/7/223
yet it got no response.
That's not strictly true.
I replied to the mail you cited, attempting to clarify as best I could.
You replied again, and it's true I didn't respond there, but there was no new substantiative argument. To summarize that thread, to the best of my understanding:
* We disagree on the semantic of "an error" in this context. Clearly we aren't going to agree.
* We agree that error reporting and handling is painful in this area.
* We disagree w.r.t. using printk() and friends. My position has not been swayed.
[...]
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
AFAICT, my comments hold, yet the driver still gets resubmitted without them being addressed. How do we get out of this loop?
We've repeatedly explained why the approach you suggest is not feasible. Perhaps you could try to explain why our approach doesn't seem feasible to you.
Quoted 5 lines
I don't want SPE users to have to manually instrument the driver in order to find out what it didn't like about the parameters they specified. This problem has already been reported by other early adopters. perf itself says "dmesg may provide additional information", so let's please use it.
Sorry, but regardless of any argument there is to be had on how best to handle errors, I'm not going to be swayed to the position that the solution is printk() or its ilk, for the reasons that I have outlined several times previously.
As one of the maintainers of PMU code, I must NAK such code in any PMU driver.
FWIW, I'm more than happy to:
* Add pr_debug() statements so that developers directly using the perf interfaces can debug their userspace code and without having to first develop a full knowledge of what is and isn't permitted.
* Add documentation such that userspace developers can figure out what is and is not supported.
* Add interfaces as appropriate such that userspace can more reliably determine the reason(s) an error code has been returned. For example, we might expose sample period information under sysfs.
* Help with any userspace error handling code. I am more than happy to review such code and to provide improvements myself.
... so if you want to make any progress on this front, please either look at one of those, or make a *new* suggestion that does not involve printk.
Thanks,
Mark.
Re: [PATCH v3 4/5] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Quoted 20 lines · On Mon, 22 May 2017 17:22:12 +0100 Mark Rutland <[email protected]> wrote:
Quoted 19 lines · Kim Phillips
Quoted 16 lines · On Mon, 22 May 2017 13:44:46 +0100 Mark Rutland <[email protected]> wrote:
Quoted 13 lines · Kim Phillips
drivers/perf/arm_spe_pmu.c line 672
Quoted 11 lines · On Thu, 18 May 2017 18:24:32 +0100 Will Deacon <[email protected]> wrote:
drivers/perf/arm_spe_pmu.c new file +11
-0+/* Perf callbacks */ +static int arm_spe_pmu_event_init (struct perf_event *event) +{ +u64 reg; +struct perf_event_attr *attr = &event->attr; +struct arm_spe_pmu *spe_pmu =to_spe_pmu (event->pmu); + +/* This is, of course, deeply driver-specific */ +if (attr->type != event->pmu->type) +return -ENOENT ; +[trimming other return sites]
Quoted 6 lines
Quoted 2 lines
Thanks but other conditions, such as the user specified sample period check would be more appropriate to be left in for this discussion.
Sure, I was just trimming to a single example for brevity. I appreciate there are cases where it may not be as simple to determine the cause from userspace today.
That helps, thanks.
Quoted 15 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I've consistently brought up lack of proper user error messaging in all previous submissions of this driver:
... and we've consistently explained why logging such things to dmesg by default will not fly. As before, while we call these return codes error values, they are *not* errors in the same sense as
pr_err().Quoted 5 lines
I've expressed my disagreement to that matter here:
https://lkml.org/lkml/2017/4/7/223
yet it got no response.
That's not strictly true.
Quoted 7 lines
I replied to the mail you cited, attempting to clarify as best I could. You replied again, and it's true I didn't respond there, but there was no new substantiative argument. To summarize that thread, to the best of my understanding:
* We disagree on the semantic of "an error" in this context. Clearly we aren't going to agree.
That's bad. We ought to agree on what an error is, in this and any other context. I'm willing to listen if you have a convincing argument, but none was given after my last reply:
"The driver is trying to report an error: in the above example, it's reporting that it cannot support an operation by returning -*E*OPNOTSUPP: an ERROR because it was unable to complete the request:
the request failed. Unlike e.g., a warning where something may not have been quite right, but went along with executing the operation anyway."
To put it another way, perf_event_open returning errno EINVAL is no different than open() returning the same with the meaning 'Invalid value in flags.' In fact, the perf_event_open manpage says errors in setting the sample frequency make the syscall return the error code -1 and EINVAL in errno.
Prior to that I see what might possibly be the underlying cause for the
Quoted 2 lines · discrepancy: you said:
Quoted 2 lines
Quoted 2 lines
The above cases are not (system) errors, and using
dev_err(even ratelimited) is certainly not appropriate. These arepr_debug()at best.
So is it that you are resisting technically calling it an error because that would imply we use pr_err() instead of pr_debug() perhaps? In which case, is that because of fuzzing?:
quoting you again:
"There are some cases where they're actively harmful (e.g. when fuzzing)."
to which my response remains:
"I'd expect fuzzer users to be more amenable to manually modifying the driver rather than regular users of the driver."
to which your then-response was seemingly irrelevant, and against the benefit of normal user of the driver:
"When fuzzing, I take a mainline, defconfig kernel, and run it through its paces. I don't touch each and every driver."
If this is the case, can we find another solution to make both regular fuzzer runners and regular users happy?
Quoted 6 lines
* We agree that error reporting and handling is painful in this area.
* We disagree w.r.t. using
printk()and friends. My position has not been swayed.[...]
I beg you to please reconsider, given we agree that this particular syscall is bad, and the alternative (no messaging) will truly be worse for our users.
Quoted 13 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
AFAICT, my comments hold, yet the driver still gets resubmitted without them being addressed. How do we get out of this loop?
We've repeatedly explained why the approach you suggest is not feasible. Perhaps you could try to explain why our approach doesn't seem feasible to you.
Quoted 5 lines
I don't want SPE users to have to manually instrument the driver in order to find out what it didn't like about the parameters they specified. This problem has already been reported by other early adopters. perf itself says "dmesg may provide additional information", so let's please use it.
Quoted 7 lines
Sorry, but regardless of any argument there is to be had on how best to handle errors, I'm not going to be swayed to the position that the solution is
printk()or its ilk, for the reasons that I have outlined several times previously.As one of the maintainers of PMU code, I must NAK such code in any PMU driver.
We disagree here: I am of the belief that users should be made aware of what they're doing wrong, and right now, dmesg is the vehicle to do so.
Quoted 5 lines
FWIW, I'm more than happy to:
* Add
pr_debug()statements so that developers directly using the perf interfaces can debug their userspace code and without having to first develop a full knowledge of what is and isn't permitted.
Perhaps this is a terminology context problem again, but to be abundantly clear: This isn't for developers per se; this is for normal, regular perf users trying to use perf to debug the performance of their applications. I don't expect these users to have to know how to turn on pr_debug messaging, esp. because it might turn on other noisy drivers in use at the same time.
Quoted 7 lines
* Add documentation such that userspace developers can figure out what is and is not supported.
* Add interfaces as appropriate such that userspace can more reliably determine the reason(s) an error code has been returned. For example, we might expose sample period information under sysfs.
Quoted 6 lines
* Help with any userspace error handling code. I am more than happy to review such code and to provide improvements myself.
... so if you want to make any progress on this front, please either look at one of those, or make a *new* suggestion that does not involve printk.
Not that I was looking, but I did just happen to notice this posting today:
https://lkml.org/lkml/2017/5/22/578
but I have no clue if or when it will be accepted, let alone whether it's applicable to perf, so *for the time being*, dmesg is what we have for now.
Kim