From b5c31a23ca94f21c701680acba10528254523244 Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Thu, 20 Oct 2016 17:21:16 +0530 Subject: gpu: nvgpu: move freq clipping to target function We right now obtain pm_qos frequency requirments in qos notifier callback gk20a_scale_qos_notify() But now we want to limit GPU frequencies based on frequency limited from devfreq nodes And devfreq requirement should precede over qos requirements Hence, move all frequency estimation and clipping to function gk20a_scale_target() which sets the frequency at the end Bug 200245796 Change-Id: I0572c676dce0acc0917924a11e4c0fb4a9db4e6e Signed-off-by: Deepak Nibade Reviewed-on: http://git-master/r/1243427 (cherry picked from commit 81c757a3232463d126aecba64ca0c55d8e4423d2) Reviewed-on: http://git-master/r/1239936 Reviewed-by: Aaron Huang Tested-by: Aaron Huang Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/gk20a/gk20a.h | 2 - drivers/gpu/nvgpu/gk20a/gk20a_scale.c | 77 ++++++++++++++++++++++++++--------- drivers/gpu/nvgpu/gk20a/gk20a_scale.h | 2 + 3 files changed, 60 insertions(+), 21 deletions(-) (limited to 'drivers/gpu') diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.h b/drivers/gpu/nvgpu/gk20a/gk20a.h index 07752d66..ffddebe7 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/gk20a.h @@ -936,8 +936,6 @@ struct gk20a { wait_queue_head_t sw_irq_nonstall_last_handled_wq; struct devfreq *devfreq; - u32 devfreq_max_freq; - u32 devfreq_min_freq; struct gk20a_scale_profile *scale_profile; diff --git a/drivers/gpu/nvgpu/gk20a/gk20a_scale.c b/drivers/gpu/nvgpu/gk20a/gk20a_scale.c index ac28d967..d2229a6a 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a_scale.c +++ b/drivers/gpu/nvgpu/gk20a/gk20a_scale.c @@ -50,28 +50,25 @@ int gk20a_scale_qos_notify(struct notifier_block *nb, qos_notify_block); struct gk20a *g = get_gk20a(profile->dev); struct devfreq *devfreq = g->devfreq; - s32 min_qos_freq, max_qos_freq; if (!devfreq) return NOTIFY_OK; - /* check for pm_qos min and max frequency requirement */ - min_qos_freq = pm_qos_read_min_bound(PM_QOS_GPU_FREQ_BOUNDS) * 1000; - max_qos_freq = pm_qos_read_max_bound(PM_QOS_GPU_FREQ_BOUNDS) * 1000; - mutex_lock(&devfreq->lock); + /* check for pm_qos min and max frequency requirement */ + profile->qos_min_freq = + pm_qos_read_min_bound(PM_QOS_GPU_FREQ_BOUNDS) * 1000; + profile->qos_max_freq = + pm_qos_read_max_bound(PM_QOS_GPU_FREQ_BOUNDS) * 1000; + + if (profile->qos_min_freq > profile->qos_max_freq) { + gk20a_err(g->dev, + "QoS: setting invalid limit, min_freq=%lu max_freq=%lu\n", + profile->qos_min_freq, profile->qos_max_freq); + profile->qos_min_freq = profile->qos_max_freq; + } - devfreq->min_freq = max_t(u32, g->devfreq_min_freq, min_qos_freq); - devfreq->max_freq = min_t(u32, g->devfreq_max_freq, max_qos_freq); - - WARN_ON(devfreq->min_freq > devfreq->max_freq); - - /* - * update_devfreq() will adjust the current (or newly estimated) - * frequency based on devfreq->min_freq/max_freq - */ update_devfreq(devfreq); - mutex_unlock(&devfreq->lock); return NOTIFY_OK; @@ -143,8 +140,49 @@ static int gk20a_scale_target(struct device *dev, unsigned long *freq, u32 flags) { struct gk20a_platform *platform = dev_get_drvdata(dev); - unsigned long rounded_rate = - platform->clk_round_rate(dev, *freq); + struct gk20a *g = platform->g; + struct gk20a_scale_profile *profile = g->scale_profile; + struct devfreq *devfreq = g->devfreq; + unsigned long local_freq = *freq; + unsigned long rounded_rate; + unsigned long min_freq = 0, max_freq = 0; + + /* + * Calculate floor and cap frequency values + * + * Policy : + * We have two APIs to clip the frequency + * 1. devfreq + * 2. pm_qos + * + * To calculate floor (min) freq, we select MAX of floor frequencies + * requested from both APIs + * To get cap (max) freq, we select MIN of max frequencies + * + * In case we have conflict (min_freq > max_freq) after above + * steps, we ensure that devfreq->min_freq wins over + * qos_max_freq + */ + min_freq = max_t(u32, devfreq->min_freq, profile->qos_min_freq); + max_freq = min_t(u32, devfreq->max_freq, profile->qos_max_freq); + + if (min_freq > max_freq) { + if (min_freq == devfreq->min_freq && + max_freq != devfreq->max_freq) { + max_freq = min_t(u32, min_freq, devfreq->max_freq); + } + min_freq = max_freq; + } + + /* Clip requested frequency */ + if (local_freq < min_freq) + local_freq = min_freq; + + if (local_freq > max_freq) + local_freq = max_freq; + + /* set the final frequency */ + rounded_rate = platform->clk_round_rate(dev, local_freq); if (platform->clk_get_rate(dev) == rounded_rate) *freq = rounded_rate; @@ -332,6 +370,9 @@ void gk20a_scale_init(struct device *dev) if (err || !profile->devfreq_profile.max_state) goto err_get_freqs; + profile->qos_min_freq = 0; + profile->qos_max_freq = UINT_MAX; + /* Store device profile so we can access it if devfreq governor * init needs that */ g->scale_profile = profile; @@ -354,8 +395,6 @@ void gk20a_scale_init(struct device *dev) devfreq = NULL; g->devfreq = devfreq; - g->devfreq_max_freq = devfreq->max_freq; - g->devfreq_min_freq = devfreq->min_freq; } /* Should we register QoS callback for this device? */ diff --git a/drivers/gpu/nvgpu/gk20a/gk20a_scale.h b/drivers/gpu/nvgpu/gk20a/gk20a_scale.h index 025c2070..c1e6fe86 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a_scale.h +++ b/drivers/gpu/nvgpu/gk20a/gk20a_scale.h @@ -29,6 +29,8 @@ struct gk20a_scale_profile { struct devfreq_dev_profile devfreq_profile; struct devfreq_dev_status dev_stat; struct notifier_block qos_notify_block; + unsigned long qos_min_freq; + unsigned long qos_max_freq; void *private_data; }; -- cgit v1.2.2