Skip to content

Commit 43c0e98

Browse files
author
Christoph Rudorff
committed
msm_gpu_devfreq: report average load
for fine tuning: /sys/kernel/debug/dri/0/devfreq/ Signed-off-by: Christoph Rudorff <chris@rudorff.com>
1 parent 3afa529 commit 43c0e98

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

drivers/gpu/drm/msm/msm_gpu.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ struct msm_gpu_devfreq {
122122
/** time: Time of last sampling period. */
123123
ktime_t time;
124124

125+
/** load avg **/
126+
unsigned long load;
127+
unsigned long load_avg;
128+
125129
/** suspended: tracks if we're suspended */
126130
bool suspended;
127131
};
@@ -214,6 +218,7 @@ struct msm_gpu {
214218
/* Hang and Inactivity Detection:
215219
*/
216220
#define DRM_MSM_INACTIVE_PERIOD 66 /* in ms (roughly four frames) */
221+
// #define DRM_MSM_INACTIVE_PERIOD 120
217222

218223
#define DRM_MSM_HANGCHECK_DEFAULT_PERIOD 500 /* in ms */
219224
#define DRM_MSM_HANGCHECK_PROGRESS_RETRIES 3

drivers/gpu/drm/msm/msm_gpu_devfreq.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ static int msm_devfreq_target(struct device *dev, unsigned long *freq,
2828
if (df->suspended)
2929
dev_err(dev, "%s while suspended ??\n", __func__);
3030

31+
dev_dbg(dev, "suggest: %lu\n", *freq);
32+
3133
unsigned long curr_freq = get_freq(gpu);
3234
if (*freq == curr_freq)
3335
return 0;
@@ -86,7 +88,7 @@ static int msm_devfreq_get_dev_status(struct device *dev,
8688
status->total_time = ktime_us_delta(time, df->time);
8789
df->time = time;
8890

89-
if (df->suspended) {
91+
if ((df->suspended) || (status->total_time == 0)) {
9092
mutex_unlock(&df->lock);
9193
status->busy_time = 0;
9294
return 0;
@@ -96,21 +98,34 @@ static int msm_devfreq_get_dev_status(struct device *dev,
9698
busy_time = busy_cycles - df->busy_cycles;
9799
df->busy_cycles = busy_cycles;
98100

99-
mutex_unlock(&df->lock);
100101

101102
busy_time *= USEC_PER_SEC;
102103
busy_time = div64_ul(busy_time, sample_rate);
103104
if (WARN_ON(busy_time > ~0LU))
104105
busy_time = ~0LU;
105106

106-
status->busy_time = busy_time;
107+
/*
108+
running avg:
109+
a=((a*2) + (p+c))/4; p=c; a
110+
load per mille:
111+
*/
112+
unsigned long load = busy_time*1000 / status->total_time;
113+
df->load_avg = ((df->load_avg * 2) + (df->load + load)) / 4;
114+
df->load = load;
115+
116+
status->busy_time = df->load_avg;
117+
status->total_time = 1000;
118+
119+
mutex_unlock(&df->lock);
120+
121+
// status->busy_time = busy_time;
107122

108123
dev_dbg(&gpu->pdev->dev,
109-
"busy %lu / total %lu = %lu | freq %lu MHz bscy: %llu | srate: %lu\n",
124+
"busy %lu / total %lu = %lu | freq %lu MHz load: %lu | srate: %lu\n",
110125
status->busy_time, status->total_time,
111-
status->busy_time / (status->total_time / 100),
126+
status->busy_time * 100 / status->total_time,
112127
status->current_frequency / 1000 / 1000,
113-
busy_cycles,
128+
load,
114129
sample_rate);
115130

116131

@@ -153,8 +168,8 @@ void msm_devfreq_init(struct msm_gpu *gpu)
153168
* where due to stalling waiting for vblank we could get stuck
154169
* at (for ex) 30fps at 50% utilization.
155170
*/
156-
priv->gpu_devfreq_config.upthreshold = 50;
157-
priv->gpu_devfreq_config.downdifferential = 10;
171+
priv->gpu_devfreq_config.upthreshold = 80;
172+
priv->gpu_devfreq_config.downdifferential = 20;
158173

159174
mutex_init(&df->lock);
160175

@@ -225,10 +240,10 @@ void msm_devfreq_suspend(struct msm_gpu *gpu)
225240
if (!has_devfreq(gpu))
226241
return;
227242

243+
devfreq_suspend_device(df->devfreq);
244+
228245
mutex_lock(&df->lock);
229246
df->suspended = true;
230247
mutex_unlock(&df->lock);
231-
232-
devfreq_suspend_device(df->devfreq);
233248
}
234249

0 commit comments

Comments
 (0)