drm/i915/guc: Add Compute context hint
Subsystems (3)
PATCH 1/1 drm/i915/guc: Add Compute context hint
Allow user to provide a context hint. When this is set, KMD will send a hint to GuC which results in special handling for this context. SLPC will ramp the GT frequency aggressively every time it switches to this context. The down freq threshold will also be lower so GuC will ramp down the GT freq for this context more slowly. We also disable waitboost for this context as that will interfere with the strategy.
We need to enable the use of Compute strategy during SLPC init, but it will apply only to contexts that set this bit during context creation.
Userland can check whether this feature is supported using a new param- I915_PARAM_HAS_COMPUTE_CONTEXT. This flag is true for all guc submission enabled platforms since they use SLPC for freq management.
The Mesa usage model for this flag is here -
https://gitlab.freedesktop.org/sushmave/mesa/-/commits/compute_hint
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 8 +++++++ .../gpu/drm/i915/gem/i915_gem_context_types.h | 1 + drivers/gpu/drm/i915/gt/intel_rps.c | 8 +++++++ .../drm/i915/gt/uc/abi/guc_actions_slpc_abi.h | 21 +++++++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c | 17 +++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h | 1 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 7 +++++++ drivers/gpu/drm/i915/i915_getparam.c | 11 ++++++++++ include/uapi/drm/i915_drm.h | 15 +++++++++++++ 9 files changed, 89 insertions(+)
drivers/gpu/drm/i915/gem/i915_gem_context.c +8 -0
@@ -879,6 +879,7 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv,struct i915_gem_proto_context *pc, struct drm_i915_gem_context_param *args) { + struct drm_i915_private *i915 = fpriv->i915;int ret =0 ;switch (args->param) {
@@ -904,6 +905,13 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv, pc->user_flags &= ~BIT (UCONTEXT_BANNABLE );break ; +case I915_CONTEXT_PARAM_IS_COMPUTE : +if (!intel_uc_uses_guc_submission (&to_gt (i915)->uc)) + ret = -EINVAL ; +else + pc->user_flags |=BIT (UCONTEXT_COMPUTE ); +break ; +case I915_CONTEXT_PARAM_RECOVERABLE :if (args->size) ret = -EINVAL ;
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +1 -0
@@ -338,6 +338,7 @@ struct i915_gem_context {#define UCONTEXT_BANNABLE 2#define UCONTEXT_RECOVERABLE 3#define UCONTEXT_PERSISTENCE 4 +#define UCONTEXT_COMPUTE 5/** * @flags: small set of booleans
drivers/gpu/drm/i915/gt/intel_rps.c +8 -0
@@ -24,6 +24,7 @@#include "intel_pcode.h" #include "intel_rps.h" #include "vlv_sideband.h" +#include "../gem/i915_gem_context.h" #include "../../../platform/x86/intel_ips.h" #define BUSY_MAX_EI 20u/* ms */
@@ -1018,6 +1019,13 @@ void intel_rps_boost(struct i915_request *rq)struct intel_rps *rps = &READ_ONCE (rq->engine)->gt->rps;if (rps_uses_slpc (rps)) { +const struct i915_gem_context *ctx; + + ctx =i915_request_gem_context (rq); +if (ctx && +test_bit (UCONTEXT_COMPUTE , &ctx->user_flags)) +return ; + slpc =rps_to_slpc (rps);if (slpc->min_freq_softlimit >= slpc->boost_freq)
drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.h +21 -0
@@ -207,6 +207,27 @@ struct slpc_shared_data {u8 reserved_mode_definition[4096 ]; } __packed; +struct slpc_context_frequency_request { +u32 frequency_request:16 ; +u32 reserved:12 ; +u32 is_compute:1 ; +u32 ignore_busyness:1 ; +u32 is_minimum:1 ; +u32 is_predefined:1 ; +} __packed; + +#define SLPC_CTX_FREQ_REQ_IS_COMPUTE REG_BIT(28) + +struct slpc_optimized_strategies { +u32 compute:1 ; +u32 async_flip:1 ; +u32 media:1 ; +u32 vsync_flip:1 ; +u32 reserved:28 ; +} __packed; + +#define SLPC_OPTIMIZED_STRATEGY_COMPUTE REG_BIT(0) +/** * DOC: SLPC H2G MESSAGE FORMAT *
drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +17 -0
@@ -537,6 +537,20 @@ int intel_guc_slpc_get_min_freq(struct intel_guc_slpc *slpc, u32 *val)return ret; } +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val) +{ +struct drm_i915_private *i915 =slpc_to_i915 (slpc); +intel_wakeref_t wakeref; +int ret =0 ; + +with_intel_runtime_pm (&i915->runtime_pm, wakeref) + ret = slpc_set_param(slpc, +SLPC_PARAM_STRATEGIES , + val); + +return ret; +} +int intel_guc_slpc_set_media_ratio_mode (struct intel_guc_slpc *slpc,u32 val) {struct drm_i915_private *i915 =slpc_to_i915 (slpc);
@@ -711,6 +725,9 @@ int intel_guc_slpc_enable(struct intel_guc_slpc *slpc)/* Set cached media freq ratio mode */ intel_guc_slpc_set_media_ratio_mode (slpc, slpc->media_ratio_mode); +/* Enable SLPC Optimized Strategy for compute */ +intel_guc_slpc_set_strategy (slpc,SLPC_OPTIMIZED_STRATEGY_COMPUTE ); +return 0 ; }
drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h +1 -0
@@ -45,5 +45,6 @@ void intel_guc_pm_intrmsk_enable(struct intel_gt *gt);void intel_guc_slpc_boost (struct intel_guc_slpc *slpc);void intel_guc_slpc_dec_waiters (struct intel_guc_slpc *slpc);int intel_guc_slpc_set_ignore_eff_freq (struct intel_guc_slpc *slpc,bool val); +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val);#endif
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7 -0
@@ -2645,6 +2645,7 @@ MAKE_CONTEXT_POLICY_ADD(execution_quantum, EXECUTION_QUANTUM) MAKE_CONTEXT_POLICY_ADD(preemption_timeout, PREEMPTION_TIMEOUT) MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY) MAKE_CONTEXT_POLICY_ADD(preempt_to_idle, PREEMPT_TO_IDLE_ON_QUANTUM_EXPIRY) +MAKE_CONTEXT_POLICY_ADD(slpc_ctx_freq_req, SLPM_GT_FREQUENCY)#undef MAKE_CONTEXT_POLICY_ADD
@@ -2662,8 +2663,10 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop)struct intel_engine_cs *engine = ce->engine;struct intel_guc *guc = &engine->gt->uc.guc;struct context_policy policy; +struct i915_gem_context *ctx =rcu_dereference (ce->gem_context);u32 execution_quantum;u32 preemption_timeout; +u32 slpc_ctx_freq_req =0 ;unsigned long flags;int ret;
@@ -2675,11 +2678,15 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop) execution_quantum = engine->props.timeslice_duration_ms *1000 ; preemption_timeout = engine->props.preempt_timeout_ms *1000 ; +if (ctx && (ctx->user_flags &BIT (UCONTEXT_COMPUTE ))) + slpc_ctx_freq_req |=SLPC_CTX_FREQ_REQ_IS_COMPUTE ; +__guc_context_policy_start_klv (&policy, ce->guc_id.id);__guc_context_policy_add_priority (&policy, ce->guc_state.prio);__guc_context_policy_add_execution_quantum (&policy, execution_quantum);__guc_context_policy_add_preemption_timeout (&policy, preemption_timeout); +__guc_context_policy_add_slpc_ctx_freq_req (&policy, slpc_ctx_freq_req);if (engine->flags &I915_ENGINE_WANT_FORCED_PREEMPTION )__guc_context_policy_add_preempt_to_idle (&policy,1 );
drivers/gpu/drm/i915/i915_getparam.c +11 -0
@@ -155,6 +155,17 @@ int i915_getparam_ioctl(struct drm_device *dev, void *data,*/ value =1 ;break ; +case I915_PARAM_HAS_COMPUTE_CONTEXT : +/* This feature has been available in GuC for a while but +* a use case now required the use of this feature. We +* return true now since this is now being supported from +* the kernel side as well. +*/ +if (intel_uc_uses_guc_submission (&to_gt (i915)->uc)) + value =1 ; +else + value = -EINVAL ; +break ;case I915_PARAM_HAS_CONTEXT_ISOLATION : value =intel_engines_has_context_isolation (i915);break ;
include/uapi/drm/i915_drm.h +15 -0
@@ -806,6 +806,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_PXP_STATUS 58 +/* +* Query if kernel allows marking a context as a Compute context. This will +* result in more aggressive GT frequency ramping for this context. +*/ +#define I915_PARAM_HAS_COMPUTE_CONTEXT 59 +/* Must be kept compact -- no holes and well documented */ /**
@@ -2148,6 +2154,15 @@ struct drm_i915_gem_context_param {* -EIO: The firmware did not succeed in creating the protected context. */ #define I915_CONTEXT_PARAM_PROTECTED_CONTENT 0xd + +/* +* I915_CONTEXT_PARAM_IS_COMPUTE: +* +* Mark this context as a Compute related workload which requires aggressive GT +* frequency scaling. Query I915_PARAM_HAS_CONTEXT_COMPUTE to check if the kernel +* supports this functionality. +*/ +#define I915_CONTEXT_PARAM_IS_COMPUTE 0xe/* Must be kept compact -- no holes and well documented */ /** @value: Context parameter value to be set or queried */
Signature · 1 line
2.38.1
Patchwork
CI✗ Fi.CI.SPARSE: warning for drm/i915/guc: Add Compute context hint
== Series Details ==
== Series Details ==
Series: drm/i915/guc: Add Compute context hint
URL : https://patchwork.freedesktop.org/series/130163/
State : warning
== Summary ==
Error: dim sparse failed
Sparse version: v0.6.2
Fast mode used, each commit won't be checked separately.
Patchwork
CI✗ Fi.CI.BAT: failure for drm/i915/guc: Add Compute context hint
In reply to Vinay Belgaumkar== Series Details ==
== Series Details ==
Series: drm/i915/guc: Add Compute context hint
URL : https://patchwork.freedesktop.org/series/130163/
State : failure
== Summary ==
CI Bug Log - changes from CI_DRM_14305 -> Patchwork_130163v1
====================================================
Summary
-------
**FAILURE**
Serious unknown changes coming with Patchwork_130163v1 absolutely need to be verified manually.
If you think the reported changes have nothing to do with the changes
introduced in Patchwork_130163v1, please notify your bug team ([email protected]) to allow them to document this new failure mode, which will reduce false positives in CI.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/index.html
Participating hosts (40 -> 38)
------------------------------
Missing (2): bat-mtlp-8 fi-snb-2520m
Possible new issues
-------------------
Here are the unknown changes that may have been introduced in Patchwork_130163v1:
### IGT changes ###
#### Possible regressions ####
* igt@i915_module_load@reload:
- bat-adlp-6: [PASS][1] -> [DMESG-WARN][2] +39 other tests dmesg-warn
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-adlp-6/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-adlp-6/igt@[email protected]
* igt@i915_selftest@live@client:
- bat-dg2-8: [PASS][3] -> [DMESG-WARN][4] +39 other tests dmesg-warn
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-dg2-8/igt@i915_selftest@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-dg2-8/igt@i915_selftest@[email protected]
- bat-adlm-1: [PASS][5] -> [DMESG-WARN][6] +39 other tests dmesg-warn
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-adlm-1/igt@i915_selftest@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-adlm-1/igt@i915_selftest@[email protected]
* igt@i915_selftest@live@coherency:
- bat-dg2-9: [PASS][7] -> [DMESG-WARN][8] +38 other tests dmesg-warn
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-dg2-9/igt@i915_selftest@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-dg2-9/igt@i915_selftest@[email protected]
* igt@i915_selftest@live@dmabuf:
- bat-rplp-1: [PASS][9] -> [DMESG-WARN][10] +39 other tests dmesg-warn
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-rplp-1/igt@i915_selftest@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-rplp-1/igt@i915_selftest@[email protected]
* igt@i915_selftest@live@gem_contexts:
- bat-mtlp-6: [PASS][11] -> [DMESG-WARN][12] +39 other tests dmesg-warn
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-mtlp-6/igt@i915_selftest@live@gem_contexts.html
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-mtlp-6/igt@i915_selftest@live@gem_contexts.html
* igt@i915_selftest@live@gt_tlb:
- bat-adlp-9: [PASS][13] -> [DMESG-WARN][14] +39 other tests dmesg-warn
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-adlp-9/igt@i915_selftest@live@gt_tlb.html
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-adlp-9/igt@i915_selftest@live@gt_tlb.html
* igt@i915_selftest@live@late_gt_pm:
- bat-adln-1: [PASS][15] -> [DMESG-WARN][16] +39 other tests dmesg-warn
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-adln-1/igt@i915_selftest@live@late_gt_pm.html
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-adln-1/igt@i915_selftest@live@late_gt_pm.html
* igt@i915_selftest@live@perf:
- bat-dg2-11: [PASS][17] -> [DMESG-WARN][18] +38 other tests dmesg-warn
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-dg2-11/igt@i915_selftest@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-dg2-11/igt@i915_selftest@[email protected]
* igt@i915_selftest@live@slpc:
- bat-atsm-1: [PASS][19] -> [DMESG-WARN][20] +39 other tests dmesg-warn
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-atsm-1/igt@i915_selftest@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-atsm-1/igt@i915_selftest@[email protected]
* igt@i915_selftest@live@uncore:
- bat-dg1-7: [PASS][21] -> [DMESG-WARN][22] +39 other tests dmesg-warn
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-dg1-7/igt@i915_selftest@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-dg1-7/igt@i915_selftest@[email protected]
#### Suppressed ####
The following results come from untrusted machines, tests, or statuses. They do not affect the overall result.
* igt@i915_module_load@load:
- {bat-arls-1}: [PASS][23] -> [DMESG-WARN][24] +1 other test dmesg-warn
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-arls-1/igt@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-arls-1/igt@[email protected]
- {bat-dg2-13}: [PASS][25] -> [DMESG-WARN][26]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-dg2-13/igt@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-dg2-13/igt@[email protected]
- {bat-arls-2}: [PASS][27] -> [DMESG-WARN][28]
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-arls-2/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-arls-2/igt@[email protected]
* igt@i915_module_load@reload:
- {bat-arls-2}: [INCOMPLETE][29] -> [DMESG-WARN][30]
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-arls-2/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-arls-2/igt@[email protected]
* igt@i915_pm_rpm@module-reload:
- {bat-dg2-14}: [PASS][31] -> [DMESG-WARN][32] +38 other tests dmesg-warn
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-dg2-14/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-dg2-14/igt@[email protected]
Known issues
------------
Here are the changes found in Patchwork_130163v1 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@i915_module_load@reload:
- bat-dg2-11: [PASS][33] -> [DMESG-WARN][34] ([i915#1982])
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-dg2-11/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-dg2-11/igt@[email protected]
- bat-dg2-9: [PASS][35] -> [DMESG-WARN][36] ([i915#1982])
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-dg2-9/igt@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-dg2-9/igt@[email protected]
* igt@i915_pm_rpm@module-reload:
- fi-kbl-7567u: [PASS][37] -> [CRASH][38] ([i915#9947])
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/fi-kbl-7567u/igt@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/fi-kbl-7567u/igt@[email protected]
* igt@i915_selftest@live@execlists:
- fi-bsw-nick: [PASS][39] -> [ABORT][40] ([i915#7911])
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/fi-bsw-nick/igt@i915_selftest@[email protected]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/fi-bsw-nick/igt@i915_selftest@[email protected]
#### Possible fixes ####
* igt@vgem_basic@create:
- {bat-arls-2}: [FAIL][41] -> [PASS][42] +4 other tests pass
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-arls-2/igt@[email protected]
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-arls-2/igt@[email protected]
* igt@vgem_basic@dmabuf-mmap:
- {bat-arls-2}: [INCOMPLETE][43] -> [PASS][44] +5 other tests pass
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14305/bat-arls-2/igt@[email protected]
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/bat-arls-2/igt@[email protected]
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[i915#10194]: https://gitlab.freedesktop.org/drm/intel/issues/10194
[i915#10196]: https://gitlab.freedesktop.org/drm/intel/issues/10196
[i915#10212]: https://gitlab.freedesktop.org/drm/intel/issues/10212
[i915#10213]: https://gitlab.freedesktop.org/drm/intel/issues/10213
[i915#10214]: https://gitlab.freedesktop.org/drm/intel/issues/10214
[i915#10215]: https://gitlab.freedesktop.org/drm/intel/issues/10215
[i915#10216]: https://gitlab.freedesktop.org/drm/intel/issues/10216
[i915#1982]: https://gitlab.freedesktop.org/drm/intel/issues/1982
[i915#3708]: https://gitlab.freedesktop.org/drm/intel/issues/3708
[i915#4077]: https://gitlab.freedesktop.org/drm/intel/issues/4077
[i915#7911]: https://gitlab.freedesktop.org/drm/intel/issues/7911
[i915#9947]: https://gitlab.freedesktop.org/drm/intel/issues/9947
Build changes
-------------
* Linux: CI_DRM_14305 -> Patchwork_130163v1
CI-20190529: 20190529
CI_DRM_14305: 4b8a238dee9c18201f3652695414587cd2ef6d8f @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7718: 40e8b9122853f455c84afcfa56469a6bc9a0d564 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_130163v1: 4b8a238dee9c18201f3652695414587cd2ef6d8f @ git://anongit.freedesktop.org/gfx-ci/linux
### Linux commits
298af428a37e drm/i915/guc: Add Compute context hint
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_130163v1/index.html
Quoted 12 lines · Vinay Belgaumkar
Allow user to provide a context hint. When this is set, KMD will send a hint to GuC which results in special handling for this context. SLPC will ramp the GT frequency aggressively every time it switches to this context. The down freq threshold will also be lower so GuC will ramp down the GT freq for this context more slowly. We also disable waitboost for this context as that will interfere with the strategy.
We need to enable the use of Compute strategy during SLPC init, but it will apply only to contexts that set this bit during context creation.
Quoted 6 lines
Userland can check whether this feature is supported using a new param-
I915_PARAM_HAS_COMPUTE_CONTEXT. This flag is true for all guc submission enabled platforms since they use SLPC for freq management.The Mesa usage model for this flag is here -
https://gitlab.freedesktop.org/sushmave/mesa/-/commits/compute_hint
This allows for setting it for the whole application, correct? Upsides, downsides? Are there any plans for per context?
Quoted 45 lines
Cc Rodrigo Vivi <[email protected]>Signed-off-by Vinay Belgaumkar <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 8 +++++++ .../gpu/drm/i915/gem/i915_gem_context_types.h | 1 + drivers/gpu/drm/i915/gt/intel_rps.c | 8 +++++++ .../drm/i915/gt/uc/abi/guc_actions_slpc_abi.h | 21 +++++++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c | 17 +++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h | 1 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 7 +++++++ drivers/gpu/drm/i915/i915_getparam.c | 11 ++++++++++ include/uapi/drm/i915_drm.h | 15 +++++++++++++ 9 files changed, 89 insertions(+)drivers/gpu/drm/i915/gem/i915_gem_context.c +8
-0@@ -879,6 +879,7 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv,struct i915_gem_proto_context *pc, struct drm_i915_gem_context_param *args) { + struct drm_i915_private *i915 = fpriv->i915;int ret =0 ;switch (args->param) {@@ -904,6 +905,13 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv, pc->user_flags &= ~BIT (UCONTEXT_BANNABLE );break ; +case I915_CONTEXT_PARAM_IS_COMPUTE : +if (!intel_uc_uses_guc_submission (&to_gt (i915)->uc)) + ret = -EINVAL ; +else + pc->user_flags |=BIT (UCONTEXT_COMPUTE ); +break ; +case I915_CONTEXT_PARAM_RECOVERABLE :if (args->size) ret = -EINVAL ;drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0
drivers/gpu/drm/i915/gem/i915_gem_context_types.h struct i915_gem_context { · line 341
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +1
-0@@ -338,6 +338,7 @@ struct i915_gem_context {#define UCONTEXT_BANNABLE 2#define UCONTEXT_RECOVERABLE 3#define UCONTEXT_PERSISTENCE 4 +#define UCONTEXT_COMPUTE 5
What is the GuC behaviour when SLPC_CTX_FREQ_REQ_IS_COMPUTE is set for non-compute engines? Wondering if per intel_context is what we want instead. (Which could then be the i915_context_param_engines extension to mark individual contexts as compute strategy.)
Quoted 16 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0/** * @flags: small set of booleans drivers/gpu/drm/i915/gt/intel_rps.c +1
-0@@ -24,6 +24,7 @@#include "intel_pcode.h" #include "intel_rps.h" #include "vlv_sideband.h" +#include "../gem/i915_gem_context.h" #include "../../../platform/x86/intel_ips.h" #define BUSY_MAX_EI 20u/* ms */
drivers/gpu/drm/i915/gt/intel_rps.c void intel_rps_boost(struct i915_request *rq) · line 1028
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_rps.c +7
-0@@ -1018,6 +1019,13 @@ void intel_rps_boost(struct i915_request *rq)struct intel_rps *rps = &READ_ONCE (rq->engine)->gt->rps;if (rps_uses_slpc (rps)) { +const struct i915_gem_context *ctx; + + ctx =i915_request_gem_context (rq); +if (ctx && +test_bit (UCONTEXT_COMPUTE , &ctx->user_flags)) +return ; +
I think request and intel_context do not own a strong reference to GEM context. So at minimum you need a local one obtained under a RCU lock with kref_get_unless_zero, as do some other places do.
However.. it may be simpler to just store the flag in intel_context->flags. If you carry it over at the time GEM context is assigned to intel_context, not only you simplify runtime rules, but you get the ability to not set the compute flags for video etc.
It may even make sense to add a "don't waitboost" flag on top of the "is compute" so this call site becomes self-documenting (otherwise I ask to add a comment here please). Then you could even move it out from the SLPC special case.
Quoted 125 lines
drivers/gpu/drm/i915/gt/intel_rps.c +0
-0slpc =rps_to_slpc (rps);if (slpc->min_freq_softlimit >= slpc->boost_freq)drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.h +21
-0@@ -207,6 +207,27 @@ struct slpc_shared_data {u8 reserved_mode_definition[4096 ]; } __packed; +struct slpc_context_frequency_request { +u32 frequency_request:16 ; +u32 reserved:12 ; +u32 is_compute:1 ; +u32 ignore_busyness:1 ; +u32 is_minimum:1 ; +u32 is_predefined:1 ; +} __packed; + +#define SLPC_CTX_FREQ_REQ_IS_COMPUTE REG_BIT(28) + +struct slpc_optimized_strategies { +u32 compute:1 ; +u32 async_flip:1 ; +u32 media:1 ; +u32 vsync_flip:1 ; +u32 reserved:28 ; +} __packed; + +#define SLPC_OPTIMIZED_STRATEGY_COMPUTE REG_BIT(0) +/** * DOC: SLPC H2G MESSAGE FORMAT * drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +17
-0@@ -537,6 +537,20 @@ int intel_guc_slpc_get_min_freq(struct intel_guc_slpc *slpc, u32 *val)return ret; } +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val) +{ +struct drm_i915_private *i915 =slpc_to_i915 (slpc); +intel_wakeref_t wakeref; +int ret =0 ; + +with_intel_runtime_pm (&i915->runtime_pm, wakeref) + ret = slpc_set_param(slpc, +SLPC_PARAM_STRATEGIES , + val); + +return ret; +} +int intel_guc_slpc_set_media_ratio_mode (struct intel_guc_slpc *slpc,u32 val) {struct drm_i915_private *i915 =slpc_to_i915 (slpc);@@ -711,6 +725,9 @@ int intel_guc_slpc_enable(struct intel_guc_slpc *slpc)/* Set cached media freq ratio mode */ intel_guc_slpc_set_media_ratio_mode (slpc, slpc->media_ratio_mode); +/* Enable SLPC Optimized Strategy for compute */ +intel_guc_slpc_set_strategy (slpc,SLPC_OPTIMIZED_STRATEGY_COMPUTE ); +return 0 ; }drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h +1
-0@@ -45,5 +45,6 @@ void intel_guc_pm_intrmsk_enable(struct intel_gt *gt);void intel_guc_slpc_boost (struct intel_guc_slpc *slpc);void intel_guc_slpc_dec_waiters (struct intel_guc_slpc *slpc);int intel_guc_slpc_set_ignore_eff_freq (struct intel_guc_slpc *slpc,bool val); +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val);#endif drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0@@ -2645,6 +2645,7 @@ MAKE_CONTEXT_POLICY_ADD(execution_quantum, EXECUTION_QUANTUM) MAKE_CONTEXT_POLICY_ADD(preemption_timeout, PREEMPTION_TIMEOUT) MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY) MAKE_CONTEXT_POLICY_ADD(preempt_to_idle, PREEMPT_TO_IDLE_ON_QUANTUM_EXPIRY) +MAKE_CONTEXT_POLICY_ADD(slpc_ctx_freq_req, SLPM_GT_FREQUENCY)#undef MAKE_CONTEXT_POLICY_ADD@@ -2662,8 +2663,10 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop)struct intel_engine_cs *engine = ce->engine;struct intel_guc *guc = &engine->gt->uc.guc;struct context_policy policy; +struct i915_gem_context *ctx =rcu_dereference (ce->gem_context);u32 execution_quantum;u32 preemption_timeout; +u32 slpc_ctx_freq_req =0 ;unsigned long flags;int ret;@@ -2675,11 +2678,15 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop) execution_quantum = engine->props.timeslice_duration_ms *1000 ; preemption_timeout = engine->props.preempt_timeout_ms *1000 ; +if (ctx && (ctx->user_flags &BIT (UCONTEXT_COMPUTE ))) + slpc_ctx_freq_req |=SLPC_CTX_FREQ_REQ_IS_COMPUTE ; +__guc_context_policy_start_klv (&policy, ce->guc_id.id);__guc_context_policy_add_priority (&policy, ce->guc_state.prio);__guc_context_policy_add_execution_quantum (&policy, execution_quantum);__guc_context_policy_add_preemption_timeout (&policy, preemption_timeout); +__guc_context_policy_add_slpc_ctx_freq_req (&policy, slpc_ctx_freq_req);if (engine->flags &I915_ENGINE_WANT_FORCED_PREEMPTION )__guc_context_policy_add_preempt_to_idle (&policy,1 );drivers/gpu/drm/i915/i915_getparam.c +0
-0
drivers/gpu/drm/i915/i915_getparam.c int i915_getparam_ioctl(struct drm_device *dev, void *data, · line 163
Quoted 9 lines
drivers/gpu/drm/i915/i915_getparam.c +6
-0@@ -155,6 +155,17 @@ int i915_getparam_ioctl(struct drm_device *dev, void *data,*/ value =1 ;break ; +case I915_PARAM_HAS_COMPUTE_CONTEXT : +/* This feature has been available in GuC for a while but +* a use case now required the use of this feature. We +* return true now since this is now being supported from +* the kernel side as well. +*/
Nit - stick to the multi-line comment style i915 uses please.
Regards,
Tvrtko
Quoted 41 lines
drivers/gpu/drm/i915/i915_getparam.c +5
-0+if (intel_uc_uses_guc_submission (&to_gt (i915)->uc)) + value =1 ; +else + value = -EINVAL ; +break ;case I915_PARAM_HAS_CONTEXT_ISOLATION : value =intel_engines_has_context_isolation (i915);break ;include/uapi/drm/i915_drm.h +15
-0@@ -806,6 +806,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_PXP_STATUS 58 +/* +* Query if kernel allows marking a context as a Compute context. This will +* result in more aggressive GT frequency ramping for this context. +*/ +#define I915_PARAM_HAS_COMPUTE_CONTEXT 59 +/* Must be kept compact -- no holes and well documented */ /** @@ -2148,6 +2154,15 @@ struct drm_i915_gem_context_param {* -EIO: The firmware did not succeed in creating the protected context. */ #define I915_CONTEXT_PARAM_PROTECTED_CONTENT 0xd + +/* +* I915_CONTEXT_PARAM_IS_COMPUTE: +* +* Mark this context as a Compute related workload which requires aggressive GT +* frequency scaling. Query I915_PARAM_HAS_CONTEXT_COMPUTE to check if the kernel +* supports this functionality. +*/ +#define I915_CONTEXT_PARAM_IS_COMPUTE 0xe/* Must be kept compact -- no holes and well documented */ /** @value: Context parameter value to be set or queried */
Rodrigo Vivi
maintainerQuoted 18 lines · Tvrtko Ursulin
Quoted 16 lines · Vinay Belgaumkar
Allow user to provide a context hint. When this is set, KMD will send a hint to GuC which results in special handling for this context. SLPC will ramp the GT frequency aggressively every time it switches to this context. The down freq threshold will also be lower so GuC will ramp down the GT freq for this context more slowly. We also disable waitboost for this context as that will interfere with the strategy.
We need to enable the use of Compute strategy during SLPC init, but it will apply only to contexts that set this bit during context creation.
Userland can check whether this feature is supported using a new param-
I915_PARAM_HAS_COMPUTE_CONTEXT. This flag is true for all guc submission enabled platforms since they use SLPC for freq management.
Quoted 5 lines
Quoted 2 lines
The Mesa usage model for this flag is here -
https://gitlab.freedesktop.org/sushmave/mesa/-/commits/compute_hintThis allows for setting it for the whole application, correct? Upsides, downsides? Are there any plans for per context?
Currently there's no extension on a high level API (Vulkan/OpenGL/OpenCL/etc) that would allow the application to hint for power/freq/latency. So Mesa cannot decide when to hint. So their solution was to use .drirc and make per-application decision.
I would prefer a high level extension for a more granular and informative decision. We need to work with that goal, but for now I don't see any cons on this approach.
Quoted 45 lines
Quoted 45 lines
Cc Rodrigo Vivi <[email protected]>Signed-off-by Vinay Belgaumkar <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 8 +++++++ .../gpu/drm/i915/gem/i915_gem_context_types.h | 1 + drivers/gpu/drm/i915/gt/intel_rps.c | 8 +++++++ .../drm/i915/gt/uc/abi/guc_actions_slpc_abi.h | 21 +++++++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c | 17 +++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h | 1 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 7 +++++++ drivers/gpu/drm/i915/i915_getparam.c | 11 ++++++++++ include/uapi/drm/i915_drm.h | 15 +++++++++++++ 9 files changed, 89 insertions(+)drivers/gpu/drm/i915/gem/i915_gem_context.c +8
-0@@ -879,6 +879,7 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv,struct i915_gem_proto_context *pc, struct drm_i915_gem_context_param *args) { + struct drm_i915_private *i915 = fpriv->i915;int ret =0 ;switch (args->param) {@@ -904,6 +905,13 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv, pc->user_flags &= ~BIT (UCONTEXT_BANNABLE );break ; +case I915_CONTEXT_PARAM_IS_COMPUTE : +if (!intel_uc_uses_guc_submission (&to_gt (i915)->uc)) + ret = -EINVAL ; +else + pc->user_flags |=BIT (UCONTEXT_COMPUTE ); +break ; +case I915_CONTEXT_PARAM_RECOVERABLE :if (args->size) ret = -EINVAL ;drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0@@ -338,6 +338,7 @@ struct i915_gem_context {#define UCONTEXT_BANNABLE 2
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h struct i915_gem_context { · line 341
Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +1
-0#define UCONTEXT_RECOVERABLE 3#define UCONTEXT_PERSISTENCE 4 +#define UCONTEXT_COMPUTE 5What is the GuC behaviour when
SLPC_CTX_FREQ_REQ_IS_COMPUTEis set for non-compute engines? Wondering if perintel_contextis what we want instead. (Which could then be thei915_context_param_enginesextension to mark individual contexts as compute strategy.)
Perhaps we should rename this? This is a freq-decision-strategy inside GuC that is there mostly targeting compute workloads that needs lower latency with short burst execution. But the engine itself doesn't matter. It can be applied to any engine.
Quoted 29 lines
Quoted 15 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0/** * @flags: small set of booleans drivers/gpu/drm/i915/gt/intel_rps.c +1
-0@@ -24,6 +24,7 @@#include "intel_pcode.h" #include "intel_rps.h" #include "vlv_sideband.h" +#include "../gem/i915_gem_context.h" #include "../../../platform/x86/intel_ips.h" #define BUSY_MAX_EI 20u/* ms */ drivers/gpu/drm/i915/gt/intel_rps.c void intel_rps_boost(struct i915_request *rq) · line 1027
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_rps.c +7
-0@@ -1018,6 +1019,13 @@ void intel_rps_boost(struct i915_request *rq)struct intel_rps *rps = &READ_ONCE (rq->engine)->gt->rps;if (rps_uses_slpc (rps)) { +const struct i915_gem_context *ctx; + + ctx =i915_request_gem_context (rq); +if (ctx && +test_bit (UCONTEXT_COMPUTE , &ctx->user_flags)) +return ; +I think request and
intel_contextdo not own a strong reference to GEM context. So at minimum you need a local one obtained under a RCU lock withkref_get_unless_zero, as do some other places do.
Quoted 4 lines
However.. it may be simpler to just store the flag in
intel_context->flags. If you carry it over at the time GEM context is assigned tointel_context, not only you simplify runtime rules, but you get the ability to not set the compute flags for video etc.
+1 on the intel_context->flags
Quoted 5 lines
It may even make sense to add a "don't waitboost" flag on top of the "is compute" so this call site becomes self-documenting (otherwise I ask to add a comment here please). Then you could even move it out from the SLPC special case.
+1 on the dont_waitboost flag as well. might be worth for other cases like display metrics for instance.
Quoted 168 lines
Quoted 114 lines
drivers/gpu/drm/i915/gt/intel_rps.c +0
-0slpc =rps_to_slpc (rps);if (slpc->min_freq_softlimit >= slpc->boost_freq)drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.h +21
-0@@ -207,6 +207,27 @@ struct slpc_shared_data {u8 reserved_mode_definition[4096 ]; } __packed; +struct slpc_context_frequency_request { +u32 frequency_request:16 ; +u32 reserved:12 ; +u32 is_compute:1 ; +u32 ignore_busyness:1 ; +u32 is_minimum:1 ; +u32 is_predefined:1 ; +} __packed; + +#define SLPC_CTX_FREQ_REQ_IS_COMPUTE REG_BIT(28) + +struct slpc_optimized_strategies { +u32 compute:1 ; +u32 async_flip:1 ; +u32 media:1 ; +u32 vsync_flip:1 ; +u32 reserved:28 ; +} __packed; + +#define SLPC_OPTIMIZED_STRATEGY_COMPUTE REG_BIT(0) +/** * DOC: SLPC H2G MESSAGE FORMAT * drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +17
-0@@ -537,6 +537,20 @@ int intel_guc_slpc_get_min_freq(struct intel_guc_slpc *slpc, u32 *val)return ret; } +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val) +{ +struct drm_i915_private *i915 =slpc_to_i915 (slpc); +intel_wakeref_t wakeref; +int ret =0 ; + +with_intel_runtime_pm (&i915->runtime_pm, wakeref) + ret = slpc_set_param(slpc, +SLPC_PARAM_STRATEGIES , + val); + +return ret; +} +int intel_guc_slpc_set_media_ratio_mode (struct intel_guc_slpc *slpc,u32 val) {struct drm_i915_private *i915 =slpc_to_i915 (slpc);@@ -711,6 +725,9 @@ int intel_guc_slpc_enable(struct intel_guc_slpc *slpc)/* Set cached media freq ratio mode */ intel_guc_slpc_set_media_ratio_mode (slpc, slpc->media_ratio_mode); +/* Enable SLPC Optimized Strategy for compute */ +intel_guc_slpc_set_strategy (slpc,SLPC_OPTIMIZED_STRATEGY_COMPUTE ); +return 0 ; }drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h +1
-0@@ -45,5 +45,6 @@ void intel_guc_pm_intrmsk_enable(struct intel_gt *gt);void intel_guc_slpc_boost (struct intel_guc_slpc *slpc);void intel_guc_slpc_dec_waiters (struct intel_guc_slpc *slpc);int intel_guc_slpc_set_ignore_eff_freq (struct intel_guc_slpc *slpc,bool val); +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val);#endif drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0@@ -2645,6 +2645,7 @@ MAKE_CONTEXT_POLICY_ADD(execution_quantum, EXECUTION_QUANTUM) MAKE_CONTEXT_POLICY_ADD(preemption_timeout, PREEMPTION_TIMEOUT) MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY) MAKE_CONTEXT_POLICY_ADD(preempt_to_idle, PREEMPT_TO_IDLE_ON_QUANTUM_EXPIRY) +MAKE_CONTEXT_POLICY_ADD(slpc_ctx_freq_req, SLPM_GT_FREQUENCY)#undef MAKE_CONTEXT_POLICY_ADD@@ -2662,8 +2663,10 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop)struct intel_engine_cs *engine = ce->engine;struct intel_guc *guc = &engine->gt->uc.guc;struct context_policy policy; +struct i915_gem_context *ctx =rcu_dereference (ce->gem_context);u32 execution_quantum;u32 preemption_timeout; +u32 slpc_ctx_freq_req =0 ;unsigned long flags;int ret;@@ -2675,11 +2678,15 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop) execution_quantum = engine->props.timeslice_duration_ms *1000 ; preemption_timeout = engine->props.preempt_timeout_ms *1000 ; +if (ctx && (ctx->user_flags &BIT (UCONTEXT_COMPUTE ))) + slpc_ctx_freq_req |=SLPC_CTX_FREQ_REQ_IS_COMPUTE ; +__guc_context_policy_start_klv (&policy, ce->guc_id.id);__guc_context_policy_add_priority (&policy, ce->guc_state.prio);__guc_context_policy_add_execution_quantum (&policy, execution_quantum);__guc_context_policy_add_preemption_timeout (&policy, preemption_timeout); +__guc_context_policy_add_slpc_ctx_freq_req (&policy, slpc_ctx_freq_req);if (engine->flags &I915_ENGINE_WANT_FORCED_PREEMPTION )__guc_context_policy_add_preempt_to_idle (&policy,1 );drivers/gpu/drm/i915/i915_getparam.c +0
-0drivers/gpu/drm/i915/i915_getparam.c int i915_getparam_ioctl(struct drm_device *dev, void *data, · line 163
Quoted 9 lines
drivers/gpu/drm/i915/i915_getparam.c +6
-0@@ -155,6 +155,17 @@ int i915_getparam_ioctl(struct drm_device *dev, void *data,*/ value =1 ;break ; +case I915_PARAM_HAS_COMPUTE_CONTEXT : +/* This feature has been available in GuC for a while but +* a use case now required the use of this feature. We +* return true now since this is now being supported from +* the kernel side as well. +*/ Nit - stick to the multi-line comment style i915 uses please.
Regards,
Tvrtko
Quoted 38 lines
drivers/gpu/drm/i915/i915_getparam.c +5
-0+if (intel_uc_uses_guc_submission (&to_gt (i915)->uc)) + value =1 ; +else + value = -EINVAL ; +break ;case I915_PARAM_HAS_CONTEXT_ISOLATION : value =intel_engines_has_context_isolation (i915);break ;include/uapi/drm/i915_drm.h +15
-0@@ -806,6 +806,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_PXP_STATUS 58 +/* +* Query if kernel allows marking a context as a Compute context. This will +* result in more aggressive GT frequency ramping for this context. +*/ +#define I915_PARAM_HAS_COMPUTE_CONTEXT 59 +/* Must be kept compact -- no holes and well documented */ /** @@ -2148,6 +2154,15 @@ struct drm_i915_gem_context_param {* -EIO: The firmware did not succeed in creating the protected context. */ #define I915_CONTEXT_PARAM_PROTECTED_CONTENT 0xd + +/* +* I915_CONTEXT_PARAM_IS_COMPUTE: +* +* Mark this context as a Compute related workload which requires aggressive GT +* frequency scaling. Query I915_PARAM_HAS_CONTEXT_COMPUTE to check if the kernel +* supports this functionality. +*/ +#define I915_CONTEXT_PARAM_IS_COMPUTE 0xe/* Must be kept compact -- no holes and well documented */ /** @value: Context parameter value to be set or queried */
Quoted 25 lines · Rodrigo Vivi
Quoted 18 lines · Tvrtko Ursulin
Quoted 16 lines · Vinay Belgaumkar
Allow user to provide a context hint. When this is set, KMD will send a hint to GuC which results in special handling for this context. SLPC will ramp the GT frequency aggressively every time it switches to this context. The down freq threshold will also be lower so GuC will ramp down the GT freq for this context more slowly. We also disable waitboost for this context as that will interfere with the strategy.
We need to enable the use of Compute strategy during SLPC init, but it will apply only to contexts that set this bit during context creation.
Userland can check whether this feature is supported using a new param-
I915_PARAM_HAS_COMPUTE_CONTEXT. This flag is true for all guc submission enabled platforms since they use SLPC for freq management.Quoted 5 lines
Quoted 2 lines
The Mesa usage model for this flag is here -
https://gitlab.freedesktop.org/sushmave/mesa/-/commits/compute_hintThis allows for setting it for the whole application, correct? Upsides, downsides? Are there any plans for per context?
Quoted 8 lines
Currently there's no extension on a high level API (Vulkan/OpenGL/OpenCL/etc) that would allow the application to hint for power/freq/latency. So Mesa cannot decide when to hint. So their solution was to use .drirc and make per-application decision.
I would prefer a high level extension for a more granular and informative decision. We need to work with that goal, but for now I don't see any cons on this approach.
In principle yeah I doesn't harm to have the option. I am just not sure how useful this intermediate step this is with its lack of intra-process granularity.
Quoted 53 lines
Quoted 44 lines
Quoted 44 lines
Cc Rodrigo Vivi <[email protected]>Signed-off-by Vinay Belgaumkar <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 8 +++++++ .../gpu/drm/i915/gem/i915_gem_context_types.h | 1 + drivers/gpu/drm/i915/gt/intel_rps.c | 8 +++++++ .../drm/i915/gt/uc/abi/guc_actions_slpc_abi.h | 21 +++++++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c | 17 +++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h | 1 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 7 +++++++ drivers/gpu/drm/i915/i915_getparam.c | 11 ++++++++++ include/uapi/drm/i915_drm.h | 15 +++++++++++++ 9 files changed, 89 insertions(+)drivers/gpu/drm/i915/gem/i915_gem_context.c +8
-0@@ -879,6 +879,7 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv,struct i915_gem_proto_context *pc, struct drm_i915_gem_context_param *args) { + struct drm_i915_private *i915 = fpriv->i915;int ret =0 ;switch (args->param) {@@ -904,6 +905,13 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv, pc->user_flags &= ~BIT (UCONTEXT_BANNABLE );break ; +case I915_CONTEXT_PARAM_IS_COMPUTE : +if (!intel_uc_uses_guc_submission (&to_gt (i915)->uc)) + ret = -EINVAL ; +else + pc->user_flags |=BIT (UCONTEXT_COMPUTE ); +break ; +case I915_CONTEXT_PARAM_RECOVERABLE :if (args->size) ret = -EINVAL ;drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0@@ -338,6 +338,7 @@ struct i915_gem_context {#define UCONTEXT_BANNABLE 2Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h struct i915_gem_context { · line 341
Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +1
-0#define UCONTEXT_RECOVERABLE 3#define UCONTEXT_PERSISTENCE 4 +#define UCONTEXT_COMPUTE 5What is the GuC behaviour when
SLPC_CTX_FREQ_REQ_IS_COMPUTEis set for non-compute engines? Wondering if perintel_contextis what we want instead. (Which could then be thei915_context_param_enginesextension to mark individual contexts as compute strategy.)
Quoted 4 lines
Perhaps we should rename this? This is a freq-decision-strategy inside GuC that is there mostly targeting compute workloads that needs lower latency with short burst execution. But the engine itself doesn't matter. It can be applied to any engine.
I have no idea if it makes sense for other engines, such as video, and what would be pros and cons in terms of PnP. But in the case we end up allowing it on any engine, then at least userspace name shouldn't be compute. :)
Or if we decide to call it compute and only apply to compute engines, then I would strongly suggest making the uapi per intel_context i.e. the set engines extension instead of the GEM context param. Otherwise it would be odd that some engines get it and some don't. With explicit configuration userspace gets to see the clear picture of what is what.
Regards,
Tvrtko
Quoted 212 lines
Quoted 28 lines
Quoted 14 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0/** * @flags: small set of booleans drivers/gpu/drm/i915/gt/intel_rps.c +1
-0@@ -24,6 +24,7 @@#include "intel_pcode.h" #include "intel_rps.h" #include "vlv_sideband.h" +#include "../gem/i915_gem_context.h" #include "../../../platform/x86/intel_ips.h" #define BUSY_MAX_EI 20u/* ms */ drivers/gpu/drm/i915/gt/intel_rps.c void intel_rps_boost(struct i915_request *rq) · line 1027
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_rps.c +7
-0@@ -1018,6 +1019,13 @@ void intel_rps_boost(struct i915_request *rq)struct intel_rps *rps = &READ_ONCE (rq->engine)->gt->rps;if (rps_uses_slpc (rps)) { +const struct i915_gem_context *ctx; + + ctx =i915_request_gem_context (rq); +if (ctx && +test_bit (UCONTEXT_COMPUTE , &ctx->user_flags)) +return ; +I think request and
intel_contextdo not own a strong reference to GEM context. So at minimum you need a local one obtained under a RCU lock withkref_get_unless_zero, as do some other places do.Quoted 4 lines
However.. it may be simpler to just store the flag in
intel_context->flags. If you carry it over at the time GEM context is assigned tointel_context, not only you simplify runtime rules, but you get the ability to not set the compute flags for video etc.+1 on the
intel_context->flagsQuoted 5 lines
It may even make sense to add a "don't waitboost" flag on top of the "is compute" so this call site becomes self-documenting (otherwise I ask to add a comment here please). Then you could even move it out from the SLPC special case.
+1 on the
dont_waitboostflag as well. might be worth for other cases like display metrics for instance.Quoted 168 lines
Quoted 114 lines
drivers/gpu/drm/i915/gt/intel_rps.c +0
-0slpc =rps_to_slpc (rps);if (slpc->min_freq_softlimit >= slpc->boost_freq)drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.h +21
-0@@ -207,6 +207,27 @@ struct slpc_shared_data {u8 reserved_mode_definition[4096 ]; } __packed; +struct slpc_context_frequency_request { +u32 frequency_request:16 ; +u32 reserved:12 ; +u32 is_compute:1 ; +u32 ignore_busyness:1 ; +u32 is_minimum:1 ; +u32 is_predefined:1 ; +} __packed; + +#define SLPC_CTX_FREQ_REQ_IS_COMPUTE REG_BIT(28) + +struct slpc_optimized_strategies { +u32 compute:1 ; +u32 async_flip:1 ; +u32 media:1 ; +u32 vsync_flip:1 ; +u32 reserved:28 ; +} __packed; + +#define SLPC_OPTIMIZED_STRATEGY_COMPUTE REG_BIT(0) +/** * DOC: SLPC H2G MESSAGE FORMAT * drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +17
-0@@ -537,6 +537,20 @@ int intel_guc_slpc_get_min_freq(struct intel_guc_slpc *slpc, u32 *val)return ret; } +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val) +{ +struct drm_i915_private *i915 =slpc_to_i915 (slpc); +intel_wakeref_t wakeref; +int ret =0 ; + +with_intel_runtime_pm (&i915->runtime_pm, wakeref) + ret = slpc_set_param(slpc, +SLPC_PARAM_STRATEGIES , + val); + +return ret; +} +int intel_guc_slpc_set_media_ratio_mode (struct intel_guc_slpc *slpc,u32 val) {struct drm_i915_private *i915 =slpc_to_i915 (slpc);@@ -711,6 +725,9 @@ int intel_guc_slpc_enable(struct intel_guc_slpc *slpc)/* Set cached media freq ratio mode */ intel_guc_slpc_set_media_ratio_mode (slpc, slpc->media_ratio_mode); +/* Enable SLPC Optimized Strategy for compute */ +intel_guc_slpc_set_strategy (slpc,SLPC_OPTIMIZED_STRATEGY_COMPUTE ); +return 0 ; }drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h +1
-0@@ -45,5 +45,6 @@ void intel_guc_pm_intrmsk_enable(struct intel_gt *gt);void intel_guc_slpc_boost (struct intel_guc_slpc *slpc);void intel_guc_slpc_dec_waiters (struct intel_guc_slpc *slpc);int intel_guc_slpc_set_ignore_eff_freq (struct intel_guc_slpc *slpc,bool val); +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val);#endif drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0@@ -2645,6 +2645,7 @@ MAKE_CONTEXT_POLICY_ADD(execution_quantum, EXECUTION_QUANTUM) MAKE_CONTEXT_POLICY_ADD(preemption_timeout, PREEMPTION_TIMEOUT) MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY) MAKE_CONTEXT_POLICY_ADD(preempt_to_idle, PREEMPT_TO_IDLE_ON_QUANTUM_EXPIRY) +MAKE_CONTEXT_POLICY_ADD(slpc_ctx_freq_req, SLPM_GT_FREQUENCY)#undef MAKE_CONTEXT_POLICY_ADD@@ -2662,8 +2663,10 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop)struct intel_engine_cs *engine = ce->engine;struct intel_guc *guc = &engine->gt->uc.guc;struct context_policy policy; +struct i915_gem_context *ctx =rcu_dereference (ce->gem_context);u32 execution_quantum;u32 preemption_timeout; +u32 slpc_ctx_freq_req =0 ;unsigned long flags;int ret;@@ -2675,11 +2678,15 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop) execution_quantum = engine->props.timeslice_duration_ms *1000 ; preemption_timeout = engine->props.preempt_timeout_ms *1000 ; +if (ctx && (ctx->user_flags &BIT (UCONTEXT_COMPUTE ))) + slpc_ctx_freq_req |=SLPC_CTX_FREQ_REQ_IS_COMPUTE ; +__guc_context_policy_start_klv (&policy, ce->guc_id.id);__guc_context_policy_add_priority (&policy, ce->guc_state.prio);__guc_context_policy_add_execution_quantum (&policy, execution_quantum);__guc_context_policy_add_preemption_timeout (&policy, preemption_timeout); +__guc_context_policy_add_slpc_ctx_freq_req (&policy, slpc_ctx_freq_req);if (engine->flags &I915_ENGINE_WANT_FORCED_PREEMPTION )__guc_context_policy_add_preempt_to_idle (&policy,1 );drivers/gpu/drm/i915/i915_getparam.c +0
-0drivers/gpu/drm/i915/i915_getparam.c int i915_getparam_ioctl(struct drm_device *dev, void *data, · line 163
Quoted 9 lines
drivers/gpu/drm/i915/i915_getparam.c +6
-0@@ -155,6 +155,17 @@ int i915_getparam_ioctl(struct drm_device *dev, void *data,*/ value =1 ;break ; +case I915_PARAM_HAS_COMPUTE_CONTEXT : +/* This feature has been available in GuC for a while but +* a use case now required the use of this feature. We +* return true now since this is now being supported from +* the kernel side as well. +*/ Nit - stick to the multi-line comment style i915 uses please.
Regards,
Tvrtko
Quoted 38 lines
drivers/gpu/drm/i915/i915_getparam.c +5
-0+if (intel_uc_uses_guc_submission (&to_gt (i915)->uc)) + value =1 ; +else + value = -EINVAL ; +break ;case I915_PARAM_HAS_CONTEXT_ISOLATION : value =intel_engines_has_context_isolation (i915);break ;include/uapi/drm/i915_drm.h +15
-0@@ -806,6 +806,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_PXP_STATUS 58 +/* +* Query if kernel allows marking a context as a Compute context. This will +* result in more aggressive GT frequency ramping for this context. +*/ +#define I915_PARAM_HAS_COMPUTE_CONTEXT 59 +/* Must be kept compact -- no holes and well documented */ /** @@ -2148,6 +2154,15 @@ struct drm_i915_gem_context_param {* -EIO: The firmware did not succeed in creating the protected context. */ #define I915_CONTEXT_PARAM_PROTECTED_CONTENT 0xd + +/* +* I915_CONTEXT_PARAM_IS_COMPUTE: +* +* Mark this context as a Compute related workload which requires aggressive GT +* frequency scaling. Query I915_PARAM_HAS_CONTEXT_COMPUTE to check if the kernel +* supports this functionality. +*/ +#define I915_CONTEXT_PARAM_IS_COMPUTE 0xe/* Must be kept compact -- no holes and well documented */ /** @value: Context parameter value to be set or queried */
Quoted 94 lines · Tvrtko Ursulin
Quoted 25 lines · Rodrigo Vivi
Quoted 18 lines · Tvrtko Ursulin
Quoted 16 lines · Vinay Belgaumkar
Allow user to provide a context hint. When this is set, KMD will send a hint to GuC which results in special handling for this context. SLPC will ramp the GT frequency aggressively every time it switches to this context. The down freq threshold will also be lower so GuC will ramp down the GT freq for this context more slowly. We also disable waitboost for this context as that will interfere with the strategy.
We need to enable the use of Compute strategy during SLPC init, but it will apply only to contexts that set this bit during context creation.
Userland can check whether this feature is supported using a new param-
I915_PARAM_HAS_COMPUTE_CONTEXT. This flag is true for all guc submission enabled platforms since they use SLPC for freq management.Quoted 5 lines
Quoted 2 lines
The Mesa usage model for this flag is here -
https://gitlab.freedesktop.org/sushmave/mesa/-/commits/compute_hintThis allows for setting it for the whole application, correct? Upsides, downsides? Are there any plans for per context?
Quoted 8 lines
Currently there's no extension on a high level API (Vulkan/OpenGL/OpenCL/etc) that would allow the application to hint for power/freq/latency. So Mesa cannot decide when to hint. So their solution was to use .drirc and make per-application decision.
I would prefer a high level extension for a more granular and informative decision. We need to work with that goal, but for now I don't see any cons on this approach.
In principle yeah I doesn't harm to have the option. I am just not sure how useful this intermediate step this is with its lack of intra-process granularity.
Quoted 56 lines
Quoted 55 lines
Quoted 46 lines
Cc Rodrigo Vivi <[email protected]>Signed-off-by Vinay Belgaumkar <[email protected]>---
drivers/gpu/drm/i915/gem/i915_gem_context.c | 8 +++++++.../gpu/drm/i915/gem/i915_gem_context_types.h| 1 + drivers/gpu/drm/i915/gt/intel_rps.c | 8 +++++++.../drm/i915/gt/uc/abi/guc_actions_slpc_abi.h| 21
+++++++++++++++++++
drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c | 17 +++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h | 1 +.../gpu/drm/i915/gt/uc/intel_guc_submission.c| 7 +++++++ drivers/gpu/drm/i915/i915_getparam.c | 11 ++++++++++ include/uapi/drm/i915_drm.h | 15 +++++++++++++9 files changed, 89 insertions(+)drivers/gpu/drm/i915/gem/i915_gem_context.c +8
-0@@ -879,6 +879,7 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv, struct i915_gem_proto_context *pc, struct drm_i915_gem_context_param *args) { + struct drm_i915_private *i915 = fpriv->i915; int ret = 0; switch (args->param) {@@ -904,6 +905,13 @@ static int set_proto_ctx_param(structdrm_i915_file_private *fpriv, pc->user_flags &= ~BIT(UCONTEXT_BANNABLE); break; + case I915_CONTEXT_PARAM_IS_COMPUTE: + if (!intel_uc_uses_guc_submission(&to_gt(i915)->uc)) + ret = -EINVAL; + else + pc->user_flags |= BIT(UCONTEXT_COMPUTE); + break; +case
I915_CONTEXT_PARAM_RECOVERABLE:
if (args->size)
ret =-EINVAL;drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0drivers/gpu/drm/i915/gem/i915_gem_context_types.h struct i915_gem_context { · line 341
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +1
-0@@ -338,6 +338,7 @@ struct i915_gem_context { #define UCONTEXT_BANNABLE 2 #define UCONTEXT_RECOVERABLE 3 #define UCONTEXT_PERSISTENCE 4 +#define UCONTEXT_COMPUTE 5What is the GuC behaviour when
SLPC_CTX_FREQ_REQ_IS_COMPUTEis set for non-compute engines? Wondering if perintel_contextis what we want instead. (Which could then be thei915_context_param_enginesextension to mark individual contexts as compute strategy.)
Quoted 6 lines
Quoted 4 lines
Perhaps we should rename this? This is a freq-decision-strategy inside GuC that is there mostly targeting compute workloads that needs lower latency with short burst execution. But the engine itself doesn't matter. It can be applied to any engine.
I have no idea if it makes sense for other engines, such as video, and what would be pros and cons in terms of PnP. But in the case we end up allowing it on any engine, then at least userspace name shouldn't be compute. :)
Yes, one of the suggestions from Daniele was to have something along the lines of UCONTEXT_HIFREQ or something along those lines so we don't confuse it with the Compute Engine.
Quoted 2 lines
Or if we decide to call it compute and only apply to compute engines, then I would strongly suggest making the uapi per
intel_contexti.e. the set engines extension instead of the GEM context param. Otherwise it would be odd that some engines get it and some don't. With explicit configuration userspace gets to see the clear picture of what is what.
It will not be per engine, so may be better to keep it at the gem_context level. Trying to percolate it to the intel_context level seems to be more complicated. We process the gem_context_param flags first and then create the intel_context per engine. Not sure if we want to keep 2 copies of the same flag in gem_context and intel_context as well.
Quoted 48 lines
Regards,
Tvrtko
Quoted 43 lines
Quoted 28 lines
Quoted 14 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0/*** @flags: small set of booleans drivers/gpu/drm/i915/gt/intel_rps.c +1
-0@@ -24,6 +24,7 @@ #include "intel_pcode.h" #include "intel_rps.h" #include "vlv_sideband.h" +#include "../gem/i915_gem_context.h" #include "../../../platform/x86/intel_ips.h" #define BUSY_MAX_EI 20u /* ms */drivers/gpu/drm/i915/gt/intel_rps.c void intel_rps_boost(struct i915_request *rq) · line 1027
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_rps.c +7
-0@@ -1018,6 +1019,13 @@ void intel_rps_boost(struct i915_request *rq) struct intel_rps *rps = &READ_ONCE(rq->engine)->gt->rps; if (rps_uses_slpc(rps)) { + const struct i915_gem_context *ctx; + + ctx = i915_request_gem_context(rq); + if (ctx && + test_bit(UCONTEXT_COMPUTE, &ctx->user_flags)) + return; +I think request and
intel_contextdo not own a strong reference to GEM context. So at minimum you need a local one obtained under a RCU lock withkref_get_unless_zero, as do some other places do.Quoted 4 lines
However.. it may be simpler to just store the flag in
intel_context->flags. If you carry it over at the time GEM context is assigned tointel_context, not only you simplify runtime rules, but you get the ability to not set the compute flags for video etc.+1 on the
intel_context->flagsQuoted 5 lines
It may even make sense to add a "don't waitboost" flag on top of the "is compute" so this call site becomes self-documenting (otherwise I ask to add a comment here please). Then you could even move it out from the SLPC special case.
+1 on the
dont_waitboostflag as well. might be worth for other cases like display metrics for instance.
We could define another disable_waitboost flag in intel_context, but seems redundant if we already have this info in the gem_context. We don't need to check for SLPC special case, just need to check this flag as we won't enable it for the non-slpc case anyways.
Thanks,
Vinay.
Quoted 182 lines
Quoted 182 lines
Quoted 182 lines
Quoted 124 lines
drivers/gpu/drm/i915/gt/intel_rps.c +0
-0slpc = rps_to_slpc(rps); if (slpc->min_freq_softlimit >= slpc->boost_freq)drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.h +21
-0@@ -207,6 +207,27 @@ struct slpc_shared_data { u8 reserved_mode_definition[4096]; } __packed; +struct slpc_context_frequency_request { + u32 frequency_request:16; + u32 reserved:12; + u32 is_compute:1; + u32 ignore_busyness:1; + u32 is_minimum:1; + u32 is_predefined:1; +} __packed; + +#define SLPC_CTX_FREQ_REQ_IS_COMPUTE REG_BIT(28) + +struct slpc_optimized_strategies { + u32 compute:1; + u32 async_flip:1; + u32 media:1; + u32 vsync_flip:1; + u32 reserved:28; +} __packed; + +#define SLPC_OPTIMIZED_STRATEGY_COMPUTE REG_BIT(0) + /*** DOC: SLPC H2G MESSAGE FORMAT * drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +17
-0@@ -537,6 +537,20 @@ int intel_guc_slpc_get_min_freq(struct intel_guc_slpc *slpc, u32 *val) return ret; } +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val) +{ + struct drm_i915_private *i915 = slpc_to_i915(slpc); + intel_wakeref_t wakeref; + int ret = 0; + + with_intel_runtime_pm(&i915->runtime_pm, wakeref) + ret = slpc_set_param(slpc, + SLPC_PARAM_STRATEGIES, + val); + + return ret; +} + int intel_guc_slpc_set_media_ratio_mode(struct intel_guc_slpc *slpc, u32 val) { struct drm_i915_private *i915 = slpc_to_i915(slpc);@@ -711,6 +725,9 @@ int intel_guc_slpc_enable(struct intel_guc_slpc *slpc) /* Set cached media freq ratio mode */ intel_guc_slpc_set_media_ratio_mode(slpc, slpc->media_ratio_mode); + /* Enable SLPC Optimized Strategy for compute */ + intel_guc_slpc_set_strategy(slpc,SLPC_OPTIMIZED_STRATEGY_COMPUTE ); + return 0; }drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h +1
-0@@ -45,5 +45,6 @@ void intel_guc_pm_intrmsk_enable(struct intel_gt *gt); void intel_guc_slpc_boost(struct intel_guc_slpc *slpc); void intel_guc_slpc_dec_waiters(struct intel_guc_slpc *slpc); int intel_guc_slpc_set_ignore_eff_freq(struct intel_guc_slpc *slpc, bool val); +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val);#endif
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0@@ -2645,6 +2645,7 @@ MAKE_CONTEXT_POLICY_ADD(execution_quantum, EXECUTION_QUANTUM) MAKE_CONTEXT_POLICY_ADD(preemption_timeout, PREEMPTION_TIMEOUT) MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY) MAKE_CONTEXT_POLICY_ADD(preempt_to_idle, PREEMPT_TO_IDLE_ON_QUANTUM_EXPIRY) +MAKE_CONTEXT_POLICY_ADD(slpc_ctx_freq_req, SLPM_GT_FREQUENCY) #undef MAKE_CONTEXT_POLICY_ADD@@ -2662,8 +2663,10 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop) struct intel_engine_cs *engine = ce->engine; struct intel_guc *guc = &engine->gt->uc.guc; struct context_policy policy; + struct i915_gem_context *ctx = rcu_dereference(ce->gem_context); u32 execution_quantum; u32 preemption_timeout; + u32 slpc_ctx_freq_req = 0; unsigned long flags; int ret;@@ -2675,11 +2678,15 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop) execution_quantum = engine->props.timeslice_duration_ms * 1000; preemption_timeout = engine->props.preempt_timeout_ms * 1000; + if (ctx && (ctx->user_flags & BIT(UCONTEXT_COMPUTE))) + slpc_ctx_freq_req |= SLPC_CTX_FREQ_REQ_IS_COMPUTE; + __guc_context_policy_start_klv(&policy, ce->guc_id.id); __guc_context_policy_add_priority(&policy, ce->guc_state.prio);__guc_context_policy_add_execution_quantum (&policy, execution_quantum);__guc_context_policy_add_preemption_timeout (&policy, preemption_timeout); + __guc_context_policy_add_slpc_ctx_freq_req(&policy, slpc_ctx_freq_req); if (engine->flags & I915_ENGINE_WANT_FORCED_PREEMPTION)__guc_context_policy_add_preempt_to_idle (&policy,1 );drivers/gpu/drm/i915/i915_getparam.c +0
-0drivers/gpu/drm/i915/i915_getparam.c int i915_getparam_ioctl(struct drm_device · line 164
Quoted 10 lines
drivers/gpu/drm/i915/i915_getparam.c +6
-0@@ -155,6 +155,17 @@ int i915_getparam_ioctl(struct drm_device*dev, void *data, */ value = 1; break; + case I915_PARAM_HAS_COMPUTE_CONTEXT: + /* This feature has been available in GuC for a while but +* a use case now required the use of this feature. We +* return true now since this is now being supported from +* the kernel side as well. +*/ Nit - stick to the multi-line comment style i915 uses please.
Regards,
Tvrtko
Quoted 41 lines
drivers/gpu/drm/i915/i915_getparam.c +5
-0+ if (intel_uc_uses_guc_submission(&to_gt(i915)->uc)) + value = 1; + else + value = -EINVAL; + break;case
I915_PARAM_HAS_CONTEXT_ISOLATION:
value =intel_engines_has_context_isolation(i915); break;include/uapi/drm/i915_drm.h +2
-0@@ -806,6 +806,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_PXP_STATUS 58 +/* +* Query if kernel allows marking a context as a Compute context. This will
+ * result in more aggressive GT frequency ramping for this context.
+ */include/uapi/drm/i915_drm.h +2
-0+#define I915_PARAM_HAS_COMPUTE_CONTEXT 59 +/* Must be kept compact -- no holes and well documented */ /**
include/uapi/drm/i915_drm.h +5
-0@@ -2148,6 +2154,15 @@ struct drm_i915_gem_context_param {* -EIO: The firmware did not succeed in creating the protected context. */ #define I915_CONTEXT_PARAM_PROTECTED_CONTENT 0xd + +/* +* I915_CONTEXT_PARAM_IS_COMPUTE: +* +* Mark this context as a Compute related workload which requires aggressive GT
+ * frequency scaling. QueryI915_PARAM_HAS_CONTEXT_COMPUTEto check if the kernel
+ * supports this functionality.
+ */
+#define I915_CONTEXT_PARAM_IS_COMPUTE0xe
/* Must be kept compact -- no holes and well documented */ /** @value: Context parameter value to be set or queried */
Quoted 96 lines · Vinay
Quoted 94 lines · Tvrtko Ursulin
Quoted 25 lines · Rodrigo Vivi
Quoted 18 lines · Tvrtko Ursulin
Quoted 16 lines · Vinay Belgaumkar
Allow user to provide a context hint. When this is set, KMD will send a hint to GuC which results in special handling for this context. SLPC will ramp the GT frequency aggressively every time it switches to this context. The down freq threshold will also be lower so GuC will ramp down the GT freq for this context more slowly. We also disable waitboost for this context as that will interfere with the strategy.
We need to enable the use of Compute strategy during SLPC init, but it will apply only to contexts that set this bit during context creation.
Userland can check whether this feature is supported using a new param-
I915_PARAM_HAS_COMPUTE_CONTEXT. This flag is true for all guc submission enabled platforms since they use SLPC for freq management.Quoted 5 lines
Quoted 2 lines
The Mesa usage model for this flag is here -
https://gitlab.freedesktop.org/sushmave/mesa/-/commits/compute_hintThis allows for setting it for the whole application, correct? Upsides, downsides? Are there any plans for per context?
Quoted 8 lines
Currently there's no extension on a high level API (Vulkan/OpenGL/OpenCL/etc) that would allow the application to hint for power/freq/latency. So Mesa cannot decide when to hint. So their solution was to use .drirc and make per-application decision.
I would prefer a high level extension for a more granular and informative decision. We need to work with that goal, but for now I don't see any cons on this approach.
In principle yeah I doesn't harm to have the option. I am just not sure how useful this intermediate step this is with its lack of intra-process granularity.
Quoted 56 lines
Quoted 55 lines
Quoted 46 lines
Cc Rodrigo Vivi <[email protected]>Signed-off-by Vinay Belgaumkar <[email protected]>---
drivers/gpu/drm/i915/gem/i915_gem_context.c | 8 +++++++.../gpu/drm/i915/gem/i915_gem_context_types.h| 1 + drivers/gpu/drm/i915/gt/intel_rps.c | 8 +++++++.../drm/i915/gt/uc/abi/guc_actions_slpc_abi.h| 21
+++++++++++++++++++
drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c | 17 +++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h | 1 +.../gpu/drm/i915/gt/uc/intel_guc_submission.c| 7 +++++++ drivers/gpu/drm/i915/i915_getparam.c | 11 ++++++++++ include/uapi/drm/i915_drm.h | 15 +++++++++++++9 files changed, 89 insertions(+)drivers/gpu/drm/i915/gem/i915_gem_context.c +8
-0@@ -879,6 +879,7 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv, struct i915_gem_proto_context *pc, struct drm_i915_gem_context_param *args) { + struct drm_i915_private *i915 = fpriv->i915; int ret = 0; switch (args->param) {@@ -904,6 +905,13 @@ static int set_proto_ctx_param(structdrm_i915_file_private *fpriv, pc->user_flags &= ~BIT(UCONTEXT_BANNABLE); break; + case I915_CONTEXT_PARAM_IS_COMPUTE: + if (!intel_uc_uses_guc_submission(&to_gt(i915)->uc)) + ret = -EINVAL; + else + pc->user_flags |= BIT(UCONTEXT_COMPUTE); + break; +case
I915_CONTEXT_PARAM_RECOVERABLE:
if (args->size)
ret =-EINVAL;drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0drivers/gpu/drm/i915/gem/i915_gem_context_types.h struct i915_gem_context { · line 341
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +1
-0@@ -338,6 +338,7 @@ struct i915_gem_context { #define UCONTEXT_BANNABLE 2 #define UCONTEXT_RECOVERABLE 3 #define UCONTEXT_PERSISTENCE 4 +#define UCONTEXT_COMPUTE 5What is the GuC behaviour when
SLPC_CTX_FREQ_REQ_IS_COMPUTEis set for non-compute engines? Wondering if perintel_contextis what we want instead. (Which could then be thei915_context_param_enginesextension to mark individual contexts as compute strategy.)
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Perhaps we should rename this? This is a freq-decision-strategy inside GuC that is there mostly targeting compute workloads that needs lower latency with short burst execution. But the engine itself doesn't matter. It can be applied to any engine.
I have no idea if it makes sense for other engines, such as video, and what would be pros and cons in terms of PnP. But in the case we end up allowing it on any engine, then at least userspace name shouldn't be compute. :)
Yes, one of the suggestions from Daniele was to have something along the lines of
UCONTEXT_HIFREQor something along those lines so we don't confuse it with the Compute Engine.
Okay, but additional question is would anyone ever want to set it for video or blitter. Would it harm, benefir, or be neutral.
Quoted 3 lines
Quoted 1 line
Or if we decide to call it compute and only apply to compute engines, then I would strongly suggest making the uapi per
intel_contexti.e. the set engines extension instead of the GEM context param. Otherwise it would be odd that some engines get it and some don't. With explicit configuration userspace gets to see the clear picture of what is what.It will not be per engine, so may be better to keep it at the
Why? Just because..
Quoted 1 line
gem_contextlevel. Trying to percolate it to theintel_contextlevel seems to be more complicated. We process thegem_context_paramflags first and then create theintel_contextper engine. Not sure if we want to keep 2 copies of the same flag ingem_contextandintel_contextas well.
.. it is complicated? It is not complicated at all. There is intel_context_set_gem which is just for uses like that.
Once you have this, then the only difference is whether you go from GEM context setparam to intel_context, or flag goes directly to intel_context as they are created via custom engine maps.
Regards,
Tvrtko
Quoted 237 lines
Quoted 48 lines
Regards,
Tvrtko
Quoted 43 lines
Quoted 28 lines
Quoted 14 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0/*** @flags: small set of booleans drivers/gpu/drm/i915/gt/intel_rps.c +1
-0@@ -24,6 +24,7 @@ #include "intel_pcode.h" #include "intel_rps.h" #include "vlv_sideband.h" +#include "../gem/i915_gem_context.h" #include "../../../platform/x86/intel_ips.h" #define BUSY_MAX_EI 20u /* ms */drivers/gpu/drm/i915/gt/intel_rps.c void intel_rps_boost(struct i915_request *rq) · line 1027
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_rps.c +7
-0@@ -1018,6 +1019,13 @@ void intel_rps_boost(struct i915_request *rq) struct intel_rps *rps = &READ_ONCE(rq->engine)->gt->rps; if (rps_uses_slpc(rps)) { + const struct i915_gem_context *ctx; + + ctx = i915_request_gem_context(rq); + if (ctx && + test_bit(UCONTEXT_COMPUTE, &ctx->user_flags)) + return; +I think request and
intel_contextdo not own a strong reference to GEM context. So at minimum you need a local one obtained under a RCU lock withkref_get_unless_zero, as do some other places do.Quoted 4 lines
However.. it may be simpler to just store the flag in
intel_context->flags. If you carry it over at the time GEM context is assigned tointel_context, not only you simplify runtime rules, but you get the ability to not set the compute flags for video etc.+1 on the
intel_context->flagsQuoted 5 lines
It may even make sense to add a "don't waitboost" flag on top of the "is compute" so this call site becomes self-documenting (otherwise I ask to add a comment here please). Then you could even move it out from the SLPC special case.
+1 on the
dont_waitboostflag as well. might be worth for other cases like display metrics for instance.We could define another
disable_waitboostflag inintel_context, but seems redundant if we already have this info in thegem_context. We don't need to check for SLPC special case, just need to check this flag as we won't enable it for the non-slpc case anyways.Thanks,
Vinay.
Quoted 182 lines
Quoted 182 lines
Quoted 182 lines
Quoted 124 lines
drivers/gpu/drm/i915/gt/intel_rps.c +0
-0slpc = rps_to_slpc(rps); if (slpc->min_freq_softlimit >= slpc->boost_freq)drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.h +21
-0@@ -207,6 +207,27 @@ struct slpc_shared_data { u8 reserved_mode_definition[4096]; } __packed; +struct slpc_context_frequency_request { + u32 frequency_request:16; + u32 reserved:12; + u32 is_compute:1; + u32 ignore_busyness:1; + u32 is_minimum:1; + u32 is_predefined:1; +} __packed; + +#define SLPC_CTX_FREQ_REQ_IS_COMPUTE REG_BIT(28) + +struct slpc_optimized_strategies { + u32 compute:1; + u32 async_flip:1; + u32 media:1; + u32 vsync_flip:1; + u32 reserved:28; +} __packed; + +#define SLPC_OPTIMIZED_STRATEGY_COMPUTE REG_BIT(0) + /*** DOC: SLPC H2G MESSAGE FORMAT * drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +17
-0@@ -537,6 +537,20 @@ int intel_guc_slpc_get_min_freq(struct intel_guc_slpc *slpc, u32 *val) return ret; } +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val) +{ + struct drm_i915_private *i915 = slpc_to_i915(slpc); + intel_wakeref_t wakeref; + int ret = 0; + + with_intel_runtime_pm(&i915->runtime_pm, wakeref) + ret = slpc_set_param(slpc, + SLPC_PARAM_STRATEGIES, + val); + + return ret; +} + int intel_guc_slpc_set_media_ratio_mode(struct intel_guc_slpc *slpc, u32 val) { struct drm_i915_private *i915 = slpc_to_i915(slpc);@@ -711,6 +725,9 @@ int intel_guc_slpc_enable(struct intel_guc_slpc *slpc) /* Set cached media freq ratio mode */ intel_guc_slpc_set_media_ratio_mode(slpc, slpc->media_ratio_mode); + /* Enable SLPC Optimized Strategy for compute */ + intel_guc_slpc_set_strategy(slpc,SLPC_OPTIMIZED_STRATEGY_COMPUTE ); + return 0; }drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h +1
-0@@ -45,5 +45,6 @@ void intel_guc_pm_intrmsk_enable(struct intel_gt *gt); void intel_guc_slpc_boost(struct intel_guc_slpc *slpc); void intel_guc_slpc_dec_waiters(struct intel_guc_slpc *slpc); int intel_guc_slpc_set_ignore_eff_freq(struct intel_guc_slpc *slpc, bool val); +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val);#endif
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0@@ -2645,6 +2645,7 @@ MAKE_CONTEXT_POLICY_ADD(execution_quantum, EXECUTION_QUANTUM) MAKE_CONTEXT_POLICY_ADD(preemption_timeout, PREEMPTION_TIMEOUT) MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY) MAKE_CONTEXT_POLICY_ADD(preempt_to_idle, PREEMPT_TO_IDLE_ON_QUANTUM_EXPIRY) +MAKE_CONTEXT_POLICY_ADD(slpc_ctx_freq_req, SLPM_GT_FREQUENCY) #undef MAKE_CONTEXT_POLICY_ADD@@ -2662,8 +2663,10 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop) struct intel_engine_cs *engine = ce->engine; struct intel_guc *guc = &engine->gt->uc.guc; struct context_policy policy; + struct i915_gem_context *ctx = rcu_dereference(ce->gem_context); u32 execution_quantum; u32 preemption_timeout; + u32 slpc_ctx_freq_req = 0; unsigned long flags; int ret;@@ -2675,11 +2678,15 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop) execution_quantum = engine->props.timeslice_duration_ms * 1000; preemption_timeout = engine->props.preempt_timeout_ms * 1000; + if (ctx && (ctx->user_flags & BIT(UCONTEXT_COMPUTE))) + slpc_ctx_freq_req |= SLPC_CTX_FREQ_REQ_IS_COMPUTE; + __guc_context_policy_start_klv(&policy, ce->guc_id.id); __guc_context_policy_add_priority(&policy, ce->guc_state.prio);__guc_context_policy_add_execution_quantum (&policy, execution_quantum);__guc_context_policy_add_preemption_timeout (&policy, preemption_timeout); + __guc_context_policy_add_slpc_ctx_freq_req(&policy, slpc_ctx_freq_req); if (engine->flags & I915_ENGINE_WANT_FORCED_PREEMPTION)__guc_context_policy_add_preempt_to_idle (&policy,1 );drivers/gpu/drm/i915/i915_getparam.c +0
-0drivers/gpu/drm/i915/i915_getparam.c int i915_getparam_ioctl(struct drm_device · line 164
Quoted 10 lines
drivers/gpu/drm/i915/i915_getparam.c +6
-0@@ -155,6 +155,17 @@ int i915_getparam_ioctl(struct drm_device*dev, void *data, */ value = 1; break; + case I915_PARAM_HAS_COMPUTE_CONTEXT: + /* This feature has been available in GuC for a while but +* a use case now required the use of this feature. We +* return true now since this is now being supported from +* the kernel side as well. +*/ Nit - stick to the multi-line comment style i915 uses please.
Regards,
Tvrtko
Quoted 41 lines
drivers/gpu/drm/i915/i915_getparam.c +5
-0+ if (intel_uc_uses_guc_submission(&to_gt(i915)->uc)) + value = 1; + else + value = -EINVAL; + break;case
I915_PARAM_HAS_CONTEXT_ISOLATION:
value =intel_engines_has_context_isolation(i915); break;include/uapi/drm/i915_drm.h +2
-0@@ -806,6 +806,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_PXP_STATUS 58 +/* +* Query if kernel allows marking a context as a Compute context. This will
+ * result in more aggressive GT frequency ramping for this context.
+ */include/uapi/drm/i915_drm.h +2
-0+#define I915_PARAM_HAS_COMPUTE_CONTEXT 59 +/* Must be kept compact -- no holes and well documented */ /**
include/uapi/drm/i915_drm.h +5
-0@@ -2148,6 +2154,15 @@ struct drm_i915_gem_context_param {* -EIO: The firmware did not succeed in creating the protected context. */ #define I915_CONTEXT_PARAM_PROTECTED_CONTENT 0xd + +/* +* I915_CONTEXT_PARAM_IS_COMPUTE: +* +* Mark this context as a Compute related workload which requires aggressive GT
+ * frequency scaling. QueryI915_PARAM_HAS_CONTEXT_COMPUTEto check if the kernel
+ * supports this functionality.
+ */
+#define I915_CONTEXT_PARAM_IS_COMPUTE0xe
/* Must be kept compact -- no holes and well documented */ /** @value: Context parameter value to be set or queried */
Quoted 104 lines · Tvrtko Ursulin
Quoted 102 lines · Vinay
Quoted 100 lines · Tvrtko Ursulin
Quoted 25 lines · Rodrigo Vivi
Quoted 18 lines · Tvrtko Ursulin
Quoted 16 lines · Vinay Belgaumkar
Allow user to provide a context hint. When this is set, KMD will send a hint to GuC which results in special handling for this context. SLPC will ramp the GT frequency aggressively every time it switches to this context. The down freq threshold will also be lower so GuC will ramp down the GT freq for this context more slowly. We also disable waitboost for this context as that will interfere with the strategy.
We need to enable the use of Compute strategy during SLPC init, but it will apply only to contexts that set this bit during context creation.
Userland can check whether this feature is supported using a new param-
I915_PARAM_HAS_COMPUTE_CONTEXT. This flag is true for all guc submission enabled platforms since they use SLPC for freq management.Quoted 5 lines
Quoted 2 lines
The Mesa usage model for this flag is here -
https://gitlab.freedesktop.org/sushmave/mesa/-/commits/compute_hintThis allows for setting it for the whole application, correct? Upsides, downsides? Are there any plans for per context?
Quoted 8 lines
Currently there's no extension on a high level API (Vulkan/OpenGL/OpenCL/etc) that would allow the application to hint for power/freq/latency. So Mesa cannot decide when to hint. So their solution was to use .drirc and make per-application decision.
I would prefer a high level extension for a more granular and informative decision. We need to work with that goal, but for now I don't see any cons on this approach.
In principle yeah I doesn't harm to have the option. I am just not sure how useful this intermediate step this is with its lack of intra-process granularity.
Quoted 61 lines
Quoted 48 lines
Quoted 48 lines
Cc Rodrigo Vivi <[email protected]>Signed-off-by Vinay Belgaumkar <[email protected]>---
drivers/gpu/drm/i915/gem/i915_gem_context.c | 8 +++++++.../gpu/drm/i915/gem/i915_gem_context_types.h| 1 + drivers/gpu/drm/i915/gt/intel_rps.c | 8 +++++++.../drm/i915/gt/uc/abi/guc_actions_slpc_abi.h| 21
+++++++++++++++++++
drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c | 17
+++++++++++++++
drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h | 1 +.../gpu/drm/i915/gt/uc/intel_guc_submission.c| 7 +++++++ drivers/gpu/drm/i915/i915_getparam.c | 11 ++++++++++ include/uapi/drm/i915_drm.h | 15 +++++++++++++9 files changed, 89 insertions(+)drivers/gpu/drm/i915/gem/i915_gem_context.c +8
-0@@ -879,6 +879,7 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv, struct i915_gem_proto_context *pc, struct drm_i915_gem_context_param *args) { + struct drm_i915_private *i915 = fpriv->i915; int ret = 0; switch (args->param) {@@ -904,6 +905,13 @@ static int set_proto_ctx_param(structdrm_i915_file_private *fpriv, pc->user_flags &= ~BIT(UCONTEXT_BANNABLE); break; + case I915_CONTEXT_PARAM_IS_COMPUTE: + if (!intel_uc_uses_guc_submission(&to_gt(i915)->uc)) + ret = -EINVAL; + else + pc->user_flags |= BIT(UCONTEXT_COMPUTE); + break; +case
I915_CONTEXT_PARAM_RECOVERABLE:
if (args->size)
ret =-EINVAL;drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0@@ -338,6 +338,7 @@ struct i915_gem_context { #define UCONTEXT_BANNABLE 2Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h struct i915_gem_context { · line 341
Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +1
-0#define UCONTEXT_RECOVERABLE 3 #define UCONTEXT_PERSISTENCE 4 +#define UCONTEXT_COMPUTE 5What is the GuC behaviour when
SLPC_CTX_FREQ_REQ_IS_COMPUTEis set for non-compute engines? Wondering if perintel_contextis what we want instead. (Which could then be thei915_context_param_enginesextension to mark individual contexts as compute strategy.)Perhaps we should rename this? This is a freq-decision-strategy inside GuC that is there mostly targeting compute workloads that needs lower latency with short burst execution. But the engine itself doesn't matter. It can be applied to any engine.
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
I have no idea if it makes sense for other engines, such as video, and what would be pros and cons in terms of PnP. But in the case we end up allowing it on any engine, then at least userspace name shouldn't be compute. :)
Yes, one of the suggestions from Daniele was to have something along the lines of
UCONTEXT_HIFREQor something along those lines so we don't confuse it with the Compute Engine.Okay, but additional question is would anyone ever want to set it for video or blitter. Would it harm, benefir, or be neutral.
It would depend on the use case. SLPC will not distinguish either ways. It will aggressively ramp the GT freq when this context is active. User is making a decision to choose perf over power.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Or if we decide to call it compute and only apply to compute engines, then I would strongly suggest making the uapi per
intel_contexti.e. the set engines extension instead of the GEM context param. Otherwise it would be odd that some engines get it and some don't. With explicit configuration userspace gets to see the clear picture of what is what.It will not be per engine, so may be better to keep it at the
Why? Just because..
Feels strange that we are giving a coarse control(per gem context) to UMD but mapping it to a finer control(per engine) on the KMD side. Anyways, hopefully we can find a way to extend this to UMD eventually as well.
Quoted 6 lines
Quoted 2 lines
gem_contextlevel. Trying to percolate it to theintel_contextlevel seems to be more complicated. We process thegem_context_paramflags first and then create theintel_contextper engine. Not sure if we want to keep 2 copies of the same flag ingem_contextandintel_contextas well... it is complicated? It is not complicated at all. There is
intel_context_set_gemwhich is just for uses like that.Once you have this, then the only difference is whether you go from GEM context setparam to
intel_context, or flag goes directly tointel_contextas they are created via custom engine maps.
Yes, though intel_context_set_gem is called before we copy over the flags from the user AFAICS. Will need to somehow access the user flags in that function.
Thanks,
Vinay.
Quoted 244 lines
Regards,
Tvrtko
Quoted 239 lines
Quoted 48 lines
Regards,
Tvrtko
Quoted 43 lines
Quoted 28 lines
Quoted 14 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0/*** @flags: small set of booleans drivers/gpu/drm/i915/gt/intel_rps.c +1
-0@@ -24,6 +24,7 @@ #include "intel_pcode.h" #include "intel_rps.h" #include "vlv_sideband.h" +#include "../gem/i915_gem_context.h" #include "../../../platform/x86/intel_ips.h" #define BUSY_MAX_EI 20u /* ms */drivers/gpu/drm/i915/gt/intel_rps.c void intel_rps_boost(struct i915_request *rq) · line 1027
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_rps.c +7
-0@@ -1018,6 +1019,13 @@ void intel_rps_boost(struct i915_request *rq) struct intel_rps *rps = &READ_ONCE(rq->engine)->gt->rps; if (rps_uses_slpc(rps)) { + const struct i915_gem_context *ctx; + + ctx = i915_request_gem_context(rq); + if (ctx && + test_bit(UCONTEXT_COMPUTE, &ctx->user_flags)) + return; +I think request and
intel_contextdo not own a strong reference to GEM context. So at minimum you need a local one obtained under a RCU lock withkref_get_unless_zero, as do some other places do.Quoted 4 lines
However.. it may be simpler to just store the flag in
intel_context->flags. If you carry it over at the time GEM context is assigned tointel_context, not only you simplify runtime rules, but you get the ability to not set the compute flags for video etc.+1 on the
intel_context->flagsQuoted 5 lines
It may even make sense to add a "don't waitboost" flag on top of the "is compute" so this call site becomes self-documenting (otherwise I ask to add a comment here please). Then you could even move it out from the SLPC special case.
+1 on the
dont_waitboostflag as well. might be worth for other cases like display metrics for instance.We could define another
disable_waitboostflag inintel_context, but seems redundant if we already have this info in thegem_context. We don't need to check for SLPC special case, just need to check this flag as we won't enable it for the non-slpc case anyways.Thanks,
Vinay.
Quoted 184 lines
Quoted 184 lines
Quoted 184 lines
Quoted 126 lines
drivers/gpu/drm/i915/gt/intel_rps.c +0
-0slpc = rps_to_slpc(rps); if (slpc->min_freq_softlimit >= slpc->boost_freq)drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.h +21
-0@@ -207,6 +207,27 @@ struct slpc_shared_data { u8 reserved_mode_definition[4096]; } __packed; +struct slpc_context_frequency_request { + u32 frequency_request:16; + u32 reserved:12; + u32 is_compute:1; + u32 ignore_busyness:1; + u32 is_minimum:1; + u32 is_predefined:1; +} __packed; + +#define SLPC_CTX_FREQ_REQ_IS_COMPUTE REG_BIT(28) + +struct slpc_optimized_strategies { + u32 compute:1; + u32 async_flip:1; + u32 media:1; + u32 vsync_flip:1; + u32 reserved:28; +} __packed; + +#define SLPC_OPTIMIZED_STRATEGY_COMPUTE REG_BIT(0) + /*** DOC: SLPC H2G MESSAGE FORMAT * drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +14
-0@@ -537,6 +537,20 @@ int intel_guc_slpc_get_min_freq(struct intel_guc_slpc *slpc, u32 *val) return ret; } +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val) +{ + struct drm_i915_private *i915 = slpc_to_i915(slpc); + intel_wakeref_t wakeref; + int ret = 0; + + with_intel_runtime_pm(&i915->runtime_pm, wakeref) + ret = slpc_set_param(slpc, + SLPC_PARAM_STRATEGIES, + val); + + return ret; +} + int intel_guc_slpc_set_media_ratio_mode(struct intel_guc_slpc *slpc, u32 val) {struct
drm_i915_private*i915 =slpc_to_i915(slpc);drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +3
-0@@ -711,6 +725,9 @@ int intel_guc_slpc_enable(struct intel_guc_slpc *slpc) /* Set cached media freq ratio mode */ intel_guc_slpc_set_media_ratio_mode(slpc, slpc->media_ratio_mode); + /* Enable SLPC Optimized Strategy for compute */ + intel_guc_slpc_set_strategy(slpc,SLPC_OPTIMIZED_STRATEGY_COMPUTE ); + return 0; }drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h +1
-0@@ -45,5 +45,6 @@ void intel_guc_pm_intrmsk_enable(struct intel_gt *gt); void intel_guc_slpc_boost(struct intel_guc_slpc *slpc); void intel_guc_slpc_dec_waiters(struct intel_guc_slpc *slpc); int intel_guc_slpc_set_ignore_eff_freq(struct intel_guc_slpc *slpc, bool val); +int intel_guc_slpc_set_strategy (struct intel_guc_slpc *slpc,u32 val);#endif
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3
-0@@ -2645,6 +2645,7 @@ MAKE_CONTEXT_POLICY_ADD(execution_quantum, EXECUTION_QUANTUM) MAKE_CONTEXT_POLICY_ADD(preemption_timeout, PREEMPTION_TIMEOUT) MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY) MAKE_CONTEXT_POLICY_ADD(preempt_to_idle, PREEMPT_TO_IDLE_ON_QUANTUM_EXPIRY) +MAKE_CONTEXT_POLICY_ADD(slpc_ctx_freq_req, SLPM_GT_FREQUENCY) #undef MAKE_CONTEXT_POLICY_ADD@@ -2662,8 +2663,10 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop) struct intel_engine_cs *engine = ce->engine; struct intel_guc *guc = &engine->gt->uc.guc; struct context_policy policy; + struct i915_gem_context *ctx =rcu_dereference (ce->gem_context); u32 execution_quantum; u32 preemption_timeout; + u32 slpc_ctx_freq_req = 0; unsigned long flags;int ret;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +4
-0@@ -2675,11 +2678,15 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop) execution_quantum = engine->props.timeslice_duration_ms * 1000; preemption_timeout = engine->props.preempt_timeout_ms * 1000; + if (ctx && (ctx->user_flags & BIT(UCONTEXT_COMPUTE))) + slpc_ctx_freq_req |= SLPC_CTX_FREQ_REQ_IS_COMPUTE; + __guc_context_policy_start_klv(&policy, ce->guc_id.id); __guc_context_policy_add_priority(&policy, ce->guc_state.prio);__guc_context_policy_add_execution_quantum (&policy, execution_quantum);__guc_context_policy_add_preemption_timeout (&policy, preemption_timeout); +__guc_context_policy_add_slpc_ctx_freq_req (&policy, slpc_ctx_freq_req); if (engine->flags & I915_ENGINE_WANT_FORCED_PREEMPTION)__guc_context_policy_add_preempt_to_idle (&policy,1 );drivers/gpu/drm/i915/i915_getparam.c +0
-0drivers/gpu/drm/i915/i915_getparam.c int i915_getparam_ioctl(struct drm_device · line 164
Quoted 10 lines
drivers/gpu/drm/i915/i915_getparam.c +6
-0@@ -155,6 +155,17 @@ int i915_getparam_ioctl(struct drm_device*dev, void *data, */ value = 1; break; + case I915_PARAM_HAS_COMPUTE_CONTEXT: + /* This feature has been available in GuC for a while but +* a use case now required the use of this feature. We +* return true now since this is now being supported from +* the kernel side as well. +*/ Nit - stick to the multi-line comment style i915 uses please.
Regards,
Tvrtko
Quoted 41 lines
drivers/gpu/drm/i915/i915_getparam.c +5
-0+ if (intel_uc_uses_guc_submission(&to_gt(i915)->uc)) + value = 1; + else + value = -EINVAL; + break;case
I915_PARAM_HAS_CONTEXT_ISOLATION:
value =intel_engines_has_context_isolation(i915); break;include/uapi/drm/i915_drm.h +2
-0@@ -806,6 +806,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_PXP_STATUS 58 +/* +* Query if kernel allows marking a context as a Compute context. This will
+ * result in more aggressive GT frequency ramping for this context.
+ */include/uapi/drm/i915_drm.h +2
-0+#define I915_PARAM_HAS_COMPUTE_CONTEXT 59 +/* Must be kept compact -- no holes and well documented */ /**
include/uapi/drm/i915_drm.h +5
-0@@ -2148,6 +2154,15 @@ struct drm_i915_gem_context_param {* -EIO: The firmware did not succeed in creating the protected context. */ #define I915_CONTEXT_PARAM_PROTECTED_CONTENT 0xd + +/* +* I915_CONTEXT_PARAM_IS_COMPUTE: +* +* Mark this context as a Compute related workload which requires aggressive GT
+ * frequency scaling. QueryI915_PARAM_HAS_CONTEXT_COMPUTEto check if the kernel
+ * supports this functionality.
+ */
+#define I915_CONTEXT_PARAM_IS_COMPUTE0xe
/* Must be kept compact -- no holes and well documented */ /** @value: Context parameter value to be set or queried */
Rodrigo Vivi
maintainerQuoted 126 lines · Vinay
Quoted 124 lines · Tvrtko Ursulin
Quoted 122 lines · Vinay
Quoted 120 lines · Tvrtko Ursulin
Quoted 38 lines · Rodrigo Vivi
Quoted 22 lines · Tvrtko Ursulin
Quoted 20 lines · Vinay Belgaumkar
Allow user to provide a context hint. When this is set, KMD will send a hint to GuC which results in special handling for this context. SLPC will ramp the GT frequency aggressively every time it switches to this context. The down freq threshold will also be lower so GuC will ramp down the GT freq for this context more slowly.
We also disable waitboost for this context as that
will interfere with
the strategy.We need to enable the use of Compute strategy during SLPC init, but it will apply only to contexts that set this bit during context creation.
Userland can check whether this feature is supported using a new param-
I915_PARAM_HAS_COMPUTE_CONTEXT. This flag is true for all guc submission
enabled platforms since they use SLPC for freq management.Quoted 6 lines
Quoted 2 lines
The Mesa usage model for this flag is here -
https://gitlab.freedesktop.org/sushmave/mesa/-/commits/compute_hintThis allows for setting it for the whole application, correct? Upsides,
downsides? Are there any plans for per context?Currently there's no extension on a high level API (Vulkan/OpenGL/OpenCL/etc)
that would allow the application to hint for power/freq/latency. So Mesa cannot
decide when to hint. So their solution was to use .drirc and make per-application
decision.Quoted 4 lines
I would prefer a high level extension for a more granular and informative
decision. We need to work with that goal, but for now I don't see any cons on this approach.In principle yeah I doesn't harm to have the option. I am just not sure how useful this intermediate step this is with its lack of intra-process granularity.
Quoted 70 lines
Quoted 56 lines
Quoted 56 lines
Cc Rodrigo Vivi <[email protected]>Signed-off-by Vinay Belgaumkar <[email protected]>---
drivers/gpu/drm/i915/gem/i915_gem_context.c | 8 +++++++.../gpu/drm/i915/gem/i915_gem_context_types.h| 1 + drivers/gpu/drm/i915/gt/intel_rps.c | 8 +++++++.../drm/i915/gt/uc/abi/guc_actions_slpc_abi.h|
21 +++++++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c |
17 +++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h | 1 +.../gpu/drm/i915/gt/uc/intel_guc_submission.c| 7 +++++++ drivers/gpu/drm/i915/i915_getparam.c | 11 ++++++++++ include/uapi/drm/i915_drm.h | 15 +++++++++++++9 files changed, 89 insertions(+)diff --git
a/drivers/gpu/drm/i915/gem/i915_gem_context.cb/drivers/gpu/drm/i915/gem/i915_gem_context.c
indexdcbfe32fd30c..ceab7dbe9b47100644drivers/gpu/drm/i915/gem/i915_gem_context.c +0
-0@@ -879,6 +879,7 @@ static intset_proto_ctx_param(struct
drm_i915_file_private*fpriv,
structi915_gem_proto_context*pc, structdrm_i915_gem_context_param*args) {
+ structdrm_i915_private*i915 =fpriv->i915; int ret = 0;
switch (args->param) {drivers/gpu/drm/i915/gem/i915_gem_context.c +0
-0@@ -904,6 +905,13 @@ static intset_proto_ctx_param(struct
drm_i915_file_private*fpriv,
pc->user_flags&= ~BIT(UCONTEXT_BANNABLE); break;
+ caseI915_CONTEXT_PARAM_IS_COMPUTE:
+ if (!intel_uc_uses_guc_submission(&to_gt(i915)->uc)) + ret =-EINVAL;
+ else
+pc->user_flags|=BIT(UCONTEXT_COMPUTE); + break;
+
caseI915_CONTEXT_PARAM_RECOVERABLE:
if (args->size)
ret =-EINVAL;
diff --gita/drivers/gpu/drm/i915/gem/i915_gem_context_types.hb/drivers/gpu/drm/i915/gem/i915_gem_context_types.hindex03bc7f9d191b..db86d6f6245f100644drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0@@ -338,6 +338,7 @@ struct i915_gem_context { #define UCONTEXT_BANNABLE 2 #define UCONTEXT_RECOVERABLE 3 #define UCONTEXT_PERSISTENCE 4Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h struct i915_gem_context { · line 341
Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +1
-0+#define UCONTEXT_COMPUTE 5What is the GuC behaviour when
SLPC_CTX_FREQ_REQ_IS_COMPUTEis set for
non-compute engines? Wondering if perintel_contextis what we want instead.
(Which could then be thei915_context_param_enginesextension to mark individual contexts as compute strategy.)Perhaps we should rename this? This is a freq-decision-strategy inside GuC that is there mostly targeting compute workloads that needs lower latency with short burst execution. But the engine itself doesn't matter.
It can be applied to any engine.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
I have no idea if it makes sense for other engines, such as video, and what would be pros and cons in terms of PnP. But in the case we end up allowing it on any engine, then at least userspace name shouldn't be compute. :)
Yes, one of the suggestions from Daniele was to have something along the lines of
UCONTEXT_HIFREQor something along those lines so we don't confuse it with the Compute Engine.
hmm... I'm not fan of this name. GuC's compute strategy is not just about high gt frequency, but also some hysteresis to keep the freq high for a while and cover burst cases where the latency up and down on the frequency transactions would be damaging the performance.
also, one might say that waitboost is already 'hifreq'.
But I honestly believe that no one has a real good name for this thing and this is why it ended up calling 'compute' strategy in GuC, because it was created with compute use cases in mind.
Maybe UCONTEXT_HIFREQ_LOWLATENCY?
maybe UCONTEXT_HIFREQ_AND_BURSTY?
maybe UCONTEXT_BURSTY?
Quoted 6 lines
Quoted 3 lines
Okay, but additional question is would anyone ever want to set it for video or blitter. Would it harm, benefir, or be neutral.
It would depend on the use case. SLPC will not distinguish either ways. It will aggressively ramp the GT freq when this context is active. User is making a decision to choose perf over power.
I agree with Vinay here. It depends on the use case and I don't see any issue with that.
On some cases like heavy transcoder it would be neutral when compared to waitboost since both are hifreq and transcoder woudn't alternate fast on dropping and getting the wait boost.
In one of the cases that we have in the pipeline we need an opposite flag to only disable waitboost without enabling the 'compute' strategy so a video conference wouldn't waste power.
Quoted 316 lines
Quoted 11 lines
Quoted 9 lines
Quoted 7 lines
Or if we decide to call it compute and only apply to compute engines, then I would strongly suggest making the uapi per
intel_contexti.e. the set engines extension instead of the GEM context param. Otherwise it would be odd that some engines get it and some don't. With explicit configuration userspace gets to see the clear picture of what is what.It will not be per engine, so may be better to keep it at the
Why? Just because..
Feels strange that we are giving a coarse control(per gem context) to UMD but mapping it to a finer control(per engine) on the KMD side. Anyways, hopefully we can find a way to extend this to UMD eventually as well.
Quoted 7 lines
Quoted 6 lines
gem_contextlevel. Trying to percolate it to theintel_contextlevel seems to be more complicated. We process thegem_context_paramflags first and then create theintel_contextper engine. Not sure if we want to keep 2 copies of the same flag ingem_contextandintel_contextas well.Quoted 6 lines
.. it is complicated? It is not complicated at all. There is
intel_context_set_gemwhich is just for uses like that.Once you have this, then the only difference is whether you go from GEM context setparam to
intel_context, or flag goes directly tointel_contextas they are created via custom engine maps.Yes, though
intel_context_set_gemis called before we copy over the flags from the user AFAICS. Will need to somehow access the user flags in that function.Thanks,
Vinay.
Quoted 280 lines
Regards,
Tvrtko
Quoted 275 lines
Quoted 56 lines
Regards,
Tvrtko
Quoted 51 lines
Quoted 31 lines
Quoted 15 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0/*** @flags: small set of booleans drivers/gpu/drm/i915/gt/intel_rps.c +1
-0@@ -24,6 +24,7 @@ #include "intel_pcode.h" #include "intel_rps.h" #include "vlv_sideband.h" +#include "../gem/i915_gem_context.h" #include "../../../platform/x86/intel_ips.h" #define BUSY_MAX_EI 20u /* ms */drivers/gpu/drm/i915/gt/intel_rps.c void intel_rps_boost(struct i915_request *rq) · line 1027
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_rps.c +7
-0@@ -1018,6 +1019,13 @@ void intel_rps_boost(struct i915_request *rq) struct intel_rps *rps = &READ_ONCE(rq->engine)->gt->rps; if (rps_uses_slpc(rps)) { + const struct i915_gem_context *ctx; + + ctx = i915_request_gem_context(rq); + if (ctx && + test_bit(UCONTEXT_COMPUTE, &ctx->user_flags)) + return; +I think request and
intel_contextdo not own a strong reference to GEM
context. So at minimum you need a local one obtained under a RCU lock withkref_get_unless_zero, as do some other places do.Quoted 7 lines
However.. it may be simpler to just store the flag in
intel_context->flags.
If you carry it over at the time GEM context is assigned tointel_context,
not only you simplify runtime rules, but you get the ability to not set the
compute flags for video etc.+1 on the
intel_context->flagsQuoted 7 lines
It may even make sense to add a "don't waitboost" flag
on top of the "is
compute" so this call site becomes self-documenting (otherwise I ask to add
a comment here please). Then you could even move it out from the SLPC special case.+1 on the
dont_waitboostflag as well. might be worth for other cases like display metrics for instance.We could define another
disable_waitboostflag inintel_context, but seems redundant if we already have this info in thegem_context. We don't need to check for SLPC special case, just need to check this flag as we won't enable it for the non-slpc case anyways.Thanks,
Vinay.
Quoted 209 lines
Quoted 209 lines
Quoted 209 lines
Quoted 148 lines
drivers/gpu/drm/i915/gt/intel_rps.c +0
-0slpc = rps_to_slpc(rps); if (slpc->min_freq_softlimit >= slpc->boost_freq)diff --git
a/drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.hb/drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.hindex811add10c30d..c34674e797c6100644drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.h +21
-0@@ -207,6 +207,27 @@ struct slpc_shared_data { u8 reserved_mode_definition[4096]; } __packed; +struct slpc_context_frequency_request { + u32 frequency_request:16; + u32 reserved:12; + u32 is_compute:1; + u32 ignore_busyness:1; + u32 is_minimum:1; + u32 is_predefined:1; +} __packed; + +#define SLPC_CTX_FREQ_REQ_IS_COMPUTE REG_BIT(28) + +struct slpc_optimized_strategies { + u32 compute:1; + u32 async_flip:1; + u32 media:1; + u32 vsync_flip:1; + u32 reserved:28; +} __packed; + +#define SLPC_OPTIMIZED_STRATEGY_COMPUTE REG_BIT(0) + /*** DOC: SLPC H2G MESSAGE FORMAT * diff --git
a/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.cb/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
index3e681ab6fbf9..706fffca698b100644drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +0
-0@@ -537,6 +537,20 @@ intintel_guc_slpc_get_min_freq(struct
intel_guc_slpc
*slpc, u32 *val)
return ret;
}
+int intel_guc_slpc_set_strategy(structintel_guc_slpc*slpc, u32 val)drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +13
-0+{ + struct drm_i915_private *i915 = slpc_to_i915(slpc); + intel_wakeref_t wakeref; + int ret = 0; + + with_intel_runtime_pm(&i915->runtime_pm, wakeref) + ret = slpc_set_param(slpc, + SLPC_PARAM_STRATEGIES, + val); + + return ret; +} +int
intel_guc_slpc_set_media_ratio_mode(struct intel_guc_slpc *slpc, u32 val)
{
structdrm_i915_private*i915 =slpc_to_i915(slpc);drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +3
-0@@ -711,6 +725,9 @@ int intel_guc_slpc_enable(struct intel_guc_slpc *slpc) /* Set cached media freq ratio mode */ intel_guc_slpc_set_media_ratio_mode(slpc, slpc->media_ratio_mode); + /* Enable SLPC Optimized Strategy for compute */ + intel_guc_slpc_set_strategy(slpc,SLPC_OPTIMIZED_STRATEGY_COMPUTE ); + return 0;}
diff --gita/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.hb/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h
index6ac6503c39d4..1cb5fd44f05c100644drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h +0
-0@@ -45,5 +45,6 @@ void intel_guc_pm_intrmsk_enable(struct intel_gt *gt); void intel_guc_slpc_boost(struct intel_guc_slpc *slpc); void intel_guc_slpc_dec_waiters(struct intel_guc_slpc *slpc);int
intel_guc_slpc_set_ignore_eff_freq(struct intel_guc_slpc *slpc, bool val);
+intintel_guc_slpc_set_strategy(struct intel_guc_slpc *slpc, u32 val);
#endif
diff --gita/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.cb/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.cindexf3dcae4b9d45..bbabfa5532e5100644drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-0@@ -2645,6 +2645,7 @@ MAKE_CONTEXT_POLICY_ADD(execution_quantum, EXECUTION_QUANTUM) MAKE_CONTEXT_POLICY_ADD(preemption_timeout, PREEMPTION_TIMEOUT) MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY) MAKE_CONTEXT_POLICY_ADD(preempt_to_idle, PREEMPT_TO_IDLE_ON_QUANTUM_EXPIRY) +MAKE_CONTEXT_POLICY_ADD (slpc_ctx_freq_req,SLPM_GT_FREQUENCY )#undef
MAKE_CONTEXT_POLICY_ADDdrivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0@@ -2662,8 +2663,10 @@ static int
guc_context_policy_init_v70(struct intel_context *ce, bool loop)
structintel_engine_cs*engine =ce->engine; structintel_guc*guc =&engine->gt->uc.guc; structcontext_policypolicy;
+ structi915_gem_context*ctx =rcu_dereference(ce->gem_context);
u32execution_quantum;
u32preemption_timeout;
+ u32slpc_ctx_freq_req= 0;
unsigned long flags;
int ret;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0@@ -2675,11 +2678,15 @@ static intguc_context_policy_init_v70(struct
intel_context
*ce, bool loop)
execution_quantum=engine->props.timeslice_duration_ms* 1000;preemption_timeout=engine->props.preempt_timeout_ms* 1000; + if (ctx && (ctx->user_flags&BIT(UCONTEXT_COMPUTE))) +slpc_ctx_freq_req|=SLPC_CTX_FREQ_REQ_IS_COMPUTE; +
__guc_context_policy_start_klv(&policy, ce->guc_id.id);__guc_context_policy_add_priority(&policy, ce->guc_state.prio);__guc_context_policy_add_execution_quantum(&policy, execution_quantum);__guc_context_policy_add_preemption_timeout(&policy, preemption_timeout);
+__guc_context_policy_add_slpc_ctx_freq_req(&policy, slpc_ctx_freq_req);
if (engine->flags&I915_ENGINE_WANT_FORCED_PREEMPTION)__guc_context_policy_add_preempt_to_idle(&policy, 1);drivers/gpu/drm/i915/i915_getparam.c +0
-0drivers/gpu/drm/i915/i915_getparam.c int i915_getparam_ioctl(struct · line 164
Quoted 10 lines
drivers/gpu/drm/i915/i915_getparam.c +6
-0@@ -155,6 +155,17 @@ int i915_getparam_ioctl(structdrm_device *dev, void *data, */ value = 1; break; + case I915_PARAM_HAS_COMPUTE_CONTEXT: + /* This feature has been available in GuC for a while but +* a use case now required the use of this feature. We +* return true now since this is now being supported from +* the kernel side as well. +*/ Nit - stick to the multi-line comment style i915 uses please.
Regards,
Tvrtko
Quoted 44 lines
drivers/gpu/drm/i915/i915_getparam.c +5
-0+ if (intel_uc_uses_guc_submission(&to_gt(i915)->uc)) + value = 1; + else + value = -EINVAL; + break;case
I915_PARAM_HAS_CONTEXT_ISOLATION:
value =intel_engines_has_context_isolation(i915); break;include/uapi/drm/i915_drm.h +2
-0@@ -806,6 +806,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_PXP_STATUS 58 +/* +* Query if kernel allows marking a context as a Compute context. This will
+ * result in more aggressive GT frequency ramping for this context.
+ */include/uapi/drm/i915_drm.h +2
-0+#define I915_PARAM_HAS_COMPUTE_CONTEXT 59 +/* Must be kept compact -- no holes and well documented */ /**
include/uapi/drm/i915_drm.h +0
-0@@ -2148,6 +2154,15 @@ struct drm_i915_gem_context_param { * -EIO: The firmware did not succeed in creatingthe protected context.
*/
#define I915_CONTEXT_PARAM_PROTECTED_CONTENT0xdinclude/uapi/drm/i915_drm.h +5
-0+ +/* +* I915_CONTEXT_PARAM_IS_COMPUTE: +* +* Mark this context as a Compute related workload which requires aggressive GT
+ * frequency scaling. QueryI915_PARAM_HAS_CONTEXT_COMPUTEto check if the
kernel
+ * supports this functionality.
+ */
+#define I915_CONTEXT_PARAM_IS_COMPUTE0xe
/* Must be kept compact -- no holes and well documented */ /** @value: Context parameter value to be set or queried */
Quoted 142 lines · Rodrigo Vivi
Quoted 126 lines · Vinay
Quoted 124 lines · Tvrtko Ursulin
Quoted 122 lines · Vinay
Quoted 120 lines · Tvrtko Ursulin
Quoted 38 lines · Rodrigo Vivi
Quoted 22 lines · Tvrtko Ursulin
Quoted 20 lines · Vinay Belgaumkar
Allow user to provide a context hint. When this is set, KMD will send a hint to GuC which results in special handling for this context. SLPC will ramp the GT frequency aggressively every time it switches to this context. The down freq threshold will also be lower so GuC will ramp down the GT freq for this context more slowly.
We also disable waitboost for this context as that
will interfere with
the strategy.We need to enable the use of Compute strategy during SLPC init, but it will apply only to contexts that set this bit during context creation.
Userland can check whether this feature is supported using a new param-
I915_PARAM_HAS_COMPUTE_CONTEXT. This flag is true for all guc submission
enabled platforms since they use SLPC for freq management.Quoted 6 lines
Quoted 2 lines
The Mesa usage model for this flag is here -
https://gitlab.freedesktop.org/sushmave/mesa/-/commits/compute_hintThis allows for setting it for the whole application, correct? Upsides,
downsides? Are there any plans for per context?Currently there's no extension on a high level API (Vulkan/OpenGL/OpenCL/etc)
that would allow the application to hint for power/freq/latency. So Mesa cannot
decide when to hint. So their solution was to use .drirc and make per-application
decision.Quoted 4 lines
I would prefer a high level extension for a more granular and informative
decision. We need to work with that goal, but for now I don't see any cons on this approach.In principle yeah I doesn't harm to have the option. I am just not sure how useful this intermediate step this is with its lack of intra-process granularity.
Quoted 70 lines
Quoted 56 lines
Quoted 56 lines
Cc Rodrigo Vivi <[email protected]>Signed-off-by Vinay Belgaumkar <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 8 +++++++ .../gpu/drm/i915/gem/i915_gem_context_types.h | 1 + drivers/gpu/drm/i915/gt/intel_rps.c | 8 +++++++
.../drm/i915/gt/uc/abi/guc_actions_slpc_abi.h|
21 +++++++++++++++++++
drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c |
17 +++++++++++++++drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h | 1 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 7 +++++++ drivers/gpu/drm/i915/i915_getparam.c | 11 ++++++++++ include/uapi/drm/i915_drm.h | 15 +++++++++++++ 9 files changed, 89 insertions(+)diff --git
a/drivers/gpu/drm/i915/gem/i915_gem_context.cb/drivers/gpu/drm/i915/gem/i915_gem_context.c
indexdcbfe32fd30c..ceab7dbe9b47100644drivers/gpu/drm/i915/gem/i915_gem_context.c +0
-0@@ -879,6 +879,7 @@ static intset_proto_ctx_param(struct
drm_i915_file_private*fpriv,
structi915_gem_proto_context*pc, structdrm_i915_gem_context_param*args) {
+ structdrm_i915_private*i915 =fpriv->i915;
int ret = 0;
switch (args->param) {drivers/gpu/drm/i915/gem/i915_gem_context.c +0
-0@@ -904,6 +905,13 @@ static intset_proto_ctx_param(struct
drm_i915_file_private*fpriv,
pc->user_flags&= ~BIT(UCONTEXT_BANNABLE); break;
+ caseI915_CONTEXT_PARAM_IS_COMPUTE:
+ if (!intel_uc_uses_guc_submission(&to_gt(i915)->uc)) + ret =-EINVAL;
+ else
+pc->user_flags|=BIT(UCONTEXT_COMPUTE); + break;
+
caseI915_CONTEXT_PARAM_RECOVERABLE:
if (args->size)
ret =-EINVAL;
diff --gita/drivers/gpu/drm/i915/gem/i915_gem_context_types.hb/drivers/gpu/drm/i915/gem/i915_gem_context_types.hindex03bc7f9d191b..db86d6f6245f100644drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0@@ -338,6 +338,7 @@ struct i915_gem_context { #define UCONTEXT_BANNABLE 2 #define UCONTEXT_RECOVERABLE 3 #define UCONTEXT_PERSISTENCE 4Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h struct i915_gem_context { · line 341
Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +1
-0+#define UCONTEXT_COMPUTE 5What is the GuC behaviour when
SLPC_CTX_FREQ_REQ_IS_COMPUTEis set for
non-compute engines? Wondering if perintel_contextis what we want instead.
(Which could then be thei915_context_param_enginesextension to mark individual contexts as compute strategy.)Perhaps we should rename this? This is a freq-decision-strategy inside GuC that is there mostly targeting compute workloads that needs lower latency with short burst execution. But the engine itself doesn't matter.
It can be applied to any engine.Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
I have no idea if it makes sense for other engines, such as video, and what would be pros and cons in terms of PnP. But in the case we end up allowing it on any engine, then at least userspace name shouldn't be compute. :)
Yes, one of the suggestions from Daniele was to have something along the lines of
UCONTEXT_HIFREQor something along those lines so we don't confuse it with the Compute Engine.hmm... I'm not fan of this name. GuC's compute strategy is not just about high gt frequency, but also some hysteresis to keep the freq high for a while and cover burst cases where the latency up and down on the frequency transactions would be damaging the performance.
also, one might say that waitboost is already 'hifreq'.
Quoted 7 lines
But I honestly believe that no one has a real good name for this thing and this is why it ended up calling 'compute' strategy in GuC, because it was created with compute use cases in mind.
Maybe
UCONTEXT_HIFREQ_LOWLATENCY?
maybeUCONTEXT_HIFREQ_AND_BURSTY?
maybeUCONTEXT_BURSTY?
I like low latency.
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
Okay, but additional question is would anyone ever want to set it for video or blitter. Would it harm, benefir, or be neutral.
It would depend on the use case. SLPC will not distinguish either ways. It will aggressively ramp the GT freq when this context is active. User is making a decision to choose perf over power.
Quoted 6 lines
I agree with Vinay here. It depends on the use case and I don't see any issue with that.
On some cases like heavy transcoder it would be neutral when compared to waitboost since both are hifreq and transcoder woudn't alternate fast on dropping and getting the wait boost.
I am asking this question simply for a wider consideration of whether or not being coarse would force some userspace into creating multiple GEM contexts, and then needing to implement VM sharing on top, while otherwise they would be happy with just one.
The issue wouldn't apply to a library that is purely compute obviously, but for something mixed use it might. Whether or not such user exists I am not sure, but the main point is that with granular control one does not even have to know and simply punts the decision and flexibility to userspace.
Quoted 3 lines
In one of the cases that we have in the pipeline we need an opposite flag to only disable waitboost without enabling the 'compute' strategy so a video conference wouldn't waste power.
And for that flag it would be the same question. While you have the vaapi driver it is not a concern (one GEM context just for decode by definition), but if someone wanted to implement both decode and render in the same context/address space, then per intel_context control could be better than per GEM context.
Or for both from a different angle - what is the donwside of allowing per intel_context control?
Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Or if we decide to call it compute and only apply to compute engines, then I would strongly suggest making the uapi per
intel_contexti.e. the set engines extension instead of the GEM context param. Otherwise it would be odd that some engines get it and some don't. With explicit configuration userspace gets to see the clear picture of what is what.It will not be per engine, so may be better to keep it at the
Why? Just because..
Feels strange that we are giving a coarse control(per gem context) to UMD but mapping it to a finer control(per engine) on the KMD side. Anyways, hopefully we can find a way to extend this to UMD eventually as well.
Quoted 10 lines
Quoted 6 lines
gem_contextlevel. Trying to percolate it to theintel_contextlevel seems to be more complicated. We process thegem_context_paramflags first and then create theintel_contextper engine. Not sure if we want to keep 2 copies of the same flag ingem_contextandintel_contextas well... it is complicated? It is not complicated at all. There is
intel_context_set_gemwhich is just for uses like that.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Once you have this, then the only difference is whether you go from GEM context setparam to
intel_context, or flag goes directly tointel_contextas they are created via custom engine maps.Yes, though
intel_context_set_gemis called before we copy over the flags from the user AFAICS. Will need to somehow access the user flags in that function.
That looks a trivial matter of either moving that flag assignment few lines up, or passing pc->user_flags to user_engines and default_engines. Either sounds preferrable to having to do the rcu_read_lock and kref_get_unless_zero dance on every access.
Regards,
Tvrtko
Quoted 285 lines
Quoted 285 lines
Thanks,
Vinay.
Quoted 280 lines
Regards,
Tvrtko
Quoted 275 lines
Quoted 56 lines
Regards,
Tvrtko
Quoted 51 lines
Quoted 31 lines
Quoted 15 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0/*** @flags: small set of booleans drivers/gpu/drm/i915/gt/intel_rps.c +1
-0@@ -24,6 +24,7 @@ #include "intel_pcode.h" #include "intel_rps.h" #include "vlv_sideband.h" +#include "../gem/i915_gem_context.h" #include "../../../platform/x86/intel_ips.h" #define BUSY_MAX_EI 20u /* ms */drivers/gpu/drm/i915/gt/intel_rps.c void intel_rps_boost(struct i915_request *rq) · line 1027
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_rps.c +7
-0@@ -1018,6 +1019,13 @@ void intel_rps_boost(struct i915_request *rq) struct intel_rps *rps = &READ_ONCE(rq->engine)->gt->rps; if (rps_uses_slpc(rps)) { + const struct i915_gem_context *ctx; + + ctx = i915_request_gem_context(rq); + if (ctx && + test_bit(UCONTEXT_COMPUTE, &ctx->user_flags)) + return; +I think request and
intel_contextdo not own a strong reference to GEM
context. So at minimum you need a local one obtained under a RCU lock withkref_get_unless_zero, as do some other places do.Quoted 7 lines
However.. it may be simpler to just store the flag in
intel_context->flags.
If you carry it over at the time GEM context is assigned tointel_context,
not only you simplify runtime rules, but you get the ability to not set the
compute flags for video etc.+1 on the
intel_context->flagsQuoted 7 lines
It may even make sense to add a "don't waitboost" flag
on top of the "is
compute" so this call site becomes self-documenting (otherwise I ask to add
a comment here please). Then you could even move it out from the SLPC special case.+1 on the
dont_waitboostflag as well. might be worth for other cases like display metrics for instance.We could define another
disable_waitboostflag inintel_context, but seems redundant if we already have this info in thegem_context. We don't need to check for SLPC special case, just need to check this flag as we won't enable it for the non-slpc case anyways.Thanks,
Vinay.
Quoted 209 lines
Quoted 209 lines
Quoted 209 lines
Quoted 148 lines
drivers/gpu/drm/i915/gt/intel_rps.c +0
-0slpc = rps_to_slpc(rps); if (slpc->min_freq_softlimit >= slpc->boost_freq)diff --git
a/drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.hb/drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.hindex811add10c30d..c34674e797c6100644drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.h +21
-0@@ -207,6 +207,27 @@ struct slpc_shared_data { u8 reserved_mode_definition[4096]; } __packed; +struct slpc_context_frequency_request { + u32 frequency_request:16; + u32 reserved:12; + u32 is_compute:1; + u32 ignore_busyness:1; + u32 is_minimum:1; + u32 is_predefined:1; +} __packed; + +#define SLPC_CTX_FREQ_REQ_IS_COMPUTE REG_BIT(28) + +struct slpc_optimized_strategies { + u32 compute:1; + u32 async_flip:1; + u32 media:1; + u32 vsync_flip:1; + u32 reserved:28; +} __packed; + +#define SLPC_OPTIMIZED_STRATEGY_COMPUTE REG_BIT(0) + /*** DOC: SLPC H2G MESSAGE FORMAT * diff --git
a/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.cb/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
index3e681ab6fbf9..706fffca698b100644drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +0
-0@@ -537,6 +537,20 @@ intintel_guc_slpc_get_min_freq(struct
intel_guc_slpc
*slpc, u32 *val)
return ret;
}
+int intel_guc_slpc_set_strategy(structintel_guc_slpc*slpc, u32 val)drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +13
-0+{ + struct drm_i915_private *i915 = slpc_to_i915(slpc); + intel_wakeref_t wakeref; + int ret = 0; + + with_intel_runtime_pm(&i915->runtime_pm, wakeref) + ret = slpc_set_param(slpc, + SLPC_PARAM_STRATEGIES, + val); + + return ret; +} + int intel_guc_slpc_set_media_ratio_mode(struct
intel_guc_slpc*slpc, u32 val)
{
structdrm_i915_private*i915 =slpc_to_i915(slpc);drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +3
-0@@ -711,6 +725,9 @@ int intel_guc_slpc_enable(struct intel_guc_slpc *slpc) /* Set cached media freq ratio mode */ intel_guc_slpc_set_media_ratio_mode(slpc, slpc->media_ratio_mode); + /* Enable SLPC Optimized Strategy for compute */ + intel_guc_slpc_set_strategy(slpc,SLPC_OPTIMIZED_STRATEGY_COMPUTE ); + return 0;}
diff --gita/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.hb/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h
index6ac6503c39d4..1cb5fd44f05c100644drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h +1
-0@@ -45,5 +45,6 @@ void intel_guc_pm_intrmsk_enable(struct intel_gt *gt); void intel_guc_slpc_boost(struct intel_guc_slpc *slpc); void intel_guc_slpc_dec_waiters(struct intel_guc_slpc *slpc); int intel_guc_slpc_set_ignore_eff_freq(structintel_guc_slpc *slpc,bool val); +int intel_guc_slpc_set_strategy(struct
intel_guc_slpc*slpc, u32 val);
#endif
diff --gita/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.cb/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.cindexf3dcae4b9d45..bbabfa5532e5100644drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-0@@ -2645,6 +2645,7 @@ MAKE_CONTEXT_POLICY_ADD(execution_quantum, EXECUTION_QUANTUM) MAKE_CONTEXT_POLICY_ADD(preemption_timeout, PREEMPTION_TIMEOUT) MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY) MAKE_CONTEXT_POLICY_ADD(preempt_to_idle, PREEMPT_TO_IDLE_ON_QUANTUM_EXPIRY) +MAKE_CONTEXT_POLICY_ADD (slpc_ctx_freq_req,SLPM_GT_FREQUENCY )#undef
MAKE_CONTEXT_POLICY_ADDdrivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0@@ -2662,8 +2663,10 @@ static int
guc_context_policy_init_v70(struct intel_context *ce, bool loop)
structintel_engine_cs*engine =ce->engine; structintel_guc*guc =&engine->gt->uc.guc; structcontext_policypolicy;
+ structi915_gem_context*ctx =rcu_dereference(ce->gem_context);
u32execution_quantum;
u32preemption_timeout;
+ u32slpc_ctx_freq_req= 0;
unsigned long flags;
int ret;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0@@ -2675,11 +2678,15 @@ static intguc_context_policy_init_v70(struct
intel_context
*ce, bool loop)
execution_quantum=engine->props.timeslice_duration_ms* 1000;
preemption_timeout=engine->props.preempt_timeout_ms* 1000;
+ if (ctx && (ctx->user_flags&BIT(UCONTEXT_COMPUTE))) +slpc_ctx_freq_req|=SLPC_CTX_FREQ_REQ_IS_COMPUTE; +
__guc_context_policy_start_klv(&policy, ce->guc_id.id); __guc_context_policy_add_priority(&policy,ce->guc_state.prio);__guc_context_policy_add_execution_quantum(&policy, execution_quantum);__guc_context_policy_add_preemption_timeout(&policy, preemption_timeout);
+__guc_context_policy_add_slpc_ctx_freq_req(&policy, slpc_ctx_freq_req);
if (engine->flags&I915_ENGINE_WANT_FORCED_PREEMPTION)__guc_context_policy_add_preempt_to_idle(&policy, 1);drivers/gpu/drm/i915/i915_getparam.c +0
-0drivers/gpu/drm/i915/i915_getparam.c int i915_getparam_ioctl(struct · line 164
Quoted 10 lines
drivers/gpu/drm/i915/i915_getparam.c +6
-0@@ -155,6 +155,17 @@ int i915_getparam_ioctl(structdrm_device *dev, void *data, */ value = 1; break; + case I915_PARAM_HAS_COMPUTE_CONTEXT: + /* This feature has been available in GuC for a while but +* a use case now required the use of this feature. We +* return true now since this is now being supported from +* the kernel side as well. +*/ Nit - stick to the multi-line comment style i915 uses please.
Regards,
Tvrtko
Quoted 44 lines
drivers/gpu/drm/i915/i915_getparam.c +5
-0+ if (intel_uc_uses_guc_submission(&to_gt(i915)->uc)) + value = 1; + else + value = -EINVAL; + break; case I915_PARAM_HAS_CONTEXT_ISOLATION: value = intel_engines_has_context_isolation(i915);break;
include/uapi/drm/i915_drm.h +2
-0@@ -806,6 +806,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_PXP_STATUS 58 +/* +* Query if kernel allows marking a context as a Compute context. This will
+ * result in more aggressive GT frequency ramping for this context.
+ */include/uapi/drm/i915_drm.h +2
-0+#define I915_PARAM_HAS_COMPUTE_CONTEXT 59 + /* Must be kept compact -- no holes and well documented */ /**@@ -2148,6 +2154,15 @@ struct drm_i915_gem_context_param { * -EIO: The firmware did not succeed in creatingthe protected context.
*/
#define I915_CONTEXT_PARAM_PROTECTED_CONTENT0xdinclude/uapi/drm/i915_drm.h +5
-0+ +/* +* I915_CONTEXT_PARAM_IS_COMPUTE: +* +* Mark this context as a Compute related workload which requires aggressive GT
+ * frequency scaling. QueryI915_PARAM_HAS_CONTEXT_COMPUTEto check if the
kernel
+ * supports this functionality.
+ */
+#define I915_CONTEXT_PARAM_IS_COMPUTE0xe
/* Must be kept compact -- no holes and well documented */ /** @value: Context parameter value to be set or queried */
Quoted 172 lines · Tvrtko Ursulin
Quoted 143 lines · Rodrigo Vivi
Quoted 127 lines · Vinay
Quoted 125 lines · Tvrtko Ursulin
Quoted 123 lines · Vinay
Quoted 121 lines · Tvrtko Ursulin
Quoted 38 lines · Rodrigo Vivi
Quoted 22 lines · Tvrtko Ursulin
Quoted 20 lines · Vinay Belgaumkar
Allow user to provide a context hint. When this is set, KMD will send a hint to GuC which results in special handling for this context. SLPC will ramp the GT frequency aggressively every time it switches to this context. The down freq threshold will also be lower so GuC will ramp down the GT freq for this context more slowly.
We also disable waitboost for this context as that
will interfere with
the strategy.We need to enable the use of Compute strategy during SLPC init, but it will apply only to contexts that set this bit during context creation.
Userland can check whether this feature is supported using a new param-
I915_PARAM_HAS_COMPUTE_CONTEXT. This flag is true for all guc submission
enabled platforms since they use SLPC for freq management.Quoted 6 lines
Quoted 2 lines
The Mesa usage model for this flag is here -
https://gitlab.freedesktop.org/sushmave/mesa/-/commits/compute_hintThis allows for setting it for the whole application, correct? Upsides,
downsides? Are there any plans for per context?Currently there's no extension on a high level API (Vulkan/OpenGL/OpenCL/etc)
that would allow the application to hint for power/freq/latency. So Mesa cannot
decide when to hint. So their solution was to use .drirc and make per-application
decision.Quoted 4 lines
I would prefer a high level extension for a more granular and informative
decision. We need to work with that goal, but for now I don't see any cons on this approach.In principle yeah I doesn't harm to have the option. I am just not sure how useful this intermediate step this is with its lack of intra-process granularity.
Quoted 71 lines
Quoted 57 lines
Quoted 57 lines
Cc Rodrigo Vivi <[email protected]>Signed-off-by Vinay Belgaumkar <[email protected]>---
drivers/gpu/drm/i915/gem/i915_gem_context.c | 8 +++++++.../gpu/drm/i915/gem/i915_gem_context_types.h| 1 + drivers/gpu/drm/i915/gt/intel_rps.c | 8 +++++++.../drm/i915/gt/uc/abi/guc_actions_slpc_abi.h|
21 +++++++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c |
17 +++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h | 1 +.../gpu/drm/i915/gt/uc/intel_guc_submission.c| 7 +++++++ drivers/gpu/drm/i915/i915_getparam.c | 11 ++++++++++ include/uapi/drm/i915_drm.h | 15
+++++++++++++9 files changed, 89 insertions(+)diff --git
a/drivers/gpu/drm/i915/gem/i915_gem_context.cb/drivers/gpu/drm/i915/gem/i915_gem_context.c
indexdcbfe32fd30c..ceab7dbe9b47100644drivers/gpu/drm/i915/gem/i915_gem_context.c +0
-0@@ -879,6 +879,7 @@ static intset_proto_ctx_param(struct
drm_i915_file_private*fpriv,
structi915_gem_proto_context*pc, structdrm_i915_gem_context_param*args) {
+ structdrm_i915_private*i915 =fpriv->i915;
int ret = 0;
switch (args->param) {drivers/gpu/drm/i915/gem/i915_gem_context.c +0
-0@@ -904,6 +905,13 @@ static intset_proto_ctx_param(struct
drm_i915_file_private*fpriv,
pc->user_flags&= ~BIT(UCONTEXT_BANNABLE); break;
+ caseI915_CONTEXT_PARAM_IS_COMPUTE:
+ if (!intel_uc_uses_guc_submission(&to_gt(i915)->uc)) + ret =-EINVAL;
+ else
+pc->user_flags|=BIT(UCONTEXT_COMPUTE); + break;
+
caseI915_CONTEXT_PARAM_RECOVERABLE:
if (args->size)
ret =-EINVAL;
diff --gita/drivers/gpu/drm/i915/gem/i915_gem_context_types.hb/drivers/gpu/drm/i915/gem/i915_gem_context_types.hindex03bc7f9d191b..db86d6f6245f100644drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0@@ -338,6 +338,7 @@ struct i915_gem_context { #define UCONTEXT_BANNABLE 2 #define UCONTEXT_RECOVERABLE 3 #define UCONTEXT_PERSISTENCE 4Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h struct i915_gem_context { · line 341
Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +1
-0+#define UCONTEXT_COMPUTE 5What is the GuC behaviour when
SLPC_CTX_FREQ_REQ_IS_COMPUTEis set for
non-compute engines? Wondering if perintel_contextis what we want instead.
(Which could then be thei915_context_param_enginesextension to mark individual contexts as compute strategy.)Perhaps we should rename this? This is a freq-decision-strategy inside GuC that is there mostly targeting compute workloads that needs lower latency with short burst execution. But the engine itself doesn't matter.
It can be applied to any engine.Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
I have no idea if it makes sense for other engines, such as video, and what would be pros and cons in terms of PnP. But in the case we end up allowing it on any engine, then at least userspace name shouldn't be compute. :)
Yes, one of the suggestions from Daniele was to have something along the lines of
UCONTEXT_HIFREQor something along those lines so we don't confuse it with the Compute Engine.hmm... I'm not fan of this name. GuC's compute strategy is not just about high gt frequency, but also some hysteresis to keep the freq high for a while and cover burst cases where the latency up and down on the frequency transactions would be damaging the performance.
also, one might say that waitboost is already 'hifreq'.
Quoted 7 lines
But I honestly believe that no one has a real good name for this thing and this is why it ended up calling 'compute' strategy in GuC, because it was created with compute use cases in mind.
Maybe
UCONTEXT_HIFREQ_LOWLATENCY?
maybeUCONTEXT_HIFREQ_AND_BURSTY?
maybeUCONTEXT_BURSTY?I like low latency.
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
Okay, but additional question is would anyone ever want to set it for video or blitter. Would it harm, benefir, or be neutral.
It would depend on the use case. SLPC will not distinguish either ways. It will aggressively ramp the GT freq when this context is active. User is making a decision to choose perf over power.
Quoted 6 lines
I agree with Vinay here. It depends on the use case and I don't see any issue with that.
On some cases like heavy transcoder it would be neutral when compared to waitboost since both are hifreq and transcoder woudn't alternate fast on dropping and getting the wait boost.
I am asking this question simply for a wider consideration of whether or not being coarse would force some userspace into creating multiple GEM contexts, and then needing to implement VM sharing on top, while otherwise they would be happy with just one.
The issue wouldn't apply to a library that is purely compute obviously, but for something mixed use it might. Whether or not such user exists I am not sure, but the main point is that with granular control one does not even have to know and simply punts the decision and flexibility to userspace.
Quoted 7 lines
Quoted 3 lines
In one of the cases that we have in the pipeline we need an opposite flag to only disable waitboost without enabling the 'compute' strategy so a video conference wouldn't waste power.
And for that flag it would be the same question. While you have the vaapi driver it is not a concern (one GEM context just for decode by definition), but if someone wanted to implement both decode and render in the same context/address space, then per
intel_contextcontrol could be better than per GEM context.Or for both from a different angle - what is the donwside of allowing per
intel_contextcontrol?
And to be clear it is okay to eventually decide either way. Just that it is good to lay down (and document in the commit message probably) the pros and cons of all considered options. Just wanting to make sure we thought about all the angles before adding uapi.
Regards,
Tvrtko
Quoted 325 lines
Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Or if we decide to call it compute and only apply to compute engines, then I would strongly suggest making the uapi per
intel_contexti.e. the set engines extension instead of the GEM context param. Otherwise it would be odd that some engines get it and some don't. With explicit configuration userspace gets to see the clear picture of what is what.It will not be per engine, so may be better to keep it at the
Why? Just because..
Feels strange that we are giving a coarse control(per gem context) to UMD but mapping it to a finer control(per engine) on the KMD side. Anyways, hopefully we can find a way to extend this to UMD eventually as well.
Quoted 10 lines
Quoted 6 lines
gem_contextlevel. Trying to percolate it to theintel_contextlevel seems to be more complicated. We process thegem_context_paramflags first and then create theintel_contextper engine. Not sure if we want to keep 2 copies of the same flag ingem_contextandintel_contextas well... it is complicated? It is not complicated at all. There is
intel_context_set_gemwhich is just for uses like that.Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Once you have this, then the only difference is whether you go from GEM context setparam to
intel_context, or flag goes directly tointel_contextas they are created via custom engine maps.Yes, though
intel_context_set_gemis called before we copy over the flags from the user AFAICS. Will need to somehow access the user flags in that function.That looks a trivial matter of either moving that flag assignment few lines up, or passing
pc->user_flagstouser_enginesanddefault_engines. Either sounds preferrable to having to do thercu_read_lockandkref_get_unless_zerodance on every access.Regards,
Tvrtko
Quoted 288 lines
Quoted 288 lines
Thanks,
Vinay.
Quoted 283 lines
Regards,
Tvrtko
Quoted 278 lines
Quoted 58 lines
Regards,
Tvrtko
Quoted 53 lines
Quoted 32 lines
Quoted 15 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0/*** @flags: small set of booleans drivers/gpu/drm/i915/gt/intel_rps.c +1
-0@@ -24,6 +24,7 @@ #include "intel_pcode.h" #include "intel_rps.h" #include "vlv_sideband.h" +#include "../gem/i915_gem_context.h" #include "../../../platform/x86/intel_ips.h" #define BUSY_MAX_EI 20u /* ms */drivers/gpu/drm/i915/gt/intel_rps.c void intel_rps_boost(struct i915_request · line 1028
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_rps.c +7
-0@@ -1018,6 +1019,13 @@ void intel_rps_boost(struct i915_request *rq) struct intel_rps *rps = &READ_ONCE(rq->engine)->gt->rps; if (rps_uses_slpc(rps)) { + const struct i915_gem_context *ctx; + + ctx = i915_request_gem_context(rq); + if (ctx && + test_bit(UCONTEXT_COMPUTE, &ctx->user_flags)) + return; +I think request and
intel_contextdo not own a strong reference to GEM
context. So at minimum you need a local one obtained under a RCU lock withkref_get_unless_zero, as do some other places do.Quoted 7 lines
However.. it may be simpler to just store the flag in
intel_context->flags.
If you carry it over at the time GEM context is assigned tointel_context,
not only you simplify runtime rules, but you get the ability to not set the
compute flags for video etc.+1 on the
intel_context->flagsQuoted 7 lines
It may even make sense to add a "don't waitboost" flag
on top of the "is
compute" so this call site becomes self-documenting (otherwise I ask to add
a comment here please). Then you could even move it out from the SLPC special case.+1 on the
dont_waitboostflag as well. might be worth for other cases
like display metrics for instance.We could define another
disable_waitboostflag inintel_context, but seems redundant if we already have this info in thegem_context. We don't need to check for SLPC special case, just need to check this flag as we won't enable it for the non-slpc case anyways.Thanks,
Vinay.
Quoted 210 lines
Quoted 210 lines
Quoted 210 lines
Quoted 148 lines
drivers/gpu/drm/i915/gt/intel_rps.c +0
-0slpc = rps_to_slpc(rps); if (slpc->min_freq_softlimit >= slpc->boost_freq)diff --git
a/drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.hb/drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.hindex811add10c30d..c34674e797c6100644drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.h +21
-0@@ -207,6 +207,27 @@ struct slpc_shared_data { u8 reserved_mode_definition[4096]; } __packed; +struct slpc_context_frequency_request { + u32 frequency_request:16; + u32 reserved:12; + u32 is_compute:1; + u32 ignore_busyness:1; + u32 is_minimum:1; + u32 is_predefined:1; +} __packed; + +#define SLPC_CTX_FREQ_REQ_IS_COMPUTE REG_BIT(28) + +struct slpc_optimized_strategies { + u32 compute:1; + u32 async_flip:1; + u32 media:1; + u32 vsync_flip:1; + u32 reserved:28; +} __packed; + +#define SLPC_OPTIMIZED_STRATEGY_COMPUTE REG_BIT(0) + /*** DOC: SLPC H2G MESSAGE FORMAT * diff --git
a/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.cb/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
index3e681ab6fbf9..706fffca698b100644drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +0
-0@@ -537,6 +537,20 @@ intintel_guc_slpc_get_min_freq(struct
intel_guc_slpc
*slpc, u32 *val)
return ret;
}
+int intel_guc_slpc_set_strategy(structintel_guc_slpc*slpc, u32 val)drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +13
-0+{ + struct drm_i915_private *i915 = slpc_to_i915(slpc); + intel_wakeref_t wakeref; + int ret = 0; + + with_intel_runtime_pm(&i915->runtime_pm, wakeref) + ret = slpc_set_param(slpc, + SLPC_PARAM_STRATEGIES, + val); + + return ret; +} +int
intel_guc_slpc_set_media_ratio_mode(struct intel_guc_slpc *slpc, u32 val)
{
structdrm_i915_private*i915 =slpc_to_i915(slpc);drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c +3
-0@@ -711,6 +725,9 @@ int intel_guc_slpc_enable(struct intel_guc_slpc *slpc) /* Set cached media freq ratio mode */ intel_guc_slpc_set_media_ratio_mode(slpc, slpc->media_ratio_mode); + /* Enable SLPC Optimized Strategy for compute */ + intel_guc_slpc_set_strategy(slpc,SLPC_OPTIMIZED_STRATEGY_COMPUTE ); + return 0;}
diff --gita/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.hb/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h
index6ac6503c39d4..1cb5fd44f05c100644drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h +0
-0@@ -45,5 +45,6 @@ void intel_guc_pm_intrmsk_enable(struct intel_gt *gt); void intel_guc_slpc_boost(struct intel_guc_slpc *slpc); void intel_guc_slpc_dec_waiters(struct intel_guc_slpc *slpc);int
intel_guc_slpc_set_ignore_eff_freq(struct intel_guc_slpc *slpc, bool val);
+intintel_guc_slpc_set_strategy(struct intel_guc_slpc *slpc, u32 val);
#endif
diff --gita/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.cb/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.cindexf3dcae4b9d45..bbabfa5532e5100644drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-0@@ -2645,6 +2645,7 @@ MAKE_CONTEXT_POLICY_ADD(execution_quantum, EXECUTION_QUANTUM) MAKE_CONTEXT_POLICY_ADD(preemption_timeout, PREEMPTION_TIMEOUT) MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY) MAKE_CONTEXT_POLICY_ADD(preempt_to_idle, PREEMPT_TO_IDLE_ON_QUANTUM_EXPIRY) +MAKE_CONTEXT_POLICY_ADD (slpc_ctx_freq_req,SLPM_GT_FREQUENCY )#undef
MAKE_CONTEXT_POLICY_ADDdrivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0@@ -2662,8 +2663,10 @@ static int
guc_context_policy_init_v70(struct intel_context *ce, bool loop)
structintel_engine_cs*engine =ce->engine; structintel_guc*guc =&engine->gt->uc.guc; structcontext_policypolicy;
+ structi915_gem_context*ctx =rcu_dereference(ce->gem_context);
u32execution_quantum;
u32preemption_timeout;
+ u32slpc_ctx_freq_req= 0;
unsigned long flags;
int ret;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0@@ -2675,11 +2678,15 @@ static intguc_context_policy_init_v70(struct
intel_context
*ce, bool loop)
execution_quantum=engine->props.timeslice_duration_ms* 1000;preemption_timeout=engine->props.preempt_timeout_ms* 1000; + if (ctx && (ctx->user_flags&BIT(UCONTEXT_COMPUTE))) +slpc_ctx_freq_req|=SLPC_CTX_FREQ_REQ_IS_COMPUTE; +
__guc_context_policy_start_klv(&policy, ce->guc_id.id);__guc_context_policy_add_priority(&policy, ce->guc_state.prio);__guc_context_policy_add_execution_quantum(&policy, execution_quantum);__guc_context_policy_add_preemption_timeout(&policy, preemption_timeout);
+__guc_context_policy_add_slpc_ctx_freq_req(&policy, slpc_ctx_freq_req);
if (engine->flags&I915_ENGINE_WANT_FORCED_PREEMPTION)__guc_context_policy_add_preempt_to_idle(&policy, 1);drivers/gpu/drm/i915/i915_getparam.c +0
-0drivers/gpu/drm/i915/i915_getparam.c int i915_getparam_ioctl(struct · line 164
Quoted 10 lines
drivers/gpu/drm/i915/i915_getparam.c +6
-0@@ -155,6 +155,17 @@ int i915_getparam_ioctl(structdrm_device *dev, void *data, */ value = 1; break; + case I915_PARAM_HAS_COMPUTE_CONTEXT: + /* This feature has been available in GuC for a while but +* a use case now required the use of this feature. We +* return true now since this is now being supported from +* the kernel side as well. +*/ Nit - stick to the multi-line comment style i915 uses please.
Regards,
Tvrtko
Quoted 45 lines
drivers/gpu/drm/i915/i915_getparam.c +5
-0+ if (intel_uc_uses_guc_submission(&to_gt(i915)->uc)) + value = 1; + else + value = -EINVAL; + break;case
I915_PARAM_HAS_CONTEXT_ISOLATION:
value =intel_engines_has_context_isolation(i915); break;include/uapi/drm/i915_drm.h +2
-0@@ -806,6 +806,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_PXP_STATUS 58 +/* +* Query if kernel allows marking a context as a Compute context. This will
+ * result in more aggressive GT frequency ramping for this context.
+ */include/uapi/drm/i915_drm.h +2
-0+#define I915_PARAM_HAS_COMPUTE_CONTEXT 59 +/* Must be kept compact -- no holes and well documented */ /**
include/uapi/drm/i915_drm.h +0
-0@@ -2148,6 +2154,15 @@ struct drm_i915_gem_context_param { * -EIO: The firmware did not succeed in creatingthe protected context.
*/
#define I915_CONTEXT_PARAM_PROTECTED_CONTENT0xdinclude/uapi/drm/i915_drm.h +5
-0+ +/* +* I915_CONTEXT_PARAM_IS_COMPUTE: +* +* Mark this context as a Compute related workload which requires aggressive GT
+ * frequency scaling. QueryI915_PARAM_HAS_CONTEXT_COMPUTEto check if the
kernel
+ * supports this functionality.
+ */
+#define I915_CONTEXT_PARAM_IS_COMPUTE0xe
/* Must be kept compact -- no holes and well documented */ /** @value: Context parameter value to be set or queried */