perf/core: Generalise event exclusion checking
Subsystems (15)
v2 cover perf/core: Generalise event exclusion checking
Many PMU drivers do not have the capability to exclude counting events that occur in specific contexts such as idle, kernel, guest, etc. These drivers indicate this by returning an error in their event_init upon testing the events attribute flags.
However this approach requires that each time a new event modifier is added to perf, all the perf drivers need to be modified to indicate that they don't support the attribute. This results in additional boiler-plate code common to many drivers that needs to be maintained. Furthermore the drivers are not consistent with regards to the error value they return when reporting unsupported attributes.
This patchset allow PMU drivers to advertise their ability to exclude based on context via a new capability: PERF_PMU_CAP_EXCLUDE. This allows the perf core to reject requests for exclusion events where there is no support in the PMU.
This is a functional change, in particular:
- Some drivers will now additionally (but correctly) report unsupported exclusion flags. It's typical for existing userspace tools such as perf to handle such errors by retrying the system call without the unsupported flags.
- Drivers that do not support any exclusion that previously reported -EPERM or -EOPNOTSUPP will now report -EINVAL - this is consistent with the majority and results in userspace perf retrying without exclusion.
All drivers touched by this patchset have been compile tested.
Changes from v1:
- Changed approach from explicitly rejecting events in unsupporting PMU drivers to explicitly advertising a capability in PMU drivers that do support exclusion events
- Added additional information to tools/perf/design.txt
- Rename event_has_exclude_flags to event_has_any_exclude_flag and update commit log to reflect it's a function
Andrew Murray (20):
perf/doc: update design.txt for exclude_{host|guest} flags perf/core: add function to test for event exclusion flags perf/core: add PERF_PMU_CAP_EXCLUDE for exclusion capable PMUs perf/hw_breakpoint: perf/core: advertise PMU exclusion capability
alpha: perf/core: remove unnecessary checks for exclusion
arc: perf/core: advertise PMU exclusion capability
arm: perf: conditionally advertise PMU exclusion capability
arm: perf/core: remove unnecessary checks for exclusion drivers/perf: perf/core: remove unnecessary checks for exclusion drivers/perf: perf/core: remove unnecessary checks for exclusion drivers/perf: perf/core: advertise PMU exclusion capability
mips: perf/core: advertise PMU exclusion capability
powerpc: perf/core: advertise PMU exclusion capability
powerpc: perf/core: remove unnecessary checks for exclusion
s390: perf/events: advertise PMU exclusion capability
sparc: perf/core: advertise PMU exclusion capability
x86: perf/core: remove unnecessary checks for exclusion
x86: perf/core remove unnecessary checks for exclusion
x86: perf/core: advertise PMU exclusion capability perf/core: remove unused perf_flags
arch/alpha/kernel/perf_event.c | 6 ------ arch/arc/kernel/perf_event.c | 1 + arch/arm/mach-imx/mmdc.c | 8 +------- arch/arm/mm/cache-l2x0-pmu.c | 8 -------- arch/mips/kernel/perf_event_mipsxx.c | 1 + arch/powerpc/perf/core-book3s.c | 1 + arch/powerpc/perf/core-fsl-emb.c | 1 + arch/powerpc/perf/hv-24x7.c | 9 --------- arch/powerpc/perf/hv-gpci.c | 9 --------- arch/powerpc/perf/imc-pmu.c | 18 ------------------ arch/s390/kernel/perf_cpum_cf.c | 1 + arch/s390/kernel/perf_cpum_sf.c | 2 ++ arch/sparc/kernel/perf_event.c | 1 + arch/x86/events/amd/ibs.c | 12 ------------ arch/x86/events/amd/iommu.c | 5 ----- arch/x86/events/amd/power.c | 9 +-------- arch/x86/events/amd/uncore.c | 5 ----- arch/x86/events/core.c | 2 ++ arch/x86/events/intel/bts.c | 2 +- arch/x86/events/intel/cstate.c | 8 +------- arch/x86/events/intel/pt.c | 4 +++- arch/x86/events/intel/rapl.c | 8 +------- arch/x86/events/intel/uncore.c | 8 -------- arch/x86/events/intel/uncore_snb.c | 8 +------- arch/x86/events/msr.c | 8 +------- drivers/perf/arm-cci.c | 9 --------- drivers/perf/arm-ccn.c | 5 +---- drivers/perf/arm_dsu_pmu.c | 8 +------- drivers/perf/arm_pmu.c | 15 +++++---------- drivers/perf/arm_spe_pmu.c | 3 ++- drivers/perf/hisilicon/hisi_uncore_pmu.c | 9 --------- drivers/perf/qcom_l2_pmu.c | 8 -------- drivers/perf/qcom_l3_pmu.c | 7 ------- drivers/perf/xgene_pmu.c | 5 ----- include/linux/perf_event.h | 10 ++++++++++ include/uapi/linux/perf_event.h | 2 -- kernel/events/core.c | 9 +++++++++ kernel/events/hw_breakpoint.c | 2 ++ tools/include/uapi/linux/perf_event.h | 2 -- tools/perf/design.txt | 4 ++++ 40 files changed, 54 insertions(+), 189 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 1/20 perf/doc: update design.txt for exclude_{host|guest} flags
Update design.txt to reflect the presence of the exclude_host and exclude_guest perf flags.
--- tools/perf/design.txt | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/design.txt +4 -0
@@ -222,6 +222,10 @@ The 'exclude_user', 'exclude_kernel' and 'exclude_hv' bits provide a way to request that counting of events be restricted to times when the CPU is in user, kernel and/or hypervisor mode. +Furthermore the 'exclude_host' and 'exclude_guest' bits provide a way +to request counting of events restricted to guest and host contexts when +using KVM virtualisation. + The 'mmap' and 'munmap' bits allow recording of PROT_EXEC mmap/munmap operations, these can be used to relate userspace IP addresses to actual code, even after the mapping (or even the whole process) is gone,
Signature · 1 line
2.7.4
Re: [PATCH v2 01/20] perf/doc: update design.txt for exclude_{host|guest} flags
Hi Andrew,
Quoted 4 lines · Andrew Murray
Update design.txt to reflect the presence of the
exclude_hostandexclude_guestperf flags.Signed-off-by Andrew Murray <[email protected]>
Thanks a lot for adding this !
Quoted 9 lines
--- tools/perf/design.txt | 4 ++++ 1 file changed, 4 insertions(+)tools/perf/design.txt +0
-0
tools/perf/design.txt The 'exclude_user', 'exclude_kernel' and 'exclude_hv' bits provide a · line 227
Quoted 6 lines
tools/perf/design.txt +3
-0@@ -222,6 +222,10 @@ The 'exclude_user', 'exclude_kernel' and 'exclude_hv' bits provide a way to request that counting of events be restricted to times when the CPU is in user, kernel and/or hypervisor mode. +Furthermore the 'exclude_host' and 'exclude_guest' bits provide a way +to request counting of events restricted to guest and host contexts when +using KVM virtualisation.
minor nit: could we generalise this to :
"using Linux as the hypervisor".
Otherwise, looks good to me.
Cheers
Suzuki
PATCH v2 2/20 perf/core: add function to test for event exclusion flags
In reply to Andrew MurrayAdd a function that tests if any of the perf event exclusion flags are set on a given event.
--- include/linux/perf_event.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/perf_event.h +9 -0
@@ -1004,6 +1004,15 @@ perf_event__output_id_sample(struct perf_event *event,extern void perf_log_lost_samples (struct perf_event *event,u64 lost); +static inline bool event_has_any_exclude_flag (struct perf_event *event) +{ +struct perf_event_attr *attr = &event->attr; + +return attr->exclude_idle || attr->exclude_user || + attr->exclude_kernel || attr->exclude_hv || + attr->exclude_guest || attr->exclude_host; +} +static inline bool is_sampling_event (struct perf_event *event) {return event->attr.sample_period !=0 ;
Signature · 1 line
2.7.4
PATCH v2 3/20 perf/core: add PERF_PMU_CAP_EXCLUDE for exclusion capable PMUs
In reply to Andrew MurrayMany PMU drivers do not have the capability to exclude counting events that occur in specific contexts such as idle, kernel, guest, etc. These drivers indicate this by returning an error in their event_init upon testing the events attribute flags. This approach is error prone and often inconsistent.
Let's instead allow PMU drivers to advertise their ability to exclude based on context via a new capability: PERF_PMU_CAP_EXCLUDE. This allows the perf core to reject requests for exclusion events where there is no support in the PMU.
--- include/linux/perf_event.h | 1 + kernel/events/core.c | 9 +++++++++ 2 files changed, 10 insertions(+)
include/linux/perf_event.h +1 -0
@@ -244,6 +244,7 @@ struct perf_event;#define PERF_PMU_CAP_EXCLUSIVE 0x10#define PERF_PMU_CAP_ITRACE 0x20#define PERF_PMU_CAP_HETEROGENEOUS_CPUS 0x40 +#define PERF_PMU_CAP_EXCLUDE 0x80/** * struct pmu - generic performance monitoring unit
kernel/events/core.c +9 -0
@@ -9743,6 +9743,15 @@ static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)if (ctx)perf_event_ctx_unlock (event->group_leader, ctx); +if (!ret) { +if (!(pmu->capabilities &PERF_PMU_CAP_EXCLUDE ) && +event_has_any_exclude_flag (event)) { +if (event->destroy) + event->destroy (event); + ret = -EINVAL ; + } + } +if (ret)module_put (pmu->module);
Signature · 1 line
2.7.4
Re: [PATCH v2 03/20] perf/core: add PERF_PMU_CAP_EXCLUDE for exclusion capable PMUs
Hi Andrew,
Quoted 34 lines · Andrew Murray
Many PMU drivers do not have the capability to exclude counting events that occur in specific contexts such as idle, kernel, guest, etc. These drivers indicate this by returning an error in their
event_initupon testing the events attribute flags. This approach is error prone and often inconsistent.Let's instead allow PMU drivers to advertise their ability to exclude based on context via a new capability:
PERF_PMU_CAP_EXCLUDE. This allows the perf core to reject requests for exclusion events where there is no support in the PMU.Signed-off-by Andrew Murray <[email protected]>--- include/linux/perf_event.h | 1 + kernel/events/core.c | 9 +++++++++ 2 files changed, 10 insertions(+)include/linux/perf_event.h +1
-0@@ -244,6 +244,7 @@ struct perf_event;#define PERF_PMU_CAP_EXCLUSIVE 0x10#define PERF_PMU_CAP_ITRACE 0x20#define PERF_PMU_CAP_HETEROGENEOUS_CPUS 0x40 +#define PERF_PMU_CAP_EXCLUDE 0x80/** * struct pmu - generic performance monitoring unit kernel/events/core.c +0
-0
kernel/events/core.c static int perf_try_init_event(struct pmu *pmu, struct perf_event *event) · line 9748
Quoted 6 lines
kernel/events/core.c +3
-0@@ -9743,6 +9743,15 @@ static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)if (ctx)perf_event_ctx_unlock (event->group_leader, ctx); +if (!ret) { +if (!(pmu->capabilities &PERF_PMU_CAP_EXCLUDE ) && +event_has_any_exclude_flag (event)) {
Technically this is a bisection-breaker, since no driver has this capability yet - ideally, this patch should come after all the ones introducing it to the relevant drivers (with the removal of the now-redundant code from the other drivers at the end).
Alternatively, since we already have several other negative capabilities, unless there's a strong feeling against adding any more then it might work out simpler to flip it to PERF_PMU_CAP_NO_EXCLUDE, such that we only need to introduce the core check then directly replace the open-coded event checks with the capability in the appropriate drivers, and need not touch the exclusion-supporting ones at all.
Robin.
Quoted 10 lines
kernel/events/core.c +6
-0+if (event->destroy) + event->destroy (event); + ret = -EINVAL ; + } + } +if (ret)module_put (pmu->module);
Re: [PATCH v2 03/20] perf/core: add PERF_PMU_CAP_EXCLUDE for exclusion capable PMUs
Quoted 38 lines · Robin Murphy
Hi Andrew,
Quoted 35 lines · Andrew Murray
Many PMU drivers do not have the capability to exclude counting events that occur in specific contexts such as idle, kernel, guest, etc. These drivers indicate this by returning an error in their
event_initupon testing the events attribute flags. This approach is error prone and often inconsistent.Let's instead allow PMU drivers to advertise their ability to exclude based on context via a new capability:
PERF_PMU_CAP_EXCLUDE. This allows the perf core to reject requests for exclusion events where there is no support in the PMU.Signed-off-by Andrew Murray <[email protected]>--- include/linux/perf_event.h | 1 + kernel/events/core.c | 9 +++++++++ 2 files changed, 10 insertions(+)include/linux/perf_event.h +1
-0@@ -244,6 +244,7 @@ struct perf_event;#define PERF_PMU_CAP_EXCLUSIVE 0x10#define PERF_PMU_CAP_ITRACE 0x20#define PERF_PMU_CAP_HETEROGENEOUS_CPUS 0x40 +#define PERF_PMU_CAP_EXCLUDE 0x80/** * struct pmu - generic performance monitoring unit kernel/events/core.c +0
-0@@ -9743,6 +9743,15 @@ static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)if (ctx)perf_event_ctx_unlock (event->group_leader, ctx);
Quoted 8 lines
kernel/events/core.c static int perf_try_init_event(struct pmu *pmu, struct perf_event *event) · line 9748
Quoted 3 lines
kernel/events/core.c +3
-0+if (!ret) { +if (!(pmu->capabilities &PERF_PMU_CAP_EXCLUDE ) && +event_has_any_exclude_flag (event)) {Technically this is a bisection-breaker, since no driver has this capability yet - ideally, this patch should come after all the ones introducing it to the relevant drivers (with the removal of the now-redundant code from the other drivers at the end).
Indeed. Thought it is possible to first introduce the capability, update the relevant drivers to advertise it, then add the change to core.c and finally remove the unnecessary error checks as a result of using the new capability. This approach could be bisection-proof.
Quoted 7 lines
Alternatively, since we already have several other negative capabilities, unless there's a strong feeling against adding any more then it might work out simpler to flip it to
PERF_PMU_CAP_NO_EXCLUDE, such that we only need to introduce the core check then directly replace the open-coded event checks with the capability in the appropriate drivers, and need not touch the exclusion-supporting ones at all.
This would certaintly be less risky and invasive (e.g. compare the number of files touched between this v2 and the previous v1).
I'm happy with either approach.
Thanks,
Andrew Murray
Quoted 12 lines
Robin.
Quoted 9 lines
kernel/events/core.c +6
-0+if (event->destroy) + event->destroy (event); + ret = -EINVAL ; + } + } +if (ret)module_put (pmu->module);
PATCH v2 4/20 perf/hw_breakpoint: perf/core: advertise PMU exclusion capability
In reply to Andrew MurrayThe breakpoint PMU has the capability to exclude kernel contexts, let's advertise that we support the PERF_PMU_CAP_EXCLUDE capability so that perf doesn't prevent us from handling events with any exclusion flags set.
--- kernel/events/hw_breakpoint.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/events/hw_breakpoint.c +2 -0
@@ -669,6 +669,8 @@ static struct pmu perf_breakpoint = { .start = hw_breakpoint_start, .stop = hw_breakpoint_stop, .read = hw_breakpoint_pmu_read, + + .capabilities = PERF_PMU_CAP_EXCLUDE, };int __init init_hw_breakpoint (void )
Signature · 1 line
2.7.4
PATCH v2 5/20 alpha: perf/core: remove unnecessary checks for exclusion
In reply to Andrew MurrayAs the Alpha PMU doesn't support context exclusion we do not advertise the PERF_PMU_CAP_EXCLUDE capability. This ensures that perf will prevent us from handling events where any exclusion flags are set. Let's remove the now unnecessary check for exclusion flags.
This change means that __hw_perf_event_init will now also indicate that it doesn't support exclude_host and exclude_guest and will now implicitly return -EINVAL instead of -EPERM. This is likely more desirable as -EPERM will result in a kernel.perf_event_paranoid related warning from the perf userspace utility.
--- arch/alpha/kernel/perf_event.c | 6 ------ 1 file changed, 6 deletions(-)
arch/alpha/kernel/perf_event.c +0 -6
@@ -630,12 +630,6 @@ static int __hw_perf_event_init(struct perf_event *event)return ev; } -/* The EV67 does not support mode exclusion */ -if (attr->exclude_kernel || attr->exclude_user - || attr->exclude_hv || attr->exclude_idle) { -return -EPERM ; - } -/* * We place the event type in event_base here and leave calculation * of the codes to programme the PMU for alpha_pmu_enable() because
Signature · 1 line
2.7.4
PATCH v2 6/20 arc: perf/core: advertise PMU exclusion capability
In reply to Andrew MurrayThe ARC PMU has the capability to exclude events based on context. Let's advertise that we support the PERF_PMU_CAP_EXCLUDE capability to ensure that perf doesn't prevent us from handling events where any exclusion flags are set.
--- arch/arc/kernel/perf_event.c | 1 + 1 file changed, 1 insertion(+)
arch/arc/kernel/perf_event.c +1 -0
@@ -514,6 +514,7 @@ static int arc_pmu_device_probe(struct platform_device *pdev) .start = arc_pmu_start, .stop = arc_pmu_stop, .read = arc_pmu_read, + .capabilities = PERF_PMU_CAP_EXCLUDE, };if (has_interrupts) {
Signature · 1 line
2.7.4
PATCH v2 7/20 arm: perf: conditionally advertise PMU exclusion capability
In reply to Andrew MurrayThe ARM PMU driver can be used to represent a variety of ARM based PMUs. Some of these PMUs provide support for context exclusion, where this is the case we advertise this via the PERF_PMU_CAP_EXCLUDE capability to ensure that perf doesn't prevent us from handling events where any exclusion flags are set.
--- drivers/perf/arm_pmu.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/perf/arm_pmu.c +5 -10
@@ -357,13 +357,6 @@ static irqreturn_t armpmu_dispatch_irq(int irq, void *dev) }static int -event_requires_mode_exclusion (struct perf_event_attr *attr) -{ -return attr->exclude_idle || attr->exclude_user || - attr->exclude_kernel || attr->exclude_hv; -} - -static int __hw_perf_event_init (struct perf_event *event) {struct arm_pmu *armpmu =to_arm_pmu (event->pmu);
@@ -393,9 +386,8 @@ __hw_perf_event_init(struct perf_event *event)/* * Check whether we need to exclude the counter from certain modes. */ -if ((!armpmu->set_event_filter || - armpmu->set_event_filter (hwc, &event->attr)) && -event_requires_mode_exclusion (&event->attr)) { +if (armpmu->set_event_filter && + armpmu->set_event_filter (hwc, &event->attr)) {pr_debug ("ARM performance counters do not support " "mode exclusion\n" );return -EOPNOTSUPP ;
@@ -861,6 +853,9 @@ int armpmu_register(struct arm_pmu *pmu)if (ret)return ret; +if (pmu->set_event_filter) + pmu->pmu.capabilities |=PERF_PMU_CAP_EXCLUDE ; + ret =perf_pmu_register (&pmu->pmu, pmu->name,-1 );if (ret) goto out_destroy;
Signature · 1 line
2.7.4
PATCH v2 8/20 arm: perf/core: remove unnecessary checks for exclusion
In reply to Andrew MurrayFor drivers that do not support context exclusion we do not advertise the PERF_PMU_CAP_EXCLUDE capability. This ensures that perf will prevent us from handling events where any exclusion flags are set. Let's remove the now unnecessary check for exclusion flags.
--- arch/arm/mach-imx/mmdc.c | 8 +------- arch/arm/mm/cache-l2x0-pmu.c | 8 -------- 2 files changed, 1 insertion(+), 15 deletions(-)
arch/arm/mach-imx/mmdc.c +1 -7
@@ -293,13 +293,7 @@ static int mmdc_pmu_event_init(struct perf_event *event)return -EOPNOTSUPP ; } -if (event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_hv || - event->attr.exclude_idle || - event->attr.exclude_host || - event->attr.exclude_guest || - event->attr.sample_period) +if (event->attr.sample_period)return -EINVAL ;if (cfg <0 || cfg >=MMDC_NUM_COUNTERS )
arch/arm/mm/cache-l2x0-pmu.c +0 -8
@@ -314,14 +314,6 @@ static int l2x0_pmu_event_init(struct perf_event *event) event->attach_state & PERF_ATTACH_TASK)return -EINVAL ; -if (event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_hv || - event->attr.exclude_idle || - event->attr.exclude_host || - event->attr.exclude_guest) -return -EINVAL ; -if (event->cpu <0 )return -EINVAL ;
Signature · 1 line
2.7.4
PATCH v2 9/20 drivers/perf: perf/core: remove unnecessary checks for exclusion
In reply to Andrew MurrayFor drivers that do not support context exclusion we do not advertise the PERF_PMU_CAP_EXCLUDE capability. This ensures that perf will prevent us from handling events where any exclusion flags are set. Let's remove the now unnecessary check for exclusion flags.
--- drivers/perf/arm-cci.c | 9 --------- drivers/perf/arm-ccn.c | 5 +---- drivers/perf/arm_dsu_pmu.c | 8 +------- drivers/perf/hisilicon/hisi_uncore_pmu.c | 9 --------- 4 files changed, 2 insertions(+), 29 deletions(-)
drivers/perf/arm-cci.c +0 -9
@@ -1327,15 +1327,6 @@ static int cci_pmu_event_init(struct perf_event *event)if (is_sampling_event (event) || event->attach_state &PERF_ATTACH_TASK )return -EOPNOTSUPP ; -/* We have no filtering of any kind */ -if (event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_hv || - event->attr.exclude_idle || - event->attr.exclude_host || - event->attr.exclude_guest) -return -EINVAL ; -/* * Following the example set by other "uncore" PMUs, we accept any CPU * and rewrite its affinity dynamically rather than having perf core
drivers/perf/arm-ccn.c +1 -4
@@ -741,10 +741,7 @@ static int arm_ccn_pmu_event_init(struct perf_event *event)return -EOPNOTSUPP ; } -if (has_branch_stack (event) || event->attr.exclude_user || - event->attr.exclude_kernel || event->attr.exclude_hv || - event->attr.exclude_idle || event->attr.exclude_host || - event->attr.exclude_guest) { +if (has_branch_stack (event)) {dev_dbg (ccn->dev,"Can't exclude execution levels!\n" );return -EINVAL ; }
drivers/perf/arm_dsu_pmu.c +1 -7
@@ -562,13 +562,7 @@ static int dsu_pmu_event_init(struct perf_event *event)return -EINVAL ; } -if (has_branch_stack (event) || - event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_hv || - event->attr.exclude_idle || - event->attr.exclude_host || - event->attr.exclude_guest) { +if (has_branch_stack (event)) {dev_dbg (dsu_pmu->pmu.dev,"Can't support filtering\n" );return -EINVAL ; }
drivers/perf/hisilicon/hisi_uncore_pmu.c +0 -9
@@ -142,15 +142,6 @@ int hisi_uncore_pmu_event_init(struct perf_event *event)if (is_sampling_event (event) || event->attach_state &PERF_ATTACH_TASK )return -EOPNOTSUPP ; -/* counters do not have these bits */ -if (event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_host || - event->attr.exclude_guest || - event->attr.exclude_hv || - event->attr.exclude_idle) -return -EINVAL ; -/* * The uncore counters not specific to any CPU, so cannot * support per-task
Signature · 1 line
2.7.4
PATCH v2 10/20 drivers/perf: perf/core: remove unnecessary checks for exclusion
In reply to Andrew MurrayFor drivers that do not support context exclusion we do not advertise the PERF_PMU_CAP_EXCLUDE capability. This ensures that perf will prevent us from handling events where any exclusion flags are set. Let's remove the now unnecessary check for exclusion flags.
This change means that qcom_{l2|l3}_pmu will now also indicate that they do not support exclude_{host|guest} and that xgene_pmu does not also support exclude_idle and exclude_hv.
Note that for qcom_l2_pmu we now implictly return -EINVAL instead of -EOPNOTSUPP. This change will result in the perf userspace utility retrying the perf_event_open system call with fallback event attributes that do not fail.
--- drivers/perf/qcom_l2_pmu.c | 8 -------- drivers/perf/qcom_l3_pmu.c | 7 ------- drivers/perf/xgene_pmu.c | 5 ----- 3 files changed, 20 deletions(-)
drivers/perf/qcom_l2_pmu.c +0 -8
@@ -509,14 +509,6 @@ static int l2_cache_event_init(struct perf_event *event)return -EOPNOTSUPP ; } -/* We cannot filter accurately so we just don't allow it. */ -if (event->attr.exclude_user || event->attr.exclude_kernel || - event->attr.exclude_hv || event->attr.exclude_idle) { -dev_dbg_ratelimited (&l2cache_pmu->pdev->dev, -"Can't exclude execution levels\n" ); -return -EOPNOTSUPP ; - } -if (((L2_EVT_GROUP (event->attr.config) >L2_EVT_GROUP_MAX ) || ((event->attr.config & ~L2_EVT_MASK ) !=0 )) && (event->attr.config !=L2CYCLE_CTR_RAW_CODE )) {
drivers/perf/qcom_l3_pmu.c +0 -7
@@ -495,13 +495,6 @@ static int qcom_l3_cache__event_init(struct perf_event *event)return -ENOENT ;/* -* There are no per-counter mode filters in the PMU. -*/ -if (event->attr.exclude_user || event->attr.exclude_kernel || - event->attr.exclude_hv || event->attr.exclude_idle) -return -EINVAL ; - -/* * Sampling not supported since these events are not core-attributable. */ if (hwc->sample_period)
drivers/perf/xgene_pmu.c +0 -5
@@ -914,11 +914,6 @@ static int xgene_perf_event_init(struct perf_event *event)if (is_sampling_event (event) || event->attach_state &PERF_ATTACH_TASK )return -EINVAL ; -/* SOC counters do not have usr/os/guest/host bits */ -if (event->attr.exclude_user || event->attr.exclude_kernel || - event->attr.exclude_host || event->attr.exclude_guest) -return -EINVAL ; -if (event->cpu <0 )return -EINVAL ;/*
Signature · 1 line
2.7.4
PATCH v2 11/20 drivers/perf: perf/core: advertise PMU exclusion capability
In reply to Andrew MurrayThe arm_pse PMU has the capability to exclude events based on context. Let's advertise that we support the PERF_PMU_CAP_EXCLUDE capability to ensure that perf doesn't prevent us from handling events where any exclusion flags are set.
--- drivers/perf/arm_spe_pmu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/perf/arm_spe_pmu.c +2 -1
@@ -902,7 +902,8 @@ static int arm_spe_pmu_perf_init(struct arm_spe_pmu *spe_pmu) spe_pmu->pmu = (struct pmu ) { .module =THIS_MODULE , - .capabilities =PERF_PMU_CAP_EXCLUSIVE |PERF_PMU_CAP_ITRACE , + .capabilities =PERF_PMU_CAP_EXCLUSIVE |PERF_PMU_CAP_ITRACE | +PERF_PMU_CAP_EXCLUDE , .attr_groups = arm_spe_pmu_attr_groups,/* * We hitch a ride on the software context here, so that
Signature · 1 line
2.7.4
PATCH v2 12/20 mips: perf/core: advertise PMU exclusion capability
In reply to Andrew MurrayThe MIPS PMU has the capability to exclude events based on context. Let's advertise that we support the PERF_PMU_CAP_EXCLUDE capability to ensure that perf doesn't prevent us from handling events where any exclusion flags are set.
--- arch/mips/kernel/perf_event_mipsxx.c | 1 + 1 file changed, 1 insertion(+)
arch/mips/kernel/perf_event_mipsxx.c +1 -0
@@ -670,6 +670,7 @@ static struct pmu pmu = { .start = mipspmu_start, .stop = mipspmu_stop, .read = mipspmu_read, + .capabilities = PERF_PMU_CAP_EXCLUDE, };static unsigned int mipspmu_perf_event_encode (const struct mips_perf_event *pev)
Signature · 1 line
2.7.4
PATCH v2 13/20 powerpc: perf/core: advertise PMU exclusion capability
In reply to Andrew MurrayFor PowerPC PMUs that have the capability to exclude events based on context. Let's advertise that we support the PERF_PMU_CAP_EXCLUDE capability to ensure that perf doesn't prevent us from handling events where any exclusion flags are set.
--- arch/powerpc/perf/core-book3s.c | 1 + arch/powerpc/perf/core-fsl-emb.c | 1 + 2 files changed, 2 insertions(+)
arch/powerpc/perf/core-book3s.c +1 -0
@@ -2007,6 +2007,7 @@ static struct pmu power_pmu = { .commit_txn = power_pmu_commit_txn, .event_idx = power_pmu_event_idx, .sched_task = power_pmu_sched_task, + .capabilities = PERF_PMU_CAP_EXCLUDE, };/*
arch/powerpc/perf/core-fsl-emb.c +1 -0
@@ -596,6 +596,7 @@ static struct pmu fsl_emb_pmu = { .start = fsl_emb_pmu_start, .stop = fsl_emb_pmu_stop, .read = fsl_emb_pmu_read, + .capabilities = PERF_PMU_CAP_EXCLUDE, };/*
Signature · 1 line
2.7.4
PATCH v2 14/20 powerpc: perf/core: remove unnecessary checks for exclusion
In reply to Andrew MurrayFor PowerPC PMUs that do not support context exclusion we do not advertise the PERF_PMU_CAP_EXCLUDE capability. This ensures that perf will prevent us from handling events where any exclusion flags are set. Let's remove the now unnecessary check for exclusion flags.
--- arch/powerpc/perf/hv-24x7.c | 9 --------- arch/powerpc/perf/hv-gpci.c | 9 --------- arch/powerpc/perf/imc-pmu.c | 18 ------------------ 3 files changed, 36 deletions(-)
arch/powerpc/perf/hv-24x7.c +0 -9
@@ -1306,15 +1306,6 @@ static int h_24x7_event_init(struct perf_event *event)return -EINVAL ; } -/* unsupported modes and filters */ -if (event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_hv || - event->attr.exclude_idle || - event->attr.exclude_host || - event->attr.exclude_guest) -return -EINVAL ; -/* no branch sampling */ if (has_branch_stack (event))return -EOPNOTSUPP ;
arch/powerpc/perf/hv-gpci.c +0 -9
@@ -232,15 +232,6 @@ static int h_gpci_event_init(struct perf_event *event)return -EINVAL ; } -/* unsupported modes and filters */ -if (event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_hv || - event->attr.exclude_idle || - event->attr.exclude_host || - event->attr.exclude_guest) -return -EINVAL ; -/* no branch sampling */ if (has_branch_stack (event))return -EOPNOTSUPP ;
arch/powerpc/perf/imc-pmu.c +0 -18
@@ -473,15 +473,6 @@ static int nest_imc_event_init(struct perf_event *event)if (event->hw.sample_period)return -EINVAL ; -/* unsupported modes and filters */ -if (event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_hv || - event->attr.exclude_idle || - event->attr.exclude_host || - event->attr.exclude_guest) -return -EINVAL ; -if (event->cpu <0 )return -EINVAL ;
@@ -748,15 +739,6 @@ static int core_imc_event_init(struct perf_event *event)if (event->hw.sample_period)return -EINVAL ; -/* unsupported modes and filters */ -if (event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_hv || - event->attr.exclude_idle || - event->attr.exclude_host || - event->attr.exclude_guest) -return -EINVAL ; -if (event->cpu <0 )return -EINVAL ;
Signature · 1 line
2.7.4
PATCH v2 15/20 s390: perf/events: advertise PMU exclusion capability
In reply to Andrew MurrayThe s390 cpum_cf and cpum_sf PMUs have the capability to exclude events based on context. Let's advertise that we support the PERF_PMU_CAP_EXCLUDE capability to ensure that perf doesn't prevent us from handling events where any exclusion flags are set.
--- arch/s390/kernel/perf_cpum_cf.c | 1 + arch/s390/kernel/perf_cpum_sf.c | 2 ++ 2 files changed, 3 insertions(+)
arch/s390/kernel/perf_cpum_cf.c +1 -0
@@ -667,6 +667,7 @@ static struct pmu cpumf_pmu = { .start_txn = cpumf_pmu_start_txn, .commit_txn = cpumf_pmu_commit_txn, .cancel_txn = cpumf_pmu_cancel_txn, + .capabilities = PERF_PMU_CAP_EXCLUDE, };static int cpumf_pmf_setup (unsigned int cpu,int flags)
arch/s390/kernel/perf_cpum_sf.c +2 -0
@@ -1885,6 +1885,8 @@ static struct pmu cpumf_sampling = { .setup_aux = aux_buffer_setup, .free_aux = aux_buffer_free, + + .capabilities = PERF_PMU_CAP_EXCLUDE, }; static void cpumf_measurement_alert(struct ext_code ext_code,
Signature · 1 line
2.7.4
Re: [PATCH v2 15/20] s390: perf/events: advertise PMU exclusion capability
Quoted 10 lines · Andrew Murray
The s390
cpum_cfandcpum_sfPMUs have the capability to exclude events based on context. Let's advertise that we support thePERF_PMU_CAP_EXCLUDEcapability to ensure that perf doesn't prevent us from handling events where any exclusion flags are set.Signed-off-by Andrew Murray <[email protected]>--- arch/s390/kernel/perf_cpum_cf.c | 1 + arch/s390/kernel/perf_cpum_sf.c | 2 ++ 2 files changed, 3 insertions(+)
PATCH v2 16/20 sparc: perf/core: advertise PMU exclusion capability
In reply to Andrew MurrayThe SPARC PMU has the capability to exclude events based on context
- let's advertise that we support the PERF_PMU_CAP_EXCLUDE
capability to ensure that perf doesn't prevent us from handling events where any exclusion flags are set.
--- arch/sparc/kernel/perf_event.c | 1 + 1 file changed, 1 insertion(+)
arch/sparc/kernel/perf_event.c +1 -0
@@ -1571,6 +1571,7 @@ static struct pmu pmu = { .start_txn = sparc_pmu_start_txn, .cancel_txn = sparc_pmu_cancel_txn, .commit_txn = sparc_pmu_commit_txn, + .capabilities = PERF_PMU_CAP_EXCLUDE, };void perf_event_print_debug (void )
Signature · 1 line
2.7.4
Re: [PATCH v2 16/20] sparc: perf/core: advertise PMU exclusion capability
From: Andrew Murray <[email protected]>
Date: Mon, 26 Nov 2018 11:12:32 +0000
Quoted 6 lines
The SPARC PMU has the capability to exclude events based on context
- let's advertise that we support thePERF_PMU_CAP_EXCLUDE
capability to ensure that perf doesn't prevent us from handling events where any exclusion flags are set.Signed-off-by Andrew Murray <[email protected]>
PATCH v2 17/20 x86: perf/core: remove unnecessary checks for exclusion
In reply to Andrew MurrayFor drivers that do not support context exclusion we do not advertise the PERF_PMU_CAP_EXCLUDE capability. This ensures that perf will prevent us from handling events where any exclusion flags are set. Let's remove the now unnecessary check for exclusion flags.
--- arch/x86/events/amd/ibs.c | 12 ------------ arch/x86/events/amd/power.c | 9 +-------- arch/x86/events/intel/cstate.c | 8 +------- arch/x86/events/intel/rapl.c | 8 +------- arch/x86/events/intel/uncore_snb.c | 8 +------- arch/x86/events/msr.c | 8 +------- 6 files changed, 5 insertions(+), 48 deletions(-)
arch/x86/events/amd/ibs.c +0 -12
@@ -253,15 +253,6 @@ static int perf_ibs_precise_event(struct perf_event *event, u64 *config)return -EOPNOTSUPP ; } -static const struct perf_event_attr ibs_notsupp = { - .exclude_user =1 , - .exclude_kernel =1 , - .exclude_hv =1 , - .exclude_idle =1 , - .exclude_host =1 , - .exclude_guest =1 , -}; -static int perf_ibs_init (struct perf_event *event) {struct hw_perf_event *hwc = &event->hw;
@@ -282,9 +273,6 @@ static int perf_ibs_init(struct perf_event *event)if (event->pmu != &perf_ibs->pmu)return -ENOENT ; -if (perf_flags (&event->attr) &perf_flags (&ibs_notsupp)) -return -EINVAL ; -if (config & ~perf_ibs->config_mask)return -EINVAL ;
arch/x86/events/amd/power.c +1 -8
@@ -136,14 +136,7 @@ static int pmu_event_init(struct perf_event *event)return -ENOENT ;/* Unsupported modes and filters. */ -if (event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_hv || - event->attr.exclude_idle || - event->attr.exclude_host || - event->attr.exclude_guest || -/* no sampling */ - event->attr.sample_period) +if (event->attr.sample_period)return -EINVAL ;if (cfg !=AMD_POWER_EVENTSEL_PKG )
arch/x86/events/intel/cstate.c +1 -7
@@ -280,13 +280,7 @@ static int cstate_pmu_event_init(struct perf_event *event)return -ENOENT ;/* unsupported modes and filters */ -if (event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_hv || - event->attr.exclude_idle || - event->attr.exclude_host || - event->attr.exclude_guest || - event->attr.sample_period)/* no sampling */ +if (event->attr.sample_period)/* no sampling */ return -EINVAL ;if (event->cpu <0 )
arch/x86/events/intel/rapl.c +1 -7
@@ -397,13 +397,7 @@ static int rapl_pmu_event_init(struct perf_event *event)return -EINVAL ;/* unsupported modes and filters */ -if (event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_hv || - event->attr.exclude_idle || - event->attr.exclude_host || - event->attr.exclude_guest || - event->attr.sample_period)/* no sampling */ +if (event->attr.sample_period)/* no sampling */ return -EINVAL ;/* must be done before validate_group */
arch/x86/events/intel/uncore_snb.c +1 -7
@@ -374,13 +374,7 @@ static int snb_uncore_imc_event_init(struct perf_event *event)return -EINVAL ;/* unsupported modes and filters */ -if (event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_hv || - event->attr.exclude_idle || - event->attr.exclude_host || - event->attr.exclude_guest || - event->attr.sample_period)/* no sampling */ +if (event->attr.sample_period)/* no sampling */ return -EINVAL ;/*
arch/x86/events/msr.c +1 -7
@@ -160,13 +160,7 @@ static int msr_event_init(struct perf_event *event)return -ENOENT ;/* unsupported modes and filters */ -if (event->attr.exclude_user || - event->attr.exclude_kernel || - event->attr.exclude_hv || - event->attr.exclude_idle || - event->attr.exclude_host || - event->attr.exclude_guest || - event->attr.sample_period)/* no sampling */ +if (event->attr.sample_period)/* no sampling */ return -EINVAL ;if (cfg >=PERF_MSR_EVENT_MAX )
Signature · 1 line
2.7.4
PATCH v2 18/20 x86: perf/core remove unnecessary checks for exclusion
In reply to Andrew MurrayFor x86 PMUs that do not support context exclusion we do not advertise the PERF_PMU_CAP_EXCLUDE capability. This ensures that perf will prevent us from handling events where any exclusion flags are set. Let's remove the now unnecessary check for exclusion flags.
This change means that amd/iommu and amd/uncore will now also indicate that they do not support exclude_{hv|idle} and intel/uncore that it does not support exclude_{guest|host}.
--- arch/x86/events/amd/iommu.c | 5 ----- arch/x86/events/amd/uncore.c | 5 ----- arch/x86/events/intel/uncore.c | 8 -------- 3 files changed, 18 deletions(-)
arch/x86/events/amd/iommu.c +0 -5
@@ -223,11 +223,6 @@ static int perf_iommu_event_init(struct perf_event *event)if (is_sampling_event (event) || event->attach_state &PERF_ATTACH_TASK )return -EINVAL ; -/* IOMMU counters do not have usr/os/guest/host bits */ -if (event->attr.exclude_user || event->attr.exclude_kernel || - event->attr.exclude_host || event->attr.exclude_guest) -return -EINVAL ; -if (event->cpu <0 )return -EINVAL ;
arch/x86/events/amd/uncore.c +0 -5
@@ -201,11 +201,6 @@ static int amd_uncore_event_init(struct perf_event *event)if (is_sampling_event (event) || event->attach_state &PERF_ATTACH_TASK )return -EINVAL ; -/* NB and Last level cache counters do not have usr/os/guest/host bits */ -if (event->attr.exclude_user || event->attr.exclude_kernel || - event->attr.exclude_host || event->attr.exclude_guest) -return -EINVAL ; -/* and we do not enable counter overflow interrupts */ hwc->config = event->attr.config &AMD64_RAW_EVENT_MASK_NB ; hwc->idx =-1 ;
arch/x86/events/intel/uncore.c +0 -8
@@ -695,14 +695,6 @@ static int uncore_pmu_event_init(struct perf_event *event)if (pmu->func_id <0 )return -ENOENT ; -/* -* Uncore PMU does measure at all privilege level all the time. -* So it doesn't make sense to specify any exclude bits. -*/ -if (event->attr.exclude_user || event->attr.exclude_kernel || - event->attr.exclude_hv || event->attr.exclude_idle) -return -EINVAL ; -/* Sampling not supported yet */ if (hwc->sample_period)return -EINVAL ;
Signature · 1 line
2.7.4
PATCH v2 19/20 x86: perf/core: advertise PMU exclusion capability
In reply to Andrew MurrayFor PMUs that have the capability to exclude events based on context. Let's advertise that we support the PERF_PMU_CAP_EXCLUDE capability to ensure that perf doesn't prevent us from handling events where any exclusion flags are set.
--- arch/x86/events/core.c | 2 ++ arch/x86/events/intel/bts.c | 2 +- arch/x86/events/intel/pt.c | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-)
arch/x86/events/core.c +2 -0
@@ -2297,6 +2297,8 @@ static struct pmu pmu = { .event_idx = x86_pmu_event_idx, .sched_task = x86_pmu_sched_task, .task_ctx_size = sizeof(struct x86_perf_task_context), + + .capabilities = PERF_PMU_CAP_EXCLUDE, }; void arch_perf_update_userpage(struct perf_event *event,
arch/x86/events/intel/bts.c +1 -1
@@ -601,7 +601,7 @@ static __init int bts_init(void) } bts_pmu.capabilities =PERF_PMU_CAP_AUX_NO_SG |PERF_PMU_CAP_ITRACE | -PERF_PMU_CAP_EXCLUSIVE ; +PERF_PMU_CAP_EXCLUSIVE |PERF_PMU_CAP_EXCLUDE ; bts_pmu.task_ctx_nr = perf_sw_context; bts_pmu.event_init = bts_event_init; bts_pmu.add = bts_event_add;
arch/x86/events/intel/pt.c +3 -1
@@ -1516,7 +1516,9 @@ static __init int pt_init(void) pt_pmu.pmu.capabilities =PERF_PMU_CAP_AUX_NO_SG |PERF_PMU_CAP_AUX_SW_DOUBLEBUF ; - pt_pmu.pmu.capabilities |=PERF_PMU_CAP_EXCLUSIVE |PERF_PMU_CAP_ITRACE ; + pt_pmu.pmu.capabilities =PERF_PMU_CAP_EXCLUSIVE | +PERF_PMU_CAP_ITRACE | +PERF_PMU_CAP_EXCLUDE ; pt_pmu.pmu.attr_groups = pt_attr_groups; pt_pmu.pmu.task_ctx_nr = perf_sw_context; pt_pmu.pmu.event_init = pt_event_init;
Signature · 1 line
2.7.4
PATCH v2 20/20 perf/core: remove unused perf_flags
In reply to Andrew MurrayNow that perf_flags is not used we remove it.
--- include/uapi/linux/perf_event.h | 2 -- tools/include/uapi/linux/perf_event.h | 2 -- 2 files changed, 4 deletions(-)
include/uapi/linux/perf_event.h +0 -2
@@ -445,8 +445,6 @@ struct perf_event_query_bpf {__u32 ids[0 ]; }; -#define perf_flags (attr) (*(&(attr)->read_format + 1)) -/* * Ioctls that can be done on a perf event fd: */
tools/include/uapi/linux/perf_event.h +0 -2
@@ -445,8 +445,6 @@ struct perf_event_query_bpf {__u32 ids[0 ]; }; -#define perf_flags (attr) (*(&(attr)->read_format + 1)) -/* * Ioctls that can be done on a perf event fd: */
Signature · 1 line
2.7.4