From: Rob Herring <robh@kernel.org> Date: 2021-09-14 20:48:04
Another version of arm64 userspace counter access support.
The arm64 support departs from the x86 implementation by requiring the user
to explicitly request user access (via attr.config1) and only enables access
for task bound events. Since usage is explicitly requested, access is
enabled at perf_event_open() rather than on mmap() as that greatly
simplifies the implementation. Rather than trying to lock down the access
as the x86 implementation has been doing, we can start with only a limited
use case enabled and later expand it if needed.
I've run this version thru Vince's perf tests[12] with arm64 support added.
I wish I'd found these tests sooner...
This originally resurrected Raphael's series[1] to enable userspace counter
access on arm64. My previous versions are here[2][3][4][5][6][7][8][9][10].
A git branch is here[11].
Changes in v10:
- Drop changing event_mapped/event_unmapped ops to run on the event's
current CPU. This won't work for x86 where any thread sharing an mm
context will have rdpmc enabled. Instead, simply track user access
events when added to a perf context and use that count.
- Documentation for the sysctl disable
Changes in v9:
- Reworked x86 and perf core to handle user access tracking and call
.event_mapped() and .event_unmapped() on the CPU with the event like
other changes to events.
- Use sysctl instead of sysfs to disable user access.
Changes in v8:
- Restrict user access to thread bound events which simplifies the
implementation. A couple of perf core changes (patches 1 and 2) are
needed to do this.
- Always require the user to request userspace access.
Changes in v7:
- Handling of dirty counter leakage and reworking of context switch and
user access enabling. The .sched_task hook and undef instruction handler
are now utilized. (Patch 3)
- Add a userspace disable switch like x86. (Patch 5)
Changes in v6:
- Reworking of the handling of 64-bit counters and user access. There's
a new config1 flag to request user access. This takes priority over
the 64-bit flag and the user will get the maximum size the h/w
supports without chaining.
- The libperf evsel mmap struct is stored in its own xyarray
- New tests for user 64-bit and 32-bit counters
- Rebase to v5.12-rc2
Changes in v5:
- Limit enabling/disabling access to CPUs associated with the PMU
(supported_cpus) and with the mm_struct matching current->active_mm.
The x86 method of using mm_cpumask doesn't work for arm64 as it is not
updated.
- Only set cap_user_rdpmc if event is on current cpu. See patch 2.
- Create an mmap for every event in an evsel. This results in some changes
to the libperf mmap API from the last version.
- Rebase to v5.11-rc2
Changes in v4:
- Dropped 'arm64: pmu: Add hook to handle pmu-related undefined instructions'.
The onus is on userspace to pin itself to a homogeneous subset of CPUs
and avoid any aborts on heterogeneous systems, so the hook is not needed.
- Make perf_evsel__mmap() take pages rather than bytes for size
- Fix building arm64 heterogeneous test.
Changes in v3:
- Dropped removing x86 rdpmc test until libperf tests can run via 'perf test'
- Added verbose prints for tests
- Split adding perf_evsel__mmap() to separate patch
The following changes to the arm64 support have been made compared to
Raphael's last version:
The major change is support for heterogeneous systems with some
restrictions. Specifically, userspace must pin itself to like CPUs, open
a specific PMU by type, and use h/w specific events. The tests have been
reworked to demonstrate this.
Chained events are not supported. The problem with supporting chained
events was there's no way to distinguish between a chained event and a
native 64-bit counter. We could add some flag, but do self monitoring
processes really need that? Native 64-bit counters are supported if the
PMU h/w has support. As there's already an explicit ABI to request 64-bit
counters, userspace can request 64-bit counters and if user
access is not enabled, then it must retry with 32-bit counters.
Prior versions broke the build on arm32 (surprisingly never caught by
0-day). As a result, event_mapped and event_unmapped implementations have
been moved into the arm64 code.
There was a bug in that pmc_width was not set in the user page. The tests
now check for this.
The documentation has been converted to rST. I've added sections on
chained events and heterogeneous.
Rob
[1] https://lore.kernel.org/r/20190822144220.27860-1-raphael.gault@arm.com/
[2] https://lore.kernel.org/r/20200707205333.624938-1-robh@kernel.org/
[3] https://lore.kernel.org/r/20200828205614.3391252-1-robh@kernel.org/
[4] https://lore.kernel.org/r/20200911215118.2887710-1-robh@kernel.org/
[5] https://lore.kernel.org/r/20201001140116.651970-1-robh@kernel.org/
[6] https://lore.kernel.org/r/20210114020605.3943992-1-robh@kernel.org/
[7] https://lore.kernel.org/r/20210311000837.3630499-1-robh@kernel.org/
[8] https://lore.kernel.org/r/20210420031511.2348977-1-robh@kernel.org/
[9] https://lore.kernel.org/r/20210517195405.3079458-1-robh@kernel.org/
[10] https://lore.kernel.org/all/20210806225123.1958497-1-robh@kernel.org/
[11] git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git arm64-user-perf-event-v10
[12] https://github.com/deater/perf_event_tests
Raphael Gault (1):
Documentation: arm64: Document PMU counters access from userspace
Rob Herring (4):
x86: perf: Move RDPMC event flag to a common definition
perf: Add a counter for number of user access events in context
arm64: perf: Add userspace counter access disable switch
arm64: perf: Enable PMU counter userspace access for perf event
Documentation/admin-guide/sysctl/kernel.rst | 11 ++
Documentation/arm64/perf.rst | 73 +++++++++++-
arch/arm64/kernel/perf_event.c | 126 ++++++++++++++++++--
arch/x86/events/core.c | 10 +-
arch/x86/events/perf_event.h | 2 +-
include/linux/perf_event.h | 3 +
kernel/events/core.c | 4 +
7 files changed, 215 insertions(+), 14 deletions(-)
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Rob Herring <robh@kernel.org> Date: 2021-09-14 20:48:06
In preparation to enable user counter access on arm64 and to move some
of the user access handling to perf core, create a common event flag for
user counter access and convert x86 to use it.
Since the architecture specific flags start at the LSB, starting at the
MSB for common flags.
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <redacted>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Kan Liang <redacted>
Cc: Thomas Gleixner <redacted>
Cc: Borislav Petkov <bp@alien8.de>
Cc: x86@kernel.org
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: linux-perf-users@vger.kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
---
arch/x86/events/core.c | 10 +++++-----
arch/x86/events/perf_event.h | 2 +-
include/linux/perf_event.h | 2 ++
3 files changed, 8 insertions(+), 6 deletions(-)
From: Rob Herring <robh@kernel.org> Date: 2021-09-14 20:48:08
For controlling user space counter access, we need to know if any event
in a context (currently scheduled or not) is using user space counters.
Walking the context's list of events would be slow, so add a counter
to track this.
Signed-off-by: Rob Herring <robh@kernel.org>
---
v10:
- Re-added.
- Maintain the count in the perf core
v9:
- Dropped
v8:
- new patch
---
include/linux/perf_event.h | 1 +
kernel/events/core.c | 4 ++++
2 files changed, 5 insertions(+)
From: Rob Herring <robh@kernel.org> Date: 2021-09-14 20:48:12
Like x86, some users may want to disable userspace PMU counter
altogether. Add a sysctl 'perf_user_access' file to control userspace
counter access. The default is '0' which is disabled. Writing '1'
enables access.
Note that x86 also supports writing '2' to globally enable user access.
As there's not existing userspace support to worry about, this shouldn't
be necessary for Arm. It could be added later if the need arises.
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <redacted>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: linux-perf-users@vger.kernel.org
Acked-by: Will Deacon <will@kernel.org>
Signed-off-by: Rob Herring <robh@kernel.org>
---
v10:
- Add documentation
- Use a custom handler (needed on the next patch)
v9:
- Use sysctl instead of sysfs attr
- Default to disabled
v8:
- New patch
---
Documentation/admin-guide/sysctl/kernel.rst | 11 +++++++++
arch/arm64/kernel/perf_event.c | 27 +++++++++++++++++++++
2 files changed, 38 insertions(+)
@@ -905,6 +905,17 @@ enabled, otherwise writing to this file will return ``-EBUSY``. The default value is 8.+perf_user_access (arm64 only)+=================================++Controls user space access for reading perf event counters. When set to 1,+user space can read performance monitor counter registers directly.++The default value is 0 (access disabled).++See Documentation/arm64/perf.rst for more information.++ pid_max =======
From: Rob Herring <robh@kernel.org> Date: 2021-09-14 20:48:14
Arm PMUs can support direct userspace access of counters which allows for
low overhead (i.e. no syscall) self-monitoring of tasks. The same feature
exists on x86 called 'rdpmc'. Unlike x86, userspace access will only be
enabled for thread bound events. This could be extended if needed, but
simplifies the implementation and reduces the chances for any
information leaks (which the x86 implementation suffers from).
PMU EL0 access will be enabled when an event with userspace access is
part of the thread's context. This includes when the event is not
scheduled on the PMU. There's some additional overhead clearing
dirty counters when access is enabled in order to prevent leaking
disabled counter data from other tasks.
Unlike x86, enabling of userspace access must be requested with a new
attr bit: config1:1. If the user requests userspace access and 64-bit
counters, then chaining will be disabled and the user will get the
maximum size counter the underlying h/w can support. The modes for
config1 are as follows:
config1 = 0 : user access disabled and always 32-bit
config1 = 1 : user access disabled and always 64-bit (using chaining if needed)
config1 = 2 : user access enabled and always 32-bit
config1 = 3 : user access enabled and counter size matches underlying counter.
Based on work by Raphael Gault [off-list ref], but has been
completely re-written.
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <redacted>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
---
v10:
- Don't control enabling user access based on mmap(). Changing the
event_(un)mapped to run on the event's cpu doesn't work for x86.
Triggering on mmap() doesn't limit access in any way and complicates
the implementation.
- Drop dirty counter tracking and just clear all unused counters.
- Make the sysctl immediately disable access via IPI.
- Merge armv8pmu_event_is_chained() and armv8pmu_event_can_chain()
v9:
- Enabling/disabling of user access is now controlled in .start() and
mmap hooks which are now called on CPUs that the event is on.
Depends on rework of perf core and x86 RDPMC code posted here:
https://lore.kernel.org/lkml/20210728230230.1911468-1-robh@kernel.org/
v8:
- Rework user access tracking and enabling to be done on task
context changes using sched_task() hook. This avoids the need for any
IPIs, mm_switch hooks or undef instr handler.
- Only support user access when explicitly requested on open and
only for a thread bound events. This avoids some of the information
leaks x86 has and simplifies the implementation.
v7:
- Clear disabled counters when user access is enabled for a task to
avoid leaking other tasks counter data.
- Rework context switch handling utilizing sched_task callback
- Add armv8pmu_event_can_chain() helper
- Rework config1 flags handling structure
- Use ARMV8_IDX_CYCLE_COUNTER_USER define for remapped user cycle
counter index
v6:
- Add new attr.config1 rdpmc bit for userspace to hint it wants
userspace access when also requesting 64-bit counters.
v5:
- Only set cap_user_rdpmc if event is on current cpu
- Limit enabling/disabling access to CPUs associated with the PMU
(supported_cpus) and with the mm_struct matching current->active_mm.
v2:
- Move mapped/unmapped into arm64 code. Fixes arm32.
- Rebase on cap_user_time_short changes
Changes from Raphael's v4:
- Drop homogeneous check
- Disable access for chained counters
- Set pmc_width in user page
---
arch/arm64/kernel/perf_event.c | 99 +++++++++++++++++++++++++++++++---
1 file changed, 92 insertions(+), 7 deletions(-)
@@ -995,9 +1050,23 @@ static int __armv8_pmuv3_map_event(struct perf_event *event,&armv8_pmuv3_perf_cache_map,ARMV8_PMU_EVTYPE_EVENT);-if(armv8pmu_event_is_64bit(event))+/*+*Atthispoint,thecounterisnotassigned.Ifa64-bitcounteris+*requested,wemustmakesuretheh/whas64-bitcountersifweset+*theeventsizeto64-bitbecausechainingisnotsupportedwith+*userspaceaccess.ThismaystillfaillateroniftheCPUcycle+*counterisinuse.+*/+if(armv8pmu_event_is_64bit(event)&&+(!armv8pmu_event_want_user_access(event)||+armv8pmu_has_long_event(armpmu)||(hw_event_id==ARMV8_PMUV3_PERFCTR_CPU_CYCLES)))event->hw.flags|=ARMPMU_EVT_64BIT;+/* Userspace counter access only enabled if requested and a per task event */+if(sysctl_perf_user_access&&armv8pmu_event_want_user_access(event)&&+(event->attach_state&PERF_ATTACH_TASK))+event->hw.flags|=PERF_EVENT_FLAG_USER_READ_CNT;+/* Only expose micro/arch events supported by this PMU */if((hw_event_id>0)&&(hw_event_id<ARMV8_PMUV3_MAX_COMMON_EVENTS)&&test_bit(hw_event_id,armpmu->pmceid_bitmap)){
@@ -1106,6 +1175,11 @@ static int armv8pmu_probe_pmu(struct arm_pmu *cpu_pmu)returnprobe.present?0:-ENODEV;}+staticvoidarmv8pmu_disable_user_access_ipi(void*unused)+{+armv8pmu_disable_user_access();+}+intarmv8pmu_proc_user_access_handler(structctl_table*table,intwrite,void*buffer,size_t*lenp,loff_t*ppos){
@@ -1113,6 +1187,7 @@ int armv8pmu_proc_user_access_handler(struct ctl_table *table, int write,if(ret||!write||sysctl_perf_user_access)returnret;+on_each_cpu(armv8pmu_disable_user_access_ipi,NULL,1);return0;}
From: Rob Herring <robh@kernel.org> Date: 2021-09-14 20:48:18
From: Raphael Gault <redacted>
Add documentation to describe the access to the pmu hardware counters from
userspace.
Signed-off-by: Raphael Gault <redacted>
Signed-off-by: Rob Herring <robh@kernel.org>
---
v10:
- Add details on perf_user_access sysctl
v9:
- No change
v8:
- Reword that config1:1 must always be set to request user access
v7:
- Merge into existing arm64 perf.rst
v6:
- Update the chained event section with attr.config1 details
v2:
- Update links to test examples
Changes from Raphael's v4:
- Convert to rSt
- Update chained event status
- Add section for heterogeneous systems
---
Documentation/arm64/perf.rst | 73 +++++++++++++++++++++++++++++++++++-
1 file changed, 72 insertions(+), 1 deletion(-)
@@ -88,3 +91,71 @@ exclude_host. However when using !exclude_hv there is a small blackout window at the guest entry/exit where host events are not captured. On VHE systems there are no blackout windows.++Perf Userspace PMU Hardware Counter Access+==========================================++Overview+--------+The perf userspace tool relies on the PMU to monitor events. It offers an+abstraction layer over the hardware counters since the underlying+implementation is cpu-dependent.+Arm64 allows userspace tools to have access to the registers storing the+hardware counters' values directly.++This targets specifically self-monitoring tasks in order to reduce the overhead+by directly accessing the registers without having to go through the kernel.++How-to+------+The focus is set on the armv8 PMUv3 which makes sure that the access to the pmu+registers is enabled and that the userspace has access to the relevant+information in order to use them.++In order to have access to the hardware counters, the global sysctl+kernel/perf_user_access must first be enabled:++..code-block:: sh++ echo 1 > /proc/sys/kernel/perf_user_access++It is necessary to open the event using the perf tool interface with config1:1+attr bit set: the sys_perf_event_open syscall returns a fd which can+subsequently be used with the mmap syscall in order to retrieve a page of memory+containing information about the event. The PMU driver uses this page to expose+to the user the hardware counter's index and other necessary data. Using this+index enables the user to access the PMU registers using the `mrs` instruction.++The userspace access is supported in libperf using the perf_evsel__mmap()+and perf_evsel__read() functions. See `tools/lib/perf/tests/test-evsel.c`_ for+an example.++About heterogeneous systems+---------------------------+On heterogeneous systems such as big.LITTLE, userspace PMU counter access can+only be enabled when the tasks are pinned to a homogeneous subset of cores and+the corresponding PMU instance is opened by specifying the 'type' attribute.+The use of generic event types is not supported in this case.++Have a look at `tools/perf/arch/arm64/tests/user-events.c`_ for an example. It+can be run using the perf tool to check that the access to the registers works+correctly from userspace:++..code-block:: sh++ perf test -v user++About chained events and 64-bit counters+----------------------------------------+Chained events are not supported in conjunction with userspace counter+access. If a 64-bit counter is requested (attr.config1:0) with userspace+access (attr.config1:1 set), then counter chaining will be disabled. The+'pmc_width' in the user page will indicate the actual width of the+counter which could be only 32-bits depending on the event and PMU+features.++.. Links+.._tools/perf/arch/arm64/tests/user-events.c:+ https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/arch/arm64/tests/user-events.c+.._tools/lib/perf/tests/test-evsel.c:+ https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/lib/perf/tests/test-evsel.c
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Rob Herring <robh@kernel.org> Date: 2021-09-27 20:46:30
On Tue, Sep 14, 2021 at 3:48 PM Rob Herring [off-list ref] wrote:
Another version of arm64 userspace counter access support.
Any chance someone can review this... Ideally before the end of the
cycle this time so there's time for me to respin if needed.
The arm64 support departs from the x86 implementation by requiring the user
to explicitly request user access (via attr.config1) and only enables access
for task bound events. Since usage is explicitly requested, access is
enabled at perf_event_open() rather than on mmap() as that greatly
simplifies the implementation. Rather than trying to lock down the access
as the x86 implementation has been doing, we can start with only a limited
use case enabled and later expand it if needed.
I've run this version thru Vince's perf tests[12] with arm64 support added.
I wish I'd found these tests sooner...
This originally resurrected Raphael's series[1] to enable userspace counter
access on arm64. My previous versions are here[2][3][4][5][6][7][8][9][10].
A git branch is here[11].
Changes in v10:
- Drop changing event_mapped/event_unmapped ops to run on the event's
current CPU. This won't work for x86 where any thread sharing an mm
context will have rdpmc enabled. Instead, simply track user access
events when added to a perf context and use that count.
- Documentation for the sysctl disable
Changes in v9:
- Reworked x86 and perf core to handle user access tracking and call
.event_mapped() and .event_unmapped() on the CPU with the event like
other changes to events.
- Use sysctl instead of sysfs to disable user access.
Changes in v8:
- Restrict user access to thread bound events which simplifies the
implementation. A couple of perf core changes (patches 1 and 2) are
needed to do this.
- Always require the user to request userspace access.
Changes in v7:
- Handling of dirty counter leakage and reworking of context switch and
user access enabling. The .sched_task hook and undef instruction handler
are now utilized. (Patch 3)
- Add a userspace disable switch like x86. (Patch 5)
Changes in v6:
- Reworking of the handling of 64-bit counters and user access. There's
a new config1 flag to request user access. This takes priority over
the 64-bit flag and the user will get the maximum size the h/w
supports without chaining.
- The libperf evsel mmap struct is stored in its own xyarray
- New tests for user 64-bit and 32-bit counters
- Rebase to v5.12-rc2
Changes in v5:
- Limit enabling/disabling access to CPUs associated with the PMU
(supported_cpus) and with the mm_struct matching current->active_mm.
The x86 method of using mm_cpumask doesn't work for arm64 as it is not
updated.
- Only set cap_user_rdpmc if event is on current cpu. See patch 2.
- Create an mmap for every event in an evsel. This results in some changes
to the libperf mmap API from the last version.
- Rebase to v5.11-rc2
Changes in v4:
- Dropped 'arm64: pmu: Add hook to handle pmu-related undefined instructions'.
The onus is on userspace to pin itself to a homogeneous subset of CPUs
and avoid any aborts on heterogeneous systems, so the hook is not needed.
- Make perf_evsel__mmap() take pages rather than bytes for size
- Fix building arm64 heterogeneous test.
Changes in v3:
- Dropped removing x86 rdpmc test until libperf tests can run via 'perf test'
- Added verbose prints for tests
- Split adding perf_evsel__mmap() to separate patch
The following changes to the arm64 support have been made compared to
Raphael's last version:
The major change is support for heterogeneous systems with some
restrictions. Specifically, userspace must pin itself to like CPUs, open
a specific PMU by type, and use h/w specific events. The tests have been
reworked to demonstrate this.
Chained events are not supported. The problem with supporting chained
events was there's no way to distinguish between a chained event and a
native 64-bit counter. We could add some flag, but do self monitoring
processes really need that? Native 64-bit counters are supported if the
PMU h/w has support. As there's already an explicit ABI to request 64-bit
counters, userspace can request 64-bit counters and if user
access is not enabled, then it must retry with 32-bit counters.
Prior versions broke the build on arm32 (surprisingly never caught by
0-day). As a result, event_mapped and event_unmapped implementations have
been moved into the arm64 code.
There was a bug in that pmc_width was not set in the user page. The tests
now check for this.
The documentation has been converted to rST. I've added sections on
chained events and heterogeneous.
Rob
[1] https://lore.kernel.org/r/20190822144220.27860-1-raphael.gault@arm.com/
[2] https://lore.kernel.org/r/20200707205333.624938-1-robh@kernel.org/
[3] https://lore.kernel.org/r/20200828205614.3391252-1-robh@kernel.org/
[4] https://lore.kernel.org/r/20200911215118.2887710-1-robh@kernel.org/
[5] https://lore.kernel.org/r/20201001140116.651970-1-robh@kernel.org/
[6] https://lore.kernel.org/r/20210114020605.3943992-1-robh@kernel.org/
[7] https://lore.kernel.org/r/20210311000837.3630499-1-robh@kernel.org/
[8] https://lore.kernel.org/r/20210420031511.2348977-1-robh@kernel.org/
[9] https://lore.kernel.org/r/20210517195405.3079458-1-robh@kernel.org/
[10] https://lore.kernel.org/all/20210806225123.1958497-1-robh@kernel.org/
[11] git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git arm64-user-perf-event-v10
[12] https://github.com/deater/perf_event_tests
Raphael Gault (1):
Documentation: arm64: Document PMU counters access from userspace
Rob Herring (4):
x86: perf: Move RDPMC event flag to a common definition
perf: Add a counter for number of user access events in context
arm64: perf: Add userspace counter access disable switch
arm64: perf: Enable PMU counter userspace access for perf event
Documentation/admin-guide/sysctl/kernel.rst | 11 ++
Documentation/arm64/perf.rst | 73 +++++++++++-
arch/arm64/kernel/perf_event.c | 126 ++++++++++++++++++--
arch/x86/events/core.c | 10 +-
arch/x86/events/perf_event.h | 2 +-
include/linux/perf_event.h | 3 +
kernel/events/core.c | 4 +
7 files changed, 215 insertions(+), 14 deletions(-)
--
2.30.2
From: Mark Rutland <mark.rutland@arm.com> Date: 2021-10-13 17:25:59
Hi Rob,
On Tue, Sep 14, 2021 at 03:47:56PM -0500, Rob Herring wrote:
In preparation to enable user counter access on arm64 and to move some
of the user access handling to perf core, create a common event flag for
user counter access and convert x86 to use it.
Since the architecture specific flags start at the LSB, starting at the
MSB for common flags.
Minor comments below (definition rename, and a comment block), but with
those:
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Peter, are you happy with this from the x86 side?
quoted hunk
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <redacted>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Kan Liang <redacted>
Cc: Thomas Gleixner <redacted>
Cc: Borislav Petkov <bp@alien8.de>
Cc: x86@kernel.org
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: linux-perf-users@vger.kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
---
arch/x86/events/core.c | 10 +++++-----
arch/x86/events/perf_event.h | 2 +-
include/linux/perf_event.h | 2 ++
3 files changed, 8 insertions(+), 6 deletions(-)
I realise this matches the style of PERF_HES_* and PERF_EF_*. but could
we please arrange this like the PERF_PMU_CAP_* definitions, and move
this immediately before the struct hw_perf_event defintion, with a
comment block, e.g.
/*
* hw_perf_event::flag values
*
* PERF_EVENT_FLAG_ARCH bits are reserved for architecture-specific
* usage.
*/
#define PERF_EVENT_FLAG_ARCH 0x0000ffff
#define PERF_EVENT_FLAG_USER_READ_CNT 0x80000000
Thanks,
Mark.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Mark Rutland <mark.rutland@arm.com> Date: 2021-10-13 17:26:44
On Tue, Sep 14, 2021 at 03:47:57PM -0500, Rob Herring wrote:
For controlling user space counter access, we need to know if any event
in a context (currently scheduled or not) is using user space counters.
Walking the context's list of events would be slow, so add a counter
to track this.
Signed-off-by: Rob Herring <robh@kernel.org>
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Mark.
quoted hunk
---
v10:
- Re-added.
- Maintain the count in the perf core
v9:
- Dropped
v8:
- new patch
---
include/linux/perf_event.h | 1 +
kernel/events/core.c | 4 ++++
2 files changed, 5 insertions(+)
From: Mark Rutland <mark.rutland@arm.com> Date: 2021-10-13 17:30:29
On Tue, Sep 14, 2021 at 03:47:58PM -0500, Rob Herring wrote:
Like x86, some users may want to disable userspace PMU counter
altogether. Add a sysctl 'perf_user_access' file to control userspace
counter access. The default is '0' which is disabled. Writing '1'
enables access.
Note that x86 also supports writing '2' to globally enable user access.
For clarity it might be worth mentioning that on x86 this is controlled
by the PMU's `rdpmc` sysfs attribute, i.e.
Note that x86 supports globally enabling user access by writing '2' to
/sys/bus/event_source/devices/cpu/rdpmc
quoted hunk
As there's not existing userspace support to worry about, this shouldn't
be necessary for Arm. It could be added later if the need arises.
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <redacted>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: linux-perf-users@vger.kernel.org
Acked-by: Will Deacon <will@kernel.org>
Signed-off-by: Rob Herring <robh@kernel.org>
---
v10:
- Add documentation
- Use a custom handler (needed on the next patch)
v9:
- Use sysctl instead of sysfs attr
- Default to disabled
v8:
- New patch
---
Documentation/admin-guide/sysctl/kernel.rst | 11 +++++++++
arch/arm64/kernel/perf_event.c | 27 +++++++++++++++++++++
2 files changed, 38 insertions(+)
@@ -905,6 +905,17 @@ enabled, otherwise writing to this file will return ``-EBUSY``. The default value is 8.+perf_user_access (arm64 only)+=================================++Controls user space access for reading perf event counters. When set to 1,+user space can read performance monitor counter registers directly.++The default value is 0 (access disabled).++See Documentation/arm64/perf.rst for more information.
Looking at the existing perf sysctls:
# ls /proc/sys/kernel/perf*
/proc/sys/kernel/perf_cpu_time_max_percent
/proc/sys/kernel/perf_event_max_contexts_per_stack
/proc/sys/kernel/perf_event_max_sample_rate
/proc/sys/kernel/perf_event_max_stack
/proc/sys/kernel/perf_event_mlock_kb
/proc/sys/kernel/perf_event_paranoid
I see that other than `perf_cpu_time_max_percent`, we've used
`perf_event_` as the prefix, and I suspect we should do the same here,
but I guess it may not matter either way.
@@ -1104,6 +1106,29 @@ static int armv8pmu_probe_pmu(struct arm_pmu *cpu_pmu)returnprobe.present?0:-ENODEV;}+intarmv8pmu_proc_user_access_handler(structctl_table*table,intwrite,+void*buffer,size_t*lenp,loff_t*ppos)+{+intret=proc_dointvec_minmax(table,write,buffer,lenp,ppos);+if(ret||!write||sysctl_perf_user_access)+returnret;++return0;+}
Maybe this is needed in the next patch, but the if statement is entirely
redundant on this patch and looks really odd.
Can we please either:
1) Use proc_dointvec_minmax() directly in this patch (which is what Will
Acked in v9) and add the wrapper in the next patch when we need it.
2) make this:
| int armv8pmu_proc_user_access_handler(struct ctl_table *table, int write,
| void *buffer, size_t *lenp, loff_t *ppos)
| {
| return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
| }
... and flesh it out in the next patch.
With either of those two options (and regardless of whether the
attribute is renamed):
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Thanks,
Mark.
From: Mark Rutland <mark.rutland@arm.com> Date: 2021-10-13 17:32:35
Hi Rob,
On Mon, Sep 27, 2021 at 03:46:15PM -0500, Rob Herring wrote:
On Tue, Sep 14, 2021 at 3:48 PM Rob Herring [off-list ref] wrote:
quoted
Another version of arm64 userspace counter access support.
Any chance someone can review this... Ideally before the end of the
cycle this time so there's time for me to respin if needed.
Sorry for the long delay on this.
I've given some comments on patches 1-3 (which are trivial, and I think
we can fix up when applying if necessary), and I've started
reviewing/testing patch 4; I'll try to follow up with more comments
tomorrow.
Thanks,
Mark.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Mark Rutland <mark.rutland@arm.com> Date: 2021-10-14 16:58:36
Hi Rob,
This looks pretty good!
I have one largish query below, and otherwise only trivialities that I'm
happy to fix up.
On Tue, Sep 14, 2021 at 03:47:59PM -0500, Rob Herring wrote:
Arm PMUs can support direct userspace access of counters which allows for
low overhead (i.e. no syscall) self-monitoring of tasks. The same feature
exists on x86 called 'rdpmc'. Unlike x86, userspace access will only be
enabled for thread bound events. This could be extended if needed, but
simplifies the implementation and reduces the chances for any
information leaks (which the x86 implementation suffers from).
PMU EL0 access will be enabled when an event with userspace access is
part of the thread's context. This includes when the event is not
scheduled on the PMU. There's some additional overhead clearing
dirty counters when access is enabled in order to prevent leaking
disabled counter data from other tasks.
Unlike x86, enabling of userspace access must be requested with a new
attr bit: config1:1. If the user requests userspace access and 64-bit
counters, then chaining will be disabled and the user will get the
maximum size counter the underlying h/w can support. The modes for
config1 are as follows:
config1 = 0 : user access disabled and always 32-bit
config1 = 1 : user access disabled and always 64-bit (using chaining if needed)
config1 = 2 : user access enabled and always 32-bit
config1 = 3 : user access enabled and counter size matches underlying counter.
We probably need to note somewhere (i.e. in the next patch) that we mean
*logically* 32-bit, and this could be a biased 64-bit counter, so
userspace needs to treat the upper 32-bits of counters as UNKNOWN.
For the `config1 = 3` case (potentially) overriding the usual long
semantic, I'm struggling to understand why we need that rather than
forcing the use of a 64-bit counter, because in that case:
* For a CPU_CYCLES event:
__armv8_pmuv3_map_event() will always pick 64-bits
get_event_idx() may fail to allocate a 64-bit counter.
* For other events:
__armv8_pmuv3_map_event() will pick 32/64 based on long counter
support
get_event_idx() will only fail if there are no counters free.
Whereas if __armv8_pmuv3_map_event() returned an error for the latter
when long counter support is not implemented, we'd have consistent
`long` semantics, and the CPU_CYCLES behaviour would be identical.
What's the rationale for `3` leaving the choice to the kernel?
If the problem is discoverability, I'd be happy to add something to
sysfs to describe whether the PMU has long event support.
quoted hunk
Based on work by Raphael Gault [off-list ref], but has been
completely re-written.
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <redacted>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
---
v10:
- Don't control enabling user access based on mmap(). Changing the
event_(un)mapped to run on the event's cpu doesn't work for x86.
Triggering on mmap() doesn't limit access in any way and complicates
the implementation.
- Drop dirty counter tracking and just clear all unused counters.
- Make the sysctl immediately disable access via IPI.
- Merge armv8pmu_event_is_chained() and armv8pmu_event_can_chain()
v9:
- Enabling/disabling of user access is now controlled in .start() and
mmap hooks which are now called on CPUs that the event is on.
Depends on rework of perf core and x86 RDPMC code posted here:
https://lore.kernel.org/lkml/20210728230230.1911468-1-robh@kernel.org/
v8:
- Rework user access tracking and enabling to be done on task
context changes using sched_task() hook. This avoids the need for any
IPIs, mm_switch hooks or undef instr handler.
- Only support user access when explicitly requested on open and
only for a thread bound events. This avoids some of the information
leaks x86 has and simplifies the implementation.
v7:
- Clear disabled counters when user access is enabled for a task to
avoid leaking other tasks counter data.
- Rework context switch handling utilizing sched_task callback
- Add armv8pmu_event_can_chain() helper
- Rework config1 flags handling structure
- Use ARMV8_IDX_CYCLE_COUNTER_USER define for remapped user cycle
counter index
v6:
- Add new attr.config1 rdpmc bit for userspace to hint it wants
userspace access when also requesting 64-bit counters.
v5:
- Only set cap_user_rdpmc if event is on current cpu
- Limit enabling/disabling access to CPUs associated with the PMU
(supported_cpus) and with the mm_struct matching current->active_mm.
v2:
- Move mapped/unmapped into arm64 code. Fixes arm32.
- Rebase on cap_user_time_short changes
Changes from Raphael's v4:
- Drop homogeneous check
- Disable access for chained counters
- Set pmc_width in user page
---
arch/arm64/kernel/perf_event.c | 99 +++++++++++++++++++++++++++++++---
1 file changed, 92 insertions(+), 7 deletions(-)
Above this, could we please add:
| static inline bool armv8pmu_event_has_user_read(struct perf_event *event)
| {
| return event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT;
| }
... and use that where we look at PERF_EVENT_FLAG_USER_READ_CNT?
+{
+ if (!sysctl_perf_user_access ||
+ !(event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT))
+ return 0;
+
+ /*
+ * We remap the cycle counter index to 32 to
+ * match the offset applied to the rest of
+ * the counter indices.
+ */
+ if (event->hw.idx == ARMV8_IDX_CYCLE_COUNTER)
+ return ARMV8_IDX_CYCLE_COUNTER_USER;
+
+ return event->hw.idx;
+}
+
/*
* Add an event filter to a given event.
*/
@@ -995,9 +1050,23 @@ static int __armv8_pmuv3_map_event(struct perf_event *event, &armv8_pmuv3_perf_cache_map, ARMV8_PMU_EVTYPE_EVENT);- if (armv8pmu_event_is_64bit(event))+ /*+ * At this point, the counter is not assigned. If a 64-bit counter is+ * requested, we must make sure the h/w has 64-bit counters if we set+ * the event size to 64-bit because chaining is not supported with+ * userspace access. This may still fail later on if the CPU cycle+ * counter is in use.+ */+ if (armv8pmu_event_is_64bit(event) &&+ (!armv8pmu_event_want_user_access(event) ||+ armv8pmu_has_long_event(armpmu) || (hw_event_id == ARMV8_PMUV3_PERFCTR_CPU_CYCLES))) event->hw.flags |= ARMPMU_EVT_64BIT;
If we can follow my suggestion in reply to the cover text, we can make
this:
if (armv8pmu_event_is_64bit(event))
event->hw.flags |= ARMPMU_EVT_64BIT;
/*
* User events must be allocated into a single counter, and so
* must not be chained.
*
* Most 64-bit events require long counter support, but 64-bit
* CPU_CYCLES events can be placed into the dedicated cycle
* counter when this is free.
*
if (armv8pmu_event_want_user_access()) {
if (armv8pmu_event_is_64bit(event) &&
(hw_event_id != ARMV8_PMUV3_PERFCTR_CPU_CYCLES) &&
!armv8pmu_has_long_event(armpmu))
return -EINVAL;
}
+ /* Userspace counter access only enabled if requested and a per task event */
+ if (sysctl_perf_user_access && armv8pmu_event_want_user_access(event) &&
+ (event->attach_state & PERF_ATTACH_TASK))
+ event->hw.flags |= PERF_EVENT_FLAG_USER_READ_CNT;
Can we please explicitly reject !PERF_ATTACH_TASK case?
If the user requested something we don't intend to support, I'd rather
return -EINVAL here, rather than continue on.
Thanks,
Mark.
quoted hunk
+
/* Only expose micro/arch events supported by this PMU */
if ((hw_event_id > 0) && (hw_event_id < ARMV8_PMUV3_MAX_COMMON_EVENTS)
&& test_bit(hw_event_id, armpmu->pmceid_bitmap)) {
From: Rob Herring <robh@kernel.org> Date: 2021-10-14 19:25:05
On Thu, Oct 14, 2021 at 11:58 AM Mark Rutland [off-list ref] wrote:
Hi Rob,
This looks pretty good!
I have one largish query below, and otherwise only trivialities that I'm
happy to fix up.
On Tue, Sep 14, 2021 at 03:47:59PM -0500, Rob Herring wrote:
quoted
Arm PMUs can support direct userspace access of counters which allows for
low overhead (i.e. no syscall) self-monitoring of tasks. The same feature
exists on x86 called 'rdpmc'. Unlike x86, userspace access will only be
enabled for thread bound events. This could be extended if needed, but
simplifies the implementation and reduces the chances for any
information leaks (which the x86 implementation suffers from).
PMU EL0 access will be enabled when an event with userspace access is
part of the thread's context. This includes when the event is not
scheduled on the PMU. There's some additional overhead clearing
dirty counters when access is enabled in order to prevent leaking
disabled counter data from other tasks.
Unlike x86, enabling of userspace access must be requested with a new
attr bit: config1:1. If the user requests userspace access and 64-bit
counters, then chaining will be disabled and the user will get the
maximum size counter the underlying h/w can support. The modes for
config1 are as follows:
config1 = 0 : user access disabled and always 32-bit
config1 = 1 : user access disabled and always 64-bit (using chaining if needed)
config1 = 2 : user access enabled and always 32-bit
config1 = 3 : user access enabled and counter size matches underlying counter.
We probably need to note somewhere (i.e. in the next patch) that we mean
*logically* 32-bit, and this could be a biased 64-bit counter, so
userspace needs to treat the upper 32-bits of counters as UNKNOWN.
Okay, though this detail doesn't matter if the user uses the correct
read loop (now in libperf).
For the `config1 = 3` case (potentially) overriding the usual long
semantic, I'm struggling to understand why we need that rather than
forcing the use of a 64-bit counter, because in that case:
* For a CPU_CYCLES event:
__armv8_pmuv3_map_event() will always pick 64-bits
get_event_idx() may fail to allocate a 64-bit counter.
* For other events:
__armv8_pmuv3_map_event() will pick 32/64 based on long counter
support
get_event_idx() will only fail if there are no counters free.
Whereas if __armv8_pmuv3_map_event() returned an error for the latter
when long counter support is not implemented, we'd have consistent
`long` semantics, and the CPU_CYCLES behaviour would be identical.
What's the rationale for `3` leaving the choice to the kernel?
It's the give me the maximum sized counter the h/w can support choice.
That's easier for userspace to implement. Bit 1 is more of a hint that
the user wants userspace access rather than a requirement.
If the problem is discoverability, I'd be happy to add something to
sysfs to describe whether the PMU has long event support.
Checking sysfs or a try for 64-bit support then fall back to 32-bit
support isn't much difference.
Keep in mind that x86 always succeeds here. Every userspace user will
have to add whatever dance we create here. For example, each libperf
test with user access (there's only 2 in my tree, but there's a series
adding more) has to have an '#ifdef __aarch64__' for whatever we do
here. I was seeking to minimize that. Right now, that's just a set
config1 to 0x3. Also, note that libperf will opportunistically use a
userspace read instead of read(). The user just has to mmap the event
and libperf will use a userspace read when enabled which ultimately
depends on what the mmapped page says.
[...]
quoted
@@ -995,9 +1050,23 @@ static int __armv8_pmuv3_map_event(struct perf_event *event, &armv8_pmuv3_perf_cache_map, ARMV8_PMU_EVTYPE_EVENT);- if (armv8pmu_event_is_64bit(event))+ /*+ * At this point, the counter is not assigned. If a 64-bit counter is+ * requested, we must make sure the h/w has 64-bit counters if we set+ * the event size to 64-bit because chaining is not supported with+ * userspace access. This may still fail later on if the CPU cycle+ * counter is in use.+ */+ if (armv8pmu_event_is_64bit(event) &&+ (!armv8pmu_event_want_user_access(event) ||+ armv8pmu_has_long_event(armpmu) || (hw_event_id == ARMV8_PMUV3_PERFCTR_CPU_CYCLES))) event->hw.flags |= ARMPMU_EVT_64BIT;
If we can follow my suggestion in reply to the cover text, we can make
this:
if (armv8pmu_event_is_64bit(event))
event->hw.flags |= ARMPMU_EVT_64BIT;
/*
* User events must be allocated into a single counter, and so
* must not be chained.
*
* Most 64-bit events require long counter support, but 64-bit
* CPU_CYCLES events can be placed into the dedicated cycle
* counter when this is free.
*
if (armv8pmu_event_want_user_access()) {
if (armv8pmu_event_is_64bit(event) &&
(hw_event_id != ARMV8_PMUV3_PERFCTR_CPU_CYCLES) &&
!armv8pmu_has_long_event(armpmu))
return -EINVAL;
}
quoted
+ /* Userspace counter access only enabled if requested and a per task event */
+ if (sysctl_perf_user_access && armv8pmu_event_want_user_access(event) &&
+ (event->attach_state & PERF_ATTACH_TASK))
+ event->hw.flags |= PERF_EVENT_FLAG_USER_READ_CNT;
Can we please explicitly reject !PERF_ATTACH_TASK case?
If the user requested something we don't intend to support, I'd rather
return -EINVAL here, rather than continue on.
This is similar to the 64-bit case though I'm somewhat less concerned
here given per cpu events aren't too useful in this case and the setup
is a bit different already.
Rob
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Rob Herring <robh@kernel.org> Date: 2021-10-15 15:53:34
On Thu, Oct 14, 2021 at 11:58 AM Mark Rutland [off-list ref] wrote:
Hi Rob,
This looks pretty good!
I have one largish query below, and otherwise only trivialities that I'm
happy to fix up.
On Tue, Sep 14, 2021 at 03:47:59PM -0500, Rob Herring wrote:
Above this, could we please add:
| static inline bool armv8pmu_event_has_user_read(struct perf_event *event)
| {
| return event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT;
| }
... and use that where we look at PERF_EVENT_FLAG_USER_READ_CNT?
Sure, but as this is a common flag now, I should probably make that a
common function in linux/perf_event.h and have x86 code use it too.
Rob
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Mark Rutland <mark.rutland@arm.com> Date: 2021-10-19 15:28:43
Hi Rob,
On Thu, Oct 14, 2021 at 02:24:46PM -0500, Rob Herring wrote:
On Thu, Oct 14, 2021 at 11:58 AM Mark Rutland [off-list ref] wrote:
quoted
On Tue, Sep 14, 2021 at 03:47:59PM -0500, Rob Herring wrote:
For the `config1 = 3` case (potentially) overriding the usual long
semantic, I'm struggling to understand why we need that rather than
forcing the use of a 64-bit counter, because in that case:
* For a CPU_CYCLES event:
__armv8_pmuv3_map_event() will always pick 64-bits
get_event_idx() may fail to allocate a 64-bit counter.
* For other events:
__armv8_pmuv3_map_event() will pick 32/64 based on long counter
support
get_event_idx() will only fail if there are no counters free.
Whereas if __armv8_pmuv3_map_event() returned an error for the latter
when long counter support is not implemented, we'd have consistent
`long` semantics, and the CPU_CYCLES behaviour would be identical.
What's the rationale for `3` leaving the choice to the kernel?
It's the give me the maximum sized counter the h/w can support choice.
That's easier for userspace to implement. Bit 1 is more of a hint that
the user wants userspace access rather than a requirement.
quoted
If the problem is discoverability, I'd be happy to add something to
sysfs to describe whether the PMU has long event support.
Checking sysfs or a try for 64-bit support then fall back to 32-bit
support isn't much difference.
Keep in mind that x86 always succeeds here. Every userspace user will
have to add whatever dance we create here. For example, each libperf
test with user access (there's only 2 in my tree, but there's a series
adding more) has to have an '#ifdef __aarch64__' for whatever we do
here. I was seeking to minimize that. Right now, that's just a set
config1 to 0x3. Also, note that libperf will opportunistically use a
userspace read instead of read(). The user just has to mmap the event
and libperf will use a userspace read when enabled which ultimately
depends on what the mmapped page says.
I think that x86 always succeeding here is more of a legacy thing that
they're stuck with rather than a design to be copied.
I'd prefer to keep the existing meaning of the `long` flag to mean "give
me 64 bits of counter, somehow", with `rdpmc` meaning "give me a single
counter I can access from userspace", even if that means the combination
of the two can sometimes be rejected. As you say, we can probe for that
as necessary by trying `long` then falling back to a plain event, and if
that ends up being a bottleneck somehow we can figure out a way of
advertising support to userspace. Regardless, we should
Importantly, I don't think libperf should override a user's request for
`long`, since the user may want to optimize for minimal perturbation
rather than faster access.
If we want a "please give me the longest counter that's compatible with
other constraints", I think that should be a new flag e.g. `trylong`,
and shouldn't override the existing `long`. We can add that as a
follow-up if we want it.
Thanks,
Mark.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel