Introduce framework for forwarding generic non-OA performance
Subsystems (3)
cover Introduce framework for forwarding generic non-OA performance
From: Sourab Gupta <[email protected]>
This is an updated patch set (changes list at end), which builds upon the multi context OA patch set introduced earlier at:
http://lists.freedesktop.org/archives/intel-gfx/2015-July/071697.html
The OA unit, as such, is specific to render ring and can't cater to performance data requirements for other GPU engines.
Specifically, the media workloads may utilize other GPU engines, but there is currently no framework which can be used to query performance statistics for non-RCS workloads and provide this data to userspace tools. This patch set tries to address this specific problem. The aim of this patch series is to build upon the perf event framework developed earlier and use it for forwarding performance data of non-RCS engine workloads.
Since the previous PMU is customized to handle OA reports, a new perf PMU is added to handle generic non-OA performance data. An example of such non-OA performance data is the timestamps/mmio registers.
This patch set enables framework for capturing the timestamps at batch buffer boundaries, by inserting commands for the same in ringbuffer, and forwarding the samples to userspace through perf interface. Nevertheless, the framework and data structures can be extended to introduce more performance data types (other than timestamps). The intention here is to introduce a framework to enable capturing of generic performance data and forwarding the same to userspace using perf apis.
The reports generated will again have an additional footer for metadata information such as ctx_id, pid, ring id and tags (in the same way as done for OA reports specified in the patch series earlier). This information can be used by userspace tools such as MVP (Modular Video Profiler) to associate reports with individual contexts and different stages of workload execution.
In this patch set, the timestamps are captured at BB boundaries by inserting the commands in the ringbuffer at the batchbuffer boundaries. As specified earlier, for a system wide GPU profiler, the relative complexity of doing this in kernel is significantly less than supporting this usecase through userspace command insertion by all the different components.
The final patch in the series tries to extend the data structures to enable capture of upto 8 MMIO register values, in conjunction with timestamps
v2: This patch series has the following changes wrt the one floated earlier:
- Removing synchronous waits during event stop/destroy
- segregating the book-keeping data for the samples from destination buffer and collecting it into a separate list
- managing the lifetime of destination buffer with the help of gem active reference tracking
- having the scope of i915 device mutex limited to places of gem interaction and having the pmu data structures protected with a per pmu lock
- userspace can now control the metadata it wants by requesting the same during event init. The sample is sent with the requested metadata in a packed format.
- Some patches merged together and a few more introduced
- mmio whitelist in place
Sourab Gupta (8):
drm/i915: Add a new PMU for handling non-OA counter data profiling
requests
drm/i915: Add mechanism for forwarding the timestamp data through perf drm/i915: Handle event stop and destroy for GPU commands submitted drm/i915: Insert commands for capturing timestamps in the ring drm/i915: Add support for forwarding ring id in sample metadata
through perf
drm/i915: Add support for forwarding pid in timestamp sample metadata
through perf
drm/i915: Add support for forwarding execbuffer tags in timestamp
sample metadata
drm/i915: Support for retrieving MMIO register values alongwith
timestamps through perf
drivers/gpu/drm/i915/i915_dma.c | 2 + drivers/gpu/drm/i915/i915_drv.h | 41 +++ drivers/gpu/drm/i915/i915_oa_perf.c | 680 ++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_reg.h | 2 + include/uapi/drm/i915_drm.h | 41 +++ 5 files changed, 766 insertions(+)
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC 1/8 drm/i915: Add a new PMU for handling non-OA counter data profiling requests
From: Sourab Gupta <[email protected]>
The current perf PMU driver is specific for collection of OA counter statistics (which may be done in a periodic or asynchronous way). Since this enables us (and limits us) to render ring, we have no means for collection of data pertaining to other rings.
To overcome this limitation, we need to have a new PMU driver which enables data collection for other rings also (in a non-OA specific mode). This patch adds a new perf PMU to i915 device private, for handling profiling requests for non-OA counter data.This data may encompass timestamps, mmio register values, etc. for the relevant ring. The new perf PMU will serve these purposes, without constraining itself to type of data being dumped (which may restrict the user to specific ring like in case of OA counters).
The patch introduces this PMU driver alongwith its associated callbacks.
--- drivers/gpu/drm/i915/i915_dma.c | 2 + drivers/gpu/drm/i915/i915_drv.h | 18 +++ drivers/gpu/drm/i915/i915_oa_perf.c | 220 ++++++++++++++++++++++++++++++++++++ 3 files changed, 240 insertions(+)
drivers/gpu/drm/i915/i915_dma.c +2 -0
@@ -822,6 +822,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)* otherwise i915_oa_context_pin_notify() will lock an un-initialized * spinlock, upsetting lockdep checks */ i915_oa_pmu_register (dev); +i915_gen_pmu_register (dev);intel_pm_setup (dev);
@@ -1072,6 +1073,7 @@ int i915_driver_unload(struct drm_device *dev)return ret; } +i915_gen_pmu_unregister (dev);i915_oa_pmu_unregister (dev);intel_power_domains_fini (dev_priv);
drivers/gpu/drm/i915/i915_drv.h +18 -0
@@ -1985,6 +1985,20 @@ struct drm_i915_private { int sample_info_flags; } oa_pmu; +struct { +struct pmu pmu; +spinlock_t lock; +struct hrtimer timer; +struct pt_regs dummy_regs; +struct perf_event *exclusive_event; +bool event_active; + +struct { +struct drm_i915_gem_object *obj; +u8 *addr; + } buffer; + } gen_pmu; +void (*insert_profile_cmd[I915_PROFILE_MAX ]) (struct intel_ringbuffer *ringbuf,u32 ctx_id,int tag);#endif
@@ -3292,10 +3306,14 @@ int i915_parse_cmds(struct intel_engine_cs *ring,/* i915_oa_perf.c */ #ifdef CONFIG_PERF_EVENTS extern void i915_oa_pmu_register (struct drm_device *dev); +extern void i915_gen_pmu_register (struct drm_device *dev);extern void i915_oa_pmu_unregister (struct drm_device *dev); +extern void i915_gen_pmu_unregister (struct drm_device *dev);#else static inline void i915_oa_pmu_register (struct drm_device *dev) {} +static inline void i915_gen_pmu_register (struct drm_device *dev) {}static inline void i915_oa_pmu_unregister (struct drm_device *dev) {} +static inline void i915_gen_pmu_unregister (struct drm_device *dev) {}#endif /* i915_suspend.c */
drivers/gpu/drm/i915/i915_oa_perf.c +220 -0
247 lines not on this page · raw message
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC 2/8 drm/i915: Add mechanism for forwarding the timestamp data through perf
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch adds the mechanism for forwarding the timestamp data to userspace using the Gen PMU perf event interface.
The timestamps will be captured in a gem buffer object. The metadata information (ctx_id right now) pertaining to snapshot is maintained in a list, whose each node has offsets into the gem buffer object for each snapshot captured.
In order to track whether the gpu has completed processing the node, a field pertaining to corresponding gem request is added. The request is expected to be referenced whenever the gpu command is submitted.
Each snapshot collected is forwarded as a separate perf sample. The perf sample will have raw timestamp data followed by metadata information pertaining to that sample.
While forwarding the samples, we check whether the gem request is completed and dereference the corresponding request. The need to dereference the request necessitates a worker here, which will be scheduled when the hrtimer triggers.
While flushing the samples, we have to wait for the requests already scheduled, before forwarding the samples. This wait is done in a lockless fashion.
--- drivers/gpu/drm/i915/i915_drv.h | 11 ++++ drivers/gpu/drm/i915/i915_oa_perf.c | 118 +++++++++++++++++++++++++++++++++++- include/uapi/drm/i915_drm.h | 10 +++ 3 files changed, 137 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +11 -0
@@ -1675,6 +1675,13 @@ struct i915_oa_rcs_node {u32 tag; }; +struct i915_gen_pmu_node { +struct list_head head; +struct drm_i915_gem_request *req; +u32 offset; +u32 ctx_id; +}; +extern const struct i915_oa_reg i915_oa_3d_mux_config_hsw[];extern const int i915_oa_3d_mux_config_hsw_len;extern const struct i915_oa_reg i915_oa_3d_b_counter_config_hsw[];
@@ -1996,7 +2003,11 @@ struct drm_i915_private {struct {struct drm_i915_gem_object *obj;u8 *addr; +u32 node_size; +u32 node_count; } buffer; +struct list_head node_list; +struct work_struct work_timer; } gen_pmu;void (*insert_profile_cmd[I915_PROFILE_MAX ])
drivers/gpu/drm/i915/i915_oa_perf.c +116 -2
158 lines not on this page · raw message
include/uapi/drm/i915_drm.h +10 -0
@@ -140,6 +140,16 @@ struct drm_i915_oa_node_tag {__u32 pad; }; +struct drm_i915_ts_data { +__u32 ts_low; +__u32 ts_high; +}; + +struct drm_i915_ts_node_ctx_id { +__u32 ctx_id; +__u32 pad; +}; +/* Each region is a minimum of 16k, and there are at most 255 of them. */ #define I915_NR_TEX_REGIONS 255/* table size 2k - maximum due to use
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [RFC 2/8] drm/i915: Add mechanism for forwarding the timestamp data through perf
Quoted 9 lines · On Wed, Jul 15, 2015 at 02:21:40PM +0530, [email protected] wrote:
From: Sourab Gupta <[email protected]>
This patch adds the mechanism for forwarding the timestamp data to userspace using the Gen PMU perf event interface.
The timestamps will be captured in a gem buffer object. The metadata information (
ctx_idright now) pertaining to snapshot is maintained in a list, whose each node has offsets into the gem buffer object for each snapshot captured.
What is the definition of ctx_id? The only persistent one is the user_handle which is only valid within the file_priv namespace. There is no guid for ctx at the moment.
Quoted 57 lines
In order to track whether the gpu has completed processing the node, a field pertaining to corresponding gem request is added. The request is expected to be referenced whenever the gpu command is submitted.
Each snapshot collected is forwarded as a separate perf sample. The perf sample will have raw timestamp data followed by metadata information pertaining to that sample.
While forwarding the samples, we check whether the gem request is completed and dereference the corresponding request. The need to dereference the request necessitates a worker here, which will be scheduled when the hrtimer triggers.
While flushing the samples, we have to wait for the requests already scheduled, before forwarding the samples. This wait is done in a lockless fashion.Signed-off-by Sourab Gupta <[email protected]>--- drivers/gpu/drm/i915/i915_drv.h | 11 ++++ drivers/gpu/drm/i915/i915_oa_perf.c | 118 +++++++++++++++++++++++++++++++++++- include/uapi/drm/i915_drm.h | 10 +++ 3 files changed, 137 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_drv.h +11
-0@@ -1675,6 +1675,13 @@ struct i915_oa_rcs_node {u32 tag; }; +struct i915_gen_pmu_node { +struct list_head head; +struct drm_i915_gem_request *req; +u32 offset; +u32 ctx_id; +}; +extern const struct i915_oa_reg i915_oa_3d_mux_config_hsw[];extern const int i915_oa_3d_mux_config_hsw_len;extern const struct i915_oa_reg i915_oa_3d_b_counter_config_hsw[];@@ -1996,7 +2003,11 @@ struct drm_i915_private {struct {struct drm_i915_gem_object *obj;u8 *addr; +u32 node_size; +u32 node_count; } buffer; +struct list_head node_list; +struct work_struct work_timer; } gen_pmu;void (*insert_profile_cmd[I915_PROFILE_MAX ])drivers/gpu/drm/i915/i915_oa_perf.c +0
-0
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 411
Quoted 4 lines
drivers/gpu/drm/i915/i915_oa_perf.c +1
-0@@ -408,11 +408,108 @@ void forward_oa_rcs_snapshots_work(struct work_struct *__work) } } +int i915_gen_pmu_wait_gpu (struct drm_i915_private *dev_priv)
Why so many exports from this file? And why are half of them privately named?
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 422
Quoted 11 lines
drivers/gpu/drm/i915/i915_oa_perf.c +11
-0+{ +struct i915_gen_pmu_node *last_entry; +unsigned long lock_flags; +int ret; + +/* +* Wait for the last scheduled request to complete. This would +* implicitly wait for the prior submitted requests. The refcount +* of the requests is not decremented here. +*/ +spin_lock_irqsave (&dev_priv->gen_pmu.lock, lock_flags);
Urm, are we really going to be called in irq context? I really hope you are not planning on hooking in the irq handlers...
Afaict, you are just using the list from a timer context, so spin_lock_bh() would be sufficient. Apparently it isn't a timer (thanks for the misleading name!) so just spin_lock().
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 430
Quoted 7 lines
drivers/gpu/drm/i915/i915_oa_perf.c +7
-0+if (list_empty (&dev_priv->gen_pmu.node_list)) { +spin_unlock_irqrestore (&dev_priv->gen_pmu.lock, lock_flags); +return 0 ; + } + last_entry =list_last_entry (&dev_priv->gen_pmu.node_list, + struct i915_gen_pmu_node, head); +spin_unlock_irqrestore (&dev_priv->gen_pmu.lock, lock_flags);
You could write this a little neater with just one path through the crticial section.
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 432
Quoted 1 line
drivers/gpu/drm/i915/i915_oa_perf.c +1
-0+if (last_entry && last_entry->req) {
last_entry cannot be NULL.
When is req NULL? Does the last_entry->req being NULL guarrantee that all previous req are NULL?
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 435
Quoted 3 lines
drivers/gpu/drm/i915/i915_oa_perf.c +3
-0+ ret =__i915_wait_request (last_entry->req,atomic_read ( + &dev_priv->gpu_error.reset_counter), + dev_priv->mm.interruptible,NULL ,NULL );
Invalid use of dev_priv->mm.interruptible (just pass true).
Quoted 10 lines
drivers/gpu/drm/i915/i915_oa_perf.c +10
-0+if (ret) { +DRM_ERROR ("failed to wait\n" ); +return ret; + } + } +return 0 ; +} + +static void forward_one_gen_pmu_sample (struct drm_i915_private *dev_priv, +struct i915_gen_pmu_node *node)
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 455
Quoted 10 lines
drivers/gpu/drm/i915/i915_oa_perf.c +10
-0+{ +struct perf_sample_data data; +struct perf_event *event = dev_priv->gen_pmu.exclusive_event; +int ts_size, snapshot_size; +u8 *snapshot; +struct drm_i915_ts_node_ctx_id *ctx_info; +struct perf_raw_record raw; + + ts_size =sizeof (struct drm_i915_ts_data ); + snapshot_size = ts_size +sizeof (*ctx_info);
If you kept these as compile time constants it will make the rest a bit easier to follow.
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 464
Quoted 9 lines
drivers/gpu/drm/i915/i915_oa_perf.c +9
-0+ snapshot = dev_priv->gen_pmu.buffer.addr + node->offset; + + ctx_info = (struct drm_i915_ts_node_ctx_id *)(snapshot + ts_size); + ctx_info->ctx_id = node->ctx_id; + +perf_sample_data_init (&data,0 , event->hw.last_period); + +/* Note: the combined u32 raw->size member + raw data itself must be 8 +* byte aligned. (See note in init_gen_pmu_buffer for more details) */
You mean this comment?
/* size has to be aligned to 8 bytes (required by relevant gpu cmds) */ That's not particularly enlightening.
Missing BUILD_BUG tests to assert that your structure sizes are what you claim they should be. To illustrate this comment, you could do
BUILD_BUG_ON(sizeof(struct drm_i915_ts_data) != 8); BUILD_BUG_ON(sizeof(struct drm_i915_ts_mode_ctx_id) != 8); BUILD_BUG_ON((snapshot_size + 4 + sizeof(raw.size) % 8) == 0);
Otherwise the comment doesn't really make it clear exactly what has to be aligned to 8 or *why*.
Quoted 11 lines
drivers/gpu/drm/i915/i915_oa_perf.c +10
-0+ raw.size = snapshot_size +4 ; + raw.data = snapshot; + data.raw = &raw; + +perf_event_overflow (event, &data, &dev_priv->gen_pmu.dummy_regs); +} + +void forward_gen_pmu_snapshots_work (struct work_struct *__work) +{ + struct drm_i915_private *dev_priv =
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 485
Quoted 10 lines
drivers/gpu/drm/i915/i915_oa_perf.c +10
-0+container_of (__work,typeof (*dev_priv), gen_pmu.work_timer); +struct i915_gen_pmu_node *entry, *next; +struct drm_i915_gem_request *req; +unsigned long lock_flags; +int ret; + +list_for_each_entry_safe + (entry, next, &dev_priv->gen_pmu.node_list, head) { + req = entry->req; +if (req &&i915_gem_request_completed (req, true)) {
Negate the test and reduce indentation for ease of reading.
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 491
Quoted 6 lines
drivers/gpu/drm/i915/i915_oa_perf.c +6
-0+forward_one_gen_pmu_sample (dev_priv, entry); + ret =i915_mutex_lock_interruptible (dev_priv->dev); +if (ret) +break ; +i915_gem_request_assign (&entry->req,NULL ); +mutex_unlock (&dev_priv->dev->struct_mutex);
This is just i915_gem_request_unreference_unlocked().
Quoted 12 lines
drivers/gpu/drm/i915/i915_oa_perf.c +12
-0+ }else +break ; + +/* +* Do we instead need to protect whole loop? If so, we would +* need to *list_move_tail* to a deferred list, from where +* i915 device mutex could be taken to deference the requests, +* and free the node. +*/ +spin_lock_irqsave (&dev_priv->gen_pmu.lock, lock_flags); +list_del (&entry->head); +spin_unlock_irqrestore (&dev_priv->gen_pmu.lock, lock_flags);
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 512
Quoted 10 lines
drivers/gpu/drm/i915/i915_oa_perf.c +5
-1+kfree (entry); + } +} +static void gen_pmu_flush_snapshots (struct drm_i915_private *dev_priv) {WARN_ON (!dev_priv->gen_pmu.buffer.addr); -/* TODO: routine for forwarding snapshots to userspace */ +schedule_work (&dev_priv->gen_pmu.work_timer);
Why are we scheduling a timer? Might be a bad name for a work item to infer that it is a timer.
Why is this in a work queue if you already blocked during the flush?
Quoted 29 lines
drivers/gpu/drm/i915/i915_oa_perf.c +10
-1} static void@@ -761,7 +858,7 @@ static int init_gen_pmu_buffer(struct perf_event *event)struct drm_i915_private *dev_priv =container_of (event->pmu,typeof (*dev_priv), gen_pmu.pmu);struct drm_i915_gem_object *bo; -int ret; +int ret, node_size;BUG_ON (dev_priv->gen_pmu.buffer.obj);@@ -772,6 +869,15 @@ static int init_gen_pmu_buffer(struct perf_event *event) dev_priv->gen_pmu.buffer.obj = bo; dev_priv->gen_pmu.buffer.addr =vmap_oa_buffer (bo); +INIT_LIST_HEAD (&dev_priv->gen_pmu.node_list); + + node_size =sizeof (struct drm_i915_ts_data ) + +sizeof (struct drm_i915_ts_node_ctx_id ); + +/* size has to be aligned to 8 bytes (required by relevant gpu cmds) */ + node_size =ALIGN (node_size,8 ); + dev_priv->gen_pmu.buffer.node_size = node_size; + dev_priv->gen_pmu.buffer.node_count = bo->base.size / node_size;DRM_DEBUG_DRIVER ("Gen PMU Buffer initialized, vaddr = %p" , dev_priv->gen_pmu.buffer.addr);
drivers/gpu/drm/i915/i915_oa_perf.c static int i915_gen_event_flush(struct perf_event *event) · line 1512
Quoted 10 lines
drivers/gpu/drm/i915/i915_oa_perf.c +5
-0@@ -1397,6 +1503,11 @@ static int i915_gen_event_flush(struct perf_event *event) {struct drm_i915_private *i915 =container_of (event->pmu,typeof (*i915), gen_pmu.pmu); +int ret; + + ret =i915_gen_pmu_wait_gpu (i915); +if (ret) +return ret;gen_pmu_flush_snapshots (i915);
Wait for idle, then schedule a task???
-Chris
Quoted 1 line
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [RFC 2/8] drm/i915: Add mechanism for forwarding the timestamp data through perf
Quoted 6 lines · Chris Wilson
Quoted 5 lines · On Wed, Jul 15, 2015 at 02:21:40PM +0530, [email protected] wrote:
From: Sourab Gupta <[email protected]>
This patch adds the mechanism for forwarding the timestamp data to userspace using the Gen PMU perf event interface.
Quoted 8 lines
Quoted 4 lines
The timestamps will be captured in a gem buffer object. The metadata information (
ctx_idright now) pertaining to snapshot is maintained in a list, whose each node has offsets into the gem buffer object for each snapshot captured.What is the definition of
ctx_id? The only persistent one is theuser_handlewhich is only valid within thefile_privnamespace. There is no guid for ctx at the moment.
Well, this patch set makes assumption on the availability of a globally unique ctx_id. The first patch in the series proposes the same:
http://lists.freedesktop.org/archives/intel-gfx/2015-July/071698.html
Not sure, whether that would be acceptable though.
Quoted 61 lines
Quoted 61 lines
In order to track whether the gpu has completed processing the node, a field pertaining to corresponding gem request is added. The request is expected to be referenced whenever the gpu command is submitted.
Each snapshot collected is forwarded as a separate perf sample. The perf sample will have raw timestamp data followed by metadata information pertaining to that sample.
While forwarding the samples, we check whether the gem request is completed and dereference the corresponding request. The need to dereference the request necessitates a worker here, which will be scheduled when the hrtimer triggers.
While flushing the samples, we have to wait for the requests already scheduled, before forwarding the samples. This wait is done in a lockless fashion.Signed-off-by Sourab Gupta <[email protected]>--- drivers/gpu/drm/i915/i915_drv.h | 11 ++++ drivers/gpu/drm/i915/i915_oa_perf.c | 118 +++++++++++++++++++++++++++++++++++- include/uapi/drm/i915_drm.h | 10 +++ 3 files changed, 137 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_drv.h +11
-0@@ -1675,6 +1675,13 @@ struct i915_oa_rcs_node {u32 tag; }; +struct i915_gen_pmu_node { +struct list_head head; +struct drm_i915_gem_request *req; +u32 offset; +u32 ctx_id; +}; +extern const struct i915_oa_reg i915_oa_3d_mux_config_hsw[];extern const int i915_oa_3d_mux_config_hsw_len;extern const struct i915_oa_reg i915_oa_3d_b_counter_config_hsw[];@@ -1996,7 +2003,11 @@ struct drm_i915_private {struct {struct drm_i915_gem_object *obj;u8 *addr; +u32 node_size; +u32 node_count; } buffer; +struct list_head node_list; +struct work_struct work_timer; } gen_pmu;void (*insert_profile_cmd[I915_PROFILE_MAX ])drivers/gpu/drm/i915/i915_oa_perf.c +0
-0@@ -408,11 +408,108 @@ void forward_oa_rcs_snapshots_work(struct work_struct *__work) } }
Quoted 4 lines
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 411
Quoted 1 line
drivers/gpu/drm/i915/i915_oa_perf.c +1
-0+int i915_gen_pmu_wait_gpu (struct drm_i915_private *dev_priv)Why so many exports from this file? And why are half of them privately named?
Acknowledged. The exports are not needed. Will have a static declaration.
Quoted 16 lines
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 422
Quoted 12 lines
drivers/gpu/drm/i915/i915_oa_perf.c +11
-0+{ +struct i915_gen_pmu_node *last_entry; +unsigned long lock_flags; +int ret; + +/* +* Wait for the last scheduled request to complete. This would +* implicitly wait for the prior submitted requests. The refcount +* of the requests is not decremented here. +*/ +spin_lock_irqsave (&dev_priv->gen_pmu.lock, lock_flags);Urm, are we really going to be called in irq context? I really hope you are not planning on hooking in the irq handlers...
Quoted 3 lines
Afaict, you are just using the list from a timer context, so
spin_lock_bh()would be sufficient. Apparently it isn't a timer (thanks for the misleading name!) so justspin_lock().
No, it won't be called from irq context. I'll just use spin_lock() here.
Quoted 11 lines
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 430
Quoted 8 lines
drivers/gpu/drm/i915/i915_oa_perf.c +7
-0+if (list_empty (&dev_priv->gen_pmu.node_list)) { +spin_unlock_irqrestore (&dev_priv->gen_pmu.lock, lock_flags); +return 0 ; + } + last_entry =list_last_entry (&dev_priv->gen_pmu.node_list, + struct i915_gen_pmu_node, head); +spin_unlock_irqrestore (&dev_priv->gen_pmu.lock, lock_flags);You could write this a little neater with just one path through the crticial section.
Will rework on this.
Quoted 7 lines
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 432
Quoted 2 lines
drivers/gpu/drm/i915/i915_oa_perf.c +1
-0+if (last_entry && last_entry->req) {
last_entrycannot be NULL.When is req NULL? Does the
last_entry->reqbeing NULL guarrantee that all previous req are NULL?
Sorry, these extraneous checks may have crept in. Agreed that last_entry can't be NULL, and same for req, since we have refcounted the req. Will remove these.
Quoted 6 lines
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 435
Quoted 4 lines
drivers/gpu/drm/i915/i915_oa_perf.c +3
-0+ ret =__i915_wait_request (last_entry->req,atomic_read ( + &dev_priv->gpu_error.reset_counter), + dev_priv->mm.interruptible,NULL ,NULL );Invalid use of
dev_priv->mm.interruptible(just pass true).
Will make this change.
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/i915/i915_oa_perf.c +15
-0+if (ret) { +DRM_ERROR ("failed to wait\n" ); +return ret; + } + } +return 0 ; +} + +static void forward_one_gen_pmu_sample (struct drm_i915_private *dev_priv, +struct i915_gen_pmu_node *node) +{ +struct perf_sample_data data; +struct perf_event *event = dev_priv->gen_pmu.exclusive_event; +int ts_size, snapshot_size; +u8 *snapshot;
Quoted 8 lines
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 455
Quoted 5 lines
drivers/gpu/drm/i915/i915_oa_perf.c +5
-0+struct drm_i915_ts_node_ctx_id *ctx_info; +struct perf_raw_record raw; + + ts_size =sizeof (struct drm_i915_ts_data ); + snapshot_size = ts_size +sizeof (*ctx_info);If you kept these as compile time constants it will make the rest a bit easier to follow.
Will make this change.
Quoted 18 lines
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 464
Quoted 10 lines
drivers/gpu/drm/i915/i915_oa_perf.c +9
-0+ snapshot = dev_priv->gen_pmu.buffer.addr + node->offset; + + ctx_info = (struct drm_i915_ts_node_ctx_id *)(snapshot + ts_size); + ctx_info->ctx_id = node->ctx_id; + +perf_sample_data_init (&data,0 , event->hw.last_period); + +/* Note: the combined u32 raw->size member + raw data itself must be 8 +* byte aligned. (See note in init_gen_pmu_buffer for more details) */ You mean this comment?
/* size has to be aligned to 8 bytes (required by relevant gpu cmds) */ That's not particularly enlightening.Missing
BUILD_BUGtests to assert that your structure sizes are what you claim they should be. To illustrate this comment, you could do
Quoted 7 lines
BUILD_BUG_ON(sizeof(struct drm_i915_ts_data) != 8);BUILD_BUG_ON(sizeof(struct drm_i915_ts_mode_ctx_id) != 8);BUILD_BUG_ON((snapshot_size + 4 + sizeof(raw.size) % 8) == 0);Otherwise the comment doesn't really make it clear exactly what has to be aligned to 8 or *why*.
Actually, this check is for ensuring that the combined size of raw data
+ the size of 'raw->size' member field should be multiple of 8 bytes. This check can be seen at kernel/events/core.c: perf_prepare_sample() (the place where PERF_SAMPLE_RAW is processed).
Will reword the comment to make it clearer, in addition to having the BUILD_BUG_ON macro checks.
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/i915/i915_oa_perf.c +14
-0+ raw.size = snapshot_size +4 ; + raw.data = snapshot; + data.raw = &raw; + +perf_event_overflow (event, &data, &dev_priv->gen_pmu.dummy_regs); +} + +void forward_gen_pmu_snapshots_work (struct work_struct *__work) +{ +struct drm_i915_private *dev_priv = +container_of (__work,typeof (*dev_priv), gen_pmu.work_timer); +struct i915_gen_pmu_node *entry, *next; +struct drm_i915_gem_request *req; +unsigned long lock_flags;
Quoted 8 lines
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 485
Quoted 6 lines
drivers/gpu/drm/i915/i915_oa_perf.c +6
-0+int ret; + +list_for_each_entry_safe + (entry, next, &dev_priv->gen_pmu.node_list, head) { + req = entry->req; +if (req &&i915_gem_request_completed (req, true)) {Negate the test and reduce indentation for ease of reading.
Ok, will do.
Quoted 9 lines
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 491
Quoted 7 lines
drivers/gpu/drm/i915/i915_oa_perf.c +6
-0+forward_one_gen_pmu_sample (dev_priv, entry); + ret =i915_mutex_lock_interruptible (dev_priv->dev); +if (ret) +break ; +i915_gem_request_assign (&entry->req,NULL ); +mutex_unlock (&dev_priv->dev->struct_mutex);This is just
i915_gem_request_unreference_unlocked().
Right. Missed it. Will have this function.
Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/i915/i915_oa_perf.c +16
-0+ }else +break ; + +/* +* Do we instead need to protect whole loop? If so, we would +* need to *list_move_tail* to a deferred list, from where +* i915 device mutex could be taken to deference the requests, +* and free the node. +*/ +spin_lock_irqsave (&dev_priv->gen_pmu.lock, lock_flags); +list_del (&entry->head); +spin_unlock_irqrestore (&dev_priv->gen_pmu.lock, lock_flags); +kfree (entry); + } +} +static void gen_pmu_flush_snapshots (struct drm_i915_private *dev_priv) {WARN_ON (!dev_priv->gen_pmu.buffer.addr);
Quoted 6 lines
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 512
Quoted 2 lines
drivers/gpu/drm/i915/i915_oa_perf.c +1
-1-/* TODO: routine for forwarding snapshots to userspace */ +schedule_work (&dev_priv->gen_pmu.work_timer);Why are we scheduling a timer? Might be a bad name for a work item to infer that it is a timer.
Well, this is a case of bad name and it's a work item really.
Quoted 2 lines
Why is this in a work queue if you already blocked during the flush?
Actually, the gen_pmu_flush_snapshots() fn is called from 3 places:
hrtimer, event_stop and event_flush. And we can block only from event flush. So, this function not really tied with event flush only.
Also, the job of forwarding samples needs mutex to be taken (to dereference the request : i915_gem_request_unreference_unlocked), and since the forwarding has to be initiated from atomic context (e.g. hrtimer), I created a wq for the same, with the intention of not having code duplication for event flush.
Probably, the better sense would be to have the forwarding functionality implemented in a seperate function. The work item (which would be scheduled from hrtimer/event stop) would be calling that function. And the the event flush would directly call this forwarding fn, without the extraneous work item scheduled. Does this seem ok?
Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/i915/i915_oa_perf.c +15
-1} static void@@ -761,7 +858,7 @@ static int init_gen_pmu_buffer(struct perf_event *event)struct drm_i915_private *dev_priv =container_of (event->pmu,typeof (*dev_priv), gen_pmu.pmu);struct drm_i915_gem_object *bo; -int ret; +int ret, node_size;BUG_ON (dev_priv->gen_pmu.buffer.obj);@@ -772,6 +869,15 @@ static int init_gen_pmu_buffer(struct perf_event *event) dev_priv->gen_pmu.buffer.obj = bo; dev_priv->gen_pmu.buffer.addr =vmap_oa_buffer (bo); +INIT_LIST_HEAD (&dev_priv->gen_pmu.node_list); + + node_size =sizeof (struct drm_i915_ts_data ) + +sizeof (struct drm_i915_ts_node_ctx_id ); + +/* size has to be aligned to 8 bytes (required by relevant gpu cmds) */ + node_size =ALIGN (node_size,8 ); + dev_priv->gen_pmu.buffer.node_size = node_size; + dev_priv->gen_pmu.buffer.node_count = bo->base.size / node_size;DRM_DEBUG_DRIVER ("Gen PMU Buffer initialized, vaddr = %p" , dev_priv->gen_pmu.buffer.addr);@@ -1397,6 +1503,11 @@ static int i915_gen_event_flush(struct perf_event *event) {struct drm_i915_private *i915 =container_of (event->pmu,typeof (*i915), gen_pmu.pmu); +int ret; + + ret =i915_gen_pmu_wait_gpu (i915); +if (ret) +return ret;
Quoted 6 lines
drivers/gpu/drm/i915/i915_oa_perf.c static int i915_gen_event_flush(struct perf_event *event) · line 1512
Quoted 1 line
drivers/gpu/drm/i915/i915_oa_perf.c +0
-0gen_pmu_flush_snapshots (i915);Wait for idle, then schedule a task???
-ChrisQuoted 1 line
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [RFC 2/8] drm/i915: Add mechanism for forwarding the timestamp data through perf
Quoted 26 lines · Sourab
Quoted 10 lines · Chris Wilson
drivers/gpu/drm/i915/i915_oa_perf.c void forward_oa_rcs_snapshots_work(struct work_struct *__work) · line 512
Quoted 6 lines
static void
gen_pmu_flush_snapshots(struct drm_i915_private *dev_priv){drivers/gpu/drm/i915/i915_oa_perf.c +1
-1WARN_ON (!dev_priv->gen_pmu.buffer.addr); -/* TODO: routine for forwarding snapshots to userspace */ +schedule_work (&dev_priv->gen_pmu.work_timer);Why are we scheduling a timer? Might be a bad name for a work item to infer that it is a timer.
Well, this is a case of bad name and it's a work item really.
Quoted 2 lines
Why is this in a work queue if you already blocked during the flush?
Actually, the
gen_pmu_flush_snapshots()fn is called from 3 places:
hrtimer,event_stopandevent_flush. And we can block only from event flush. So, this function not really tied with event flush only.Also, the job of forwarding samples needs mutex to be taken (to dereference the request :
i915_gem_request_unreference_unlocked), and since the forwarding has to be initiated from atomic context (e.g. hrtimer), I created a wq for the same, with the intention of not having code duplication for event flush.
Quoted 5 lines
Probably, the better sense would be to have the forwarding functionality implemented in a seperate function. The work item (which would be scheduled from hrtimer/event stop) would be calling that function. And the the event flush would directly call this forwarding fn, without the extraneous work item scheduled. Does this seem ok?
Indeed that's an improvement for flush, where the semantics may be such that after calling it we do expect to be able to process the samples (in userspace) immediately.
Having a comment at the top the forward function would also help the reader to understand the contexts from which we can be called (and why). It's something we often lack, but is very useful for review. -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC 3/8 drm/i915: Handle event stop and destroy for GPU commands submitted
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch handles the event stop and destroy callbacks taking into account the fact that there may be commands scheduled on GPU which may utilize the destination buffer.
The event stop would just set the event state, and stop forwarding data to userspace. From userspace perspective, for all purposes, the event sampling is stopped.A subsequent event start (without event destroy) would start forwarding samples again.
The event destroy releases the local copy of the dest buffer. But since it is expected that the active reference of buffer is taken while inserting commands, we can rest assured that buffer is freed up only after GPU is done with it.
Still there is a need to schedule a worker from event destroy, because we need to do some further stuff like freeing up request references.
The ideal solution here would be to have a callback when the last request is finished on GPU, so that we can do this stuff there (WIP:Chris' retire-notification mechanism). Till the time, a worker thread will do.
A subsequent event init would have to wait for previously submitted RPC commands to complete or return -EBUSY. Currently, for the sake of simplicity, we are returning -EBUSY if such a case is detected.
--- drivers/gpu/drm/i915/i915_drv.h | 2 + drivers/gpu/drm/i915/i915_oa_perf.c | 104 +++++++++++++++++++++++++++++++----- 2 files changed, 92 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -1679,6 +1679,7 @@ struct i915_gen_pmu_node {struct list_head head;struct drm_i915_gem_request *req;u32 offset; +bool discard;u32 ctx_id; };
@@ -2008,6 +2009,7 @@ struct drm_i915_private { } buffer;struct list_head node_list;struct work_struct work_timer; +struct work_struct work_event_destroy; } gen_pmu;void (*insert_profile_cmd[I915_PROFILE_MAX ])
drivers/gpu/drm/i915/i915_oa_perf.c +90 -14
177 lines not on this page · raw message
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC 4/8 drm/i915: Insert commands for capturing timestamps in the ring
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch adds the routines through which one can insert commands in the ringbuf for capturing timestamps, which are used to insert these commands around the batchbuffer.
While inserting the commands, we keep a reference of associated request. This will be released when we are forwarding the samples to userspace (or when the event is being destroyed).
Also, an active reference of the destination buffer is taken here, so that we can be assured that the buffer is freed up only after GPU is done with it, even if the local reference of the buffer is released.
--- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_oa_perf.c | 73 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_reg.h | 2 + 3 files changed, 76 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +1 -0
@@ -1662,6 +1662,7 @@ enum i915_oa_event_state {enum i915_profile_mode {I915_PROFILE_OA =0 , +I915_PROFILE_TS ,I915_PROFILE_MAX , };
drivers/gpu/drm/i915/i915_oa_perf.c +73 -0
91 lines not on this page · raw message
drivers/gpu/drm/i915/i915_reg.h +2 -0
@@ -347,6 +347,7 @@#define MI_FLUSH_DW_STORE_INDEX (1<<21)#define MI_INVALIDATE_TLB (1<<18)#define MI_FLUSH_DW_OP_STOREDW (1<<14) +#define MI_FLUSH_DW_OP_STAMP (3<<14)#define MI_FLUSH_DW_OP_MASK (3<<14)#define MI_FLUSH_DW_NOTIFY (1<<8)#define MI_INVALIDATE_BSD (1<<7)
@@ -423,6 +424,7 @@#define PIPE_CONTROL_MEDIA_STATE_CLEAR (1<<16)#define PIPE_CONTROL_QW_WRITE (1<<14)#define PIPE_CONTROL_POST_SYNC_OP_MASK (3<<14) +#define PIPE_CONTROL_TIMESTAMP_WRITE (3<<14)#define PIPE_CONTROL_DEPTH_STALL (1<<13)#define PIPE_CONTROL_WRITE_FLUSH (1<<12)#define PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH (1<<12)/* gen6+ */
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC 5/8 drm/i915: Add support for forwarding ring id in sample metadata through perf
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch introduces flags and adds support for having ring id output with the timestamp samples and forwarding them through perf.
When the userspace expresses its interest in listening to the ring id through a gen pmu attr field during event init, the samples generated would have an additional field appended with the ring id information. This patch enables this framework, which can be expanded upon to introduce further fields in the gen pmu attr through which additional metadata information can be appended to samples.
--- drivers/gpu/drm/i915/i915_drv.h | 3 ++ drivers/gpu/drm/i915/i915_oa_perf.c | 90 ++++++++++++++++++++++++++++++++++++- include/uapi/drm/i915_drm.h | 13 ++++++ 3 files changed, 105 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +3 -0
@@ -1682,6 +1682,7 @@ struct i915_gen_pmu_node {u32 offset;bool discard;u32 ctx_id; +u32 ring; };extern const struct i915_oa_reg i915_oa_3d_mux_config_hsw[];
@@ -2011,6 +2012,8 @@ struct drm_i915_private {struct list_head node_list;struct work_struct work_timer;struct work_struct work_event_destroy; +#define I915_GEN_PMU_SAMPLE_RING (1<<0) +int sample_info_flags; } gen_pmu;void (*insert_profile_cmd[I915_PROFILE_MAX ])
drivers/gpu/drm/i915/i915_oa_perf.c +89 -1
137 lines not on this page · raw message
include/uapi/drm/i915_drm.h +13 -0
@@ -81,6 +81,8 @@#define I915_OA_ATTR_SIZE_VER0 32/* sizeof first published struct */ +#define I915_GEN_PMU_ATTR_SIZE_VER0 8/* sizeof first published struct */ + typedef struct _drm_i915_oa_attr { __u32 size;
@@ -98,6 +100,12 @@ typedef struct _drm_i915_oa_attr { __reserved_1:60 ; } drm_i915_oa_attr_t; +struct drm_i915_gen_pmu_attr { +__u32 size; +__u32 sample_ring:1 , + __reserved_1:31 ; +}; +/* Header for PERF_RECORD_DEVICE type events */ typedef struct _drm_i915_oa_event_header { __u32 type;
@@ -150,6 +158,11 @@ struct drm_i915_ts_node_ctx_id {__u32 pad; }; +struct drm_i915_ts_node_ring_id { +__u32 ring; +__u32 pad; +}; +/* Each region is a minimum of 16k, and there are at most 255 of them. */ #define I915_NR_TEX_REGIONS 255/* table size 2k - maximum due to use
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC 6/8 drm/i915: Add support for forwarding pid in timestamp sample metadata through perf
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch introduces flags and adds support for having pid output with the timestamp samples and forwarding them through perf.
When the userspace expresses its interest in listening to the pid through a gen pmu attr field during event init, the samples generated would have an additional field appended with the pid information.
--- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_oa_perf.c | 16 ++++++++++++++++ include/uapi/drm/i915_drm.h | 8 +++++++- 3 files changed, 25 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -1683,6 +1683,7 @@ struct i915_gen_pmu_node {bool discard;u32 ctx_id;u32 ring; +u32 pid; };extern const struct i915_oa_reg i915_oa_3d_mux_config_hsw[];
@@ -2013,6 +2014,7 @@ struct drm_i915_private {struct work_struct work_timer;struct work_struct work_event_destroy;#define I915_GEN_PMU_SAMPLE_RING (1<<0) +#define I915_GEN_PMU_SAMPLE_PID (1<<1)int sample_info_flags; } gen_pmu;
drivers/gpu/drm/i915/i915_oa_perf.c +16 -0
@@ -124,6 +124,8 @@ void i915_gen_insert_cmd_ts(struct intel_ringbuffer *ringbuf, u32 ctx_id, entry->ctx_id = ctx_id;if (dev_priv->gen_pmu.sample_info_flags &I915_GEN_PMU_SAMPLE_RING ) entry->ring =ring_id_mask (ring); +if (dev_priv->gen_pmu.sample_info_flags &I915_GEN_PMU_SAMPLE_PID ) + entry->pid = current->pid;i915_gem_request_assign (&entry->req, ring->outstanding_lazy_request);spin_lock_irqsave (&dev_priv->gen_pmu.lock, lock_flags);
@@ -556,6 +558,7 @@ static void forward_one_gen_pmu_sample(struct drm_i915_private *dev_priv,u8 *snapshot, *current_ptr;struct drm_i915_ts_node_ctx_id *ctx_info;struct drm_i915_ts_node_ring_id *ring_info; +struct drm_i915_ts_node_pid *pid_info;struct perf_raw_record raw; ts_size =sizeof (struct drm_i915_ts_data );
@@ -573,6 +576,13 @@ static void forward_one_gen_pmu_sample(struct drm_i915_private *dev_priv, current_ptr = snapshot + snapshot_size; } +if (dev_priv->gen_pmu.sample_info_flags &I915_GEN_PMU_SAMPLE_PID ) { + pid_info = (struct drm_i915_ts_node_pid *)current_ptr; + pid_info->pid = node->pid; + snapshot_size +=sizeof (*pid_info); + current_ptr = snapshot + snapshot_size; + } +perf_sample_data_init (&data,0 , event->hw.last_period);/* Note: the combined u32 raw->size member + raw data itself must be 8
@@ -1027,6 +1037,9 @@ static int init_gen_pmu_buffer(struct perf_event *event)if (dev_priv->gen_pmu.sample_info_flags &I915_GEN_PMU_SAMPLE_RING ) node_size +=sizeof (struct drm_i915_ts_node_ring_id ); +if (dev_priv->gen_pmu.sample_info_flags &I915_GEN_PMU_SAMPLE_PID ) + node_size +=sizeof (struct drm_i915_ts_node_pid ); +/* size has to be aligned to 8 bytes (required by relevant gpu cmds) */ node_size =ALIGN (node_size,8 ); dev_priv->gen_pmu.buffer.node_size = node_size;
@@ -1642,6 +1655,9 @@ static int i915_gen_event_init(struct perf_event *event) dev_priv->gen_pmu.sample_info_flags |=I915_GEN_PMU_SAMPLE_RING ; +if (gen_attr.sample_pid) + dev_priv->gen_pmu.sample_info_flags |=I915_GEN_PMU_SAMPLE_PID ; +/* To avoid the complexity of having to accurately filter * data and marshal to the appropriate client * we currently only allow exclusive access */
include/uapi/drm/i915_drm.h +7 -1
@@ -103,7 +103,8 @@ typedef struct _drm_i915_oa_attr {struct drm_i915_gen_pmu_attr {__u32 size;__u32 sample_ring:1 , - __reserved_1:31 ; + sample_pid:1 , + __reserved_1:30 ; };/* Header for PERF_RECORD_DEVICE type events */
@@ -163,6 +164,11 @@ struct drm_i915_ts_node_ring_id {__u32 pad; }; +struct drm_i915_ts_node_pid { +__u32 pid; +__u32 pad; +}; +/* Each region is a minimum of 16k, and there are at most 255 of them. */ #define I915_NR_TEX_REGIONS 255/* table size 2k - maximum due to use
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC 7/8 drm/i915: Add support for forwarding execbuffer tags in timestamp sample metadata
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch enables userspace to specify tags (per workload), provided via execbuffer ioctl, which could be added to timestamps samples, to help associate samples with the corresponding workloads.
There may be multiple stages within a single context, from a userspace perspective. An ability is needed to individually associate the samples with their corresponding workloads(execbuffers), which may not be possible solely with ctx_id or pid information.
This patch enables such this mechanism.
--- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_oa_perf.c | 16 ++++++++++++++++ include/uapi/drm/i915_drm.h | 8 +++++++- 3 files changed, 25 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -1684,6 +1684,7 @@ struct i915_gen_pmu_node {u32 ctx_id;u32 ring;u32 pid; +u32 tag; };extern const struct i915_oa_reg i915_oa_3d_mux_config_hsw[];
@@ -2015,6 +2016,7 @@ struct drm_i915_private {struct work_struct work_event_destroy;#define I915_GEN_PMU_SAMPLE_RING (1<<0)#define I915_GEN_PMU_SAMPLE_PID (1<<1) +#define I915_GEN_PMU_SAMPLE_TAG (1<<2)int sample_info_flags; } gen_pmu;
drivers/gpu/drm/i915/i915_oa_perf.c +16 -0
@@ -126,6 +126,8 @@ void i915_gen_insert_cmd_ts(struct intel_ringbuffer *ringbuf, u32 ctx_id, entry->ring =ring_id_mask (ring);if (dev_priv->gen_pmu.sample_info_flags &I915_GEN_PMU_SAMPLE_PID ) entry->pid = current->pid; +if (dev_priv->gen_pmu.sample_info_flags &I915_GEN_PMU_SAMPLE_TAG ) + entry->tag = tag;i915_gem_request_assign (&entry->req, ring->outstanding_lazy_request);spin_lock_irqsave (&dev_priv->gen_pmu.lock, lock_flags);
@@ -559,6 +561,7 @@ static void forward_one_gen_pmu_sample(struct drm_i915_private *dev_priv,struct drm_i915_ts_node_ctx_id *ctx_info;struct drm_i915_ts_node_ring_id *ring_info;struct drm_i915_ts_node_pid *pid_info; +struct drm_i915_ts_node_tag *tag_info;struct perf_raw_record raw; ts_size =sizeof (struct drm_i915_ts_data );
@@ -583,6 +586,13 @@ static void forward_one_gen_pmu_sample(struct drm_i915_private *dev_priv, current_ptr = snapshot + snapshot_size; } +if (dev_priv->gen_pmu.sample_info_flags &I915_GEN_PMU_SAMPLE_TAG ) { + tag_info = (struct drm_i915_ts_node_tag *)current_ptr; + tag_info->tag = node->tag; + snapshot_size +=sizeof (*tag_info); + current_ptr = snapshot + snapshot_size; + } +perf_sample_data_init (&data,0 , event->hw.last_period);/* Note: the combined u32 raw->size member + raw data itself must be 8
@@ -1040,6 +1050,9 @@ static int init_gen_pmu_buffer(struct perf_event *event)if (dev_priv->gen_pmu.sample_info_flags &I915_GEN_PMU_SAMPLE_PID ) node_size +=sizeof (struct drm_i915_ts_node_pid ); +if (dev_priv->gen_pmu.sample_info_flags &I915_GEN_PMU_SAMPLE_TAG ) + node_size +=sizeof (struct drm_i915_ts_node_tag ); +/* size has to be aligned to 8 bytes (required by relevant gpu cmds) */ node_size =ALIGN (node_size,8 ); dev_priv->gen_pmu.buffer.node_size = node_size;
@@ -1658,6 +1671,9 @@ static int i915_gen_event_init(struct perf_event *event)if (gen_attr.sample_pid) dev_priv->gen_pmu.sample_info_flags |=I915_GEN_PMU_SAMPLE_PID ; +if (gen_attr.sample_tag) + dev_priv->gen_pmu.sample_info_flags |=I915_GEN_PMU_SAMPLE_TAG ; +/* To avoid the complexity of having to accurately filter * data and marshal to the appropriate client * we currently only allow exclusive access */
include/uapi/drm/i915_drm.h +7 -1
@@ -104,7 +104,8 @@ struct drm_i915_gen_pmu_attr {__u32 size; __u32 sample_ring:1, sample_pid:1, - __reserved_1:30; + sample_tag:1, + __reserved_1:29; };/* Header for PERF_RECORD_DEVICE type events */
@@ -169,6 +170,11 @@ struct drm_i915_ts_node_pid {__u32 pad; }; +struct drm_i915_ts_node_tag { +__u32 tag; +__u32 pad; +}; +/* Each region is a minimum of 16k, and there are at most 255 of them. */ #define I915_NR_TEX_REGIONS 255/* table size 2k - maximum due to use
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC 8/8 drm/i915: Support for retrieving MMIO register values alongwith timestamps through perf
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch adds support for retrieving MMIO register values alongwith timestamps and forwarding them to userspace through perf.
The userspace can request upto 8 MMIO register values to be dumped. The addresses of upto 8 MMIO registers can be passed through perf attr config. The registers are checked against a whitelist before passing them on. The commands to dump the values of these MMIO registers are then inserted into the ring alongwith commands to dump the timestamps.
--- drivers/gpu/drm/i915/i915_drv.h | 2 + drivers/gpu/drm/i915/i915_oa_perf.c | 87 ++++++++++++++++++++++++++++++++++--- include/uapi/drm/i915_drm.h | 10 ++++- 3 files changed, 92 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -2017,7 +2017,9 @@ struct drm_i915_private {#define I915_GEN_PMU_SAMPLE_RING (1<<0)#define I915_GEN_PMU_SAMPLE_PID (1<<1)#define I915_GEN_PMU_SAMPLE_TAG (1<<2) +#define I915_GEN_PMU_SAMPLE_MMIO (1<<3)int sample_info_flags; +u32 mmio_list[8 ]; } gen_pmu;void (*insert_profile_cmd[I915_PROFILE_MAX ])
drivers/gpu/drm/i915/i915_oa_perf.c +82 -5
137 lines not on this page · raw message
include/uapi/drm/i915_drm.h +8 -2
@@ -81,7 +81,7 @@#define I915_OA_ATTR_SIZE_VER0 32/* sizeof first published struct */ -#define I915_GEN_PMU_ATTR_SIZE_VER0 8/* sizeof first published struct */ +#define I915_GEN_PMU_ATTR_SIZE_VER0 40/* sizeof first published struct */ typedef struct _drm_i915_oa_attr { __u32 size;
@@ -105,7 +105,9 @@ struct drm_i915_gen_pmu_attr { __u32 sample_ring:1, sample_pid:1, sample_tag:1, - __reserved_1:29; + sample_mmio:1, + __reserved_1:28; +__u32 mmio_list[8 ]; };/* Header for PERF_RECORD_DEVICE type events */
@@ -155,6 +157,10 @@ struct drm_i915_ts_data {__u32 ts_high; }; +struct drm_i915_mmio_data { +__u32 mmio[8 ]; +}; +struct drm_i915_ts_node_ctx_id {__u32 ctx_id;__u32 pad;
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [RFC 8/8] drm/i915: Support for retrieving MMIO register values alongwith timestamps through perf
Quoted 66 lines · On Wed, Jul 15, 2015 at 02:21:46PM +0530, [email protected] wrote:
From: Sourab Gupta <[email protected]>
This patch adds support for retrieving MMIO register values alongwith timestamps and forwarding them to userspace through perf.
The userspace can request upto 8 MMIO register values to be dumped. The addresses of upto 8 MMIO registers can be passed through perf attr config. The registers are checked against a whitelist before passing them on. The commands to dump the values of these MMIO registers are then inserted into the ring alongwith commands to dump the timestamps.Signed-off-by Sourab Gupta <[email protected]>--- drivers/gpu/drm/i915/i915_drv.h | 2 + drivers/gpu/drm/i915/i915_oa_perf.c | 87 ++++++++++++++++++++++++++++++++++--- include/uapi/drm/i915_drm.h | 10 ++++- 3 files changed, 92 insertions(+), 7 deletions(-)drivers/gpu/drm/i915/i915_drv.h +2
-0@@ -2017,7 +2017,9 @@ struct drm_i915_private {#define I915_GEN_PMU_SAMPLE_RING (1<<0)#define I915_GEN_PMU_SAMPLE_PID (1<<1)#define I915_GEN_PMU_SAMPLE_TAG (1<<2) +#define I915_GEN_PMU_SAMPLE_MMIO (1<<3)int sample_info_flags; +u32 mmio_list[8 ]; } gen_pmu;void (*insert_profile_cmd[I915_PROFILE_MAX ])drivers/gpu/drm/i915/i915_oa_perf.c +11
-2@@ -113,8 +113,8 @@ void i915_gen_insert_cmd_ts(struct intel_ringbuffer *ringbuf, u32 ctx_id,struct drm_i915_gem_object *obj = dev_priv->gen_pmu.buffer.obj;struct i915_gen_pmu_node *entry;unsigned long lock_flags; -u32 addr =0 ; -int ret; +u32 mmio_addr, addr =0 ; +int ret, i; entry =kzalloc (sizeof (*entry),GFP_KERNEL );if (entry ==NULL ) {@@ -150,6 +150,7 @@ void i915_gen_insert_cmd_ts(struct intel_ringbuffer *ringbuf, u32 ctx_id,spin_unlock_irqrestore (&dev_priv->gen_pmu.lock, lock_flags); addr =i915_gem_obj_ggtt_offset (obj) + entry->offset; + mmio_addr = addr +sizeof (struct drm_i915_ts_data );if (ring->id ==RCS ) { ret =intel_ring_begin (ring,6 );@@ -177,6 +178,25 @@ void i915_gen_insert_cmd_ts(struct intel_ringbuffer *ringbuf, u32 ctx_id,intel_ring_emit (ring,0 );/* imm high, must be zero */ intel_ring_advance (ring); } +for (i =0 ; i <8 ; i++) { +if (0 == dev_priv->gen_pmu.mmio_list[i]) +break ; + + addr = mmio_addr + + i *sizeof (dev_priv->gen_pmu.mmio_list[i]); + + ret =intel_ring_begin (ring,4 );
drivers/gpu/drm/i915/i915_oa_perf.c void i915_gen_insert_cmd_ts(struct intel_ringbuffer *ringbuf, u32 ctx_id, · line 198
Quoted 10 lines
drivers/gpu/drm/i915/i915_oa_perf.c +10
-0+if (ret) +return ; + +intel_ring_emit (ring, +MI_STORE_REGISTER_MEM (1 ) | +MI_SRM_LRM_GLOBAL_GTT ); +intel_ring_emit (ring, dev_priv->gen_pmu.mmio_list[i]); +intel_ring_emit (ring, addr); +intel_ring_emit (ring,MI_NOOP ); +intel_ring_advance (ring);
Premature optimisation, but can we store the register array with a single command?
for (i = 0; i < 8; i++) {
if (0 == dev_priv->gen_pmu.mmio_list[i])
break;ret = intel_ring_begin(ring, 2*i + 2);
if (ret)
return;
intel_ring_emit(MI_STORE_REGISTER_MEM(i));
for (i = 0; i < 8; i++) {
if (0 == dev_priv->gen_pmu.mmio_list[i])
break;
intel_ring_emit(dev_priv->gen_pmu.mmio_list[i]);
intel_ring_emit(addr + i*4);
}intel_ring_emit(MI_NOOP);
You should also consider ensuring that we have a command barrier between these and 3d operations. If only we had engine->emit_flush(I915_COMMAND_BARRIER).
drivers/gpu/drm/i915/i915_oa_perf.c err_size: · line 1695
Quoted 13 lines
drivers/gpu/drm/i915/i915_oa_perf.c +13
-0+/* Some embargoed entries missing from whitelist */ +static const struct register_whitelist { +uint64_t offset; +uint32_t size; +/* supported gens, 0x10 for 4, 0x30 for 4 and 5, etc. */ +uint32_t gen_bitmask; +} whitelist[] = { + {GEN6_GT_GFX_RC6 ,4 ,GEN_RANGE (7 ,9 ) }, + { GEN6_GT_GFX_RC6p,4 ,GEN_RANGE (7 ,9 ) }, +}; + +static int check_mmio_whitelist (struct drm_i915_private *dev_priv, +struct drm_i915_gen_pmu_attr *gen_attr)
Just what I came looking for.
drivers/gpu/drm/i915/i915_oa_perf.c err_size: · line 1700
Quoted 5 lines
drivers/gpu/drm/i915/i915_oa_perf.c +5
-0+{ +struct register_whitelist const *entry = whitelist; +int i, count; + +for (count =0 ; count <8 ; count++) {
hardcoded value, ARRAY_SIZE(gen_attr->mmio_list)
drivers/gpu/drm/i915/i915_oa_perf.c err_size: · line 1704
Quoted 4 lines
drivers/gpu/drm/i915/i915_oa_perf.c +4
-0+if (!gen_attr->mmio_list[count]) +break ; + +for (i =0 ; i <ARRAY_SIZE (whitelist); i++, entry++) {
Interesting choice of continuation in the ABI. Seems a litte forced. Move the whitelist into the function, no one else should think of accessing it (right?), then just use whitelist[i].
drivers/gpu/drm/i915/i915_oa_perf.c err_size: · line 1706
Quoted 2 lines
drivers/gpu/drm/i915/i915_oa_perf.c +2
-0+ if (entry->offset == gen_attr->mmio_list[count] && + (1 << INTEL_INFO(dev_priv->dev)->gen &
dev_priv->dev->dev_priv->info, you have to be kidding me.
INTEL_INFO(dev_priv) is the natural form.
Quoted 14 lines
drivers/gpu/drm/i915/i915_oa_perf.c +10
-0+ entry->gen_bitmask)) +break ; + } + +if (i ==ARRAY_SIZE (whitelist)) +return -EINVAL ; + } +return 0 ; +} +static int i915_gen_event_init (struct perf_event *event) { struct drm_i915_private *dev_priv =
drivers/gpu/drm/i915/i915_oa_perf.c static int i915_gen_event_init(struct perf_event *event) · line 1746
Quoted 7 lines
drivers/gpu/drm/i915/i915_oa_perf.c +4
-0@@ -1674,6 +1740,17 @@ static int i915_gen_event_init(struct perf_event *event)if (gen_attr.sample_tag) dev_priv->gen_pmu.sample_info_flags |=I915_GEN_PMU_SAMPLE_TAG ; +if (gen_attr.sample_mmio) { + ret =check_mmio_whitelist (dev_priv, &gen_attr); +if (ret) +return ret;
Global hw state should only be inspectable by root (unless the system has relaxed perf permissions).
Quoted 23 lines
drivers/gpu/drm/i915/i915_oa_perf.c +6
-0+ dev_priv->gen_pmu.sample_info_flags |= +I915_GEN_PMU_SAMPLE_MMIO ; +memcpy (dev_priv->gen_pmu.mmio_list, gen_attr.mmio_list, +sizeof (dev_priv->gen_pmu.mmio_list)); + } +/* To avoid the complexity of having to accurately filter * data and marshal to the appropriate client * we currently only allow exclusive access */ include/uapi/drm/i915_drm.h +1
-1@@ -81,7 +81,7 @@#define I915_OA_ATTR_SIZE_VER0 32/* sizeof first published struct */ -#define I915_GEN_PMU_ATTR_SIZE_VER0 8/* sizeof first published struct */ +#define I915_GEN_PMU_ATTR_SIZE_VER0 40/* sizeof first published struct */ typedef struct _drm_i915_oa_attr { __u32 size;
include/uapi/drm/i915_drm.h struct drm_i915_gen_pmu_attr { · line 111
Quoted 8 lines
include/uapi/drm/i915_drm.h +3
-1@@ -105,7 +105,9 @@ struct drm_i915_gen_pmu_attr { __u32 sample_ring:1, sample_pid:1, sample_tag:1, - __reserved_1:29; + sample_mmio:1, + __reserved_1:28; +__u32 mmio_list[8 ]; };
seems like having aBUILD_BUG_ON(sizeof(struct _drm_i915_oa_attr) != I915_GEN_PMU_ATTR_SIZE_VER0) is in order. -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx