perf: Add infrastructure and support for Intel PT
Subsystems (2)
Alexander Shishkin
reviewerv9 cover perf: Add infrastructure and support for Intel PT
Hi Peter and all,
Here's version 9 of PT support, addressing comments to the previous version. This series applies to tip perf/core branch and to v3.18, but has one trivial conflict with Linus' master in cpu features department.
[full description below the changelog]
Changes since v8:
* refuse to load if PT is enabled during driver initialization, issue a warning,
* added more elaborate comments about handle_nmi in the PT driver,
* added a comment for the ITRACE_START record.
This patchset adds support for Intel Processor Trace (PT) extension [1] of Intel Architecture that allows the capture of information about software execution flow, to the perf kernel infrastructure.
The single most notable thing is that while PT outputs trace data in a compressed binary format, it will still generate hundreds of megabytes of trace data per second per core. Decoding this binary stream takes 2-3 orders of magnitude the cpu time that it takes to generate it. These considerations make it impossible to carry out decoding in kernel space. Therefore, the trace data is exported to userspace as a zero-copy mapping that userspace can collect and store for later decoding. To address this, this patchset extends perf ring buffer with an "AUX space", which is allocated for hardware blocks such as PT to export their trace data with minimal overhead. This space can be configured via buffer's user page and mmapped from the same file descriptor with a given offset. Data can then be collected from it by reading the aux_head (write) pointer from the user page and updating aux_tail (read) pointer similarly to data_{head,tail} of the traditional perf buffer. There is an api between perf core and pmu drivers that wish to make use of this AUX space to export their data.
For tracing blocks that don't support hardware scatter-gather tables, we provide high-order physically contiguous allocations to minimize the overhead needed for software double buffering and PMI pressure.
This way we get a normal perf data stream that provides sideband information that is required to decode the trace data, such as MMAPs, COMMs etc, plus the actual trace in its own logical space.
If the trace buffer is mapped writable, the driver will stop tracing when it fills up (aux_head approaches aux_tail), till data is read, aux_tail pointer is moved forward and an ioctl() is issued to re-enable tracing. If the trace buffer is mapped read only, the tracing will continue, overwriting older data, so that the buffer always contains the most recent data. Tracing can be stopped with an ioctl() and restarted once the data is collected.
This patchset consists of necessary changes to the perf kernel infrastructure, and PT and BTS pmu drivers. The tooling support is not included in this series, however, it can be found in my github tree [2].
[1] chapter 36 of
http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-manual-325462.pdf
[2] http://github.com/virtuoso/linux-perf/tree/intel_pt
Alexander Shishkin (13):
perf: Add data_{offset,size} to user_page
perf: Support high-order allocations for AUX space
perf: Add a capability for AUX_NO_SG pmus to do software double
buffering
perf: Add a pmu capability for "exclusive" events
perf: Add AUX record
perf: Add api for pmus to write to AUX area
perf: Support overwrite mode for AUX area
perf: Add wakeup watermark control to AUX area
x86: Add Intel Processor Trace (INTEL_PT) cpu feature detection
x86: perf: Intel PT and LBR/BTS are mutually exclusive
x86: perf: intel_pt: Intel PT PMU driver
x86: perf: intel_bts: Add BTS PMU driver
perf: add ITRACE_START record to indicate that tracing has started
Peter Zijlstra (1):
perf: Add AUX area to ring buffer for raw data streams
arch/x86/include/asm/cpufeature.h | 1 + arch/x86/include/uapi/asm/msr-index.h | 18 + arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/intel_pt.h | 131 ++++ arch/x86/kernel/cpu/perf_event.c | 43 ++ arch/x86/kernel/cpu/perf_event.h | 49 ++ arch/x86/kernel/cpu/perf_event_intel.c | 40 +- arch/x86/kernel/cpu/perf_event_intel_bts.c | 525 +++++++++++++ arch/x86/kernel/cpu/perf_event_intel_ds.c | 3 +- arch/x86/kernel/cpu/perf_event_intel_pt.c | 1095 ++++++++++++++++++++++++++++ arch/x86/kernel/cpu/scattered.c | 1 + include/linux/perf_event.h | 47 +- include/uapi/linux/perf_event.h | 60 +- kernel/events/core.c | 268 ++++++- kernel/events/internal.h | 33 + kernel/events/ring_buffer.c | 327 ++++++++- 16 files changed, 2591 insertions(+), 51 deletions(-) create mode 100644 arch/x86/kernel/cpu/intel_pt.h create mode 100644 arch/x86/kernel/cpu/perf_event_intel_bts.c create mode 100644 arch/x86/kernel/cpu/perf_event_intel_pt.c
Signature · 1 line
2.1.4
Alexander Shishkin
reviewerPATCH v9 1/14 perf: Add data_{offset,size} to user_page
Currently, the actual perf ring buffer is one page into the mmap area, following the user page and the userspace follows this convention. This patch adds data_{offset,size} fields to user_page that can be used by userspace instead for locating perf data in the mmap area. This is also helpful when mapping existing or shared buffers if their size is not known in advance.
Right now, it is made to follow the existing convention that
data_offset == PAGE_SIZE and data_offset + data_size == mmap_size.
--- include/uapi/linux/perf_event.h | 5 +++++ kernel/events/core.c | 2 ++ 2 files changed, 7 insertions(+)
include/uapi/linux/perf_event.h +5 -0
@@ -500,9 +500,14 @@ struct perf_event_mmap_page {* In this case the kernel will not over-write unread data. * * See perf_output_put_handle() for the data ordering. +* +* data_{offset,size} indicate the location and size of the perf record +* buffer within the mmapped area. */ __u64 data_head;/* head in the data section */ __u64 data_tail;/* user-space written tail */ +__u64 data_offset;/* where the buffer starts */ +__u64 data_size;/* data buffer size */ };#define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0)
kernel/events/core.c +2 -0
@@ -3944,6 +3944,8 @@ static void perf_event_init_userpage(struct perf_event *event)/* Allow new userspace to detect that bit 0 is deprecated */ userpg->cap_bit0_is_deprecated =1 ; userpg->size = offsetof(struct perf_event_mmap_page , __reserved); + userpg->data_offset =PAGE_SIZE ; + userpg->data_size =perf_data_size (rb); unlock:rcu_read_unlock ();
Signature · 1 line
2.1.4
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf: Add data_{offset,size} to user_page
perf: Add data_{offset,size} to user_page
Commit-ID: e8c6deac69629c0cb97c3d3272f8631ef17f8f0f Gitweb: http://git.kernel.org/tip/e8c6deac69629c0cb97c3d3272f8631ef17f8f0f Author: Alexander Shishkin <[email protected]> AuthorDate: Wed, 14 Jan 2015 14:18:10 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:13:32 +0200
perf: Add data_{offset,size} to user_page
Currently, the actual perf ring buffer is one page into the mmap area, following the user page and the userspace follows this convention. This patch adds data_{offset,size} fields to user_page that can be used by userspace instead for locating perf data in the mmap area. This is also helpful when mapping existing or shared buffers if their size is not known in advance.
Right now, it is made to follow the existing convention that
data_offset == PAGE_SIZE and data_offset + data_size == mmap_size.
--- include/uapi/linux/perf_event.h | 5 +++++ kernel/events/core.c | 2 ++ 2 files changed, 7 insertions(+)
include/uapi/linux/perf_event.h +5 -0
@@ -522,9 +522,14 @@ struct perf_event_mmap_page {* In this case the kernel will not over-write unread data. * * See perf_output_put_handle() for the data ordering. +* +* data_{offset,size} indicate the location and size of the perf record +* buffer within the mmapped area. */ __u64 data_head;/* head in the data section */ __u64 data_tail;/* user-space written tail */ +__u64 data_offset;/* where the buffer starts */ +__u64 data_size;/* data buffer size */ };#define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0)
kernel/events/core.c +2 -0
@@ -4105,6 +4105,8 @@ static void perf_event_init_userpage(struct perf_event *event)/* Allow new userspace to detect that bit 0 is deprecated */ userpg->cap_bit0_is_deprecated =1 ; userpg->size = offsetof(struct perf_event_mmap_page , __reserved); + userpg->data_offset =PAGE_SIZE ; + userpg->data_size =perf_data_size (rb); unlock:rcu_read_unlock ();
Alexander Shishkin
reviewerPATCH v9 2/14 perf: Add AUX area to ring buffer for raw data streams
In reply to Alexander ShishkinFrom: Peter Zijlstra <[email protected]>
This patch introduces "AUX space" in the perf mmap buffer, intended for exporting high bandwidth data streams to userspace, such as instruction flow traces.
AUX space is a ring buffer, defined by aux_{offset,size} fields in the user_page structure, and read/write pointers aux_{head,tail}, which abide by the same rules as data_* counterparts of the main perf buffer.
In order to allocate/mmap AUX, userspace needs to set up aux_offset to such an offset that will be greater than data_offset+data_size and aux_size to be the desired buffer size. Both need to be page aligned. Then, same aux_offset and aux_size should be passed to mmap() call and if everything adds up, you should have an AUX buffer as a result.
Pages that are mapped into this buffer also come out of user's mlock rlimit plus perf_event_mlock_kb allowance.
--- include/linux/perf_event.h | 17 +++++ include/uapi/linux/perf_event.h | 16 +++++ kernel/events/core.c | 140 +++++++++++++++++++++++++++++++++------- kernel/events/internal.h | 23 +++++++ kernel/events/ring_buffer.c | 97 ++++++++++++++++++++++++++-- 5 files changed, 264 insertions(+), 29 deletions(-)
include/linux/perf_event.h +17 -0
@@ -263,6 +263,18 @@ struct pmu {* flush branch stack on context-switches (needed in cpu-wide mode) */ void (*flush_branch_stack) (void ); + +/* +* Set up pmu-private data structures for an AUX area +*/ +void *(*setup_aux) (int cpu,void **pages, +int nr_pages,bool overwrite); +/* optional */ + +/* +* Free pmu-private AUX data structures +*/ +void (*free_aux) (void *aux);/* optional */ };/**
@@ -785,6 +797,11 @@ static inline bool has_branch_stack(struct perf_event *event)return event->attr.sample_type &PERF_SAMPLE_BRANCH_STACK ; } +static inline bool has_aux (struct perf_event *event) +{ +return event->pmu->setup_aux; +} +extern int perf_output_begin (struct perf_output_handle *handle,struct perf_event *event,unsigned int size);extern void perf_output_end (struct perf_output_handle *handle);
include/uapi/linux/perf_event.h +16 -0
@@ -508,6 +508,22 @@ struct perf_event_mmap_page {__u64 data_tail;/* user-space written tail */ __u64 data_offset;/* where the buffer starts */ __u64 data_size;/* data buffer size */ + +/* +* AUX area is defined by aux_{offset,size} fields that should be set +* by the userspace, so that +* +* aux_offset >= data_offset + data_size +* +* prior to mmap()ing it. Size of the mmap()ed area should be aux_size. +* +* Ring buffer pointers aux_{head,tail} have the same semantics as +* data_{head,tail} and same ordering rules apply. +*/ +__u64 aux_head; +__u64 aux_tail; +__u64 aux_offset; +__u64 aux_size; };#define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0)
kernel/events/core.c +115 -25
214 lines not on this page · raw message
kernel/events/internal.h +23 -0
@@ -35,6 +35,16 @@ struct ring_buffer {unsigned long mmap_locked;struct user_struct *mmap_user; +/* AUX area */ +unsigned long aux_pgoff; +int aux_nr_pages; +atomic_t aux_mmap_count; +unsigned long aux_mmap_locked; +void (*free_aux)(void *); +atomic_t aux_refcount; +void **aux_pages; +void *aux_priv; +struct perf_event_mmap_page *user_page;void *data_pages[0 ]; };
@@ -43,6 +53,14 @@ extern void rb_free(struct ring_buffer *rb);extern struct ring_buffer *rb_alloc (int nr_pages,long watermark,int cpu,int flags);extern void perf_event_wakeup (struct perf_event *event); +extern int rb_alloc_aux (struct ring_buffer *rb,struct perf_event *event, +pgoff_t pgoff,int nr_pages,int flags); +extern void rb_free_aux (struct ring_buffer *rb); + +static inline bool rb_has_aux (struct ring_buffer *rb) +{ +return !!rb->aux_nr_pages; +} extern void perf_event_header__init_id(struct perf_event_header *header,
@@ -81,6 +99,11 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)return rb->nr_pages << (PAGE_SHIFT +page_order (rb)); } +static inline unsigned long perf_aux_size (struct ring_buffer *rb) +{ +return rb->aux_nr_pages <<PAGE_SHIFT ; +} +#define DEFINE_OUTPUT_COPY (func_name, memcpy_func) \ static inline unsigned long \ func_name(struct perf_output_handle *handle, \
kernel/events/ring_buffer.c +93 -4
118 lines not on this page · raw message
Signature · 1 line
2.1.4
tip-bot for Peter Zijlstra
merge bot[tip:perf/core] perf: Add AUX area to ring buffer for raw data streams
perf: Add AUX area to ring buffer for raw data streams
Commit-ID: 45bfb2e50471abbbfd83d40d28c986078b0d24ff Gitweb: http://git.kernel.org/tip/45bfb2e50471abbbfd83d40d28c986078b0d24ff Author: Peter Zijlstra <[email protected]> AuthorDate: Wed, 14 Jan 2015 14:18:11 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:13:46 +0200
perf: Add AUX area to ring buffer for raw data streams
This patch introduces "AUX space" in the perf mmap buffer, intended for exporting high bandwidth data streams to userspace, such as instruction flow traces.
AUX space is a ring buffer, defined by aux_{offset,size} fields in the user_page structure, and read/write pointers aux_{head,tail}, which abide by the same rules as data_* counterparts of the main perf buffer.
In order to allocate/mmap AUX, userspace needs to set up aux_offset to such an offset that will be greater than data_offset+data_size and aux_size to be the desired buffer size. Both need to be page aligned. Then, same aux_offset and aux_size should be passed to mmap() call and if everything adds up, you should have an AUX buffer as a result.
Pages that are mapped into this buffer also come out of user's mlock rlimit plus perf_event_mlock_kb allowance.
--- include/linux/perf_event.h | 17 +++++ include/uapi/linux/perf_event.h | 16 +++++ kernel/events/core.c | 141 +++++++++++++++++++++++++++++++++------- kernel/events/internal.h | 23 +++++++ kernel/events/ring_buffer.c | 97 +++++++++++++++++++++++++-- 5 files changed, 265 insertions(+), 29 deletions(-)
include/linux/perf_event.h +17 -0
@@ -284,6 +284,18 @@ struct pmu {* Return the count value for a counter. */ u64 (*count) (struct perf_event *event);/*optional*/ + +/* +* Set up pmu-private data structures for an AUX area +*/ +void *(*setup_aux) (int cpu,void **pages, +int nr_pages,bool overwrite); +/* optional */ + +/* +* Free pmu-private AUX data structures +*/ +void (*free_aux) (void *aux);/* optional */ };/**
@@ -862,6 +874,11 @@ static inline bool needs_branch_stack(struct perf_event *event)return event->attr.branch_sample_type !=0 ; } +static inline bool has_aux (struct perf_event *event) +{ +return event->pmu->setup_aux; +} +extern int perf_output_begin (struct perf_output_handle *handle,struct perf_event *event,unsigned int size);extern void perf_output_end (struct perf_output_handle *handle);
include/uapi/linux/perf_event.h +16 -0
@@ -530,6 +530,22 @@ struct perf_event_mmap_page {__u64 data_tail;/* user-space written tail */ __u64 data_offset;/* where the buffer starts */ __u64 data_size;/* data buffer size */ + +/* +* AUX area is defined by aux_{offset,size} fields that should be set +* by the userspace, so that +* +* aux_offset >= data_offset + data_size +* +* prior to mmap()ing it. Size of the mmap()ed area should be aux_size. +* +* Ring buffer pointers aux_{head,tail} have the same semantics as +* data_{head,tail} and same ordering rules apply. +*/ +__u64 aux_head; +__u64 aux_tail; +__u64 aux_offset; +__u64 aux_size; };#define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0)
kernel/events/core.c +116 -25
215 lines not on this page · raw message
kernel/events/internal.h +23 -0
@@ -35,6 +35,16 @@ struct ring_buffer {unsigned long mmap_locked;struct user_struct *mmap_user; +/* AUX area */ +unsigned long aux_pgoff; +int aux_nr_pages; +atomic_t aux_mmap_count; +unsigned long aux_mmap_locked; +void (*free_aux)(void *); +atomic_t aux_refcount; +void **aux_pages; +void *aux_priv; +struct perf_event_mmap_page *user_page;void *data_pages[0 ]; };
@@ -43,6 +53,14 @@ extern void rb_free(struct ring_buffer *rb);extern struct ring_buffer *rb_alloc (int nr_pages,long watermark,int cpu,int flags);extern void perf_event_wakeup (struct perf_event *event); +extern int rb_alloc_aux (struct ring_buffer *rb,struct perf_event *event, +pgoff_t pgoff,int nr_pages,int flags); +extern void rb_free_aux (struct ring_buffer *rb); + +static inline bool rb_has_aux (struct ring_buffer *rb) +{ +return !!rb->aux_nr_pages; +} extern void perf_event_header__init_id(struct perf_event_header *header,
@@ -81,6 +99,11 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)return rb->nr_pages << (PAGE_SHIFT +page_order (rb)); } +static inline unsigned long perf_aux_size (struct ring_buffer *rb) +{ +return rb->aux_nr_pages <<PAGE_SHIFT ; +} +#define DEFINE_OUTPUT_COPY (func_name, memcpy_func) \ static inline unsigned long \ func_name(struct perf_output_handle *handle, \
kernel/events/ring_buffer.c +93 -4
118 lines not on this page · raw message
Alexander Shishkin
reviewerPATCH v9 3/14 perf: Support high-order allocations for AUX space
In reply to Alexander ShishkinSome pmus (such as BTS or Intel PT without multiple-entry ToPA capability) don't support scatter-gather and will prefer larger contiguous areas for their output regions.
This patch adds a new pmu capability to request higher order allocations.
--- include/linux/perf_event.h | 1 + kernel/events/ring_buffer.c | 56 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 6 deletions(-)
include/linux/perf_event.h +1 -0
@@ -171,6 +171,7 @@ struct perf_event;* pmu::capabilities flags */ #define PERF_PMU_CAP_NO_INTERRUPT 0x01 +#define PERF_PMU_CAP_AUX_NO_SG 0x02/** * struct pmu - generic performance monitoring unit
kernel/events/ring_buffer.c +50 -6
87 lines not on this page · raw message
Signature · 1 line
2.1.4
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf: Support high-order allocations for AUX space
perf: Support high-order allocations for AUX space
Commit-ID: 0a4e38e64f5e91ce131cc42ee5bb3925377ec840 Gitweb: http://git.kernel.org/tip/0a4e38e64f5e91ce131cc42ee5bb3925377ec840 Author: Alexander Shishkin <[email protected]> AuthorDate: Wed, 14 Jan 2015 14:18:12 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:14:08 +0200
perf: Support high-order allocations for AUX space
Some pmus (such as BTS or Intel PT without multiple-entry ToPA capability) don't support scatter-gather and will prefer larger contiguous areas for their output regions.
This patch adds a new pmu capability to request higher order allocations.
--- include/linux/perf_event.h | 1 + kernel/events/ring_buffer.c | 56 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 6 deletions(-)
include/linux/perf_event.h +1 -0
@@ -174,6 +174,7 @@ struct perf_event;*/ #define PERF_PMU_CAP_NO_INTERRUPT 0x01#define PERF_PMU_CAP_NO_NMI 0x02 +#define PERF_PMU_CAP_AUX_NO_SG 0x04/** * struct pmu - generic performance monitoring unit
kernel/events/ring_buffer.c +50 -6
87 lines not on this page · raw message
Alexander Shishkin
reviewerPATCH v9 4/14 perf: Add a capability for AUX_NO_SG pmus to do software double buffering
In reply to Alexander ShishkinFor pmus that don't support scatter-gather for AUX data in hardware, it might still make sense to implement software double buffering to avoid losing data while the user is reading data out. For this purpose, add a pmu capability that guarantees multiple high-order chunks for AUX buffer, so that the pmu driver can do switchover tricks.
To make use of this feature, add PERF_PMU_CAP_AUX_SW_DOUBLEBUF to your pmu's capability mask. This will make the ring buffer AUX allocation code ensure that the biggest high order allocation for the aux buffer pages is no bigger than half of the total requested buffer size, thus making sure that the buffer has at least two high order allocations.
--- include/linux/perf_event.h | 1 + kernel/events/ring_buffer.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)
include/linux/perf_event.h +1 -0
@@ -172,6 +172,7 @@ struct perf_event;*/ #define PERF_PMU_CAP_NO_INTERRUPT 0x01#define PERF_PMU_CAP_AUX_NO_SG 0x02 +#define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x04/** * struct pmu - generic performance monitoring unit
kernel/events/ring_buffer.c +14 -1
@@ -286,13 +286,26 @@ int rb_alloc_aux(struct ring_buffer *rb, struct perf_event *event,if (!has_aux (event))return -ENOTSUPP ; -if (event->pmu->capabilities &PERF_PMU_CAP_AUX_NO_SG ) +if (event->pmu->capabilities &PERF_PMU_CAP_AUX_NO_SG ) {/* * We need to start with the max_order that fits in nr_pages, * not the other way around, hence ilog2() and not get_order. */ max_order =ilog2 (nr_pages); +/* +* PMU requests more than one contiguous chunks of memory +* for SW double buffering +*/ +if ((event->pmu->capabilities &PERF_PMU_CAP_AUX_SW_DOUBLEBUF ) && + !overwrite) { +if (!max_order) +return -EINVAL ; + + max_order--; + } + } + rb->aux_pages =kzalloc_node (nr_pages *sizeof (void *),GFP_KERNEL , node);if (!rb->aux_pages)return -ENOMEM ;
Signature · 1 line
2.1.4
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf: Add a capability for AUX_NO_SG pmus to do software double buffering
perf: Add a capability for AUX_NO_SG pmus to do software double buffering
Commit-ID: 6a279230391b63130070e0219b0ad09d34d28c89 Gitweb: http://git.kernel.org/tip/6a279230391b63130070e0219b0ad09d34d28c89 Author: Alexander Shishkin <[email protected]> AuthorDate: Wed, 14 Jan 2015 14:18:13 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:14:10 +0200
perf: Add a capability for AUX_NO_SG pmus to do software double buffering
For pmus that don't support scatter-gather for AUX data in hardware, it might still make sense to implement software double buffering to avoid losing data while the user is reading data out. For this purpose, add a pmu capability that guarantees multiple high-order chunks for AUX buffer, so that the pmu driver can do switchover tricks.
To make use of this feature, add PERF_PMU_CAP_AUX_SW_DOUBLEBUF to your pmu's capability mask. This will make the ring buffer AUX allocation code ensure that the biggest high order allocation for the aux buffer pages is no bigger than half of the total requested buffer size, thus making sure that the buffer has at least two high order allocations.
--- include/linux/perf_event.h | 1 + kernel/events/ring_buffer.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)
include/linux/perf_event.h +1 -0
@@ -175,6 +175,7 @@ struct perf_event;#define PERF_PMU_CAP_NO_INTERRUPT 0x01#define PERF_PMU_CAP_NO_NMI 0x02#define PERF_PMU_CAP_AUX_NO_SG 0x04 +#define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x08/** * struct pmu - generic performance monitoring unit
kernel/events/ring_buffer.c +14 -1
@@ -287,13 +287,26 @@ int rb_alloc_aux(struct ring_buffer *rb, struct perf_event *event,if (!has_aux (event))return -ENOTSUPP ; -if (event->pmu->capabilities &PERF_PMU_CAP_AUX_NO_SG ) +if (event->pmu->capabilities &PERF_PMU_CAP_AUX_NO_SG ) {/* * We need to start with the max_order that fits in nr_pages, * not the other way around, hence ilog2() and not get_order. */ max_order =ilog2 (nr_pages); +/* +* PMU requests more than one contiguous chunks of memory +* for SW double buffering +*/ +if ((event->pmu->capabilities &PERF_PMU_CAP_AUX_SW_DOUBLEBUF ) && + !overwrite) { +if (!max_order) +return -EINVAL ; + + max_order--; + } + } + rb->aux_pages =kzalloc_node (nr_pages *sizeof (void *),GFP_KERNEL , node);if (!rb->aux_pages)return -ENOMEM ;
Alexander Shishkin
reviewerPATCH v9 5/14 perf: Add a pmu capability for "exclusive" events
In reply to Alexander ShishkinUsually, pmus that do, for example, instruction tracing, would only ever be able to have one event per task per cpu (or per perf_context). For such pmus it makes sense to disallow creating conflicting events early on, so as to provide consistent behavior for the user.
This patch adds a pmu capability that indicates such constraint on event creation.
--- include/linux/perf_event.h | 1 + kernel/events/core.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+)
include/linux/perf_event.h +1 -0
@@ -173,6 +173,7 @@ struct perf_event;#define PERF_PMU_CAP_NO_INTERRUPT 0x01#define PERF_PMU_CAP_AUX_NO_SG 0x02#define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x04 +#define PERF_PMU_CAP_EXCLUSIVE 0x08/** * struct pmu - generic performance monitoring unit
kernel/events/core.c +45 -0
69 lines not on this page · raw message
Signature · 1 line
2.1.4
Alexander Shishkin
reviewerPATCH v9 6/14 perf: Add AUX record
In reply to Alexander ShishkinWhen there's new data in the AUX space, output a record indicating its offset and size and a set of flags, such as PERF_AUX_FLAG_TRUNCATED, to mean the described data was truncated to fit in the ring buffer.
--- include/uapi/linux/perf_event.h | 19 +++++++++++++++++++ kernel/events/core.c | 34 ++++++++++++++++++++++++++++++++++ kernel/events/internal.h | 3 +++ 3 files changed, 56 insertions(+)
include/uapi/linux/perf_event.h +19 -0
@@ -746,6 +746,20 @@ enum perf_event_type {*/ PERF_RECORD_MMAP2 =10 , +/* +* Records that new data landed in the AUX buffer part. +* +* struct { +* struct perf_event_header header; +* +* u64 aux_offset; +* u64 aux_size; +* u64 flags; +* struct sample_id sample_id; +* }; +*/ +PERF_RECORD_AUX =11 , + PERF_RECORD_MAX, /* non-ABI */ };
@@ -763,6 +777,11 @@ enum perf_callchain_context { PERF_CONTEXT_MAX = (__u64)-4095, }; +/** +* PERF_RECORD_AUX::flags bits +*/ +#define PERF_AUX_FLAG_TRUNCATED 0x01/* record was truncated to fit */ +#define PERF_FLAG_FD_NO_GROUP (1UL << 0)#define PERF_FLAG_FD_OUTPUT (1UL << 1)#define PERF_FLAG_PID_CGROUP (1UL << 2)/* pid=cgroup id, per-cpu mode only */
kernel/events/core.c +34 -0
@@ -5648,6 +5648,40 @@ void perf_event_mmap(struct vm_area_struct *vma)perf_event_mmap_event (&mmap_event); } +void perf_event_aux_event (struct perf_event *event,unsigned long head, +unsigned long size,u64 flags) +{ +struct perf_output_handle handle; +struct perf_sample_data sample; +struct perf_aux_event { +struct perf_event_header header; +u64 offset; +u64 size; +u64 flags; + } rec = { + .header = { + .type =PERF_RECORD_AUX , + .misc =0 , + .size =sizeof (rec), + }, + .offset = head, + .size = size, + .flags = flags, + }; +int ret; + +perf_event_header__init_id (&rec.header, &sample, event); + ret =perf_output_begin (&handle, event, rec.header.size); + +if (ret) +return ; + +perf_output_put (&handle, rec); +perf_event__output_id_sample (event, &handle, &sample); + +perf_output_end (&handle); +} +/* * IRQ throttle logging */
kernel/events/internal.h +3 -0
@@ -62,6 +62,9 @@ static inline bool rb_has_aux(struct ring_buffer *rb)return !!rb->aux_nr_pages; } +void perf_event_aux_event (struct perf_event *event,unsigned long head, +unsigned long size,u64 flags); + extern void perf_event_header__init_id(struct perf_event_header *header, struct perf_sample_data *data,
Signature · 1 line
2.1.4
Re: [PATCH v9 06/14] perf: Add AUX record
Quoted 20 lines · Alexander Shishkin
When there's new data in the AUX space, output a record indicating its offset and size and a set of flags, such as
PERF_AUX_FLAG_TRUNCATED, to mean the described data was truncated to fit in the ring buffer.Signed-off-by Alexander Shishkin <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>--- include/uapi/linux/perf_event.h | 19 +++++++++++++++++++ kernel/events/core.c | 34 ++++++++++++++++++++++++++++++++++ kernel/events/internal.h | 3 +++ 3 files changed, 56 insertions(+)include/uapi/linux/perf_event.h +0
-0@@ -746,6 +746,20 @@ enum perf_event_type {*/ PERF_RECORD_MMAP2 = 10,
include/uapi/linux/perf_event.h enum perf_event_type { · line 758
Quoted 10 lines
include/uapi/linux/perf_event.h +10
-0+/* +* Records that new data landed in the AUX buffer part. +* +* struct { +* struct perf_event_header header; +* +* u64 aux_offset; +* u64 aux_size; +* u64 flags; +* struct sample_id sample_id;
hum, I dont see sample_id below in implementation
jirka
Quoted 86 lines
include/uapi/linux/perf_event.h +9
-0+* }; +*/ +PERF_RECORD_AUX =11 , + PERF_RECORD_MAX, /* non-ABI */ };@@ -763,6 +777,11 @@ enum perf_callchain_context { PERF_CONTEXT_MAX = (__u64)-4095, }; +/** +* PERF_RECORD_AUX::flags bits +*/ +#define PERF_AUX_FLAG_TRUNCATED 0x01/* record was truncated to fit */ +#define PERF_FLAG_FD_NO_GROUP (1UL << 0)#define PERF_FLAG_FD_OUTPUT (1UL << 1)#define PERF_FLAG_PID_CGROUP (1UL << 2)/* pid=cgroup id, per-cpu mode only */ kernel/events/core.c +34
-0@@ -5648,6 +5648,40 @@ void perf_event_mmap(struct vm_area_struct *vma)perf_event_mmap_event (&mmap_event); } +void perf_event_aux_event (struct perf_event *event,unsigned long head, +unsigned long size,u64 flags) +{ +struct perf_output_handle handle; +struct perf_sample_data sample; +struct perf_aux_event { +struct perf_event_header header; +u64 offset; +u64 size; +u64 flags; + } rec = { + .header = { + .type =PERF_RECORD_AUX , + .misc =0 , + .size =sizeof (rec), + }, + .offset = head, + .size = size, + .flags = flags, + }; +int ret; + +perf_event_header__init_id (&rec.header, &sample, event); + ret =perf_output_begin (&handle, event, rec.header.size); + +if (ret) +return ; + +perf_output_put (&handle, rec); +perf_event__output_id_sample (event, &handle, &sample); + +perf_output_end (&handle); +} +/* * IRQ throttle logging */ kernel/events/internal.h +3
-0@@ -62,6 +62,9 @@ static inline bool rb_has_aux(struct ring_buffer *rb)return !!rb->aux_nr_pages; } +void perf_event_aux_event (struct perf_event *event,unsigned long head, +unsigned long size,u64 flags); + extern void perf_event_header__init_id(struct perf_event_header *header, struct perf_sample_data *data,Signature · 7 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Adrian Hunter
reviewerRe: [PATCH v9 06/14] perf: Add AUX record
Quoted 21 lines · Jiri Olsa
Quoted 20 lines · Alexander Shishkin
When there's new data in the AUX space, output a record indicating its offset and size and a set of flags, such as
PERF_AUX_FLAG_TRUNCATED, to mean the described data was truncated to fit in the ring buffer.Signed-off-by Alexander Shishkin <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>--- include/uapi/linux/perf_event.h | 19 +++++++++++++++++++ kernel/events/core.c | 34 ++++++++++++++++++++++++++++++++++ kernel/events/internal.h | 3 +++ 3 files changed, 56 insertions(+)include/uapi/linux/perf_event.h +0
-0@@ -746,6 +746,20 @@ enum perf_event_type {*/ PERF_RECORD_MMAP2 = 10,
Quoted 12 lines
include/uapi/linux/perf_event.h enum perf_event_type { · line 758
Quoted 10 lines
include/uapi/linux/perf_event.h +10
-0+/* +* Records that new data landed in the AUX buffer part. +* +* struct { +* struct perf_event_header header; +* +* u64 aux_offset; +* u64 aux_size; +* u64 flags; +* struct sample_id sample_id; hum, I dont see
sample_idbelow in implementation
Alex is away, so I will take the liberty of answering.
perf_event_aux_event() calls perf_event__output_id_sample() That's it isn't it?
Quoted 91 lines
jirka
Quoted 86 lines
include/uapi/linux/perf_event.h +9
-0+* }; +*/ +PERF_RECORD_AUX =11 , + PERF_RECORD_MAX, /* non-ABI */ };@@ -763,6 +777,11 @@ enum perf_callchain_context { PERF_CONTEXT_MAX = (__u64)-4095, }; +/** +* PERF_RECORD_AUX::flags bits +*/ +#define PERF_AUX_FLAG_TRUNCATED 0x01/* record was truncated to fit */ +#define PERF_FLAG_FD_NO_GROUP (1UL << 0)#define PERF_FLAG_FD_OUTPUT (1UL << 1)#define PERF_FLAG_PID_CGROUP (1UL << 2)/* pid=cgroup id, per-cpu mode only */ kernel/events/core.c +34
-0@@ -5648,6 +5648,40 @@ void perf_event_mmap(struct vm_area_struct *vma)perf_event_mmap_event (&mmap_event); } +void perf_event_aux_event (struct perf_event *event,unsigned long head, +unsigned long size,u64 flags) +{ +struct perf_output_handle handle; +struct perf_sample_data sample; +struct perf_aux_event { +struct perf_event_header header; +u64 offset; +u64 size; +u64 flags; + } rec = { + .header = { + .type =PERF_RECORD_AUX , + .misc =0 , + .size =sizeof (rec), + }, + .offset = head, + .size = size, + .flags = flags, + }; +int ret; + +perf_event_header__init_id (&rec.header, &sample, event); + ret =perf_output_begin (&handle, event, rec.header.size); + +if (ret) +return ; + +perf_output_put (&handle, rec); +perf_event__output_id_sample (event, &handle, &sample); + +perf_output_end (&handle); +} +/* * IRQ throttle logging */ kernel/events/internal.h +3
-0@@ -62,6 +62,9 @@ static inline bool rb_has_aux(struct ring_buffer *rb)return !!rb->aux_nr_pages; } +void perf_event_aux_event (struct perf_event *event,unsigned long head, +unsigned long size,u64 flags); + extern void perf_event_header__init_id(struct perf_event_header *header, struct perf_sample_data *data,Signature · 7 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v9 06/14] perf: Add AUX record
Quoted 35 lines · Adrian Hunter
Quoted 21 lines · Jiri Olsa
Quoted 20 lines · Alexander Shishkin
When there's new data in the AUX space, output a record indicating its offset and size and a set of flags, such as
PERF_AUX_FLAG_TRUNCATED, to mean the described data was truncated to fit in the ring buffer.Signed-off-by Alexander Shishkin <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>--- include/uapi/linux/perf_event.h | 19 +++++++++++++++++++ kernel/events/core.c | 34 ++++++++++++++++++++++++++++++++++ kernel/events/internal.h | 3 +++ 3 files changed, 56 insertions(+)include/uapi/linux/perf_event.h +0
-0@@ -746,6 +746,20 @@ enum perf_event_type {*/ PERF_RECORD_MMAP2 = 10,Quoted 12 lines
include/uapi/linux/perf_event.h enum perf_event_type { · line 758
Quoted 10 lines
include/uapi/linux/perf_event.h +10
-0+/* +* Records that new data landed in the AUX buffer part. +* +* struct { +* struct perf_event_header header; +* +* u64 aux_offset; +* u64 aux_size; +* u64 flags; +* struct sample_id sample_id; hum, I dont see
sample_idbelow in implementation
Quoted 4 lines
Alex is away, so I will take the liberty of answering.
perf_event_aux_event()callsperf_event__output_id_sample()That's it isn't it?
argh, now I see it ;-) sry
jirka
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf: Add AUX record
In reply to Alexander Shishkinperf: Add AUX record
Commit-ID: 68db7e98c3a6ebe7284b6cf14906ed7c55f3f7f0 Gitweb: http://git.kernel.org/tip/68db7e98c3a6ebe7284b6cf14906ed7c55f3f7f0 Author: Alexander Shishkin <[email protected]> AuthorDate: Wed, 14 Jan 2015 14:18:15 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:14:12 +0200
perf: Add AUX record
When there's new data in the AUX space, output a record indicating its offset and size and a set of flags, such as PERF_AUX_FLAG_TRUNCATED, to mean the described data was truncated to fit in the ring buffer.
--- include/uapi/linux/perf_event.h | 19 +++++++++++++++++++ kernel/events/core.c | 34 ++++++++++++++++++++++++++++++++++ kernel/events/internal.h | 3 +++ 3 files changed, 56 insertions(+)
include/uapi/linux/perf_event.h +19 -0
@@ -768,6 +768,20 @@ enum perf_event_type {*/ PERF_RECORD_MMAP2 =10 , +/* +* Records that new data landed in the AUX buffer part. +* +* struct { +* struct perf_event_header header; +* +* u64 aux_offset; +* u64 aux_size; +* u64 flags; +* struct sample_id sample_id; +* }; +*/ +PERF_RECORD_AUX =11 , + PERF_RECORD_MAX, /* non-ABI */ };
@@ -785,6 +799,11 @@ enum perf_callchain_context { PERF_CONTEXT_MAX = (__u64)-4095, }; +/** +* PERF_RECORD_AUX::flags bits +*/ +#define PERF_AUX_FLAG_TRUNCATED 0x01/* record was truncated to fit */ +#define PERF_FLAG_FD_NO_GROUP (1UL << 0)#define PERF_FLAG_FD_OUTPUT (1UL << 1)#define PERF_FLAG_PID_CGROUP (1UL << 2)/* pid=cgroup id, per-cpu mode only */
kernel/events/core.c +34 -0
@@ -5916,6 +5916,40 @@ void perf_event_mmap(struct vm_area_struct *vma)perf_event_mmap_event (&mmap_event); } +void perf_event_aux_event (struct perf_event *event,unsigned long head, +unsigned long size,u64 flags) +{ +struct perf_output_handle handle; +struct perf_sample_data sample; +struct perf_aux_event { +struct perf_event_header header; +u64 offset; +u64 size; +u64 flags; + } rec = { + .header = { + .type =PERF_RECORD_AUX , + .misc =0 , + .size =sizeof (rec), + }, + .offset = head, + .size = size, + .flags = flags, + }; +int ret; + +perf_event_header__init_id (&rec.header, &sample, event); + ret =perf_output_begin (&handle, event, rec.header.size); + +if (ret) +return ; + +perf_output_put (&handle, rec); +perf_event__output_id_sample (event, &handle, &sample); + +perf_output_end (&handle); +} +/* * IRQ throttle logging */
kernel/events/internal.h +3 -0
@@ -62,6 +62,9 @@ static inline bool rb_has_aux(struct ring_buffer *rb)return !!rb->aux_nr_pages; } +void perf_event_aux_event (struct perf_event *event,unsigned long head, +unsigned long size,u64 flags); + extern void perf_event_header__init_id(struct perf_event_header *header, struct perf_sample_data *data,
Alexander Shishkin
reviewerPATCH v9 7/14 perf: Add api for pmus to write to AUX area
In reply to Alexander ShishkinFor pmus that wish to write data to ring buffer's AUX area, provide perf_aux_output_{begin,end}() calls to initiate/commit data writes, similarly to perf_output_{begin,end}. These also use the same output handle structure. Also, similarly to software counterparts, these will direct inherited events' output to parents' ring buffers.
After the perf_aux_output_begin() returns successfully, handle->size is set to the maximum amount of data that can be written wrt aux_tail pointer, so that no data that the user hasn't seen will be overwritten, therefore this should always be called before hardware writing is enabled. On success, this will return the pointer to pmu driver's private structure allocated for this aux area by pmu::setup_aux. Same pointer can also be retrieved using perf_get_aux() while hardware writing is enabled.
PMU driver should pass the actual amount of data written as a parameter to perf_aux_output_end(). All hardware writes should be completed and visible before this one is called.
Additionally, perf_aux_output_skip() will adjust output handle and aux_head in case some part of the buffer has to be skipped over to maintain hardware's alignment constraints.
Nested writers are forbidden and guards are in place to catch such attempts.
--- include/linux/perf_event.h | 23 +++++++- kernel/events/core.c | 5 +- kernel/events/internal.h | 4 ++ kernel/events/ring_buffer.c | 139 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+), 4 deletions(-)
include/linux/perf_event.h +22 -1
@@ -555,12 +555,22 @@ struct perf_output_handle {struct ring_buffer *rb;unsigned long wakeup;unsigned long size; -void *addr; +union { +void *addr; +unsigned long head; + };int page; };#ifdef CONFIG_PERF_EVENTS +extern void *perf_aux_output_begin (struct perf_output_handle *handle, +struct perf_event *event); +extern void perf_aux_output_end (struct perf_output_handle *handle, +unsigned long size,bool truncated); +extern int perf_aux_output_skip (struct perf_output_handle *handle, +unsigned long size); +extern void *perf_get_aux (struct perf_output_handle *handle);extern int perf_pmu_register (struct pmu *pmu,const char *name,int type);extern void perf_pmu_unregister (struct pmu *pmu);
@@ -820,6 +830,17 @@ extern void perf_event_disable(struct perf_event *event);extern int __perf_event_disable (void *info);extern void perf_event_task_tick (void );#else /* !CONFIG_PERF_EVENTS: */ +static inline void * +perf_aux_output_begin (struct perf_output_handle *handle, +struct perf_event *event) {return NULL ; } +static inline void +perf_aux_output_end (struct perf_output_handle *handle,unsigned long size, +bool truncated) { } +static inline int +perf_aux_output_skip (struct perf_output_handle *handle, +unsigned long size) {return -EINVAL ; } +static inline void * +perf_get_aux (struct perf_output_handle *handle) {return NULL ; }static inline void perf_event_task_sched_in (struct task_struct *prev,struct task_struct *task) { }
kernel/events/core.c +2 -3
@@ -3295,7 +3295,6 @@ static void free_event_rcu(struct rcu_head *head)kfree (event); } -static void ring_buffer_put (struct ring_buffer *rb);static void ring_buffer_attach (struct perf_event *event,struct ring_buffer *rb);
@@ -4112,7 +4111,7 @@ static void rb_free_rcu(struct rcu_head *rcu_head)rb_free (rb); } -static struct ring_buffer *ring_buffer_get (struct perf_event *event) +struct ring_buffer *ring_buffer_get (struct perf_event *event) {struct ring_buffer *rb;
@@ -4127,7 +4126,7 @@ static struct ring_buffer *ring_buffer_get(struct perf_event *event)return rb; } -static void ring_buffer_put (struct ring_buffer *rb) +void ring_buffer_put (struct ring_buffer *rb) {if (!atomic_dec_and_test (&rb->refcount))return ;
kernel/events/internal.h +4 -0
@@ -36,6 +36,8 @@ struct ring_buffer {struct user_struct *mmap_user;/* AUX area */ +local_t aux_head; +local_t aux_nest;unsigned long aux_pgoff;int aux_nr_pages;atomic_t aux_mmap_count;
@@ -56,6 +58,8 @@ extern void perf_event_wakeup(struct perf_event *event);extern int rb_alloc_aux (struct ring_buffer *rb,struct perf_event *event,pgoff_t pgoff,int nr_pages,int flags);extern void rb_free_aux (struct ring_buffer *rb); +extern struct ring_buffer *ring_buffer_get (struct perf_event *event); +extern void ring_buffer_put (struct ring_buffer *rb);static inline bool rb_has_aux (struct ring_buffer *rb) {
kernel/events/ring_buffer.c +139 -0
145 lines not on this page · raw message
Signature · 1 line
2.1.4
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf: Add API for PMUs to write to the AUX area
perf: Add API for PMUs to write to the AUX area
Commit-ID: fdc2670666f40ab3e03143f04d1ebf4a05e2c24a Gitweb: http://git.kernel.org/tip/fdc2670666f40ab3e03143f04d1ebf4a05e2c24a Author: Alexander Shishkin <[email protected]> AuthorDate: Wed, 14 Jan 2015 14:18:16 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:14:13 +0200
perf: Add API for PMUs to write to the AUX area
For pmus that wish to write data to ring buffer's AUX area, provide perf_aux_output_{begin,end}() calls to initiate/commit data writes, similarly to perf_output_{begin,end}. These also use the same output handle structure. Also, similarly to software counterparts, these will direct inherited events' output to parents' ring buffers.
After the perf_aux_output_begin() returns successfully, handle->size is set to the maximum amount of data that can be written wrt aux_tail pointer, so that no data that the user hasn't seen will be overwritten, therefore this should always be called before hardware writing is enabled. On success, this will return the pointer to pmu driver's private structure allocated for this aux area by pmu::setup_aux. Same pointer can also be retrieved using perf_get_aux() while hardware writing is enabled.
PMU driver should pass the actual amount of data written as a parameter to perf_aux_output_end(). All hardware writes should be completed and visible before this one is called.
Additionally, perf_aux_output_skip() will adjust output handle and aux_head in case some part of the buffer has to be skipped over to maintain hardware's alignment constraints.
Nested writers are forbidden and guards are in place to catch such attempts.
--- include/linux/perf_event.h | 24 +++++++- kernel/events/core.c | 5 +- kernel/events/internal.h | 4 ++ kernel/events/ring_buffer.c | 139 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 4 deletions(-)
include/linux/perf_event.h +23 -1
@@ -573,7 +573,10 @@ struct perf_output_handle {struct ring_buffer *rb;unsigned long wakeup;unsigned long size; -void *addr; +union { +void *addr; +unsigned long head; + };int page; };
@@ -608,6 +611,14 @@ perf_cgroup_from_task(struct task_struct *task)#ifdef CONFIG_PERF_EVENTS +extern void *perf_aux_output_begin (struct perf_output_handle *handle, +struct perf_event *event); +extern void perf_aux_output_end (struct perf_output_handle *handle, +unsigned long size,bool truncated); +extern int perf_aux_output_skip (struct perf_output_handle *handle, +unsigned long size); +extern void *perf_get_aux (struct perf_output_handle *handle); +extern int perf_pmu_register (struct pmu *pmu,const char *name,int type);extern void perf_pmu_unregister (struct pmu *pmu);
@@ -898,6 +909,17 @@ extern void perf_event_disable(struct perf_event *event);extern int __perf_event_disable (void *info);extern void perf_event_task_tick (void );#else /* !CONFIG_PERF_EVENTS: */ +static inline void * +perf_aux_output_begin (struct perf_output_handle *handle, +struct perf_event *event) {return NULL ; } +static inline void +perf_aux_output_end (struct perf_output_handle *handle,unsigned long size, +bool truncated) { } +static inline int +perf_aux_output_skip (struct perf_output_handle *handle, +unsigned long size) {return -EINVAL ; } +static inline void * +perf_get_aux (struct perf_output_handle *handle) {return NULL ; }static inline void perf_event_task_sched_in (struct task_struct *prev,struct task_struct *task) { }
kernel/events/core.c +2 -3
@@ -3423,7 +3423,6 @@ static void free_event_rcu(struct rcu_head *head)kfree (event); } -static void ring_buffer_put (struct ring_buffer *rb);static void ring_buffer_attach (struct perf_event *event,struct ring_buffer *rb);
@@ -4361,7 +4360,7 @@ static void rb_free_rcu(struct rcu_head *rcu_head)rb_free (rb); } -static struct ring_buffer *ring_buffer_get (struct perf_event *event) +struct ring_buffer *ring_buffer_get (struct perf_event *event) {struct ring_buffer *rb;
@@ -4376,7 +4375,7 @@ static struct ring_buffer *ring_buffer_get(struct perf_event *event)return rb; } -static void ring_buffer_put (struct ring_buffer *rb) +void ring_buffer_put (struct ring_buffer *rb) {if (!atomic_dec_and_test (&rb->refcount))return ;
kernel/events/internal.h +4 -0
@@ -36,6 +36,8 @@ struct ring_buffer {struct user_struct *mmap_user;/* AUX area */ +local_t aux_head; +local_t aux_nest;unsigned long aux_pgoff;int aux_nr_pages;atomic_t aux_mmap_count;
@@ -56,6 +58,8 @@ extern void perf_event_wakeup(struct perf_event *event);extern int rb_alloc_aux (struct ring_buffer *rb,struct perf_event *event,pgoff_t pgoff,int nr_pages,int flags);extern void rb_free_aux (struct ring_buffer *rb); +extern struct ring_buffer *ring_buffer_get (struct perf_event *event); +extern void ring_buffer_put (struct ring_buffer *rb);static inline bool rb_has_aux (struct ring_buffer *rb) {
kernel/events/ring_buffer.c +139 -0
145 lines not on this page · raw message
Alexander Shishkin
reviewerPATCH v9 8/14 perf: Support overwrite mode for AUX area
In reply to Alexander ShishkinThis adds support for overwrite mode in the AUX area, which means "keep collecting data till you're stopped", turning AUX area into a circular buffer, where new data overwrites old data. It does not depend on data buffer's overwrite mode, so that it doesn't lose sideband data that is instrumental for processing AUX data.
Overwrite mode is enabled at mapping AUX area read only. Even though aux_tail in the buffer's user page might be user writable, it will be ignored in this mode.
A PERF_RECORD_AUX with PERF_AUX_FLAG_OVERWRITE set is written to the perf data stream every time an event writes new data to the AUX area. The pmu driver might not be able to infer the exact beginning of the new data in each snapshot, some drivers will only provide the tail, which is aux_offset + aux_size in the AUX record. Consumer has to be able to tell the new data from the old one, for example, by means of time stamps if such are provided in the trace.
Consumer is also responsible for disabling any events that might write to the AUX area (thus potentially racing with the consumer) before collecting the data.
--- include/uapi/linux/perf_event.h | 1 + kernel/events/internal.h | 1 + kernel/events/ring_buffer.c | 48 ++++++++++++++++++++++++++++------------- 3 files changed, 35 insertions(+), 15 deletions(-)
include/uapi/linux/perf_event.h +1 -0
@@ -781,6 +781,7 @@ enum perf_callchain_context {* PERF_RECORD_AUX::flags bits */ #define PERF_AUX_FLAG_TRUNCATED 0x01/* record was truncated to fit */ +#define PERF_AUX_FLAG_OVERWRITE 0x02/* snapshot from overwrite mode */ #define PERF_FLAG_FD_NO_GROUP (1UL << 0)#define PERF_FLAG_FD_OUTPUT (1UL << 1)
kernel/events/internal.h +1 -0
@@ -40,6 +40,7 @@ struct ring_buffer {local_t aux_nest;unsigned long aux_pgoff;int aux_nr_pages; +int aux_overwrite;atomic_t aux_mmap_count;unsigned long aux_mmap_locked;void (*free_aux)(void *);
kernel/events/ring_buffer.c +33 -15
78 lines not on this page · raw message
Signature · 1 line
2.1.4
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf: Support overwrite mode for the AUX area
perf: Support overwrite mode for the AUX area
Commit-ID: 2023a0d2829e521fe6ad6b9907f3f90bfbf57142 Gitweb: http://git.kernel.org/tip/2023a0d2829e521fe6ad6b9907f3f90bfbf57142 Author: Alexander Shishkin <[email protected]> AuthorDate: Wed, 14 Jan 2015 14:18:17 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:14:15 +0200
perf: Support overwrite mode for the AUX area
This adds support for overwrite mode in the AUX area, which means "keep collecting data till you're stopped", turning AUX area into a circular buffer, where new data overwrites old data. It does not depend on data buffer's overwrite mode, so that it doesn't lose sideband data that is instrumental for processing AUX data.
Overwrite mode is enabled at mapping AUX area read only. Even though aux_tail in the buffer's user page might be user writable, it will be ignored in this mode.
A PERF_RECORD_AUX with PERF_AUX_FLAG_OVERWRITE set is written to the perf data stream every time an event writes new data to the AUX area. The pmu driver might not be able to infer the exact beginning of the new data in each snapshot, some drivers will only provide the tail, which is aux_offset + aux_size in the AUX record. Consumer has to be able to tell the new data from the old one, for example, by means of time stamps if such are provided in the trace.
Consumer is also responsible for disabling any events that might write to the AUX area (thus potentially racing with the consumer) before collecting the data.
--- include/uapi/linux/perf_event.h | 1 + kernel/events/internal.h | 1 + kernel/events/ring_buffer.c | 48 ++++++++++++++++++++++++++++------------- 3 files changed, 35 insertions(+), 15 deletions(-)
include/uapi/linux/perf_event.h +1 -0
@@ -803,6 +803,7 @@ enum perf_callchain_context {* PERF_RECORD_AUX::flags bits */ #define PERF_AUX_FLAG_TRUNCATED 0x01/* record was truncated to fit */ +#define PERF_AUX_FLAG_OVERWRITE 0x02/* snapshot from overwrite mode */ #define PERF_FLAG_FD_NO_GROUP (1UL << 0)#define PERF_FLAG_FD_OUTPUT (1UL << 1)
kernel/events/internal.h +1 -0
@@ -40,6 +40,7 @@ struct ring_buffer {local_t aux_nest;unsigned long aux_pgoff;int aux_nr_pages; +int aux_overwrite;atomic_t aux_mmap_count;unsigned long aux_mmap_locked;void (*free_aux)(void *);
kernel/events/ring_buffer.c +33 -15
78 lines not on this page · raw message
Alexander Shishkin
reviewerPATCH v9 9/14 perf: Add wakeup watermark control to AUX area
In reply to Alexander ShishkinWhen AUX area gets a certain amount of new data, we want to wake up userspace to collect it. This adds a new control to specify how much data will cause a wakeup. This is then passed down to pmu drivers via output handle's "wakeup" field, so that the driver can find the nearest point where it can generate an interrupt.
We repurpose __reserved_2 in the event attribute for this, even though it was never checked to be zero before, aux_watermark will only matter for new AUX-aware code, so the old code should still be fine.
--- include/uapi/linux/perf_event.h | 8 ++++++-- kernel/events/core.c | 3 ++- kernel/events/internal.h | 4 +++- kernel/events/ring_buffer.c | 22 +++++++++++++++++++--- 4 files changed, 30 insertions(+), 7 deletions(-)
include/uapi/linux/perf_event.h +6 -2
@@ -240,6 +240,7 @@ enum perf_event_read_format {#define PERF_ATTR_SIZE_VER3 96/* add: sample_regs_user */ /* add: sample_stack_user */ #define PERF_ATTR_SIZE_VER4 104/* add: sample_regs_intr */ +/* add: aux_watermark */ /* * Hardware event_id to monitor via a performance monitoring event:
@@ -334,8 +335,11 @@ struct perf_event_attr {*/ __u32 sample_stack_user; -/* Align to u64. */ -__u32 __reserved_2; +/* +* Wakeup watermark for AUX area +*/ +__u32 aux_watermark; +/* * Defines set of regs to dump for each sample * state captured on:
kernel/events/core.c +2 -1
@@ -4421,7 +4421,8 @@ accounting:perf_event_init_userpage (event);perf_event_update_userpage (event); }else { - ret =rb_alloc_aux (rb, event, vma->vm_pgoff, nr_pages, flags); + ret =rb_alloc_aux (rb, event, vma->vm_pgoff, nr_pages, + event->attr.aux_watermark, flags);if (!ret) rb->aux_mmap_locked = extra; }
kernel/events/internal.h +3 -1
@@ -27,6 +27,7 @@ struct ring_buffer {local_t lost;/* nr records lost */ long watermark;/* wakeup watermark */ +long aux_watermark;/* poll crap */ spinlock_t event_lock;struct list_head event_list;
@@ -38,6 +39,7 @@ struct ring_buffer {/* AUX area */ local_t aux_head;local_t aux_nest; +local_t aux_wakeup;unsigned long aux_pgoff;int aux_nr_pages;int aux_overwrite;
@@ -57,7 +59,7 @@ extern struct ring_buffer * rb_alloc(int nr_pages, long watermark, int cpu, int flags);extern void perf_event_wakeup (struct perf_event *event);extern int rb_alloc_aux (struct ring_buffer *rb,struct perf_event *event, -pgoff_t pgoff,int nr_pages,int flags); +pgoff_t pgoff,int nr_pages,long watermark,int flags);extern void rb_free_aux (struct ring_buffer *rb);extern struct ring_buffer *ring_buffer_get (struct perf_event *event);extern void ring_buffer_put (struct ring_buffer *rb);
kernel/events/ring_buffer.c +19 -3
@@ -295,6 +295,7 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,*/ if (!rb->aux_overwrite) { aux_tail =ACCESS_ONCE (rb->user_page->aux_tail); + handle->wakeup =local_read (&rb->aux_wakeup) + rb->aux_watermark;if (aux_head - aux_tail <perf_aux_size (rb)) handle->size =CIRC_SPACE (aux_head, aux_tail,perf_aux_size (rb));
@@ -358,9 +359,12 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size,perf_event_aux_event (handle->event, aux_head, size, flags); } - rb->user_page->aux_head =local_read (&rb->aux_head); + aux_head = rb->user_page->aux_head =local_read (&rb->aux_head); -perf_output_wakeup (handle); +if (aux_head -local_read (&rb->aux_wakeup) >= rb->aux_watermark) { +perf_output_wakeup (handle); +local_add (rb->aux_watermark, &rb->aux_wakeup); + } handle->event =NULL ;local_set (&rb->aux_nest,0 );
@@ -382,6 +386,14 @@ int perf_aux_output_skip(struct perf_output_handle *handle, unsigned long size)local_add (size, &rb->aux_head); + aux_head = rb->user_page->aux_head =local_read (&rb->aux_head); +if (aux_head -local_read (&rb->aux_wakeup) >= rb->aux_watermark) { +perf_output_wakeup (handle); +local_add (rb->aux_watermark, &rb->aux_wakeup); + handle->wakeup =local_read (&rb->aux_wakeup) + + rb->aux_watermark; + } + handle->head = aux_head; handle->size -= size;
@@ -432,7 +444,7 @@ static void rb_free_aux_page(struct ring_buffer *rb, int idx) }int rb_alloc_aux (struct ring_buffer *rb,struct perf_event *event, -pgoff_t pgoff,int nr_pages,int flags) +pgoff_t pgoff,int nr_pages,long watermark,int flags) {bool overwrite = !(flags &RING_BUFFER_WRITABLE );int node = (event->cpu ==-1 ) ?-1 :cpu_to_node (event->cpu);
@@ -496,6 +508,10 @@ int rb_alloc_aux(struct ring_buffer *rb, struct perf_event *event,atomic_set (&rb->aux_refcount,1 ); rb->aux_overwrite = overwrite; + rb->aux_watermark = watermark; + +if (!rb->aux_watermark && !rb->aux_overwrite) + rb->aux_watermark = nr_pages << (PAGE_SHIFT -1 ); out:if (!ret)
Signature · 1 line
2.1.4
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf: Add wakeup watermark control to the AUX area
perf: Add wakeup watermark control to the AUX area
Commit-ID: 1a5941312414c71dece6717da9a0fa1303127afa Gitweb: http://git.kernel.org/tip/1a5941312414c71dece6717da9a0fa1303127afa Author: Alexander Shishkin <[email protected]> AuthorDate: Wed, 14 Jan 2015 14:18:18 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:14:16 +0200
perf: Add wakeup watermark control to the AUX area
When AUX area gets a certain amount of new data, we want to wake up userspace to collect it. This adds a new control to specify how much data will cause a wakeup. This is then passed down to pmu drivers via output handle's "wakeup" field, so that the driver can find the nearest point where it can generate an interrupt.
We repurpose __reserved_2 in the event attribute for this, even though it was never checked to be zero before, aux_watermark will only matter for new AUX-aware code, so the old code should still be fine.
--- include/uapi/linux/perf_event.h | 7 +++++++ kernel/events/core.c | 3 ++- kernel/events/internal.h | 4 +++- kernel/events/ring_buffer.c | 22 +++++++++++++++++++--- 4 files changed, 31 insertions(+), 5 deletions(-)
include/uapi/linux/perf_event.h +7 -0
@@ -261,6 +261,7 @@ enum perf_event_read_format {#define PERF_ATTR_SIZE_VER3 96/* add: sample_regs_user */ /* add: sample_stack_user */ #define PERF_ATTR_SIZE_VER4 104/* add: sample_regs_intr */ +#define PERF_ATTR_SIZE_VER5 112/* add: aux_watermark */ /* * Hardware event_id to monitor via a performance monitoring event:
@@ -366,6 +367,12 @@ struct perf_event_attr {* See asm/perf_regs.h for details. */ __u64 sample_regs_intr; + +/* +* Wakeup watermark for AUX area +*/ +__u32 aux_watermark; +__u32 __reserved_2;/* align to __u64 */ };#define perf_flags (attr) (*(&(attr)->read_format + 1))
kernel/events/core.c +2 -1
@@ -4677,7 +4677,8 @@ accounting:perf_event_init_userpage (event);perf_event_update_userpage (event); }else { - ret =rb_alloc_aux (rb, event, vma->vm_pgoff, nr_pages, flags); + ret =rb_alloc_aux (rb, event, vma->vm_pgoff, nr_pages, + event->attr.aux_watermark, flags);if (!ret) rb->aux_mmap_locked = extra; }
kernel/events/internal.h +3 -1
@@ -27,6 +27,7 @@ struct ring_buffer {local_t lost;/* nr records lost */ long watermark;/* wakeup watermark */ +long aux_watermark;/* poll crap */ spinlock_t event_lock;struct list_head event_list;
@@ -38,6 +39,7 @@ struct ring_buffer {/* AUX area */ local_t aux_head;local_t aux_nest; +local_t aux_wakeup;unsigned long aux_pgoff;int aux_nr_pages;int aux_overwrite;
@@ -57,7 +59,7 @@ extern struct ring_buffer * rb_alloc(int nr_pages, long watermark, int cpu, int flags);extern void perf_event_wakeup (struct perf_event *event);extern int rb_alloc_aux (struct ring_buffer *rb,struct perf_event *event, -pgoff_t pgoff,int nr_pages,int flags); +pgoff_t pgoff,int nr_pages,long watermark,int flags);extern void rb_free_aux (struct ring_buffer *rb);extern struct ring_buffer *ring_buffer_get (struct perf_event *event);extern void ring_buffer_put (struct ring_buffer *rb);
kernel/events/ring_buffer.c +19 -3
@@ -296,6 +296,7 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,*/ if (!rb->aux_overwrite) { aux_tail =ACCESS_ONCE (rb->user_page->aux_tail); + handle->wakeup =local_read (&rb->aux_wakeup) + rb->aux_watermark;if (aux_head - aux_tail <perf_aux_size (rb)) handle->size =CIRC_SPACE (aux_head, aux_tail,perf_aux_size (rb));
@@ -359,9 +360,12 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size,perf_event_aux_event (handle->event, aux_head, size, flags); } - rb->user_page->aux_head =local_read (&rb->aux_head); + aux_head = rb->user_page->aux_head =local_read (&rb->aux_head); -perf_output_wakeup (handle); +if (aux_head -local_read (&rb->aux_wakeup) >= rb->aux_watermark) { +perf_output_wakeup (handle); +local_add (rb->aux_watermark, &rb->aux_wakeup); + } handle->event =NULL ;local_set (&rb->aux_nest,0 );
@@ -383,6 +387,14 @@ int perf_aux_output_skip(struct perf_output_handle *handle, unsigned long size)local_add (size, &rb->aux_head); + aux_head = rb->user_page->aux_head =local_read (&rb->aux_head); +if (aux_head -local_read (&rb->aux_wakeup) >= rb->aux_watermark) { +perf_output_wakeup (handle); +local_add (rb->aux_watermark, &rb->aux_wakeup); + handle->wakeup =local_read (&rb->aux_wakeup) + + rb->aux_watermark; + } + handle->head = aux_head; handle->size -= size;
@@ -433,7 +445,7 @@ static void rb_free_aux_page(struct ring_buffer *rb, int idx) }int rb_alloc_aux (struct ring_buffer *rb,struct perf_event *event, -pgoff_t pgoff,int nr_pages,int flags) +pgoff_t pgoff,int nr_pages,long watermark,int flags) {bool overwrite = !(flags &RING_BUFFER_WRITABLE );int node = (event->cpu ==-1 ) ?-1 :cpu_to_node (event->cpu);
@@ -497,6 +509,10 @@ int rb_alloc_aux(struct ring_buffer *rb, struct perf_event *event,atomic_set (&rb->aux_refcount,1 ); rb->aux_overwrite = overwrite; + rb->aux_watermark = watermark; + +if (!rb->aux_watermark && !rb->aux_overwrite) + rb->aux_watermark = nr_pages << (PAGE_SHIFT -1 ); out:if (!ret)
Alexander Shishkin
reviewerPATCH v9 10/14 x86: Add Intel Processor Trace (INTEL_PT) cpu feature detection
In reply to Alexander ShishkinIntel Processor Trace is an architecture extension that allows for program flow tracing.
--- arch/x86/include/asm/cpufeature.h | 1 + arch/x86/kernel/cpu/scattered.c | 1 + 2 files changed, 2 insertions(+)
arch/x86/include/asm/cpufeature.h +1 -0
@@ -189,6 +189,7 @@#define X86_FEATURE_DTHERM ( 7*32+ 7)/* Digital Thermal Sensor */ #define X86_FEATURE_HW_PSTATE ( 7*32+ 8)/* AMD HW-PState */ #define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9)/* AMD ProcFeedbackInterface */ +#define X86_FEATURE_INTEL_PT ( 7*32+10)/* Intel Processor Trace */ /* Virtualization flags: Linux defined, word 8 */ #define X86_FEATURE_TPR_SHADOW ( 8*32+ 0)/* Intel TPR Shadow */
arch/x86/kernel/cpu/scattered.c +1 -0
@@ -36,6 +36,7 @@ void init_scattered_cpuid_features(struct cpuinfo_x86 *c) { X86_FEATURE_ARAT, CR_EAX, 2, 0x00000006, 0 }, { X86_FEATURE_PLN, CR_EAX, 4, 0x00000006, 0 }, { X86_FEATURE_PTS, CR_EAX, 6, 0x00000006, 0 }, + { X86_FEATURE_INTEL_PT, CR_EBX,25, 0x00000007, 0 }, { X86_FEATURE_APERFMPERF, CR_ECX, 0, 0x00000006, 0 }, { X86_FEATURE_EPB, CR_ECX, 3, 0x00000006, 0 }, { X86_FEATURE_HW_PSTATE, CR_EDX, 7, 0x80000007, 0 },
Signature · 1 line
2.1.4
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] x86: Add Intel Processor Trace (INTEL_PT) cpu feature detection
x86: Add Intel Processor Trace (INTEL_PT) cpu feature detection
Commit-ID: ed69628b3b04578179334393d7f5fe60a2681f1c Gitweb: http://git.kernel.org/tip/ed69628b3b04578179334393d7f5fe60a2681f1c Author: Alexander Shishkin <[email protected]> AuthorDate: Wed, 14 Jan 2015 14:18:19 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:14:18 +0200
x86: Add Intel Processor Trace (INTEL_PT) cpu feature detection
Intel Processor Trace is an architecture extension that allows for program flow tracing.
--- arch/x86/include/asm/cpufeature.h | 1 + arch/x86/kernel/cpu/scattered.c | 1 + 2 files changed, 2 insertions(+)
arch/x86/include/asm/cpufeature.h +1 -0
@@ -195,6 +195,7 @@#define X86_FEATURE_HWP_ACT_WINDOW ( 7*32+ 12)/* Intel HWP_ACT_WINDOW */ #define X86_FEATURE_HWP_EPP ( 7*32+13)/* Intel HWP_EPP */ #define X86_FEATURE_HWP_PKG_REQ ( 7*32+14)/* Intel HWP_PKG_REQ */ +#define X86_FEATURE_INTEL_PT ( 7*32+15)/* Intel Processor Trace */ /* Virtualization flags: Linux defined, word 8 */ #define X86_FEATURE_TPR_SHADOW ( 8*32+ 0)/* Intel TPR Shadow */
arch/x86/kernel/cpu/scattered.c +1 -0
@@ -41,6 +41,7 @@ void init_scattered_cpuid_features(struct cpuinfo_x86 *c) { X86_FEATURE_HWP_ACT_WINDOW, CR_EAX, 9, 0x00000006, 0 }, { X86_FEATURE_HWP_EPP, CR_EAX,10, 0x00000006, 0 }, { X86_FEATURE_HWP_PKG_REQ, CR_EAX,11, 0x00000006, 0 }, + { X86_FEATURE_INTEL_PT, CR_EBX,25, 0x00000007, 0 }, { X86_FEATURE_APERFMPERF, CR_ECX, 0, 0x00000006, 0 }, { X86_FEATURE_EPB, CR_ECX, 3, 0x00000006, 0 }, { X86_FEATURE_HW_PSTATE, CR_EDX, 7, 0x80000007, 0 },
Alexander Shishkin
reviewerPATCH v9 11/14 x86: perf: Intel PT and LBR/BTS are mutually exclusive
In reply to Alexander ShishkinIntel PT cannot be used at the same time as LBR or BTS and will cause a
general protection fault if they are used together. In order to avoid
fixing up GPs in the fast path, instead we disallow creating LBR/BTS events when PT events are present and vice versa.
--- arch/x86/kernel/cpu/perf_event.c | 43 ++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event.h | 40 +++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event_intel.c | 26 ++++++++++---------- 3 files changed, 95 insertions(+), 14 deletions(-)
arch/x86/kernel/cpu/perf_event.c +43 -0
@@ -259,6 +259,14 @@ static void hw_perf_event_destroy(struct perf_event *event) } } +void hw_perf_lbr_event_destroy (struct perf_event *event) +{ +hw_perf_event_destroy (event); + +/* undo the lbr/bts event accounting */ +x86_del_exclusive (x86_lbr_exclusive_lbr); +} +static inline int x86_pmu_initialized (void ) {return x86_pmu.handle_irq !=NULL ;
@@ -298,6 +306,35 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event *event)return x86_pmu_extra_regs (val, event); } +/* +* Check if we can create event of a certain type (that no conflicting events +* are present). +*/ +int x86_add_exclusive (unsigned int what) +{ +int ret = -EBUSY , i; + +if (atomic_inc_not_zero (&x86_pmu.lbr_exclusive[what])) +return 0 ; + +mutex_lock (&pmc_reserve_mutex); +for (i =0 ; i <ARRAY_SIZE (x86_pmu.lbr_exclusive); i++) +if (i != what &&atomic_read (&x86_pmu.lbr_exclusive[i])) + goto out; + +atomic_inc (&x86_pmu.lbr_exclusive[what]); + ret =0 ; + +out: +mutex_unlock (&pmc_reserve_mutex); +return ret; +} + +void x86_del_exclusive (unsigned int what) +{ +atomic_dec (&x86_pmu.lbr_exclusive[what]); +} +int x86_setup_perfctr (struct perf_event *event) {struct perf_event_attr *attr = &event->attr;
@@ -342,6 +379,12 @@ int x86_setup_perfctr(struct perf_event *event)/* BTS is currently only allowed for user-mode. */ if (!attr->exclude_kernel)return -EOPNOTSUPP ; + +/* disallow bts if conflicting events are present */ +if (x86_add_exclusive (x86_lbr_exclusive_lbr)) +return -EBUSY ; + + event->destroy = hw_perf_lbr_event_destroy; } hwc->config |= config;
arch/x86/kernel/cpu/perf_event.h +40 -0
@@ -406,6 +406,12 @@ union x86_pmu_config { #define X86_CONFIG(args...) ((union x86_pmu_config){.bits = {args}}).value +enum { + x86_lbr_exclusive_lbr, + x86_lbr_exclusive_pt, + x86_lbr_exclusive_max, +}; +/* * struct x86_pmu - generic x86 pmu */
@@ -502,6 +508,11 @@ struct x86_pmu {bool lbr_double_abort;/* duplicated lbr aborts */ /* +* Intel PT/LBR/BTS are exclusive +*/ +atomic_t lbr_exclusive[x86_lbr_exclusive_max]; + +/* * Extra registers for events */ struct extra_reg *extra_regs;
@@ -586,6 +597,12 @@ static inline int x86_pmu_rdpmc_index(int index)return x86_pmu.rdpmc_index ? x86_pmu.rdpmc_index (index) : index; } +int x86_add_exclusive (unsigned int what); + +void x86_del_exclusive (unsigned int what); + +void hw_perf_lbr_event_destroy (struct perf_event *event); +int x86_setup_perfctr (struct perf_event *event);int x86_pmu_hw_config (struct perf_event *event);
@@ -672,6 +689,29 @@ static inline int amd_pmu_init(void)#ifdef CONFIG_CPU_SUP_INTEL +static inline bool intel_pmu_needs_lbr_smpl (struct perf_event *event) +{ +/* user explicitly requested branch sampling */ +if (has_branch_stack (event)) +return true; + +/* implicit branch sampling to correct PEBS skid */ +if (x86_pmu.intel_cap.pebs_trap && event->attr.precise_ip >1 && + x86_pmu.intel_cap.pebs_format <2 ) +return true; + +return false; +} + +static inline bool intel_pmu_has_bts (struct perf_event *event) +{ +if (event->attr.config ==PERF_COUNT_HW_BRANCH_INSTRUCTIONS && + !event->attr.freq && event->hw.sample_period ==1 ) +return true; + +return false; +} +int intel_pmu_save_and_restart (struct perf_event *event); struct event_constraint *
arch/x86/kernel/cpu/perf_event_intel.c +12 -14
@@ -1029,20 +1029,6 @@ static __initconst const u64 slm_hw_cache_event_ids }, }; -static inline bool intel_pmu_needs_lbr_smpl (struct perf_event *event) -{ -/* user explicitly requested branch sampling */ -if (has_branch_stack (event)) -return true; - -/* implicit branch sampling to correct PEBS skid */ -if (x86_pmu.intel_cap.pebs_trap && event->attr.precise_ip >1 && - x86_pmu.intel_cap.pebs_format <2 ) -return true; - -return false; -} -static void intel_pmu_disable_all (void ) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events);
@@ -1751,6 +1737,18 @@ static int intel_pmu_hw_config(struct perf_event *event) ret =intel_pmu_setup_lbr_filter (event);if (ret)return ret; + +/* +* bts is set up earlier in this path, so don't account +* twice +*/ +if (!intel_pmu_has_bts (event)) { +/* disallow lbr if conflicting events are present */ +if (x86_add_exclusive (x86_lbr_exclusive_lbr)) +return -EBUSY ; + + event->destroy = hw_perf_lbr_event_destroy; + } }if (event->attr.type !=PERF_TYPE_RAW )
Signature · 1 line
2.1.4
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf/x86: Mark Intel PT and LBR/ BTS as mutually exclusive
perf/x86: Mark Intel PT and LBR/BTS as mutually exclusive
Commit-ID: 4807034248bed58d49a4f9f450c024e3b0f58577 Gitweb: http://git.kernel.org/tip/4807034248bed58d49a4f9f450c024e3b0f58577 Author: Alexander Shishkin <[email protected]> AuthorDate: Wed, 14 Jan 2015 14:18:20 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:14:19 +0200
perf/x86: Mark Intel PT and LBR/BTS as mutually exclusive
Intel PT cannot be used at the same time as LBR or BTS and will cause a
general protection fault if they are used together. In order to avoid
fixing up GPs in the fast path, instead we disallow creating LBR/BTS events when PT events are present and vice versa.
--- arch/x86/kernel/cpu/perf_event.c | 43 ++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event.h | 40 +++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event_intel.c | 11 +++++++++ 3 files changed, 94 insertions(+)
arch/x86/kernel/cpu/perf_event.c +43 -0
@@ -263,6 +263,14 @@ static void hw_perf_event_destroy(struct perf_event *event) } } +void hw_perf_lbr_event_destroy (struct perf_event *event) +{ +hw_perf_event_destroy (event); + +/* undo the lbr/bts event accounting */ +x86_del_exclusive (x86_lbr_exclusive_lbr); +} +static inline int x86_pmu_initialized (void ) {return x86_pmu.handle_irq !=NULL ;
@@ -302,6 +310,35 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event *event)return x86_pmu_extra_regs (val, event); } +/* +* Check if we can create event of a certain type (that no conflicting events +* are present). +*/ +int x86_add_exclusive (unsigned int what) +{ +int ret = -EBUSY , i; + +if (atomic_inc_not_zero (&x86_pmu.lbr_exclusive[what])) +return 0 ; + +mutex_lock (&pmc_reserve_mutex); +for (i =0 ; i <ARRAY_SIZE (x86_pmu.lbr_exclusive); i++) +if (i != what &&atomic_read (&x86_pmu.lbr_exclusive[i])) + goto out; + +atomic_inc (&x86_pmu.lbr_exclusive[what]); + ret =0 ; + +out: +mutex_unlock (&pmc_reserve_mutex); +return ret; +} + +void x86_del_exclusive (unsigned int what) +{ +atomic_dec (&x86_pmu.lbr_exclusive[what]); +} +int x86_setup_perfctr (struct perf_event *event) {struct perf_event_attr *attr = &event->attr;
@@ -346,6 +383,12 @@ int x86_setup_perfctr(struct perf_event *event)/* BTS is currently only allowed for user-mode. */ if (!attr->exclude_kernel)return -EOPNOTSUPP ; + +/* disallow bts if conflicting events are present */ +if (x86_add_exclusive (x86_lbr_exclusive_lbr)) +return -EBUSY ; + + event->destroy = hw_perf_lbr_event_destroy; } hwc->config |= config;
arch/x86/kernel/cpu/perf_event.h +40 -0
@@ -408,6 +408,12 @@ union x86_pmu_config { #define X86_CONFIG(args...) ((union x86_pmu_config){.bits = {args}}).value +enum { + x86_lbr_exclusive_lbr, + x86_lbr_exclusive_pt, + x86_lbr_exclusive_max, +}; +/* * struct x86_pmu - generic x86 pmu */
@@ -506,6 +512,11 @@ struct x86_pmu {bool lbr_double_abort;/* duplicated lbr aborts */ /* +* Intel PT/LBR/BTS are exclusive +*/ +atomic_t lbr_exclusive[x86_lbr_exclusive_max]; + +/* * Extra registers for events */ struct extra_reg *extra_regs;
@@ -603,6 +614,12 @@ static inline int x86_pmu_rdpmc_index(int index)return x86_pmu.rdpmc_index ? x86_pmu.rdpmc_index (index) : index; } +int x86_add_exclusive (unsigned int what); + +void x86_del_exclusive (unsigned int what); + +void hw_perf_lbr_event_destroy (struct perf_event *event); +int x86_setup_perfctr (struct perf_event *event);int x86_pmu_hw_config (struct perf_event *event);
@@ -689,6 +706,29 @@ static inline int amd_pmu_init(void)#ifdef CONFIG_CPU_SUP_INTEL +static inline bool intel_pmu_needs_lbr_smpl (struct perf_event *event) +{ +/* user explicitly requested branch sampling */ +if (has_branch_stack (event)) +return true; + +/* implicit branch sampling to correct PEBS skid */ +if (x86_pmu.intel_cap.pebs_trap && event->attr.precise_ip >1 && + x86_pmu.intel_cap.pebs_format <2 ) +return true; + +return false; +} + +static inline bool intel_pmu_has_bts (struct perf_event *event) +{ +if (event->attr.config ==PERF_COUNT_HW_BRANCH_INSTRUCTIONS && + !event->attr.freq && event->hw.sample_period ==1 ) +return true; + +return false; +} +int intel_pmu_save_and_restart (struct perf_event *event); struct event_constraint *
arch/x86/kernel/cpu/perf_event_intel.c +11 -0
@@ -1942,6 +1942,17 @@ static int intel_pmu_hw_config(struct perf_event *event) ret =intel_pmu_setup_lbr_filter (event);if (ret)return ret; + +/* +* BTS is set up earlier in this path, so don't account twice +*/ +if (!intel_pmu_has_bts (event)) { +/* disallow lbr if conflicting events are present */ +if (x86_add_exclusive (x86_lbr_exclusive_lbr)) +return -EBUSY ; + + event->destroy = hw_perf_lbr_event_destroy; + } }if (event->attr.type !=PERF_TYPE_RAW )
Alexander Shishkin
reviewerPATCH v9 12/14 x86: perf: intel_pt: Intel PT PMU driver
In reply to Alexander ShishkinAdd support for Intel Processor Trace (PT) to kernel's perf events. PT is an extension of Intel Architecture that collects information about software execuction such as control flow, execution modes and timings and formats it into highly compressed binary packets. Even being compressed, these packets are generated at hundreds of megabytes per second per core, which makes it impractical to decode them on the fly in the kernel.
This driver exports trace data by through AUX space in the perf ring buffer, which is zero-copy mapped into userspace for faster data retrieval.
--- arch/x86/include/uapi/asm/msr-index.h | 18 + arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/intel_pt.h | 131 ++++ arch/x86/kernel/cpu/perf_event.h | 2 + arch/x86/kernel/cpu/perf_event_intel.c | 8 + arch/x86/kernel/cpu/perf_event_intel_pt.c | 1095 +++++++++++++++++++++++++++++ 6 files changed, 1255 insertions(+) create mode 100644 arch/x86/kernel/cpu/intel_pt.h create mode 100644 arch/x86/kernel/cpu/perf_event_intel_pt.c
arch/x86/include/uapi/asm/msr-index.h +18 -0
@@ -74,6 +74,24 @@#define MSR_IA32_PERF_CAPABILITIES 0x00000345#define MSR_PEBS_LD_LAT_THRESHOLD 0x000003f6 +#define MSR_IA32_RTIT_CTL 0x00000570 +#define RTIT_CTL_TRACEEN BIT(0) +#define RTIT_CTL_OS BIT(2) +#define RTIT_CTL_USR BIT(3) +#define RTIT_CTL_CR3EN BIT(7) +#define RTIT_CTL_TOPA BIT(8) +#define RTIT_CTL_TSC_EN BIT(10) +#define RTIT_CTL_DISRETC BIT(11) +#define RTIT_CTL_BRANCH_EN BIT(13) +#define MSR_IA32_RTIT_STATUS 0x00000571 +#define RTIT_STATUS_CONTEXTEN BIT(1) +#define RTIT_STATUS_TRIGGEREN BIT(2) +#define RTIT_STATUS_ERROR BIT(4) +#define RTIT_STATUS_STOPPED BIT(5) +#define MSR_IA32_RTIT_CR3_MATCH 0x00000572 +#define MSR_IA32_RTIT_OUTPUT_BASE 0x00000560 +#define MSR_IA32_RTIT_OUTPUT_MASK 0x00000561 +#define MSR_MTRRfix64K_00000 0x00000250#define MSR_MTRRfix16K_80000 0x00000258#define MSR_MTRRfix16K_A0000 0x00000259
arch/x86/kernel/cpu/Makefile +1 -0
@@ -40,6 +40,7 @@ endif obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_p6.o perf_event_knc.o perf_event_p4.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_lbr.o perf_event_intel_ds.o perf_event_intel.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_rapl.o +obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += perf_event_intel_uncore.o \ perf_event_intel_uncore_snb.o \
arch/x86/kernel/cpu/intel_pt.h new file +131 -0
131 lines not on this page · raw message
arch/x86/kernel/cpu/perf_event.h +2 -0
@@ -787,6 +787,8 @@ void intel_pmu_lbr_init_snb(void);int intel_pmu_setup_lbr_filter (struct perf_event *event); +void intel_pt_interrupt (void ); +int p4_pmu_init (void );int p6_pmu_init (void );
arch/x86/kernel/cpu/perf_event_intel.c +8 -0
@@ -1385,6 +1385,14 @@ again: }/* +* Intel PT +*/ +if (__test_and_clear_bit (55 , (unsigned long *)&status)) { + handled++; +intel_pt_interrupt (); + } + +/* * Checkpointed counters can lead to 'spurious' PMIs because the * rollback caused by the PMI will have cleared the overflow status * bit. Therefore always force probe these counters.
arch/x86/kernel/cpu/perf_event_intel_pt.c new file +1095 -0
1,095 lines not on this page · raw message
Signature · 1 line
2.1.4
Peter Zijlstra
maintainerRe: [PATCH v9 12/14] x86: perf: intel_pt: Intel PT PMU driver
arch/x86/kernel/cpu/perf_event_intel_pt.c line 1081
Quoted 5 lines · Alexander Shishkin
arch/x86/kernel/cpu/perf_event_intel_pt.c new file +4
-0+static __init int pt_init (void ) +{ + pt_pmu.pmu.attr_groups = pt_attr_groups; + pt_pmu.pmu.task_ctx_nr = perf_hw_context;
I just noticed this one, how can this ever work? We want the PT thing to always get programmed, right? -- because we disallow creating more than 1?
Which reminds me; does that exclusive thing you did not allow you to create one cpu wide and one per task (they're separate contexts) events? At which point we're not schedulable at all.
By sticking it on the HW context list it can end up not being programed because its stuck after a bunch of hardware events that don't all fit on the PMU.
Would not the SW list be more appropriate; the SW list is a list of events that's guaranteed to be schedulable.
Quoted 12 lines
arch/x86/kernel/cpu/perf_event_intel_pt.c new file +12
-0+ pt_pmu.pmu.event_init = pt_event_init; + pt_pmu.pmu.add = pt_event_add; + pt_pmu.pmu.del = pt_event_del; + pt_pmu.pmu.start = pt_event_start; + pt_pmu.pmu.stop = pt_event_stop; + pt_pmu.pmu.read = pt_event_read; + pt_pmu.pmu.setup_aux = pt_buffer_setup_aux; + pt_pmu.pmu.free_aux = pt_buffer_free_aux; + ret =perf_pmu_register (&pt_pmu.pmu,"intel_pt" ,-1 ); + +return ret; +}
Alexander Shishkin
reviewerRe: [PATCH v9 12/14] x86: perf: intel_pt: Intel PT PMU driver
Quoted 15 lines · Peter Zijlstra
Review
Quoted 5 lines · Alexander Shishkin
(quoted diff) +4
-0+static __init int pt_init(void) +{ + pt_pmu.pmu.attr_groups = pt_attr_groups; + pt_pmu.pmu.task_ctx_nr = perf_hw_context;I just noticed this one, how can this ever work? We want the PT thing to always get programmed, right? -- because we disallow creating more than 1?
Which reminds me; does that exclusive thing you did not allow you to create one cpu wide and one per task (they're separate contexts) events? At which point we're not schedulable at all.
Quoted 6 lines
By sticking it on the HW context list it can end up not being programed because its stuck after a bunch of hardware events that don't all fit on the PMU.
Would not the SW list be more appropriate; the SW list is a list of events that's guaranteed to be schedulable.
You're right, of course.
As for the exclusive events, how about something like the code below (on top of the previous exclusive event patch)? The only remaining issue that I see is creating cpu-wide events in the presence of per-thread (event->cpu==-1) events. Both would still work, but only one of them will actually get scheduled at a time. I'm thinking about adding a counter for per-thread events to struct pmu for this purpose, so that if any are present, we can disallow creating cpu-wide events. Or, we can leave it as it is.
What do you think?
--- kernel/events/core.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-)
kernel/events/core.c +47 -5
@@ -7688,14 +7688,11 @@ static bool exclusive_event_match(struct perf_event *e1, struct perf_event *e2)return false; } -static bool exclusive_event_ok (struct perf_event *event, -struct perf_event_context *ctx) +static bool __exclusive_event_ok (struct perf_event *event, +struct perf_event_context *ctx) {struct perf_event *iter_event; -if (!(event->pmu->capabilities &PERF_PMU_CAP_EXCLUSIVE )) -return true; -list_for_each_entry (iter_event, &ctx->event_list, event_entry) {if (exclusive_event_match (iter_event, event))return false;
@@ -7704,6 +7701,51 @@ static bool exclusive_event_ok(struct perf_event *event,return true; } +static bool __exclusive_event_ok_on_cpu (struct perf_event *event,int cpu) +{ +struct perf_event_context *cpuctx; +bool ret; + + cpuctx =find_get_context (event->pmu,NULL , cpu); +mutex_lock (&cpuctx->mutex); + ret =__exclusive_event_ok (event, cpuctx); +perf_unpin_context (cpuctx); +put_ctx (cpuctx); +mutex_unlock (&cpuctx->mutex); + +return ret; +} + +static bool exclusive_event_ok (struct perf_event *event, +struct perf_event_context *ctx) +{ +bool ret = true; + +if (!(event->pmu->capabilities &PERF_PMU_CAP_EXCLUSIVE )) +return true; + +if (!__exclusive_event_ok (event, ctx)) +return false; + +if (ctx->task) { +int cpu; + +if (event->cpu ==-1 ) { +get_online_cpus (); +for_each_online_cpu (cpu) { + ret =__exclusive_event_ok_on_cpu (event, cpu); +if (ret) +break ; + } +put_online_cpus (); + }else { + ret =__exclusive_event_ok_on_cpu (event, event->cpu); + } + } + +return ret; +} +/** * sys_perf_event_open - open a performance event, associate it to a task/cpu *
Signature · 1 line
2.1.4
Alexander Shishkin
reviewerRe: [PATCH v9 12/14] x86: perf: intel_pt: Intel PT PMU driver
Quoted 67 lines · Alexander Shishkin
Quoted 15 lines · Peter Zijlstra
Review
Quoted 5 lines · Alexander Shishkin
(quoted diff) +4
-0+static __init int pt_init(void) +{ + pt_pmu.pmu.attr_groups = pt_attr_groups; + pt_pmu.pmu.task_ctx_nr = perf_hw_context;I just noticed this one, how can this ever work? We want the PT thing to always get programmed, right? -- because we disallow creating more than 1?
Which reminds me; does that exclusive thing you did not allow you to create one cpu wide and one per task (they're separate contexts) events? At which point we're not schedulable at all.
Quoted 6 lines
By sticking it on the HW context list it can end up not being programed because its stuck after a bunch of hardware events that don't all fit on the PMU.
Would not the SW list be more appropriate; the SW list is a list of events that's guaranteed to be schedulable.
You're right, of course.
As for the exclusive events, how about something like the code below (on top of the previous exclusive event patch)? The only remaining issue that I see is creating cpu-wide events in the presence of per-thread (event->cpu==-1) events. Both would still work, but only one of them will actually get scheduled at a time. I'm thinking about adding a counter for per-thread events to struct pmu for this purpose, so that if any are present, we can disallow creating cpu-wide events. Or, we can leave it as it is.
What do you think?
--- kernel/events/core.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-)kernel/events/core.c +3
-5@@ -7688,14 +7688,11 @@ static bool exclusive_event_match(struct perf_event *e1, struct perf_event *e2)return false; } -static bool exclusive_event_ok (struct perf_event *event, -struct perf_event_context *ctx) +static bool __exclusive_event_ok (struct perf_event *event, +struct perf_event_context *ctx) {struct perf_event *iter_event; -if (!(event->pmu->capabilities &PERF_PMU_CAP_EXCLUSIVE )) -return true; -list_for_each_entry (iter_event, &ctx->event_list, event_entry) {if (exclusive_event_match (iter_event, event))return false;@@ -7704,6 +7701,51 @@ static bool exclusive_event_ok(struct perf_event *event,return true; } +static bool __exclusive_event_ok_on_cpu (struct perf_event *event,int cpu)
kernel/events/core.c static bool exclusive_event_ok(struct perf_event *event, · line 7714
Quoted 10 lines
kernel/events/core.c +10
-0+{ +struct perf_event_context *cpuctx; +bool ret; + + cpuctx =find_get_context (event->pmu,NULL , cpu); +mutex_lock (&cpuctx->mutex); + ret =__exclusive_event_ok (event, cpuctx); +perf_unpin_context (cpuctx); +put_ctx (cpuctx); +mutex_unlock (&cpuctx->mutex);
Actually, find_get_context() is not needed here, the following should be sufficient:
cpuctx = &per_cpu_ptr(event->pmu->pmu_cpu_context, cpu)->ctx; mutex_lock(&cpuctx->mutex); ret = __exclusive_event_ok(event, cpuctx); mutex_unlock(&cpuctx->mutex);
Regards,
--
Alex
Peter Zijlstra
maintainerRe: [PATCH v9 12/14] x86: perf: intel_pt: Intel PT PMU driver
Quoted 55 lines · Alexander Shishkin
Quoted 41 lines
As for the exclusive events, how about something like the code below (on top of the previous exclusive event patch)? The only remaining issue that I see is creating cpu-wide events in the presence of per-thread (event->cpu==-1) events. Both would still work, but only one of them will actually get scheduled at a time. I'm thinking about adding a counter for per-thread events to struct pmu for this purpose, so that if any are present, we can disallow creating cpu-wide events. Or, we can leave it as it is.
What do you think?
--- kernel/events/core.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-)kernel/events/core.c +3
-5@@ -7688,14 +7688,11 @@ static bool exclusive_event_match(struct perf_event *e1, struct perf_event *e2)return false; } -static bool exclusive_event_ok (struct perf_event *event, -struct perf_event_context *ctx) +static bool __exclusive_event_ok (struct perf_event *event, +struct perf_event_context *ctx) {struct perf_event *iter_event; -if (!(event->pmu->capabilities &PERF_PMU_CAP_EXCLUSIVE )) -return true; -list_for_each_entry (iter_event, &ctx->event_list, event_entry) {if (exclusive_event_match (iter_event, event))return false;@@ -7704,6 +7701,51 @@ static bool exclusive_event_ok(struct perf_event *event,return true; } +static bool __exclusive_event_ok_on_cpu (struct perf_event *event,int cpu)kernel/events/core.c static bool exclusive_event_ok(struct perf_event *event, · line 7714
Quoted 10 lines
kernel/events/core.c +10
-0+{ +struct perf_event_context *cpuctx; +bool ret; + + cpuctx =find_get_context (event->pmu,NULL , cpu); +mutex_lock (&cpuctx->mutex); + ret =__exclusive_event_ok (event, cpuctx); +perf_unpin_context (cpuctx); +put_ctx (cpuctx); +mutex_unlock (&cpuctx->mutex);Actually,
find_get_context()is not needed here, the following should be sufficient:
Quoted 5 lines
cpuctx = &per_cpu_ptr(event->pmu->pmu_cpu_context, cpu)->ctx; mutex_lock(&cpuctx->mutex); ret = __exclusive_event_ok(event, cpuctx); mutex_unlock(&cpuctx->mutex);
Yes that'll work.
Alexander Shishkin
reviewerRe: [PATCH v9 12/14] x86: perf: intel_pt: Intel PT PMU driver
Quoted 2 lines · Peter Zijlstra
Yes that'll work.
Ok, let me respin this last patch, with the per-task event counter to prevent cpu-wide events together with per-task events. The idea is that cpu-wide events are disallowed when per-task events exist on this pmu and vice versa. It adds an atomic counter to struct pmu to account for per-task events.
If this looks all right to you, I can resend the patchset.
--- include/linux/perf_event.h | 1 + kernel/events/core.c | 87 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 81 insertions(+), 7 deletions(-)
include/linux/perf_event.h +1 -0
@@ -189,6 +189,7 @@ struct pmu {int *__percpu pmu_disable_count;struct perf_cpu_context *__percpu pmu_cpu_context; +atomic_t nr_per_task_events;int task_ctx_nr;int hrtimer_interval_ms;
kernel/events/core.c +80 -7
136 lines not on this page · raw message
Signature · 1 line
2.1.4
Peter Zijlstra
maintainerRe: [PATCH v9 12/14] x86: perf: intel_pt: Intel PT PMU driver
Quoted 14 lines · Alexander Shishkin
(quoted diff) +14
-0+static int account_per_task_counter(struct perf_event *event) +{ + struct pmu *pmu = event->pmu; + + if (!(pmu->capabilities & PERF_PMU_CAP_EXCLUSIVE)) + return 0; + + /* + * Prevent co-existence of per-task and cpu-wide events on the + * same exclusive pmu. + * + * Negative pmu::nr_per_task_events means there are cpu-wide + * events on this "exclusive" pmu, positive means there are + * per-task events.
Review
Quoted 10 lines
(quoted diff) +10
-0+ */ + if (event->cpu == -1 && + !atomic_inc_unless_negative(&pmu->nr_per_task_events)) + return -EBUSY; + else if (!(event->attach_state & PERF_ATTACH_TASK) && + !atomic_dec_unless_positive(&pmu->nr_per_task_events)) + return -EBUSY; + + return 0; +}
I think that logic fails for per-task events that have a cpu set.
Quoted 11 lines
(quoted diff) +11
-0+static bool exclusive_event_ok(struct perf_event *event, + struct perf_event_context *ctx) +{ + struct pmu *pmu = event->pmu; + bool ret = true; + + if (!(pmu->capabilities & PERF_PMU_CAP_EXCLUSIVE)) + return true; + + if (!__exclusive_event_ok(event, ctx)) + return false;
Review
Quoted 10 lines
(quoted diff) +10
-0+ + if (ctx->task) { + if (event->cpu != -1) { + struct perf_event_context *cpuctx; + + cpuctx = &per_cpu_ptr(pmu->pmu_cpu_context, event->cpu)->ctx; + + mutex_lock(&cpuctx->mutex); + ret = __exclusive_event_ok(event, cpuctx); + mutex_unlock(&cpuctx->mutex);
We're already holding ctx->mutex, this should have made lockdep scream.
Review
Quoted 5 lines
(quoted diff) +5
-0+ } + } + + return ret; +}
Would something like this work?
---
include/linux/perf_event.h +2 -0
@@ -168,6 +168,7 @@ struct perf_event;#define PERF_PMU_CAP_NO_INTERRUPT 0x01#define PERF_PMU_CAP_AUX_NO_SG 0x02#define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x04 +#define PERF_PMU_CAP_EXCLUSIVE 0x08/** * struct pmu - generic performance monitoring unit
@@ -188,6 +189,7 @@ struct pmu {int *__percpu pmu_disable_count;struct perf_cpu_context *__percpu pmu_cpu_context; +atomic_t exclusive_cnt;/* <0: cpu, >0: tsk */ int task_ctx_nr;int hrtimer_interval_ms;
kernel/events/core.c +93 -0
129 lines not on this page · raw message
Alexander Shishkin
reviewerRe: [PATCH v9 12/14] x86: perf: intel_pt: Intel PT PMU driver
Quoted 1 line · Peter Zijlstra
I think that logic fails for per-task events that have a cpu set.
True.
Quoted 15 lines
Quoted 15 lines
kernel/events/core.c +15
-0+static bool exclusive_event_ok (struct perf_event *event, +struct perf_event_context *ctx) +{ +struct pmu *pmu = event->pmu; +bool ret = true; + +if (!(pmu->capabilities &PERF_PMU_CAP_EXCLUSIVE )) +return true; + +if (!__exclusive_event_ok (event, ctx)) +return false; + +if (ctx->task) { +if (event->cpu !=-1 ) { +struct perf_event_context *cpuctx;
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ + cpuctx = &per_cpu_ptr(pmu->pmu_cpu_context, event->cpu)->ctx; + + mutex_lock(&cpuctx->mutex); + ret = __exclusive_event_ok(event, cpuctx); + mutex_unlock(&cpuctx->mutex);We're already holding
ctx->mutex, this should have made lockdep scream.
As I mentioned offline, cpuctx->ctx.mutex is set to a lockdep class of its own, so lockdep doesn't see this. It is, of course, still a problem.
But as you pointed out, if we grab the exclusive_cnt for per-task cpu!=-1 events as well, we don't need to look into other contexts here at all.
Quoted 32 lines
kernel/events/core.c perf_event_set_output(struct perf_event · line 7600
Quoted 6 lines
kernel/events/core.c +5
-0+ } + } + +return ret; +}Would something like this work?
---
include/linux/perf_event.h +2
-0@@ -168,6 +168,7 @@ struct perf_event;#define PERF_PMU_CAP_NO_INTERRUPT 0x01#define PERF_PMU_CAP_AUX_NO_SG 0x02#define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x04 +#define PERF_PMU_CAP_EXCLUSIVE 0x08/** * struct pmu - generic performance monitoring unit @@ -188,6 +189,7 @@ struct pmu {int *__percpu pmu_disable_count;struct perf_cpu_context *__percpu pmu_cpu_context; +atomic_t exclusive_cnt;/* <0: cpu, >0: tsk */ int task_ctx_nr;int hrtimer_interval_ms;
kernel/events/core.c static void __free_event(struct perf_eve · line 3491
Quoted 5 lines
kernel/events/core.c +2
-0@@ -3487,6 +3487,9 @@ static void __free_event(struct perf_eveif (event->destroy) event->destroy (event); +if (event->pmu && event->ctx) +exclusive_event_release (event);
It looks like event can be already removed from its context at this point, so event->ctx will be NULL and the counter would leak or am I missing something?
I used the event->attach_state & PERF_ATTACH_TASK to see if it's a per-task counter, which seems reliable even though it might need documenting.
Quoted 31 lines
kernel/events/core.c +17
-0+if (event->ctx)put_ctx (event->ctx);@@ -7092,6 +7095,7 @@ int perf_pmu_register(struct pmu *pmu, c pmu->event_idx = perf_event_idx_default;list_add_rcu (&pmu->entry, &pmus); +atomic_set (&pmu->exclusive_cnt,0 ); ret =0 ; unlock:mutex_unlock (&pmus_lock);@@ -7537,6 +7541,78 @@ perf_event_set_output(struct perf_eventreturn ret; } +static bool exclusive_event_match (struct perf_event *e1,struct perf_event *e2) +{ +if ((e1->pmu->capabilities &PERF_PMU_CAP_EXCLUSIVE ) && + (e1->cpu == e2->cpu || + e1->cpu ==-1 || + e2->cpu ==-1 )) +return true; +return false; +} + +static bool __exclusive_event_ok (struct perf_event *event, +struct perf_event_context *ctx) +{ +struct perf_event *iter_event; +
kernel/events/core.c perf_event_set_output(struct perf_event · line 7568
Quoted 10 lines
kernel/events/core.c +10
-0+list_for_each_entry (iter_event, &ctx->event_list, event_entry) { +if (exclusive_event_match (iter_event, event)) +return false; + } + +return true; +} + +static bool exclusive_event_ok (struct perf_event *event, +struct perf_event_context *ctx)
Then, maybe exclusive_event_installable() is a better name, because this one only deals with the current context; cpu-wide vs per-task case is taken care of in perf_event_alloc()/__free_event().
Quoted 8 lines
kernel/events/core.c +8
-0+{ +struct pmu *pmu = event->pmu; +bool ret; + +if (!(pmu->capabilities &PERF_PMU_CAP_EXCLUSIVE )) +return true; + +/*
kernel/events/core.c perf_event_set_output(struct perf_event · line 7586
Quoted 10 lines
kernel/events/core.c +10
-0+* exclusive_cnt <0: cpu +* >0: tsk +*/ +if (ctx->task) { +if (!atomic_inc_unless_negative (&pmu->exclusive_cnt)) +return false; + }else { +if (!atomic_dec_unless_positive (&pmu->exclusive_cnt)) +return false; + }
So I would like to keep this bit in perf_event_alloc() path and the reverse in __free_event(),
kernel/events/core.c perf_event_set_output(struct perf_event · line 7597
Quoted 11 lines
kernel/events/core.c +11
-0+ +mutex_lock (&ctx->lock); + ret =__exclusive_event_ok (event, ctx); +mutex_unlock (&ctx->lock); + +if (!ret) { +if (ctx->task) +atomic_dec (&pmu->exclusive_cnt); +else +atomic_inc (&pmu->exclusive_cnt); + }
in which case we don't need to undo the counter here, because it will still go through __free_event() in the error path.
Quoted 38 lines
kernel/events/core.c +27
-0+ +return ret; +} + +static void exclusive_event_release (struct perf_event *event) +{ +struct perf_event_context *ctx = event->ctx; +struct pmu *pmu = event->pmu; + +if (!(pmu->capabilities &PERF_PMU_CAP_EXCLUSIVE )) +return ; + +if (ctx->task) +atomic_dec (&pmu->exclusive_cnt); +else +atomic_inc (&pmu->exclusive_cnt); +} +static void mutex_lock_double (struct mutex *a,struct mutex *b) {if (b < a)@@ -7702,6 +7778,15 @@ SYSCALL_DEFINE5(perf_event_open, task =NULL ; } +if (pmu->capabilities &PERF_PMU_CAP_EXCLUSIVE ) { + err = -EBUSY ; +if (group_leader) + goto err_context; + +if (!exclusive_event_ok (event, ctx)) + goto err_context; + } +/* * Look up the group leader (we will attach this event to it): */
kernel/events/core.c perf_event_create_kernel_counter(struct · line 7997
Quoted 10 lines
kernel/events/core.c +5
-0@@ -7903,6 +7988,11 @@ perf_event_create_kernel_counter(struct goto err_free; } +if (!exclusive_event_ok (event, ctx)) { + err = -EBUSY ; + goto err_context; + } +WARN_ON_ONCE (ctx->parent_ctx);mutex_lock (&ctx->mutex);
So we can call exclusive_event_ok() here without dropping the ctx::mutex, to make sure we don't race with another event creation.
Regards,
--
Alex
Peter Zijlstra
maintainerRe: [PATCH v9 12/14] x86: perf: intel_pt: Intel PT PMU driver
Quoted 5 lines · Alexander Shishkin
Quoted 1 line
We're already holding
ctx->mutex, this should have made lockdep scream.As I mentioned offline,
cpuctx->ctx.mutexis set to a lockdep class of its own, so lockdep doesn't see this. It is, of course, still a problem.
Right; I don't think we currently use that annotation of cpuctx->ctx.mutex but I had indeed overlooked that.
Per perf_ctx_lock() the nesting order is:
cpuctx
ctx
And here we would have done the inverse. Still I'm not entirely sure it would've resulted in a deadlock, we typically don't take multiple ctx->mutex locks, and where we do its either between different context on the same CPU (eg, moving a software event to the hardware lists), or between the same context on different CPUs (perf_pmu_migrate_context), or between inherited contexts (put_event, in child->parent nesting).
None of those cases seem to overlap with this order.
However,
Quoted 3 lines
But as you pointed out, if we grab the
exclusive_cntfor per-task cpu!=-1 events as well, we don't need to look into other contexts here at all.
its irrelevant because we can avoid the entire ordeal ;-)
Quoted 6 lines
Quoted 6 lines
kernel/events/core.c +0
-0@@ -3487,6 +3487,9 @@ static void __free_event(struct perf_eveif (event->destroy) event->destroy (event);
Quoted 6 lines
kernel/events/core.c static void __free_event(struct perf_eve · line 3491
Quoted 2 lines
kernel/events/core.c +2
-0+if (event->pmu && event->ctx) +exclusive_event_release (event);It looks like event can be already removed from its context at this point, so
event->ctxwill be NULL and the counter would leak or am I missing something?
Yeah, event->ctx is _magic_ ;-)
event->ctx is never NULL, although it can change. Much fun because of that; see: lkml.kernel.org/r/[email protected] if you like to torture yourself a wee bit.
Quoted 3 lines
I used the
event->attach_state&PERF_ATTACH_TASKto see if it's a per-task counter, which seems reliable even though it might need documenting.
Yes, I suppose that is indeed better, I had feared we clear the ATTACH_TASK state on remove_from_context() like we do all the other ATTACH states, but we do not.
Quoted 6 lines
kernel/events/core.c perf_event_set_output(struct perf_event · line 7568
Quoted 2 lines
kernel/events/core.c +2
-0+static bool exclusive_event_ok (struct perf_event *event, +struct perf_event_context *ctx)Then, maybe
exclusive_event_installable()is a better name, because this one only deals with the current context; cpu-wide vs per-task case is taken care of in perf_event_alloc()/__free_event().
OK.
Quoted 12 lines
kernel/events/core.c perf_event_set_output(struct perf_event · line 7586
Quoted 11 lines
kernel/events/core.c +11
-0+/* +* exclusive_cnt <0: cpu +* >0: tsk +*/ +if (ctx->task) { +if (!atomic_inc_unless_negative (&pmu->exclusive_cnt)) +return false; + }else { +if (!atomic_dec_unless_positive (&pmu->exclusive_cnt)) +return false; + }
Quoted 2 lines
So I would like to keep this bit in
perf_event_alloc()path and the reverse in__free_event(),
Fair enough; exclusive_event_init() ?
Quoted 4 lines
kernel/events/core.c perf_event_set_output(struct perf_event · line 7590
Quoted 4 lines
kernel/events/core.c +4
-0+ +mutex_lock (&ctx->lock); + ret =__exclusive_event_ok (event, ctx); +mutex_unlock (&ctx->lock);
And as you pointed out on IRC, this needs to be in the same section as install_in_context() otherwise we have a race.
Quoted 9 lines
kernel/events/core.c perf_event_set_output(struct perf_event · line 7597
Quoted 6 lines
kernel/events/core.c +6
-0+if (!ret) { +if (ctx->task) +atomic_dec (&pmu->exclusive_cnt); +else +atomic_inc (&pmu->exclusive_cnt); + }in which case we don't need to undo the counter here, because it will still go through
__free_event()in the error path.
OK; exclusive_event_destroy() ?
Peter Zijlstra
maintainerRe: [PATCH v9 12/14] x86: perf: intel_pt: Intel PT PMU driver
Quoted 1 line · Peter Zijlstra
event->ctxis never NULL,
With the one exception of partially initialized events, that is.
Alexander Shishkin
reviewerRe: [PATCH v9 12/14] x86: perf: intel_pt: Intel PT PMU driver
In reply to Peter ZijlstraQuoted 15 lines · Peter Zijlstra
Quoted 5 lines · Alexander Shishkin
Quoted 1 line
We're already holding
ctx->mutex, this should have made lockdep scream.As I mentioned offline,
cpuctx->ctx.mutexis set to a lockdep class of its own, so lockdep doesn't see this. It is, of course, still a problem.Right; I don't think we currently use that annotation of
cpuctx->ctx.mutexbut I had indeed overlooked that.Per
perf_ctx_lock()the nesting order is:cpuctx
ctx
Quoted 8 lines
And here we would have done the inverse. Still I'm not entirely sure it would've resulted in a deadlock, we typically don't take multiple
ctx->mutexlocks, and where we do its either between different context on the same CPU (eg, moving a software event to the hardware lists), or between the same context on different CPUs (perf_pmu_migrate_context), or between inherited contexts (put_event, inchild->parentnesting).None of those cases seem to overlap with this order.
Indeed.
Quoted 7 lines
However,
Quoted 3 lines
But as you pointed out, if we grab the
exclusive_cntfor per-task cpu!=-1 events as well, we don't need to look into other contexts here at all.its irrelevant because we can avoid the entire ordeal ;-)
Exactly. :)
Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
kernel/events/core.c +0
-0@@ -3487,6 +3487,9 @@ static void __free_event(struct perf_eveif (event->destroy) event->destroy (event);Quoted 6 lines
kernel/events/core.c static void __free_event(struct perf_eve · line 3491
Quoted 2 lines
kernel/events/core.c +2
-0+if (event->pmu && event->ctx) +exclusive_event_release (event);It looks like event can be already removed from its context at this point, so
event->ctxwill be NULL and the counter would leak or am I missing something?
Quoted 5 lines
Yeah,
event->ctxis _magic_ ;-)
event->ctxis never NULL, although it can change. Much fun because of that; see: lkml.kernel.org/r/[email protected] if you like to torture yourself a wee bit.
Yeah, I already did, having noticed mutex_lock_double() in the context of your diff. And I'll probably re-read it a few more times. :)
Quoted 7 lines
Quoted 3 lines
I used the
event->attach_state&PERF_ATTACH_TASKto see if it's a per-task counter, which seems reliable even though it might need documenting.Yes, I suppose that is indeed better, I had feared we clear the
ATTACH_TASKstate onremove_from_context()like we do all the other ATTACH states, but we do not.
Yep. It probably needs documenting though, in case somebody decides to change this in future.
Quoted 21 lines
Quoted 6 lines
kernel/events/core.c perf_event_set_output(struct perf_event · line 7568
Quoted 2 lines
kernel/events/core.c +2
-0+static bool exclusive_event_ok (struct perf_event *event, +struct perf_event_context *ctx)Then, maybe
exclusive_event_installable()is a better name, because this one only deals with the current context; cpu-wide vs per-task case is taken care of in perf_event_alloc()/__free_event().OK.
Quoted 12 lines
Quoted 11 lines
kernel/events/core.c +11
-0+/* +* exclusive_cnt <0: cpu +* >0: tsk +*/ +if (ctx->task) { +if (!atomic_inc_unless_negative (&pmu->exclusive_cnt)) +return false; + }else { +if (!atomic_dec_unless_positive (&pmu->exclusive_cnt)) +return false; + }
Quoted 4 lines
Quoted 2 lines
So I would like to keep this bit in
perf_event_alloc()path and the reverse in__free_event(),Fair enough;
exclusive_event_init()?
Ok.
Quoted 16 lines
Quoted 5 lines
kernel/events/core.c perf_event_set_output(struct perf_event · line 7590
Quoted 5 lines
kernel/events/core.c +4
-0+ +mutex_lock (&ctx->lock); + ret =__exclusive_event_ok (event, ctx); +mutex_unlock (&ctx->lock);And as you pointed out on IRC, this needs to be in the same section as
install_in_context()otherwise we have a race.Quoted 7 lines
Quoted 6 lines
kernel/events/core.c +6
-0+if (!ret) { +if (ctx->task) +atomic_dec (&pmu->exclusive_cnt); +else +atomic_inc (&pmu->exclusive_cnt); + }
Quoted 4 lines
Quoted 2 lines
in which case we don't need to undo the counter here, because it will still go through
__free_event()in the error path.OK;
exclusive_event_destroy()?
Yep.
Cheers,
--
Alex
Alexander Shishkin
reviewerPATCH 1/1 perf: Add a pmu capability for "exclusive" events
In reply to Peter ZijlstraUsually, pmus that do, for example, instruction tracing, would only ever be able to have one event per task per cpu (or per perf_event_context). For such pmus it makes sense to disallow creating conflicting events early on, so as to provide consistent behavior for the user.
This patch adds a pmu capability that indicates such constraint on event creation.
--- include/linux/perf_event.h | 2 + kernel/events/core.c | 119 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 119 insertions(+), 2 deletions(-)
include/linux/perf_event.h +2 -0
@@ -168,6 +168,7 @@ struct perf_event;#define PERF_PMU_CAP_NO_INTERRUPT 0x01#define PERF_PMU_CAP_AUX_NO_SG 0x02#define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x04 +#define PERF_PMU_CAP_EXCLUSIVE 0x08/** * struct pmu - generic performance monitoring unit
@@ -188,6 +189,7 @@ struct pmu {int *__percpu pmu_disable_count;struct perf_cpu_context *__percpu pmu_cpu_context; +atomic_t exclusive_cnt;/* < 0: cpu; > 0: tsk */ int task_ctx_nr;int hrtimer_interval_ms;
kernel/events/core.c +117 -2
171 lines not on this page · raw message
Signature · 1 line
2.1.4
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf: Add a pmu capability for "exclusive" events
perf: Add a pmu capability for "exclusive" events
Commit-ID: bed5b25ad9c8a2f5d735ef0bc746ec870c01c1b0 Gitweb: http://git.kernel.org/tip/bed5b25ad9c8a2f5d735ef0bc746ec870c01c1b0 Author: Alexander Shishkin <[email protected]> AuthorDate: Fri, 30 Jan 2015 12:31:06 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:14:12 +0200
perf: Add a pmu capability for "exclusive" events
Usually, pmus that do, for example, instruction tracing, would only ever be able to have one event per task per cpu (or per perf_event_context). For such pmus it makes sense to disallow creating conflicting events early on, so as to provide consistent behavior for the user.
This patch adds a pmu capability that indicates such constraint on event creation.
--- include/linux/perf_event.h | 2 + kernel/events/core.c | 119 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 119 insertions(+), 2 deletions(-)
include/linux/perf_event.h +2 -0
@@ -176,6 +176,7 @@ struct perf_event;#define PERF_PMU_CAP_NO_NMI 0x02#define PERF_PMU_CAP_AUX_NO_SG 0x04#define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x08 +#define PERF_PMU_CAP_EXCLUSIVE 0x10/** * struct pmu - generic performance monitoring unit
@@ -196,6 +197,7 @@ struct pmu {int *__percpu pmu_disable_count;struct perf_cpu_context *__percpu pmu_cpu_context; +atomic_t exclusive_cnt;/* < 0: cpu; > 0: tsk */ int task_ctx_nr;int hrtimer_interval_ms;
kernel/events/core.c +117 -2
171 lines not on this page · raw message
Alexander Shishkin
reviewerPATCH 1/1 x86: perf: intel_pt: Intel PT PMU driver
In reply to Peter ZijlstraAdd support for Intel Processor Trace (PT) to kernel's perf events. PT is an extension of Intel Architecture that collects information about software execuction such as control flow, execution modes and timings and formats it into highly compressed binary packets. Even being compressed, these packets are generated at hundreds of megabytes per second per core, which makes it impractical to decode them on the fly in the kernel.
This driver exports trace data by through AUX space in the perf ring buffer, which is zero-copy mapped into userspace for faster data retrieval.
--- arch/x86/include/uapi/asm/msr-index.h | 18 + arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/intel_pt.h | 131 ++++ arch/x86/kernel/cpu/perf_event.h | 2 + arch/x86/kernel/cpu/perf_event_intel.c | 8 + arch/x86/kernel/cpu/perf_event_intel_pt.c | 1095 +++++++++++++++++++++++++++++ 6 files changed, 1255 insertions(+) create mode 100644 arch/x86/kernel/cpu/intel_pt.h create mode 100644 arch/x86/kernel/cpu/perf_event_intel_pt.c
arch/x86/include/uapi/asm/msr-index.h +18 -0
@@ -74,6 +74,24 @@#define MSR_IA32_PERF_CAPABILITIES 0x00000345#define MSR_PEBS_LD_LAT_THRESHOLD 0x000003f6 +#define MSR_IA32_RTIT_CTL 0x00000570 +#define RTIT_CTL_TRACEEN BIT(0) +#define RTIT_CTL_OS BIT(2) +#define RTIT_CTL_USR BIT(3) +#define RTIT_CTL_CR3EN BIT(7) +#define RTIT_CTL_TOPA BIT(8) +#define RTIT_CTL_TSC_EN BIT(10) +#define RTIT_CTL_DISRETC BIT(11) +#define RTIT_CTL_BRANCH_EN BIT(13) +#define MSR_IA32_RTIT_STATUS 0x00000571 +#define RTIT_STATUS_CONTEXTEN BIT(1) +#define RTIT_STATUS_TRIGGEREN BIT(2) +#define RTIT_STATUS_ERROR BIT(4) +#define RTIT_STATUS_STOPPED BIT(5) +#define MSR_IA32_RTIT_CR3_MATCH 0x00000572 +#define MSR_IA32_RTIT_OUTPUT_BASE 0x00000560 +#define MSR_IA32_RTIT_OUTPUT_MASK 0x00000561 +#define MSR_MTRRfix64K_00000 0x00000250#define MSR_MTRRfix16K_80000 0x00000258#define MSR_MTRRfix16K_A0000 0x00000259
arch/x86/kernel/cpu/Makefile +1 -0
@@ -40,6 +40,7 @@ endif obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_p6.o perf_event_knc.o perf_event_p4.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_lbr.o perf_event_intel_ds.o perf_event_intel.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_rapl.o +obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += perf_event_intel_uncore.o \ perf_event_intel_uncore_snb.o \
arch/x86/kernel/cpu/intel_pt.h new file +131 -0
131 lines not on this page · raw message
arch/x86/kernel/cpu/perf_event.h +2 -0
@@ -787,6 +787,8 @@ void intel_pmu_lbr_init_snb(void);int intel_pmu_setup_lbr_filter (struct perf_event *event); +void intel_pt_interrupt (void ); +int p4_pmu_init (void );int p6_pmu_init (void );
arch/x86/kernel/cpu/perf_event_intel.c +8 -0
@@ -1385,6 +1385,14 @@ again: }/* +* Intel PT +*/ +if (__test_and_clear_bit (55 , (unsigned long *)&status)) { + handled++; +intel_pt_interrupt (); + } + +/* * Checkpointed counters can lead to 'spurious' PMIs because the * rollback caused by the PMI will have cleared the overflow status * bit. Therefore always force probe these counters.
arch/x86/kernel/cpu/perf_event_intel_pt.c new file +1095 -0
1,095 lines not on this page · raw message
Signature · 1 line
2.1.4
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf/x86/intel/pt: Add Intel PT PMU driver
perf/x86/intel/pt: Add Intel PT PMU driver
Commit-ID: 52ca9ced3f70779589e6ecc329baffe69d8f5f7a Gitweb: http://git.kernel.org/tip/52ca9ced3f70779589e6ecc329baffe69d8f5f7a Author: Alexander Shishkin <[email protected]> AuthorDate: Fri, 30 Jan 2015 12:39:52 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:14:20 +0200
perf/x86/intel/pt: Add Intel PT PMU driver
Add support for Intel Processor Trace (PT) to kernel's perf events. PT is an extension of Intel Architecture that collects information about software execuction such as control flow, execution modes and timings and formats it into highly compressed binary packets. Even being compressed, these packets are generated at hundreds of megabytes per second per core, which makes it impractical to decode them on the fly in the kernel.
This driver exports trace data by through AUX space in the perf ring buffer, which is zero-copy mapped into userspace for faster data retrieval.
--- arch/x86/include/uapi/asm/msr-index.h | 18 + arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/intel_pt.h | 131 ++++ arch/x86/kernel/cpu/perf_event.h | 2 + arch/x86/kernel/cpu/perf_event_intel.c | 8 + arch/x86/kernel/cpu/perf_event_intel_pt.c | 1096 +++++++++++++++++++++++++++++ 6 files changed, 1256 insertions(+)
arch/x86/include/uapi/asm/msr-index.h +18 -0
@@ -74,6 +74,24 @@#define MSR_IA32_PERF_CAPABILITIES 0x00000345#define MSR_PEBS_LD_LAT_THRESHOLD 0x000003f6 +#define MSR_IA32_RTIT_CTL 0x00000570 +#define RTIT_CTL_TRACEEN BIT(0) +#define RTIT_CTL_OS BIT(2) +#define RTIT_CTL_USR BIT(3) +#define RTIT_CTL_CR3EN BIT(7) +#define RTIT_CTL_TOPA BIT(8) +#define RTIT_CTL_TSC_EN BIT(10) +#define RTIT_CTL_DISRETC BIT(11) +#define RTIT_CTL_BRANCH_EN BIT(13) +#define MSR_IA32_RTIT_STATUS 0x00000571 +#define RTIT_STATUS_CONTEXTEN BIT(1) +#define RTIT_STATUS_TRIGGEREN BIT(2) +#define RTIT_STATUS_ERROR BIT(4) +#define RTIT_STATUS_STOPPED BIT(5) +#define MSR_IA32_RTIT_CR3_MATCH 0x00000572 +#define MSR_IA32_RTIT_OUTPUT_BASE 0x00000560 +#define MSR_IA32_RTIT_OUTPUT_MASK 0x00000561 +#define MSR_MTRRfix64K_00000 0x00000250#define MSR_MTRRfix16K_80000 0x00000258#define MSR_MTRRfix16K_A0000 0x00000259
arch/x86/kernel/cpu/Makefile +1 -0
@@ -40,6 +40,7 @@ endif obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_p6.o perf_event_knc.o perf_event_p4.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_lbr.o perf_event_intel_ds.o perf_event_intel.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_rapl.o perf_event_intel_cqm.o +obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += perf_event_intel_uncore.o \ perf_event_intel_uncore_snb.o \
arch/x86/kernel/cpu/intel_pt.h new file +131 -0
131 lines not on this page · raw message
arch/x86/kernel/cpu/perf_event.h +2 -0
@@ -808,6 +808,8 @@ void intel_pmu_lbr_init_hsw(void);int intel_pmu_setup_lbr_filter (struct perf_event *event); +void intel_pt_interrupt (void ); +int p4_pmu_init (void );int p6_pmu_init (void );
arch/x86/kernel/cpu/perf_event_intel.c +8 -0
@@ -1590,6 +1590,14 @@ again: }/* +* Intel PT +*/ +if (__test_and_clear_bit (55 , (unsigned long *)&status)) { + handled++; +intel_pt_interrupt (); + } + +/* * Checkpointed counters can lead to 'spurious' PMIs because the * rollback caused by the PMI will have cleared the overflow status * bit. Therefore always force probe these counters.
arch/x86/kernel/cpu/perf_event_intel_pt.c new file +1096 -0
1,096 lines not on this page · raw message
Alexander Shishkin
reviewerPATCH 1/1 x86: perf: intel_bts: Add BTS PMU driver
In reply to Peter ZijlstraAdd support for Branch Trace Store (BTS) via kernel perf event infrastructure. The difference with the existing implementation of BTS support is that this one is a separate PMU that exports events' trace buffers to userspace by means of AUX area of the perf buffer, which is zero-copy mapped into userspace.
The immediate benefit is that the buffer size can be much bigger, resulting in fewer interrupts and no kernel side copying is involved and little to no trace data loss. Also, kernel code can be traced with this driver.
The old way of collecting BTS traces still works.
--- arch/x86/kernel/cpu/Makefile | 2 +- arch/x86/kernel/cpu/perf_event.h | 7 + arch/x86/kernel/cpu/perf_event_intel.c | 6 +- arch/x86/kernel/cpu/perf_event_intel_bts.c | 525 +++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event_intel_ds.c | 3 +- 5 files changed, 540 insertions(+), 3 deletions(-) create mode 100644 arch/x86/kernel/cpu/perf_event_intel_bts.c
arch/x86/kernel/cpu/Makefile +1 -1
@@ -40,7 +40,7 @@ endif obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_p6.o perf_event_knc.o perf_event_p4.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_lbr.o perf_event_intel_ds.o perf_event_intel.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_rapl.o -obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o +obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o perf_event_intel_bts.o obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += perf_event_intel_uncore.o \ perf_event_intel_uncore_snb.o \
arch/x86/kernel/cpu/perf_event.h +7 -0
@@ -408,6 +408,7 @@ union x86_pmu_config {enum { x86_lbr_exclusive_lbr, + x86_lbr_exclusive_bts, x86_lbr_exclusive_pt, x86_lbr_exclusive_max, };
@@ -789,6 +790,12 @@ int intel_pmu_setup_lbr_filter(struct perf_event *event);void intel_pt_interrupt (void ); +int intel_bts_interrupt (void ); + +void intel_bts_enable_local (void ); + +void intel_bts_disable_local (void ); +int p4_pmu_init (void );int p6_pmu_init (void );
arch/x86/kernel/cpu/perf_event_intel.c +5 -1
@@ -1037,6 +1037,8 @@ static void intel_pmu_disable_all(void)if (test_bit (INTEL_PMC_IDX_FIXED_BTS , cpuc->active_mask))intel_pmu_disable_bts (); +else +intel_bts_disable_local ();intel_pmu_pebs_disable_all ();intel_pmu_lbr_disable_all ();
@@ -1059,7 +1061,8 @@ static void intel_pmu_enable_all(int added)return ;intel_pmu_enable_bts (event->hw.config); - } + }else +intel_bts_enable_local (); }/*
@@ -1345,6 +1348,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs)apic_write (APIC_LVTPC ,APIC_DM_NMI );intel_pmu_disable_all (); handled =intel_pmu_drain_bts_buffer (); + handled +=intel_bts_interrupt (); status =intel_pmu_get_status ();if (!status) goto done;
arch/x86/kernel/cpu/perf_event_intel_bts.c new file +525 -0
525 lines not on this page · raw message
arch/x86/kernel/cpu/perf_event_intel_ds.c +2 -1
@@ -461,7 +461,8 @@ void intel_pmu_enable_bts(u64 config) debugctlmsr |=DEBUGCTLMSR_TR ; debugctlmsr |=DEBUGCTLMSR_BTS ; - debugctlmsr |=DEBUGCTLMSR_BTINT ; +if (config &ARCH_PERFMON_EVENTSEL_INT ) + debugctlmsr |=DEBUGCTLMSR_BTINT ;if (!(config &ARCH_PERFMON_EVENTSEL_OS )) debugctlmsr |=DEBUGCTLMSR_BTS_OFF_OS ;
Signature · 1 line
2.1.4
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf/x86/intel/bts: Add BTS PMU driver
perf/x86/intel/bts: Add BTS PMU driver
Commit-ID: 8062382c8dbe2dc11d37e7f0b139508cf10de9d4 Gitweb: http://git.kernel.org/tip/8062382c8dbe2dc11d37e7f0b139508cf10de9d4 Author: Alexander Shishkin <[email protected]> AuthorDate: Fri, 30 Jan 2015 12:40:35 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:14:21 +0200
perf/x86/intel/bts: Add BTS PMU driver
Add support for Branch Trace Store (BTS) via kernel perf event infrastructure. The difference with the existing implementation of BTS support is that this one is a separate PMU that exports events' trace buffers to userspace by means of AUX area of the perf buffer, which is zero-copy mapped into userspace.
The immediate benefit is that the buffer size can be much bigger, resulting in fewer interrupts and no kernel side copying is involved and little to no trace data loss. Also, kernel code can be traced with this driver.
The old way of collecting BTS traces still works.
--- arch/x86/kernel/cpu/Makefile | 2 +- arch/x86/kernel/cpu/perf_event.h | 7 + arch/x86/kernel/cpu/perf_event_intel.c | 6 +- arch/x86/kernel/cpu/perf_event_intel_bts.c | 525 +++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event_intel_ds.c | 3 +- 5 files changed, 540 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/Makefile +1 -1
@@ -40,7 +40,7 @@ endif obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_p6.o perf_event_knc.o perf_event_p4.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_lbr.o perf_event_intel_ds.o perf_event_intel.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_rapl.o perf_event_intel_cqm.o -obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o +obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o perf_event_intel_bts.o obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += perf_event_intel_uncore.o \ perf_event_intel_uncore_snb.o \
arch/x86/kernel/cpu/perf_event.h +7 -0
@@ -410,6 +410,7 @@ union x86_pmu_config {enum { x86_lbr_exclusive_lbr, + x86_lbr_exclusive_bts, x86_lbr_exclusive_pt, x86_lbr_exclusive_max, };
@@ -810,6 +811,12 @@ int intel_pmu_setup_lbr_filter(struct perf_event *event);void intel_pt_interrupt (void ); +int intel_bts_interrupt (void ); + +void intel_bts_enable_local (void ); + +void intel_bts_disable_local (void ); +int p4_pmu_init (void );int p6_pmu_init (void );
arch/x86/kernel/cpu/perf_event_intel.c +5 -1
@@ -1242,6 +1242,8 @@ static void intel_pmu_disable_all(void)if (test_bit (INTEL_PMC_IDX_FIXED_BTS , cpuc->active_mask))intel_pmu_disable_bts (); +else +intel_bts_disable_local ();intel_pmu_pebs_disable_all ();intel_pmu_lbr_disable_all ();
@@ -1264,7 +1266,8 @@ static void intel_pmu_enable_all(int added)return ;intel_pmu_enable_bts (event->hw.config); - } + }else +intel_bts_enable_local (); }/*
@@ -1550,6 +1553,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs)apic_write (APIC_LVTPC ,APIC_DM_NMI );intel_pmu_disable_all (); handled =intel_pmu_drain_bts_buffer (); + handled +=intel_bts_interrupt (); status =intel_pmu_get_status ();if (!status) goto done;
arch/x86/kernel/cpu/perf_event_intel_bts.c new file +525 -0
525 lines not on this page · raw message
arch/x86/kernel/cpu/perf_event_intel_ds.c +2 -1
@@ -461,7 +461,8 @@ void intel_pmu_enable_bts(u64 config) debugctlmsr |=DEBUGCTLMSR_TR ; debugctlmsr |=DEBUGCTLMSR_BTS ; - debugctlmsr |=DEBUGCTLMSR_BTINT ; +if (config &ARCH_PERFMON_EVENTSEL_INT ) + debugctlmsr |=DEBUGCTLMSR_BTINT ;if (!(config &ARCH_PERFMON_EVENTSEL_OS )) debugctlmsr |=DEBUGCTLMSR_BTS_OFF_OS ;
Alexander Shishkin
reviewerPATCH v9 13/14 x86: perf: intel_bts: Add BTS PMU driver
In reply to Alexander ShishkinAdd support for Branch Trace Store (BTS) via kernel perf event infrastructure. The difference with the existing implementation of BTS support is that this one is a separate PMU that exports events' trace buffers to userspace by means of AUX area of the perf buffer, which is zero-copy mapped into userspace.
The immediate benefit is that the buffer size can be much bigger, resulting in fewer interrupts and no kernel side copying is involved and little to no trace data loss. Also, kernel code can be traced with this driver.
The old way of collecting BTS traces still works.
--- arch/x86/kernel/cpu/Makefile | 2 +- arch/x86/kernel/cpu/perf_event.h | 7 + arch/x86/kernel/cpu/perf_event_intel.c | 6 +- arch/x86/kernel/cpu/perf_event_intel_bts.c | 525 +++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event_intel_ds.c | 3 +- 5 files changed, 540 insertions(+), 3 deletions(-) create mode 100644 arch/x86/kernel/cpu/perf_event_intel_bts.c
arch/x86/kernel/cpu/Makefile +1 -1
@@ -40,7 +40,7 @@ endif obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_p6.o perf_event_knc.o perf_event_p4.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_lbr.o perf_event_intel_ds.o perf_event_intel.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_rapl.o -obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o +obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o perf_event_intel_bts.o obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += perf_event_intel_uncore.o \ perf_event_intel_uncore_snb.o \
arch/x86/kernel/cpu/perf_event.h +7 -0
@@ -408,6 +408,7 @@ union x86_pmu_config {enum { x86_lbr_exclusive_lbr, + x86_lbr_exclusive_bts, x86_lbr_exclusive_pt, x86_lbr_exclusive_max, };
@@ -789,6 +790,12 @@ int intel_pmu_setup_lbr_filter(struct perf_event *event);void intel_pt_interrupt (void ); +int intel_bts_interrupt (void ); + +void intel_bts_enable_local (void ); + +void intel_bts_disable_local (void ); +int p4_pmu_init (void );int p6_pmu_init (void );
arch/x86/kernel/cpu/perf_event_intel.c +5 -1
@@ -1037,6 +1037,8 @@ static void intel_pmu_disable_all(void)if (test_bit (INTEL_PMC_IDX_FIXED_BTS , cpuc->active_mask))intel_pmu_disable_bts (); +else +intel_bts_disable_local ();intel_pmu_pebs_disable_all ();intel_pmu_lbr_disable_all ();
@@ -1059,7 +1061,8 @@ static void intel_pmu_enable_all(int added)return ;intel_pmu_enable_bts (event->hw.config); - } + }else +intel_bts_enable_local (); }/*
@@ -1345,6 +1348,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs)apic_write (APIC_LVTPC ,APIC_DM_NMI );intel_pmu_disable_all (); handled =intel_pmu_drain_bts_buffer (); + handled +=intel_bts_interrupt (); status =intel_pmu_get_status ();if (!status) goto done;
arch/x86/kernel/cpu/perf_event_intel_bts.c new file +525 -0
525 lines not on this page · raw message
arch/x86/kernel/cpu/perf_event_intel_ds.c +2 -1
@@ -461,7 +461,8 @@ void intel_pmu_enable_bts(u64 config) debugctlmsr |=DEBUGCTLMSR_TR ; debugctlmsr |=DEBUGCTLMSR_BTS ; - debugctlmsr |=DEBUGCTLMSR_BTINT ; +if (config &ARCH_PERFMON_EVENTSEL_INT ) + debugctlmsr |=DEBUGCTLMSR_BTINT ;if (!(config &ARCH_PERFMON_EVENTSEL_OS )) debugctlmsr |=DEBUGCTLMSR_BTS_OFF_OS ;
Signature · 1 line
2.1.4
Alexander Shishkin
reviewerPATCH v9 14/14 perf: add ITRACE_START record to indicate that tracing has started
In reply to Alexander ShishkinFor counters that generate AUX data that is bound to the context of a running task, such as instruction tracing, the decoder needs to know exactly which task is running when the event is first scheduled in, before the first sched_switch. The decoder's need to know this stems from the fact that instruction flow trace decoding will almost always require program's object code in order to reconstruct said flow and for that we need at least its pid/tid in the perf stream.
To single out such instruction tracing pmus, this patch introduces ITRACE PMU capability. The reason this is not part of RECORD_AUX record is that not all pmus capable of generating AUX data need this, and the opposite is *probably* also true.
While sched_switch covers for most cases, there are two problems with it:
the consumer will need to process events out of order (that is, having found RECORD_AUX, it will have to skip forward to the nearest sched_switch to figure out which task it was, then go back to the actual trace to decode it) and it completely misses the case when the tracing is enabled and disabled before sched_switch, for example, via PERF_EVENT_IOC_DISABLE.
--- include/linux/perf_event.h | 4 ++++ include/uapi/linux/perf_event.h | 11 +++++++++++ kernel/events/core.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+)
include/linux/perf_event.h +4 -0
@@ -127,6 +127,9 @@ struct hw_perf_event {/* for tp_event->class */ struct list_head tp_list; }; +struct {/* itrace */ +int itrace_started; + }; #ifdef CONFIG_HAVE_HW_BREAKPOINT struct { /* breakpoint */ /*
@@ -174,6 +177,7 @@ struct perf_event;#define PERF_PMU_CAP_AUX_NO_SG 0x02#define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x04#define PERF_PMU_CAP_EXCLUSIVE 0x08 +#define PERF_PMU_CAP_ITRACE 0x10/** * struct pmu - generic performance monitoring unit
include/uapi/linux/perf_event.h +11 -0
@@ -764,6 +764,17 @@ enum perf_event_type {*/ PERF_RECORD_AUX =11 , +/* +* Indicates that instruction trace has started +* +* struct { +* struct perf_event_header header; +* u32 pid; +* u32 tid; +* }; +*/ +PERF_RECORD_ITRACE_START =12 , + PERF_RECORD_MAX, /* non-ABI */ };
kernel/events/core.c +41 -0
59 lines not on this page · raw message
Signature · 1 line
2.1.4
tip-bot for Alexander Shishkin
merge bot[tip:perf/core] perf: Add ITRACE_START record to indicate that tracing has started
perf: Add ITRACE_START record to indicate that tracing has started
Commit-ID: ec0d7729bbaed4b9d2d3fada693278e13a3d1368 Gitweb: http://git.kernel.org/tip/ec0d7729bbaed4b9d2d3fada693278e13a3d1368 Author: Alexander Shishkin <[email protected]> AuthorDate: Wed, 14 Jan 2015 14:18:23 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 2 Apr 2015 17:14:17 +0200
perf: Add ITRACE_START record to indicate that tracing has started
For counters that generate AUX data that is bound to the context of a running task, such as instruction tracing, the decoder needs to know exactly which task is running when the event is first scheduled in, before the first sched_switch. The decoder's need to know this stems from the fact that instruction flow trace decoding will almost always require program's object code in order to reconstruct said flow and for that we need at least its pid/tid in the perf stream.
To single out such instruction tracing pmus, this patch introduces ITRACE PMU capability. The reason this is not part of RECORD_AUX record is that not all pmus capable of generating AUX data need this, and the opposite is *probably* also true.
While sched_switch covers for most cases, there are two problems with it:
the consumer will need to process events out of order (that is, having found RECORD_AUX, it will have to skip forward to the nearest sched_switch to figure out which task it was, then go back to the actual trace to decode it) and it completely misses the case when the tracing is enabled and disabled before sched_switch, for example, via PERF_EVENT_IOC_DISABLE.
--- include/linux/perf_event.h | 4 ++++ include/uapi/linux/perf_event.h | 11 +++++++++++ kernel/events/core.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+)
include/linux/perf_event.h +4 -0
@@ -129,6 +129,9 @@ struct hw_perf_event {struct list_head cqm_groups_entry;struct list_head cqm_group_entry; }; +struct {/* itrace */ +int itrace_started; + }; #ifdef CONFIG_HAVE_HW_BREAKPOINT struct { /* breakpoint */ /*
@@ -177,6 +180,7 @@ struct perf_event;#define PERF_PMU_CAP_AUX_NO_SG 0x04#define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x08#define PERF_PMU_CAP_EXCLUSIVE 0x10 +#define PERF_PMU_CAP_ITRACE 0x20/** * struct pmu - generic performance monitoring unit
include/uapi/linux/perf_event.h +11 -0
@@ -789,6 +789,17 @@ enum perf_event_type {*/ PERF_RECORD_AUX =11 , +/* +* Indicates that instruction trace has started +* +* struct { +* struct perf_event_header header; +* u32 pid; +* u32 tid; +* }; +*/ +PERF_RECORD_ITRACE_START =12 , + PERF_RECORD_MAX, /* non-ABI */ };
kernel/events/core.c +41 -0
59 lines not on this page · raw message
Alexander Shishkin
reviewerQuoted 1 line · Alexander Shishkin
* added a comment for the
ITRACE_STARTrecord.
...and I messed it up so the last change didn't make it, apologies. Should I resend the whole series as v10, for consistency?
Regards,
--
Alex
Peter Zijlstra
maintainerQuoted 6 lines · Alexander Shishkin
Quoted 1 line · Alexander Shishkin
* added a comment for the
ITRACE_STARTrecord....and I messed it up so the last change didn't make it, apologies. Should I resend the whole series as v10, for consistency?
Nah, just the one patch affected would do.
Thanks!
Alexander Shishkin
reviewerPATCH v10 14/14 perf: add ITRACE_START record to indicate that tracing has started
For counters that generate AUX data that is bound to the context of a running task, such as instruction tracing, the decoder needs to know exactly which task is running when the event is first scheduled in, before the first sched_switch. The decoder's need to know this stems from the fact that instruction flow trace decoding will almost always require program's object code in order to reconstruct said flow and for that we need at least its pid/tid in the perf stream.
To single out such instruction tracing pmus, this patch introduces ITRACE PMU capability. The reason this is not part of RECORD_AUX record is that not all pmus capable of generating AUX data need this, and the opposite is *probably* also true.
While sched_switch covers for most cases, there are two problems with it:
the consumer will need to process events out of order (that is, having found RECORD_AUX, it will have to skip forward to the nearest sched_switch to figure out which task it was, then go back to the actual trace to decode it) and it completely misses the case when the tracing is enabled and disabled before sched_switch, for example, via PERF_EVENT_IOC_DISABLE.
--- include/linux/perf_event.h | 4 ++++ include/uapi/linux/perf_event.h | 12 +++++++++++ kernel/events/core.c | 46 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+)
include/linux/perf_event.h +4 -0
@@ -127,6 +127,9 @@ struct hw_perf_event {/* for tp_event->class */ struct list_head tp_list; }; +struct {/* itrace */ +int itrace_started; + }; #ifdef CONFIG_HAVE_HW_BREAKPOINT struct { /* breakpoint */ /*
@@ -174,6 +177,7 @@ struct perf_event;#define PERF_PMU_CAP_AUX_NO_SG 0x02#define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x04#define PERF_PMU_CAP_EXCLUSIVE 0x08 +#define PERF_PMU_CAP_ITRACE 0x10/** * struct pmu - generic performance monitoring unit
include/uapi/linux/perf_event.h +12 -0
@@ -764,6 +764,18 @@ enum perf_event_type {*/ PERF_RECORD_AUX =11 , +/* +* Indicates that instruction trace has started +* +* struct { +* struct perf_event_header header; +* u32 pid; +* u32 tid; +* struct sample_id sample_id; +* }; +*/ +PERF_RECORD_ITRACE_START =12 , + PERF_RECORD_MAX, /* non-ABI */ };
kernel/events/core.c +46 -0
64 lines not on this page · raw message
Signature · 1 line
2.1.4