drm/i915: Vulkan performance query support
Subsystems (3)
v5 cover drm/i915: Vulkan performance query support
Hi,
Since the last iteration we found a couple of issues with the NOA configuration not being ready when we run the performance queries.
This led me to realized I had "lost" a patch during a rebase ("drm/i915/perf: implement active wait for noa configurations") and also exposed a bug fixed ("drm/i915/perf: add missing delay for OA muxes configuration").
Finally a new patch is added to make use of active NOA wait ("drm/i915/perf: execute OA configuration from command stream") instead of a wait on the CPU side. This makes all of the non per context part of OA configurations to be executed on the command streamer rather than through CPU MMIO.
Cheers,
Lionel Landwerlin (10):
drm/i915/perf: add missing delay for OA muxes configuration drm/i915/perf: introduce a versioning of the i915-perf uapi drm/i915/perf: allow for CS OA configs to be created lazily drm/i915/perf: implement active wait for noa configurations drm/i915: introduce a mechanism to extend execbuf2 drm/i915: add syncobj timeline support
drm/i915: add a new perf configuration execbuf parameter drm/i915/perf: allow holding preemption on filtered ctx drm/i915/perf: execute OA configuration from command stream drm/i915: add support for perf configuration queries
.../gpu/drm/i915/gem/i915_gem_execbuffer.c | 440 +++++++++++++-- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 2 + drivers/gpu/drm/i915/gt/intel_engine_types.h | 9 + drivers/gpu/drm/i915/gt/intel_gpu_commands.h | 25 + drivers/gpu/drm/i915/gt/intel_lrc.c | 8 +- drivers/gpu/drm/i915/gt/intel_ringbuffer.c | 4 +- drivers/gpu/drm/i915/i915_debugfs.c | 25 + drivers/gpu/drm/i915/i915_drv.c | 9 + drivers/gpu/drm/i915/i915_drv.h | 59 +- drivers/gpu/drm/i915/i915_perf.c | 525 ++++++++++++++---- drivers/gpu/drm/i915/i915_priolist_types.h | 7 + drivers/gpu/drm/i915/i915_query.c | 279 ++++++++++ drivers/gpu/drm/i915/i915_reg.h | 4 +- drivers/gpu/drm/i915/i915_request.c | 1 + drivers/gpu/drm/i915/i915_request.h | 1 + drivers/gpu/drm/i915/intel_guc_submission.c | 12 +- include/uapi/drm/i915_drm.h | 193 ++++++- 17 files changed, 1436 insertions(+), 167 deletions(-)
--
2.21.0.392.gf8f6787159e
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 1/10 drm/i915/perf: add missing delay for OA muxes configuration
--- drivers/gpu/drm/i915/i915_perf.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/gpu/drm/i915/i915_perf.c +23 -0
@@ -1838,6 +1838,29 @@ static int gen8_enable_metric_set(struct i915_perf_stream *stream)config_oa_regs (dev_priv, oa_config->mux_regs, oa_config->mux_regs_len); +/* It apparently takes a fairly long time for a new MUX +* configuration to be be applied after these register writes. +* This delay duration was derived empirically based on the +* render_basic config but hopefully it covers the maximum +* configuration latency. +* +* As a fallback, the checks in _append_oa_reports() to skip +* invalid OA reports do also seem to work to discard reports +* generated before this config has completed - albeit not +* silently. +* +* Unfortunately this is essentially a magic number, since we +* don't currently know of a reliable mechanism for predicting +* how long the MUX config will take to apply and besides +* seeing invalid reports we don't know of a reliable way to +* explicitly check that the MUX config has landed. +* +* It's even possible we've miss characterized the underlying +* problem - it just seems like the simplest explanation why +* a delay at this location would mitigate any invalid reports. +*/ +usleep_range (15000 ,20000 ); +config_oa_regs (dev_priv, oa_config->b_counter_regs, oa_config->b_counter_regs_len);
Signature · 6 lines
2.21.0.392.gf8f6787159e _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 01/10] drm/i915/perf: add missing delay for OA muxes configuration
Quoting Lionel Landwerlin (2019-06-27 09:00:36)
Quoted 14 lines
Signed-off-by Lionel Landwerlin <[email protected]>Fixes 19f81df2859eb1 ("drm/i915/perf: Add OA unit support for Gen 8+")--- drivers/gpu/drm/i915/i915_perf.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)drivers/gpu/drm/i915/i915_perf.c +0
-0@@ -1838,6 +1838,29 @@ static int gen8_enable_metric_set(struct i915_perf_stream *stream)config_oa_regs (dev_priv, oa_config->mux_regs, oa_config->mux_regs_len);
drivers/gpu/drm/i915/i915_perf.c static int gen8_enable_metric_set(struct i915_perf_stream *stream) · line 1850
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+/* It apparently takes a fairly long time for a new MUX +* configuration to be be applied after these register writes. +* This delay duration was derived empirically based on the +* render_basic config but hopefully it covers the maximum +* configuration latency. +* +* As a fallback, the checks in _append_oa_reports() to skip +* invalid OA reports do also seem to work to discard reports +* generated before this config has completed - albeit not +* silently.
If you know the initial batch of reports is invalid after changing the register, why not just silently discard them until you see X valid reports? No gratuitous sleeps required, still a magic number (albeit it may be a small number).
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 01/10] drm/i915/perf: add missing delay for OA muxes configuration
Quoted 15 lines · Chris Wilson
Quoting Lionel Landwerlin (2019-06-27 09:00:36)
Quoted 14 lines
Signed-off-by Lionel Landwerlin <[email protected]>Fixes 19f81df2859eb1 ("drm/i915/perf: Add OA unit support for Gen 8+")--- drivers/gpu/drm/i915/i915_perf.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)drivers/gpu/drm/i915/i915_perf.c +0
-0@@ -1838,6 +1838,29 @@ static int gen8_enable_metric_set(struct i915_perf_stream *stream)config_oa_regs (dev_priv, oa_config->mux_regs, oa_config->mux_regs_len);
Quoted 16 lines
drivers/gpu/drm/i915/i915_perf.c static int gen8_enable_metric_set(struct i915_perf_stream *stream) · line 1850
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+/* It apparently takes a fairly long time for a new MUX +* configuration to be be applied after these register writes. +* This delay duration was derived empirically based on the +* render_basic config but hopefully it covers the maximum +* configuration latency. +* +* As a fallback, the checks in _append_oa_reports() to skip +* invalid OA reports do also seem to work to discard reports +* generated before this config has completed - albeit not +* silently. If you know the initial batch of reports is invalid after changing the register, why not just silently discard them until you see X valid reports? No gratuitous sleeps required, still a magic number (albeit it may be a small number).
-Chris
That would be nice, but unfortunately we don't really have a criteria to tell whether the values written in the snapshots are right or wrong.
That's because the B/C counters in the snapshots are programmable.
-Lionel
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 2/10 drm/i915/perf: introduce a versioning of the i915-perf uapi
In reply to Lionel LandwerlinReporting this version will help application figure out what level of the support the running kernel provides.
--- drivers/gpu/drm/i915/i915_drv.c | 3 +++ include/uapi/drm/i915_drm.h | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+)
drivers/gpu/drm/i915/i915_drv.c +3 -0
@@ -482,6 +482,9 @@ static int i915_getparam_ioctl(struct drm_device *dev, void *data,case I915_PARAM_MMAP_GTT_COHERENT : value =INTEL_INFO (dev_priv)->has_coherent_ggtt;break ; +case I915_PARAM_PERF_REVISION : + value =1 ; +break ;default :DRM_DEBUG ("Unknown parameter %d\n" , param->param);return -EINVAL ;
include/uapi/drm/i915_drm.h +21 -0
@@ -610,6 +610,13 @@ typedef struct drm_i915_irq_wait {* See I915_EXEC_FENCE_OUT and I915_EXEC_FENCE_SUBMIT. */ #define I915_PARAM_HAS_EXEC_SUBMIT_FENCE 53 + +/* +* Revision of the i915-perf uAPI. The value returned helps determine what +* i915-perf features are available. See drm_i915_perf_property_id. +*/ +#define I915_PARAM_PERF_REVISION 54 +/* Must be kept compact -- no holes and well documented */ typedef struct drm_i915_getparam {
@@ -1843,23 +1850,31 @@ enum drm_i915_perf_property_id {* Open the stream for a specific context handle (as used with * execbuffer2). A stream opened for a specific context this way * won't typically require root privileges. +* +* This property is available in perf revision 1. */ DRM_I915_PERF_PROP_CTX_HANDLE =1 ,/** * A value of 1 requests the inclusion of raw OA unit reports as * part of stream samples. +* +* This property is available in perf revision 1. */ DRM_I915_PERF_PROP_SAMPLE_OA ,/** * The value specifies which set of OA unit metrics should be * be configured, defining the contents of any OA unit reports. +* +* This property is available in perf revision 1. */ DRM_I915_PERF_PROP_OA_METRICS_SET ,/** * The value specifies the size and layout of OA unit reports. +* +* This property is available in perf revision 1. */ DRM_I915_PERF_PROP_OA_FORMAT,
@@ -1869,6 +1884,8 @@ enum drm_i915_perf_property_id {* from this exponent as follows: * * 80ns * 2^(period_exponent + 1) +* +* This property is available in perf revision 1. */ DRM_I915_PERF_PROP_OA_EXPONENT,
@@ -1900,6 +1917,8 @@ struct drm_i915_perf_open_param {* to close and re-open a stream with the same configuration. * * It's undefined whether any pending data for the stream will be lost. +* +* This ioctl is available in perf revision 1. */ #define I915_PERF_IOCTL_ENABLE _IO('i', 0x0)
@@ -1907,6 +1926,8 @@ struct drm_i915_perf_open_param {* Disable data capture for a stream. * * It is an error to try and read a stream that is disabled. +* +* This ioctl is available in perf revision 1. */ #define I915_PERF_IOCTL_DISABLE _IO('i', 0x1)
Signature · 6 lines
2.21.0.392.gf8f6787159e _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 3/10 drm/i915/perf: allow for CS OA configs to be created lazily
In reply to Lionel LandwerlinHere we introduce a mechanism by which the execbuf part of the i915 driver will be able to request that a batch buffer containing the programming for a particular OA config be created.
We'll execute these OA configuration buffers right before executing a set of userspace commands so that a particular user batchbuffer be executed with a given OA configuration.
This mechanism essentially allows the userspace driver to go through several OA configuration without having to open/close the i915/perf stream.
v2: No need for locking on object OA config object creation (Chris)
Flush cpu mapping of OA config (Chris)
--- drivers/gpu/drm/i915/gt/intel_gpu_commands.h | 1 + drivers/gpu/drm/i915/i915_drv.h | 22 ++- drivers/gpu/drm/i915/i915_perf.c | 171 +++++++++++++++---- 3 files changed, 162 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +1 -0
@@ -126,6 +126,7 @@*/ #define MI_LOAD_REGISTER_IMM (x) MI_INSTR(0x22, 2*(x)-1)#define MI_LRI_FORCE_POSTED (1<<12) +#define MI_LOAD_REGISTER_IMM_MAX_REGS (126)#define MI_STORE_REGISTER_MEM MI_INSTR(0x24, 1)#define MI_STORE_REGISTER_MEM_GEN8 MI_INSTR(0x24, 2)#define MI_SRM_LRM_GLOBAL_GTT (1<<22)
drivers/gpu/drm/i915/i915_drv.h +20 -2
@@ -1110,6 +1110,10 @@ struct i915_oa_config {struct attribute *attrs[2 ];struct device_attribute sysfs_metric_id; +struct drm_i915_gem_object *obj; + +struct list_head vma_link; +atomic_t ref_count; };
@@ -1696,11 +1700,21 @@ struct drm_i915_private {struct mutex metrics_lock;/* -* List of dynamic configurations, you need to hold -* dev_priv->perf.metrics_lock to access it. +* List of dynamic configurations (struct i915_oa_config), you +* need to hold dev_priv->perf.metrics_lock to access it. */ struct idr metrics_idr; +/* +* List of dynamic configurations (struct i915_oa_config) +* which have an allocated buffer in GGTT for reconfiguration, +* you need to hold dev_priv->perf.metrics_lock to access it. +* Elements are added to the list lazilly on execbuf (when a +* particular configuration is requested). The list is freed +* upon closing the perf stream. +*/ +struct list_head metrics_buffers; +/* * Lock associated with anything below within this structure * except exclusive_stream.
@@ -2586,6 +2600,10 @@ int i915_perf_remove_config_ioctl(struct drm_device *dev, void *data,void i915_oa_init_reg_state (struct intel_engine_cs *engine,struct intel_context *ce,u32 *reg_state); +int i915_perf_get_oa_config (struct drm_i915_private *i915, +int metrics_set, +struct i915_oa_config **out_config, +struct drm_i915_gem_object **out_obj);/* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct i915_address_space *vm,
drivers/gpu/drm/i915/i915_perf.c +141 -30
261 lines not on this page · raw message
Signature · 6 lines
2.21.0.392.gf8f6787159e _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 4/10 drm/i915/perf: implement active wait for noa configurations
In reply to Lionel LandwerlinNOA configuration take some amount of time to apply. That amount of time depends on the size of the GT. There is no documented time for this. For example, past experimentations with powergating configuration changes seem to indicate a 60~70us delay. We go with 500us as default for now which should be over the required amount of time (according to HW architects).
--- drivers/gpu/drm/i915/gt/intel_gpu_commands.h | 24 +++ drivers/gpu/drm/i915/i915_debugfs.c | 25 +++ drivers/gpu/drm/i915/i915_drv.h | 8 + drivers/gpu/drm/i915/i915_perf.c | 178 ++++++++++++++++++- drivers/gpu/drm/i915/i915_reg.h | 4 +- 5 files changed, 236 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +24 -0
@@ -151,6 +151,7 @@#define MI_BATCH_GTT (2<<6)/* aliased with (1<<7) on gen4 */ #define MI_BATCH_BUFFER_START_GEN8 MI_INSTR(0x31, 1)#define MI_BATCH_RESOURCE_STREAMER (1<<10) +#define MI_BATCH_PREDICATE (1 << 15)/* HSW+ on RCS only*/ /* * 3D instructions used by the kernel
@@ -226,6 +227,29 @@#define PIPE_CONTROL_DEPTH_CACHE_FLUSH (1<<0)#define PIPE_CONTROL_GLOBAL_GTT (1<<2)/* in addr dword */ +#define MI_MATH (x) MI_INSTR(0x1a, (x)-1) +#define MI_ALU_OP (op, src1, src2) (((op) << 20) | ((src1) << 10) | (src2)) +/* operands */ +#define MI_ALU_OP_NOOP 0 +#define MI_ALU_OP_LOAD 128 +#define MI_ALU_OP_LOADINV 1152 +#define MI_ALU_OP_LOAD0 129 +#define MI_ALU_OP_LOAD1 1153 +#define MI_ALU_OP_ADD 256 +#define MI_ALU_OP_SUB 257 +#define MI_ALU_OP_AND 258 +#define MI_ALU_OP_OR 259 +#define MI_ALU_OP_XOR 260 +#define MI_ALU_OP_STORE 384 +#define MI_ALU_OP_STOREINV 1408 +/* sources */ +#define MI_ALU_SRC_REG (x) (x)/* 0 -> 15 */ +#define MI_ALU_SRC_SRCA 32 +#define MI_ALU_SRC_SRCB 33 +#define MI_ALU_SRC_ACCU 49 +#define MI_ALU_SRC_ZF 50 +#define MI_ALU_SRC_CF 51 +/* * Commands used only by the command parser */
drivers/gpu/drm/i915/i915_debugfs.c +25 -0
@@ -3646,6 +3646,30 @@ DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops, i915_wedged_get, i915_wedged_set, "%llu\n"); +static int +i915_perf_noa_delay_set (void *data,u64 val) +{ +struct drm_i915_private *i915 = data; + +atomic64_set (&i915->perf.oa.noa_programming_delay, val); +return 0 ; +} + +static int +i915_perf_noa_delay_get (void *data,u64 *val) +{ +struct drm_i915_private *i915 = data; + + *val =atomic64_read (&i915->perf.oa.noa_programming_delay); +return 0 ; +} + +DEFINE_SIMPLE_ATTRIBUTE (i915_perf_noa_delay_fops, + i915_perf_noa_delay_get, + i915_perf_noa_delay_set, +"%llu\n" ); + +#define DROP_UNBOUND BIT(0)#define DROP_BOUND BIT(1)#define DROP_RETIRE BIT(2)
@@ -4411,6 +4435,7 @@ static const struct i915_debugfs_files {const char *name;const struct file_operations *fops; } i915_debugfs_files[] = { + {"i915_perf_noa_delay", &i915_perf_noa_delay_fops}, {"i915_wedged", &i915_wedged_fops}, {"i915_cache_sharing", &i915_cache_sharing_fops}, {"i915_gem_drop_caches", &i915_drop_caches_fops},
drivers/gpu/drm/i915/i915_drv.h +8 -0
@@ -1835,6 +1835,14 @@ struct drm_i915_private {struct i915_oa_ops ops;const struct i915_oa_format *oa_formats; + +/** +* A batch buffer doing a wait on the GPU for the NOA +* logic to be reprogrammed. +*/ +struct i915_vma *noa_wait; + +atomic64_t noa_programming_delay; } oa; } perf;
drivers/gpu/drm/i915/i915_perf.c +176 -2
226 lines not on this page · raw message
drivers/gpu/drm/i915/i915_reg.h +3 -1
@@ -567,7 +567,9 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)#define MI_PREDICATE_SRC0_UDW _MMIO(0x2400 + 4)#define MI_PREDICATE_SRC1 _MMIO(0x2408)#define MI_PREDICATE_SRC1_UDW _MMIO(0x2408 + 4) - +#define MI_PREDICATE_DATA _MMIO(0x2410) +#define MI_PREDICATE_RESULT _MMIO(0x2418) +#define MI_PREDICATE_RESULT_1 _MMIO(0x241c)#define MI_PREDICATE_RESULT_2 _MMIO(0x2214)#define LOWER_SLICE_ENABLED (1 << 0)#define LOWER_SLICE_DISABLED (0 << 0)
Signature · 6 lines
2.21.0.392.gf8f6787159e _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 04/10] drm/i915/perf: implement active wait for noa configurations
Quoting Lionel Landwerlin (2019-06-27 09:00:39)
drivers/gpu/drm/i915/i915_perf.c static int alloc_oa_config_buffer(struct drm_i915_private *i915, · line 413
Quoted 9 lines
drivers/gpu/drm/i915/i915_perf.c +1
-0@@ -410,6 +410,8 @@ static int alloc_oa_config_buffer(struct drm_i915_private *i915,size_t config_length =0 ;u32 *cs; +lockdep_assert_held (&i915->drm.struct_mutex);
What inside *this* function depends on the struct_mutex? The noa_wait vma is already pinned and I didn't spot anything else added that might be contentious.
Quoted 13 lines
drivers/gpu/drm/i915/i915_perf.c +1
-1if (oa_config->mux_regs_len >0 ) { config_length +=DIV_ROUND_UP (oa_config->mux_regs_len,MI_LOAD_REGISTER_IMM_MAX_REGS ) *4 ;@@ -425,7 +427,7 @@ static int alloc_oa_config_buffer(struct drm_i915_private *i915, MI_LOAD_REGISTER_IMM_MAX_REGS) * 4; config_length += oa_config->flex_regs_len *8 ; } - config_length +=4 ;/* MI_BATCH_BUFFER_END */ + config_length +=12 ;/* MI_BATCH_BUFFER_START into noa_wait loop */ config_length =ALIGN (config_length,I915_GTT_PAGE_SIZE ); bo =i915_gem_object_create_shmem (i915, config_length);
drivers/gpu/drm/i915/i915_perf.c static int alloc_oa_config_buffer(struct drm_i915_private *i915, · line 451
Quoted 9 lines
drivers/gpu/drm/i915/i915_perf.c +5
-1@@ -442,7 +444,12 @@ static int alloc_oa_config_buffer(struct drm_i915_private *i915, cs =write_cs_mi_lri (cs, oa_config->b_counter_regs, oa_config->b_counter_regs_len); cs =write_cs_mi_lri (cs, oa_config->flex_regs, oa_config->flex_regs_len); - *cs++ =MI_BATCH_BUFFER_END ; + +/* Jump into the NOA wait busy loop. */ + *cs++ = (INTEL_GEN (i915) <8 ? +MI_BATCH_BUFFER_START :MI_BATCH_BUFFER_START_GEN8 ); + *cs++ = i915->perf.oa.noa_wait->node.start;
i915_ggtt_offset(i915->perf.oa.noa_wait);
double checks that you are in the ggtt and so assuming u32 is valid.
This is operating inside the user context right? (If I remember correctly, you plug into the user dispatch) If so, where do you save and restore the CS_GPR overwritten?
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 04/10] drm/i915/perf: implement active wait for noa configurations
Quoted 9 lines · Chris Wilson
Quoting Lionel Landwerlin (2019-06-27 09:00:39)
Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c +0
-0@@ -410,6 +410,8 @@ static int alloc_oa_config_buffer(struct drm_i915_private *i915,size_t config_length =0 ;u32 *cs;
Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c static int alloc_oa_config_buffer(struct drm_i915_private *i915, · line 413
Quoted 1 line
drivers/gpu/drm/i915/i915_perf.c +1
-0+lockdep_assert_held (&i915->drm.struct_mutex);What inside *this* function depends on the
struct_mutex? Thenoa_waitvma is already pinned and I didn't spot anything else added that might be contentious.
Thanks, will drop this.
Quoted 17 lines
Quoted 17 lines
drivers/gpu/drm/i915/i915_perf.c +1
-1if (oa_config->mux_regs_len >0 ) { config_length +=DIV_ROUND_UP (oa_config->mux_regs_len,MI_LOAD_REGISTER_IMM_MAX_REGS ) *4 ;@@ -425,7 +427,7 @@ static int alloc_oa_config_buffer(struct drm_i915_private *i915, MI_LOAD_REGISTER_IMM_MAX_REGS) * 4; config_length += oa_config->flex_regs_len *8 ; } - config_length +=4 ;/* MI_BATCH_BUFFER_END */ + config_length +=12 ;/* MI_BATCH_BUFFER_START into noa_wait loop */ config_length =ALIGN (config_length,I915_GTT_PAGE_SIZE ); bo =i915_gem_object_create_shmem (i915, config_length);@@ -442,7 +444,12 @@ static int alloc_oa_config_buffer(struct drm_i915_private *i915, cs =write_cs_mi_lri (cs, oa_config->b_counter_regs, oa_config->b_counter_regs_len); cs =write_cs_mi_lri (cs, oa_config->flex_regs, oa_config->flex_regs_len);
Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c static int alloc_oa_config_buffer(struct drm_i915_private *i915, · line 451
Quoted 6 lines
drivers/gpu/drm/i915/i915_perf.c +5
-1- *cs++ =MI_BATCH_BUFFER_END ; + +/* Jump into the NOA wait busy loop. */ + *cs++ = (INTEL_GEN (i915) <8 ? +MI_BATCH_BUFFER_START :MI_BATCH_BUFFER_START_GEN8 ); + *cs++ = i915->perf.oa.noa_wait->node.start;
i915_ggtt_offset(i915->perf.oa.noa_wait);
double checks that you are in the ggtt and so assuming u32 is valid.
Right, will do.
Quoted 4 lines
This is operating inside the user context right? (If I remember correctly, you plug into the user dispatch) If so, where do you save and restore the
CS_GPRoverwritten?
Duh! In a previous iteration I was saving this in the scratch BO as a given location.
Should I alloc my own buffer?
Thanks a lot,
-Lionel
Quoted 2 lines
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 04/10] drm/i915/perf: implement active wait for noa configurations
Quoting Lionel Landwerlin (2019-06-27 09:52:34)
Quoted 10 lines · Chris Wilson
Quoted 3 lines
This is operating inside the user context right? (If I remember correctly, you plug into the user dispatch) If so, where do you save and restore the
CS_GPRoverwritten?Duh! In a previous iteration I was saving this in the scratch BO as a given location.
Should I alloc my own buffer?
You only need a few temporaries right? You can squeeze into engine->gt->scratch. We need to mark out reserved fields in there!
Pick an offset in the upper 2k as a starting point. -Chris
_______________________________________________
Intel-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 5/10 drm/i915: introduce a mechanism to extend execbuf2
In reply to Lionel LandwerlinWe're planning to use this for a couple of new feature where we need to provide additional parameters to execbuf.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 30 ++++++++++++++++++- include/uapi/drm/i915_drm.h | 25 ++++++++++++++-- 2 files changed, 51 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +29 -1
@@ -23,6 +23,7 @@#include "i915_gem_clflush.h" #include "i915_gem_context.h" #include "i915_trace.h" +#include "i915_user_extensions.h" #include "intel_drv.h" enum {
@@ -271,6 +272,10 @@ struct i915_execbuffer {*/ int lut_size;struct hlist_head *buckets;/** ht for relocation handles */ + +struct { +u64 flags;/** Available extensions parameters */ + } extensions; };#define exec_entry (EB ,VMA ) (&(EB)->exec[(VMA)->exec_flags - (EB)->flags])
@@ -1969,7 +1974,7 @@ static bool i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)return false;/* Kernel clipping was a DRI1 misfeature */ -if (!(exec->flags &I915_EXEC_FENCE_ARRAY )) { +if (!(exec->flags & (I915_EXEC_FENCE_ARRAY |I915_EXEC_EXT ))) {if (exec->num_cliprects || exec->cliprects_ptr)return false; }
@@ -2347,6 +2352,22 @@ signal_fence_array(struct i915_execbuffer *eb, } } +static const i915_user_extension_fn execbuf_extensions[] = { +}; + +static int +parse_execbuf2_extensions (struct drm_i915_gem_execbuffer2 *args, +struct i915_execbuffer *eb) +{ +if (args->num_cliprects !=0 ) +return -EINVAL ; + +return i915_user_extensions (u64_to_user_ptr (args->cliprects_ptr), + execbuf_extensions, +ARRAY_SIZE (execbuf_extensions), + eb); +} + static int i915_gem_do_execbuffer(struct drm_device *dev, struct drm_file *file,
@@ -2393,6 +2414,13 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (args->flags &I915_EXEC_IS_PINNED ) eb.batch_flags |=I915_DISPATCH_PINNED ; + eb.extensions.flags =0 ; +if (args->flags &I915_EXEC_EXT ) { + err =parse_execbuf2_extensions (args, &eb); +if (err) +return err; + } +if (args->flags &I915_EXEC_FENCE_IN ) { in_fence =sync_file_get_fence (lower_32_bits (args->rsvd2));if (!in_fence)
include/uapi/drm/i915_drm.h +22 -3
@@ -1013,6 +1013,10 @@ struct drm_i915_gem_exec_fence {__u32 flags; }; +enum drm_i915_gem_execbuffer_ext { +DRM_I915_GEM_EXECBUFFER_EXT_MAX /* non-ABI */ +}; +struct drm_i915_gem_execbuffer2 {/** * List of gem_exec_object2 structs
@@ -1029,8 +1033,14 @@ struct drm_i915_gem_execbuffer2 {__u32 num_cliprects;/** * This is a struct drm_clip_rect *cliprects if I915_EXEC_FENCE_ARRAY -* is not set. If I915_EXEC_FENCE_ARRAY is set, then this is a -* struct drm_i915_gem_exec_fence *fences. +* & I915_EXEC_EXT are not set. +* +* If I915_EXEC_FENCE_ARRAY is set, then this is a pointer to an array +* of struct drm_i915_gem_exec_fence and num_cliprects is the length +* of the array. +* +* If I915_EXEC_EXT is set, then this is a pointer to a single struct +* drm_i915_gem_base_execbuffer_ext and num_cliprects is 0. */ __u64 cliprects_ptr;#define I915_EXEC_RING_MASK (0x3f)
@@ -1148,7 +1158,16 @@ struct drm_i915_gem_execbuffer2 {*/ #define I915_EXEC_FENCE_SUBMIT (1 << 20) -#define __I915_EXEC_UNKNOWN_FLAGS (-(I915_EXEC_FENCE_SUBMIT << 1)) +/* +* Setting I915_EXEC_EXT implies that drm_i915_gem_execbuffer2.cliprects_ptr +* is treated as a pointer to an linked list of i915_user_extension. Each +* i915_user_extension node is the base of a larger structure. The list of +* supported structures are listed in the drm_i915_gem_execbuffer_ext +* enum. +*/ +#define I915_EXEC_EXT (1 << 21) + +#define __I915_EXEC_UNKNOWN_FLAGS (-(I915_EXEC_EXT<<1))#define I915_EXEC_CONTEXT_ID_MASK (0xffffffff)#define i915_execbuffer2_set_context_id (eb2, context) \
Signature · 6 lines
2.21.0.392.gf8f6787159e _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 6/10 drm/i915: add syncobj timeline support
In reply to Lionel LandwerlinIntroduces a new parameters to execbuf so that we can specify syncobj handles as well as timeline points.
v2: Reuse i915_user_extension_fn
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 280 ++++++++++++++---- drivers/gpu/drm/i915/i915_drv.c | 2 + include/uapi/drm/i915_drm.h | 37 +++ 3 files changed, 263 insertions(+), 56 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +224 -56
@@ -213,6 +213,13 @@ enum {* the batchbuffer in trusted mode, otherwise the ioctl is rejected. */ +struct i915_drm_dma_fences { +struct drm_syncobj *syncobj;/* Use with ptr_mask_bits() */ +struct dma_fence *dma_fence; +u64 value; +struct dma_fence_chain *chain_fence; +}; +struct i915_execbuffer {struct drm_i915_private *i915;/** i915 backpointer */ struct drm_file *file;/** per-file lookup tables and limits */
@@ -275,6 +282,7 @@ struct i915_execbuffer {struct {u64 flags;/** Available extensions parameters */ +struct drm_i915_gem_execbuffer_ext_timeline_fences timeline_fences; } extensions; };
@@ -2224,67 +2232,193 @@ eb_select_engine(struct i915_execbuffer *eb, }static void -__free_fence_array (struct drm_syncobj **fences,unsigned int n) +__free_fence_array (struct i915_drm_dma_fences *fences,unsigned int n) { -while (n--) -drm_syncobj_put (ptr_mask_bits (fences[n],2 )); +while (n--) { +drm_syncobj_put (ptr_mask_bits (fences[n].syncobj,2 )); +dma_fence_put (fences[n].dma_fence); +kfree (fences[n].chain_fence); + }kvfree (fences); } -static struct drm_syncobj ** -get_fence_array (struct drm_i915_gem_execbuffer2 *args, -struct drm_file *file) +static struct i915_drm_dma_fences * +get_timeline_fence_array (struct i915_execbuffer *eb,int *out_n_fences) { -const unsigned long nfences = args->num_cliprects; +struct drm_i915_gem_execbuffer_ext_timeline_fences *timeline_fences = + &eb->extensions.timeline_fences; +struct drm_i915_gem_exec_fence __user *user_fences; +struct i915_drm_dma_fences *fences; +u64 __user *user_values; +unsigned long n; +int err; + + *out_n_fences = timeline_fences->handle_count; + +/* Check multiplication overflow for access_ok() and kvmalloc_array() */ +BUILD_BUG_ON (sizeof (size_t ) >sizeof (unsigned long )); + if (*out_n_fences > min_t(unsigned long, +ULONG_MAX /sizeof (*user_fences), +SIZE_MAX /sizeof (*fences))) +return ERR_PTR (-EINVAL ); + + user_fences =u64_to_user_ptr (timeline_fences->handles_ptr); +if (!access_ok (user_fences, *out_n_fences *sizeof (*user_fences))) +return ERR_PTR (-EFAULT ); + + user_values =u64_to_user_ptr (timeline_fences->values_ptr); +if (!access_ok (user_values, *out_n_fences *sizeof (*user_values))) +return ERR_PTR (-EFAULT ); + + fences =kvmalloc_array (*out_n_fences,sizeof (*fences), + __GFP_NOWARN |GFP_KERNEL ); +if (!fences) +return ERR_PTR (-ENOMEM ); + +BUILD_BUG_ON (~(ARCH_KMALLOC_MINALIGN -1 ) & + ~__I915_EXEC_FENCE_UNKNOWN_FLAGS); + +for (n =0 ; n < *out_n_fences; n++) { +struct drm_i915_gem_exec_fence user_fence; +struct drm_syncobj *syncobj; +struct dma_fence *fence =NULL ; +u64 point; + +if (__copy_from_user (&user_fence, user_fences++,sizeof (user_fence))) { + err = -EFAULT ; + goto err; + } + +if (user_fence.flags & __I915_EXEC_FENCE_UNKNOWN_FLAGS) { + err = -EINVAL ; + goto err; + } + +if (__get_user (point, user_values++)) { + err = -EFAULT ; + goto err; + } + + syncobj =drm_syncobj_find (eb->file, user_fence.handle); +if (!syncobj) { +DRM_DEBUG ("Invalid syncobj handle provided\n" ); + err = -EINVAL ; + goto err; + } + +if (user_fence.flags &I915_EXEC_FENCE_WAIT ) { + fence =drm_syncobj_fence_get (syncobj); +if (!fence) { +DRM_DEBUG ("Syncobj handle has no fence\n" ); +drm_syncobj_put (syncobj); + err = -EINVAL ; + goto err; + } + + err =dma_fence_chain_find_seqno (&fence, point); +if (err) { +DRM_DEBUG ("Syncobj handle missing requested point\n" ); + goto err; + } + } + +/* +* For timeline syncobjs we need to create a chain. +*/ +if (point !=0 && user_fence.flags &I915_EXEC_FENCE_SIGNAL ) { + fences[n].chain_fence = +kmalloc (sizeof (*fences[n].chain_fence), +GFP_KERNEL ); +if (!fences[n].chain_fence) { +dma_fence_put (fence); +drm_syncobj_put (syncobj); + err = -ENOMEM ; +DRM_DEBUG ("Unable to alloc chain_fence\n" ); + goto err; + } + }else { + fences[n].chain_fence =NULL ; + } + + fences[n].syncobj =ptr_pack_bits (syncobj, user_fence.flags,2 ); + fences[n].dma_fence = fence; + fences[n].value = point; + } + +return fences; + +err: +__free_fence_array (fences, n); +return ERR_PTR (err); +} + +static struct i915_drm_dma_fences * +get_legacy_fence_array (struct i915_execbuffer *eb, +int *out_n_fences) +{ +struct drm_i915_gem_execbuffer2 *args = eb->args;struct drm_i915_gem_exec_fence __user *user; -struct drm_syncobj **fences; +struct i915_drm_dma_fences *fences;unsigned long n;int err; -if (!(args->flags &I915_EXEC_FENCE_ARRAY )) -return NULL ; + *out_n_fences = args->num_cliprects;/* Check multiplication overflow for access_ok() and kvmalloc_array() */ BUILD_BUG_ON (sizeof (size_t ) >sizeof (unsigned long )); - if (nfences > min_t(unsigned long, -ULONG_MAX /sizeof (*user), -SIZE_MAX /sizeof (*fences))) + if (*out_n_fences > min_t(unsigned long, +ULONG_MAX /sizeof (*user), +SIZE_MAX /sizeof (*fences)))return ERR_PTR (-EINVAL ); user =u64_to_user_ptr (args->cliprects_ptr); -if (!access_ok (user, nfences *sizeof (*user))) +if (!access_ok (user, *out_n_fences *sizeof (*user)))return ERR_PTR (-EFAULT ); - fences =kvmalloc_array (nfences,sizeof (*fences), + fences =kvmalloc_array (*out_n_fences,sizeof (*fences), __GFP_NOWARN |GFP_KERNEL );if (!fences)return ERR_PTR (-ENOMEM ); -for (n =0 ; n < nfences; n++) { -struct drm_i915_gem_exec_fence fence; +for (n =0 ; n < *out_n_fences; n++) { +struct drm_i915_gem_exec_fence user_fence;struct drm_syncobj *syncobj; +struct dma_fence *fence =NULL ; -if (__copy_from_user (&fence, user++,sizeof (fence))) { +if (__copy_from_user (&user_fence, user++,sizeof (user_fence))) { err = -EFAULT ; goto err; } -if (fence.flags & __I915_EXEC_FENCE_UNKNOWN_FLAGS) { +if (user_fence.flags & __I915_EXEC_FENCE_UNKNOWN_FLAGS) { err = -EINVAL ; goto err; } - syncobj =drm_syncobj_find (file, fence.handle); + syncobj =drm_syncobj_find (eb->file, user_fence.handle);if (!syncobj) {DRM_DEBUG ("Invalid syncobj handle provided\n" ); err = -ENOENT ; goto err; } +if (user_fence.flags &I915_EXEC_FENCE_WAIT ) { + fence =drm_syncobj_fence_get (syncobj); +if (!fence) { +DRM_DEBUG ("Syncobj handle has no fence\n" ); +drm_syncobj_put (syncobj); + err = -EINVAL ; + goto err; + } + } +BUILD_BUG_ON (~(ARCH_KMALLOC_MINALIGN -1 ) & ~__I915_EXEC_FENCE_UNKNOWN_FLAGS); - fences[n] =ptr_pack_bits (syncobj, fence.flags,2 ); + fences[n].syncobj =ptr_pack_bits (syncobj, user_fence.flags,2 ); + fences[n].dma_fence = fence; + fences[n].value =0 ; + fences[n].chain_fence =NULL ; }return fences;
@@ -2294,37 +2428,44 @@ get_fence_array(struct drm_i915_gem_execbuffer2 *args,return ERR_PTR (err); } +static struct i915_drm_dma_fences * +get_fence_array (struct i915_execbuffer *eb,int *out_n_fences) +{ +if (eb->args->flags &I915_EXEC_FENCE_ARRAY ) +return get_legacy_fence_array (eb, out_n_fences); +if (eb->extensions.flags &BIT (DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES )) +return get_timeline_fence_array (eb, out_n_fences); + + *out_n_fences =0 ; + +return NULL ; +} +static void -put_fence_array (struct drm_i915_gem_execbuffer2 *args, -struct drm_syncobj **fences) +put_fence_array (struct i915_drm_dma_fences *fences,int nfences) {if (fences) -__free_fence_array (fences, args->num_cliprects); +__free_fence_array (fences, nfences); }static int await_fence_array (struct i915_execbuffer *eb, -struct drm_syncobj **fences) +struct i915_drm_dma_fences *fences, +int nfences) { -const unsigned int nfences = eb->args->num_cliprects;unsigned int n;int err;for (n =0 ; n < nfences; n++) {struct drm_syncobj *syncobj; -struct dma_fence *fence;unsigned int flags; - syncobj =ptr_unpack_bits (fences[n], &flags,2 ); + syncobj =ptr_unpack_bits (fences[n].syncobj, &flags,2 );if (!(flags &I915_EXEC_FENCE_WAIT ))continue ; - fence =drm_syncobj_fence_get (syncobj); -if (!fence) -return -EINVAL ; - - err =i915_request_await_dma_fence (eb->request, fence); -dma_fence_put (fence); + err =i915_request_await_dma_fence (eb->request, + fences[n].dma_fence);if (err <0 )return err; }
@@ -2334,9 +2475,9 @@ await_fence_array(struct i915_execbuffer *eb,static void signal_fence_array (struct i915_execbuffer *eb, -struct drm_syncobj **fences) +struct i915_drm_dma_fences *fences, +int nfences) { -const unsigned int nfences = eb->args->num_cliprects;struct dma_fence *const fence = &eb->request->fence;unsigned int n;
@@ -2344,15 +2485,43 @@ signal_fence_array(struct i915_execbuffer *eb,struct drm_syncobj *syncobj;unsigned int flags; - syncobj =ptr_unpack_bits (fences[n], &flags,2 ); + syncobj =ptr_unpack_bits (fences[n].syncobj, &flags,2 );if (!(flags &I915_EXEC_FENCE_SIGNAL ))continue ; -drm_syncobj_replace_fence (syncobj, fence); +if (fences[n].chain_fence) { +drm_syncobj_add_point (syncobj, fences[n].chain_fence, + fence, fences[n].value); +/* +* The chain's ownership is transfered to the +* timeline. +*/ + fences[n].chain_fence =NULL ; + }else { +drm_syncobj_replace_fence (syncobj, fence); + } } } +static int parse_timeline_fences (struct i915_user_extension __user *ext,void *data) +{ +struct i915_execbuffer *eb = data; + +/* Timeline fences are incompatible with the fence array flag. */ +if (eb->args->flags &I915_EXEC_FENCE_ARRAY ) +return -EINVAL ; + +if (copy_from_user (&eb->extensions.timeline_fences, ext, +sizeof (eb->extensions.timeline_fences))) +return -EFAULT ; + + eb->extensions.flags |=BIT (DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES ); + +return 0 ; +} +static const i915_user_extension_fn execbuf_extensions[] = { + [DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES ] = parse_timeline_fences, }; static int
@@ -2372,14 +2541,15 @@ static int i915_gem_do_execbuffer(struct drm_device *dev, struct drm_file *file, struct drm_i915_gem_execbuffer2 *args, - struct drm_i915_gem_exec_object2 *exec, - struct drm_syncobj **fences) + struct drm_i915_gem_exec_object2 *exec) { struct i915_execbuffer eb;struct dma_fence *in_fence =NULL ;struct dma_fence *exec_fence =NULL ;struct sync_file *out_fence =NULL ; +struct i915_drm_dma_fences *fences =NULL ;int out_fence_fd =-1 ; +int nfences =0 ;int err;BUILD_BUG_ON (__EXEC_INTERNAL_FLAGS & ~__I915_EXEC_ILLEGAL_FLAGS);
@@ -2421,10 +2591,16 @@ i915_gem_do_execbuffer(struct drm_device *dev,return err; } + fences =get_fence_array (&eb, &nfences); +if (IS_ERR (fences)) +return PTR_ERR (fences); +if (args->flags &I915_EXEC_FENCE_IN ) { in_fence =sync_file_get_fence (lower_32_bits (args->rsvd2)); -if (!in_fence) -return -EINVAL ; +if (!in_fence) { + err = -EINVAL ; + goto err_fences; + } }if (args->flags &I915_EXEC_FENCE_SUBMIT ) {
@@ -2582,7 +2758,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, }if (fences) { - err =await_fence_array (&eb, fences); + err =await_fence_array (&eb, fences, nfences);if (err) goto err_request; }
@@ -2611,7 +2787,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,i915_request_add (eb.request);if (fences) -signal_fence_array (&eb, fences); +signal_fence_array (&eb, fences, nfences);if (out_fence) {if (err ==0 ) {
@@ -2646,6 +2822,8 @@ i915_gem_do_execbuffer(struct drm_device *dev,dma_fence_put (exec_fence); err_in_fence:dma_fence_put (in_fence); +err_fences: +put_fence_array (fences, nfences);return err; }
@@ -2739,7 +2917,7 @@ i915_gem_execbuffer_ioctl(struct drm_device *dev, void *data, exec2_list[i].flags =0 ; } - err =i915_gem_do_execbuffer (dev, file, &exec2, exec2_list,NULL ); + err =i915_gem_do_execbuffer (dev, file, &exec2, exec2_list);if (exec2.flags & __EXEC_HAS_RELOC) {struct drm_i915_gem_exec_object __user *user_exec_list =u64_to_user_ptr (args->buffers_ptr);
@@ -2770,7 +2948,6 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, {struct drm_i915_gem_execbuffer2 *args = data;struct drm_i915_gem_exec_object2 *exec2_list; -struct drm_syncobj **fences =NULL ;const size_t count = args->buffer_count;int err;
@@ -2798,15 +2975,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,return -EFAULT ; } -if (args->flags &I915_EXEC_FENCE_ARRAY ) { - fences =get_fence_array (args, file); -if (IS_ERR (fences)) { -kvfree (exec2_list); -return PTR_ERR (fences); - } - } - - err =i915_gem_do_execbuffer (dev, file, args, exec2_list, fences); + err =i915_gem_do_execbuffer (dev, file, args, exec2_list);/* * Now that we have begun execution of the batchbuffer, we ignore
@@ -2846,7 +3015,6 @@ end:; } args->flags &= ~__I915_EXEC_UNKNOWN_FLAGS; -put_fence_array (args, fences);kvfree (exec2_list);return err; }
drivers/gpu/drm/i915/i915_drv.c +2 -0
@@ -456,6 +456,7 @@ static int i915_getparam_ioctl(struct drm_device *dev, void *data,case I915_PARAM_HAS_EXEC_BATCH_FIRST :case I915_PARAM_HAS_EXEC_FENCE_ARRAY :case I915_PARAM_HAS_EXEC_SUBMIT_FENCE : +case I915_PARAM_HAS_EXEC_TIMELINE_FENCES :/* For the time being all of these are always true; * if some supported hardware does not have one of these * features this value needs to be provided from
@@ -3220,6 +3221,7 @@ static struct drm_driver driver = { .driver_features =DRIVER_GEM |DRIVER_RENDER |DRIVER_MODESET |DRIVER_ATOMIC |DRIVER_SYNCOBJ , +DRIVER_SYNCOBJ_TIMELINE , .release = i915_driver_release, .open = i915_driver_open, .lastclose = i915_driver_lastclose,
include/uapi/drm/i915_drm.h +37 -0
@@ -617,6 +617,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_PERF_REVISION 54 +/* Query whether DRM_I915_GEM_EXECBUFFER2 supports supplying an array of +* timeline syncobj through drm_i915_gem_execbuf_ext_timeline_fences. See +* I915_EXEC_EXT. +*/ +#define I915_PARAM_HAS_EXEC_TIMELINE_FENCES 55 +/* Must be kept compact -- no holes and well documented */ typedef struct drm_i915_getparam {
@@ -1014,9 +1020,40 @@ struct drm_i915_gem_exec_fence { };enum drm_i915_gem_execbuffer_ext { +/** +* This identifier is associated with +* drm_i915_gem_execbuf_ext_timeline_fences. +*/ +DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES , +DRM_I915_GEM_EXECBUFFER_EXT_MAX /* non-ABI */ }; +/** +* This structure describes an array of drm_syncobj and associated points for +* timeline variants of drm_syncobj. It is invalid to append this structure to +* the execbuf if I915_EXEC_FENCE_ARRAY is set. +*/ +struct drm_i915_gem_execbuffer_ext_timeline_fences { +struct i915_user_extension base; + +/** +* Number of element in the handles_ptr & value_ptr arrays. +*/ +__u64 handle_count; + +/** +* Pointer to an array of struct drm_i915_gem_exec_fence of size handle_count. +*/ +__u64 handles_ptr; + +/** +* Pointer to an array of u64 values of size handle_count. Values must +* be 0 for a binary drm_syncobj. +*/ +__u64 values_ptr; +}; +struct drm_i915_gem_execbuffer2 {/** * List of gem_exec_object2 structs
Signature · 6 lines
2.21.0.392.gf8f6787159e _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 06/10] drm/i915: add syncobj timeline support
Quoting Lionel Landwerlin (2019-06-27 09:00:41)
Quoted 17 lines
Introduces a new parameters to execbuf so that we can specify syncobj handles as well as timeline points.
v2: Reuse
i915_user_extension_fnSigned-off-by Lionel Landwerlin <[email protected]>--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 280 ++++++++++++++---- drivers/gpu/drm/i915/i915_drv.c | 2 + include/uapi/drm/i915_drm.h | 37 +++ 3 files changed, 263 insertions(+), 56 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +0
-0
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c enum { · line 216
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1
-0@@ -213,6 +213,13 @@ enum {* the batchbuffer in trusted mode, otherwise the ioctl is rejected. */ +struct i915_drm_dma_fences {
i915_execbuffer_fences or eb_fences as it is private to the impl.
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +6
-0+struct drm_syncobj *syncobj;/* Use with ptr_mask_bits() */ +struct dma_fence *dma_fence; +u64 value; +struct dma_fence_chain *chain_fence; +}; +struct i915_execbuffer {struct drm_i915_private *i915;/** i915 backpointer */ struct drm_file *file;/** per-file lookup tables and limits */
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c struct i915_execbuffer { · line 285
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1
-0@@ -275,6 +282,7 @@ struct i915_execbuffer {struct {u64 flags;/** Available extensions parameters */ +struct drm_i915_gem_execbuffer_ext_timeline_fences timeline_fences;
Another 40b on stack. Getting closer to those warning bells being set off.
Quoted 26 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +8
-6} extensions; };@@ -2224,67 +2232,193 @@ eb_select_engine(struct i915_execbuffer *eb, }static void -__free_fence_array (struct drm_syncobj **fences,unsigned int n) +__free_fence_array (struct i915_drm_dma_fences *fences,unsigned int n) { -while (n--) -drm_syncobj_put (ptr_mask_bits (fences[n],2 )); +while (n--) { +drm_syncobj_put (ptr_mask_bits (fences[n].syncobj,2 )); +dma_fence_put (fences[n].dma_fence); +kfree (fences[n].chain_fence); + }kvfree (fences); } -static struct drm_syncobj ** -get_fence_array (struct drm_i915_gem_execbuffer2 *args, -struct drm_file *file) +static struct i915_drm_dma_fences * +get_timeline_fence_array (struct i915_execbuffer *eb,int *out_n_fences) {
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c eb_select_engine(struct i915_execbuffer *eb, · line 2256
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +9
-1-const unsigned long nfences = args->num_cliprects; +struct drm_i915_gem_execbuffer_ext_timeline_fences *timeline_fences = + &eb->extensions.timeline_fences; +struct drm_i915_gem_exec_fence __user *user_fences; +struct i915_drm_dma_fences *fences; +u64 __user *user_values; +unsigned long n; +int err; + + *out_n_fences = timeline_fences->handle_count;
I'd encourage using a const num_fences = timeline_fences->handle_count for readability within the function and then assigning
*out_n_fences = num_fences;
right before the successful return fences;
Quoted 51 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +50
-0+/* Check multiplication overflow for access_ok() and kvmalloc_array() */ +BUILD_BUG_ON (sizeof (size_t ) >sizeof (unsigned long )); + if (*out_n_fences > min_t(unsigned long, +ULONG_MAX /sizeof (*user_fences), +SIZE_MAX /sizeof (*fences))) +return ERR_PTR (-EINVAL ); + + user_fences =u64_to_user_ptr (timeline_fences->handles_ptr); +if (!access_ok (user_fences, *out_n_fences *sizeof (*user_fences))) +return ERR_PTR (-EFAULT ); + + user_values =u64_to_user_ptr (timeline_fences->values_ptr); +if (!access_ok (user_values, *out_n_fences *sizeof (*user_values))) +return ERR_PTR (-EFAULT ); + fences =kvmalloc_array (*out_n_fences,sizeof (*fences), + __GFP_NOWARN |GFP_KERNEL ); +if (!fences) +return ERR_PTR (-ENOMEM ); + +BUILD_BUG_ON (~(ARCH_KMALLOC_MINALIGN -1 ) & + ~__I915_EXEC_FENCE_UNKNOWN_FLAGS); + +for (n =0 ; n < *out_n_fences; n++) { +struct drm_i915_gem_exec_fence user_fence; +struct drm_syncobj *syncobj; +struct dma_fence *fence =NULL ; +u64 point; + +if (__copy_from_user (&user_fence, user_fences++,sizeof (user_fence))) { + err = -EFAULT ; + goto err; + } + +if (user_fence.flags & __I915_EXEC_FENCE_UNKNOWN_FLAGS) { + err = -EINVAL ; + goto err; + } + +if (__get_user (point, user_values++)) { + err = -EFAULT ; + goto err; + } + + syncobj =drm_syncobj_find (eb->file, user_fence.handle); +if (!syncobj) { +DRM_DEBUG ("Invalid syncobj handle provided\n" ); + err = -EINVAL ; + goto err; + } +
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c eb_select_engine(struct i915_execbuffer *eb, · line 2318
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +10
-0+if (user_fence.flags &I915_EXEC_FENCE_WAIT ) { + fence =drm_syncobj_fence_get (syncobj); +if (!fence) { +DRM_DEBUG ("Syncobj handle has no fence\n" ); +drm_syncobj_put (syncobj); + err = -EINVAL ; + goto err; + } + + err =dma_fence_chain_find_seqno (&fence, point);
Is an imported syncobj always a fence-chain?
drm_syncobj_import_sync_file_fence() says no.
Similarly, we put ordinary fences into the syncobj ourselves if point==0, or the user uses the old path.
I think you need something like
if (dma_fence_is_chain() || point) {
err = dma_fence_chain_find_seqno(&fence, point);
if (err) {
}
}drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c eb_select_engine(struct i915_execbuffer *eb, · line 2326
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +8
-0+if (err) { +DRM_DEBUG ("Syncobj handle missing requested point\n" ); + goto err; + } + } + +/* +* For timeline syncobjs we need to create a chain.
"need to preallocate chains for later signaling
Quoted 32 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +32
-0+*/ +if (point !=0 && user_fence.flags &I915_EXEC_FENCE_SIGNAL ) { + fences[n].chain_fence = +kmalloc (sizeof (*fences[n].chain_fence), +GFP_KERNEL ); +if (!fences[n].chain_fence) { +dma_fence_put (fence); +drm_syncobj_put (syncobj); + err = -ENOMEM ; +DRM_DEBUG ("Unable to alloc chain_fence\n" ); + goto err; + } + }else { + fences[n].chain_fence =NULL ; + } + + fences[n].syncobj =ptr_pack_bits (syncobj, user_fence.flags,2 ); + fences[n].dma_fence = fence; + fences[n].value = point; + } + +return fences; + +err: +__free_fence_array (fences, n); +return ERR_PTR (err); +} + +static struct i915_drm_dma_fences * +get_legacy_fence_array (struct i915_execbuffer *eb, +int *out_n_fences) +{
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c eb_select_engine(struct i915_execbuffer *eb, · line 2365
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +3
-3+struct drm_i915_gem_execbuffer2 *args = eb->args;struct drm_i915_gem_exec_fence __user *user; -struct drm_syncobj **fences; +struct i915_drm_dma_fences *fences;unsigned long n;int err; -if (!(args->flags &I915_EXEC_FENCE_ARRAY )) -return NULL ; + *out_n_fences = args->num_cliprects;
Same suggestion as earlier for a local num_fences.
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c get_fence_array(struct drm_i915_gem_execbuffer2 *args, · line 2435
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +5
-0+static struct i915_drm_dma_fences * +get_fence_array (struct i915_execbuffer *eb,int *out_n_fences) +{ +if (eb->args->flags &I915_EXEC_FENCE_ARRAY ) +return get_legacy_fence_array (eb, out_n_fences);
Blank line.
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c get_fence_array(struct drm_i915_gem_execbuffer2 *args, · line 2440
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +5
-0+if (eb->extensions.flags &BIT (DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES )) +return get_timeline_fence_array (eb, out_n_fences); + + *out_n_fences =0 ; +
No blank line, my argument is that both are part of the return value for the function.
Quoted 77 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +24
-17+return NULL ; +} +static void -put_fence_array (struct drm_i915_gem_execbuffer2 *args, -struct drm_syncobj **fences) +put_fence_array (struct i915_drm_dma_fences *fences,int nfences) {if (fences) -__free_fence_array (fences, args->num_cliprects); +__free_fence_array (fences, nfences); }static int await_fence_array (struct i915_execbuffer *eb, -struct drm_syncobj **fences) +struct i915_drm_dma_fences *fences, +int nfences) { -const unsigned int nfences = eb->args->num_cliprects;unsigned int n;int err;for (n =0 ; n < nfences; n++) {struct drm_syncobj *syncobj; -struct dma_fence *fence;unsigned int flags; - syncobj =ptr_unpack_bits (fences[n], &flags,2 ); + syncobj =ptr_unpack_bits (fences[n].syncobj, &flags,2 );if (!(flags &I915_EXEC_FENCE_WAIT ))continue ; - fence =drm_syncobj_fence_get (syncobj); -if (!fence) -return -EINVAL ; - - err =i915_request_await_dma_fence (eb->request, fence); -dma_fence_put (fence); + err =i915_request_await_dma_fence (eb->request, + fences[n].dma_fence);if (err <0 )return err; }@@ -2334,9 +2475,9 @@ await_fence_array(struct i915_execbuffer *eb,static void signal_fence_array (struct i915_execbuffer *eb, -struct drm_syncobj **fences) +struct i915_drm_dma_fences *fences, +int nfences) { -const unsigned int nfences = eb->args->num_cliprects;struct dma_fence *const fence = &eb->request->fence;unsigned int n;@@ -2344,15 +2485,43 @@ signal_fence_array(struct i915_execbuffer *eb,struct drm_syncobj *syncobj;unsigned int flags; - syncobj =ptr_unpack_bits (fences[n], &flags,2 ); + syncobj =ptr_unpack_bits (fences[n].syncobj, &flags,2 );if (!(flags &I915_EXEC_FENCE_SIGNAL ))continue ; -drm_syncobj_replace_fence (syncobj, fence); +if (fences[n].chain_fence) { +drm_syncobj_add_point (syncobj, fences[n].chain_fence, + fence, fences[n].value); +/* +* The chain's ownership is transfered to the +* timeline. +*/ + fences[n].chain_fence =NULL ; + }else { +drm_syncobj_replace_fence (syncobj, fence); + }
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c signal_fence_array(struct i915_execbuffer *eb, · line 2512
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +7
-0} } +static int parse_timeline_fences (struct i915_user_extension __user *ext,void *data) +{ +struct i915_execbuffer *eb = data; + +/* Timeline fences are incompatible with the fence array flag. */ +if (eb->args->flags &I915_EXEC_FENCE_ARRAY ) +return -EINVAL ;
Also you only allow one timeline_fence extension struct.
Quoted 134 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +28
-18+ +if (copy_from_user (&eb->extensions.timeline_fences, ext, +sizeof (eb->extensions.timeline_fences))) +return -EFAULT ; + + eb->extensions.flags |=BIT (DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES ); + +return 0 ; +} +static const i915_user_extension_fn execbuf_extensions[] = { + [DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES ] = parse_timeline_fences, }; static int@@ -2372,14 +2541,15 @@ static int i915_gem_do_execbuffer(struct drm_device *dev, struct drm_file *file, struct drm_i915_gem_execbuffer2 *args, - struct drm_i915_gem_exec_object2 *exec, - struct drm_syncobj **fences) + struct drm_i915_gem_exec_object2 *exec) { struct i915_execbuffer eb;struct dma_fence *in_fence =NULL ;struct dma_fence *exec_fence =NULL ;struct sync_file *out_fence =NULL ; +struct i915_drm_dma_fences *fences =NULL ;int out_fence_fd =-1 ; +int nfences =0 ;int err;BUILD_BUG_ON (__EXEC_INTERNAL_FLAGS & ~__I915_EXEC_ILLEGAL_FLAGS);@@ -2421,10 +2591,16 @@ i915_gem_do_execbuffer(struct drm_device *dev,return err; } + fences =get_fence_array (&eb, &nfences); +if (IS_ERR (fences)) +return PTR_ERR (fences); +if (args->flags &I915_EXEC_FENCE_IN ) { in_fence =sync_file_get_fence (lower_32_bits (args->rsvd2)); -if (!in_fence) -return -EINVAL ; +if (!in_fence) { + err = -EINVAL ; + goto err_fences; + } }if (args->flags &I915_EXEC_FENCE_SUBMIT ) {@@ -2582,7 +2758,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, }if (fences) { - err =await_fence_array (&eb, fences); + err =await_fence_array (&eb, fences, nfences);if (err) goto err_request; }@@ -2611,7 +2787,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,i915_request_add (eb.request);if (fences) -signal_fence_array (&eb, fences); +signal_fence_array (&eb, fences, nfences);if (out_fence) {if (err ==0 ) {@@ -2646,6 +2822,8 @@ i915_gem_do_execbuffer(struct drm_device *dev,dma_fence_put (exec_fence); err_in_fence:dma_fence_put (in_fence); +err_fences: +put_fence_array (fences, nfences);return err; }@@ -2739,7 +2917,7 @@ i915_gem_execbuffer_ioctl(struct drm_device *dev, void *data, exec2_list[i].flags =0 ; } - err =i915_gem_do_execbuffer (dev, file, &exec2, exec2_list,NULL ); + err =i915_gem_do_execbuffer (dev, file, &exec2, exec2_list);if (exec2.flags & __EXEC_HAS_RELOC) {struct drm_i915_gem_exec_object __user *user_exec_list =u64_to_user_ptr (args->buffers_ptr);@@ -2770,7 +2948,6 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, {struct drm_i915_gem_execbuffer2 *args = data;struct drm_i915_gem_exec_object2 *exec2_list; -struct drm_syncobj **fences =NULL ;const size_t count = args->buffer_count;int err;@@ -2798,15 +2975,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,return -EFAULT ; } -if (args->flags &I915_EXEC_FENCE_ARRAY ) { - fences =get_fence_array (args, file); -if (IS_ERR (fences)) { -kvfree (exec2_list); -return PTR_ERR (fences); - } - } - - err =i915_gem_do_execbuffer (dev, file, args, exec2_list, fences); + err =i915_gem_do_execbuffer (dev, file, args, exec2_list);/* * Now that we have begun execution of the batchbuffer, we ignore @@ -2846,7 +3015,6 @@ end:; } args->flags &= ~__I915_EXEC_UNKNOWN_FLAGS; -put_fence_array (args, fences);kvfree (exec2_list);return err; }drivers/gpu/drm/i915/i915_drv.c +1
-0@@ -456,6 +456,7 @@ static int i915_getparam_ioctl(struct drm_device *dev, void *data,case I915_PARAM_HAS_EXEC_BATCH_FIRST :case I915_PARAM_HAS_EXEC_FENCE_ARRAY :case I915_PARAM_HAS_EXEC_SUBMIT_FENCE : +case I915_PARAM_HAS_EXEC_TIMELINE_FENCES :/* For the time being all of these are always true; * if some supported hardware does not have one of these * features this value needs to be provided from
drivers/gpu/drm/i915/i915_drv.c static struct drm_driver driver = { · line 3224
Quoted 4 lines
drivers/gpu/drm/i915/i915_drv.c +1
-0@@ -3220,6 +3221,7 @@ static struct drm_driver driver = { .driver_features =DRIVER_GEM |DRIVER_RENDER |DRIVER_MODESET |DRIVER_ATOMIC |DRIVER_SYNCOBJ , + DRIVER_SYNCOBJ_TIMELINE,
With a comma ? i.e. .ioctls = DRIVER_SYNCOBJ_TIMELINE
Quoted 21 lines
drivers/gpu/drm/i915/i915_drv.c +0
-0.release = i915_driver_release, .open = i915_driver_open, .lastclose = i915_driver_lastclose,include/uapi/drm/i915_drm.h +6
-0@@ -617,6 +617,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_PERF_REVISION 54 +/* Query whether DRM_I915_GEM_EXECBUFFER2 supports supplying an array of +* timeline syncobj through drm_i915_gem_execbuf_ext_timeline_fences. See +* I915_EXEC_EXT. +*/ +#define I915_PARAM_HAS_EXEC_TIMELINE_FENCES 55 +/* Must be kept compact -- no holes and well documented */ typedef struct drm_i915_getparam {
include/uapi/drm/i915_drm.h struct drm_i915_gem_exec_fence { · line 1025
Quoted 6 lines
include/uapi/drm/i915_drm.h +3
-0@@ -1014,9 +1020,40 @@ struct drm_i915_gem_exec_fence { };enum drm_i915_gem_execbuffer_ext { +/** +* This identifier is associated with +* drm_i915_gem_execbuf_ext_timeline_fences.
Or just "See drm_i915_gem_execbuf_ext_timeline_fences
include/uapi/drm/i915_drm.h struct drm_i915_gem_exec_fence { · line 1027
Quoted 2 lines
include/uapi/drm/i915_drm.h +2
-0+*/ + DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES,
= 0
don't leave it up to the compiler.
Quoted 6 lines
include/uapi/drm/i915_drm.h +3
-0+ DRM_I915_GEM_EXECBUFFER_EXT_MAX /* non-ABI */ }; +/** +* This structure describes an array of drm_syncobj and associated points for
include/uapi/drm/i915_drm.h struct drm_i915_gem_exec_fence { · line 1043
Quoted 10 lines
include/uapi/drm/i915_drm.h +10
-0+* timeline variants of drm_syncobj. It is invalid to append this structure to +* the execbuf if I915_EXEC_FENCE_ARRAY is set. +*/ +struct drm_i915_gem_execbuffer_ext_timeline_fences { +struct i915_user_extension base; + +/** +* Number of element in the handles_ptr & value_ptr arrays. +*/ +__u64 handle_count;
Since it is used for both, I would use something like fence_count, or num_fences (although _count is in the majority).
include/uapi/drm/i915_drm.h struct drm_i915_gem_exec_fence { · line 1045
Quoted 2 lines
include/uapi/drm/i915_drm.h +2
-0+/** +* Pointer to an array of struct drm_i915_gem_exec_fence of size handle_count.
s/size/length/
I think we typically use size for byte sizes around the uAPI.
Quoted 20 lines
include/uapi/drm/i915_drm.h +10
-0+*/ +__u64 handles_ptr; + +/** +* Pointer to an array of u64 values of size handle_count. Values must +* be 0 for a binary drm_syncobj. +*/ +__u64 values_ptr; +}; +struct drm_i915_gem_execbuffer2 {/** * List of gem_exec_object2 structs Signature · 6 lines
2.21.0.392.gf8f6787159e _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 06/10] drm/i915: add syncobj timeline support
Thanks a lot for your comments.
Quoted 21 lines · Chris Wilson
Quoting Lionel Landwerlin (2019-06-27 09:00:41)
Quoted 20 lines
Introduces a new parameters to execbuf so that we can specify syncobj handles as well as timeline points.
v2: Reuse
i915_user_extension_fnSigned-off-by Lionel Landwerlin <[email protected]>--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 280 ++++++++++++++---- drivers/gpu/drm/i915/i915_drv.c | 2 + include/uapi/drm/i915_drm.h | 37 +++ 3 files changed, 263 insertions(+), 56 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +0
-0@@ -213,6 +213,13 @@ enum {* the batchbuffer in trusted mode, otherwise the ioctl is rejected. */
Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c enum { · line 216
Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1
-0+struct i915_drm_dma_fences {
i915_execbuffer_fencesoreb_fencesas it is private to the impl.
Sure.
Quoted 55 lines
Quoted 11 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +6
-0+struct drm_syncobj *syncobj;/* Use with ptr_mask_bits() */ +struct dma_fence *dma_fence; +u64 value; +struct dma_fence_chain *chain_fence; +}; +struct i915_execbuffer {struct drm_i915_private *i915;/** i915 backpointer */ struct drm_file *file;/** per-file lookup tables and limits */ drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c struct i915_execbuffer { · line 285
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1
-0@@ -275,6 +282,7 @@ struct i915_execbuffer {struct {u64 flags;/** Available extensions parameters */ +struct drm_i915_gem_execbuffer_ext_timeline_fences timeline_fences;Another 40b on stack. Getting closer to those warning bells being set off.
Quoted 26 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +8
-6} extensions; };@@ -2224,67 +2232,193 @@ eb_select_engine(struct i915_execbuffer *eb, }static void -__free_fence_array (struct drm_syncobj **fences,unsigned int n) +__free_fence_array (struct i915_drm_dma_fences *fences,unsigned int n) { -while (n--) -drm_syncobj_put (ptr_mask_bits (fences[n],2 )); +while (n--) { +drm_syncobj_put (ptr_mask_bits (fences[n].syncobj,2 )); +dma_fence_put (fences[n].dma_fence); +kfree (fences[n].chain_fence); + }kvfree (fences); } -static struct drm_syncobj ** -get_fence_array (struct drm_i915_gem_execbuffer2 *args, -struct drm_file *file) +static struct i915_drm_dma_fences * +get_timeline_fence_array (struct i915_execbuffer *eb,int *out_n_fences) {drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c eb_select_engine(struct i915_execbuffer *eb, · line 2256
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +9
-1-const unsigned long nfences = args->num_cliprects; +struct drm_i915_gem_execbuffer_ext_timeline_fences *timeline_fences = + &eb->extensions.timeline_fences; +struct drm_i915_gem_exec_fence __user *user_fences; +struct i915_drm_dma_fences *fences; +u64 __user *user_values; +unsigned long n; +int err; + + *out_n_fences = timeline_fences->handle_count;I'd encourage using a const
num_fences=timeline_fences->handle_countfor readability within the function and then assigning
Quoted 2 lines
*out_n_fences = num_fences;right before the successful return fences;
Done.
Quoted 63 lines
Quoted 51 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +50
-0+/* Check multiplication overflow for access_ok() and kvmalloc_array() */ +BUILD_BUG_ON (sizeof (size_t ) >sizeof (unsigned long )); + if (*out_n_fences > min_t(unsigned long, +ULONG_MAX /sizeof (*user_fences), +SIZE_MAX /sizeof (*fences))) +return ERR_PTR (-EINVAL ); + + user_fences =u64_to_user_ptr (timeline_fences->handles_ptr); +if (!access_ok (user_fences, *out_n_fences *sizeof (*user_fences))) +return ERR_PTR (-EFAULT ); + + user_values =u64_to_user_ptr (timeline_fences->values_ptr); +if (!access_ok (user_values, *out_n_fences *sizeof (*user_values))) +return ERR_PTR (-EFAULT ); + fences =kvmalloc_array (*out_n_fences,sizeof (*fences), + __GFP_NOWARN |GFP_KERNEL ); +if (!fences) +return ERR_PTR (-ENOMEM ); + +BUILD_BUG_ON (~(ARCH_KMALLOC_MINALIGN -1 ) & + ~__I915_EXEC_FENCE_UNKNOWN_FLAGS); + +for (n =0 ; n < *out_n_fences; n++) { +struct drm_i915_gem_exec_fence user_fence; +struct drm_syncobj *syncobj; +struct dma_fence *fence =NULL ; +u64 point; + +if (__copy_from_user (&user_fence, user_fences++,sizeof (user_fence))) { + err = -EFAULT ; + goto err; + } + +if (user_fence.flags & __I915_EXEC_FENCE_UNKNOWN_FLAGS) { + err = -EINVAL ; + goto err; + } + +if (__get_user (point, user_values++)) { + err = -EFAULT ; + goto err; + } + + syncobj =drm_syncobj_find (eb->file, user_fence.handle); +if (!syncobj) { +DRM_DEBUG ("Invalid syncobj handle provided\n" ); + err = -EINVAL ; + goto err; + } +drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c eb_select_engine(struct i915_execbuffer *eb, · line 2318
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +10
-0+if (user_fence.flags &I915_EXEC_FENCE_WAIT ) { + fence =drm_syncobj_fence_get (syncobj); +if (!fence) { +DRM_DEBUG ("Syncobj handle has no fence\n" ); +drm_syncobj_put (syncobj); + err = -EINVAL ; + goto err; + } + + err =dma_fence_chain_find_seqno (&fence, point);Is an imported syncobj always a fence-chain?
Quoted 1 line
drm_syncobj_import_sync_file_fence()says no.
drm_syncobj_import_sync_file_fence() would turn a timeline semaphore into a binary semaphore by breaking the chain.
drm_syncobj_transfer_to_timeline() is what you should use if you wish to import a fence into the timeline.
Quoted 11 lines
Similarly, we put ordinary fences into the syncobj ourselves if point==0, or the user uses the old path.
I think you need something like
if (dma_fence_is_chain() || point) { err = dma_fence_chain_find_seqno(&fence, point); if (err) { } }
dma_fence_chain_find_seqno() already deals with point == 0.
If the fence is not a dma_fence_chain then the application screwed up somewhere.
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c eb_select_engine(struct i915_execbuffer *eb, · line 2326
Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +8
-0+if (err) { +DRM_DEBUG ("Syncobj handle missing requested point\n" ); + goto err; + } + } + +/* +* For timeline syncobjs we need to create a chain. "need to preallocate chains for later signaling
Sure.
Quoted 40 lines
Quoted 40 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +34
-1+*/ +if (point !=0 && user_fence.flags &I915_EXEC_FENCE_SIGNAL ) { + fences[n].chain_fence = +kmalloc (sizeof (*fences[n].chain_fence), +GFP_KERNEL ); +if (!fences[n].chain_fence) { +dma_fence_put (fence); +drm_syncobj_put (syncobj); + err = -ENOMEM ; +DRM_DEBUG ("Unable to alloc chain_fence\n" ); + goto err; + } + }else { + fences[n].chain_fence =NULL ; + } + + fences[n].syncobj =ptr_pack_bits (syncobj, user_fence.flags,2 ); + fences[n].dma_fence = fence; + fences[n].value = point; + } + +return fences; + +err: +__free_fence_array (fences, n); +return ERR_PTR (err); +} + +static struct i915_drm_dma_fences * +get_legacy_fence_array (struct i915_execbuffer *eb, +int *out_n_fences) +{ +struct drm_i915_gem_execbuffer2 *args = eb->args;struct drm_i915_gem_exec_fence __user *user; -struct drm_syncobj **fences; +struct i915_drm_dma_fences *fences;unsigned long n;int err;
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c eb_select_engine(struct i915_execbuffer *eb, · line 2365
Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1
-2-if (!(args->flags &I915_EXEC_FENCE_ARRAY )) -return NULL ; + *out_n_fences = args->num_cliprects;Same suggestion as earlier for a local
num_fences.
Done.
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c get_fence_array(struct drm_i915_gem_execbuffer2 *args, · line 2435
Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +5
-0+static struct i915_drm_dma_fences * +get_fence_array (struct i915_execbuffer *eb,int *out_n_fences) +{ +if (eb->args->flags &I915_EXEC_FENCE_ARRAY ) +return get_legacy_fence_array (eb, out_n_fences);Blank line.
Oops.
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c get_fence_array(struct drm_i915_gem_execbuffer2 *args, · line 2440
Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +5
-0+if (eb->extensions.flags &BIT (DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES )) +return get_timeline_fence_array (eb, out_n_fences); + + *out_n_fences =0 ; +No blank line, my argument is that both are part of the return value for the function.
Okay.
Quoted 80 lines
Quoted 80 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +24
-17+return NULL ; +} +static void -put_fence_array (struct drm_i915_gem_execbuffer2 *args, -struct drm_syncobj **fences) +put_fence_array (struct i915_drm_dma_fences *fences,int nfences) {if (fences) -__free_fence_array (fences, args->num_cliprects); +__free_fence_array (fences, nfences); }static int await_fence_array (struct i915_execbuffer *eb, -struct drm_syncobj **fences) +struct i915_drm_dma_fences *fences, +int nfences) { -const unsigned int nfences = eb->args->num_cliprects;unsigned int n;int err;for (n =0 ; n < nfences; n++) {struct drm_syncobj *syncobj; -struct dma_fence *fence;unsigned int flags; - syncobj =ptr_unpack_bits (fences[n], &flags,2 ); + syncobj =ptr_unpack_bits (fences[n].syncobj, &flags,2 );if (!(flags &I915_EXEC_FENCE_WAIT ))continue ; - fence =drm_syncobj_fence_get (syncobj); -if (!fence) -return -EINVAL ; - - err =i915_request_await_dma_fence (eb->request, fence); -dma_fence_put (fence); + err =i915_request_await_dma_fence (eb->request, + fences[n].dma_fence);if (err <0 )return err; }@@ -2334,9 +2475,9 @@ await_fence_array(struct i915_execbuffer *eb,static void signal_fence_array (struct i915_execbuffer *eb, -struct drm_syncobj **fences) +struct i915_drm_dma_fences *fences, +int nfences) { -const unsigned int nfences = eb->args->num_cliprects;struct dma_fence *const fence = &eb->request->fence;unsigned int n;@@ -2344,15 +2485,43 @@ signal_fence_array(struct i915_execbuffer *eb,struct drm_syncobj *syncobj;unsigned int flags; - syncobj =ptr_unpack_bits (fences[n], &flags,2 ); + syncobj =ptr_unpack_bits (fences[n].syncobj, &flags,2 );if (!(flags &I915_EXEC_FENCE_SIGNAL ))continue ; -drm_syncobj_replace_fence (syncobj, fence); +if (fences[n].chain_fence) { +drm_syncobj_add_point (syncobj, fences[n].chain_fence, + fence, fences[n].value); +/* +* The chain's ownership is transfered to the +* timeline. +*/ + fences[n].chain_fence =NULL ; + }else { +drm_syncobj_replace_fence (syncobj, fence); + } } }
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c signal_fence_array(struct i915_execbuffer *eb, · line 2512
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +7
-0+static int parse_timeline_fences (struct i915_user_extension __user *ext,void *data) +{ +struct i915_execbuffer *eb = data; + +/* Timeline fences are incompatible with the fence array flag. */ +if (eb->args->flags &I915_EXEC_FENCE_ARRAY ) +return -EINVAL ;Also you only allow one
timeline_fenceextension struct.
Well spotted, thanks.
Quoted 132 lines
Quoted 132 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +28
-18+ +if (copy_from_user (&eb->extensions.timeline_fences, ext, +sizeof (eb->extensions.timeline_fences))) +return -EFAULT ; + + eb->extensions.flags |=BIT (DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES ); + +return 0 ; +} +static const i915_user_extension_fn execbuf_extensions[] = { + [DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES ] = parse_timeline_fences, }; static int@@ -2372,14 +2541,15 @@ static int i915_gem_do_execbuffer(struct drm_device *dev, struct drm_file *file, struct drm_i915_gem_execbuffer2 *args, - struct drm_i915_gem_exec_object2 *exec, - struct drm_syncobj **fences) + struct drm_i915_gem_exec_object2 *exec) { struct i915_execbuffer eb;struct dma_fence *in_fence =NULL ;struct dma_fence *exec_fence =NULL ;struct sync_file *out_fence =NULL ; +struct i915_drm_dma_fences *fences =NULL ;int out_fence_fd =-1 ; +int nfences =0 ;int err;BUILD_BUG_ON (__EXEC_INTERNAL_FLAGS & ~__I915_EXEC_ILLEGAL_FLAGS);@@ -2421,10 +2591,16 @@ i915_gem_do_execbuffer(struct drm_device *dev,return err; } + fences =get_fence_array (&eb, &nfences); +if (IS_ERR (fences)) +return PTR_ERR (fences); +if (args->flags &I915_EXEC_FENCE_IN ) { in_fence =sync_file_get_fence (lower_32_bits (args->rsvd2)); -if (!in_fence) -return -EINVAL ; +if (!in_fence) { + err = -EINVAL ; + goto err_fences; + } }if (args->flags &I915_EXEC_FENCE_SUBMIT ) {@@ -2582,7 +2758,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, }if (fences) { - err =await_fence_array (&eb, fences); + err =await_fence_array (&eb, fences, nfences);if (err) goto err_request; }@@ -2611,7 +2787,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,i915_request_add (eb.request);if (fences) -signal_fence_array (&eb, fences); +signal_fence_array (&eb, fences, nfences);if (out_fence) {if (err ==0 ) {@@ -2646,6 +2822,8 @@ i915_gem_do_execbuffer(struct drm_device *dev,dma_fence_put (exec_fence); err_in_fence:dma_fence_put (in_fence); +err_fences: +put_fence_array (fences, nfences);return err; }@@ -2739,7 +2917,7 @@ i915_gem_execbuffer_ioctl(struct drm_device *dev, void *data, exec2_list[i].flags =0 ; } - err =i915_gem_do_execbuffer (dev, file, &exec2, exec2_list,NULL ); + err =i915_gem_do_execbuffer (dev, file, &exec2, exec2_list);if (exec2.flags & __EXEC_HAS_RELOC) {struct drm_i915_gem_exec_object __user *user_exec_list =u64_to_user_ptr (args->buffers_ptr);@@ -2770,7 +2948,6 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, {struct drm_i915_gem_execbuffer2 *args = data;struct drm_i915_gem_exec_object2 *exec2_list; -struct drm_syncobj **fences =NULL ;const size_t count = args->buffer_count;int err;@@ -2798,15 +2975,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,return -EFAULT ; } -if (args->flags &I915_EXEC_FENCE_ARRAY ) { - fences =get_fence_array (args, file); -if (IS_ERR (fences)) { -kvfree (exec2_list); -return PTR_ERR (fences); - } - } - - err =i915_gem_do_execbuffer (dev, file, args, exec2_list, fences); + err =i915_gem_do_execbuffer (dev, file, args, exec2_list);/* * Now that we have begun execution of the batchbuffer, we ignore @@ -2846,7 +3015,6 @@ end:; } args->flags &= ~__I915_EXEC_UNKNOWN_FLAGS; -put_fence_array (args, fences);kvfree (exec2_list);return err; }drivers/gpu/drm/i915/i915_drv.c +1
-0@@ -456,6 +456,7 @@ static int i915_getparam_ioctl(struct drm_device *dev, void *data,case I915_PARAM_HAS_EXEC_BATCH_FIRST :case I915_PARAM_HAS_EXEC_FENCE_ARRAY :case I915_PARAM_HAS_EXEC_SUBMIT_FENCE : +case I915_PARAM_HAS_EXEC_TIMELINE_FENCES :/* For the time being all of these are always true;
Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.c static struct drm_driver driver = { · line 3224
Quoted 7 lines
drivers/gpu/drm/i915/i915_drv.c +1
-0* if some supported hardware does not have one of these * features this value needs to be provided from @@ -3220,6 +3221,7 @@ static struct drm_driver driver = { .driver_features =DRIVER_GEM |DRIVER_RENDER |DRIVER_MODESET |DRIVER_ATOMIC |DRIVER_SYNCOBJ , + DRIVER_SYNCOBJ_TIMELINE,With a comma ? i.e. .ioctls =
DRIVER_SYNCOBJ_TIMELINE
Waaaat. How am I running a this and it works....?
Quoted 29 lines
Quoted 22 lines
drivers/gpu/drm/i915/i915_drv.c +0
-0.release = i915_driver_release, .open = i915_driver_open, .lastclose = i915_driver_lastclose,include/uapi/drm/i915_drm.h +6
-0@@ -617,6 +617,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_PERF_REVISION 54 +/* Query whether DRM_I915_GEM_EXECBUFFER2 supports supplying an array of +* timeline syncobj through drm_i915_gem_execbuf_ext_timeline_fences. See +* I915_EXEC_EXT. +*/ +#define I915_PARAM_HAS_EXEC_TIMELINE_FENCES 55 +/* Must be kept compact -- no holes and well documented */ typedef struct drm_i915_getparam {include/uapi/drm/i915_drm.h struct drm_i915_gem_exec_fence { · line 1025
Quoted 6 lines
include/uapi/drm/i915_drm.h +3
-0@@ -1014,9 +1020,40 @@ struct drm_i915_gem_exec_fence { };enum drm_i915_gem_execbuffer_ext { +/** +* This identifier is associated with +* drm_i915_gem_execbuf_ext_timeline_fences. Or just "See
drm_i915_gem_execbuf_ext_timeline_fences
Quoted 4 lines
include/uapi/drm/i915_drm.h struct drm_i915_gem_exec_fence { · line 1027
Quoted 2 lines
include/uapi/drm/i915_drm.h +2
-0+*/ + DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES,= 0
don't leave it up to the compiler.
Should we set every single item in the enum or just the first one?
Quoted 4 lines
Quoted 4 lines
include/uapi/drm/i915_drm.h +1
-0+ DRM_I915_GEM_EXECBUFFER_EXT_MAX /* non-ABI */ };
Quoted 14 lines
include/uapi/drm/i915_drm.h struct drm_i915_gem_exec_fence { · line 1043
Quoted 12 lines
include/uapi/drm/i915_drm.h +12
-0+/** +* This structure describes an array of drm_syncobj and associated points for +* timeline variants of drm_syncobj. It is invalid to append this structure to +* the execbuf if I915_EXEC_FENCE_ARRAY is set. +*/ +struct drm_i915_gem_execbuffer_ext_timeline_fences { +struct i915_user_extension base; + +/** +* Number of element in the handles_ptr & value_ptr arrays. +*/ +__u64 handle_count;Since it is used for both, I would use something like
fence_count, ornum_fences(although_countis in the majority).
Done.
Quoted 6 lines
include/uapi/drm/i915_drm.h struct drm_i915_gem_exec_fence { · line 1045
Quoted 3 lines
include/uapi/drm/i915_drm.h +2
-0+/** +* Pointer to an array of struct drm_i915_gem_exec_fence of size handle_count. s/size/length/
I think we typically use size for byte sizes around the uAPI.
Sure.
Quoted 17 lines
Quoted 17 lines
include/uapi/drm/i915_drm.h +10
-0+*/ +__u64 handles_ptr; + +/** +* Pointer to an array of u64 values of size handle_count. Values must +* be 0 for a binary drm_syncobj. +*/ +__u64 values_ptr; +}; +struct drm_i915_gem_execbuffer2 {/** * List of gem_exec_object2 structs Signature · 1 line
2.21.0.392.gf8f6787159e
Quoted 4 lines
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 06/10] drm/i915: add syncobj timeline support
Quoting Lionel Landwerlin (2019-06-27 11:49:56)
Quoted 22 lines
Thanks a lot for your comments.
Quoted 19 lines · Chris Wilson
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +7
-0+ syncobj =drm_syncobj_find (eb->file, user_fence.handle); +if (!syncobj) { +DRM_DEBUG ("Invalid syncobj handle provided\n" ); + err = -EINVAL ; + goto err; + } +drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c eb_select_engine(struct i915_execbuffer *eb, · line 2318
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +10
-0+if (user_fence.flags &I915_EXEC_FENCE_WAIT ) { + fence =drm_syncobj_fence_get (syncobj); +if (!fence) { +DRM_DEBUG ("Syncobj handle has no fence\n" ); +drm_syncobj_put (syncobj); + err = -EINVAL ; + goto err; + } + + err =dma_fence_chain_find_seqno (&fence, point);Is an imported syncobj always a fence-chain?
Quoted 8 lines
Quoted 1 line
drm_syncobj_import_sync_file_fence()says no.
drm_syncobj_import_sync_file_fence()would turn a timeline semaphore into a binary semaphore by breaking the chain.
drm_syncobj_transfer_to_timeline()is what you should use if you wish to import a fence into the timeline.
What I am worrying about is the legality of the user passing in a non-timeline fence here. It looks like the interface will itself generate non-timeline fences... Oh, ignore me, I overlooked the early return for !seqno.
So timelines are not allowed to use 0. Ever. That's a bit more of a hard rule than implied by the uapi.h :)
Quoted 8 lines
Quoted 8 lines
include/uapi/drm/i915_drm.h struct drm_i915_gem_exec_fence { · line 1025
Quoted 7 lines
include/uapi/drm/i915_drm.h +3
-0@@ -1014,9 +1020,40 @@ struct drm_i915_gem_exec_fence { };enum drm_i915_gem_execbuffer_ext { +/** +* This identifier is associated with +* drm_i915_gem_execbuf_ext_timeline_fences. Or just "See
drm_i915_gem_execbuf_ext_timeline_fences
Quoted 7 lines
Quoted 4 lines
include/uapi/drm/i915_drm.h struct drm_i915_gem_exec_fence { · line 1027
Quoted 2 lines
include/uapi/drm/i915_drm.h +2
-0+*/ + DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES,= 0
don't leave it up to the compiler.Should we set every single item in the enum or just the first one?
We've been setting the first one to be explicit (doubly useful when we want a certain value to be documented to be 0), and then gaps. The spec says that each id is incremented by one from the previous, it's just the first value and natural type of the enum is up to the compiler. -Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 06/10] drm/i915: add syncobj timeline support
Quoted 28 lines · Chris Wilson
Quoting Lionel Landwerlin (2019-06-27 11:49:56)
Quoted 27 lines
Thanks a lot for your comments.
Quoted 19 lines · Chris Wilson
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +7
-0+ syncobj =drm_syncobj_find (eb->file, user_fence.handle); +if (!syncobj) { +DRM_DEBUG ("Invalid syncobj handle provided\n" ); + err = -EINVAL ; + goto err; + } +drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c eb_select_engine(struct i915_execbuffer *eb, · line 2318
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +10
-0+if (user_fence.flags &I915_EXEC_FENCE_WAIT ) { + fence =drm_syncobj_fence_get (syncobj); +if (!fence) { +DRM_DEBUG ("Syncobj handle has no fence\n" ); +drm_syncobj_put (syncobj); + err = -EINVAL ; + goto err; + } + + err =dma_fence_chain_find_seqno (&fence, point);Is an imported syncobj always a fence-chain?
Quoted 1 line
drm_syncobj_import_sync_file_fence()says no.
drm_syncobj_import_sync_file_fence()would turn a timeline semaphore into a binary semaphore by breaking the chain.
Quoted 6 lines
Quoted 2 lines
drm_syncobj_transfer_to_timeline()is what you should use if you wish to import a fence into the timeline.What I am worrying about is the legality of the user passing in a non-timeline fence here. It looks like the interface will itself generate non-timeline fences... Oh, ignore me, I overlooked the early return for !seqno.
I wrote that down in my reply then deleted it ;)
Quoted 3 lines
So timelines are not allowed to use 0. Ever. That's a bit more of a hard rule than implied by the
uapi.h:)
Anv turns any signal/wait on 0 into NOOP, those never reach i915.
The spec is pretty clear that point 0 is always signaled.
I'll add a statement with regard to timeline semaphores.
Thanks!
-Lionel
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
include/uapi/drm/i915_drm.h struct drm_i915_gem_exec_fence { · line 1025
Quoted 8 lines
include/uapi/drm/i915_drm.h +3
-0@@ -1014,9 +1020,40 @@ struct drm_i915_gem_exec_fence { };enum drm_i915_gem_execbuffer_ext { +/** +* This identifier is associated with +* drm_i915_gem_execbuf_ext_timeline_fences. Or just "See
drm_i915_gem_execbuf_ext_timeline_fencesinclude/uapi/drm/i915_drm.h struct drm_i915_gem_exec_fence { · line 1027
Quoted 2 lines
include/uapi/drm/i915_drm.h +2
-0+*/ + DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES,= 0
don't leave it up to the compiler.
Quoted 7 lines
Quoted 1 line
Should we set every single item in the enum or just the first one?
We've been setting the first one to be explicit (doubly useful when we want a certain value to be documented to be 0), and then gaps. The spec says that each id is incremented by one from the previous, it's just the first value and natural type of the enum is up to the compiler. -Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 7/10 drm/i915: add a new perf configuration execbuf parameter
In reply to Lionel LandwerlinWe want the ability to dispatch a set of command buffer to the hardware, each with a different OA configuration. To achieve this, we reuse a couple of fields from the execbuf2 struct (I CAN HAZ execbuf3?) to notify what OA configuration should be used for a batch buffer. This requires the process making the execbuf with this flag to also own the perf fd at the time of execbuf.
v2: Add a emit_oa_config() vfunc in the intel_engine_cs (Chris)
Move oa_config vma to active (Chris)
v3: Don't drop the lock for engine lookup (Chris)
Move OA config vma to active before writing the ringbuffer (Chris)
v4: Reuse i915_user_extension_fn
Serialize requests with OA config updates
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 130 +++++++++++++++++- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 2 + drivers/gpu/drm/i915/gt/intel_engine_types.h | 9 ++ drivers/gpu/drm/i915/gt/intel_lrc.c | 1 + drivers/gpu/drm/i915/gt/intel_ringbuffer.c | 4 +- drivers/gpu/drm/i915/i915_drv.c | 4 + drivers/gpu/drm/i915/i915_drv.h | 10 +- drivers/gpu/drm/i915/i915_perf.c | 26 ++-- include/uapi/drm/i915_drm.h | 37 +++++ 9 files changed, 208 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +129 -1
@@ -283,7 +283,11 @@ struct i915_execbuffer {struct {u64 flags;/** Available extensions parameters */ struct drm_i915_gem_execbuffer_ext_timeline_fences timeline_fences; +struct drm_i915_gem_execbuffer_ext_perf perf_config; } extensions; + +struct i915_oa_config *oa_config;/** HW configuration for OA, NULL is not needed. */ +struct drm_i915_gem_object *oa_bo; };#define exec_entry (EB ,VMA ) (&(EB)->exec[(VMA)->exec_flags - (EB)->flags])
@@ -1210,6 +1214,34 @@ static int reloc_move_to_gpu(struct i915_request *rq, struct i915_vma *vma)return err; } + +static int +get_execbuf_oa_config (struct drm_i915_private *dev_priv, +s32 perf_fd,u64 oa_config_id, +struct i915_oa_config **out_oa_config, +struct drm_i915_gem_object **out_oa_obj) +{ +struct file *perf_file; +int ret; + +if (!dev_priv->perf.oa.exclusive_stream) +return -EINVAL ; + + perf_file =fget (perf_fd); +if (!perf_file) +return -EINVAL ; + +if (perf_file->private_data != dev_priv->perf.oa.exclusive_stream) +return -EINVAL ; + +fput (perf_file); + + ret =i915_perf_get_oa_config (dev_priv, oa_config_id, + out_oa_config, out_oa_obj); + +return ret; +} +static int __reloc_gpu_alloc (struct i915_execbuffer *eb,struct i915_vma *vma,unsigned int len)
@@ -2072,6 +2104,64 @@ add_to_client(struct i915_request *rq, struct drm_file *file)list_add_tail (&rq->client_link, &rq->file_priv->mm.request_list); } +static int eb_oa_config (struct i915_execbuffer *eb) +{ +struct i915_vma *oa_vma; +int err; + +if (!eb->oa_config) +return 0 ; + + err =i915_active_request_set (&eb->engine->last_oa_config, + eb->request); +if (err) +return err; + +/* +* If the perf stream was opened with hold preemption, flag the +* request properly so that the priority of the request is bumped once +* it reaches the execlist ports. +*/ +if (eb->i915->perf.oa.exclusive_stream->hold_preemption) + eb->request->has_perf = true; + +/* +* If the config hasn't changed, skip reconfiguring the HW (this is +* subject to a delay we want to avoid has much as possible). +*/ +if (eb->oa_config == eb->i915->perf.oa.exclusive_stream->oa_config) +return 0 ; + + oa_vma =i915_vma_instance (eb->oa_bo, + &eb->engine->i915->ggtt.vm,NULL ); +if (unlikely (IS_ERR (oa_vma))) +return PTR_ERR (oa_vma); + + err =i915_vma_pin (oa_vma,0 ,0 ,PIN_GLOBAL ); +if (err) +return err; + + err =i915_vma_move_to_active (oa_vma, eb->request,0 ); +if (err) { +i915_vma_unpin (oa_vma); +return err; + } + + err = eb->engine->emit_bb_start (eb->request, + oa_vma->node.start, +0 ,I915_DISPATCH_SECURE ); +if (err) { +i915_vma_unpin (oa_vma); +return err; + } + +i915_vma_unpin (oa_vma); + +swap (eb->oa_config, eb->i915->perf.oa.exclusive_stream->oa_config); + +return 0 ; +} +static int eb_submit (struct i915_execbuffer *eb) {int err;
@@ -2098,6 +2188,10 @@ static int eb_submit(struct i915_execbuffer *eb)return err; } + err =eb_oa_config (eb); +if (err) +return err; + err = eb->engine->emit_bb_start(eb->request, eb->batch->node.start + eb->batch_start_offset,
@@ -2520,8 +2614,22 @@ static int parse_timeline_fences(struct i915_user_extension __user *ext, void *dreturn 0 ; } +static int parse_perf_config (struct i915_user_extension __user *ext,void *data) +{ +struct i915_execbuffer *eb = data; + +if (copy_from_user (&eb->extensions.perf_config, ext, +sizeof (eb->extensions.perf_config))) +return -EFAULT ; + + eb->extensions.flags |=BIT (DRM_I915_GEM_EXECBUFFER_EXT_PERF ); + +return 0 ; +} +static const i915_user_extension_fn execbuf_extensions[] = { [DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES ] = parse_timeline_fences, + [DRM_I915_GEM_EXECBUFFER_EXT_PERF ] = parse_perf_config, }; static int
@@ -2573,6 +2681,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, eb.buffer_count = args->buffer_count; eb.batch_start_offset = args->batch_start_offset; eb.batch_len = args->batch_len; + eb.oa_config =NULL ; eb.batch_flags =0 ;if (args->flags &I915_EXEC_SECURE ) {
@@ -2651,9 +2760,23 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (unlikely (err)) goto err_unlock; +if (eb.extensions.flags &BIT (DRM_I915_GEM_EXECBUFFER_EXT_PERF )) { +if (!intel_engine_has_oa (eb.engine)) { + err = -ENODEV ; + goto err_engine; + } + + err =get_execbuf_oa_config (eb.i915, + eb.extensions.perf_config.perf_fd, + eb.extensions.perf_config.oa_config, + &eb.oa_config, &eb.oa_bo); +if (err) + goto err_engine; + } + err =eb_wait_for_ring (&eb);/* may temporarily drop struct_mutex */ if (unlikely (err)) - goto err_engine; + goto err_oa; err =eb_relocate (&eb);if (err) {
@@ -2806,6 +2929,11 @@ i915_gem_do_execbuffer(struct drm_device *dev, err_vma:if (eb.exec)eb_release_vmas (&eb); +err_oa: +if (eb.oa_config) { +i915_gem_object_put (eb.oa_bo); +i915_oa_config_put (eb.oa_config); + } err_engine:eb_unpin_context (&eb); err_unlock:
drivers/gpu/drm/i915/gt/intel_engine_cs.c +2 -0
@@ -859,6 +859,8 @@ int intel_engine_init_common(struct intel_engine_cs *engine) engine->set_default_submission (engine); +INIT_ACTIVE_REQUEST (&engine->last_oa_config); +return 0 ; err_unpin:
drivers/gpu/drm/i915/gt/intel_engine_types.h +9 -0
@@ -363,6 +363,8 @@ struct intel_engine_cs {struct i915_wa_list wa_list;struct i915_wa_list whitelist; +struct i915_active_request last_oa_config; +u32 irq_keep_mask;/* always keep these interrupts */ u32 irq_enable_mask;/* bitmask to enable ring interrupt */ void (*irq_enable)(struct intel_engine_cs *engine);
@@ -446,6 +448,7 @@ struct intel_engine_cs {#define I915_ENGINE_HAS_SEMAPHORES BIT(3)#define I915_ENGINE_NEEDS_BREADCRUMB_TASKLET BIT(4)#define I915_ENGINE_IS_VIRTUAL BIT(5) +#define I915_ENGINE_HAS_OA BIT(6)unsigned int flags;/*
@@ -541,6 +544,12 @@ intel_engine_is_virtual(const struct intel_engine_cs *engine)return engine->flags &I915_ENGINE_IS_VIRTUAL ; } +static inline bool +intel_engine_has_oa (const struct intel_engine_cs *engine) +{ +return engine->flags &I915_ENGINE_HAS_OA ; +} +#define instdone_slice_mask (dev_priv__) \ (IS_GEN(dev_priv__, 7) ? \ 1 : RUNTIME_INFO(dev_priv__)->sseu.slice_mask)
drivers/gpu/drm/i915/gt/intel_lrc.c +1 -0
@@ -2763,6 +2763,7 @@ int intel_execlists_submission_setup(struct intel_engine_cs *engine) engine->init_context = gen8_init_rcs_context; engine->emit_flush = gen8_emit_flush_render; engine->emit_fini_breadcrumb = gen8_emit_fini_breadcrumb_rcs; + engine->flags |=I915_ENGINE_HAS_OA ; }return 0 ;
drivers/gpu/drm/i915/gt/intel_ringbuffer.c +3 -1
@@ -2192,8 +2192,10 @@ static void setup_rcs(struct intel_engine_cs *engine) engine->irq_enable_mask =I915_USER_INTERRUPT ; } -if (IS_HASWELL (i915)) +if (IS_HASWELL (i915)) { engine->emit_bb_start = hsw_emit_bb_start; + engine->flags |=I915_ENGINE_HAS_OA ; + } engine->resume = rcs_resume; }
drivers/gpu/drm/i915/i915_drv.c +4 -0
@@ -486,6 +486,10 @@ static int i915_getparam_ioctl(struct drm_device *dev, void *data,case I915_PARAM_PERF_REVISION : value =1 ;break ; +case I915_PARAM_HAS_EXEC_PERF_CONFIG : +/* Obviously requires perf support. */ + value = dev_priv->perf.initialized; +break ;default :DRM_DEBUG ("Unknown parameter %d\n" , param->param);return -EINVAL ;
drivers/gpu/drm/i915/i915_drv.h +9 -1
@@ -1096,6 +1096,8 @@ struct i915_oa_reg { };struct i915_oa_config { +struct drm_i915_private *i915; +char uuid[UUID_STRING_LEN +1 ];int id;
@@ -1114,7 +1116,7 @@ struct i915_oa_config {struct list_head vma_link; -atomic_t ref_count; +struct kref ref; };struct i915_perf_stream ;
@@ -2612,6 +2614,12 @@ int i915_perf_get_oa_config(struct drm_i915_private *i915,int metrics_set, struct i915_oa_config **out_config, struct drm_i915_gem_object **out_obj); +void i915_oa_config_release (struct kref *ref); + +static inline void i915_oa_config_put (struct i915_oa_config *oa_config) +{ +kref_put (&oa_config->ref, i915_oa_config_release); +}/* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct i915_address_space *vm,
drivers/gpu/drm/i915/i915_perf.c +14 -12
@@ -366,10 +366,11 @@ struct perf_open_properties {int oa_period_exponent; }; -static void put_oa_config (struct i915_oa_config *oa_config) +void i915_oa_config_release (struct kref *ref) { -if (!atomic_dec_and_test (&oa_config->ref_count)) -return ; +struct i915_oa_config *oa_config =container_of (ref,typeof (*oa_config), ref); + +lockdep_assert_held (&oa_config->i915->perf.metrics_lock);if (oa_config->obj) {list_del (&oa_config->vma_link);
@@ -485,7 +486,7 @@ int i915_perf_get_oa_config(struct drm_i915_private *i915, }if (out_config) { -atomic_inc (&oa_config->ref_count); +kref_get (&oa_config->ref); *out_config = oa_config; }
@@ -507,7 +508,7 @@ int i915_perf_get_oa_config(struct drm_i915_private *i915, err_buf_alloc:if (out_config) { -put_oa_config (oa_config); +i915_oa_config_put (oa_config); *out_config =NULL ; } unlock:
@@ -1483,7 +1484,7 @@ static void i915_oa_stream_destroy(struct i915_perf_stream *stream)if (stream->ctx)oa_put_render_ctx_id (stream); -put_oa_config (stream->oa_config); +i915_oa_config_put (stream->oa_config);if (dev_priv->perf.oa.spurious_report_rs.missed) { DRM_NOTE("%d spurious OA report notices suppressed due to ratelimiting\n",
@@ -2430,7 +2431,7 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,free_oa_buffer (dev_priv); err_oa_buf_alloc: -put_oa_config (stream->oa_config); +i915_oa_config_put (stream->oa_config);intel_uncore_forcewake_put (&dev_priv->uncore,FORCEWAKE_ALL );intel_runtime_pm_put (&dev_priv->runtime_pm, stream->wakeref);
@@ -3246,7 +3247,7 @@ void i915_perf_register(struct drm_i915_private *dev_priv)if (ret) goto sysfs_error; -atomic_set (&dev_priv->perf.oa.test_config.ref_count,1 ); + dev_priv->perf.oa.test_config.i915 = dev_priv; goto exit;
@@ -3502,7 +3503,8 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,return -ENOMEM ; } -atomic_set (&oa_config->ref_count,1 ); + oa_config->i915 = dev_priv; +kref_init (&oa_config->ref);if (!uuid_is_valid (args->uuid)) {DRM_DEBUG ("Invalid uuid format for OA config\n" );
@@ -3601,7 +3603,7 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data, sysfs_err:mutex_unlock (&dev_priv->perf.metrics_lock); reg_err: -put_oa_config (oa_config); +i915_oa_config_put (oa_config);DRM_DEBUG ("Failed to add new OA config\n" );return err; }
@@ -3655,7 +3657,7 @@ int i915_perf_remove_config_ioctl(struct drm_device *dev, void *data,DRM_DEBUG ("Removed config %s id=%i\n" , oa_config->uuid, oa_config->id); -put_oa_config (oa_config); +i915_oa_config_put (oa_config); config_err:mutex_unlock (&dev_priv->perf.metrics_lock);
@@ -3824,7 +3826,7 @@ static int destroy_config(int id, void *p, void *data) {struct i915_oa_config *oa_config = p; -put_oa_config (oa_config); +i915_oa_config_put (oa_config);return 0 ; }
include/uapi/drm/i915_drm.h +37 -0
@@ -623,6 +623,16 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_HAS_EXEC_TIMELINE_FENCES 55 +/* +* Request an i915/perf performance configuration change before running the +* commands given in an execbuf. +* +* Performance configuration ID and the file descriptor of the i915 perf +* stream are given through drm_i915_gem_execbuffer_ext_perf. See +* I915_EXEC_EXT. +*/ +#define I915_PARAM_HAS_EXEC_PERF_CONFIG 56 +/* Must be kept compact -- no holes and well documented */ typedef struct drm_i915_getparam {
@@ -1026,6 +1036,12 @@ enum drm_i915_gem_execbuffer_ext {*/ DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES , +/** +* This identifier is associated with +* drm_i915_gem_execbuffer_perf_ext. +*/ +DRM_I915_GEM_EXECBUFFER_EXT_PERF , + DRM_I915_GEM_EXECBUFFER_EXT_MAX /* non-ABI */ };
@@ -1054,6 +1070,27 @@ struct drm_i915_gem_execbuffer_ext_timeline_fences {__u64 values_ptr; }; +struct drm_i915_gem_execbuffer_ext_perf { +struct i915_user_extension base; + +/** +* Performance file descriptor returned by DRM_IOCTL_I915_PERF_OPEN. +* This is used to identify that the application +*/ +__s32 perf_fd; + +/** +* Unused for now. Must be cleared to zero. +*/ +__u32 pad; + +/** +* OA configuration ID to switch to before executing the commands +* associated to the execbuf. +*/ +__u64 oa_config; +}; +struct drm_i915_gem_execbuffer2 {/** * List of gem_exec_object2 structs
Signature · 6 lines
2.21.0.392.gf8f6787159e _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 07/10] drm/i915: add a new perf configuration execbuf parameter
Quoting Lionel Landwerlin (2019-06-27 09:00:42)
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +8
-0+static int +get_execbuf_oa_config (struct drm_i915_private *dev_priv, +s32 perf_fd,u64 oa_config_id, +struct i915_oa_config **out_oa_config, +struct drm_i915_gem_object **out_oa_obj) +{ +struct file *perf_file; +int ret;
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c static int reloc_move_to_gpu(struct i915_request *rq, struct i915_vma *vma) · line 1235
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +10
-0+ +if (!dev_priv->perf.oa.exclusive_stream) +return -EINVAL ; + + perf_file =fget (perf_fd); +if (!perf_file) +return -EINVAL ; + +if (perf_file->private_data != dev_priv->perf.oa.exclusive_stream) +return -EINVAL ;
Leaked the file.
Quoted 1 line
+
fput(perf_file);
and we never use perf_file again? It's only use is as a permission check on the ioctl? Just checking in case perf_fd is dup()ed by the user after we check it.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 07/10] drm/i915: add a new perf configuration execbuf parameter
Quoted 12 lines · Chris Wilson
Quoting Lionel Landwerlin (2019-06-27 09:00:42)
Quoted 11 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +11
-0+static int +get_execbuf_oa_config (struct drm_i915_private *dev_priv, +s32 perf_fd,u64 oa_config_id, +struct i915_oa_config **out_oa_config, +struct drm_i915_gem_object **out_oa_obj) +{ +struct file *perf_file; +int ret; + +if (!dev_priv->perf.oa.exclusive_stream) +return -EINVAL ;
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c static int reloc_move_to_gpu(struct i915_request *rq, struct i915_vma *vma) · line 1235
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +7
-0+ + perf_file =fget (perf_fd); +if (!perf_file) +return -EINVAL ; + +if (perf_file->private_data != dev_priv->perf.oa.exclusive_stream) +return -EINVAL ;Leaked the file.
Thanks!
Quoted 7 lines
Quoted 2 lines
+
fput(perf_file);and we never use
perf_fileagain? It's only use is as a permission check on the ioctl? Just checking in caseperf_fdis dup()ed by the user after we check it.
-Chris
Correct, if it's dup()ed then the application enters undefined behavior territory.
Much like not synchronizing buffer access across engines ;)
-Lionel
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 07/10] drm/i915: add a new perf configuration execbuf parameter
In reply to Lionel LandwerlinQuoting Lionel Landwerlin (2019-06-27 09:00:42)
Quoted 94 lines
We want the ability to dispatch a set of command buffer to the hardware, each with a different OA configuration. To achieve this, we reuse a couple of fields from the execbuf2 struct (I CAN HAZ execbuf3?) to notify what OA configuration should be used for a batch buffer. This requires the process making the execbuf with this flag to also own the perf fd at the time of execbuf.
v2: Add a
emit_oa_config()vfunc in theintel_engine_cs(Chris)
Moveoa_configvma to active (Chris)v3: Don't drop the lock for engine lookup (Chris)
Move OA config vma to active before writing the ringbuffer (Chris)v4: Reuse
i915_user_extension_fn
Serialize requests with OA config updatesSigned-off-by Lionel Landwerlin <[email protected]>--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 130 +++++++++++++++++- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 2 + drivers/gpu/drm/i915/gt/intel_engine_types.h | 9 ++ drivers/gpu/drm/i915/gt/intel_lrc.c | 1 + drivers/gpu/drm/i915/gt/intel_ringbuffer.c | 4 +- drivers/gpu/drm/i915/i915_drv.c | 4 + drivers/gpu/drm/i915/i915_drv.h | 10 +- drivers/gpu/drm/i915/i915_perf.c | 26 ++-- include/uapi/drm/i915_drm.h | 37 +++++ 9 files changed, 208 insertions(+), 15 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +42
-0@@ -283,7 +283,11 @@ struct i915_execbuffer {struct {u64 flags;/** Available extensions parameters */ struct drm_i915_gem_execbuffer_ext_timeline_fences timeline_fences; +struct drm_i915_gem_execbuffer_ext_perf perf_config; } extensions; + +struct i915_oa_config *oa_config;/** HW configuration for OA, NULL is not needed. */ +struct drm_i915_gem_object *oa_bo; };#define exec_entry (EB ,VMA ) (&(EB)->exec[(VMA)->exec_flags - (EB)->flags])@@ -1210,6 +1214,34 @@ static int reloc_move_to_gpu(struct i915_request *rq, struct i915_vma *vma)return err; } + +static int +get_execbuf_oa_config (struct drm_i915_private *dev_priv, +s32 perf_fd,u64 oa_config_id, +struct i915_oa_config **out_oa_config, +struct drm_i915_gem_object **out_oa_obj) +{ +struct file *perf_file; +int ret; + +if (!dev_priv->perf.oa.exclusive_stream) +return -EINVAL ; + + perf_file =fget (perf_fd); +if (!perf_file) +return -EINVAL ; + +if (perf_file->private_data != dev_priv->perf.oa.exclusive_stream) +return -EINVAL ; + +fput (perf_file); + + ret =i915_perf_get_oa_config (dev_priv, oa_config_id, + out_oa_config, out_oa_obj); + +return ret; +} +static int __reloc_gpu_alloc (struct i915_execbuffer *eb,struct i915_vma *vma,unsigned int len)@@ -2072,6 +2104,64 @@ add_to_client(struct i915_request *rq, struct drm_file *file)list_add_tail (&rq->client_link, &rq->file_priv->mm.request_list); } +static int eb_oa_config (struct i915_execbuffer *eb) +{ +struct i915_vma *oa_vma; +int err; + +if (!eb->oa_config) +return 0 ; + + err =i915_active_request_set (&eb->engine->last_oa_config, + eb->request);
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c add_to_client(struct i915_request *rq, struct drm_file *file) · line 2126
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +10
-0+if (err) +return err; + +/* +* If the perf stream was opened with hold preemption, flag the +* request properly so that the priority of the request is bumped once +* it reaches the execlist ports. +*/ +if (eb->i915->perf.oa.exclusive_stream->hold_preemption) + eb->request->has_perf = true;
Leave this chunk for the next battle^W patch.
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +5
-0+/* +* If the config hasn't changed, skip reconfiguring the HW (this is +* subject to a delay we want to avoid has much as possible). +*/ +if (eb->oa_config == eb->i915->perf.oa.exclusive_stream->oa_config)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c add_to_client(struct i915_request *rq, struct drm_file *file) · line 2142
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +10
-0+return 0 ; + + oa_vma =i915_vma_instance (eb->oa_bo, + &eb->engine->i915->ggtt.vm,NULL ); +if (unlikely (IS_ERR (oa_vma))) +return PTR_ERR (oa_vma); + + err =i915_vma_pin (oa_vma,0 ,0 ,PIN_GLOBAL ); +if (err) +return err;
Ugh. We should not be pinned after creating the request. Might not matter -- it's just reservation under its own lock that must not be crossed with the timeline lock currently held here.
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c add_to_client(struct i915_request *rq, struct drm_file *file) · line 2143
Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +2
-0+ + err =i915_vma_move_to_active (oa_vma, eb->request,0 );
You can unpin immediately after move_to_active (as the active is treated by being pinned).
I'm thinking this will be replaced with just i915_active_ref() as you only care about the vma.
Quoted 71 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +41
-0+if (err) { +i915_vma_unpin (oa_vma); +return err; + } + + err = eb->engine->emit_bb_start (eb->request, + oa_vma->node.start, +0 ,I915_DISPATCH_SECURE ); +if (err) { +i915_vma_unpin (oa_vma); +return err; + } + +i915_vma_unpin (oa_vma); + +swap (eb->oa_config, eb->i915->perf.oa.exclusive_stream->oa_config); + +return 0 ; +} +static int eb_submit (struct i915_execbuffer *eb) {int err;@@ -2098,6 +2188,10 @@ static int eb_submit(struct i915_execbuffer *eb)return err; } + err =eb_oa_config (eb); +if (err) +return err; + err = eb->engine->emit_bb_start(eb->request, eb->batch->node.start + eb->batch_start_offset,@@ -2520,8 +2614,22 @@ static int parse_timeline_fences(struct i915_user_extension __user *ext, void *dreturn 0 ; } +static int parse_perf_config (struct i915_user_extension __user *ext,void *data) +{ +struct i915_execbuffer *eb = data; + +if (copy_from_user (&eb->extensions.perf_config, ext, +sizeof (eb->extensions.perf_config))) +return -EFAULT ; + + eb->extensions.flags |=BIT (DRM_I915_GEM_EXECBUFFER_EXT_PERF ); + +return 0 ; +} +static const i915_user_extension_fn execbuf_extensions[] = { [DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES ] = parse_timeline_fences, + [DRM_I915_GEM_EXECBUFFER_EXT_PERF ] = parse_perf_config, }; static int@@ -2573,6 +2681,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, eb.buffer_count = args->buffer_count; eb.batch_start_offset = args->batch_start_offset; eb.batch_len = args->batch_len; + eb.oa_config =NULL ; eb.batch_flags =0 ;if (args->flags &I915_EXEC_SECURE ) {@@ -2651,9 +2760,23 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (unlikely (err)) goto err_unlock; +if (eb.extensions.flags &BIT (DRM_I915_GEM_EXECBUFFER_EXT_PERF )) { +if (!intel_engine_has_oa (eb.engine)) {
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c i915_gem_do_execbuffer(struct drm_device *dev, · line 2774
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +10
-0+ err = -ENODEV ; + goto err_engine; + } + + err =get_execbuf_oa_config (eb.i915, + eb.extensions.perf_config.perf_fd, + eb.extensions.perf_config.oa_config, + &eb.oa_config, &eb.oa_bo); +if (err) + goto err_engine;
Why is this under the struct_mutex?
Quoted 152 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +8
-1+ } + err =eb_wait_for_ring (&eb);/* may temporarily drop struct_mutex */ if (unlikely (err)) - goto err_engine; + goto err_oa; err =eb_relocate (&eb);if (err) {@@ -2806,6 +2929,11 @@ i915_gem_do_execbuffer(struct drm_device *dev, err_vma:if (eb.exec)eb_release_vmas (&eb); +err_oa: +if (eb.oa_config) { +i915_gem_object_put (eb.oa_bo); +i915_oa_config_put (eb.oa_config); + } err_engine:eb_unpin_context (&eb); err_unlock:drivers/gpu/drm/i915/gt/intel_engine_cs.c +2
-0@@ -859,6 +859,8 @@ int intel_engine_init_common(struct intel_engine_cs *engine) engine->set_default_submission (engine); +INIT_ACTIVE_REQUEST (&engine->last_oa_config); +return 0 ; err_unpin:drivers/gpu/drm/i915/gt/intel_engine_types.h +9
-0@@ -363,6 +363,8 @@ struct intel_engine_cs {struct i915_wa_list wa_list;struct i915_wa_list whitelist; +struct i915_active_request last_oa_config; +u32 irq_keep_mask;/* always keep these interrupts */ u32 irq_enable_mask;/* bitmask to enable ring interrupt */ void (*irq_enable)(struct intel_engine_cs *engine);@@ -446,6 +448,7 @@ struct intel_engine_cs {#define I915_ENGINE_HAS_SEMAPHORES BIT(3)#define I915_ENGINE_NEEDS_BREADCRUMB_TASKLET BIT(4)#define I915_ENGINE_IS_VIRTUAL BIT(5) +#define I915_ENGINE_HAS_OA BIT(6)unsigned int flags;/* @@ -541,6 +544,12 @@ intel_engine_is_virtual(const struct intel_engine_cs *engine)return engine->flags &I915_ENGINE_IS_VIRTUAL ; } +static inline bool +intel_engine_has_oa (const struct intel_engine_cs *engine) +{ +return engine->flags &I915_ENGINE_HAS_OA ; +} +#define instdone_slice_mask (dev_priv__) \ (IS_GEN(dev_priv__, 7) ? \ 1 : RUNTIME_INFO(dev_priv__)->sseu.slice_mask)drivers/gpu/drm/i915/gt/intel_lrc.c +1
-0@@ -2763,6 +2763,7 @@ int intel_execlists_submission_setup(struct intel_engine_cs *engine) engine->init_context = gen8_init_rcs_context; engine->emit_flush = gen8_emit_flush_render; engine->emit_fini_breadcrumb = gen8_emit_fini_breadcrumb_rcs; + engine->flags |=I915_ENGINE_HAS_OA ; }return 0 ;drivers/gpu/drm/i915/gt/intel_ringbuffer.c +3
-1@@ -2192,8 +2192,10 @@ static void setup_rcs(struct intel_engine_cs *engine) engine->irq_enable_mask =I915_USER_INTERRUPT ; } -if (IS_HASWELL (i915)) +if (IS_HASWELL (i915)) { engine->emit_bb_start = hsw_emit_bb_start; + engine->flags |=I915_ENGINE_HAS_OA ; + } engine->resume = rcs_resume; }drivers/gpu/drm/i915/i915_drv.c +4
-0@@ -486,6 +486,10 @@ static int i915_getparam_ioctl(struct drm_device *dev, void *data,case I915_PARAM_PERF_REVISION : value =1 ;break ; +case I915_PARAM_HAS_EXEC_PERF_CONFIG : +/* Obviously requires perf support. */ + value = dev_priv->perf.initialized; +break ;default :DRM_DEBUG ("Unknown parameter %d\n" , param->param);return -EINVAL ;drivers/gpu/drm/i915/i915_drv.h +9
-1@@ -1096,6 +1096,8 @@ struct i915_oa_reg { };struct i915_oa_config { +struct drm_i915_private *i915; +char uuid[UUID_STRING_LEN +1 ];int id;@@ -1114,7 +1116,7 @@ struct i915_oa_config {struct list_head vma_link; -atomic_t ref_count; +struct kref ref; };struct i915_perf_stream ;@@ -2612,6 +2614,12 @@ int i915_perf_get_oa_config(struct drm_i915_private *i915,int metrics_set, struct i915_oa_config **out_config, struct drm_i915_gem_object **out_obj); +void i915_oa_config_release (struct kref *ref); + +static inline void i915_oa_config_put (struct i915_oa_config *oa_config) +{ +kref_put (&oa_config->ref, i915_oa_config_release); +}/* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct i915_address_space *vm,drivers/gpu/drm/i915/i915_perf.c +0
-0@@ -366,10 +366,11 @@ struct perf_open_properties {int oa_period_exponent;
drivers/gpu/drm/i915/i915_perf.c struct perf_open_properties { · line 373
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +4
-3}; -static void put_oa_config (struct i915_oa_config *oa_config) +void i915_oa_config_release (struct kref *ref) { -if (!atomic_dec_and_test (&oa_config->ref_count)) -return ; +struct i915_oa_config *oa_config =container_of (ref,typeof (*oa_config), ref); + +lockdep_assert_held (&oa_config->i915->perf.metrics_lock);
That's not true for the eb paths.
Quoted 154 lines
drivers/gpu/drm/i915/i915_perf.c +10
-9if (oa_config->obj) {list_del (&oa_config->vma_link);@@ -485,7 +486,7 @@ int i915_perf_get_oa_config(struct drm_i915_private *i915, }if (out_config) { -atomic_inc (&oa_config->ref_count); +kref_get (&oa_config->ref); *out_config = oa_config; }@@ -507,7 +508,7 @@ int i915_perf_get_oa_config(struct drm_i915_private *i915, err_buf_alloc:if (out_config) { -put_oa_config (oa_config); +i915_oa_config_put (oa_config); *out_config =NULL ; } unlock:@@ -1483,7 +1484,7 @@ static void i915_oa_stream_destroy(struct i915_perf_stream *stream)if (stream->ctx)oa_put_render_ctx_id (stream); -put_oa_config (stream->oa_config); +i915_oa_config_put (stream->oa_config);if (dev_priv->perf.oa.spurious_report_rs.missed) { DRM_NOTE("%d spurious OA report notices suppressed due to ratelimiting\n",@@ -2430,7 +2431,7 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,free_oa_buffer (dev_priv); err_oa_buf_alloc: -put_oa_config (stream->oa_config); +i915_oa_config_put (stream->oa_config);intel_uncore_forcewake_put (&dev_priv->uncore,FORCEWAKE_ALL );intel_runtime_pm_put (&dev_priv->runtime_pm, stream->wakeref);@@ -3246,7 +3247,7 @@ void i915_perf_register(struct drm_i915_private *dev_priv)if (ret) goto sysfs_error; -atomic_set (&dev_priv->perf.oa.test_config.ref_count,1 ); + dev_priv->perf.oa.test_config.i915 = dev_priv; goto exit;@@ -3502,7 +3503,8 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,return -ENOMEM ; } -atomic_set (&oa_config->ref_count,1 ); + oa_config->i915 = dev_priv; +kref_init (&oa_config->ref);if (!uuid_is_valid (args->uuid)) {DRM_DEBUG ("Invalid uuid format for OA config\n" );@@ -3601,7 +3603,7 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data, sysfs_err:mutex_unlock (&dev_priv->perf.metrics_lock); reg_err: -put_oa_config (oa_config); +i915_oa_config_put (oa_config);DRM_DEBUG ("Failed to add new OA config\n" );return err; }@@ -3655,7 +3657,7 @@ int i915_perf_remove_config_ioctl(struct drm_device *dev, void *data,DRM_DEBUG ("Removed config %s id=%i\n" , oa_config->uuid, oa_config->id); -put_oa_config (oa_config); +i915_oa_config_put (oa_config); config_err:mutex_unlock (&dev_priv->perf.metrics_lock);@@ -3824,7 +3826,7 @@ static int destroy_config(int id, void *p, void *data) {struct i915_oa_config *oa_config = p; -put_oa_config (oa_config); +i915_oa_config_put (oa_config);return 0 ; }include/uapi/drm/i915_drm.h +37
-0@@ -623,6 +623,16 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_HAS_EXEC_TIMELINE_FENCES 55 +/* +* Request an i915/perf performance configuration change before running the +* commands given in an execbuf. +* +* Performance configuration ID and the file descriptor of the i915 perf +* stream are given through drm_i915_gem_execbuffer_ext_perf. See +* I915_EXEC_EXT. +*/ +#define I915_PARAM_HAS_EXEC_PERF_CONFIG 56 +/* Must be kept compact -- no holes and well documented */ typedef struct drm_i915_getparam {@@ -1026,6 +1036,12 @@ enum drm_i915_gem_execbuffer_ext {*/ DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES , +/** +* This identifier is associated with +* drm_i915_gem_execbuffer_perf_ext. +*/ +DRM_I915_GEM_EXECBUFFER_EXT_PERF , + DRM_I915_GEM_EXECBUFFER_EXT_MAX /* non-ABI */ };@@ -1054,6 +1070,27 @@ struct drm_i915_gem_execbuffer_ext_timeline_fences {__u64 values_ptr; }; +struct drm_i915_gem_execbuffer_ext_perf { +struct i915_user_extension base; + +/** +* Performance file descriptor returned by DRM_IOCTL_I915_PERF_OPEN. +* This is used to identify that the application +*/ +__s32 perf_fd; + +/** +* Unused for now. Must be cleared to zero. +*/ +__u32 pad; + +/** +* OA configuration ID to switch to before executing the commands +* associated to the execbuf. +*/ +__u64 oa_config; +}; +struct drm_i915_gem_execbuffer2 {/** * List of gem_exec_object2 structs Signature · 6 lines
2.21.0.392.gf8f6787159e _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 07/10] drm/i915: add a new perf configuration execbuf parameter
Quoted 98 lines · Chris Wilson
Quoting Lionel Landwerlin (2019-06-27 09:00:42)
Quoted 97 lines
We want the ability to dispatch a set of command buffer to the hardware, each with a different OA configuration. To achieve this, we reuse a couple of fields from the execbuf2 struct (I CAN HAZ execbuf3?) to notify what OA configuration should be used for a batch buffer. This requires the process making the execbuf with this flag to also own the perf fd at the time of execbuf.
v2: Add a
emit_oa_config()vfunc in theintel_engine_cs(Chris)
Moveoa_configvma to active (Chris)v3: Don't drop the lock for engine lookup (Chris)
Move OA config vma to active before writing the ringbuffer (Chris)v4: Reuse
i915_user_extension_fn
Serialize requests with OA config updatesSigned-off-by Lionel Landwerlin <[email protected]>--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 130 +++++++++++++++++- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 2 + drivers/gpu/drm/i915/gt/intel_engine_types.h | 9 ++ drivers/gpu/drm/i915/gt/intel_lrc.c | 1 + drivers/gpu/drm/i915/gt/intel_ringbuffer.c | 4 +- drivers/gpu/drm/i915/i915_drv.c | 4 + drivers/gpu/drm/i915/i915_drv.h | 10 +- drivers/gpu/drm/i915/i915_perf.c | 26 ++-- include/uapi/drm/i915_drm.h | 37 +++++ 9 files changed, 208 insertions(+), 15 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +45
-0@@ -283,7 +283,11 @@ struct i915_execbuffer {struct {u64 flags;/** Available extensions parameters */ struct drm_i915_gem_execbuffer_ext_timeline_fences timeline_fences; +struct drm_i915_gem_execbuffer_ext_perf perf_config; } extensions; + +struct i915_oa_config *oa_config;/** HW configuration for OA, NULL is not needed. */ +struct drm_i915_gem_object *oa_bo; };#define exec_entry (EB ,VMA ) (&(EB)->exec[(VMA)->exec_flags - (EB)->flags])@@ -1210,6 +1214,34 @@ static int reloc_move_to_gpu(struct i915_request *rq, struct i915_vma *vma)return err; } + +static int +get_execbuf_oa_config (struct drm_i915_private *dev_priv, +s32 perf_fd,u64 oa_config_id, +struct i915_oa_config **out_oa_config, +struct drm_i915_gem_object **out_oa_obj) +{ +struct file *perf_file; +int ret; + +if (!dev_priv->perf.oa.exclusive_stream) +return -EINVAL ; + + perf_file =fget (perf_fd); +if (!perf_file) +return -EINVAL ; + +if (perf_file->private_data != dev_priv->perf.oa.exclusive_stream) +return -EINVAL ; + +fput (perf_file); + + ret =i915_perf_get_oa_config (dev_priv, oa_config_id, + out_oa_config, out_oa_obj); + +return ret; +} +static int __reloc_gpu_alloc (struct i915_execbuffer *eb,struct i915_vma *vma,unsigned int len)@@ -2072,6 +2104,64 @@ add_to_client(struct i915_request *rq, struct drm_file *file)list_add_tail (&rq->client_link, &rq->file_priv->mm.request_list); } +static int eb_oa_config (struct i915_execbuffer *eb) +{ +struct i915_vma *oa_vma; +int err; + +if (!eb->oa_config) +return 0 ; + + err =i915_active_request_set (&eb->engine->last_oa_config, + eb->request); +if (err) +return err; +
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c add_to_client(struct i915_request *rq, struct drm_file *file) · line 2126
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +7
-0+/* +* If the perf stream was opened with hold preemption, flag the +* request properly so that the priority of the request is bumped once +* it reaches the execlist ports. +*/ +if (eb->i915->perf.oa.exclusive_stream->hold_preemption) + eb->request->has_perf = true;Leave this chunk for the next battle^W patch.
Oops.
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +10
-0+/* +* If the config hasn't changed, skip reconfiguring the HW (this is +* subject to a delay we want to avoid has much as possible). +*/ +if (eb->oa_config == eb->i915->perf.oa.exclusive_stream->oa_config) +return 0 ; + + oa_vma =i915_vma_instance (eb->oa_bo, + &eb->engine->i915->ggtt.vm,NULL ); +if (unlikely (IS_ERR (oa_vma)))
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c add_to_client(struct i915_request *rq, struct drm_file *file) · line 2142
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +5
-0+return PTR_ERR (oa_vma); + + err =i915_vma_pin (oa_vma,0 ,0 ,PIN_GLOBAL ); +if (err) +return err;Ugh. We should not be pinned after creating the request. Might not matter -- it's just reservation under its own lock that must not be crossed with the timeline lock currently held here.
Should I move this into get_execbuf_oa_config() ?
Quoted 78 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c add_to_client(struct i915_request *rq, struct drm_file *file) · line 2143
Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +2
-0+ + err =i915_vma_move_to_active (oa_vma, eb->request,0 );You can unpin immediately after
move_to_active(as the active is treated by being pinned).I'm thinking this will be replaced with just
i915_active_ref()as you only care about the vma.Quoted 69 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +39
-0+if (err) { +i915_vma_unpin (oa_vma); +return err; + } + + err = eb->engine->emit_bb_start (eb->request, + oa_vma->node.start, +0 ,I915_DISPATCH_SECURE ); +if (err) { +i915_vma_unpin (oa_vma); +return err; + } + +i915_vma_unpin (oa_vma); + +swap (eb->oa_config, eb->i915->perf.oa.exclusive_stream->oa_config); + +return 0 ; +} +static int eb_submit (struct i915_execbuffer *eb) {int err;@@ -2098,6 +2188,10 @@ static int eb_submit(struct i915_execbuffer *eb)return err; } + err =eb_oa_config (eb); +if (err) +return err; + err = eb->engine->emit_bb_start(eb->request, eb->batch->node.start + eb->batch_start_offset,@@ -2520,8 +2614,22 @@ static int parse_timeline_fences(struct i915_user_extension __user *ext, void *dreturn 0 ; } +static int parse_perf_config (struct i915_user_extension __user *ext,void *data) +{ +struct i915_execbuffer *eb = data; + +if (copy_from_user (&eb->extensions.perf_config, ext, +sizeof (eb->extensions.perf_config))) +return -EFAULT ; + + eb->extensions.flags |=BIT (DRM_I915_GEM_EXECBUFFER_EXT_PERF ); + +return 0 ; +} +static const i915_user_extension_fn execbuf_extensions[] = { [DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES ] = parse_timeline_fences, + [DRM_I915_GEM_EXECBUFFER_EXT_PERF ] = parse_perf_config, }; static int@@ -2573,6 +2681,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, eb.buffer_count = args->buffer_count; eb.batch_start_offset = args->batch_start_offset; eb.batch_len = args->batch_len; + eb.oa_config =NULL ; eb.batch_flags =0 ;if (args->flags &I915_EXEC_SECURE ) {@@ -2651,9 +2760,23 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (unlikely (err)) goto err_unlock;
Quoted 13 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c i915_gem_do_execbuffer(struct drm_device *dev, · line 2774
Quoted 12 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +12
-0+if (eb.extensions.flags &BIT (DRM_I915_GEM_EXECBUFFER_EXT_PERF )) { +if (!intel_engine_has_oa (eb.engine)) { + err = -ENODEV ; + goto err_engine; + } + + err =get_execbuf_oa_config (eb.i915, + eb.extensions.perf_config.perf_fd, + eb.extensions.perf_config.oa_config, + &eb.oa_config, &eb.oa_bo); +if (err) + goto err_engine;Why is this under the
struct_mutex?
Access to dev_priv->perf.oa.exclusive_stream must be under struct_mutex.
Also because we verify that the engine actually has OA support.
I could split the getting the configuration part away.
Quoted 155 lines
Quoted 155 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +8
-1+ } + err =eb_wait_for_ring (&eb);/* may temporarily drop struct_mutex */ if (unlikely (err)) - goto err_engine; + goto err_oa; err =eb_relocate (&eb);if (err) {@@ -2806,6 +2929,11 @@ i915_gem_do_execbuffer(struct drm_device *dev, err_vma:if (eb.exec)eb_release_vmas (&eb); +err_oa: +if (eb.oa_config) { +i915_gem_object_put (eb.oa_bo); +i915_oa_config_put (eb.oa_config); + } err_engine:eb_unpin_context (&eb); err_unlock:drivers/gpu/drm/i915/gt/intel_engine_cs.c +2
-0@@ -859,6 +859,8 @@ int intel_engine_init_common(struct intel_engine_cs *engine) engine->set_default_submission (engine); +INIT_ACTIVE_REQUEST (&engine->last_oa_config); +return 0 ; err_unpin:drivers/gpu/drm/i915/gt/intel_engine_types.h +9
-0@@ -363,6 +363,8 @@ struct intel_engine_cs {struct i915_wa_list wa_list;struct i915_wa_list whitelist; +struct i915_active_request last_oa_config; +u32 irq_keep_mask;/* always keep these interrupts */ u32 irq_enable_mask;/* bitmask to enable ring interrupt */ void (*irq_enable)(struct intel_engine_cs *engine);@@ -446,6 +448,7 @@ struct intel_engine_cs {#define I915_ENGINE_HAS_SEMAPHORES BIT(3)#define I915_ENGINE_NEEDS_BREADCRUMB_TASKLET BIT(4)#define I915_ENGINE_IS_VIRTUAL BIT(5) +#define I915_ENGINE_HAS_OA BIT(6)unsigned int flags;/* @@ -541,6 +544,12 @@ intel_engine_is_virtual(const struct intel_engine_cs *engine)return engine->flags &I915_ENGINE_IS_VIRTUAL ; } +static inline bool +intel_engine_has_oa (const struct intel_engine_cs *engine) +{ +return engine->flags &I915_ENGINE_HAS_OA ; +} +#define instdone_slice_mask (dev_priv__) \ (IS_GEN(dev_priv__, 7) ? \ 1 : RUNTIME_INFO(dev_priv__)->sseu.slice_mask)drivers/gpu/drm/i915/gt/intel_lrc.c +1
-0@@ -2763,6 +2763,7 @@ int intel_execlists_submission_setup(struct intel_engine_cs *engine) engine->init_context = gen8_init_rcs_context; engine->emit_flush = gen8_emit_flush_render; engine->emit_fini_breadcrumb = gen8_emit_fini_breadcrumb_rcs; + engine->flags |=I915_ENGINE_HAS_OA ; }return 0 ;drivers/gpu/drm/i915/gt/intel_ringbuffer.c +3
-1@@ -2192,8 +2192,10 @@ static void setup_rcs(struct intel_engine_cs *engine) engine->irq_enable_mask =I915_USER_INTERRUPT ; } -if (IS_HASWELL (i915)) +if (IS_HASWELL (i915)) { engine->emit_bb_start = hsw_emit_bb_start; + engine->flags |=I915_ENGINE_HAS_OA ; + } engine->resume = rcs_resume; }drivers/gpu/drm/i915/i915_drv.c +4
-0@@ -486,6 +486,10 @@ static int i915_getparam_ioctl(struct drm_device *dev, void *data,case I915_PARAM_PERF_REVISION : value =1 ;break ; +case I915_PARAM_HAS_EXEC_PERF_CONFIG : +/* Obviously requires perf support. */ + value = dev_priv->perf.initialized; +break ;default :DRM_DEBUG ("Unknown parameter %d\n" , param->param);return -EINVAL ;drivers/gpu/drm/i915/i915_drv.h +9
-1@@ -1096,6 +1096,8 @@ struct i915_oa_reg { };struct i915_oa_config { +struct drm_i915_private *i915; +char uuid[UUID_STRING_LEN +1 ];int id;@@ -1114,7 +1116,7 @@ struct i915_oa_config {struct list_head vma_link; -atomic_t ref_count; +struct kref ref; };struct i915_perf_stream ;@@ -2612,6 +2614,12 @@ int i915_perf_get_oa_config(struct drm_i915_private *i915,int metrics_set, struct i915_oa_config **out_config, struct drm_i915_gem_object **out_obj); +void i915_oa_config_release (struct kref *ref); + +static inline void i915_oa_config_put (struct i915_oa_config *oa_config) +{ +kref_put (&oa_config->ref, i915_oa_config_release); +}/* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct i915_address_space *vm,drivers/gpu/drm/i915/i915_perf.c +0
-0@@ -366,10 +366,11 @@ struct perf_open_properties {int oa_period_exponent; };
Quoted 9 lines
drivers/gpu/drm/i915/i915_perf.c struct perf_open_properties { · line 373
Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c +4
-3-static void put_oa_config (struct i915_oa_config *oa_config) +void i915_oa_config_release (struct kref *ref) { -if (!atomic_dec_and_test (&oa_config->ref_count)) -return ; +struct i915_oa_config *oa_config =container_of (ref,typeof (*oa_config), ref); + +lockdep_assert_held (&oa_config->i915->perf.metrics_lock);That's not true for the eb paths.
Actually that's not true anywhere...
Quoted 151 lines
Quoted 151 lines
drivers/gpu/drm/i915/i915_perf.c +10
-9if (oa_config->obj) {list_del (&oa_config->vma_link);@@ -485,7 +486,7 @@ int i915_perf_get_oa_config(struct drm_i915_private *i915, }if (out_config) { -atomic_inc (&oa_config->ref_count); +kref_get (&oa_config->ref); *out_config = oa_config; }@@ -507,7 +508,7 @@ int i915_perf_get_oa_config(struct drm_i915_private *i915, err_buf_alloc:if (out_config) { -put_oa_config (oa_config); +i915_oa_config_put (oa_config); *out_config =NULL ; } unlock:@@ -1483,7 +1484,7 @@ static void i915_oa_stream_destroy(struct i915_perf_stream *stream)if (stream->ctx)oa_put_render_ctx_id (stream); -put_oa_config (stream->oa_config); +i915_oa_config_put (stream->oa_config);if (dev_priv->perf.oa.spurious_report_rs.missed) { DRM_NOTE("%d spurious OA report notices suppressed due to ratelimiting\n",@@ -2430,7 +2431,7 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,free_oa_buffer (dev_priv); err_oa_buf_alloc: -put_oa_config (stream->oa_config); +i915_oa_config_put (stream->oa_config);intel_uncore_forcewake_put (&dev_priv->uncore,FORCEWAKE_ALL );intel_runtime_pm_put (&dev_priv->runtime_pm, stream->wakeref);@@ -3246,7 +3247,7 @@ void i915_perf_register(struct drm_i915_private *dev_priv)if (ret) goto sysfs_error; -atomic_set (&dev_priv->perf.oa.test_config.ref_count,1 ); + dev_priv->perf.oa.test_config.i915 = dev_priv; goto exit;@@ -3502,7 +3503,8 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,return -ENOMEM ; } -atomic_set (&oa_config->ref_count,1 ); + oa_config->i915 = dev_priv; +kref_init (&oa_config->ref);if (!uuid_is_valid (args->uuid)) {DRM_DEBUG ("Invalid uuid format for OA config\n" );@@ -3601,7 +3603,7 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data, sysfs_err:mutex_unlock (&dev_priv->perf.metrics_lock); reg_err: -put_oa_config (oa_config); +i915_oa_config_put (oa_config);DRM_DEBUG ("Failed to add new OA config\n" );return err; }@@ -3655,7 +3657,7 @@ int i915_perf_remove_config_ioctl(struct drm_device *dev, void *data,DRM_DEBUG ("Removed config %s id=%i\n" , oa_config->uuid, oa_config->id); -put_oa_config (oa_config); +i915_oa_config_put (oa_config); config_err:mutex_unlock (&dev_priv->perf.metrics_lock);@@ -3824,7 +3826,7 @@ static int destroy_config(int id, void *p, void *data) {struct i915_oa_config *oa_config = p; -put_oa_config (oa_config); +i915_oa_config_put (oa_config);return 0 ; }include/uapi/drm/i915_drm.h +37
-0@@ -623,6 +623,16 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_HAS_EXEC_TIMELINE_FENCES 55 +/* +* Request an i915/perf performance configuration change before running the +* commands given in an execbuf. +* +* Performance configuration ID and the file descriptor of the i915 perf +* stream are given through drm_i915_gem_execbuffer_ext_perf. See +* I915_EXEC_EXT. +*/ +#define I915_PARAM_HAS_EXEC_PERF_CONFIG 56 +/* Must be kept compact -- no holes and well documented */ typedef struct drm_i915_getparam {@@ -1026,6 +1036,12 @@ enum drm_i915_gem_execbuffer_ext {*/ DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES , +/** +* This identifier is associated with +* drm_i915_gem_execbuffer_perf_ext. +*/ +DRM_I915_GEM_EXECBUFFER_EXT_PERF , + DRM_I915_GEM_EXECBUFFER_EXT_MAX /* non-ABI */ };@@ -1054,6 +1070,27 @@ struct drm_i915_gem_execbuffer_ext_timeline_fences {__u64 values_ptr; }; +struct drm_i915_gem_execbuffer_ext_perf { +struct i915_user_extension base; + +/** +* Performance file descriptor returned by DRM_IOCTL_I915_PERF_OPEN. +* This is used to identify that the application +*/ +__s32 perf_fd; + +/** +* Unused for now. Must be cleared to zero. +*/ +__u32 pad; + +/** +* OA configuration ID to switch to before executing the commands +* associated to the execbuf. +*/ +__u64 oa_config; +}; +struct drm_i915_gem_execbuffer2 {/** * List of gem_exec_object2 structs Signature · 1 line
2.21.0.392.gf8f6787159e
Quoted 4 lines
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 07/10] drm/i915: add a new perf configuration execbuf parameter
Quoting Lionel Landwerlin (2019-06-27 13:32:13)
Quoted 22 lines · Chris Wilson
Quoted 11 lines
Quoting Lionel Landwerlin (2019-06-27 09:00:42)
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +10
-0+/* +* If the config hasn't changed, skip reconfiguring the HW (this is +* subject to a delay we want to avoid has much as possible). +*/ +if (eb->oa_config == eb->i915->perf.oa.exclusive_stream->oa_config) +return 0 ; + + oa_vma =i915_vma_instance (eb->oa_bo, + &eb->engine->i915->ggtt.vm,NULL ); +if (unlikely (IS_ERR (oa_vma)))Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c add_to_client(struct i915_request *rq, struct drm_file *file) · line 2142
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +5
-0+return PTR_ERR (oa_vma); + + err =i915_vma_pin (oa_vma,0 ,0 ,PIN_GLOBAL ); +if (err) +return err;Ugh. We should not be pinned after creating the request. Might not matter -- it's just reservation under its own lock that must not be crossed with the timeline lock currently held here.
Quoted 1 line
Should I move this into
get_execbuf_oa_config()?
That would be save me fretting about the lock nesting.
Quoted 19 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +0
-0@@ -2651,9 +2760,23 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (unlikely (err)) goto err_unlock;Quoted 13 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c i915_gem_do_execbuffer(struct drm_device *dev, · line 2774
Quoted 12 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +12
-0+if (eb.extensions.flags &BIT (DRM_I915_GEM_EXECBUFFER_EXT_PERF )) { +if (!intel_engine_has_oa (eb.engine)) { + err = -ENODEV ; + goto err_engine; + } + + err =get_execbuf_oa_config (eb.i915, + eb.extensions.perf_config.perf_fd, + eb.extensions.perf_config.oa_config, + &eb.oa_config, &eb.oa_bo); +if (err) + goto err_engine;Why is this under the
struct_mutex?
Quoted 5 lines
Access to
dev_priv->perf.oa.exclusive_streammust be understruct_mutex.Also because we verify that the engine actually has OA support.
I could split the getting the configuration part away.
I'm about 10^W 50^W certainly less than a 100 patches away from killing struct_mutex for execbuf...
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 07/10] drm/i915: add a new perf configuration execbuf parameter
Quoted 43 lines · Chris Wilson
Quoting Lionel Landwerlin (2019-06-27 13:32:13)
Quoted 21 lines · Chris Wilson
Quoted 11 lines
Quoting Lionel Landwerlin (2019-06-27 09:00:42)
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +10
-0+/* +* If the config hasn't changed, skip reconfiguring the HW (this is +* subject to a delay we want to avoid has much as possible). +*/ +if (eb->oa_config == eb->i915->perf.oa.exclusive_stream->oa_config) +return 0 ; + + oa_vma =i915_vma_instance (eb->oa_bo, + &eb->engine->i915->ggtt.vm,NULL ); +if (unlikely (IS_ERR (oa_vma)))Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c add_to_client(struct i915_request *rq, struct drm_file *file) · line 2142
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +5
-0+return PTR_ERR (oa_vma); + + err =i915_vma_pin (oa_vma,0 ,0 ,PIN_GLOBAL ); +if (err) +return err;Ugh. We should not be pinned after creating the request. Might not matter -- it's just reservation under its own lock that must not be crossed with the timeline lock currently held here.
Quoted 1 line
Should I move this into
get_execbuf_oa_config()?That would be save me fretting about the lock nesting.
Quoted 18 lines
Quoted 17 lines
Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +2
-0@@ -2651,9 +2760,23 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (unlikely (err)) goto err_unlock; +if (eb.extensions.flags &BIT (DRM_I915_GEM_EXECBUFFER_EXT_PERF )) { +if (!intel_engine_has_oa (eb.engine)) {drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c i915_gem_do_execbuffer(struct drm_device *dev, · line 2774
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +10
-0+ err = -ENODEV ; + goto err_engine; + } + + err =get_execbuf_oa_config (eb.i915, + eb.extensions.perf_config.perf_fd, + eb.extensions.perf_config.oa_config, + &eb.oa_config, &eb.oa_bo); +if (err) + goto err_engine;Why is this under the
struct_mutex?
Quoted 9 lines
Quoted 5 lines
Access to
dev_priv->perf.oa.exclusive_streammust be understruct_mutex.Also because we verify that the engine actually has OA support.
I could split the getting the configuration part away.
I'm about 10^W 50^W certainly less than a 100 patches away from killing
struct_mutexfor execbuf...
-Chris
I'm sorry. Dealing with all this OA stuff is underwhelming.
I think an engine lock would be enough if that's not too bad for you.
-Lionel
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 8/10 drm/i915/perf: allow holding preemption on filtered ctx
In reply to Lionel LandwerlinWe would like to make use of perf in Vulkan. The Vulkan API is much lower level than OpenGL, with applications directly exposed to the concept of command buffers (pretty much equivalent to our batch buffers). In Vulkan, queries are always limited in scope to a command buffer. In OpenGL, the lack of command buffer concept meant that queries' duration could span multiple command buffers.
With that restriction gone in Vulkan, we would like to simplify measuring performance just by measuring the deltas between the counter snapshots written by 2 MI_RECORD_PERF_COUNT commands, rather than the more complex scheme we currently have in the GL driver, using 2 MI_RECORD_PERF_COUNT commands and doing some post processing on the stream of OA reports, coming from the global OA buffer, to remove any unrelated deltas in between the 2 MI_RECORD_PERF_COUNT.
Disabling preemption only apply to a single context with which want to query performance counters for and is considered a privileged operation, by default protected by CAP_SYS_ADMIN. It is possible to enable it for a normal user by disabling the paranoid stream setting.
v2: Store preemption setting in intel_context (Chris)
v3: Use priorities to avoid preemption rather than the HW mechanism
v4: Just modify the port priority reporting function
--- drivers/gpu/drm/i915/gt/intel_lrc.c | 7 ++++++- drivers/gpu/drm/i915/i915_drv.c | 2 +- drivers/gpu/drm/i915/i915_drv.h | 13 ++++++++++++ drivers/gpu/drm/i915/i915_perf.c | 22 +++++++++++++++++++-- drivers/gpu/drm/i915/i915_priolist_types.h | 7 +++++++ drivers/gpu/drm/i915/i915_request.c | 1 + drivers/gpu/drm/i915/i915_request.h | 1 + drivers/gpu/drm/i915/intel_guc_submission.c | 12 ++++++++++- include/uapi/drm/i915_drm.h | 11 +++++++++++ 9 files changed, 71 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gt/intel_lrc.c +6 -1
@@ -256,7 +256,12 @@ static inline int rq_prio(const struct i915_request *rq)static int effective_prio (const struct i915_request *rq) { -int prio =rq_prio (rq); +int prio; + +if (rq->has_perf) + prio =I915_USER_PRIORITY (I915_PRIORITY_PERF ); +else + prio =rq_prio (rq);/* * On unwinding the active request, we give it a priority bump
drivers/gpu/drm/i915/i915_drv.c +1 -1
@@ -484,7 +484,7 @@ static int i915_getparam_ioctl(struct drm_device *dev, void *data, value =INTEL_INFO (dev_priv)->has_coherent_ggtt;break ;case I915_PARAM_PERF_REVISION : - value =1 ; + value =2 ;break ;case I915_PARAM_HAS_EXEC_PERF_CONFIG :/* Obviously requires perf support. */
drivers/gpu/drm/i915/i915_drv.h +13 -0
@@ -1232,6 +1232,19 @@ struct i915_perf_stream {*/ bool enabled; +/** +* @hold_preemption: Whether preemption is put on hold for command +* submissions done on the @ctx. This is useful for some drivers that +* cannot easily post process the OA buffer context to subtract delta +* of performance counters not associated with @ctx. +*/ +bool hold_preemption; + +/** +* @last_config_request +*/ +struct i915_request *last_config_request; +/** * @ops: The callbacks providing the implementation of this specific * type of configured stream.
drivers/gpu/drm/i915/i915_perf.c +20 -2
@@ -343,6 +343,8 @@ static const struct i915_oa_format gen8_plus_oa_formats[I915_OA_FORMAT_MAX] = {* struct perf_open_properties - for validated properties given to open a stream * @sample_flags: `DRM_I915_PERF_PROP_SAMPLE_*` properties are tracked as flags * @single_context: Whether a single or all gpu contexts should be monitored +* @hold_preemption: Whether the preemption is disabled for the filtered +* context * @ctx_handle: A gem ctx handle for use with @single_context * @metrics_set: An ID for an OA unit metric set advertised via sysfs * @oa_format: An OA unit HW report format
@@ -357,6 +359,7 @@ struct perf_open_properties {u32 sample_flags; u64 single_context:1; + u64 hold_preemption:1;u64 ctx_handle;/* OA sampling state */
@@ -2352,6 +2355,8 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, stream->sample_flags |=SAMPLE_OA_REPORT ; stream->sample_size += format_size; + stream->hold_preemption = props->hold_preemption; + dev_priv->perf.oa.oa_buffer.format_size = format_size;if (WARN_ON (dev_priv->perf.oa.oa_buffer.format_size ==0 ))return -EINVAL ;
@@ -2890,6 +2895,15 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv, } } +if (props->hold_preemption) { +if (!props->single_context) { +DRM_DEBUG ("preemption disable with no context\n" ); + ret = -EINVAL ; + goto err; + } + privileged_op = true; + } +/* * On Haswell the OA unit supports clock gating off for a specific * context and in this mode there's no visibility of metrics for the
@@ -2904,8 +2918,9 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv,* MI_REPORT_PERF_COUNT commands and so consider it a privileged op to * enable the OA unit by default. */ -if (IS_HASWELL (dev_priv) && specific_ctx) +if (IS_HASWELL (dev_priv) && specific_ctx && !props->hold_preemption) { privileged_op = false; + }/* Similar to perf's kernel.perf_paranoid_cpu sysctl option * we check a dev.i915.perf_stream_paranoid sysctl option
@@ -2914,7 +2929,7 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv,*/ if (privileged_op && i915_perf_stream_paranoid && !capable (CAP_SYS_ADMIN )) { -DRM_DEBUG ("Insufficient privileges to open system-wide i915 perf stream\n" ); +DRM_DEBUG ("Insufficient privileges to open i915 perf stream\n" ); ret = -EACCES ; goto err_ctx; }
@@ -3106,6 +3121,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_HOLD_PREEMPTION : + props->hold_preemption = value !=0 ?1 :0 ; +break ;case DRM_I915_PERF_PROP_MAX :MISSING_CASE (id);return -EINVAL ;
drivers/gpu/drm/i915/i915_priolist_types.h +7 -0
@@ -17,6 +17,13 @@ enum {I915_PRIORITY_NORMAL =I915_CONTEXT_DEFAULT_PRIORITY ,I915_PRIORITY_MAX =I915_CONTEXT_MAX_USER_PRIORITY +1 , +/* Requests containing performance queries must not be preempted by +* another context. They get scheduled with their default priority and +* once they reach the execlist ports we bump them to +* I915_PRIORITY_PERF so that they stick to the HW until they finish. +*/ +I915_PRIORITY_PERF =I915_CONTEXT_MAX_USER_PRIORITY +2 , + I915_PRIORITY_INVALID = INT_MIN };
drivers/gpu/drm/i915/i915_request.c +1 -0
@@ -685,6 +685,7 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp) rq->batch =NULL ; rq->capture_list =NULL ; rq->waitboost = false; + rq->has_perf = false; rq->execution_mask =ALL_ENGINES ;INIT_LIST_HEAD (&rq->active_list);
drivers/gpu/drm/i915/i915_request.h +1 -0
@@ -217,6 +217,7 @@ struct i915_request {unsigned long emitted_jiffies;bool waitboost; +bool has_perf;/** timeline->request entry for this request */ struct list_head link;
drivers/gpu/drm/i915/intel_guc_submission.c +11 -1
@@ -707,6 +707,16 @@ static inline int rq_prio(const struct i915_request *rq)return rq->sched.attr.priority | __NO_PREEMPTION; } +static inline int effective_prio (const struct i915_request *rq) +{ +int prio; + +if (rq->has_perf) +return I915_USER_PRIORITY (I915_PRIORITY_PERF ) | __NO_PREEMPTION; + +return rq_prio (rq); +} +static struct i915_request *schedule_in (struct i915_request *rq,int idx) {trace_i915_request_in (rq, idx);
@@ -747,7 +757,7 @@ static void __guc_dequeue(struct intel_engine_cs *engine) &engine->i915->guc.preempt_work[engine->id];int prio = execlists->queue_priority_hint; -if (i915_scheduler_need_preempt (prio,rq_prio (last))) { +if (i915_scheduler_need_preempt (prio,effective_prio (last))) {intel_write_status_page (engine,I915_GEM_HWS_PREEMPT ,GUC_PREEMPT_INPROGRESS );
include/uapi/drm/i915_drm.h +11 -0
@@ -1982,6 +1982,17 @@ enum drm_i915_perf_property_id {*/ DRM_I915_PERF_PROP_OA_EXPONENT , +/** +* Specifying this property is only valid when specify a context to +* filter with DRM_I915_PERF_PROP_CTX_HANDLE. Specifying this property +* will hold preemption of the particular context we want to gather +* performance data about. The execbuf2 submissions must include a +* drm_i915_gem_execbuffer_ext_perf parameter for this to apply. +* +* This property is available in perf revision 2. +*/ +DRM_I915_PERF_PROP_HOLD_PREEMPTION , + DRM_I915_PERF_PROP_MAX /* non-ABI */ };
Signature · 6 lines
2.21.0.392.gf8f6787159e _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 08/10] drm/i915/perf: allow holding preemption on filtered ctx
Quoting Lionel Landwerlin (2019-06-27 09:00:43)
Quoted 44 lines
We would like to make use of perf in Vulkan. The Vulkan API is much lower level than OpenGL, with applications directly exposed to the concept of command buffers (pretty much equivalent to our batch buffers). In Vulkan, queries are always limited in scope to a command buffer. In OpenGL, the lack of command buffer concept meant that queries' duration could span multiple command buffers.
With that restriction gone in Vulkan, we would like to simplify measuring performance just by measuring the deltas between the counter snapshots written by 2
MI_RECORD_PERF_COUNTcommands, rather than the more complex scheme we currently have in the GL driver, using 2MI_RECORD_PERF_COUNTcommands and doing some post processing on the stream of OA reports, coming from the global OA buffer, to remove any unrelated deltas in between the 2MI_RECORD_PERF_COUNT.Disabling preemption only apply to a single context with which want to query performance counters for and is considered a privileged operation, by default protected by
CAP_SYS_ADMIN. It is possible to enable it for a normal user by disabling the paranoid stream setting.v2: Store preemption setting in
intel_context(Chris)v3: Use priorities to avoid preemption rather than the HW mechanism
v4: Just modify the port priority reporting function
Signed-off-by Lionel Landwerlin <[email protected]>--- drivers/gpu/drm/i915/gt/intel_lrc.c | 7 ++++++- drivers/gpu/drm/i915/i915_drv.c | 2 +- drivers/gpu/drm/i915/i915_drv.h | 13 ++++++++++++ drivers/gpu/drm/i915/i915_perf.c | 22 +++++++++++++++++++-- drivers/gpu/drm/i915/i915_priolist_types.h | 7 +++++++ drivers/gpu/drm/i915/i915_request.c | 1 + drivers/gpu/drm/i915/i915_request.h | 1 + drivers/gpu/drm/i915/intel_guc_submission.c | 12 ++++++++++- include/uapi/drm/i915_drm.h | 11 +++++++++++ 9 files changed, 71 insertions(+), 5 deletions(-)drivers/gpu/drm/i915/gt/intel_lrc.c +0
-0
drivers/gpu/drm/i915/gt/intel_lrc.c static inline int rq_prio(const struct i915_request *rq) · line 264
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +6
-1@@ -256,7 +256,12 @@ static inline int rq_prio(const struct i915_request *rq)static int effective_prio (const struct i915_request *rq) { -int prio =rq_prio (rq); +int prio; + +if (rq->has_perf) + prio =I915_USER_PRIORITY (I915_PRIORITY_PERF ); +else + prio =rq_prio (rq);
This doesn't cover everything. You will get timesliced now.
But I do think this is the safest approach that evades all the PI sanity checks and possible deadlocks.
There is also the problem where we check the priority on the last request in the queue, but preemption may need to be disabled at the head of the queue (the executing request). Is that a concern? I was thinking of marking the context as non-preemptible until after the oa is removed.
Quoted 106 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +0
-0/* * On unwinding the active request, we give it a priority bump drivers/gpu/drm/i915/i915_drv.c +1
-1@@ -484,7 +484,7 @@ static int i915_getparam_ioctl(struct drm_device *dev, void *data, value =INTEL_INFO (dev_priv)->has_coherent_ggtt;break ;case I915_PARAM_PERF_REVISION : - value =1 ; + value =2 ;break ;case I915_PARAM_HAS_EXEC_PERF_CONFIG :/* Obviously requires perf support. */ drivers/gpu/drm/i915/i915_drv.h +13
-0@@ -1232,6 +1232,19 @@ struct i915_perf_stream {*/ bool enabled; +/** +* @hold_preemption: Whether preemption is put on hold for command +* submissions done on the @ctx. This is useful for some drivers that +* cannot easily post process the OA buffer context to subtract delta +* of performance counters not associated with @ctx. +*/ +bool hold_preemption; + +/** +* @last_config_request +*/ +struct i915_request *last_config_request; +/** * @ops: The callbacks providing the implementation of this specific * type of configured stream. drivers/gpu/drm/i915/i915_perf.c +17
-2@@ -343,6 +343,8 @@ static const struct i915_oa_format gen8_plus_oa_formats[I915_OA_FORMAT_MAX] = {* struct perf_open_properties - for validated properties given to open a stream * @sample_flags: `DRM_I915_PERF_PROP_SAMPLE_*` properties are tracked as flags * @single_context: Whether a single or all gpu contexts should be monitored +* @hold_preemption: Whether the preemption is disabled for the filtered +* context * @ctx_handle: A gem ctx handle for use with @single_context * @metrics_set: An ID for an OA unit metric set advertised via sysfs * @oa_format: An OA unit HW report format @@ -357,6 +359,7 @@ struct perf_open_properties {u32 sample_flags; u64 single_context:1; + u64 hold_preemption:1;u64 ctx_handle;/* OA sampling state */ @@ -2352,6 +2355,8 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, stream->sample_flags |=SAMPLE_OA_REPORT ; stream->sample_size += format_size; + stream->hold_preemption = props->hold_preemption; + dev_priv->perf.oa.oa_buffer.format_size = format_size;if (WARN_ON (dev_priv->perf.oa.oa_buffer.format_size ==0 ))return -EINVAL ;@@ -2890,6 +2895,15 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv, } } +if (props->hold_preemption) { +if (!props->single_context) { +DRM_DEBUG ("preemption disable with no context\n" ); + ret = -EINVAL ; + goto err; + } + privileged_op = true; + } +/* * On Haswell the OA unit supports clock gating off for a specific * context and in this mode there's no visibility of metrics for the @@ -2904,8 +2918,9 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv,* MI_REPORT_PERF_COUNT commands and so consider it a privileged op to * enable the OA unit by default. */ -if (IS_HASWELL (dev_priv) && specific_ctx) +if (IS_HASWELL (dev_priv) && specific_ctx && !props->hold_preemption) { privileged_op = false; + }/* Similar to perf's kernel.perf_paranoid_cpu sysctl option * we check a dev.i915.perf_stream_paranoid sysctl option @@ -2914,7 +2929,7 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv,*/ if (privileged_op && i915_perf_stream_paranoid && !capable (CAP_SYS_ADMIN )) { -DRM_DEBUG ("Insufficient privileges to open system-wide i915 perf stream\n" ); +DRM_DEBUG ("Insufficient privileges to open i915 perf stream\n" ); ret = -EACCES ; goto err_ctx; }
drivers/gpu/drm/i915/i915_perf.c static int read_properties_unlocked(struct drm_i915_private *dev_priv, · line 3125
Quoted 5 lines
drivers/gpu/drm/i915/i915_perf.c +2
-0@@ -3106,6 +3121,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_HOLD_PREEMPTION : + props->hold_preemption = value !=0 ?1 :0 ;
!!value.
Quoted 9 lines
drivers/gpu/drm/i915/i915_perf.c +1
-0+break ;case DRM_I915_PERF_PROP_MAX :MISSING_CASE (id);return -EINVAL ;drivers/gpu/drm/i915/i915_priolist_types.h +0
-0
drivers/gpu/drm/i915/i915_priolist_types.h enum { · line 25
Quoted 9 lines
drivers/gpu/drm/i915/i915_priolist_types.h +6
-0@@ -17,6 +17,13 @@ enum {I915_PRIORITY_NORMAL =I915_CONTEXT_DEFAULT_PRIORITY ,I915_PRIORITY_MAX =I915_CONTEXT_MAX_USER_PRIORITY +1 , +/* Requests containing performance queries must not be preempted by +* another context. They get scheduled with their default priority and +* once they reach the execlist ports we bump them to +* I915_PRIORITY_PERF so that they stick to the HW until they finish. +*/ + I915_PRIORITY_PERF = I915_CONTEXT_MAX_USER_PRIORITY + 2,
Just let it be next, one above max?
Quoted 21 lines
drivers/gpu/drm/i915/i915_priolist_types.h +1
-0+ I915_PRIORITY_INVALID = INT_MIN };drivers/gpu/drm/i915/i915_request.c +1
-0@@ -685,6 +685,7 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp) rq->batch =NULL ; rq->capture_list =NULL ; rq->waitboost = false; + rq->has_perf = false; rq->execution_mask =ALL_ENGINES ;INIT_LIST_HEAD (&rq->active_list);drivers/gpu/drm/i915/i915_request.h +0
-0
drivers/gpu/drm/i915/i915_request.h struct i915_request { · line 220
Quoted 4 lines
drivers/gpu/drm/i915/i915_request.h +1
-0@@ -217,6 +217,7 @@ struct i915_request {unsigned long emitted_jiffies;bool waitboost; +bool has_perf;
2 bools, probably time for a flags if we stick with this approach.
Also note previous patch didn't compile but rq->perf was out of sequence.
-Chris
_______________________________________________
Intel-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 08/10] drm/i915/perf: allow holding preemption on filtered ctx
Quoted 57 lines · Chris Wilson
Quoting Lionel Landwerlin (2019-06-27 09:00:43)
Quoted 44 lines
We would like to make use of perf in Vulkan. The Vulkan API is much lower level than OpenGL, with applications directly exposed to the concept of command buffers (pretty much equivalent to our batch buffers). In Vulkan, queries are always limited in scope to a command buffer. In OpenGL, the lack of command buffer concept meant that queries' duration could span multiple command buffers.
With that restriction gone in Vulkan, we would like to simplify measuring performance just by measuring the deltas between the counter snapshots written by 2
MI_RECORD_PERF_COUNTcommands, rather than the more complex scheme we currently have in the GL driver, using 2MI_RECORD_PERF_COUNTcommands and doing some post processing on the stream of OA reports, coming from the global OA buffer, to remove any unrelated deltas in between the 2MI_RECORD_PERF_COUNT.Disabling preemption only apply to a single context with which want to query performance counters for and is considered a privileged operation, by default protected by
CAP_SYS_ADMIN. It is possible to enable it for a normal user by disabling the paranoid stream setting.v2: Store preemption setting in
intel_context(Chris)v3: Use priorities to avoid preemption rather than the HW mechanism
v4: Just modify the port priority reporting function
Signed-off-by Lionel Landwerlin <[email protected]>--- drivers/gpu/drm/i915/gt/intel_lrc.c | 7 ++++++- drivers/gpu/drm/i915/i915_drv.c | 2 +- drivers/gpu/drm/i915/i915_drv.h | 13 ++++++++++++ drivers/gpu/drm/i915/i915_perf.c | 22 +++++++++++++++++++-- drivers/gpu/drm/i915/i915_priolist_types.h | 7 +++++++ drivers/gpu/drm/i915/i915_request.c | 1 + drivers/gpu/drm/i915/i915_request.h | 1 + drivers/gpu/drm/i915/intel_guc_submission.c | 12 ++++++++++- include/uapi/drm/i915_drm.h | 11 +++++++++++ 9 files changed, 71 insertions(+), 5 deletions(-)drivers/gpu/drm/i915/gt/intel_lrc.c +0
-0drivers/gpu/drm/i915/gt/intel_lrc.c static inline int rq_prio(const struct i915_request *rq) · line 264
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +6
-1@@ -256,7 +256,12 @@ static inline int rq_prio(const struct i915_request *rq)static int effective_prio (const struct i915_request *rq) { -int prio =rq_prio (rq); +int prio; + +if (rq->has_perf) + prio =I915_USER_PRIORITY (I915_PRIORITY_PERF ); +else + prio =rq_prio (rq);This doesn't cover everything. You will get timesliced now.
Quoted 7 lines
But I do think this is the safest approach that evades all the PI sanity checks and possible deadlocks.
There is also the problem where we check the priority on the last request in the queue, but preemption may need to be disabled at the head of the queue (the executing request). Is that a concern? I was thinking of marking the context as non-preemptible until after the oa is removed.
What do you mean by timesliced?
I don't really have a good way of working around the global counters so whatever you think is best to allow queries in batch buffers to complete.
Quoted 105 lines
Quoted 105 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +0
-0/* * On unwinding the active request, we give it a priority bump drivers/gpu/drm/i915/i915_drv.c +1
-1@@ -484,7 +484,7 @@ static int i915_getparam_ioctl(struct drm_device *dev, void *data, value =INTEL_INFO (dev_priv)->has_coherent_ggtt;break ;case I915_PARAM_PERF_REVISION : - value =1 ; + value =2 ;break ;case I915_PARAM_HAS_EXEC_PERF_CONFIG :/* Obviously requires perf support. */ drivers/gpu/drm/i915/i915_drv.h +13
-0@@ -1232,6 +1232,19 @@ struct i915_perf_stream {*/ bool enabled; +/** +* @hold_preemption: Whether preemption is put on hold for command +* submissions done on the @ctx. This is useful for some drivers that +* cannot easily post process the OA buffer context to subtract delta +* of performance counters not associated with @ctx. +*/ +bool hold_preemption; + +/** +* @last_config_request +*/ +struct i915_request *last_config_request; +/** * @ops: The callbacks providing the implementation of this specific * type of configured stream. drivers/gpu/drm/i915/i915_perf.c +17
-2@@ -343,6 +343,8 @@ static const struct i915_oa_format gen8_plus_oa_formats[I915_OA_FORMAT_MAX] = {* struct perf_open_properties - for validated properties given to open a stream * @sample_flags: `DRM_I915_PERF_PROP_SAMPLE_*` properties are tracked as flags * @single_context: Whether a single or all gpu contexts should be monitored +* @hold_preemption: Whether the preemption is disabled for the filtered +* context * @ctx_handle: A gem ctx handle for use with @single_context * @metrics_set: An ID for an OA unit metric set advertised via sysfs * @oa_format: An OA unit HW report format @@ -357,6 +359,7 @@ struct perf_open_properties {u32 sample_flags; u64 single_context:1; + u64 hold_preemption:1;u64 ctx_handle;/* OA sampling state */ @@ -2352,6 +2355,8 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, stream->sample_flags |=SAMPLE_OA_REPORT ; stream->sample_size += format_size; + stream->hold_preemption = props->hold_preemption; + dev_priv->perf.oa.oa_buffer.format_size = format_size;if (WARN_ON (dev_priv->perf.oa.oa_buffer.format_size ==0 ))return -EINVAL ;@@ -2890,6 +2895,15 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv, } } +if (props->hold_preemption) { +if (!props->single_context) { +DRM_DEBUG ("preemption disable with no context\n" ); + ret = -EINVAL ; + goto err; + } + privileged_op = true; + } +/* * On Haswell the OA unit supports clock gating off for a specific * context and in this mode there's no visibility of metrics for the @@ -2904,8 +2918,9 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv,* MI_REPORT_PERF_COUNT commands and so consider it a privileged op to * enable the OA unit by default. */ -if (IS_HASWELL (dev_priv) && specific_ctx) +if (IS_HASWELL (dev_priv) && specific_ctx && !props->hold_preemption) { privileged_op = false; + }/* Similar to perf's kernel.perf_paranoid_cpu sysctl option * we check a dev.i915.perf_stream_paranoid sysctl option @@ -2914,7 +2929,7 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv,*/ if (privileged_op && i915_perf_stream_paranoid && !capable (CAP_SYS_ADMIN )) { -DRM_DEBUG ("Insufficient privileges to open system-wide i915 perf stream\n" ); +DRM_DEBUG ("Insufficient privileges to open i915 perf stream\n" ); ret = -EACCES ; goto err_ctx;
Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c static int read_properties_unlocked(struct drm_i915_private *dev_priv, · line 3125
Quoted 7 lines
drivers/gpu/drm/i915/i915_perf.c +2
-0}@@ -3106,6 +3121,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_HOLD_PREEMPTION : + props->hold_preemption = value !=0 ?1 :0 ;!!value.
Done.
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/i915/i915_perf.c +1
-0+break ;case DRM_I915_PERF_PROP_MAX :MISSING_CASE (id);return -EINVAL ;drivers/gpu/drm/i915/i915_priolist_types.h +0
-0@@ -17,6 +17,13 @@ enum {I915_PRIORITY_NORMAL =I915_CONTEXT_DEFAULT_PRIORITY , I915_PRIORITY_MAX = I915_CONTEXT_MAX_USER_PRIORITY + 1,
Quoted 7 lines
drivers/gpu/drm/i915/i915_priolist_types.h enum { · line 25
Quoted 6 lines
drivers/gpu/drm/i915/i915_priolist_types.h +6
-0+/* Requests containing performance queries must not be preempted by +* another context. They get scheduled with their default priority and +* once they reach the execlist ports we bump them to +* I915_PRIORITY_PERF so that they stick to the HW until they finish. +*/ + I915_PRIORITY_PERF = I915_CONTEXT_MAX_USER_PRIORITY + 2,Just let it be next, one above max?
Done.
Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/i915/i915_priolist_types.h +1
-0+ I915_PRIORITY_INVALID = INT_MIN };drivers/gpu/drm/i915/i915_request.c +1
-0@@ -685,6 +685,7 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp) rq->batch =NULL ; rq->capture_list =NULL ; rq->waitboost = false; + rq->has_perf = false; rq->execution_mask =ALL_ENGINES ;INIT_LIST_HEAD (&rq->active_list);drivers/gpu/drm/i915/i915_request.h +0
-0@@ -217,6 +217,7 @@ struct i915_request {unsigned long emitted_jiffies;
Quoted 8 lines
drivers/gpu/drm/i915/i915_request.h struct i915_request { · line 220
Quoted 2 lines
drivers/gpu/drm/i915/i915_request.h +1
-0bool waitboost; +bool has_perf;2 bools, probably time for a flags if we stick with this approach.
Also note previous patch didn't compile but
rq->perfwas out of sequence.
-Chris
Done.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 08/10] drm/i915/perf: allow holding preemption on filtered ctx
Quoting Lionel Landwerlin (2019-06-27 15:27:40)
Quoted 61 lines · Chris Wilson
Quoted 60 lines
Quoting Lionel Landwerlin (2019-06-27 09:00:43)
Quoted 44 lines
We would like to make use of perf in Vulkan. The Vulkan API is much lower level than OpenGL, with applications directly exposed to the concept of command buffers (pretty much equivalent to our batch buffers). In Vulkan, queries are always limited in scope to a command buffer. In OpenGL, the lack of command buffer concept meant that queries' duration could span multiple command buffers.
With that restriction gone in Vulkan, we would like to simplify measuring performance just by measuring the deltas between the counter snapshots written by 2
MI_RECORD_PERF_COUNTcommands, rather than the more complex scheme we currently have in the GL driver, using 2MI_RECORD_PERF_COUNTcommands and doing some post processing on the stream of OA reports, coming from the global OA buffer, to remove any unrelated deltas in between the 2MI_RECORD_PERF_COUNT.Disabling preemption only apply to a single context with which want to query performance counters for and is considered a privileged operation, by default protected by
CAP_SYS_ADMIN. It is possible to enable it for a normal user by disabling the paranoid stream setting.v2: Store preemption setting in
intel_context(Chris)v3: Use priorities to avoid preemption rather than the HW mechanism
v4: Just modify the port priority reporting function
Signed-off-by Lionel Landwerlin <[email protected]>--- drivers/gpu/drm/i915/gt/intel_lrc.c | 7 ++++++- drivers/gpu/drm/i915/i915_drv.c | 2 +- drivers/gpu/drm/i915/i915_drv.h | 13 ++++++++++++ drivers/gpu/drm/i915/i915_perf.c | 22 +++++++++++++++++++-- drivers/gpu/drm/i915/i915_priolist_types.h | 7 +++++++ drivers/gpu/drm/i915/i915_request.c | 1 + drivers/gpu/drm/i915/i915_request.h | 1 + drivers/gpu/drm/i915/intel_guc_submission.c | 12 ++++++++++- include/uapi/drm/i915_drm.h | 11 +++++++++++ 9 files changed, 71 insertions(+), 5 deletions(-)drivers/gpu/drm/i915/gt/intel_lrc.c +0
-0drivers/gpu/drm/i915/gt/intel_lrc.c static inline int rq_prio(const struct i915_request *rq) · line 264
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +6
-1@@ -256,7 +256,12 @@ static inline int rq_prio(const struct i915_request *rq)static int effective_prio (const struct i915_request *rq) { -int prio =rq_prio (rq); +int prio; + +if (rq->has_perf) + prio =I915_USER_PRIORITY (I915_PRIORITY_PERF ); +else + prio =rq_prio (rq);This doesn't cover everything. You will get timesliced now.
But I do think this is the safest approach that evades all the PI sanity checks and possible deadlocks.
Quoted 7 lines
Quoted 4 lines
There is also the problem where we check the priority on the last request in the queue, but preemption may need to be disabled at the head of the queue (the executing request). Is that a concern? I was thinking of marking the context as non-preemptible until after the oa is removed.
What do you mean by timesliced?
Actually just sent the patch that would allow this to apply to the other preemption path.
Quoted 2 lines
I don't really have a good way of working around the global counters so whatever you think is best to allow queries in batch buffers to complete.
Gut feeling is that if you need preemption protection, it should be on the context. Otherwise it seems easy to create a situation where the request being tracked for the context submission doesn't have the oa flag, but is masking one that does.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 9/10 drm/i915/perf: execute OA configuration from command stream
In reply to Lionel LandwerlinWe can't run into issues with doing writing the global OA/NOA registers configuration from CPU so far, but HW engineers actually recommend doing this from the command streamer.
Since we have a command buffer prepared for the execbuffer side of things, we can reuse that approach here too.
--- drivers/gpu/drm/i915/i915_perf.c | 203 +++++++++++++++---------------- 1 file changed, 100 insertions(+), 103 deletions(-)
drivers/gpu/drm/i915/i915_perf.c +100 -103
@@ -389,6 +389,19 @@ void i915_oa_config_release(struct kref *ref)kfree (oa_config); } +static void i915_oa_config_dispose_buffers (struct drm_i915_private *i915) +{ +struct i915_oa_config *oa_config, *next; + +mutex_lock (&i915->perf.metrics_lock); +list_for_each_entry_safe (oa_config, next, &i915->perf.metrics_buffers, vma_link) { +list_del (&oa_config->vma_link); +i915_gem_object_put (oa_config->obj); + oa_config->obj =NULL ; + } +mutex_unlock (&i915->perf.metrics_lock); +} +static u32 *write_cs_mi_lri (u32 *cs,const struct i915_oa_reg *reg_data,u32 n_regs) {u32 i;
@@ -1813,67 +1826,86 @@ static int alloc_noa_wait(struct drm_i915_private *i915)return ret; } -static void config_oa_regs (struct drm_i915_private *dev_priv, -const struct i915_oa_reg *regs, -u32 n_regs) +static int config_oa_regs (struct drm_i915_private *i915, +struct i915_oa_config *oa_config) { -u32 i; +struct i915_request *rq; +struct i915_vma *vma; +long timeout; +u32 *cs; +int err; -for (i =0 ; i < n_regs; i++) { -const struct i915_oa_reg *reg = regs + i; + rq =i915_request_create (i915->engine[RCS0 ]->kernel_context); +if (IS_ERR (rq)) +return PTR_ERR (rq); -I915_WRITE (reg->addr, reg->value); + err =i915_active_request_set (&i915->engine[RCS0 ]->last_oa_config, + rq); +if (err) { +i915_request_add (rq); +return err; + } + + vma =i915_vma_instance (oa_config->obj, &i915->ggtt.vm,NULL ); +if (unlikely (IS_ERR (vma))) { +i915_request_add (rq); +return PTR_ERR (vma); + } + + err =i915_vma_pin (vma,0 ,0 ,PIN_GLOBAL ); +if (err) { +i915_request_add (rq); +return err; } + + err =i915_vma_move_to_active (vma, rq,0 ); +if (err) { +i915_vma_unpin (vma); +i915_request_add (rq); +return err; + } + + cs =intel_ring_begin (rq,INTEL_GEN (i915) >=8 ?4 :2 ); +if (IS_ERR (cs)) { +i915_vma_unpin (vma); +i915_request_add (rq); +return PTR_ERR (cs); + } + +if (INTEL_GEN (i915) >8 ) { + *cs++ =MI_BATCH_BUFFER_START_GEN8 ; + *cs++ =lower_32_bits (vma->node.start); + *cs++ =upper_32_bits (vma->node.start); + *cs++ =MI_NOOP ; + }else { + *cs++ =MI_BATCH_BUFFER_START ; + *cs++ = vma->node.start; + } + +intel_ring_advance (rq, cs); + +i915_vma_unpin (vma); + +i915_request_add (rq); + +i915_request_get (rq); + timeout =i915_request_wait (rq,I915_WAIT_INTERRUPTIBLE |I915_WAIT_LOCKED , +MAX_SCHEDULE_TIMEOUT ); +i915_request_put (rq); + +return timeout <0 ? err :0 ; }static int hsw_enable_metric_set (struct i915_perf_stream *stream) {struct drm_i915_private *dev_priv = stream->dev_priv; -const struct i915_oa_config *oa_config = stream->oa_config; -/* PRM: -* -* OA unit is using “crclk” for its functionality. When trunk -* level clock gating takes place, OA clock would be gated, -* unable to count the events from non-render clock domain. -* Render clock gating must be disabled when OA is enabled to -* count the events from non-render domain. Unit level clock -* gating for RCS should also be disabled. -*/ I915_WRITE (GEN7_MISCCPCTL , (I915_READ (GEN7_MISCCPCTL ) & ~GEN7_DOP_CLOCK_GATE_ENABLE ));I915_WRITE (GEN6_UCGCTL1 , (I915_READ (GEN6_UCGCTL1 ) |GEN6_CSUNIT_CLOCK_GATE_DISABLE )); -config_oa_regs (dev_priv, oa_config->mux_regs, oa_config->mux_regs_len); - -/* It apparently takes a fairly long time for a new MUX -* configuration to be be applied after these register writes. -* This delay duration was derived empirically based on the -* render_basic config but hopefully it covers the maximum -* configuration latency. -* -* As a fallback, the checks in _append_oa_reports() to skip -* invalid OA reports do also seem to work to discard reports -* generated before this config has completed - albeit not -* silently. -* -* Unfortunately this is essentially a magic number, since we -* don't currently know of a reliable mechanism for predicting -* how long the MUX config will take to apply and besides -* seeing invalid reports we don't know of a reliable way to -* explicitly check that the MUX config has landed. -* -* It's even possible we've miss characterized the underlying -* problem - it just seems like the simplest explanation why -* a delay at this location would mitigate any invalid reports. -*/ -usleep_range (15000 ,20000 ); - -config_oa_regs (dev_priv, oa_config->b_counter_regs, - oa_config->b_counter_regs_len); - -return 0 ; +return config_oa_regs (dev_priv, stream->oa_config); }static void hsw_disable_metric_set (struct drm_i915_private *dev_priv)
@@ -1978,7 +2010,6 @@ static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv, {unsigned int map_type =i915_coherent_map_type (dev_priv);struct i915_gem_context *ctx; -struct i915_request *rq;int ret;lockdep_assert_held (&dev_priv->drm.struct_mutex);
@@ -2037,14 +2068,9 @@ static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv, }/* -* Apply the configuration by doing one context restore of the edited -* context image. +* The above configuration will be applied when called +* config_oa_regs(). */ - rq =i915_request_create (dev_priv->engine[RCS0 ]->kernel_context); -if (IS_ERR (rq)) -return PTR_ERR (rq); - -i915_request_add (rq);return 0 ; }
@@ -2093,35 +2119,7 @@ static int gen8_enable_metric_set(struct i915_perf_stream *stream)if (ret)return ret; -config_oa_regs (dev_priv, oa_config->mux_regs, oa_config->mux_regs_len); - -/* It apparently takes a fairly long time for a new MUX -* configuration to be be applied after these register writes. -* This delay duration was derived empirically based on the -* render_basic config but hopefully it covers the maximum -* configuration latency. -* -* As a fallback, the checks in _append_oa_reports() to skip -* invalid OA reports do also seem to work to discard reports -* generated before this config has completed - albeit not -* silently. -* -* Unfortunately this is essentially a magic number, since we -* don't currently know of a reliable mechanism for predicting -* how long the MUX config will take to apply and besides -* seeing invalid reports we don't know of a reliable way to -* explicitly check that the MUX config has landed. -* -* It's even possible we've miss characterized the underlying -* problem - it just seems like the simplest explanation why -* a delay at this location would mitigate any invalid reports. -*/ -usleep_range (15000 ,20000 ); - -config_oa_regs (dev_priv, oa_config->b_counter_regs, - oa_config->b_counter_regs_len); - -return 0 ; +return config_oa_regs (dev_priv, stream->oa_config); }static void gen8_disable_metric_set (struct drm_i915_private *dev_priv)
@@ -2292,6 +2290,7 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, struct perf_open_properties *props) {struct drm_i915_private *dev_priv = stream->dev_priv; +struct drm_i915_gem_object *obj;int format_size;int ret;
@@ -2376,13 +2375,6 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, } } - ret =i915_perf_get_oa_config (dev_priv, props->metrics_set, - &stream->oa_config,NULL ); -if (ret) { -DRM_DEBUG ("Invalid OA config id=%i\n" , props->metrics_set); - goto err_config; - } - ret =alloc_noa_wait (dev_priv);if (ret) {DRM_DEBUG ("Unable to allocate NOA wait batch buffer\n" );
@@ -2412,6 +2404,19 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,if (ret) goto err_lock; + ret =i915_perf_get_oa_config (dev_priv, props->metrics_set, + &stream->oa_config, &obj); +if (ret) { +DRM_DEBUG ("Invalid OA config id=%i\n" , props->metrics_set); + goto err_config; + } + +/* +* We just need the buffer to be created, but not our own reference on +* it as the oa_config already has one. +*/ +i915_gem_object_put (obj); + stream->ops = &i915_oa_stream_ops; dev_priv->perf.oa.exclusive_stream = stream;
@@ -2430,14 +2435,16 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, err_enable: dev_priv->perf.oa.exclusive_stream =NULL ; dev_priv->perf.oa.ops.disable_metric_set (dev_priv); + +err_config: +i915_oa_config_put (stream->oa_config); +i915_oa_config_dispose_buffers (dev_priv);mutex_unlock (&dev_priv->drm.struct_mutex); err_lock:free_oa_buffer (dev_priv); err_oa_buf_alloc: -i915_oa_config_put (stream->oa_config); -intel_uncore_forcewake_put (&dev_priv->uncore,FORCEWAKE_ALL );intel_runtime_pm_put (&dev_priv->runtime_pm, stream->wakeref);
@@ -2446,9 +2453,6 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,mutex_unlock (&dev_priv->drm.struct_mutex); err_noa_wait_alloc: -i915_oa_config_put (stream->oa_config); - -err_config:if (stream->ctx)oa_put_render_ctx_id (stream);
@@ -2810,20 +2814,13 @@ static int i915_perf_release(struct inode *inode, struct file *file) {struct i915_perf_stream *stream = file->private_data;struct drm_i915_private *dev_priv = stream->dev_priv; -struct i915_oa_config *oa_config, *next;mutex_lock (&dev_priv->perf.lock);i915_perf_destroy_locked (stream);/* Dispose of all oa config batch buffers. */ -mutex_lock (&dev_priv->perf.metrics_lock); -list_for_each_entry_safe (oa_config, next, &dev_priv->perf.metrics_buffers, vma_link) { -list_del (&oa_config->vma_link); -i915_gem_object_put (oa_config->obj); - oa_config->obj =NULL ; - } -mutex_unlock (&dev_priv->perf.metrics_lock); +i915_oa_config_dispose_buffers (dev_priv);mutex_unlock (&dev_priv->perf.lock);
Signature · 6 lines
2.21.0.392.gf8f6787159e _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 09/10] drm/i915/perf: execute OA configuration from command stream
Quoting Lionel Landwerlin (2019-06-27 09:00:44)
Quoted 52 lines
We can't run into issues with doing writing the global OA/NOA registers configuration from CPU so far, but HW engineers actually recommend doing this from the command streamer.
Since we have a command buffer prepared for the execbuffer side of things, we can reuse that approach here too.
Signed-off-by Lionel Landwerlin <[email protected]>--- drivers/gpu/drm/i915/i915_perf.c | 203 +++++++++++++++---------------- 1 file changed, 100 insertions(+), 103 deletions(-)drivers/gpu/drm/i915/i915_perf.c +20
-4@@ -389,6 +389,19 @@ void i915_oa_config_release(struct kref *ref)kfree (oa_config); } +static void i915_oa_config_dispose_buffers (struct drm_i915_private *i915) +{ +struct i915_oa_config *oa_config, *next; + +mutex_lock (&i915->perf.metrics_lock); +list_for_each_entry_safe (oa_config, next, &i915->perf.metrics_buffers, vma_link) { +list_del (&oa_config->vma_link); +i915_gem_object_put (oa_config->obj); + oa_config->obj =NULL ; + } +mutex_unlock (&i915->perf.metrics_lock); +} +static u32 *write_cs_mi_lri (u32 *cs,const struct i915_oa_reg *reg_data,u32 n_regs) {u32 i;@@ -1813,67 +1826,86 @@ static int alloc_noa_wait(struct drm_i915_private *i915)return ret; } -static void config_oa_regs (struct drm_i915_private *dev_priv, -const struct i915_oa_reg *regs, -u32 n_regs) +static int config_oa_regs (struct drm_i915_private *i915, +struct i915_oa_config *oa_config) { -u32 i; +struct i915_request *rq; +struct i915_vma *vma; +long timeout; +u32 *cs; +int err;
drivers/gpu/drm/i915/i915_perf.c static int alloc_noa_wait(struct drm_i915_private *i915) · line 1843
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +5
-3-for (i =0 ; i < n_regs; i++) { -const struct i915_oa_reg *reg = regs + i; + rq =i915_request_create (i915->engine[RCS0 ]->kernel_context); +if (IS_ERR (rq)) +return PTR_ERR (rq); -I915_WRITE (reg->addr, reg->value); + err =i915_active_request_set (&i915->engine[RCS0 ]->last_oa_config, + rq);
This will need an explicit mutex as it is not serialised by any single timeline.
i915->perf.metrics_lock viable? Needs to be taken here and in execbuf.
Quoted 6 lines
drivers/gpu/drm/i915/i915_perf.c +6
-0+if (err) { +i915_request_add (rq); +return err; + } + + vma =i915_vma_instance (oa_config->obj, &i915->ggtt.vm,NULL );
drivers/gpu/drm/i915/i915_perf.c static int alloc_noa_wait(struct drm_i915_private *i915) · line 1859
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +9
-0+if (unlikely (IS_ERR (vma))) { +i915_request_add (rq); +return PTR_ERR (vma); + } + + err =i915_vma_pin (vma,0 ,0 ,PIN_GLOBAL ); +if (err) { +i915_request_add (rq); +return err; }
This time there is no excuse for not pinning outside of the timeline->mutex.
Quoted 23 lines
drivers/gpu/drm/i915/i915_perf.c +22
-0+ + err =i915_vma_move_to_active (vma, rq,0 ); +if (err) { +i915_vma_unpin (vma); +i915_request_add (rq); +return err; + } + + cs =intel_ring_begin (rq,INTEL_GEN (i915) >=8 ?4 :2 ); +if (IS_ERR (cs)) { +i915_vma_unpin (vma); +i915_request_add (rq); +return PTR_ERR (cs); + } + +if (INTEL_GEN (i915) >8 ) { + *cs++ =MI_BATCH_BUFFER_START_GEN8 ; + *cs++ =lower_32_bits (vma->node.start); + *cs++ =upper_32_bits (vma->node.start); + *cs++ =MI_NOOP ; + }else { + *cs++ =MI_BATCH_BUFFER_START ;
drivers/gpu/drm/i915/i915_perf.c static int alloc_noa_wait(struct drm_i915_private *i915) · line 1891
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+ *cs++ = vma->node.start; + } + +intel_ring_advance (rq, cs); + +i915_vma_unpin (vma); + +i915_request_add (rq); + +i915_request_get (rq);
Strictly, before the add, as the add is the xfer of the ref.
drivers/gpu/drm/i915/i915_perf.c static int alloc_noa_wait(struct drm_i915_private *i915) · line 1896
Quoted 5 lines
drivers/gpu/drm/i915/i915_perf.c +5
-0+ timeout =i915_request_wait (rq,I915_WAIT_INTERRUPTIBLE |I915_WAIT_LOCKED , +MAX_SCHEDULE_TIMEOUT ); +i915_request_put (rq); + +return timeout <0 ? err :0 ;
Report err, but timeline carries the errno?
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 09/10] drm/i915/perf: execute OA configuration from command stream
Quoted 60 lines · Chris Wilson
Quoting Lionel Landwerlin (2019-06-27 09:00:44)
Quoted 59 lines
We can't run into issues with doing writing the global OA/NOA registers configuration from CPU so far, but HW engineers actually recommend doing this from the command streamer.
Since we have a command buffer prepared for the execbuffer side of things, we can reuse that approach here too.
Signed-off-by Lionel Landwerlin <[email protected]>--- drivers/gpu/drm/i915/i915_perf.c | 203 +++++++++++++++---------------- 1 file changed, 100 insertions(+), 103 deletions(-)drivers/gpu/drm/i915/i915_perf.c +23
-6@@ -389,6 +389,19 @@ void i915_oa_config_release(struct kref *ref)kfree (oa_config); } +static void i915_oa_config_dispose_buffers (struct drm_i915_private *i915) +{ +struct i915_oa_config *oa_config, *next; + +mutex_lock (&i915->perf.metrics_lock); +list_for_each_entry_safe (oa_config, next, &i915->perf.metrics_buffers, vma_link) { +list_del (&oa_config->vma_link); +i915_gem_object_put (oa_config->obj); + oa_config->obj =NULL ; + } +mutex_unlock (&i915->perf.metrics_lock); +} +static u32 *write_cs_mi_lri (u32 *cs,const struct i915_oa_reg *reg_data,u32 n_regs) {u32 i;@@ -1813,67 +1826,86 @@ static int alloc_noa_wait(struct drm_i915_private *i915)return ret; } -static void config_oa_regs (struct drm_i915_private *dev_priv, -const struct i915_oa_reg *regs, -u32 n_regs) +static int config_oa_regs (struct drm_i915_private *i915, +struct i915_oa_config *oa_config) { -u32 i; +struct i915_request *rq; +struct i915_vma *vma; +long timeout; +u32 *cs; +int err; -for (i =0 ; i < n_regs; i++) { -const struct i915_oa_reg *reg = regs + i; + rq =i915_request_create (i915->engine[RCS0 ]->kernel_context); +if (IS_ERR (rq)) +return PTR_ERR (rq);
Quoted 7 lines
drivers/gpu/drm/i915/i915_perf.c static int alloc_noa_wait(struct drm_i915_private *i915) · line 1843
Quoted 3 lines
drivers/gpu/drm/i915/i915_perf.c +2
-1-I915_WRITE (reg->addr, reg->value); + err =i915_active_request_set (&i915->engine[RCS0 ]->last_oa_config, + rq);This will need an explicit mutex as it is not serialised by any single timeline.
i915->perf.metrics_lockviable? Needs to be taken here and in execbuf.
Not sure that I understand. This function is called under struct_mutex lock.
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+if (err) { +i915_request_add (rq); +return err; + } + + vma =i915_vma_instance (oa_config->obj, &i915->ggtt.vm,NULL ); +if (unlikely (IS_ERR (vma))) { +i915_request_add (rq); +return PTR_ERR (vma); + }
Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c static int alloc_noa_wait(struct drm_i915_private *i915) · line 1859
Quoted 6 lines
drivers/gpu/drm/i915/i915_perf.c +5
-0+ + err =i915_vma_pin (vma,0 ,0 ,PIN_GLOBAL ); +if (err) { +i915_request_add (rq); +return err; }This time there is no excuse for not pinning outside of the
timeline->mutex.
Right, okay, but there is so much going on when turning on i915-perf, draining + idling + context image edition.
Do we really need to optimize this in this patch?
After all this removes the cpu wait that was done under struct_mutex lock.
Quoted 26 lines
Quoted 26 lines
drivers/gpu/drm/i915/i915_perf.c +25
-0+ + err =i915_vma_move_to_active (vma, rq,0 ); +if (err) { +i915_vma_unpin (vma); +i915_request_add (rq); +return err; + } + + cs =intel_ring_begin (rq,INTEL_GEN (i915) >=8 ?4 :2 ); +if (IS_ERR (cs)) { +i915_vma_unpin (vma); +i915_request_add (rq); +return PTR_ERR (cs); + } + +if (INTEL_GEN (i915) >8 ) { + *cs++ =MI_BATCH_BUFFER_START_GEN8 ; + *cs++ =lower_32_bits (vma->node.start); + *cs++ =upper_32_bits (vma->node.start); + *cs++ =MI_NOOP ; + }else { + *cs++ =MI_BATCH_BUFFER_START ; + *cs++ = vma->node.start; + } +
Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c static int alloc_noa_wait(struct drm_i915_private *i915) · line 1891
Quoted 7 lines
drivers/gpu/drm/i915/i915_perf.c +7
-0+intel_ring_advance (rq, cs); + +i915_vma_unpin (vma); + +i915_request_add (rq); + +i915_request_get (rq);Strictly, before the add, as the add is the xfer of the ref.
Oops.
Quoted 7 lines
drivers/gpu/drm/i915/i915_perf.c static int alloc_noa_wait(struct drm_i915_private *i915) · line 1896
Quoted 6 lines
drivers/gpu/drm/i915/i915_perf.c +5
-0+ timeout =i915_request_wait (rq,I915_WAIT_INTERRUPTIBLE |I915_WAIT_LOCKED , +MAX_SCHEDULE_TIMEOUT ); +i915_request_put (rq); + +return timeout <0 ? err :0 ;Report err, but timeline carries the errno?
I meant to return timeout.
Quoted 2 lines
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5 09/10] drm/i915/perf: execute OA configuration from command stream
Quoting Lionel Landwerlin (2019-06-27 15:50:38)
Quoted 31 lines · Chris Wilson
Quoted 30 lines
Quoting Lionel Landwerlin (2019-06-27 09:00:44)
Quoted 16 lines
drivers/gpu/drm/i915/i915_perf.c +7
-4@@ -1813,67 +1826,86 @@ static int alloc_noa_wait(struct drm_i915_private *i915)return ret; } -static void config_oa_regs (struct drm_i915_private *dev_priv, -const struct i915_oa_reg *regs, -u32 n_regs) +static int config_oa_regs (struct drm_i915_private *i915, +struct i915_oa_config *oa_config) { -u32 i; +struct i915_request *rq; +struct i915_vma *vma; +long timeout; +u32 *cs; +int err;drivers/gpu/drm/i915/i915_perf.c static int alloc_noa_wait(struct drm_i915_private *i915) · line 1843
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +5
-3-for (i =0 ; i < n_regs; i++) { -const struct i915_oa_reg *reg = regs + i; + rq =i915_request_create (i915->engine[RCS0 ]->kernel_context); +if (IS_ERR (rq)) +return PTR_ERR (rq); -I915_WRITE (reg->addr, reg->value); + err =i915_active_request_set (&i915->engine[RCS0 ]->last_oa_config, + rq);This will need an explicit mutex as it is not serialised by any single timeline.
Quoted 4 lines
Quoted 1 line
i915->perf.metrics_lockviable? Needs to be taken here and in execbuf.Not sure that I understand. This function is called under
struct_mutexlock.
The active_request is serialised by the timeline lock, which for about the next 10 minutes struct_mutex remains in lieu of. I want you to nominate an explicit lock for serialisation of the last_oa_config barrier
Quoted 21 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+if (err) { +i915_request_add (rq); +return err; + } + + vma =i915_vma_instance (oa_config->obj, &i915->ggtt.vm,NULL ); +if (unlikely (IS_ERR (vma))) { +i915_request_add (rq); +return PTR_ERR (vma); + }Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c static int alloc_noa_wait(struct drm_i915_private *i915) · line 1859
Quoted 6 lines
drivers/gpu/drm/i915/i915_perf.c +5
-0+ + err =i915_vma_pin (vma,0 ,0 ,PIN_GLOBAL ); +if (err) { +i915_request_add (rq); +return err; }This time there is no excuse for not pinning outside of the
timeline->mutex.
Quoted 4 lines
Right, okay, but there is so much going on when turning on i915-perf, draining + idling + context image edition.
Do we really need to optimize this in this patch?
It's not optimizing, it's about the lock nesting. To pin a vma, we may ultimately need to emit requests, at which point trying to pin from inside a request critical section is going to make lockdep rightfully complain.
Quoted 1 line
After all this removes the cpu wait that was done under
struct_mutexlock.
Puzzling, as all of this is under struct_mutex and may require waits :( Fear not, removing struct_mutex here is easier than execbuf, so only 50 patches!
So long as you haven't used struct_mutex for serialising perf :)
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/i915/i915_perf.c static int alloc_noa_wait(struct drm_i915_private *i915) · line 1893
Quoted 2 lines
drivers/gpu/drm/i915/i915_perf.c +2
-0+ timeout =i915_request_wait (rq,I915_WAIT_INTERRUPTIBLE |I915_WAIT_LOCKED , +MAX_SCHEDULE_TIMEOUT );
One other thing, I915_WAIT_LOCKED is no longer used. -Chris
_______________________________________________
Intel-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 10/10 drm/i915: add support for perf configuration queries
In reply to Lionel LandwerlinListing configurations at the moment is supported only through sysfs. This might cause issues for applications wanting to list configurations from a container where sysfs isn't available.
This change adds a way to query the number of configurations and their content through the i915 query uAPI.
v2: Fix sparse warnings (Lionel)
Add support to query configuration using uuid (Lionel)
v3: Fix some inconsistency in uapi header (Lionel)
Fix unlocking when not locked issue (Lionel) Add debug messages (Lionel)
v4: Fix missing unlock (Dan)
--- drivers/gpu/drm/i915/i915_drv.h | 6 + drivers/gpu/drm/i915/i915_perf.c | 4 + drivers/gpu/drm/i915/i915_query.c | 279 ++++++++++++++++++++++++++++++ include/uapi/drm/i915_drm.h | 62 ++++++- 4 files changed, 350 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +6 -0
@@ -1730,6 +1730,12 @@ struct drm_i915_private {*/ struct list_head metrics_buffers; +/* +* Number of dynamic configurations, you need to hold +* dev_priv->perf.metrics_lock to access it. +*/ +u32 n_metrics; +/* * Lock associated with anything below within this structure * except exclusive_stream.
drivers/gpu/drm/i915/i915_perf.c +4 -0
@@ -3609,6 +3609,8 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data, goto sysfs_err; } + dev_priv->perf.n_metrics++; +mutex_unlock (&dev_priv->perf.metrics_lock);DRM_DEBUG ("Added config %s id=%i\n" , oa_config->uuid, oa_config->id);
@@ -3670,6 +3672,8 @@ int i915_perf_remove_config_ioctl(struct drm_device *dev, void *data,idr_remove (&dev_priv->perf.metrics_idr, *arg); + dev_priv->perf.n_metrics--; +DRM_DEBUG ("Removed config %s id=%i\n" , oa_config->uuid, oa_config->id);i915_oa_config_put (oa_config);
drivers/gpu/drm/i915/i915_query.c +279 -0
289 lines not on this page · raw message
include/uapi/drm/i915_drm.h +61 -1
82 lines not on this page · raw message
Signature · 6 lines
2.21.0.392.gf8f6787159e _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Fi.CI.BAT: failure for drm/i915: Vulkan performance query support (rev5)
In reply to Lionel Landwerlin== Series Details ==
== Series Details ==
Series: drm/i915: Vulkan performance query support (rev5)
URL : https://patchwork.freedesktop.org/series/60916/
State : failure
== Summary ==
CALL scripts/checksyscalls.sh
CALL scripts/atomic/check-atomics.sh
DESCEND objtool
CHK include/generated/compile.h
AR drivers/gpu/drm/i915/built-in.a
CC [M] drivers/gpu/drm/i915/header_test_i915_active_types.o
CC [M] drivers/gpu/drm/i915/header_test_i915_debugfs.o
CC [M] drivers/gpu/drm/i915/header_test_i915_drv.o
CC [M] drivers/gpu/drm/i915/header_test_i915_fixed.o
CC [M] drivers/gpu/drm/i915/header_test_i915_gem_gtt.o
CC [M] drivers/gpu/drm/i915/header_test_i915_globals.o
CC [M] drivers/gpu/drm/i915/header_test_i915_irq.o
CC [M] drivers/gpu/drm/i915/header_test_i915_params.o
CC [M] drivers/gpu/drm/i915/header_test_i915_priolist_types.o
CC [M] drivers/gpu/drm/i915/header_test_i915_pvinfo.o
CC [M] drivers/gpu/drm/i915/header_test_i915_reg.o
CC [M] drivers/gpu/drm/i915/header_test_i915_scheduler_types.o
CC [M] drivers/gpu/drm/i915/header_test_i915_utils.o
CC [M] drivers/gpu/drm/i915/header_test_i915_vgpu.o
CC [M] drivers/gpu/drm/i915/header_test_intel_csr.o
CC [M] drivers/gpu/drm/i915/header_test_intel_drv.o
CC [M] drivers/gpu/drm/i915/header_test_intel_guc_ct.o
CC [M] drivers/gpu/drm/i915/header_test_intel_guc_fwif.o
CC [M] drivers/gpu/drm/i915/header_test_intel_guc_reg.o
CC [M] drivers/gpu/drm/i915/header_test_intel_gvt.o
CC [M] drivers/gpu/drm/i915/header_test_intel_pm.o
CC [M] drivers/gpu/drm/i915/header_test_intel_runtime_pm.o
CC [M] drivers/gpu/drm/i915/header_test_intel_sideband.o
CC [M] drivers/gpu/drm/i915/header_test_intel_uc_fw.o
CC [M] drivers/gpu/drm/i915/header_test_intel_uncore.o
CC [M] drivers/gpu/drm/i915/header_test_intel_wakeref.o
CC [M] drivers/gpu/drm/i915/i915_drv.o
drivers/gpu/drm/i915/i915_drv.c:3229:6: error: initialization makes pointer from integer without a cast [-Werror=int-conversion]
DRIVER_SYNCOBJ_TIMELINE,
^~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/i915_drv.c:3229:6: note: (near initialization for ‘driver.ioctls’)
drivers/gpu/drm/i915/i915_drv.c:3249:12: error: initialized field overwritten [-Werror=override-init]
.ioctls = i915_ioctls,
^~~~~~~~~~~drivers/gpu/drm/i915/i915_drv.c:3249:12: note: (near initialization for ‘driver.ioctls’)
cc1: all warnings being treated as errorsscripts/Makefile.build:278: recipe for target 'drivers/gpu/drm/i915/i915_drv.o' failed make[4]: *** [drivers/gpu/drm/i915/i915_drv.o] Error 1 scripts/Makefile.build:489: recipe for target 'drivers/gpu/drm/i915' failed make[3]: *** [drivers/gpu/drm/i915] Error 2scripts/Makefile.build:489: recipe for target 'drivers/gpu/drm' failed make[2]: *** [drivers/gpu/drm] Error 2scripts/Makefile.build:489: recipe for target 'drivers/gpu' failed make[1]: *** [drivers/gpu] Error 2
Makefile:1071: recipe for target 'drivers' failed
make: *** [drivers] Error 2
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx