Message ID | 1544114849-47266-1-git-send-email-andrew.murray@arm.com |
---|---|
Headers | show |
Series | perf/core: Generalise event exclusion checking | expand |
On Thu, Dec 06, 2018 at 04:47:17PM +0000, Andrew Murray wrote: > 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 inability to exclude > based on context via a new capability: PERF_PMU_CAP_NO_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. For the bits under arch/arm/ and drivers/perf: Acked-by: Will Deacon <will.deacon@arm.com> Note that I've queued the TX2 uncore PMU for 4.21 [1], which could also benefit from your new flag. Will [1] https://git.kernel.org/pub/scm/linux/kernel/git/will/linux.git/commit/?h=for-next/perf&id=69c32972d59388c041268e8206e8eb1acff29b9a
Andrew Murray <andrew.murray@arm.com> writes: > For PowerPC PMUs that do not support context exclusion let's > advertise the PERF_PMU_CAP_NO_EXCLUDE capability. This ensures that > perf will prevent us from handling events where any exclusion flags > are set. Let's also remove the now unnecessary check for exclusion > flags. > > Signed-off-by: Andrew Murray <andrew.murray@arm.com> > --- > arch/powerpc/perf/hv-24x7.c | 10 +--------- > arch/powerpc/perf/hv-gpci.c | 10 +--------- > arch/powerpc/perf/imc-pmu.c | 19 +------------------ > 3 files changed, 3 insertions(+), 36 deletions(-) Looks good. Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc) cheers > diff --git a/arch/powerpc/perf/hv-24x7.c b/arch/powerpc/perf/hv-24x7.c > index 72238ee..d2b8e60 100644 > --- a/arch/powerpc/perf/hv-24x7.c > +++ b/arch/powerpc/perf/hv-24x7.c > @@ -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; > @@ -1577,6 +1568,7 @@ static struct pmu h_24x7_pmu = { > .start_txn = h_24x7_event_start_txn, > .commit_txn = h_24x7_event_commit_txn, > .cancel_txn = h_24x7_event_cancel_txn, > + .capabilities = PERF_PMU_CAP_NO_EXCLUDE, > }; > > static int hv_24x7_init(void) > diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c > index 43fabb3..735e77b 100644 > --- a/arch/powerpc/perf/hv-gpci.c > +++ b/arch/powerpc/perf/hv-gpci.c > @@ -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; > @@ -285,6 +276,7 @@ static struct pmu h_gpci_pmu = { > .start = h_gpci_event_start, > .stop = h_gpci_event_stop, > .read = h_gpci_event_update, > + .capabilities = PERF_PMU_CAP_NO_EXCLUDE, > }; > > static int hv_gpci_init(void) > diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c > index 1fafc32b..1dbb0ee 100644 > --- a/arch/powerpc/perf/imc-pmu.c > +++ b/arch/powerpc/perf/imc-pmu.c > @@ -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; > > @@ -1069,6 +1051,7 @@ static int update_pmu_ops(struct imc_pmu *pmu) > pmu->pmu.stop = imc_event_stop; > pmu->pmu.read = imc_event_update; > pmu->pmu.attr_groups = pmu->attr_groups; > + pmu->pmu.capabilities = PERF_PMU_CAP_NO_EXCLUDE; > pmu->attr_groups[IMC_FORMAT_ATTR] = &imc_format_group; > > switch (pmu->domain) { > -- > 2.7.4
On 06/12/18 10:17 PM, Andrew Murray wrote: > For PowerPC PMUs that do not support context exclusion let's > advertise the PERF_PMU_CAP_NO_EXCLUDE capability. This ensures that > perf will prevent us from handling events where any exclusion flags > are set. Let's also remove the now unnecessary check for exclusion > flags. Reviewed-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com> > > Signed-off-by: Andrew Murray <andrew.murray@arm.com> > --- > arch/powerpc/perf/hv-24x7.c | 10 +--------- > arch/powerpc/perf/hv-gpci.c | 10 +--------- > arch/powerpc/perf/imc-pmu.c | 19 +------------------ > 3 files changed, 3 insertions(+), 36 deletions(-) > > diff --git a/arch/powerpc/perf/hv-24x7.c b/arch/powerpc/perf/hv-24x7.c > index 72238ee..d2b8e60 100644 > --- a/arch/powerpc/perf/hv-24x7.c > +++ b/arch/powerpc/perf/hv-24x7.c > @@ -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; > @@ -1577,6 +1568,7 @@ static struct pmu h_24x7_pmu = { > .start_txn = h_24x7_event_start_txn, > .commit_txn = h_24x7_event_commit_txn, > .cancel_txn = h_24x7_event_cancel_txn, > + .capabilities = PERF_PMU_CAP_NO_EXCLUDE, > }; > > static int hv_24x7_init(void) > diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c > index 43fabb3..735e77b 100644 > --- a/arch/powerpc/perf/hv-gpci.c > +++ b/arch/powerpc/perf/hv-gpci.c > @@ -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; > @@ -285,6 +276,7 @@ static struct pmu h_gpci_pmu = { > .start = h_gpci_event_start, > .stop = h_gpci_event_stop, > .read = h_gpci_event_update, > + .capabilities = PERF_PMU_CAP_NO_EXCLUDE, > }; > > static int hv_gpci_init(void) > diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c > index 1fafc32b..1dbb0ee 100644 > --- a/arch/powerpc/perf/imc-pmu.c > +++ b/arch/powerpc/perf/imc-pmu.c > @@ -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; > > @@ -1069,6 +1051,7 @@ static int update_pmu_ops(struct imc_pmu *pmu) > pmu->pmu.stop = imc_event_stop; > pmu->pmu.read = imc_event_update; > pmu->pmu.attr_groups = pmu->attr_groups; > + pmu->pmu.capabilities = PERF_PMU_CAP_NO_EXCLUDE; > pmu->attr_groups[IMC_FORMAT_ATTR] = &imc_format_group; > > switch (pmu->domain) {
On Fri, Dec 07, 2018 at 05:25:17PM +0000, Will Deacon wrote: > On Thu, Dec 06, 2018 at 04:47:17PM +0000, Andrew Murray wrote: > > 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 inability to exclude > > based on context via a new capability: PERF_PMU_CAP_NO_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. > > For the bits under arch/arm/ and drivers/perf: > > Acked-by: Will Deacon <will.deacon@arm.com> > > Note that I've queued the TX2 uncore PMU for 4.21 [1], which could also > benefit from your new flag. Ah thanks for pointing this out, I'll send a patch in due course. Thanks, Andrwe Murray > > Will > > [1] > https://git.kernel.org/pub/scm/linux/kernel/git/will/linux.git/commit/?h=for-next/perf&id=69c32972d59388c041268e8206e8eb1acff29b9a