Framework to collect gpu metrics using i915 perf infrastructure
Subsystems (3)
cover Framework to collect gpu metrics using i915 perf infrastructure
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-February/086909.html
This patch set is based on Gen8+ version of Robert's patch series, which can be found here: https://github.com/rib/linux/tree/wip/rib/oa-next
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 sent earlier, this series is based on drm i915 ioctl based implementation ( which can be referred to, in Robert's work). As such, the design has been changed (and simplified) due to some earlier core perf assumptions going away.
Few salient features are listed below:
* Ability to collect command stream based OA reports on render engine, in conjunction with the periodic reports generated with the OA unit. These would be collected in seperate buffers and forwarded to userspace in the respective timestamp order. The samples are differentiated in userspace by distinguishing the value of OA sample source field.
* Ability to collect timestamps and mmio metrics, associated with command stream of any particular gpu engine. The particular sample metrics to be collected are requested by userspace client in the properties associated with the stream being opened. The samples generated depend on original sample flags requested in the stream properties.
* Ability to collect associated metadata information with the samples such as pid, tags, etc. These are collected at the time of inserting the commands into the command stream of particular gpu engine, and forwarded along with samples
* Multiple streams belonging to different engines can be opened concurrently (while restricting only one instance of open stream per engine). This allows us to open simultaneously streams belonging to different gpu engines to collect samples belonging to all of them concurrently.
* The different stages of a single workload (belonging to a single context) can be delimited by using 'execbuffer tagging' mechanism introduced here. For e.g. for the media pipeline, CodecHAL encoding stage has a single context and involves multiple stages such as Scaling, ME, MBEnc, PAK for which there are separate execbuffer calls. There is a need to have the samples generated to have such information, so as to be able to associate them with the particular workload stage. The presence of a tag sample_type, which is passed in by userspace during execbuffer ioctl fulfills this requirement.
I am looking for feedback on the design proposed here, particularly pertaining to the mechanics of metrics collection through insertion of commands in the command stream of associated gpu engines, sample generation according to the requested sample flags in stream properties, concurrent operation of different streams to collect the samples from multiple gpu engines, and any such design/implementation aspects per se.
Few open issues which I'm working on include:
* In case both timestamp and OA sample type are requested for render engine, the ts information should be able to be derived from OA report only, and we should not need to insert seperate commands for dumping timestamps. Though, we need to apply relevant timestamp base conversion for converting from OA timestamps into ns.
* The sample consistency has to be maintained between the periodic OA reports and the ones generated by command stream. This implies, for e.g., that if pid sample_type is requested, the most recent pid collected in the CS samples should be used to populate the relevant field in the periodic samples. Likewise, the field 'ctx_id' needs to be deduced from the periodic OA reports and mapped to 'intel_context::global_id', for periodic OA reports.
These open issues, though, shouldn't be distracting us too much from reviewing the general mechanism proposed here, and these can be ironed out subsequently, if there's a general agreement on the design here.
Also, one of the pre-requisite for this work is presence of globally unique id associated with each context. The present context id is specific to drm fd, and as such, it can't uniquely be used to associate the reports generated with the corresponding context scheduled from userspace in a global way. The first few patches in the series introduce the globally unique context id, and subsequent ones introduce the framework for collection of metrics.
Robert Bragg (2):
drm/i915: Constrain intel_context::global_id to 20 bits drm/i915: return ctx->global_id from intel_execlists_ctx_id()
Sourab Gupta (9):
drm/i915: Introduce global id for contexts
drm/i915: Add ctx getparam ioctl parameter to retrieve ctx global id drm/i915: Expose OA sample source to userspace
drm/i915: Framework for capturing command stream based OA reports drm/i915: Add support for having pid output with OA report drm/i915: Add support to add execbuffer tags to OA counter reports drm/i915: Extend i915 perf framework for collecting timestamps on all
gpu engines
drm/i915: Support opening multiple concurrent perf streams drm/i915: Support for capturing MMIO register values
drivers/gpu/drm/i915/i915_debugfs.c | 7 +- drivers/gpu/drm/i915/i915_drv.h | 68 +- drivers/gpu/drm/i915/i915_gem_context.c | 23 + drivers/gpu/drm/i915/i915_gem_execbuffer.c | 5 + drivers/gpu/drm/i915/i915_perf.c | 1300 +++++++++++++++++++++++++--- drivers/gpu/drm/i915/i915_reg.h | 2 + drivers/gpu/drm/i915/intel_lrc.c | 26 +- drivers/gpu/drm/i915/intel_lrc.h | 2 +- include/uapi/drm/i915_drm.h | 72 ++ 9 files changed, 1349 insertions(+), 156 deletions(-)
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 1/11 drm/i915: Introduce global id for contexts
From: Sourab Gupta <[email protected]>
The current context user handles are specific to drm file instance. There are some usecases, which may require a global id for the contexts. For e.g. a system level GPU profiler tool may lean upon the global context ids to associate the performance snapshots with individual contexts.
This global id may also be used further in order to provide a unique context id to hw.
In this patch, the global ids are allocated from a separate cyclic idr and can be further utilized for any usecase described above.
v2: According to Chris' suggestion, implemented a separate idr for holding global ids for contexts, as opposed to overloading the file specific ctx->user_handle for this purpose. This global id can also further be used wherever hw has to be programmed with ctx unique id, though this patch just introduces the hw global id as such.
--- drivers/gpu/drm/i915/i915_drv.h | 3 +++ drivers/gpu/drm/i915/i915_gem_context.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +3 -0
@@ -875,6 +875,7 @@ struct i915_ctx_hang_stats {struct intel_context {struct kref ref;int user_handle; +int global_id;uint8_t remap_slice;struct drm_i915_private *i915;int flags;
@@ -1868,6 +1869,8 @@ struct drm_i915_private {bool preserve_bios_swizzle; +struct idr global_ctx_idr; +/* overlay */ struct intel_overlay *overlay;
drivers/gpu/drm/i915/i915_gem_context.c +21 -0
@@ -256,6 +256,18 @@ __create_hw_context(struct drm_device *dev, ctx->file_priv = file_priv; ctx->user_handle = ret; + +/* TODO: If required, this global id can be used for programming the hw +* fields too. In that case, we'll have take care of hw restrictions +* while allocating idr. e.g. for some hw, we may not have full 32 bits +* available. +*/ + ret =idr_alloc_cyclic (&dev_priv->global_ctx_idr, + ctx,0 ,0 ,GFP_KERNEL ); +if (ret <0 ) + goto err_out; + + ctx->global_id = ret;/* NB: Mark all slices as needing a remap so that when the context first * loads it will restore whatever remap state already exists. If there * is no remap info, it will be a NOP. */
@@ -280,6 +292,7 @@ i915_gem_create_context(struct drm_device *dev, struct drm_i915_file_private *file_priv) {const bool is_global_default_ctx = file_priv ==NULL ; +struct drm_i915_private *dev_priv = dev->dev_private;struct intel_context *ctx;int ret =0 ;
@@ -326,6 +339,7 @@ err_unpin:i915_gem_object_ggtt_unpin (ctx->legacy_hw_ctx.rcs_state); err_destroy:idr_remove (&file_priv->context_idr, ctx->user_handle); +idr_remove (&dev_priv->global_ctx_idr, ctx->global_id);i915_gem_context_unreference (ctx);return ERR_PTR (ret); }
@@ -389,6 +403,7 @@ int i915_gem_context_init(struct drm_device *dev) dev_priv->hw_context_size =0 ; } } +idr_init (&dev_priv->global_ctx_idr); ctx =i915_gem_create_context (dev,NULL );if (IS_ERR (ctx)) {
@@ -416,6 +431,8 @@ void i915_gem_context_fini(struct drm_device *dev)struct intel_context *dctx = dev_priv->ring[RCS ].default_context;int i; +idr_destroy (&dev_priv->global_ctx_idr); +if (dctx->legacy_hw_ctx.rcs_state) {/* The only known way to stop the gpu from accessing the hw context is * to reset it. Do this as the very last operation to avoid confusing
@@ -478,6 +495,8 @@ static int context_idr_cleanup(int id, void *p, void *data) {struct intel_context *ctx = p; +idr_remove (&ctx->i915->global_ctx_idr, ctx->global_id); +i915_gem_context_unreference (ctx);return 0 ; }
@@ -890,6 +909,7 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data, {struct drm_i915_gem_context_destroy *args = data;struct drm_i915_file_private *file_priv = file->driver_priv; +struct drm_i915_private *dev_priv = dev->dev_private;struct intel_context *ctx;int ret;
@@ -907,6 +927,7 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data, }idr_remove (&ctx->file_priv->context_idr, ctx->user_handle); +idr_remove (&dev_priv->global_ctx_idr, ctx->global_id);i915_gem_context_unreference (ctx);mutex_unlock (&dev->struct_mutex);
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/11 drm/i915: Constrain intel_context::global_id to 20 bits
In reply to [email protected]From: Robert Bragg <[email protected]>
This will allow the ID to be given to the HW as the unique context identifier that's written, for example, to the context status buffer on preemption and included in reports written by the OA unit.
--- drivers/gpu/drm/i915/i915_gem_context.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +5 -6
@@ -90,6 +90,10 @@#include "i915_drv.h" #include "i915_trace.h" +/* With execlist scheduling we can program our own HW context ID but we we +* are limited to 20bits */ +#define I915_MAX_HW_CTX_ID ((1<<20)-1) +/* This is a HW constraint. The value below is the largest known requirement * I've seen in a spec to date, and that was a workaround for a non-shipping * part. It should be safe to decrease this, but it's more future proof as is.
@@ -257,13 +261,8 @@ __create_hw_context(struct drm_device *dev, ctx->file_priv = file_priv; ctx->user_handle = ret; -/* TODO: If required, this global id can be used for programming the hw -* fields too. In that case, we'll have take care of hw restrictions -* while allocating idr. e.g. for some hw, we may not have full 32 bits -* available. -*/ ret =idr_alloc_cyclic (&dev_priv->global_ctx_idr, - ctx,0 ,0 ,GFP_KERNEL ); + ctx,0 ,I915_MAX_HW_CTX_ID ,GFP_KERNEL );if (ret <0 ) goto err_out;
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/11 drm/i915: return ctx->global_id from intel_execlists_ctx_id()
In reply to [email protected]From: Robert Bragg <[email protected]>
The newly added intel_context::global_id is suitable (a globally unique 20 bit ID) for giving to the hardware as a unique context identifier.
Compared to using the pinned address of a logical ring context these IDs are constant for the lifetime of a context whereas a context could be repinned at different addresses during its lifetime.
Having a stable ID is useful when we need to buffer information associated with a context based on this ID so the association can't be lost. For example the OA unit writes out counter reports to a circular buffer tagged with this ID and we want to be able to accurately filter reports for a specific context, ideally without the added complexity of tracking context re-pinning while the OA buffer may contain reports with older IDs.
--- drivers/gpu/drm/i915/i915_debugfs.c | 7 ++++--- drivers/gpu/drm/i915/intel_lrc.c | 22 ++++++++++------------ drivers/gpu/drm/i915/intel_lrc.h | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +4 -3
@@ -1970,6 +1970,7 @@ static int i915_context_status(struct seq_file *m, void *unused)static void i915_dump_lrc_obj (struct seq_file *m,struct intel_engine_cs *ring, +struct intel_context *ctx,struct drm_i915_gem_object *ctx_obj) {struct page *page;
@@ -1984,7 +1985,7 @@ static void i915_dump_lrc_obj(struct seq_file *m, }seq_printf (m,"CONTEXT: %s %u\n" , ring->name, -intel_execlists_ctx_id (ctx_obj)); +intel_execlists_ctx_id (ctx));if (!i915_gem_obj_ggtt_bound (ctx_obj))seq_puts (m,"\tNot bound in GGTT\n" );
@@ -2033,7 +2034,7 @@ static int i915_dump_lrc(struct seq_file *m, void *unused)list_for_each_entry (ctx, &dev_priv->context_list, link) {for_each_ring (ring, dev_priv, i) {if (ring->default_context != ctx) -i915_dump_lrc_obj (m, ring, +i915_dump_lrc_obj (m, ring, ctx, ctx->engine[i].state); } }
@@ -2112,7 +2113,7 @@ static int i915_execlists(struct seq_file *m, void *data) ctx_obj = head_req->ctx->engine[ring_id].state;seq_printf (m,"\tHead request id: %u\n" , -intel_execlists_ctx_id (ctx_obj)); +intel_execlists_ctx_id (head_req->ctx));seq_printf (m,"\tHead request tail: %u\n" , head_req->tail); }
drivers/gpu/drm/i915/intel_lrc.c +10 -12
@@ -260,7 +260,7 @@ int intel_sanitize_enable_execlists(struct drm_device *dev, int enable_execlists/** * intel_execlists_ctx_id() - get the Execlists Context ID -* @ctx_obj: Logical Ring Context backing object. +* @ctx: LR context * * Do not confuse with ctx->id! Unfortunately we have a name overload * here: the old context ID we pass to userspace as a handler so that
@@ -269,15 +269,15 @@ int intel_sanitize_enable_execlists(struct drm_device *dev, int enable_execlists* interrupts. * * Return: 20-bits globally unique context ID. +* +* Further the ID given to HW can now be relied on to be constant for +* the lifetime of the context, unlike previously when we used an +* associated logical ring context address (which could be repinned at +* a different address). */ -u32 intel_execlists_ctx_id (struct drm_i915_gem_object *ctx_obj) +u32 intel_execlists_ctx_id (struct intel_context *ctx) { -u32 lrca =i915_gem_obj_ggtt_offset (ctx_obj) + -LRC_PPHWSP_PN *PAGE_SIZE ; - -/* LRCA is required to be 4K aligned so the more significant 20 bits -* are globally unique */ -return lrca >>12 ; +return ctx->global_id; }static bool disable_lite_restore_wa (struct intel_engine_cs *ring)
@@ -305,7 +305,7 @@ uint64_t intel_lr_context_descriptor(struct intel_context *ctx, desc |=GEN8_CTX_L3LLC_COHERENT ; desc |=GEN8_CTX_PRIVILEGE ; desc |= lrca; - desc |= (u64 )intel_execlists_ctx_id (ctx_obj) <<GEN8_CTX_ID_SHIFT ; + desc |= (u64 )intel_execlists_ctx_id (ctx) <<GEN8_CTX_ID_SHIFT ;/* TODO: WaDisableLiteRestore when we start using semaphore * signalling between Command Streamers */
@@ -475,9 +475,7 @@ static bool execlists_check_remove_request(struct intel_engine_cs *ring, execlist_link);if (head_req !=NULL ) { -struct drm_i915_gem_object *ctx_obj = - head_req->ctx->engine[ring->id].state; -if (intel_execlists_ctx_id (ctx_obj) == request_id) { +if (intel_execlists_ctx_id (head_req->ctx) == request_id) {WARN (head_req->elsp_submitted ==0 ,"Never submitted head request\n" );
drivers/gpu/drm/i915/intel_lrc.h +1 -1
@@ -93,7 +93,7 @@ struct i915_execbuffer_params;int intel_execlists_submission (struct i915_execbuffer_params *params,struct drm_i915_gem_execbuffer2 *args,struct list_head *vmas); -u32 intel_execlists_ctx_id (struct drm_i915_gem_object *ctx_obj); +u32 intel_execlists_ctx_id (struct intel_context *ctx);void intel_lrc_irq_handler (struct intel_engine_cs *ring);void intel_execlists_retire_requests (struct intel_engine_cs *ring);
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 03/11] drm/i915: return ctx->global_id from intel_execlists_ctx_id()
Quoted 9 lines · On 16/02/16 05:27, [email protected] wrote:
From: Robert Bragg <[email protected]>
The newly added
intel_context::global_idis suitable (a globally unique 20 bit ID) for giving to the hardware as a unique context identifier.Compared to using the pinned address of a logical ring context these IDs are constant for the lifetime of a context whereas a context could be repinned at different addresses during its lifetime.
Quoted 7 lines
Having a stable ID is useful when we need to buffer information associated with a context based on this ID so the association can't be lost. For example the OA unit writes out counter reports to a circular buffer tagged with this ID and we want to be able to accurately filter reports for a specific context, ideally without the added complexity of tracking context re-pinning while the OA buffer may contain reports with older IDs.
Unfortunately, I suspect that the GuC firmware has conflated the context ID (which ought to be a purely software-defined tag) with the (hardware) GTT page address of the LRC. So this will probably break GuC submission.
But it looks like a good idea otherwise; maybe we can get the GuC firmware updated so it doesn't make this assumption ...
.Dave.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/11 drm/i915: Add ctx getparam ioctl parameter to retrieve ctx global id
In reply to [email protected]From: Sourab Gupta <[email protected]>
This patch adds a new ctx getparam ioctl parameter, which can be used to retrieve ctx global_id for any particular ctx 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 global_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
@@ -960,6 +960,9 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,case I915_CONTEXT_PARAM_NO_ZEROMAP : args->value = ctx->flags &CONTEXT_NO_ZEROMAP ;break ; +case I915_CONTEXT_PARAM_GLOBAL_ID : + args->value = ctx->global_id; +break ;default : ret = -EINVAL ;break ;
include/uapi/drm/i915_drm.h +1 -0
@@ -1131,6 +1131,7 @@ struct drm_i915_gem_context_param {__u64 param;#define I915_CONTEXT_PARAM_BAN_PERIOD 0x1#define I915_CONTEXT_PARAM_NO_ZEROMAP 0x2 +#define I915_CONTEXT_PARAM_GLOBAL_ID 0x3__u64 value; };
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 5/11 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 | 50 +++++++++++++++++++++++++++++++++------- include/uapi/drm/i915_drm.h | 16 +++++++++++++ 2 files changed, 58 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/i915_perf.c +42 -8
@@ -44,6 +44,13 @@ static u32 i915_perf_stream_paranoid = true;#define OA_EXPONENT_MAX 0x3f +#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 ;
@@ -79,7 +86,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 {
@@ -149,6 +157,27 @@ static bool append_oa_sample(struct i915_perf_stream *stream,copy_to_user (read_state->buf, &header,sizeof (header)); read_state->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 (read_state->buf, &source,4 )) +return false; + read_state->buf +=4 ; + } +if (sample_flags &SAMPLE_OA_REPORT ) {copy_to_user (read_state->buf, report, report_size); read_state->buf += report_size;
@@ -841,11 +870,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 ;
@@ -873,8 +897,15 @@ 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 ) { + 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 );
@@ -1480,6 +1511,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_SAMPLE_OA_SOURCE_PROP : + props->sample_flags |=SAMPLE_OA_SOURCE_INFO ; +break ;case DRM_I915_PERF_PROP_MAX :BUG (); }
include/uapi/drm/i915_drm.h +16 -0
@@ -1156,6 +1156,14 @@ enum drm_i915_oa_format {#define I915_PERF_FLAG_FD_NONBLOCK (1<<1)#define I915_PERF_FLAG_DISABLED (1<<2) +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
@@ -1190,6 +1198,13 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_OA_EXPONENT_PROP , +/** +* 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_SAMPLE_OA_SOURCE_PROP , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
@@ -1237,6 +1252,7 @@ enum drm_i915_perf_record_type {* struct { * struct drm_i915_perf_record_header header; * +* { u32 source_info; } && DRM_I915_PERF_SAMPLE_OA_SOURCE_PROP * { u32 oa_report[]; } && DRM_I915_PERF_SAMPLE_OA_PROP * }; */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 6/11 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 commands to capture OA reports are inserted at BB boundaries. The metadata information pertaining to snapshot is maintained in a list, which also has corresponding gem request field which is tracked for completion of command.
Both periodic and RCS based reports are associated with a single stream (corresponding to render engine), and the samples will be forwarded to userspace in the sequential order according to their timestamps.
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 | 35 +- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 4 + drivers/gpu/drm/i915/i915_perf.c | 733 +++++++++++++++++++++++++---- drivers/gpu/drm/i915/intel_lrc.c | 4 + include/uapi/drm/i915_drm.h | 15 + 5 files changed, 690 insertions(+), 101 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +34 -1
@@ -1730,6 +1730,9 @@ struct i915_perf_stream {struct intel_context *ctx;bool enabled; +/* Whether command stream based data collection is enabled */ +bool cs_mode; +/* Enables the collection of HW samples, either in response to * I915_PERF_IOCTL_ENABLE or implicitly called when stream is * opened without I915_PERF_FLAG_DISABLED */
@@ -1773,6 +1776,12 @@ struct i915_perf_stream {* * 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); };struct i915_oa_ops {
@@ -1786,10 +1795,21 @@ struct i915_oa_ops { u32 ctx_id);void (*legacy_ctx_switch_unlocked)(struct drm_i915_gem_request *req);void (*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;
@@ -2042,6 +2062,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;
@@ -2084,6 +2106,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 */
@@ -3328,6 +3360,7 @@ void i915_oa_context_pin_notify(struct drm_i915_private *dev_priv, struct intel_context *context);void i915_oa_legacy_ctx_switch_notify (struct drm_i915_gem_request *req);void i915_oa_update_reg_state (struct intel_engine_cs *ring,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
@@ -1258,12 +1258,16 @@ i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params, exec_start = params->batch_obj_vm_offset + params->args_batch_start_offset; +i915_perf_command_stream_hook (params->request); + ret = ring->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 +633 -100
1,005 lines not on this page · raw message
drivers/gpu/drm/i915/intel_lrc.c +4 -0
@@ -931,10 +931,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 = ring->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
@@ -1160,6 +1160,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 */ };
@@ -1205,6 +1206,19 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_SAMPLE_OA_SOURCE_PROP , +/** +* The value of this property specifies the GPU engine (ring) for which +* the samples need to be collected. Specifying this property also +* implies the command stream based sample collection. +*/ +DRM_I915_PERF_RING_PROP , + +/** +* The value of this property set to 1 requests inclusion of context ID +* in the perf sample data. +*/ +DRM_I915_PERF_SAMPLE_CTX_ID_PROP , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
@@ -1253,6 +1267,7 @@ enum drm_i915_perf_record_type {* struct drm_i915_perf_record_header header; * * { u32 source_info; } && DRM_I915_PERF_SAMPLE_OA_SOURCE_PROP +* { u32 ctx_id; } && DRM_I915_PERF_SAMPLE_CTX_ID_PROP * { u32 oa_report[]; } && DRM_I915_PERF_SAMPLE_OA_PROP * }; */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 06/11] drm/i915: Framework for capturing command stream based OA reports
Hi Sourab,
As Sergio Martinez has started experimenting with this in gputop and reported seeing lots of ENOSPC errors being reported when reading I had a look into this and saw a few issues with how we check that there's data available to read in command stream mode, and a I think there's a possibility of incorrectly sorting the samples sometimes...
Quoted 53 lines · On Tue, Feb 16, 2016 at 5:27 AM, <[email protected]> wrote:
From: Sourab Gupta <[email protected]>
drivers/gpu/drm/i915/i915_perf.c +15
-1-static bool i915_oa_can_read (struct i915_perf_stream *stream) +static bool append_oa_rcs_sample (struct i915_perf_stream *stream, +struct i915_perf_read_state *read_state, +struct i915_perf_cs_data_node *node) +{ +struct drm_i915_private *dev_priv = stream->dev_priv; +struct oa_sample_data data = {0 }; +const u8 *report = dev_priv->perf.command_stream_buf.addr + + node->offset; +u32 sample_flags = stream->sample_flags; +u32 report_ts; + +/* +* Forward the periodic OA samples which have the timestamp lower +* than timestamp of this sample, before forwarding this sample. +* This ensures samples read by user are order acc. to their timestamps
drivers/gpu/drm/i915/i915_perf.c +32
-0+*/ + report_ts = *(u32 *)(report +4 ); + dev_priv->perf.oa.ops.read (stream, read_state, report_ts); + +if (sample_flags &SAMPLE_OA_SOURCE_INFO ) + data.source =I915_PERF_OA_EVENT_SOURCE_RCS ; + +if (sample_flags &SAMPLE_CTX_ID ) + data.ctx_id = node->ctx_id; + +if (sample_flags &SAMPLE_OA_REPORT ) + data.report = report; + +append_oa_sample (stream, read_state, &data); + +return true; +} + +static void oa_rcs_append_reports (struct i915_perf_stream *stream, +struct i915_perf_read_state *read_state) +{ +struct drm_i915_private *dev_priv = stream->dev_priv; +struct i915_perf_cs_data_node *entry, *next; + +list_for_each_entry_safe (entry, next, + &dev_priv->perf.node_list, link) { +if (!i915_gem_request_completed (entry->request, true)) +break ; + +if (!append_oa_rcs_sample (stream, read_state, entry)) +break ; +
drivers/gpu/drm/i915/i915_perf.c static void gen7_oa_read(struct i915_perf_stream *stream, · line 719
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+spin_lock (&dev_priv->perf.node_list_lock); +list_del (&entry->link); +spin_unlock (&dev_priv->perf.node_list_lock); + +i915_gem_request_unreference__unlocked (entry->request); +kfree (entry); + } + +/* Flush any remaining periodic reports */ + dev_priv->perf.oa.ops.read (stream, read_state,U32_MAX );
I don't think we can flush all remaining periodic reports here - at least not if we have any in-flight MI_RPC commands - in case the next request to complete might have reports with earlier timestamps than some of these periodic reports.
Even if we have periodic reports available I think we need to throttle forwarding them based on the command stream requests completing.
This is something that userspace should understand when it explicitly decides to use command stream mode in conjunction with periodic sampling.
drivers/gpu/drm/i915/i915_perf.c static void gen7_oa_read(struct i915_perf_stream *stream, · line 730
Quoted 13 lines
drivers/gpu/drm/i915/i915_perf.c +7
-1+} + +static bool command_stream_buf_is_empty (struct i915_perf_stream *stream) {struct drm_i915_private *dev_priv = stream->dev_priv; -return !dev_priv->perf.oa.ops.oa_buffer_is_empty (dev_priv); +if (stream->cs_mode) +return list_empty (&dev_priv->perf.node_list); +else +return true; }
I think this list_empty() check needs a lock around it, as it's called from stream_have_data__unlocked().
Currently only checking list_empty() can lead to some false positives that may confuse the current i915_perf_read() (the false positives come from not checking that at least one entry->request has also completed).
False positives here will affect the error reporting in i915_perf_read_locked(). The first thing i915_perf_read_locked() does is check for available data so it can return -EAGAIN for non-blocking file descriptors or block, waiting for data, for blocking fds. Once we believe there is data then if stream->read() returns zero then that's translated to a -ENOSPC error because we 'know' there's data but weren't able to copy anything to the user's buffer because it wasn't large enough to hold a complete record.
Quoted 13 lines
drivers/gpu/drm/i915/i915_perf.c +1
-1-static int i915_oa_wait_unlocked (struct i915_perf_stream *stream) +static bool stream_have_data__unlocked (struct i915_perf_stream *stream) {struct drm_i915_private *dev_priv = stream->dev_priv;@@ -397,8 +739,29 @@ static int i915_oa_wait_unlocked(struct i915_perf_stream *stream) * can't be destroyed until completion (such as a read()) thatensures
* the device + OA buffer can't disappear
*/
drivers/gpu/drm/i915/i915_perf.c static int i915_oa_wait_unlocked(struct i915_perf_stream *stream) · line 744
Quoted 3 lines
drivers/gpu/drm/i915/i915_perf.c +3
-0+return !(dev_priv->perf.oa.ops.oa_buffer_is_empty (dev_priv) && +command_stream_buf_is_empty (stream)); +}
In command stream mode, due to how we need to merge sort reports I think we need a more involved set of checks. We need to check that at least one entry->request in the node_list has completed, or else if the node_list is empty then we can check if !oa_buffer_is_empty().
There's going to be a thorny race to consider though: if this code ends up reporting that there is data to read because the node_list is empty and there are periodic samples, but by the time we call into stream->read() there's a new node_list entry that's not completed that will end up returning 0 which could again result in an incorrect ENOSPC error.
We should consider changing stream->read() so it can return -ENOSPC itself if appropriate and when it returns 0 we would instead either return -EAGAIN or loop back to waiting for blocking fds.
B.t.w for reference the stream->read() interface is a little different in the series I sent out recently for Haswell vs the gen8+ oa-next branch (which I haven't rebased yet) because I had to make some last minute changes to consider -EFAULT errors if there was a copy_to_user() error while reading. If you look at this issue, it could be good to also compare with these related changes I made recently.
drivers/gpu/drm/i915/i915_perf.c static int i915_oa_wait_unlocked(struct i915_perf_stream *stream) · line 750
Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c +6
-0+ +static bool i915_oa_can_read (struct i915_perf_stream *stream) +{ + +return stream_have_data__unlocked (stream); +}
Kind regards,
- Robert
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 06/11] drm/i915: Framework for capturing command stream based OA reports
Quoted 8 lines · Robert Bragg
Hi Sourab,
As Sergio Martinez has started experimenting with this in gputop and reported seeing lots of ENOSPC errors being reported when reading I had a look into this and saw a few issues with how we check that there's data available to read in command stream mode, and a I think there's a possibility of incorrectly sorting the samples sometimes...
Hi Robert,
Thanks for spotting this anomaly. I'll have this fixed in the next version of patch set.
Quoted 85 lines · On Tue, Feb 16, 2016 at 5:27 AM, <[email protected]> wrote:
From: Sourab Gupta <[email protected]>
-static bool
i915_oa_can_read(struct i915_perf_stream *stream)+static bool append_oa_rcs_sample(structi915_perf_stream*stream,
+ structi915_perf_read_state
*read_state,
+ structi915_perf_cs_data_node
*node)
+{
+ structdrm_i915_private*dev_priv=stream->dev_priv;
+ structoa_sample_datadata = { 0 };
+ const u8 *report =
dev_priv->perf.command_stream_buf.addr+
+node->offset;
+ u32sample_flags=stream->sample_flags;
+ u32report_ts;
+
+ /*
+ * Forward the periodic OA samples which have the
timestamp lower
+ * than timestamp of this sample, before forwarding
this sample.
+ * This ensures samples read by user are order acc. to
their timestamps
+ */
+report_ts= *(u32 *)(report + 4);
+ dev_priv->perf.oa.ops.read(stream,read_state,
report_ts);
+
+ if (sample_flags&SAMPLE_OA_SOURCE_INFO)
+ data.source =I915_PERF_OA_EVENT_SOURCE_RCS;
+
+ if (sample_flags&SAMPLE_CTX_ID)
+ data.ctx_id =node->ctx_id;
+
+ if (sample_flags&SAMPLE_OA_REPORT)
+ data.report = report;
+
+append_oa_sample(stream, read_state, &data);
+
+ return true;
+}
+
+static void oa_rcs_append_reports(structi915_perf_stream*stream,
+ structi915_perf_read_state
*read_state)
+{
+ structdrm_i915_private*dev_priv=stream->dev_priv;
+ structi915_perf_cs_data_node*entry, *next;
+
+ list_for_each_entry_safe(entry, next,
+&dev_priv->perf.node_list,
link) {
+ if (!
i915_gem_request_completed(entry->request, true))
+ break;
+
+ if (!append_oa_rcs_sample(stream,read_state,
entry))
+ break;
+
+spin_lock(&dev_priv->perf.node_list_lock);
+list_del(&entry->link);
+spin_unlock(&dev_priv->perf.node_list_lock);
+
+
i915_gem_request_unreference__unlocked(entry->request);
+ kfree(entry);
+ }
+
+ /* Flush any remaining periodic reports */
+ dev_priv->perf.oa.ops.read(stream,read_state,
U32_MAX);I don't think we can flush all remaining periodic reports here - at least not if we have any in-flight
MI_RPCcommands - in case the next request to complete might have reports with earlier timestamps than some of these periodic reports.
Quoted 8 lines
Even if we have periodic reports available I think we need to throttle forwarding them based on the command stream requests completing.
This is something that userspace should understand when it explicitly decides to use command stream mode in conjunction with periodic sampling.
I agree, there shouldn't be any flushing of remaining periodic reports here, instead any periodic reports remaining here should be taken care of during the next processing of command stream samples.
Quoted 26 lines
+} + +static bool command_stream_buf_is_empty(struct i915_perf_stream *stream) { struct drm_i915_private *dev_priv = stream->dev_priv; - return ! dev_priv->perf.oa.ops.oa_buffer_is_empty(dev_priv); + if (stream->cs_mode) + return list_empty(&dev_priv->perf.node_list); + else + return true; }I think this
list_empty()check needs a lock around it, as it's called fromstream_have_data__unlocked().Currently only checking
list_empty()can lead to some false positives that may confuse the currenti915_perf_read()(the false positives come from not checking that at least oneentry->requesthas also completed).
Quoted 9 lines
False positives here will affect the error reporting in
i915_perf_read_locked(). The first thingi915_perf_read_locked()does is check for available data so it can return-EAGAINfor non-blocking file descriptors or block, waiting for data, for blocking fds. Once we believe there is data then ifstream->read()returns zero then that's translated to a-ENOSPCerror because we 'know' there's data but weren't able to copy anything to the user's buffer because it wasn't large enough to hold a complete record.
Thanks for pointing this out. This function should check that at least one request has completed when the list is not empty. I'll aim to make this change.
Quoted 35 lines
-static int i915_oa_wait_unlocked(struct i915_perf_stream *stream) +static bool stream_have_data__unlocked(struct i915_perf_stream *stream) { struct drm_i915_private *dev_priv = stream->dev_priv; @@ -397,8 +739,29 @@ static int i915_oa_wait_unlocked(struct i915_perf_stream *stream) * can't be destroyed until completion (such as a read()) that ensures * the device + OA buffer can't disappear */ + return !(dev_priv->perf.oa.ops.oa_buffer_is_empty(dev_priv) && + command_stream_buf_is_empty(stream)); +}In command stream mode, due to how we need to merge sort reports I think we need a more involved set of checks. We need to check that at least one
entry->requestin thenode_listhas completed, or else if thenode_listis empty then we can check if !oa_buffer_is_empty().There's going to be a thorny race to consider though: if this code ends up reporting that there is data to read because the
node_listis empty and there are periodic samples, but by the time we call intostream->read()there's a newnode_listentry that's not completed that will end up returning 0 which could again result in an incorrect ENOSPC error.
Quoted 3 lines
We should consider changing
stream->read()so it can return-ENOSPCitself if appropriate and when it returns 0 we would instead either return-EAGAINor loop back to waiting for blocking fds.
Yeah, this race needs to be handled, ideally best way would be through the changes to stream->read() itself as you suggested. I'll aim to make this change (while rebasing on your recent copy_to_user changes).
Quoted 17 lines
B.t.w for reference the
stream->read()interface is a little different in the series I sent out recently for Haswell vs the gen8+ oa-next branch (which I haven't rebased yet) because I had to make some last minute changes to consider-EFAULTerrors if there was acopy_to_user()error while reading. If you look at this issue, it could be good to also compare with these related changes I made recently.+ +static bool i915_oa_can_read(struct i915_perf_stream *stream) +{ + + return stream_have_data__unlocked(stream); +}
Quoted 4 lines
Kind regards,
- Robert
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 7/11 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 | 1 + drivers/gpu/drm/i915/i915_perf.c | 39 ++++++++++++++++++++++++++++++++++++++- include/uapi/drm/i915_drm.h | 7 +++++++ 3 files changed, 46 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +1 -0
@@ -1808,6 +1808,7 @@ struct i915_perf_cs_data_node {struct drm_i915_gem_request *request;u32 offset;u32 ctx_id; +u32 pid; };struct drm_i915_private {
drivers/gpu/drm/i915/i915_perf.c +38 -1
@@ -55,6 +55,7 @@ static u32 i915_perf_stream_paranoid = true;struct oa_sample_data {u32 source;u32 ctx_id; +u32 pid;const u8 *report; };
@@ -96,6 +97,7 @@ static struct i915_oa_format gen8_plus_oa_formats[I915_OA_FORMAT_MAX] = {#define SAMPLE_OA_REPORT (1<<0)#define SAMPLE_OA_SOURCE_INFO (1<<1)#define SAMPLE_CTX_ID (1<<2) +#define SAMPLE_PID (1<<3)struct perf_open_properties {
@@ -255,6 +257,7 @@ static void i915_perf_command_stream_hook_oa(struct drm_i915_gem_request *req) } entry->ctx_id = ctx->global_id; + entry->pid = current->pid;i915_gem_request_assign (&entry->request, req);insert_perf_entry (dev_priv, entry);
@@ -405,6 +408,12 @@ static bool append_oa_sample(struct i915_perf_stream *stream, read_state->buf +=4 ; } +if (sample_flags &SAMPLE_PID ) { +if (copy_to_user (read_state->buf, &data->pid,4 )) +return false; + read_state->buf +=4 ; + } +if (sample_flags &SAMPLE_OA_REPORT ) {if (copy_to_user (read_state->buf, data->report, report_size))return false;
@@ -446,6 +455,10 @@ static bool append_oa_buffer_sample(struct i915_perf_stream *stream,if (sample_flags &SAMPLE_CTX_ID ) data.ctx_id =0 ; +#warning "FIXME: append_oa_buffer_sample: deduce pid for periodic samples based on most recent RCS pid for ctx" +if (sample_flags &SAMPLE_PID ) + data.pid =0 ; +if (sample_flags &SAMPLE_OA_REPORT ) data.report = report;
@@ -685,6 +698,9 @@ static bool append_oa_rcs_sample(struct i915_perf_stream *stream,if (sample_flags &SAMPLE_CTX_ID ) data.ctx_id = node->ctx_id; +if (sample_flags &SAMPLE_PID ) + data.pid = node->pid; +if (sample_flags &SAMPLE_OA_REPORT ) data.report = report;
@@ -1307,6 +1323,7 @@ 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 ;int format_size;int ret;
@@ -1416,8 +1433,20 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, require_cs_mode = true; } +if (require_cs_mode && !props->cs_mode) { +DRM_ERROR ("PID sampling requires a ring to be specified" ); + ret = -EINVAL ; + goto cs_error; + } +if (props->cs_mode) { -if (!(props->sample_flags &SAMPLE_CTX_ID )) { +/* +* The only time we should allow enabling CS mode if it's not +* strictly required, is if SAMPLE_CTX_ID has been requested +* as it's usable with periodic OA or CS sampling. +*/ +if (!require_cs_mode && + !(props->sample_flags &SAMPLE_CTX_ID )) {DRM_ERROR ("Ring given without requesting any CS data to sample" ); ret = -EINVAL ;
@@ -1426,6 +1455,11 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, stream->cs_mode = true; +if (props->sample_flags &SAMPLE_PID ) { + stream->sample_flags |=SAMPLE_PID ; + stream->sample_size +=4 ; + } + ret =alloc_command_stream_buf (dev_priv);if (ret) goto cs_error;
@@ -2045,6 +2079,9 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv,case DRM_I915_PERF_SAMPLE_CTX_ID_PROP : props->sample_flags |=SAMPLE_CTX_ID ;break ; +case DRM_I915_PERF_SAMPLE_PID_PROP : + props->sample_flags |=SAMPLE_PID ; +break ;case DRM_I915_PERF_PROP_MAX :BUG (); }
include/uapi/drm/i915_drm.h +7 -0
@@ -1219,6 +1219,12 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_SAMPLE_CTX_ID_PROP , +/** +* The value of this property set to 1 requests inclusion of pid in the +* perf sample data. +*/ +DRM_I915_PERF_SAMPLE_PID_PROP , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
@@ -1268,6 +1274,7 @@ enum drm_i915_perf_record_type {* * { u32 source_info; } && DRM_I915_PERF_SAMPLE_OA_SOURCE_PROP * { u32 ctx_id; } && DRM_I915_PERF_SAMPLE_CTX_ID_PROP +* { u32 pid; } && DRM_I915_PERF_SAMPLE_PID_PROP * { u32 oa_report[]; } && DRM_I915_PERF_SAMPLE_OA_PROP * }; */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 8/11 drm/i915: Add support to add execbuffer tags to 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 | 6 +++-- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 5 +++-- drivers/gpu/drm/i915/i915_perf.c | 36 +++++++++++++++++++++++++----- drivers/gpu/drm/i915/intel_lrc.c | 4 ++-- include/uapi/drm/i915_drm.h | 12 ++++++++++ 5 files changed, 52 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +4 -2
@@ -1701,6 +1701,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; };struct i915_oa_format {
@@ -1781,7 +1782,7 @@ struct i915_perf_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); +void (*command_stream_hook)(struct drm_i915_gem_request *req,u32 tag); };struct i915_oa_ops {
@@ -1809,6 +1810,7 @@ struct i915_perf_cs_data_node {u32 offset;u32 ctx_id;u32 pid; +u32 tag; };struct drm_i915_private {
@@ -3361,7 +3363,7 @@ void i915_oa_context_pin_notify(struct drm_i915_private *dev_priv, struct intel_context *context);void i915_oa_legacy_ctx_switch_notify (struct drm_i915_gem_request *req);void i915_oa_update_reg_state (struct intel_engine_cs *ring,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
@@ -1258,7 +1258,7 @@ i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params, exec_start = params->batch_obj_vm_offset + params->args_batch_start_offset; -i915_perf_command_stream_hook (params->request); +i915_perf_command_stream_hook (params->request, params->tag); ret = ring->dispatch_execbuffer(params->request, exec_start, exec_len,
@@ -1266,7 +1266,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);
@@ -1574,6 +1574,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, params->dispatch_flags = dispatch_flags; params->batch_obj = batch_obj; params->ctx = ctx; + params->tag =i915_execbuffer2_get_tag (*args); ret = dev_priv->gt.execbuf_submit (params, args, &eb->vmas);
drivers/gpu/drm/i915/i915_perf.c +31 -5
@@ -56,6 +56,7 @@ struct oa_sample_data {u32 source;u32 ctx_id;u32 pid; +u32 tag;const u8 *report; };
@@ -98,6 +99,7 @@ static struct i915_oa_format gen8_plus_oa_formats[I915_OA_FORMAT_MAX] = {#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 {
@@ -123,7 +125,7 @@ struct perf_open_properties* perf mutex lock. */ -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) {struct intel_engine_cs *ring = req->ring;struct drm_i915_private *dev_priv = ring->dev->dev_private;
@@ -135,7 +137,7 @@ void i915_perf_command_stream_hook(struct drm_i915_gem_request *req)mutex_lock (&dev_priv->perf.streams_lock);list_for_each_entry (stream, &dev_priv->perf.streams, link) {if (stream->enabled && stream->command_stream_hook) - stream->command_stream_hook (req); + stream->command_stream_hook (req, tag); }mutex_unlock (&dev_priv->perf.streams_lock); }
@@ -227,7 +229,8 @@ static void insert_perf_entry(struct drm_i915_private *dev_priv,spin_unlock (&dev_priv->perf.node_list_lock); } -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 *ring = req->ring;struct intel_ringbuffer *ringbuf = req->ringbuf;
@@ -258,6 +261,7 @@ static void i915_perf_command_stream_hook_oa(struct drm_i915_gem_request *req) entry->ctx_id = ctx->global_id; entry->pid = current->pid; + entry->tag = tag;i915_gem_request_assign (&entry->request, req);insert_perf_entry (dev_priv, entry);
@@ -414,6 +418,12 @@ static bool append_oa_sample(struct i915_perf_stream *stream, read_state->buf +=4 ; } +if (sample_flags &SAMPLE_TAG ) { +if (copy_to_user (read_state->buf, &data->tag,4 )) +return false; + read_state->buf +=4 ; + } +if (sample_flags &SAMPLE_OA_REPORT ) {if (copy_to_user (read_state->buf, data->report, report_size))return false;
@@ -459,6 +469,10 @@ static bool append_oa_buffer_sample(struct i915_perf_stream *stream,if (sample_flags &SAMPLE_PID ) data.pid =0 ; +#warning "FIXME: append_oa_buffer_sample: deduce tag for periodic samples based on most recent RCS tag for ctx" +if (sample_flags &SAMPLE_TAG ) + data.tag =0 ; +if (sample_flags &SAMPLE_OA_REPORT ) data.report = report;
@@ -701,6 +715,9 @@ static bool append_oa_rcs_sample(struct i915_perf_stream *stream,if (sample_flags &SAMPLE_PID ) data.pid = node->pid; +if (sample_flags &SAMPLE_TAG ) + data.tag = node->tag; +if (sample_flags &SAMPLE_OA_REPORT ) data.report = report;
@@ -1323,7 +1340,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 );int format_size;int ret;
@@ -1434,7 +1452,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; }
@@ -1460,6 +1478,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;
@@ -2082,6 +2105,9 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv,case DRM_I915_PERF_SAMPLE_PID_PROP : props->sample_flags |=SAMPLE_PID ;break ; +case DRM_I915_PERF_SAMPLE_TAG_PROP : + props->sample_flags |=SAMPLE_TAG ; +break ;case DRM_I915_PERF_PROP_MAX :BUG (); }
drivers/gpu/drm/i915/intel_lrc.c +2 -2
@@ -931,13 +931,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 = ring->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
@@ -788,6 +788,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;
@@ -1225,6 +1230,12 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_SAMPLE_PID_PROP , +/** +* The value of this property set to 1 requests inclusion of tag in the +* perf sample data. +*/ +DRM_I915_PERF_SAMPLE_TAG_PROP , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
@@ -1275,6 +1286,7 @@ enum drm_i915_perf_record_type {* { u32 source_info; } && DRM_I915_PERF_SAMPLE_OA_SOURCE_PROP * { u32 ctx_id; } && DRM_I915_PERF_SAMPLE_CTX_ID_PROP * { u32 pid; } && DRM_I915_PERF_SAMPLE_PID_PROP +* { u32 tag; } && DRM_I915_PERF_SAMPLE_TAG_PROP * { u32 oa_report[]; } && DRM_I915_PERF_SAMPLE_OA_PROP * }; */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 9/11 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.
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 | 33 ++- drivers/gpu/drm/i915/i915_perf.c | 578 +++++++++++++++++++++++++++------------ drivers/gpu/drm/i915/i915_reg.h | 2 + include/uapi/drm/i915_drm.h | 7 + 4 files changed, 431 insertions(+), 189 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +23 -10
@@ -1725,6 +1725,7 @@ struct i915_perf_stream {struct list_head link; +enum intel_ring_id ring_id;u32 sample_flags;int sample_size;
@@ -1734,6 +1735,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; +/* Enables the collection of HW samples, either in response to * I915_PERF_IOCTL_ENABLE or implicitly called when stream is * opened without I915_PERF_FLAG_DISABLED */
@@ -1782,7 +1786,8 @@ struct i915_perf_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,u32 tag); +void (*command_stream_hook)(struct i915_perf_stream *stream, +struct drm_i915_gem_request *req,u32 tag); };struct i915_oa_ops {
@@ -1807,7 +1812,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;
@@ -2071,14 +2085,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_RINGS ]; +struct {u32 specific_ctx_id; -struct hrtimer poll_check_timer; -wait_queue_head_t poll_wq; -bool periodic;u32 period_exponent;
@@ -2115,10 +2128,10 @@ struct drm_i915_private {struct drm_i915_gem_object *obj;struct i915_vma *vma;u8 *addr; - } command_stream_buf; + } command_stream_buf[I915_NUM_RINGS ]; -struct list_head node_list; -spinlock_t node_list_lock; +struct list_head node_list[I915_NUM_RINGS ]; +spinlock_t node_list_lock[I915_NUM_RINGS ]; } perf;/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
drivers/gpu/drm/i915/i915_perf.c +399 -179
1,011 lines not on this page · raw message
drivers/gpu/drm/i915/i915_reg.h +2 -0
@@ -359,6 +359,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)
@@ -438,6 +439,7 @@#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
@@ -1236,6 +1236,12 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_SAMPLE_TAG_PROP , +/** +* The value of this property set to 1 requests inclusion of timestamp +* in the perf sample data. +*/ +DRM_I915_PERF_SAMPLE_TS_PROP , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
@@ -1287,6 +1293,7 @@ enum drm_i915_perf_record_type {* { u32 ctx_id; } && DRM_I915_PERF_SAMPLE_CTX_ID_PROP * { u32 pid; } && DRM_I915_PERF_SAMPLE_PID_PROP * { u32 tag; } && DRM_I915_PERF_SAMPLE_TAG_PROP +* { u64 timestamp; } && DRM_I915_PERF_SAMPLE_TS_PROP * { u32 oa_report[]; } && DRM_I915_PERF_SAMPLE_OA_PROP * }; */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 10/11 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 | 65 +++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 29 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +1 -1
@@ -2086,7 +2086,7 @@ struct drm_i915_private {spinlock_t hook_lock;struct hrtimer poll_check_timer; -struct i915_perf_stream *exclusive_stream; +struct i915_perf_stream *exclusive_stream[I915_NUM_RINGS ];wait_queue_head_t poll_wq[I915_NUM_RINGS ];struct {
drivers/gpu/drm/i915/i915_perf.c +37 -28
140 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 11/11 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 | 177 ++++++++++++++++++++++++++++++++++++++- include/uapi/drm/i915_drm.h | 14 ++++ 3 files changed, 193 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +4 -0
@@ -1817,6 +1817,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;
@@ -2089,6 +2090,9 @@ struct drm_i915_private {struct i915_perf_stream *exclusive_stream[I915_NUM_RINGS ];wait_queue_head_t poll_wq[I915_NUM_RINGS ]; +u32 num_mmio; +u32 mmio_list[I915_PERF_MMIO_NUM_MAX ]; +struct {u32 specific_ctx_id;
drivers/gpu/drm/i915/i915_perf.c +175 -2
267 lines not on this page · raw message
include/uapi/drm/i915_drm.h +14 -0
@@ -1170,6 +1170,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
@@ -1242,6 +1248,13 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_SAMPLE_TS_PROP , +/** +* 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_SAMPLE_MMIO_PROP , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
@@ -1294,6 +1307,7 @@ enum drm_i915_perf_record_type {* { u32 pid; } && DRM_I915_PERF_SAMPLE_PID_PROP * { u32 tag; } && DRM_I915_PERF_SAMPLE_TAG_PROP * { u64 timestamp; } && DRM_I915_PERF_SAMPLE_TS_PROP +* { u32 mmio[]; } && DRM_I915_PERF_SAMPLE_MMIO_PROP * { u32 oa_report[]; } && DRM_I915_PERF_SAMPLE_OA_PROP * }; */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx