[Nexus 4 Original Android Development] franciscofranco:
[MENTION=3332811]faux123[/MENTION]

Good job on the GPU governor, I tested it, works great and the device seems to be cooler since its not running on max GPU all the time anymore. Although I have a few code suggestions: instead of assigning val = X and then returning it in the end of the function you can return the val right away and bail the function, might save few us. The comments where you had them make it a bit hard to read the code so I re-arranged it a little bit. Also I think it would be appropriate to add a "Modified by Paul Reioux etc" on the file header instead of the Copyright notice that you had in the middle of the file, its more alike of the normal Kernel conventions and you still retain the change credit visile on top of the file. I also think you can make it enabled by default rather than having the users change it by themselves. I didn't commit anything on my repo yet, but here's the diff of my changes:

diff --git a/drivers/gpu/msm/kgsl_pwrscale_trustzone.c b/drivers/gpu/msm/kgsl_pwrscale_trustzone.c
index 158fd9b..d976cd4 100644
--- a/drivers/gpu/msm/kgsl_pwrscale_trustzone.c
+++ b/drivers/gpu/msm/kgsl_pwrscale_trustzone.c
@@ -8,6 +8,9 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
+ *
+ * Modified by Paul Reioux (Faux123)
+ * 2013-06-20: Added KGSL Simple GPU Governor
*
*/

@@ -140,8 +143,6 @@ static void tz_wake(struct kgsl_device *device, struct kgsl_pwrscale *pwrscale)
}

#ifdef CONFIG_MSM_KGSL_SIMPLE_GOV
-/* KGSL Simple GPU Governor */
-/* Copyright (c) 2011-2013, Paul Reioux (Faux123). All rights reserved. */
static int default_laziness = 5;
module_param_named(simple_laziness, default_laziness, int, 0664);

@@ -152,33 +153,42 @@ static int laziness;

static int simple_governor(struct kgsl_device *device, int idle_stat)
{
-	int val = 0;
struct kgsl_pwrctrl *pwr = &device->pwrctrl;

/* it's currently busy */
-	if (idle_stat < ramp_up_threshold) {
+	if (idle_stat < ramp_up_threshold)
+	{
if (pwr->active_pwrlevel == 0)
-	val = 0; /* already maxed, so do nothing */
+	/* already maxed, so do nothing */
+	return 0;
+
else if ((pwr->active_pwrlevel > 0) &&
(pwr->active_pwrlevel <= (pwr->num_pwrlevels - 1)))
-	val = -1; /* bump up to next pwrlevel */
+	/* bump up to next pwrlevel */
+	return -1;
+	}
/* idle case */
-	} else {
+	else
+	{
if ((pwr->active_pwrlevel >= 0) &&
(pwr->active_pwrlevel < (pwr->num_pwrlevels - 1)))
-	if (laziness > 0) {
-	/* hold off for a while */
-	laziness--;
-	val = 0; /* don't change anything yet */
-	} else {
-	val = 1; /* above min, lower it */
-	/* reset laziness count */
+	if (likely(--laziness > 0))
+	{
+	/* don't change anything yet hold off for a while */
+	return 0;
+	}
+	else
+	{
+	/* above min, lower it */
laziness = default_laziness;
+	return 1;
}
else if (pwr->active_pwrlevel == (pwr->num_pwrlevels - 1))
-	val = 0; /* already @ min, so do nothing */
+	/* already @ min, so do nothing */
+	return 0;
}
-	return val;
+
+	return 0;
}
#endif

@@ -264,7 +274,7 @@ static int tz_init(struct kgsl_device *device, struct kgsl_pwrscale *pwrscale)
if (pwrscale->priv == NULL)
return -ENOMEM;

-	priv->governor = TZ_GOVERNOR_ONDEMAND;
+	priv->governor = TZ_GOVERNOR_SIMPLE;
spin_lock_init(&tz_lock);
kgsl_pwrscale_policy_add_files(device, pwrscale, &tz_attr_group);