Skip to content

Commit cec8281

Browse files
vsbelgaumjohnharr-intel
authored andcommitted
drm/i915/guc: Use context hints for GT frequency
Allow user to provide a low latency context hint. When set, KMD sends 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 SLPC Compute strategy during 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_CONTEXT_FREQ_HINT. This flag is true for all guc submission enabled platforms as they use SLPC for frequency management. The Mesa usage model for this flag is here - https://gitlab.freedesktop.org/sushmave/mesa/-/commits/compute_hint v2: Rename flags as per review suggestions (Rodrigo, Tvrtko). Also, use flag bits in intel_context as it allows finer control for toggling per engine if needed (Tvrtko). v3: Minor review comments (Tvrtko) v4: Update comment (Sushma) Cc: Rodrigo Vivi <[email protected]> Cc: Tvrtko Ursulin <[email protected]> Cc: Sushma Venkatesh Reddy <[email protected]> Reviewed-by: Rodrigo Vivi <[email protected]> Acked-by: Ivan Briano <[email protected]> Signed-off-by: Vinay Belgaumkar <[email protected]> Signed-off-by: John Harrison <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 7127128 commit cec8281

File tree

10 files changed

+86
-2
lines changed

10 files changed

+86
-2
lines changed

drivers/gpu/drm/i915/gem/i915_gem_context.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv,
879879
struct i915_gem_proto_context *pc,
880880
struct drm_i915_gem_context_param *args)
881881
{
882+
struct drm_i915_private *i915 = fpriv->i915;
882883
int ret = 0;
883884

884885
switch (args->param) {
@@ -904,6 +905,13 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv,
904905
pc->user_flags &= ~BIT(UCONTEXT_BANNABLE);
905906
break;
906907

908+
case I915_CONTEXT_PARAM_LOW_LATENCY:
909+
if (intel_uc_uses_guc_submission(&to_gt(i915)->uc))
910+
pc->user_flags |= BIT(UCONTEXT_LOW_LATENCY);
911+
else
912+
ret = -EINVAL;
913+
break;
914+
907915
case I915_CONTEXT_PARAM_RECOVERABLE:
908916
if (args->size)
909917
ret = -EINVAL;
@@ -992,6 +1000,9 @@ static int intel_context_set_gem(struct intel_context *ce,
9921000
if (sseu.slice_mask && !WARN_ON(ce->engine->class != RENDER_CLASS))
9931001
ret = intel_context_reconfigure_sseu(ce, sseu);
9941002

1003+
if (test_bit(UCONTEXT_LOW_LATENCY, &ctx->user_flags))
1004+
__set_bit(CONTEXT_LOW_LATENCY, &ce->flags);
1005+
9951006
return ret;
9961007
}
9971008

@@ -1630,6 +1641,9 @@ i915_gem_create_context(struct drm_i915_private *i915,
16301641
if (vm)
16311642
ctx->vm = vm;
16321643

1644+
/* Assign early so intel_context_set_gem can access these flags */
1645+
ctx->user_flags = pc->user_flags;
1646+
16331647
mutex_init(&ctx->engines_mutex);
16341648
if (pc->num_user_engines >= 0) {
16351649
i915_gem_context_set_user_engines(ctx);
@@ -1652,8 +1666,6 @@ i915_gem_create_context(struct drm_i915_private *i915,
16521666
* is no remap info, it will be a NOP. */
16531667
ctx->remap_slice = ALL_L3_SLICES(i915);
16541668

1655-
ctx->user_flags = pc->user_flags;
1656-
16571669
for (i = 0; i < ARRAY_SIZE(ctx->hang_timestamp); i++)
16581670
ctx->hang_timestamp[i] = jiffies - CONTEXT_FAST_HANG_JIFFIES;
16591671

drivers/gpu/drm/i915/gem/i915_gem_context_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ struct i915_gem_context {
338338
#define UCONTEXT_BANNABLE 2
339339
#define UCONTEXT_RECOVERABLE 3
340340
#define UCONTEXT_PERSISTENCE 4
341+
#define UCONTEXT_LOW_LATENCY 5
341342

342343
/**
343344
* @flags: small set of booleans

drivers/gpu/drm/i915/gt/intel_context_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ struct intel_context {
130130
#define CONTEXT_PERMA_PIN 11
131131
#define CONTEXT_IS_PARKING 12
132132
#define CONTEXT_EXITING 13
133+
#define CONTEXT_LOW_LATENCY 14
133134

134135
struct {
135136
u64 timeout_us;

drivers/gpu/drm/i915/gt/intel_rps.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,10 @@ void intel_rps_boost(struct i915_request *rq)
10131013
if (i915_request_signaled(rq) || i915_request_has_waitboost(rq))
10141014
return;
10151015

1016+
/* Waitboost is not needed for contexts marked with a Freq hint */
1017+
if (test_bit(CONTEXT_LOW_LATENCY, &rq->context->flags))
1018+
return;
1019+
10161020
/* Serializes with i915_request_retire() */
10171021
if (!test_and_set_bit(I915_FENCE_FLAG_BOOST, &rq->fence.flags)) {
10181022
struct intel_rps *rps = &READ_ONCE(rq->engine)->gt->rps;

drivers/gpu/drm/i915/gt/uc/abi/guc_actions_slpc_abi.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,27 @@ struct slpc_shared_data {
207207
u8 reserved_mode_definition[4096];
208208
} __packed;
209209

210+
struct slpc_context_frequency_request {
211+
u32 frequency_request:16;
212+
u32 reserved:12;
213+
u32 is_compute:1;
214+
u32 ignore_busyness:1;
215+
u32 is_minimum:1;
216+
u32 is_predefined:1;
217+
} __packed;
218+
219+
#define SLPC_CTX_FREQ_REQ_IS_COMPUTE REG_BIT(28)
220+
221+
struct slpc_optimized_strategies {
222+
u32 compute:1;
223+
u32 async_flip:1;
224+
u32 media:1;
225+
u32 vsync_flip:1;
226+
u32 reserved:28;
227+
} __packed;
228+
229+
#define SLPC_OPTIMIZED_STRATEGY_COMPUTE REG_BIT(0)
230+
210231
/**
211232
* DOC: SLPC H2G MESSAGE FORMAT
212233
*

drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,20 @@ int intel_guc_slpc_get_min_freq(struct intel_guc_slpc *slpc, u32 *val)
537537
return ret;
538538
}
539539

540+
int intel_guc_slpc_set_strategy(struct intel_guc_slpc *slpc, u32 val)
541+
{
542+
struct drm_i915_private *i915 = slpc_to_i915(slpc);
543+
intel_wakeref_t wakeref;
544+
int ret = 0;
545+
546+
with_intel_runtime_pm(&i915->runtime_pm, wakeref)
547+
ret = slpc_set_param(slpc,
548+
SLPC_PARAM_STRATEGIES,
549+
val);
550+
551+
return ret;
552+
}
553+
540554
int intel_guc_slpc_set_media_ratio_mode(struct intel_guc_slpc *slpc, u32 val)
541555
{
542556
struct drm_i915_private *i915 = slpc_to_i915(slpc);
@@ -711,6 +725,9 @@ int intel_guc_slpc_enable(struct intel_guc_slpc *slpc)
711725
/* Set cached media freq ratio mode */
712726
intel_guc_slpc_set_media_ratio_mode(slpc, slpc->media_ratio_mode);
713727

728+
/* Enable SLPC Optimized Strategy for compute */
729+
intel_guc_slpc_set_strategy(slpc, SLPC_OPTIMIZED_STRATEGY_COMPUTE);
730+
714731
return 0;
715732
}
716733

drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ void intel_guc_pm_intrmsk_enable(struct intel_gt *gt);
4545
void intel_guc_slpc_boost(struct intel_guc_slpc *slpc);
4646
void intel_guc_slpc_dec_waiters(struct intel_guc_slpc *slpc);
4747
int intel_guc_slpc_set_ignore_eff_freq(struct intel_guc_slpc *slpc, bool val);
48+
int intel_guc_slpc_set_strategy(struct intel_guc_slpc *slpc, u32 val);
4849

4950
#endif

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,6 +2645,7 @@ MAKE_CONTEXT_POLICY_ADD(execution_quantum, EXECUTION_QUANTUM)
26452645
MAKE_CONTEXT_POLICY_ADD(preemption_timeout, PREEMPTION_TIMEOUT)
26462646
MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY)
26472647
MAKE_CONTEXT_POLICY_ADD(preempt_to_idle, PREEMPT_TO_IDLE_ON_QUANTUM_EXPIRY)
2648+
MAKE_CONTEXT_POLICY_ADD(slpc_ctx_freq_req, SLPM_GT_FREQUENCY)
26482649

26492650
#undef MAKE_CONTEXT_POLICY_ADD
26502651

@@ -2664,6 +2665,7 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop)
26642665
struct context_policy policy;
26652666
u32 execution_quantum;
26662667
u32 preemption_timeout;
2668+
u32 slpc_ctx_freq_req = 0;
26672669
unsigned long flags;
26682670
int ret;
26692671

@@ -2675,11 +2677,15 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop)
26752677
execution_quantum = engine->props.timeslice_duration_ms * 1000;
26762678
preemption_timeout = engine->props.preempt_timeout_ms * 1000;
26772679

2680+
if (ce && (ce->flags & BIT(CONTEXT_LOW_LATENCY)))
2681+
slpc_ctx_freq_req |= SLPC_CTX_FREQ_REQ_IS_COMPUTE;
2682+
26782683
__guc_context_policy_start_klv(&policy, ce->guc_id.id);
26792684

26802685
__guc_context_policy_add_priority(&policy, ce->guc_state.prio);
26812686
__guc_context_policy_add_execution_quantum(&policy, execution_quantum);
26822687
__guc_context_policy_add_preemption_timeout(&policy, preemption_timeout);
2688+
__guc_context_policy_add_slpc_ctx_freq_req(&policy, slpc_ctx_freq_req);
26832689

26842690
if (engine->flags & I915_ENGINE_WANT_FORCED_PREEMPTION)
26852691
__guc_context_policy_add_preempt_to_idle(&policy, 1);

drivers/gpu/drm/i915/i915_getparam.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ int i915_getparam_ioctl(struct drm_device *dev, void *data,
155155
*/
156156
value = 1;
157157
break;
158+
case I915_PARAM_HAS_CONTEXT_FREQ_HINT:
159+
if (intel_uc_uses_guc_submission(&to_gt(i915)->uc))
160+
value = 1;
161+
else
162+
value = -EINVAL;
163+
break;
158164
case I915_PARAM_HAS_CONTEXT_ISOLATION:
159165
value = intel_engines_has_context_isolation(i915);
160166
break;

include/uapi/drm/i915_drm.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,12 @@ typedef struct drm_i915_irq_wait {
806806
*/
807807
#define I915_PARAM_PXP_STATUS 58
808808

809+
/*
810+
* Query if kernel allows marking a context to send a Freq hint to SLPC. This
811+
* will enable use of the strategies allowed by the SLPC algorithm.
812+
*/
813+
#define I915_PARAM_HAS_CONTEXT_FREQ_HINT 59
814+
809815
/* Must be kept compact -- no holes and well documented */
810816

811817
/**
@@ -2148,6 +2154,15 @@ struct drm_i915_gem_context_param {
21482154
* -EIO: The firmware did not succeed in creating the protected context.
21492155
*/
21502156
#define I915_CONTEXT_PARAM_PROTECTED_CONTENT 0xd
2157+
2158+
/*
2159+
* I915_CONTEXT_PARAM_LOW_LATENCY:
2160+
*
2161+
* Mark this context as a low latency workload which requires aggressive GT
2162+
* frequency scaling. Use I915_PARAM_HAS_CONTEXT_FREQ_HINT to check if the kernel
2163+
* supports this per context flag.
2164+
*/
2165+
#define I915_CONTEXT_PARAM_LOW_LATENCY 0xe
21512166
/* Must be kept compact -- no holes and well documented */
21522167

21532168
/** @value: Context parameter value to be set or queried */

0 commit comments

Comments
 (0)