Framework to collect command stream gpu metrics using i915 perf
cover Framework to collect command stream gpu metrics using i915 perf
From: Sourab Gupta <[email protected]>
This series adds framework for collection of gpu performance metrics associated with the command stream of a particular engine. These metrics include OA reports, timestamps, mmio metrics, etc. These metrics are are collected around batchbuffer boundaries.
This work utilizes the underlying infrastructure introduced in Robert Bragg's patches for collecting periodic OA counter snapshots (based on Haswell):
https://lists.freedesktop.org/archives/intel-gfx/2016-April/093206.html
This patch set is based on Gen8+ version of Robert's patches which can be found
here: https://github.com/rib/linux/tree/wip/rib/oa-2016-05-05-nightly
These are not yet individually floated in the mailing list, which I hope doesn't lead to any significant loss of clarity in order to review the work proposed in this patch series.
Compared to last series I floated earlier,
(https://lists.freedesktop.org/archives/intel-gfx/2016-April/093645.html),
this series incorporates the following changes/fixes, besides rebasing on Robert's latest work (on a later nightly):
* Based on Chris's suggestion, I have tried experimenting with using the cross timestamp framework for the purpose of retrieving tightly coupled device/system timestamps. In our case, this framework enables us to have correlated pairs of gpu+system time which can be used over a period of time to correct the frequency of timestamp clock, and thus enable to accurately send system time (_MONO_RAW) as requested to the userspace. The results are generally observed to quite better with the use of cross timestamps and the frequency delta gradually tapers down to 0 with increasing correction periods. The use of cross timestamp framework though requires us to have clockcounter/timecounter abstraction for the timestamp clocksource, and further requires few changes in the kernel timekeeping/clocksource code. I am looking for feedback on the use of this framework and the changes involved.
These patches can be found for viewing at
https://github.com/sourabgu/linux/tree/oa-2016-05-05
Sourab Gupta (15):
drm/i915: Add ctx getparam ioctl parameter to retrieve ctx unique id drm/i915: Expose OA sample source to userspace
drm/i915: Framework for capturing command stream based OA reports drm/i915: flush periodic samples, in case of no pending CS sample
requests
drm/i915: Handle the overflow condition for command stream buf drm/i915: Populate ctx ID for periodic OA reports drm/i915: Add support for having pid output with OA report drm/i915: Add support for emitting execbuffer tags through OA counter
reports
drm/i915: Extend i915 perf framework for collecting timestamps on all
gpu engines
drm/i915: Extract raw GPU timestamps from OA reports to forward in
perf samples
drm/i915: Support opening multiple concurrent perf streams
time: Expose current clocksource in use by timekeeping framework
time: export clocks_calc_mult_shift
drm/i915: Mechanism to forward clock monotonic raw time in perf
samples
drm/i915: Support for capturing MMIO register values
drivers/gpu/drm/i915/i915_dma.c | 2 + drivers/gpu/drm/i915/i915_drv.h | 117 +- drivers/gpu/drm/i915/i915_gem_context.c | 3 + drivers/gpu/drm/i915/i915_gem_execbuffer.c | 5 + drivers/gpu/drm/i915/i915_perf.c | 1925 +++++++++++++++++++++++++--- drivers/gpu/drm/i915/i915_reg.h | 6 + drivers/gpu/drm/i915/intel_lrc.c | 4 + include/linux/timekeeping.h | 5 + include/uapi/drm/i915_drm.h | 79 ++ kernel/time/clocksource.c | 1 + kernel/time/timekeeping.c | 12 + 11 files changed, 1958 insertions(+), 201 deletions(-)
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 1/15 drm/i915: Add ctx getparam ioctl parameter to retrieve ctx unique id
From: Sourab Gupta <[email protected]>
This patch adds a new ctx getparam ioctl parameter, which can be used to retrieve ctx unique id by userspace.
This can be used by userspace to map the i915 perf samples with their particular ctx's, since those would be having ctx unique id's. Otherwise the userspace has no way of maintaining this association, since it has the knowledge of only per-drm file specific ctx handles.
--- drivers/gpu/drm/i915/i915_gem_context.c | 3 +++ include/uapi/drm/i915_drm.h | 1 + 2 files changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_gem_context.c +3 -0
@@ -1001,6 +1001,9 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,else args->value =to_i915 (dev)->ggtt.base.total;break ; +case I915_CONTEXT_PARAM_HW_ID : + args->value = ctx->hw_id; +break ;default : ret = -EINVAL ;break ;
include/uapi/drm/i915_drm.h +1 -0
@@ -1171,6 +1171,7 @@ struct drm_i915_gem_context_param {#define I915_CONTEXT_PARAM_BAN_PERIOD 0x1#define I915_CONTEXT_PARAM_NO_ZEROMAP 0x2#define I915_CONTEXT_PARAM_GTT_SIZE 0x3 +#define I915_CONTEXT_PARAM_HW_ID 0x4__u64 value; };
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 01/15] drm/i915: Add ctx getparam ioctl parameter to retrieve ctx unique id
Quoted 35 lines · On 06/02/2016 10:48 AM, [email protected] wrote:
From: Sourab Gupta <[email protected]>
This patch adds a new ctx getparam ioctl parameter, which can be used to retrieve ctx unique id by userspace.
This can be used by userspace to map the i915 perf samples with their particular ctx's, since those would be having ctx unique id's. Otherwise the userspace has no way of maintaining this association, since it has the knowledge of only per-drm file specific ctx handles.
Signed-off-by Sourab Gupta <[email protected]>--- drivers/gpu/drm/i915/i915_gem_context.c | 3 +++ include/uapi/drm/i915_drm.h | 1 + 2 files changed, 4 insertions(+)drivers/gpu/drm/i915/i915_gem_context.c +3
-0@@ -1001,6 +1001,9 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,else args->value =to_i915 (dev)->ggtt.base.total;break ; +case I915_CONTEXT_PARAM_HW_ID : + args->value = ctx->hw_id; +break ;default : ret = -EINVAL ;break ;include/uapi/drm/i915_drm.h +0
-0
include/uapi/drm/i915_drm.h struct drm_i915_gem_context_param { · line 1177
Quoted 7 lines
include/uapi/drm/i915_drm.h +1
-0@@ -1171,6 +1171,7 @@ struct drm_i915_gem_context_param {#define I915_CONTEXT_PARAM_BAN_PERIOD 0x1#define I915_CONTEXT_PARAM_NO_ZEROMAP 0x2#define I915_CONTEXT_PARAM_GTT_SIZE 0x3 +#define I915_CONTEXT_PARAM_HW_ID 0x4__u64 value; };
Patch looks good to me
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 01/15] drm/i915: Add ctx getparam ioctl parameter to retrieve ctx unique id
Quoted 47 lines · Deepak
Quoted 35 lines · On 06/02/2016 10:48 AM, [email protected] wrote:
From: Sourab Gupta <[email protected]>
This patch adds a new ctx getparam ioctl parameter, which can be used to retrieve ctx unique id by userspace.
This can be used by userspace to map the i915 perf samples with their particular ctx's, since those would be having ctx unique id's. Otherwise the userspace has no way of maintaining this association, since it has the knowledge of only per-drm file specific ctx handles.
Signed-off-by Sourab Gupta <[email protected]>--- drivers/gpu/drm/i915/i915_gem_context.c | 3 +++ include/uapi/drm/i915_drm.h | 1 + 2 files changed, 4 insertions(+)drivers/gpu/drm/i915/i915_gem_context.c +3
-0@@ -1001,6 +1001,9 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,else args->value =to_i915 (dev)->ggtt.base.total;break ; +case I915_CONTEXT_PARAM_HW_ID : + args->value = ctx->hw_id; +break ;default : ret = -EINVAL ;break ;include/uapi/drm/i915_drm.h +0
-0include/uapi/drm/i915_drm.h struct drm_i915_gem_context_param { · line 1176
Quoted 6 lines
include/uapi/drm/i915_drm.h +1
-0@@ -1171,6 +1171,7 @@ struct drm_i915_gem_context_param {#define I915_CONTEXT_PARAM_BAN_PERIOD 0x1#define I915_CONTEXT_PARAM_NO_ZEROMAP 0x2#define I915_CONTEXT_PARAM_GTT_SIZE 0x3 +#define I915_CONTEXT_PARAM_HW_ID 0x4__u64 value; };Patch looks good to me
Quoted 1 line
Reviewed-by Deepak S <[email protected]>
ctx->hw_id gets recycled without any involvement from userspace. How exactly is this supposed to work?
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 01/15] drm/i915: Add ctx getparam ioctl parameter to retrieve ctx unique id
Quoted 48 lines · Daniel Vetter
Quoted 47 lines · Deepak
Quoted 35 lines · On 06/02/2016 10:48 AM, [email protected] wrote:
From: Sourab Gupta <[email protected]>
This patch adds a new ctx getparam ioctl parameter, which can be used to retrieve ctx unique id by userspace.
This can be used by userspace to map the i915 perf samples with their particular ctx's, since those would be having ctx unique id's. Otherwise the userspace has no way of maintaining this association, since it has the knowledge of only per-drm file specific ctx handles.
Signed-off-by Sourab Gupta <[email protected]>--- drivers/gpu/drm/i915/i915_gem_context.c | 3 +++ include/uapi/drm/i915_drm.h | 1 + 2 files changed, 4 insertions(+)drivers/gpu/drm/i915/i915_gem_context.c +3
-0@@ -1001,6 +1001,9 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,else args->value =to_i915 (dev)->ggtt.base.total;break ; +case I915_CONTEXT_PARAM_HW_ID : + args->value = ctx->hw_id; +break ;default : ret = -EINVAL ;break ;include/uapi/drm/i915_drm.h +0
-0include/uapi/drm/i915_drm.h struct drm_i915_gem_context_param { · line 1176
Quoted 6 lines
include/uapi/drm/i915_drm.h +1
-0@@ -1171,6 +1171,7 @@ struct drm_i915_gem_context_param {#define I915_CONTEXT_PARAM_BAN_PERIOD 0x1#define I915_CONTEXT_PARAM_NO_ZEROMAP 0x2#define I915_CONTEXT_PARAM_GTT_SIZE 0x3 +#define I915_CONTEXT_PARAM_HW_ID 0x4__u64 value; };Patch looks good to me
Quoted 4 lines
Quoted 1 line
Reviewed-by Deepak S <[email protected]>
ctx->hw_idgets recycled without any involvement from userspace. How exactly is this supposed to work?
ctx->hw_id is invariant for the lifetime of the context (and so we limit the number of live contents to meet hw constraints, ~1 million). -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 01/15] drm/i915: Add ctx getparam ioctl parameter to retrieve ctx unique id
Quoted 49 lines · Chris Wilson
Quoted 48 lines · Daniel Vetter
Quoted 47 lines · Deepak
Quoted 35 lines · On 06/02/2016 10:48 AM, [email protected] wrote:
From: Sourab Gupta <[email protected]>
This patch adds a new ctx getparam ioctl parameter, which can be used to retrieve ctx unique id by userspace.
This can be used by userspace to map the i915 perf samples with their particular ctx's, since those would be having ctx unique id's. Otherwise the userspace has no way of maintaining this association, since it has the knowledge of only per-drm file specific ctx handles.
Signed-off-by Sourab Gupta <[email protected]>--- drivers/gpu/drm/i915/i915_gem_context.c | 3 +++ include/uapi/drm/i915_drm.h | 1 + 2 files changed, 4 insertions(+)drivers/gpu/drm/i915/i915_gem_context.c +3
-0@@ -1001,6 +1001,9 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,else args->value =to_i915 (dev)->ggtt.base.total;break ; +case I915_CONTEXT_PARAM_HW_ID : + args->value = ctx->hw_id; +break ;default : ret = -EINVAL ;break ;include/uapi/drm/i915_drm.h +0
-0include/uapi/drm/i915_drm.h struct drm_i915_gem_context_param { · line 1176
Quoted 6 lines
include/uapi/drm/i915_drm.h +1
-0@@ -1171,6 +1171,7 @@ struct drm_i915_gem_context_param {#define I915_CONTEXT_PARAM_BAN_PERIOD 0x1#define I915_CONTEXT_PARAM_NO_ZEROMAP 0x2#define I915_CONTEXT_PARAM_GTT_SIZE 0x3 +#define I915_CONTEXT_PARAM_HW_ID 0x4__u64 value; };Patch looks good to me
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Reviewed-by Deepak S <[email protected]>
ctx->hw_idgets recycled without any involvement from userspace. How exactly is this supposed to work?
ctx->hw_idis invariant for the lifetime of the context (and so we limit the number of live contents to meet hw constraints, ~1 million).
Argh, I was tricked by the comment in assign_hw_id - I thought it's talking about the hw_id only, not about the entire ctx. -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/15 drm/i915: Expose OA sample source to userspace
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch exposes a new sample source field to userspace. This field can be populated to specify the origin of the OA report.
For e.g. for internally triggerred reports (non MI_RPC reports), the RPT_ID field has bitfields for specifying the origin such as timer, or render ctx switch, etc.
Likewise this field can be used to specify the source as MI_RPC when such support is added.
--- drivers/gpu/drm/i915/i915_perf.c | 55 ++++++++++++++++++++++++++++++++++------ include/uapi/drm/i915_drm.h | 16 ++++++++++++ 2 files changed, 63 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/i915_perf.c +47 -8
@@ -74,6 +74,13 @@ static u32 i915_perf_stream_paranoid = true;*/ #define OA_EXPONENT_MAX 31 +#define GEN8_OAREPORT_REASON_TIMER (1<<19) +#define GEN8_OAREPORT_REASON_TRIGGER1 (1<<20) +#define GEN8_OAREPORT_REASON_TRIGGER2 (1<<21) +#define GEN8_OAREPORT_REASON_CTX_SWITCH (1<<22) +#define GEN8_OAREPORT_REASON_GO_TRANSITION (1<<23) +#define GEN9_OAREPORT_REASON_CLK_RATIO (1<<24) +/* for sysctl proc_dointvec_minmax of i915_oa_min_timer_exponent */ static int zero;static int oa_exponent_max =OA_EXPONENT_MAX ;
@@ -113,7 +120,8 @@ static struct i915_oa_format gen8_plus_oa_formats[I915_OA_FORMAT_MAX] = { [I915_OA_FORMAT_C4_B8] = { 7, 64 }, }; -#define SAMPLE_OA_REPORT (1<<0) +#define SAMPLE_OA_REPORT (1<<0) +#define SAMPLE_OA_SOURCE_INFO (1<<1)struct perf_open_properties {u32 sample_flags;
@@ -216,6 +224,27 @@ static int append_oa_sample(struct i915_perf_stream *stream,return -EFAULT ; buf +=sizeof (header); +if (sample_flags &SAMPLE_OA_SOURCE_INFO ) { +enum drm_i915_perf_oa_event_source source; + +if (INTEL_INFO (dev_priv)->gen >=8 ) { +u32 reason = *(u32 *)report; + +if (reason &GEN8_OAREPORT_REASON_CTX_SWITCH ) + source = +I915_PERF_OA_EVENT_SOURCE_CONTEXT_SWITCH ; +else if (reason &GEN8_OAREPORT_REASON_TIMER ) + source =I915_PERF_OA_EVENT_SOURCE_PERIODIC ; +else + source =I915_PERF_OA_EVENT_SOURCE_UNDEFINED ; + }else + source =I915_PERF_OA_EVENT_SOURCE_PERIODIC ; + +if (copy_to_user (buf, &source,4 )) +return -EFAULT ; + buf +=4 ; + } +if (sample_flags &SAMPLE_OA_REPORT ) {if (copy_to_user (buf, report, report_size))return -EFAULT ;
@@ -1170,11 +1199,6 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,int format_size;int ret; -if (!(props->sample_flags &SAMPLE_OA_REPORT )) { -DRM_ERROR ("Only OA report sampling supported\n" ); -return -EINVAL ; - } -if (!dev_priv->perf.oa.ops.init_oa_buffer) {DRM_ERROR ("OA unit not supported\n" );return -ENODEV ;
@@ -1203,8 +1227,20 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, format_size = dev_priv->perf.oa.oa_formats[props->oa_format].size; - stream->sample_flags |=SAMPLE_OA_REPORT ; - stream->sample_size += format_size; +if (props->sample_flags &SAMPLE_OA_REPORT ) { + stream->sample_flags |=SAMPLE_OA_REPORT ; + stream->sample_size += format_size; + } + +if (props->sample_flags &SAMPLE_OA_SOURCE_INFO ) { +if (!(props->sample_flags &SAMPLE_OA_REPORT )) { +DRM_ERROR ( +"OA source type can't be sampled without OA report" ); +return -EINVAL ; + } + stream->sample_flags |=SAMPLE_OA_SOURCE_INFO ; + stream->sample_size +=4 ; + } dev_priv->perf.oa.oa_buffer.format_size = format_size;BUG_ON (dev_priv->perf.oa.oa_buffer.format_size ==0 );
@@ -1842,6 +1878,9 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv, props->oa_periodic = true; props->oa_period_exponent = value;break ; +case DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE : + props->sample_flags |=SAMPLE_OA_SOURCE_INFO ; +break ;case DRM_I915_PERF_PROP_MAX :BUG (); }
include/uapi/drm/i915_drm.h +16 -0
@@ -1192,6 +1192,14 @@ enum drm_i915_oa_format {I915_OA_FORMAT_MAX /* non-ABI */ }; +enum drm_i915_perf_oa_event_source { +I915_PERF_OA_EVENT_SOURCE_UNDEFINED , +I915_PERF_OA_EVENT_SOURCE_PERIODIC , +I915_PERF_OA_EVENT_SOURCE_CONTEXT_SWITCH , + +I915_PERF_OA_EVENT_SOURCE_MAX /* non-ABI */ +}; +enum drm_i915_perf_property_id {/** * Open the stream for a specific context handle (as used with
@@ -1226,6 +1234,13 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_PROP_OA_EXPONENT , +/** +* The value of this property set to 1 requests inclusion of sample +* source field to be given to userspace. The sample source field +* specifies the origin of OA report. +*/ +DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
@@ -1290,6 +1305,7 @@ enum drm_i915_perf_record_type {* struct { * struct drm_i915_perf_record_header header; * +* { u32 source_info; } && DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE * { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA * }; */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/15 drm/i915: Framework for capturing command stream based OA reports
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch introduces a framework to enable OA counter reports associated with Render command stream. We can then associate the reports captured through this mechanism with their corresponding context id's. This can be further extended to associate any other metadata information with the corresponding samples (since the association with Render command stream gives us the ability to capture these information while inserting the corresponding capture commands into the command stream).
The OA reports generated in this way are associated with a corresponding workload, and thus can be used the delimit the workload (i.e. sample the counters at the workload boundaries), within an ongoing stream of periodic counter snapshots.
There may be usecases wherein we need more than periodic OA capture mode which is supported currently. This mode is primarily used for two usecases:
- Ability to capture system wide metrics, alongwith the ability to map the reports back to individual contexts (particularly for HSW).
- Ability to inject tags for work, into the reports. This provides visibility into the multiple stages of work within single context.
The userspace will be able to distinguish between the periodic and CS based OA reports by the virtue of source_info sample field.
The command MI_REPORT_PERF_COUNT can be used to capture snapshots of OA counters, and is inserted at BB boundaries.
The data thus captured will be stored in a separate buffer, which will be different from the buffer used otherwise for periodic OA capture mode. The metadata information pertaining to snapshot is maintained in a list, which also has offsets into the gem buffer object per captured snapshot. In order to track whether the gpu has completed processing the node, a field pertaining to corresponding gem request is added, which is tracked for completion of the command.
Both periodic and RCS based reports are associated with a single stream (corresponding to render engine), and it is expected to have the samples in the sequential order according to their timestamps. Now, since these reports are collected in separate buffers, these are merge sorted at the time of forwarding to userspace during the read call.
v2: Aligining with the non-perf interface (custom drm ioctl based). Also, few related patches are squashed together for better readability
--- drivers/gpu/drm/i915/i915_drv.h | 44 +- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 4 + drivers/gpu/drm/i915/i915_perf.c | 871 ++++++++++++++++++++++++----- drivers/gpu/drm/i915/intel_lrc.c | 4 + include/uapi/drm/i915_drm.h | 15 + 5 files changed, 804 insertions(+), 134 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +42 -2
@@ -1791,6 +1791,18 @@ struct i915_perf_stream_ops {* The stream will always be disabled before this is called. */ void (*destroy)(struct i915_perf_stream *stream); + +/* +* Routine to emit the commands in the command streamer associated +* with the corresponding gpu engine. +*/ +void (*command_stream_hook)(struct drm_i915_gem_request *req); +}; + +enum i915_perf_stream_state { +I915_PERF_STREAM_DISABLED , +I915_PERF_STREAM_ENABLE_IN_PROGRESS , +I915_PERF_STREAM_ENABLED , };struct i915_perf_stream {
@@ -1798,11 +1810,15 @@ struct i915_perf_stream {struct list_head link; +enum intel_engine_id engine;u32 sample_flags;int sample_size;struct intel_context *ctx; -bool enabled; +enum i915_perf_stream_state state; + +/* Whether command stream based data collection is enabled */ +bool cs_mode;const struct i915_perf_stream_ops *ops; };
@@ -1818,10 +1834,21 @@ struct i915_oa_ops { u32 ctx_id);void (*legacy_ctx_switch_unlocked)(struct drm_i915_gem_request *req);int (*read)(struct i915_perf_stream *stream, -struct i915_perf_read_state *read_state); +struct i915_perf_read_state *read_state,u32 ts);bool (*oa_buffer_is_empty)(struct drm_i915_private *dev_priv); }; +/* +* List element to hold info about the perf sample data associated +* with a particular GPU command stream. +*/ +struct i915_perf_cs_data_node { +struct list_head link; +struct drm_i915_gem_request *request; +u32 offset; +u32 ctx_id; +}; +struct drm_i915_private {struct drm_device *dev;struct kmem_cache *objects;
@@ -2107,6 +2134,8 @@ struct drm_i915_private {struct ctl_table_header *sysctl_header;struct mutex lock; + +struct mutex streams_lock;struct list_head streams;spinlock_t hook_lock;
@@ -2151,6 +2180,16 @@ struct drm_i915_private {const struct i915_oa_format *oa_formats;int n_builtin_sets; } oa; + +/* Command stream based perf data buffer */ +struct { +struct drm_i915_gem_object *obj; +struct i915_vma *vma; +u8 *addr; + } command_stream_buf; + +struct list_head node_list; +spinlock_t node_list_lock; } perf;/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
@@ -3513,6 +3552,7 @@ void i915_oa_legacy_ctx_switch_notify(struct drm_i915_gem_request *req);void i915_oa_update_reg_state (struct intel_engine_cs *engine,struct intel_context *ctx,uint32_t *reg_state); +void i915_perf_command_stream_hook (struct drm_i915_gem_request *req);/* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct drm_device *dev,
drivers/gpu/drm/i915/i915_gem_execbuffer.c +4 -0
@@ -1305,12 +1305,16 @@ i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params,if (exec_len ==0 ) exec_len = params->batch_obj->base.size; +i915_perf_command_stream_hook (params->request); + ret = engine->dispatch_execbuffer (params->request, exec_start, exec_len, params->dispatch_flags);if (ret)return ret; +i915_perf_command_stream_hook (params->request); +trace_i915_gem_ring_dispatch (params->request, params->dispatch_flags);i915_gem_execbuffer_move_to_active (vmas, params->request);
drivers/gpu/drm/i915/i915_perf.c +739 -132
1,191 lines not on this page · raw message
drivers/gpu/drm/i915/intel_lrc.c +4 -0
@@ -869,10 +869,14 @@ int intel_execlists_submission(struct i915_execbuffer_params *params, exec_start = params->batch_obj_vm_offset + args->batch_start_offset; +i915_perf_command_stream_hook (params->request); + ret = engine->emit_bb_start (params->request, exec_start, params->dispatch_flags);if (ret)return ret; +i915_perf_command_stream_hook (params->request); +trace_i915_gem_ring_dispatch (params->request, params->dispatch_flags);i915_gem_execbuffer_move_to_active (vmas, params->request);
include/uapi/drm/i915_drm.h +15 -0
@@ -1196,6 +1196,7 @@ enum drm_i915_perf_oa_event_source {I915_PERF_OA_EVENT_SOURCE_UNDEFINED ,I915_PERF_OA_EVENT_SOURCE_PERIODIC ,I915_PERF_OA_EVENT_SOURCE_CONTEXT_SWITCH , +I915_PERF_OA_EVENT_SOURCE_RCS , I915_PERF_OA_EVENT_SOURCE_MAX /* non-ABI */ };
@@ -1241,6 +1242,19 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE , +/** +* The value of this property specifies the GPU engine for which +* the samples need to be collected. Specifying this property also +* implies the command stream based sample collection. +*/ +DRM_I915_PERF_PROP_ENGINE , + +/** +* The value of this property set to 1 requests inclusion of context ID +* in the perf sample data. +*/ +DRM_I915_PERF_PROP_SAMPLE_CTX_ID , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
@@ -1306,6 +1320,7 @@ enum drm_i915_perf_record_type {* struct drm_i915_perf_record_header header; * * { u32 source_info; } && DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE +* { u32 ctx_id; } && DRM_I915_PERF_PROP_SAMPLE_CTX_ID * { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA * }; */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 03/15] drm/i915: Framework for capturing command stream based OA reports
Quoted 22 lines · On 02/06/16 08:18, [email protected] wrote:
From: Sourab Gupta <[email protected]>
This patch introduces a framework to enable OA counter reports associated with Render command stream. We can then associate the reports captured through this mechanism with their corresponding context id's. This can be further extended to associate any other metadata information with the corresponding samples (since the association with Render command stream gives us the ability to capture these information while inserting the corresponding capture commands into the command stream).
The OA reports generated in this way are associated with a corresponding workload, and thus can be used the delimit the workload (i.e. sample the counters at the workload boundaries), within an ongoing stream of periodic counter snapshots.
There may be usecases wherein we need more than periodic OA capture mode which is supported currently. This mode is primarily used for two usecases:
- Ability to capture system wide metrics, alongwith the ability to map the reports back to individual contexts (particularly for HSW).
- Ability to inject tags for work, into the reports. This provides visibility into the multiple stages of work within single context.
Quoted 5 lines
The userspace will be able to distinguish between the periodic and CS based OA reports by the virtue of
source_infosample field.The command
MI_REPORT_PERF_COUNTcan be used to capture snapshots of OA counters, and is inserted at BB boundaries.
So, it is possible to trigger a read of a set of counters (all?) from the pushbuffer buffer?
If so, I like this because I was wondering how would this work break when we move to the GuC-submission model.
Thanks for working on this!
Martin
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 03/15] drm/i915: Framework for capturing command stream based OA reports
Quoted 29 lines · Martin Peres
Quoted 22 lines · On 02/06/16 08:18, [email protected] wrote:
From: Sourab Gupta <[email protected]>
This patch introduces a framework to enable OA counter reports associated with Render command stream. We can then associate the reports captured through this mechanism with their corresponding context id's. This can be further extended to associate any other metadata information with the corresponding samples (since the association with Render command stream gives us the ability to capture these information while inserting the corresponding capture commands into the command stream).
The OA reports generated in this way are associated with a corresponding workload, and thus can be used the delimit the workload (i.e. sample the counters at the workload boundaries), within an ongoing stream of periodic counter snapshots.
There may be usecases wherein we need more than periodic OA capture mode which is supported currently. This mode is primarily used for two usecases:
- Ability to capture system wide metrics, alongwith the ability to map the reports back to individual contexts (particularly for HSW).
- Ability to inject tags for work, into the reports. This provides visibility into the multiple stages of work within single context.Quoted 5 lines
The userspace will be able to distinguish between the periodic and CS based OA reports by the virtue of
source_infosample field.The command
MI_REPORT_PERF_COUNTcan be used to capture snapshots of OA counters, and is inserted at BB boundaries.
Quoted 8 lines
So, it is possible to trigger a read of a set of counters (all?) from the pushbuffer buffer?
If so, I like this because I was wondering how would this work break when we move to the GuC-submission model.
Thanks for working on this!
Martin
Yeah, we can trigger the capture of counter snapshot using command MI_REPORT_PERF_COUNT inserted in the ringbuffer. The capture is initiated on encountering this command, at an address specified in the command arguments. The exact details of counters captured (report format etc.) depends on the OA unit configuration done earlier.
-Sourab
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/15 drm/i915: flush periodic samples, in case of no pending CS sample requests
In reply to [email protected]From: Sourab Gupta <[email protected]>
When there are no pending CS OA samples, flush the periodic OA samples collected so far.
We can safely forward the periodic OA samples in the case we have no pending CS samples, but we can't do so in the case we have pending CS samples, since we don't know what the ordering between pending CS samples and periodic samples will eventually be. If we have no pending CS sample, it won't be possible for future pending CS sample to have timestamps earlier than current periodic timestamp.
--- drivers/gpu/drm/i915/i915_drv.h | 14 ++-- drivers/gpu/drm/i915/i915_perf.c | 173 +++++++++++++++++++++++++++++---------- 2 files changed, 140 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +9 -5
@@ -1751,7 +1751,7 @@ struct i915_perf_stream_ops {/* Return: true if any i915 perf records are ready to read() * for this stream. */ -bool (*can_read)(struct i915_perf_stream *stream); +bool (*can_read_unlocked)(struct i915_perf_stream *stream);/* Call poll_wait, passing a wait queue that will be woken * once there is something ready to read() for the stream
@@ -1763,8 +1763,8 @@ struct i915_perf_stream_ops {/* For handling a blocking read, wait until there is something * to ready to read() for the stream. E.g. wait on the same * wait queue that would be passed to poll_wait() until -* ->can_read() returns true (if its safe to call ->can_read() -* without the i915 perf lock held). +* ->can_read_unlocked() returns true (if its safe to call +* ->can_read_unlocked() without the i915 perf lock held). */ int (*wait_unlocked)(struct i915_perf_stream *stream);
@@ -1834,8 +1834,10 @@ struct i915_oa_ops { u32 ctx_id);void (*legacy_ctx_switch_unlocked)(struct drm_i915_gem_request *req);int (*read)(struct i915_perf_stream *stream, -struct i915_perf_read_state *read_state,u32 ts); -bool (*oa_buffer_is_empty)(struct drm_i915_private *dev_priv); +struct i915_perf_read_state *read_state, +u32 ts,u32 max_records); +int (*oa_buffer_num_samples)(struct drm_i915_private *dev_priv, +u32 *last_ts); };/*
@@ -2175,6 +2177,8 @@ struct drm_i915_private {u32 gen7_latched_oastatus1;u32 ctx_oactxctrl_off;u32 ctx_flexeu0_off; +u32 n_pending_periodic_samples; +u32 pending_periodic_ts;struct i915_oa_ops ops;const struct i915_oa_format *oa_formats;
drivers/gpu/drm/i915/i915_perf.c +131 -42
358 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 5/15 drm/i915: Handle the overflow condition for command stream buf
In reply to [email protected]From: Sourab Gupta <[email protected]>
Add a compile time option for detecting the overflow condition of command stream buffer, and not overwriting the old entries in such a case. Also, set a status flag to forward the overflow condition to userspace if overflow is detected.
--- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_perf.c | 75 ++++++++++++++++++++++++++++++++-------- 2 files changed, 62 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -2190,6 +2190,8 @@ struct drm_i915_private {struct drm_i915_gem_object *obj;struct i915_vma *vma;u8 *addr; +#define I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW (1<<0) +u32 status; } command_stream_buf;struct list_head node_list;
drivers/gpu/drm/i915/i915_perf.c +60 -15
156 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 6/15 drm/i915: Populate ctx ID for periodic OA reports
In reply to [email protected]From: Sourab Gupta <[email protected]>
This adds support for populating the ctx id for the periodic OA reports when requested through the corresponding property.
For Gen8, the OA reports itself have the ctx ID and it is the one programmed into HW while submitting workloads. Thus it's retrieved from reports itself. For Gen7, the OA reports don't have any such field, and we can populate this field with the last seen ctx ID while sending CS reports.
--- drivers/gpu/drm/i915/i915_drv.h | 3 +++ drivers/gpu/drm/i915/i915_perf.c | 52 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +3 -0
@@ -1838,6 +1838,8 @@ struct i915_oa_ops { u32 ts, u32 max_records);int (*oa_buffer_num_samples)(struct drm_i915_private *dev_priv,u32 *last_ts); +u32 (*oa_buffer_get_ctx_id)(struct i915_perf_stream *stream, +const u8 *report); };/*
@@ -2194,6 +2196,7 @@ struct drm_i915_private {u32 status; } command_stream_buf; +u32 last_ctx_id;struct list_head node_list;spinlock_t node_list_lock; } perf;
drivers/gpu/drm/i915/i915_perf.c +49 -3
84 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 7/15 drm/i915: Add support for having pid output with OA report
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch introduces flags and adds support for having pid output with the OA reports generated through the RCS commands.
When the stream is opened with pid sample type, the pid information is also captured through the command stream samples and forwarded along with the OA reports.
--- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_perf.c | 48 +++++++++++++++++++++++++++++++++++++++- include/uapi/drm/i915_drm.h | 7 ++++++ 3 files changed, 56 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -1851,6 +1851,7 @@ struct i915_perf_cs_data_node {struct drm_i915_gem_request *request;u32 offset;u32 ctx_id; +u32 pid; };struct drm_i915_private {
@@ -2197,6 +2198,7 @@ struct drm_i915_private { } command_stream_buf;u32 last_ctx_id; +u32 last_pid;struct list_head node_list;spinlock_t node_list_lock; } perf;
drivers/gpu/drm/i915/i915_perf.c +47 -1
114 lines not on this page · raw message
include/uapi/drm/i915_drm.h +7 -0
@@ -1255,6 +1255,12 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_PROP_SAMPLE_CTX_ID , +/** +* The value of this property set to 1 requests inclusion of pid in the +* perf sample data. +*/ +DRM_I915_PERF_PROP_SAMPLE_PID , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
@@ -1321,6 +1327,7 @@ enum drm_i915_perf_record_type {* * { u32 source_info; } && DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE * { u32 ctx_id; } && DRM_I915_PERF_PROP_SAMPLE_CTX_ID +* { u32 pid; } && DRM_I915_PERF_PROP_SAMPLE_PID * { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA * }; */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 8/15 drm/i915: Add support for emitting execbuffer tags through OA counter reports
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 OA reports, to help associate reports 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 OA reports with their corresponding workloads(execbuffers), which may not be possible solely with ctx_id or pid information. This patch enables such a mechanism.
In this patch, upper 32 bits of rsvd1 field, which were previously unused are now being used to pass in the tag.
--- drivers/gpu/drm/i915/i915_drv.h | 7 ++++-- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 5 ++-- drivers/gpu/drm/i915/i915_perf.c | 38 ++++++++++++++++++++++++++---- drivers/gpu/drm/i915/intel_lrc.c | 4 ++-- include/uapi/drm/i915_drm.h | 12 ++++++++++ 5 files changed, 55 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +5 -2
@@ -1708,6 +1708,7 @@ struct i915_execbuffer_params {struct drm_i915_gem_object *batch_obj;struct intel_context *ctx;struct drm_i915_gem_request *request; +uint32_t tag; };/* used in computing the new watermarks state */
@@ -1796,7 +1797,7 @@ struct i915_perf_stream_ops {* Routine to emit the commands in the command streamer associated * with the corresponding gpu engine. */ -void (*command_stream_hook)(struct drm_i915_gem_request *req); +void (*command_stream_hook)(struct drm_i915_gem_request *req,u32 tag); };enum i915_perf_stream_state {
@@ -1852,6 +1853,7 @@ struct i915_perf_cs_data_node {u32 offset;u32 ctx_id;u32 pid; +u32 tag; };struct drm_i915_private {
@@ -2199,6 +2201,7 @@ struct drm_i915_private {u32 last_ctx_id;u32 last_pid; +u32 last_tag;struct list_head node_list;spinlock_t node_list_lock; } perf;
@@ -3563,7 +3566,7 @@ void i915_oa_legacy_ctx_switch_notify(struct drm_i915_gem_request *req);void i915_oa_update_reg_state (struct intel_engine_cs *engine,struct intel_context *ctx,uint32_t *reg_state); -void i915_perf_command_stream_hook (struct drm_i915_gem_request *req); +void i915_perf_command_stream_hook (struct drm_i915_gem_request *req,u32 tag);/* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct drm_device *dev,
drivers/gpu/drm/i915/i915_gem_execbuffer.c +3 -2
@@ -1305,7 +1305,7 @@ i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params,if (exec_len ==0 ) exec_len = params->batch_obj->base.size; -i915_perf_command_stream_hook (params->request); +i915_perf_command_stream_hook (params->request, params->tag); ret = engine->dispatch_execbuffer(params->request, exec_start, exec_len,
@@ -1313,7 +1313,7 @@ i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params,if (ret)return ret; -i915_perf_command_stream_hook (params->request); +i915_perf_command_stream_hook (params->request, params->tag);trace_i915_gem_ring_dispatch (params->request, params->dispatch_flags);
@@ -1634,6 +1634,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, params->batch_obj = batch_obj; params->ctx = ctx; params->request = req; + params->tag =i915_execbuffer2_get_tag (*args); ret = dev_priv->gt.execbuf_submit (params, args, &eb->vmas); err_request:
drivers/gpu/drm/i915/i915_perf.c +33 -5
@@ -89,6 +89,7 @@ struct oa_sample_data {u32 source;u32 ctx_id;u32 pid; +u32 tag;const u8 *report; };
@@ -145,6 +146,7 @@ static const enum intel_engine_id user_ring_map[I915_USER_RINGS + 1] = {#define SAMPLE_OA_SOURCE_INFO (1<<1)#define SAMPLE_CTX_ID (1<<2)#define SAMPLE_PID (1<<3) +#define SAMPLE_TAG (1<<4)struct perf_open_properties {u32 sample_flags;
@@ -169,7 +171,8 @@ struct perf_open_properties {* perf mutex lock. */ -void i915_perf_command_stream_hook (struct drm_i915_gem_request *request) +void i915_perf_command_stream_hook (struct drm_i915_gem_request *request, +u32 tag) {struct intel_engine_cs *engine = request->engine;struct drm_i915_private *dev_priv = engine->dev->dev_private;
@@ -182,7 +185,7 @@ void i915_perf_command_stream_hook(struct drm_i915_gem_request *request)list_for_each_entry (stream, &dev_priv->perf.streams, link) {if ((stream->state ==I915_PERF_STREAM_ENABLED ) && stream->cs_mode) - stream->ops->command_stream_hook (request); + stream->ops->command_stream_hook (request, tag); }mutex_unlock (&dev_priv->perf.streams_lock); }
@@ -296,7 +299,8 @@ out_unlock:return ret; } -static void i915_perf_command_stream_hook_oa (struct drm_i915_gem_request *req) +static void i915_perf_command_stream_hook_oa (struct drm_i915_gem_request *req, +u32 tag) {struct intel_engine_cs *engine = req->engine;struct intel_ringbuffer *ringbuf = req->ringbuf;
@@ -325,6 +329,7 @@ static void i915_perf_command_stream_hook_oa(struct drm_i915_gem_request *req) entry->ctx_id = ctx->hw_id; entry->pid = current->pid; + entry->tag = tag;i915_gem_request_assign (&entry->request, req); addr = dev_priv->perf.command_stream_buf.vma->node.start +
@@ -591,6 +596,12 @@ static int append_oa_sample(struct i915_perf_stream *stream, buf +=4 ; } +if (sample_flags &SAMPLE_TAG ) { +if (copy_to_user (buf, &data->tag,4 )) +return -EFAULT ; + buf +=4 ; + } +if (sample_flags &SAMPLE_OA_REPORT ) {if (copy_to_user (buf, data->report, report_size))return -EFAULT ;
@@ -636,6 +647,9 @@ static int append_oa_buffer_sample(struct i915_perf_stream *stream,if (sample_flags &SAMPLE_PID ) data.pid = dev_priv->perf.last_pid; +if (sample_flags &SAMPLE_TAG ) + data.tag = dev_priv->perf.last_tag; +if (sample_flags &SAMPLE_OA_REPORT ) data.report = report;
@@ -1109,6 +1123,11 @@ static int append_oa_rcs_sample(struct i915_perf_stream *stream, dev_priv->perf.last_pid = node->pid; } +if (sample_flags &SAMPLE_TAG ) { + data.tag = node->tag; + dev_priv->perf.last_tag = node->tag; + } +if (sample_flags &SAMPLE_OA_REPORT ) data.report = report;
@@ -1890,7 +1909,8 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,struct drm_i915_private *dev_priv = stream->dev_priv;bool require_oa_unit = props->sample_flags & (SAMPLE_OA_REPORT |SAMPLE_OA_SOURCE_INFO ); -bool require_cs_mode = props->sample_flags &SAMPLE_PID ; +bool require_cs_mode = props->sample_flags & (SAMPLE_PID | +SAMPLE_TAG );bool cs_sample_data = props->sample_flags &SAMPLE_OA_REPORT ;int ret;
@@ -2034,7 +2054,7 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, }if (require_cs_mode && !props->cs_mode) { -DRM_ERROR ("PID sampling requires a ring to be specified" ); +DRM_ERROR ("PID or TAG sampling require a ring to be specified" ); ret = -EINVAL ; goto cs_error; }
@@ -2067,6 +2087,11 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, stream->sample_size +=4 ; } +if (props->sample_flags &SAMPLE_TAG ) { + stream->sample_flags |=SAMPLE_TAG ; + stream->sample_size +=4 ; + } + ret =alloc_command_stream_buf (dev_priv);if (ret) goto cs_error;
@@ -2707,6 +2732,9 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv,case DRM_I915_PERF_PROP_SAMPLE_PID : props->sample_flags |=SAMPLE_PID ;break ; +case DRM_I915_PERF_PROP_SAMPLE_TAG : + props->sample_flags |=SAMPLE_TAG ; +break ;case DRM_I915_PERF_PROP_MAX :BUG (); }
drivers/gpu/drm/i915/intel_lrc.c +2 -2
@@ -869,13 +869,13 @@ int intel_execlists_submission(struct i915_execbuffer_params *params, exec_start = params->batch_obj_vm_offset + args->batch_start_offset; -i915_perf_command_stream_hook (params->request); +i915_perf_command_stream_hook (params->request, params->tag); ret = engine->emit_bb_start (params->request, exec_start, params->dispatch_flags);if (ret)return ret; -i915_perf_command_stream_hook (params->request); +i915_perf_command_stream_hook (params->request, params->tag);trace_i915_gem_ring_dispatch (params->request, params->dispatch_flags);
include/uapi/drm/i915_drm.h +12 -0
@@ -796,6 +796,11 @@ struct drm_i915_gem_execbuffer2 {#define i915_execbuffer2_get_context_id (eb2) \ ((eb2).rsvd1 & I915_EXEC_CONTEXT_ID_MASK) +/* upper 32 bits of rsvd1 field contain tag */ +#define I915_EXEC_TAG_MASK (0xffffffff00000000UL) +#define i915_execbuffer2_get_tag (eb2) \ + ((eb2).rsvd1 & I915_EXEC_TAG_MASK) +struct drm_i915_gem_pin {/** Handle of the buffer to be pinned. */ __u32 handle;
@@ -1261,6 +1266,12 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_PROP_SAMPLE_PID , +/** +* The value of this property set to 1 requests inclusion of tag in the +* perf sample data. +*/ +DRM_I915_PERF_PROP_SAMPLE_TAG , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
@@ -1328,6 +1339,7 @@ enum drm_i915_perf_record_type {* { u32 source_info; } && DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE * { u32 ctx_id; } && DRM_I915_PERF_PROP_SAMPLE_CTX_ID * { u32 pid; } && DRM_I915_PERF_PROP_SAMPLE_PID +* { u32 tag; } && DRM_I915_PERF_PROP_SAMPLE_TAG * { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA * }; */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 9/15 drm/i915: Extend i915 perf framework for collecting timestamps on all gpu engines
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch extends the i915 perf framework to handle the perf sample collection for any given gpu engine. Particularly, the support for collecting timestamp sample type is added, which can be requested for any engine.
With this, for RCS, timestamps and OA reports can be collected together, and provided to userspace in separate sample fields. For other engines, the capabilility to collect timestamps is added.
The thing to note is that, still only a single stream instance can be opened at any particular time. Though that stream may now be opened for any gpu engine, for collection of timestamp samples.
So, this patch doesn't add the support to open multiple concurrent streams, as yet. Though it lays the groundwork for this support to be added susequently. Part of this groundwork involves having separate command stream buffers, per engine, for holding the samples generated. Likewise for a few other data structures maintaining per-engine state.
--- drivers/gpu/drm/i915/i915_drv.h | 32 +- drivers/gpu/drm/i915/i915_perf.c | 648 ++++++++++++++++++++++++++------------- drivers/gpu/drm/i915/i915_reg.h | 2 + include/uapi/drm/i915_drm.h | 7 + 4 files changed, 465 insertions(+), 224 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +22 -10
@@ -1797,7 +1797,8 @@ struct i915_perf_stream_ops {* Routine to emit the commands in the command streamer associated * with the corresponding gpu engine. */ -void (*command_stream_hook)(struct drm_i915_gem_request *req,u32 tag); +void (*command_stream_hook)(struct i915_perf_stream *stream, +struct drm_i915_gem_request *req,u32 tag); };enum i915_perf_stream_state {
@@ -1821,6 +1822,9 @@ struct i915_perf_stream {/* Whether command stream based data collection is enabled */ bool cs_mode; +/* Whether the OA unit is in use */ +bool using_oa; +const struct i915_perf_stream_ops *ops; };
@@ -1850,7 +1854,16 @@ struct i915_oa_ops {struct i915_perf_cs_data_node {struct list_head link;struct drm_i915_gem_request *request; -u32 offset; + +/* Offsets into the GEM obj holding the data */ +u32 start_offset; +u32 oa_offset; +u32 ts_offset; + +/* buffer size corresponding to this entry */ +u32 size; + +/* Other metadata */ u32 ctx_id;u32 pid;u32 tag;
@@ -2147,14 +2160,13 @@ struct drm_i915_private {spinlock_t hook_lock; -struct { -struct i915_perf_stream *exclusive_stream; +struct hrtimer poll_check_timer; +struct i915_perf_stream *exclusive_stream; +wait_queue_head_t poll_wq[I915_NUM_ENGINES ]; +struct {u32 specific_ctx_id; -struct hrtimer poll_check_timer; -wait_queue_head_t poll_wq; -bool periodic;int period_exponent;int timestamp_frequency;
@@ -2197,13 +2209,13 @@ struct drm_i915_private {u8 *addr;#define I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW (1<<0)u32 status; - } command_stream_buf; + } command_stream_buf[I915_NUM_ENGINES ];u32 last_ctx_id;u32 last_pid;u32 last_tag; -struct list_head node_list; -spinlock_t node_list_lock; +struct list_head node_list[I915_NUM_ENGINES ]; +spinlock_t node_list_lock[I915_NUM_ENGINES ]; } perf;/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
drivers/gpu/drm/i915/i915_perf.c +434 -214
1,157 lines not on this page · raw message
drivers/gpu/drm/i915/i915_reg.h +2 -0
@@ -410,6 +410,7 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)#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)
@@ -491,6 +492,7 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)#define PIPE_CONTROL_TLB_INVALIDATE (1<<18)#define PIPE_CONTROL_MEDIA_STATE_CLEAR (1<<16)#define PIPE_CONTROL_QW_WRITE (1<<14) +#define PIPE_CONTROL_TIMESTAMP_WRITE (3<<14)#define PIPE_CONTROL_POST_SYNC_OP_MASK (3<<14)#define PIPE_CONTROL_DEPTH_STALL (1<<13)#define PIPE_CONTROL_WRITE_FLUSH (1<<12)
include/uapi/drm/i915_drm.h +7 -0
@@ -1272,6 +1272,12 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_PROP_SAMPLE_TAG , +/** +* The value of this property set to 1 requests inclusion of timestamp +* in the perf sample data. +*/ +DRM_I915_PERF_PROP_SAMPLE_TS , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
@@ -1340,6 +1346,7 @@ enum drm_i915_perf_record_type {* { u32 ctx_id; } && DRM_I915_PERF_PROP_SAMPLE_CTX_ID * { u32 pid; } && DRM_I915_PERF_PROP_SAMPLE_PID * { u32 tag; } && DRM_I915_PERF_PROP_SAMPLE_TAG +* { u64 timestamp; } && DRM_I915_PERF_PROP_SAMPLE_TS * { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA * }; */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 10/15 drm/i915: Extract raw GPU timestamps from OA reports to forward in perf samples
In reply to [email protected]From: Sourab Gupta <[email protected]>
The OA reports contain the least significant 32 bits of the gpu timestamp. This patch enables retrieval of the timestamp field from OA reports, to forward as 64 bit raw gpu timestamps in the perf samples.
--- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_perf.c | 46 ++++++++++++++++++++++++++++++---------- drivers/gpu/drm/i915/i915_reg.h | 4 ++++ 3 files changed, 40 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +1 -0
@@ -2196,6 +2196,7 @@ struct drm_i915_private {u32 ctx_flexeu0_off;u32 n_pending_periodic_samples;u32 pending_periodic_ts; +u64 last_gpu_ts;struct i915_oa_ops ops;const struct i915_oa_format *oa_formats;
drivers/gpu/drm/i915/i915_perf.c +35 -11
89 lines not on this page · raw message
drivers/gpu/drm/i915/i915_reg.h +4 -0
@@ -591,6 +591,10 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)#define PS_DEPTH_COUNT _MMIO(0x2350)#define PS_DEPTH_COUNT_UDW _MMIO(0x2350 + 4) +/* Timestamp count register */ +#define GT_TIMESTAMP_COUNT _MMIO(0x2358) +#define GT_TIMESTAMP_COUNT_UDW _MMIO(0x2358 + 4) +/* There are the 4 64-bit counter registers, one for each stream output */ #define GEN7_SO_NUM_PRIMS_WRITTEN (n) _MMIO(0x5200 + (n) * 8)#define GEN7_SO_NUM_PRIMS_WRITTEN_UDW (n) _MMIO(0x5200 + (n) * 8 + 4)
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 11/15 drm/i915: Support opening multiple concurrent perf streams
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch adds support for opening multiple concurrent perf streams for different gpu engines, while having the restriction to open only a single stream open for a particular gpu engine.
This enables userspace client to open multiple streams, one per engine, at any time to capture sample data for multiple gpu engines.
--- drivers/gpu/drm/i915/i915_drv.h | 2 +- drivers/gpu/drm/i915/i915_perf.c | 69 ++++++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +1 -1
@@ -2161,7 +2161,7 @@ struct drm_i915_private {spinlock_t hook_lock;struct hrtimer poll_check_timer; -struct i915_perf_stream *exclusive_stream; +struct i915_perf_stream *ring_stream[I915_NUM_ENGINES ];wait_queue_head_t poll_wq[I915_NUM_ENGINES ];struct {
drivers/gpu/drm/i915/i915_perf.c +38 -31
153 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 12/15 time: Expose current clocksource in use by timekeeping framework
In reply to [email protected]From: Sourab Gupta <[email protected]>
For the drivers to be able to use the cross timestamp framework, they need the information of current clocksource being used by the kernel timekeeping. This is needed since the callback given by driver into the get_device_system_crosststamp(), in order to synchronously read the device time and system counter value, requires the knowledge of the clocksource being used to read system counter value (as a part of struct system_counterval_t).
--- include/linux/timekeeping.h | 5 +++++ kernel/time/timekeeping.c | 12 ++++++++++++ 2 files changed, 17 insertions(+)
include/linux/timekeeping.h +5 -0
@@ -320,6 +320,11 @@ extern int get_device_system_crosststamp( struct system_device_crosststamp *xtstamp);/* +* Get current clocksource used by system timekeeping framework +*/ +struct clocksource *get_current_clocksource (void ); + +/* * Simultaneously snapshot realtime and monotonic raw clocks */ extern void ktime_get_snapshot (struct system_time_snapshot *systime_snapshot);
kernel/time/timekeeping.c +12 -0
@@ -1133,6 +1133,18 @@ int get_device_system_crosststamp(int (*get_time_fn)EXPORT_SYMBOL_GPL (get_device_system_crosststamp);/** +* get_current_clocksource - Returns the current clocksource in used by tk_core +* +*/ +struct clocksource *get_current_clocksource (void ) +{ +struct timekeeper *tk = &tk_core.timekeeper; + +return tk->tkr_mono.clock; +} +EXPORT_SYMBOL_GPL (get_current_clocksource); + +/** * do_gettimeofday - Returns the time of day in a timeval * @tv: pointer to the timeval to be set *
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 13/15 time: export clocks_calc_mult_shift
In reply to [email protected]From: Sourab Gupta <[email protected]>
Exporting clocks_calc_mult_shift is helpful for drivers to calculate the mult/shift values for their clocks, given their frequency. This is particularly useful when such drivers may want to associate timecounter/cyclecounter abstraction for their clock sources, in order to use the cross timestamp infrastructure for syncing device time with system time.
--- kernel/time/clocksource.c | 1 + 1 file changed, 1 insertion(+)
kernel/time/clocksource.c +1 -0
@@ -89,6 +89,7 @@ clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 maxsec) *mult = tmp; *shift = sft; } +EXPORT_SYMBOL_GPL (clocks_calc_mult_shift);/*[Clocksource internal variables]--------- * curr_clocksource:
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 14/15 drm/i915: Mechanism to forward clock monotonic raw time in perf samples
In reply to [email protected]From: Sourab Gupta <[email protected]>
Currently, we have the ability to only forward the GPU timestamps in the samples (which are generated via OA reports or PIPE_CONTROL commands inserted in the ring). This limits the ability to correlate these samples with the system events. If we scale the GPU timestamps according the timestamp base/frequency info present in bspec, it is observed that the timestamps drift really quickly from the system time.
An ability is therefore needed to report timestamps in different clock domains, such as CLOCK_MONOTONIC (or _MONO_RAW), in the perf samples to be of more practical use to the userspace. This ability becomes important when we want to correlate/plot GPU events/samples with other system events on the same timeline (e.g. vblank events, or timestamps when work was submitted to kernel, etc.)
The patch here proposes a mechanism to achieve this. The correlation between gpu time and system time is established using the cross timestamp framework. For this purpose, the timestamp clock associated with the command stream, is abstracted as timecounter/cyclecounter, before utilizing cross timestamp framework to retrieve gpu/system time correlated values. Different such gpu/system time values are then used to detect and correct the error in published gpu timestamp clock frequency. The userspace can request CLOCK_MONOTONIC_RAW timestamps in samples by requesting the corresponding property while opening the stream.
--- drivers/gpu/drm/i915/i915_dma.c | 2 + drivers/gpu/drm/i915/i915_drv.h | 24 +++- drivers/gpu/drm/i915/i915_perf.c | 273 +++++++++++++++++++++++++++++++++++---- include/uapi/drm/i915_drm.h | 9 +- 4 files changed, 284 insertions(+), 24 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +2 -0
@@ -1327,6 +1327,8 @@ static int i915_driver_init_hw(struct drm_i915_private *dev_priv)DRM_DEBUG_DRIVER ("can't enable MSI" ); } +i915_perf_init_late (dev_priv); +return 0 ; out_ggtt:
drivers/gpu/drm/i915/i915_drv.h +23 -1
@@ -42,6 +42,9 @@#include <linux/kref.h> #include <linux/pm_qos.h> #include <linux/shmem_fs.h> +#include <linux/timecounter.h> +#include <linux/clocksource.h> +#include <linux/timekeeping.h> #include <drm/drmP.h> #include <drm/intel-gtt.h>
@@ -1825,6 +1828,9 @@ struct i915_perf_stream {/* Whether the OA unit is in use */ bool using_oa; +/* monotonic_raw clk timestamp (in ns) for last sample */ +u64 last_sample_ts; +const struct i915_perf_stream_ops *ops; };
@@ -1869,6 +1875,20 @@ struct i915_perf_cs_data_node {u32 tag; }; +/** +* struct i915_clock_info - decribes i915 timestamp clock +* +*/ +struct i915_clock_info { +struct cyclecounter cc; +struct timecounter tc; +struct system_device_crosststamp xtstamp; +ktime_t clk_offset;/* Offset (in ns) between monoraw clk and gpu time */ +u32 timestamp_frequency; +u32 resync_period;/* in msecs */ +struct delayed_work clk_sync_work; +}; +struct drm_i915_private {struct drm_device *dev;struct kmem_cache *objects;
@@ -2147,6 +2167,8 @@ struct drm_i915_private {struct i915_runtime_pm pm; +struct i915_clock_info ts_clk_info; +struct {bool initialized;
@@ -2169,7 +2191,6 @@ struct drm_i915_private {bool periodic;int period_exponent; -int timestamp_frequency;int tail_margin;
@@ -3699,6 +3720,7 @@ int i915_parse_cmds(struct intel_engine_cs *engine,/* i915_perf.c */ extern void i915_perf_init (struct drm_device *dev); +extern void i915_perf_init_late (struct drm_i915_private *dev_priv);extern void i915_perf_fini (struct drm_device *dev);/* i915_suspend.c */
drivers/gpu/drm/i915/i915_perf.c +251 -22
448 lines not on this page · raw message
include/uapi/drm/i915_drm.h +8 -1
@@ -1278,6 +1278,12 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_PROP_SAMPLE_TS , +/** +* This property requests inclusion of CLOCK_MONOTONIC system time in +* the perf sample data. +*/ +DRM_I915_PERF_PROP_SAMPLE_CLOCK_MONOTONIC_RAW , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
@@ -1346,7 +1352,8 @@ enum drm_i915_perf_record_type {* { u32 ctx_id; } && DRM_I915_PERF_PROP_SAMPLE_CTX_ID * { u32 pid; } && DRM_I915_PERF_PROP_SAMPLE_PID * { u32 tag; } && DRM_I915_PERF_PROP_SAMPLE_TAG -* { u64 timestamp; } && DRM_I915_PERF_PROP_SAMPLE_TS +* { u64 gpu_ts; } && DRM_I915_PERF_PROP_SAMPLE_TS +* { u64 clk_mono; } && DRM_I915_PERF_PROP_SAMPLE_CLOCK_MONOTONIC * { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA * }; */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 15/15 drm/i915: Support for capturing MMIO register values
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch adds support for capturing MMIO register values through i915 perf interface.
The userspace can request upto 8 MMIO register values to be dumped. The addresses of these registers can be passed through the corresponding property 'value' field while opening the stream.
The commands to dump the values of these MMIO registers are then inserted into the ring alongwith other commands.
--- drivers/gpu/drm/i915/i915_drv.h | 4 + drivers/gpu/drm/i915/i915_perf.c | 173 ++++++++++++++++++++++++++++++++++++++- include/uapi/drm/i915_drm.h | 14 ++++ 3 files changed, 188 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +4 -0
@@ -1865,6 +1865,7 @@ struct i915_perf_cs_data_node {u32 start_offset;u32 oa_offset;u32 ts_offset; +u32 mmio_offset;/* buffer size corresponding to this entry */ u32 size;
@@ -2186,6 +2187,9 @@ struct drm_i915_private {struct i915_perf_stream *ring_stream[I915_NUM_ENGINES ];wait_queue_head_t poll_wq[I915_NUM_ENGINES ]; +u32 num_mmio; +u32 mmio_list[I915_PERF_MMIO_NUM_MAX ]; +struct {u32 specific_ctx_id;
drivers/gpu/drm/i915/i915_perf.c +170 -3
265 lines not on this page · raw message
include/uapi/drm/i915_drm.h +14 -0
@@ -1206,6 +1206,12 @@ enum drm_i915_perf_oa_event_source {I915_PERF_OA_EVENT_SOURCE_MAX /* non-ABI */ }; +#define I915_PERF_MMIO_NUM_MAX 8 +struct drm_i915_perf_mmio_list { +__u32 num_mmio; +__u32 mmio_list[I915_PERF_MMIO_NUM_MAX ]; +}; +enum drm_i915_perf_property_id {/** * Open the stream for a specific context handle (as used with
@@ -1284,6 +1290,13 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_PROP_SAMPLE_CLOCK_MONOTONIC_RAW , +/** +* This property requests inclusion of mmio register values in the perf +* sample data. The value of this property specifies the address of user +* struct having the register addresses. +*/ +DRM_I915_PERF_PROP_SAMPLE_MMIO , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
@@ -1354,6 +1367,7 @@ enum drm_i915_perf_record_type {* { u32 tag; } && DRM_I915_PERF_PROP_SAMPLE_TAG * { u64 gpu_ts; } && DRM_I915_PERF_PROP_SAMPLE_TS * { u64 clk_mono; } && DRM_I915_PERF_PROP_SAMPLE_CLOCK_MONOTONIC +* { u32 mmio[]; } && DRM_I915_PERF_PROP_SAMPLE_MMIO * { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA * }; */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Ro.CI.BAT: failure for Framework to collect command stream gpu metrics using i915 perf (rev2)
In reply to [email protected]== Series Details ==
== Series Details ==
Series: Framework to collect command stream gpu metrics using i915 perf (rev2)
URL : https://patchwork.freedesktop.org/series/6154/
State : failure
== Summary ==
Applying: drm/i915: Add ctx getparam ioctl parameter to retrieve ctx unique id
Applying: drm/i915: Expose OA sample source to userspace
fatal: sha1 information is lacking or useless (drivers/gpu/drm/i915/i915_perf.c).
error: could not build fake ancestor
Patch failed at 0002 drm/i915: Expose OA sample source to userspace The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx