Skip to content

Commit 4a82ceb

Browse files
vsbelgaumrodrigovivi
authored andcommitted
drm/i915/slpc: Add sysfs for SLPC power profiles
Default SLPC power profile is Base(0). Power Saving mode(1) has conservative up/down thresholds and is suitable for use with apps that typically need to be power efficient. Selected power profile will be displayed in this format- $ cat slpc_power_profile [base] power_saving $ echo power_saving > slpc_power_profile $ cat slpc_power_profile base [power_saving] v2: Disable waitboost in power saving profile, update sysfs format and add some kernel doc for SLPC (Rodrigo) v3: Update doc with info about power profiles (Rodrigo) v4: Checkpatch warning and remove extra line (Rodrigo) Cc: Sushma Venkatesh Reddy <sushma.venkatesh.reddy@intel.com> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250117215753.749906-1-vinay.belgaumkar@intel.com Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
1 parent 9069b78 commit 4a82ceb

File tree

6 files changed

+125
-0
lines changed

6 files changed

+125
-0
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,45 @@ static ssize_t slpc_ignore_eff_freq_store(struct kobject *kobj,
464464
return err ?: count;
465465
}
466466

467+
static ssize_t slpc_power_profile_show(struct kobject *kobj,
468+
struct kobj_attribute *attr,
469+
char *buff)
470+
{
471+
struct intel_gt *gt = intel_gt_sysfs_get_drvdata(kobj, attr->attr.name);
472+
struct intel_guc_slpc *slpc = &gt->uc.guc.slpc;
473+
474+
switch (slpc->power_profile) {
475+
case SLPC_POWER_PROFILES_BASE:
476+
return sysfs_emit(buff, "[%s] %s\n", "base", "power_saving");
477+
case SLPC_POWER_PROFILES_POWER_SAVING:
478+
return sysfs_emit(buff, "%s [%s]\n", "base", "power_saving");
479+
}
480+
481+
return sysfs_emit(buff, "%u\n", slpc->power_profile);
482+
}
483+
484+
static ssize_t slpc_power_profile_store(struct kobject *kobj,
485+
struct kobj_attribute *attr,
486+
const char *buff, size_t count)
487+
{
488+
struct intel_gt *gt = intel_gt_sysfs_get_drvdata(kobj, attr->attr.name);
489+
struct intel_guc_slpc *slpc = &gt->uc.guc.slpc;
490+
char power_saving[] = "power_saving";
491+
char base[] = "base";
492+
int err;
493+
u32 val;
494+
495+
if (!strncmp(buff, power_saving, sizeof(power_saving) - 1))
496+
val = SLPC_POWER_PROFILES_POWER_SAVING;
497+
else if (!strncmp(buff, base, sizeof(base) - 1))
498+
val = SLPC_POWER_PROFILES_BASE;
499+
else
500+
return -EINVAL;
501+
502+
err = intel_guc_slpc_set_power_profile(slpc, val);
503+
return err ?: count;
504+
}
505+
467506
struct intel_gt_bool_throttle_attr {
468507
struct attribute attr;
469508
ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
@@ -668,6 +707,7 @@ INTEL_GT_ATTR_RO(media_RP0_freq_mhz);
668707
INTEL_GT_ATTR_RO(media_RPn_freq_mhz);
669708

670709
INTEL_GT_ATTR_RW(slpc_ignore_eff_freq);
710+
INTEL_GT_ATTR_RW(slpc_power_profile);
671711

672712
static const struct attribute *media_perf_power_attrs[] = {
673713
&attr_media_freq_factor.attr,
@@ -864,6 +904,13 @@ void intel_gt_sysfs_pm_init(struct intel_gt *gt, struct kobject *kobj)
864904
gt_warn(gt, "failed to create ignore_eff_freq sysfs (%pe)", ERR_PTR(ret));
865905
}
866906

907+
if (intel_uc_uses_guc_slpc(&gt->uc)) {
908+
ret = sysfs_create_file(kobj, &attr_slpc_power_profile.attr);
909+
if (ret)
910+
gt_warn(gt, "failed to create slpc_power_profile sysfs (%pe)",
911+
ERR_PTR(ret));
912+
}
913+
867914
if (i915_mmio_reg_valid(intel_gt_perf_limit_reasons_reg(gt))) {
868915
ret = sysfs_create_files(kobj, throttle_reason_attrs);
869916
if (ret)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,10 @@ void intel_rps_boost(struct i915_request *rq)
10241024
if (rps_uses_slpc(rps)) {
10251025
slpc = rps_to_slpc(rps);
10261026

1027+
/* Waitboost should not be done with power saving profile */
1028+
if (slpc->power_profile == SLPC_POWER_PROFILES_POWER_SAVING)
1029+
return;
1030+
10271031
if (slpc->min_freq_softlimit >= slpc->boost_freq)
10281032
return;
10291033

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ struct slpc_optimized_strategies {
228228

229229
#define SLPC_OPTIMIZED_STRATEGY_COMPUTE REG_BIT(0)
230230

231+
enum slpc_power_profiles {
232+
SLPC_POWER_PROFILES_BASE = 0x0,
233+
SLPC_POWER_PROFILES_POWER_SAVING = 0x1
234+
};
235+
231236
/**
232237
* DOC: SLPC H2G MESSAGE FORMAT
233238
*

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,34 @@
1515
#include "gt/intel_gt_regs.h"
1616
#include "gt/intel_rps.h"
1717

18+
/**
19+
* DOC: SLPC - Dynamic Frequency management
20+
*
21+
* Single Loop Power Control (SLPC) is a GuC algorithm that manages
22+
* GT frequency based on busyness and how KMD initializes it. SLPC is
23+
* almost completely in control after initialization except for a few
24+
* scenarios mentioned below.
25+
*
26+
* KMD uses the concept of waitboost to ramp frequency to RP0 when there
27+
* are pending submissions for a context. It achieves this by sending GuC a
28+
* request to update the min frequency to RP0. Waitboost is disabled
29+
* when the request retires.
30+
*
31+
* Another form of frequency control happens through per-context hints.
32+
* A context can be marked as low latency during creation. That will ensure
33+
* that SLPC uses an aggressive frequency ramp when that context is active.
34+
*
35+
* Power profiles add another level of control to these mechanisms.
36+
* When power saving profile is chosen, SLPC will use conservative
37+
* thresholds to ramp frequency, thus saving power. KMD will disable
38+
* waitboosts as well, which achieves further power savings. Base profile
39+
* is default and ensures balanced performance for any workload.
40+
*
41+
* Lastly, users have some level of control through sysfs, where min/max
42+
* frequency values can be altered and the use of efficient freq
43+
* can be toggled.
44+
*/
45+
1846
static inline struct intel_guc *slpc_to_guc(struct intel_guc_slpc *slpc)
1947
{
2048
return container_of(slpc, struct intel_guc, slpc);
@@ -265,6 +293,8 @@ int intel_guc_slpc_init(struct intel_guc_slpc *slpc)
265293
slpc->num_boosts = 0;
266294
slpc->media_ratio_mode = SLPC_MEDIA_RATIO_MODE_DYNAMIC_CONTROL;
267295

296+
slpc->power_profile = SLPC_POWER_PROFILES_BASE;
297+
268298
mutex_init(&slpc->lock);
269299
INIT_WORK(&slpc->boost_work, slpc_boost_work);
270300

@@ -567,6 +597,34 @@ int intel_guc_slpc_set_media_ratio_mode(struct intel_guc_slpc *slpc, u32 val)
567597
return ret;
568598
}
569599

600+
int intel_guc_slpc_set_power_profile(struct intel_guc_slpc *slpc, u32 val)
601+
{
602+
struct drm_i915_private *i915 = slpc_to_i915(slpc);
603+
intel_wakeref_t wakeref;
604+
int ret = 0;
605+
606+
if (val > SLPC_POWER_PROFILES_POWER_SAVING)
607+
return -EINVAL;
608+
609+
mutex_lock(&slpc->lock);
610+
wakeref = intel_runtime_pm_get(&i915->runtime_pm);
611+
612+
ret = slpc_set_param(slpc,
613+
SLPC_PARAM_POWER_PROFILE,
614+
val);
615+
if (ret)
616+
guc_err(slpc_to_guc(slpc),
617+
"Failed to set power profile to %d: %pe\n",
618+
val, ERR_PTR(ret));
619+
else
620+
slpc->power_profile = val;
621+
622+
intel_runtime_pm_put(&i915->runtime_pm, wakeref);
623+
mutex_unlock(&slpc->lock);
624+
625+
return ret;
626+
}
627+
570628
void intel_guc_pm_intrmsk_enable(struct intel_gt *gt)
571629
{
572630
u32 pm_intrmsk_mbz = 0;
@@ -728,6 +786,13 @@ int intel_guc_slpc_enable(struct intel_guc_slpc *slpc)
728786
/* Enable SLPC Optimized Strategy for compute */
729787
intel_guc_slpc_set_strategy(slpc, SLPC_OPTIMIZED_STRATEGY_COMPUTE);
730788

789+
/* Set cached value of power_profile */
790+
ret = intel_guc_slpc_set_power_profile(slpc, slpc->power_profile);
791+
if (unlikely(ret)) {
792+
guc_probe_error(guc, "Failed to set SLPC power profile: %pe\n", ERR_PTR(ret));
793+
return ret;
794+
}
795+
731796
return 0;
732797
}
733798

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ 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);
4848
int intel_guc_slpc_set_strategy(struct intel_guc_slpc *slpc, u32 val);
49+
int intel_guc_slpc_set_power_profile(struct intel_guc_slpc *slpc, u32 val);
4950

5051
#endif

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ struct intel_guc_slpc {
3333
u32 max_freq_softlimit;
3434
bool ignore_eff_freq;
3535

36+
/* Base or power saving */
37+
u32 power_profile;
38+
3639
/* cached media ratio mode */
3740
u32 media_ratio_mode;
3841

0 commit comments

Comments
 (0)