Skip to content

Commit c52c35e

Browse files
committed
accel/ivpu: Return max freq for DRM_IVPU_PARAM_CORE_CLOCK_RATE
DRM_IVPU_PARAM_CORE_CLOCK_RATE returns current NPU frequency which could be 0 if device was sleeping. This value isn't really useful to the user space, so return max freq instead which can be used to estimate NPU performance. Fixes: c39dc15 ("accel/ivpu: Read clock rate only if device is up") Cc: <[email protected]> # v6.7 Signed-off-by: Jacek Lawrynowicz <[email protected]> Reviewed-by: Jeffrey Hugo <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 3556f92 commit c52c35e

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

drivers/accel/ivpu/ivpu_drv.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,6 @@ static int ivpu_get_capabilities(struct ivpu_device *vdev, struct drm_ivpu_param
131131
return 0;
132132
}
133133

134-
static int ivpu_get_core_clock_rate(struct ivpu_device *vdev, u64 *clk_rate)
135-
{
136-
int ret;
137-
138-
ret = ivpu_rpm_get_if_active(vdev);
139-
if (ret < 0)
140-
return ret;
141-
142-
*clk_rate = ret ? ivpu_hw_reg_pll_freq_get(vdev) : 0;
143-
144-
if (ret)
145-
ivpu_rpm_put(vdev);
146-
147-
return 0;
148-
}
149-
150134
static int ivpu_get_param_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
151135
{
152136
struct ivpu_file_priv *file_priv = file->driver_priv;
@@ -170,7 +154,7 @@ static int ivpu_get_param_ioctl(struct drm_device *dev, void *data, struct drm_f
170154
args->value = vdev->platform;
171155
break;
172156
case DRM_IVPU_PARAM_CORE_CLOCK_RATE:
173-
ret = ivpu_get_core_clock_rate(vdev, &args->value);
157+
args->value = ivpu_hw_ratio_to_freq(vdev, vdev->hw->pll.max_ratio);
174158
break;
175159
case DRM_IVPU_PARAM_NUM_CONTEXTS:
176160
args->value = ivpu_get_context_count(vdev);

drivers/accel/ivpu/ivpu_hw.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct ivpu_hw_ops {
2121
u32 (*profiling_freq_get)(struct ivpu_device *vdev);
2222
void (*profiling_freq_drive)(struct ivpu_device *vdev, bool enable);
2323
u32 (*reg_pll_freq_get)(struct ivpu_device *vdev);
24+
u32 (*ratio_to_freq)(struct ivpu_device *vdev, u32 ratio);
2425
u32 (*reg_telemetry_offset_get)(struct ivpu_device *vdev);
2526
u32 (*reg_telemetry_size_get)(struct ivpu_device *vdev);
2627
u32 (*reg_telemetry_enable_get)(struct ivpu_device *vdev);
@@ -130,6 +131,11 @@ static inline u32 ivpu_hw_reg_pll_freq_get(struct ivpu_device *vdev)
130131
return vdev->hw->ops->reg_pll_freq_get(vdev);
131132
};
132133

134+
static inline u32 ivpu_hw_ratio_to_freq(struct ivpu_device *vdev, u32 ratio)
135+
{
136+
return vdev->hw->ops->ratio_to_freq(vdev, ratio);
137+
}
138+
133139
static inline u32 ivpu_hw_reg_telemetry_offset_get(struct ivpu_device *vdev)
134140
{
135141
return vdev->hw->ops->reg_telemetry_offset_get(vdev);

drivers/accel/ivpu/ivpu_hw_37xx.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,12 +803,12 @@ static void ivpu_hw_37xx_profiling_freq_drive(struct ivpu_device *vdev, bool ena
803803
/* Profiling freq - is a debug feature. Unavailable on VPU 37XX. */
804804
}
805805

806-
static u32 ivpu_hw_37xx_pll_to_freq(u32 ratio, u32 config)
806+
static u32 ivpu_hw_37xx_ratio_to_freq(struct ivpu_device *vdev, u32 ratio)
807807
{
808808
u32 pll_clock = PLL_REF_CLK_FREQ * ratio;
809809
u32 cpu_clock;
810810

811-
if ((config & 0xff) == PLL_RATIO_4_3)
811+
if ((vdev->hw->config & 0xff) == PLL_RATIO_4_3)
812812
cpu_clock = pll_clock * 2 / 4;
813813
else
814814
cpu_clock = pll_clock * 2 / 5;
@@ -827,7 +827,7 @@ static u32 ivpu_hw_37xx_reg_pll_freq_get(struct ivpu_device *vdev)
827827
if (!ivpu_is_silicon(vdev))
828828
return PLL_SIMULATION_FREQ;
829829

830-
return ivpu_hw_37xx_pll_to_freq(pll_curr_ratio, vdev->hw->config);
830+
return ivpu_hw_37xx_ratio_to_freq(vdev, pll_curr_ratio);
831831
}
832832

833833
static u32 ivpu_hw_37xx_reg_telemetry_offset_get(struct ivpu_device *vdev)
@@ -1050,6 +1050,7 @@ const struct ivpu_hw_ops ivpu_hw_37xx_ops = {
10501050
.profiling_freq_get = ivpu_hw_37xx_profiling_freq_get,
10511051
.profiling_freq_drive = ivpu_hw_37xx_profiling_freq_drive,
10521052
.reg_pll_freq_get = ivpu_hw_37xx_reg_pll_freq_get,
1053+
.ratio_to_freq = ivpu_hw_37xx_ratio_to_freq,
10531054
.reg_telemetry_offset_get = ivpu_hw_37xx_reg_telemetry_offset_get,
10541055
.reg_telemetry_size_get = ivpu_hw_37xx_reg_telemetry_size_get,
10551056
.reg_telemetry_enable_get = ivpu_hw_37xx_reg_telemetry_enable_get,

drivers/accel/ivpu/ivpu_hw_40xx.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,11 @@ static u32 ivpu_hw_40xx_reg_pll_freq_get(struct ivpu_device *vdev)
980980
return PLL_RATIO_TO_FREQ(pll_curr_ratio);
981981
}
982982

983+
static u32 ivpu_hw_40xx_ratio_to_freq(struct ivpu_device *vdev, u32 ratio)
984+
{
985+
return PLL_RATIO_TO_FREQ(ratio);
986+
}
987+
983988
static u32 ivpu_hw_40xx_reg_telemetry_offset_get(struct ivpu_device *vdev)
984989
{
985990
return REGB_RD32(VPU_40XX_BUTTRESS_VPU_TELEMETRY_OFFSET);
@@ -1230,6 +1235,7 @@ const struct ivpu_hw_ops ivpu_hw_40xx_ops = {
12301235
.profiling_freq_get = ivpu_hw_40xx_profiling_freq_get,
12311236
.profiling_freq_drive = ivpu_hw_40xx_profiling_freq_drive,
12321237
.reg_pll_freq_get = ivpu_hw_40xx_reg_pll_freq_get,
1238+
.ratio_to_freq = ivpu_hw_40xx_ratio_to_freq,
12331239
.reg_telemetry_offset_get = ivpu_hw_40xx_reg_telemetry_offset_get,
12341240
.reg_telemetry_size_get = ivpu_hw_40xx_reg_telemetry_size_get,
12351241
.reg_telemetry_enable_get = ivpu_hw_40xx_reg_telemetry_enable_get,

0 commit comments

Comments
 (0)