Skip to contentSkip to conversation

Janitor series 2: cleanups

PATCH Superseded Nishanth Menon 2 participants 12 messages Jun 25, 2010 – Jul 9, 2010

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Janitor series 2: cleanups

More misc cleanups for Sr branch including print cleans, checks etc. This series probably should be squashed with other patches in pm-sr branch. note some of these patches address few other comments I had made in an unrelated patch.

Related comments prior to providing patches:

a) I looked close into sr_device.c, I dont think we should decide in sr_device.c if SR is enabled by default or not. IMHO, this should be passed on from board files. it is not the sr_device's call to make. we have boards which are comfortable with SR and which are not. example some boards may choose to enable SR late in the game, while some may choose to enable it by default. we need to cater to both.

e.g. currently 3430 es3.1 would have SR enabled by default. N900 as an example chooses to allow users to decide what to have and is enabled late in the game (boots up disabled, gets enabled once userspace starts).

b) It assumes that 3630 have ntargets - this is true from ES1.1 onwards. the older silicon dont have ntargets fused in them.

How do we want to handle these?

This is the second series independent of series 1:
http://marc.info/?l=linux-omap&m=127741497415352&w=2

Nishanth Menon (7):
omap3: voltage: cleanup pr_xxxx
omap3: sr: cleanup pr_xxx
omap3: sr: enable/disable sr only if required
omap3: sr: device: cleanup pr_xxx
omap3: sr: device: add unlikely checks
omap3: sr: device: check for dev_attr
omap3: sr: device: fail sr_dev_init should return error

 arch/arm/mach-omap2/smartreflex.c |   24 ++++++++++++++++++------
 arch/arm/mach-omap2/sr_device.c   |   29 +++++++++++++++++++----------
 arch/arm/mach-omap2/voltage.c     |    7 ++++---
 3 files changed, 41 insertions(+), 19 deletions(-)

Regards,
Nishanth Menon

Cc Kevin Hilman <[email protected]>
Cc Thara Gopinath <[email protected]>
#1 lore raw

PATCH 1/7 omap3: voltage: cleanup pr_xxxx

few more pr_xxxx need cleanup for printing the function name and not using multiline prints when c allows us to do "".

Cc Kevin Hilman <[email protected]>
Cc Thara Gopinath <[email protected]>
---
 arch/arm/mach-omap2/voltage.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/arm/mach-omap2/voltage.c +4 -3
index d289691..963b037 100644
@@ -253,8 +253,9 @@ static int vp_debug_set(void *data, u64 val)
 		u32 *option = data;
 		*option = val;
 	} else {
-		pr_notice("DEBUG option not enabled!\n	\
-			echo 1 > pm_debug/enable_sr_vp_debug - to enable\n");
+		pr_notice("%s: DEBUG option not enabled! "
+			"echo 1 > pm_debug/enable_sr_vp_debug - to enable\n",
+			__func__);
 	}
 	return 0;
 }
@@ -265,7 +266,7 @@ static int vp_volt_debug_get(void *data, u64 *val)
 	u8 vsel;
 
 	vsel = voltage_read_reg(info->vp_offs.voltage_reg);
-	pr_notice("curr_vsel = %x\n", vsel);
+	pr_notice("%s: curr_vsel = %x\n", __func__, vsel);
 	*val = vsel * 12500 + 600000;
 
 	return 0;
Signature · 1 line
1.6.3.3
#2 lore raw

PATCH 2/7 omap3: sr: cleanup pr_xxx

In reply to Nishanth Menon

pr_xxx family is not informative for debug unless one decides to grep the code, instead print the function to help debug easier on the field.

Cc Kevin Hilman <[email protected]>
Cc Thara Gopinath <[email protected]>
---
 arch/arm/mach-omap2/smartreflex.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/smartreflex.c +3 -2
index 57fc9b2..d63691b 100644
@@ -804,8 +804,9 @@ static int omap_sr_params_store(void *data, u64 val)
 		u32 *option = data;
 		*option = val;
 	} else {
-		pr_notice("DEBUG option not enabled!\n	\
-			echo 1 > pm_debug/enable_sr_vp_debug - to enable\n");
+		pr_notice("%s: DEBUG option not enabled! "
+			"echo 1 > pm_debug/enable_sr_vp_debug to enable\n",
+			__func__);
 	}
 	return 0;
 }
Signature · 1 line
1.6.3.3
#3 lore raw

PATCH 3/7 omap3: sr: enable/disable sr only if required

In reply to Nishanth Menon

we dont need to go down the path of enabling/disabling the SR if we dont need to. do some sanity check and trigger if needed

Cc Kevin Hilman <[email protected]>
Cc Thara Gopinath <[email protected]>
---
 arch/arm/mach-omap2/smartreflex.c |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)
arch/arm/mach-omap2/smartreflex.c +15 -4
index d63691b..9b5a10e 100644
@@ -778,15 +778,26 @@ static int omap_sr_autocomp_show(void *data, u64 *val)
 static int omap_sr_autocomp_store(void *data, u64 val)
 {
 	struct omap_sr *sr_info = (struct omap_sr *) data;
+	u32 value = (u32) val;
 
 	if (!sr_info) {
 		pr_warning("%s: omap_sr struct for SR not found\n", __func__);
 		return -EINVAL;
 	}
-	if (!val)
-		sr_stop_vddautocomp(sr_info);
-	else
-		sr_start_vddautocomp(sr_info);
+
+	/* Sanity check */
+	if (value && (value != 1)) {
+		pr_err("%s: invalid value %d\n", __func__, value);
+		return -EINVAL;
+	}
+
+	/* change only if needed */
+	if (sr_info->is_autocomp_active ^ value) {
+		if (!val)
+			sr_stop_vddautocomp(sr_info);
+		else
+			sr_start_vddautocomp(sr_info);
+	}
 	return 0;
 }
 
Signature · 1 line
1.6.3.3
#4 lore raw

PATCH 4/7 omap3: sr: device: cleanup pr_xxx

In reply to Nishanth Menon

strings in c dont need to be split accross multiple lines with \
. instead they can be put as "abc " "def " and it is equivalent to "abc def". fix the same

Cc Kevin Hilman <[email protected]>
Cc Thara Gopinath <[email protected]>
---
 arch/arm/mach-omap2/sr_device.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/sr_device.c +3 -2
index dbf7603..7d13704 100644
@@ -151,8 +151,9 @@ static int sr_dev_init(struct omap_hwmod *oh, void *user)
 	sr_dev_data->volts_supported = omap_get_voltage_table(i,
 				&sr_dev_data->volt_data);
 	if (!sr_dev_data->volts_supported) {
-		pr_warning("%s: No Voltage table registerd fo VDD%d.Something \
-				really wrong\n\n", __func__, i + 1);
+		pr_warning("%s: No Voltage table registerd fo VDD%d. "
+				"Something is really wrong\n",
+				__func__, i + 1);
 		i++;
 		kfree(sr_data);
 		return 0;
Signature · 1 line
1.6.3.3
#5 lore raw

PATCH 5/7 omap3: sr: device: add unlikely checks

In reply to Nishanth Menon

Add unlikely checks to better optimize the rare occurrance of erroneous conditions.

Cc Kevin Hilman <[email protected]>
Cc Thara Gopinath <[email protected]>
---
 arch/arm/mach-omap2/sr_device.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)
arch/arm/mach-omap2/sr_device.c +8 -7
index 7d13704..177299a 100644
@@ -43,8 +43,9 @@ static void __init sr_read_efuse(struct omap_sr_dev_data *dev_data,
 {
 	int i;
 
-	if (!dev_data || !dev_data->volts_supported || !dev_data->volt_data ||
-			!dev_data->efuse_nvalues_offs) {
+	if (unlikely(!dev_data || !dev_data->volts_supported ||
+			!dev_data->volt_data ||
+			!dev_data->efuse_nvalues_offs)) {
 		pr_warning("%s: Bad parameters! dev_data = %x,"
 			"dev_data->volts_supported = %x,"
 			"dev_data->volt_data = %x,"
@@ -87,8 +88,8 @@ static void __init sr_set_testing_nvalues(struct omap_sr_dev_data *dev_data,
 {
 	int i;
 
-	if (!dev_data || !dev_data->volts_supported ||
-			!dev_data->volt_data || !dev_data->test_nvalues) {
+	if (unlikely(!dev_data || !dev_data->volts_supported ||
+			!dev_data->volt_data || !dev_data->test_nvalues)) {
 		pr_warning("%s: Bad parameters! dev_data = %x,"
 			"dev_data->volts_supported = %x,"
 			"dev_data->volt_data = %x,"
@@ -123,7 +124,7 @@ static int sr_dev_init(struct omap_hwmod *oh, void *user)
 	static int i;
 
 	sr_data = kzalloc(sizeof(struct omap_sr_data), GFP_KERNEL);
-	if (!sr_data) {
+	if (unlikely(!sr_data)) {
 		pr_err("%s: Unable to allocate memory for %s sr_data.Error!\n",
 			__func__, oh->name);
 		return -ENOMEM;
@@ -150,7 +151,7 @@ static int sr_dev_init(struct omap_hwmod *oh, void *user)
 	sr_data->device_idle = omap_device_idle;
 	sr_dev_data->volts_supported = omap_get_voltage_table(i,
 				&sr_dev_data->volt_data);
-	if (!sr_dev_data->volts_supported) {
+	if (unlikely(!sr_dev_data->volts_supported)) {
 		pr_warning("%s: No Voltage table registerd fo VDD%d. "
 				"Something is really wrong\n",
 				__func__, i + 1);
@@ -162,7 +163,7 @@ static int sr_dev_init(struct omap_hwmod *oh, void *user)
 	od = omap_device_build(name, i, oh, sr_data, sizeof(*sr_data),
 			       omap_sr_latency,
 			       ARRAY_SIZE(omap_sr_latency), 0);
-	if (IS_ERR(od)) {
+	if (unlikely(IS_ERR(od))) {
 		pr_warning("%s: Could not build omap_device for %s: %s.\n\n",
 			__func__, name, oh->name);
 		kfree(sr_data);
Signature · 1 line
1.6.3.3
#6 lore raw

Re: [PM-SR] [PATCH 5/7] omap3: sr: device: add unlikely checks

Quoted 7 lines · Nishanth Menon

Add unlikely checks to better optimize the rare occurrance of erroneous conditions.

Cc Kevin Hilman <[email protected]>
Cc Thara Gopinath <[email protected]>

unlikely and friends make sens only in realy hot path places. In other places like you touch, they are pointless - better let gcc make a choice of how to arrange code. And they only make the code less readable by adding extra braces and making ifs longer.

Thus, NACK for this from my side.

Signature · 7 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw

Re: [PM-SR] [PATCH 5/7] omap3: sr: device: add unlikely checks

Artem Bityutskiy had written, on 07/09/2010 08:12 AM, the following:

Quoted 23 lines · Nishanth Menon
Quoted 7 lines

Add unlikely checks to better optimize the rare occurrance of erroneous conditions.

Cc Kevin Hilman <[email protected]>
Cc Thara Gopinath <[email protected]>

unlikely and friends make sens only in realy hot path places. In other places like you touch, they are pointless - better let gcc make a choice

arch/arm/mach-omap2/sr_device.c +3 -2
@@ -43,8 +43,9 @@ static void __init sr_read_efuse(struct omap_sr_dev_data *dev_data,
 {
 	int i;
 
-	if (!dev_data || !dev_data->volts_supported || !dev_data->volt_data ||
-			!dev_data->efuse_nvalues_offs) {
+	if (unlikely(!dev_data || !dev_data->volts_supported ||
+			!dev_data->volt_data ||
+			!dev_data->efuse_nvalues_offs)) {
 

arch/arm/mach-omap2/sr_device.c static void __init sr_set_testing_nvalues(struct omap_sr_dev_data *dev_data, · line 92

Quoted 7 lines
arch/arm/mach-omap2/sr_device.c +2 -2
@@ -87,8 +88,8 @@ static void __init sr_set_testing_nvalues(struct omap_sr_dev_data *dev_data,
 {
 	int i;
 
-	if (!dev_data || !dev_data->volts_supported ||
-			!dev_data->volt_data || !dev_data->test_nvalues) {
+	if (unlikely(!dev_data || !dev_data->volts_supported ||
+			!dev_data->volt_data || !dev_data->test_nvalues)) {

and other places, why do you think that these are checks that should be expected? - would be great if you can explain inline to the patch which unlikely checks dont make sense.

static functions such as these are helpers for the maincode, unless something horribly wrong occurs within the codepath calling these helpers, they are not expected to be invalid parameters. hence the rationale for adding unlikely.

Quoted 5 lines

of how to arrange code. And they only make the code less readable by adding extra braces and making ifs longer.

Thus, NACK for this from my side.

Signature · 2 lines
Regards,
Nishanth Menon
#8 lore raw

Re: [PM-SR] [PATCH 5/7] omap3: sr: device: add unlikely checks

Quoted 36 lines · Nishanth Menon

Artem Bityutskiy had written, on 07/09/2010 08:12 AM, the following:

Quoted 23 lines · Nishanth Menon
Quoted 7 lines

Add unlikely checks to better optimize the rare occurrance of erroneous conditions.

Cc Kevin Hilman <[email protected]>
Cc Thara Gopinath <[email protected]>

unlikely and friends make sens only in realy hot path places. In other places like you touch, they are pointless - better let gcc make a choice

arch/arm/mach-omap2/sr_device.c +3 -2
@@ -43,8 +43,9 @@ static void __init sr_read_efuse(struct omap_sr_dev_data *dev_data,
 {
 	int i;
 
-	if (!dev_data || !dev_data->volts_supported || !dev_data->volt_data ||
-			!dev_data->efuse_nvalues_offs) {
+	if (unlikely(!dev_data || !dev_data->volts_supported ||
+			!dev_data->volt_data ||
+			!dev_data->efuse_nvalues_offs)) {
 

arch/arm/mach-omap2/sr_device.c static void __init sr_set_testing_nvalues(struct omap_sr_dev_data *dev_data, · line 92

Quoted 7 lines
arch/arm/mach-omap2/sr_device.c +2 -2
@@ -87,8 +88,8 @@ static void __init sr_set_testing_nvalues(struct omap_sr_dev_data *dev_data,
 {
 	int i;
 
-	if (!dev_data || !dev_data->volts_supported ||
-			!dev_data->volt_data || !dev_data->test_nvalues) {
+	if (unlikely(!dev_data || !dev_data->volts_supported ||
+			!dev_data->volt_data || !dev_data->test_nvalues)) {

and other places, why do you think that these are checks that should be expected? - would be great if you can explain inline to the patch which unlikely checks dont make sense.

Quoted 4 lines

static functions such as these are helpers for the maincode, unless something horribly wrong occurs within the codepath calling these helpers, they are not expected to be invalid parameters. hence the rationale for adding unlikely.

Sorry, I do not really understand you. All I said is that unlikely()/likely() are usually used in hot-paths / tight loops.

unlikely()/likely() are micro optimization. They make no difference when you use them in initialization paths.

So what I said, that in your patch they will make no difference performance wise. So no benefits.

But they make if () statements a bit more difficult to read, this is a drawback.

So your patch introduces no benefits, just a drawback. Thus, it is not good.

There were many flamewars about unlikely and likely in lkml in the past. And the outcome was always - do not use them anywhere except of performance-critical tight loops / hot paths.

Signature · 7 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#9 lore raw

Re: [PM-SR] [PATCH 5/7] omap3: sr: device: add unlikely checks

Artem Bityutskiy had written, on 07/09/2010 09:15 AM, the following:

Quoted 45 lines · Nishanth Menon
Quoted 24 lines

Artem Bityutskiy had written, on 07/09/2010 08:12 AM, the following:

Quoted 23 lines · Nishanth Menon
Quoted 7 lines

Add unlikely checks to better optimize the rare occurrance of erroneous conditions.

Cc Kevin Hilman <[email protected]>
Cc Thara Gopinath <[email protected]>

unlikely and friends make sens only in realy hot path places. In other places like you touch, they are pointless - better let gcc make a choice

arch/arm/mach-omap2/sr_device.c +3 -2
@@ -43,8 +43,9 @@ static void __init sr_read_efuse(struct omap_sr_dev_data *dev_data,
 {
 	int i;
 
-	if (!dev_data || !dev_data->volts_supported || !dev_data->volt_data ||
-			!dev_data->efuse_nvalues_offs) {
+	if (unlikely(!dev_data || !dev_data->volts_supported ||
+			!dev_data->volt_data ||
+			!dev_data->efuse_nvalues_offs)) {
@@ -87,8 +88,8 @@ static void __init sr_set_testing_nvalues(struct omap_sr_dev_data *dev_data,
 {
 	int i;
 
Quoted 7 lines

arch/arm/mach-omap2/sr_device.c static void __init sr_set_testing_nvalues(struct omap_sr_dev_data *dev_data, · line 92

Quoted 4 lines
arch/arm/mach-omap2/sr_device.c +2 -2
-	if (!dev_data || !dev_data->volts_supported ||
-			!dev_data->volt_data || !dev_data->test_nvalues) {
+	if (unlikely(!dev_data || !dev_data->volts_supported ||
+			!dev_data->volt_data || !dev_data->test_nvalues)) {

and other places, why do you think that these are checks that should be expected? - would be great if you can explain inline to the patch which unlikely checks dont make sense.

static functions such as these are helpers for the maincode, unless something horribly wrong occurs within the codepath calling these helpers, they are not expected to be invalid parameters. hence the rationale for adding unlikely.

Sorry, I do not really understand you. All I said is that unlikely()/likely() are usually used in hot-paths / tight loops.

unlikely()/likely() are micro optimization. They make no difference when you use them in initialization paths.

So what I said, that in your patch they will make no difference performance wise. So no benefits.

But they make if () statements a bit more difficult to read, this is a drawback.

Quoted 8 lines

So your patch introduces no benefits, just a drawback. Thus, it is not good.

There were many flamewars about unlikely and likely in lkml in the past. And the outcome was always - do not use them anywhere except of performance-critical tight loops / hot paths.

alright.. thanks for the review. will drop this patch.

Signature · 2 lines
Regards,
Nishanth Menon
#10 lore raw

PATCH 6/7 omap3: sr: device: check for dev_attr

In reply to Nishanth Menon

in the unlikely case that hwmod database is messed up, dont crash report error and attempt to recover.

Cc Kevin Hilman <[email protected]>
Cc Thara Gopinath <[email protected]>
---
 arch/arm/mach-omap2/sr_device.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/sr_device.c +6 -0
index 177299a..81d2532 100644
@@ -131,6 +131,12 @@ static int sr_dev_init(struct omap_hwmod *oh, void *user)
 	}
 
 	sr_dev_data = (struct omap_sr_dev_data *)oh->dev_attr;
+	if (unlikely(!sr_dev_data)) {
+		pr_err("%s: Bad oh->dev_attr!\n", __func__);
+		kfree(sr_data);
+		return -EINVAL;
+	}
+
 	/*
 	 * OMAP3430 ES3.1 chips by default come with Efuse burnt
 	 * with parameters required for full functionality of
Signature · 1 line
1.6.3.3
#11 lore raw

PATCH 7/7 omap3: sr: device: fail sr_dev_init should return error

In reply to Nishanth Menon

sr_dev_init should return error on error conditions

Cc Kevin Hilman <[email protected]>
Cc Thara Gopinath <[email protected]>
---
 arch/arm/mach-omap2/sr_device.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/sr_device.c +2 -1
index 81d2532..945ff45 100644
@@ -163,7 +163,7 @@ static int sr_dev_init(struct omap_hwmod *oh, void *user)
 				__func__, i + 1);
 		i++;
 		kfree(sr_data);
-		return 0;
+		return -ENODATA;
 	}
 	sr_set_nvalues(sr_dev_data, sr_data);
 	od = omap_device_build(name, i, oh, sr_data, sizeof(*sr_data),
@@ -173,6 +173,7 @@ static int sr_dev_init(struct omap_hwmod *oh, void *user)
 		pr_warning("%s: Could not build omap_device for %s: %s.\n\n",
 			__func__, name, oh->name);
 		kfree(sr_data);
+		return PTR_ERR(od);
 	}
 	i++;
 	return 0;
Signature · 1 line
1.6.3.3