Skip to contentSkip to conversation

Package Level Power limit: fix the generation of package_power_limit_count sysfile.

Patch-next Jin Dongming 3 participants 15 messages Aug 26, 2010 – Oct 8, 2010 x86

lore
Share & tools
lore
#0 lore raw

I read the source code of therm_throt.c. Most of checking codes for PLN
and PTS are like following:
if (PLN)
....
if (PTS) {
...
if (PLN)
...
}

But there is not checking code for the generation of package_power_limit_count sysfile. And the code is like following:
if (PLN)
...
if (PTS)
...
if (PLN)
...

I don't think the sysfile package_power_limit_count should be generated, when the feature PTS of CPU is not supported. The reasons are listed as following:
1.The sysfile package_power_limit_count is used for counting the happened time of PLN event of a package. If PTS is not supported by CPU, IA32_PACKAGE_THERM_STATUS and IA32_PACKAGE_THERM_INTERRUPT MSRs are not implemented on the package on which the CPU exists.The PLN interrupt bit for package in IA32_PACKAGE_THERM_INTERRUPT could not be enabled, too. Because the PLN event for package will never happen, the sysfile package_power_limit_count loses the true meaning of its existence. 2.Even if package_power_limit_count sysfile could be generated, if PTS is not supported by CPU, there is not any other source code for updating the value of package_power_limit_count. So the sysfile package_power_limit_count is not useful.

This patch is used for fixing it. But I have not confirmed this patch because I don't have such machine.

---
arch/x86/kernel/cpu/mcheck/therm_throt.c | 3 ++-

1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/mcheck/therm_throt.c +0 -0
index d9368ee..169d880 100644
@@ -216,7 +216,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,

err = sysfs_add_file_to_group(&sys_dev->kobj, &attr_core_power_limit_count.attr,
thermal_attr_group.name);
- if (cpu_has(c, X86_FEATURE_PTS))
+ if (cpu_has(c, X86_FEATURE_PTS)) {
err = sysfs_add_file_to_group(&sys_dev->kobj, &attr_package_throttle_count.attr,
thermal_attr_group.name);
@@ -224,6 +224,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev, err = sysfs_add_file_to_group(&sys_dev->kobj, &attr_package_power_limit_count.attr,
thermal_attr_group.name);
+ }

return err;
}

Signature · 9 lines
1.7.1.1




_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw
Quoted 23 lines · Jin Dongming

This patch is used for fixing it. But I have not confirmed this patch because I don't have such machine.

---
arch/x86/kernel/cpu/mcheck/therm_throt.c | 3 ++-

1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/mcheck/therm_throt.c +1 -1
index d9368ee..169d880 100644
@@ -216,7 +216,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 err = sysfs_add_file_to_group(&sys_dev->kobj,
 &attr_core_power_limit_count.attr,
 thermal_attr_group.name);
- if (cpu_has(c, X86_FEATURE_PTS))
+ if (cpu_has(c, X86_FEATURE_PTS)) {
 err = sysfs_add_file_to_group(&sys_dev->kobj,
 &attr_package_throttle_count.attr,
 thermal_attr_group.name);

arch/x86/kernel/cpu/mcheck/therm_throt.c static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev, · line 230

Quoted 7 lines
arch/x86/kernel/cpu/mcheck/therm_throt.c +1 -0
@@ -224,6 +224,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 err = sysfs_add_file_to_group(&sys_dev->kobj,
 &attr_package_power_limit_count.attr,
 thermal_attr_group.name);
+ }
 
 return err;
 }

The argument is right. A concise message (e.g. missing { and }) would be better.

Format of this patch is broken. It would be applied to kernel tree. Could you generate a patch with right format?

Thanks.

-Fenghua

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#2 lore raw

[Patch-next] therm_throt.c: fix missing { and }.

When the feature PTS is not supported by CPU, the sysfile package_power_limit_count for package should not be generated.

This patch is used for fixing missing { and }. But I have not confirmed this patch because I don't have such machine.

---
 arch/x86/kernel/cpu/mcheck/therm_throt.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/mcheck/therm_throt.c +2 -1
index d9368ee..169d880 100644
@@ -216,7 +216,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_core_power_limit_count.attr,
 					      thermal_attr_group.name);
-	if (cpu_has(c, X86_FEATURE_PTS))
+	if (cpu_has(c, X86_FEATURE_PTS)) {
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_package_throttle_count.attr,
 					      thermal_attr_group.name);
@@ -224,6 +224,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 			err = sysfs_add_file_to_group(&sys_dev->kobj,
 					&attr_package_power_limit_count.attr,
 					thermal_attr_group.name);
+	}
 
 	return err;
 }
Signature · 1 line
1.7.1.1
Reviewed-by
#3 lore raw

Re: [Patch-next] therm_throt.c: fix missing { and }.

Quoted 35 lines · Jin Dongming

When the feature PTS is not supported by CPU, the sysfile package_power_limit_count for package should not be generated.

This patch is used for fixing missing { and }. But I have not confirmed this patch because I don't have such machine.

---
 arch/x86/kernel/cpu/mcheck/therm_throt.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/mcheck/therm_throt.c +2 -1
index d9368ee..169d880 100644
@@ -216,7 +216,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_core_power_limit_count.attr,
 					      thermal_attr_group.name);
-	if (cpu_has(c, X86_FEATURE_PTS))
+	if (cpu_has(c, X86_FEATURE_PTS)) {
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_package_throttle_count.attr,
 					      thermal_attr_group.name);
@@ -224,6 +224,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 			err = sysfs_add_file_to_group(&sys_dev->kobj,
 					&attr_package_power_limit_count.attr,
 					thermal_attr_group.name);
+	}
 
 	return err;
 }
Signature · 1 line
1.7.1.1

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#4 lore raw

Re: [lm-sensors] [Patch-next] therm_throt.c: fix missing { and }.

In reply to Jin Dongming
Quoted 25 lines · Jin Dongming

When the feature PTS is not supported by CPU, the sysfile package_power_limit_count for package should not be generated.

This patch is used for fixing missing { and }. But I have not confirmed this patch because I don't have such machine.

---
 arch/x86/kernel/cpu/mcheck/therm_throt.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/mcheck/therm_throt.c +1 -1
index d9368ee..169d880 100644
@@ -216,7 +216,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_core_power_limit_count.attr,
 					      thermal_attr_group.name);
-	if (cpu_has(c, X86_FEATURE_PTS))
+	if (cpu_has(c, X86_FEATURE_PTS)) {
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_package_throttle_count.attr,
 					      thermal_attr_group.name);

arch/x86/kernel/cpu/mcheck/therm_throt.c static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev, · line 230

Quoted 7 lines
arch/x86/kernel/cpu/mcheck/therm_throt.c +1 -0
@@ -224,6 +224,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 			err = sysfs_add_file_to_group(&sys_dev->kobj,
 					&attr_package_power_limit_count.attr,
 					thermal_attr_group.name);
+	}
 
 	return err;
 }

This is incomplete. Error handling in this function is totally broken.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#5 lore raw

Re: [lm-sensors] [Patch-next] therm_throt.c: fix missing { and }.

Quoted 31 lines · Jean Delvare
Quoted 30 lines · Jin Dongming

When the feature PTS is not supported by CPU, the sysfile package_power_limit_count for package should not be generated.

This patch is used for fixing missing { and }. But I have not confirmed this patch because I don't have such machine.

---
 arch/x86/kernel/cpu/mcheck/therm_throt.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/mcheck/therm_throt.c +2 -1
index d9368ee..169d880 100644
@@ -216,7 +216,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_core_power_limit_count.attr,
 					      thermal_attr_group.name);
-	if (cpu_has(c, X86_FEATURE_PTS))
+	if (cpu_has(c, X86_FEATURE_PTS)) {
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_package_throttle_count.attr,
 					      thermal_attr_group.name);
@@ -224,6 +224,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 			err = sysfs_add_file_to_group(&sys_dev->kobj,
 					&attr_package_power_limit_count.attr,
 					thermal_attr_group.name);
+	}
 
Quoted 6 lines

arch/x86/kernel/cpu/mcheck/therm_throt.c static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev, · line 230

Quoted 2 lines
arch/x86/kernel/cpu/mcheck/therm_throt.c +0 -0
 	return err;
 }

This is incomplete. Error handling in this function is totally broken.

I am sorry for replying late.

Yes. What you thought is right.
But this patch is only used for fixing the problem that when the feature PTS is not supported by CPU, the sysfile package_power_limit_count should not be generated.

So the patch for error handling should be provided as another one. I will make a patch for it .

Thanks.

Best Regards,
Jin Dongming

#6 lore raw

RE: [lm-sensors] [Patch-next] therm_throt.c: fix missing { and }.

Quoted 2 lines

So the patch for error handling should be provided as another one. I will make a patch for it .

These two patches could be sent as one patch since they are in the same small function.

Thanks.

-Fenghua

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#7 lore raw

[Patch-next] Trival fixes in thermal_throttle_add_dev().

This patch fixed the following two problems.
1. When the feature PTS is not supported by CPU, the sysfile package_power_limit_count for package should not be generated.
2. No matter whether a sysfile is failed to be created or not, the next one will be created.

As the resolving methods:
1. Add missing { and } after checking PTS feature.
2. Fix the error handling.

---
 arch/x86/kernel/cpu/mcheck/therm_throt.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/mcheck/therm_throt.c +14 -1
index d9368ee..79d563a 100644
@@ -216,14 +216,27 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_core_power_limit_count.attr,
 					      thermal_attr_group.name);
-	if (cpu_has(c, X86_FEATURE_PTS))
+	if (err)
+		goto error;
+
+	if (cpu_has(c, X86_FEATURE_PTS)) {
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_package_throttle_count.attr,
 					      thermal_attr_group.name);
+		if (err)
+			goto error;
+
 		if (cpu_has(c, X86_FEATURE_PLN))
 			err = sysfs_add_file_to_group(&sys_dev->kobj,
 					&attr_package_power_limit_count.attr,
 					thermal_attr_group.name);
+		if (err)
+			goto error;
+	}
+
+	return 0;
+error:
+	sysfs_remove_group(&sys_dev->kobj, &thermal_attr_group);
 
 	return err;
 }
Signature · 1 line
1.7.1.1
#8 lore raw

Re: [Patch-next] Trival fixes in thermal_throttle_add_dev().

Quoted 39 lines · Jin Dongming

This patch fixed the following two problems.
1. When the feature PTS is not supported by CPU, the sysfile package_power_limit_count for package should not be generated.
2. No matter whether a sysfile is failed to be created or not, the next one will be created.

As the resolving methods:
1. Add missing { and } after checking PTS feature.
2. Fix the error handling.

---
 arch/x86/kernel/cpu/mcheck/therm_throt.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/mcheck/therm_throt.c +7 -1
index d9368ee..79d563a 100644
@@ -216,14 +216,27 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_core_power_limit_count.attr,
 					      thermal_attr_group.name);
-	if (cpu_has(c, X86_FEATURE_PTS))
+	if (err)
+		goto error;
+
+	if (cpu_has(c, X86_FEATURE_PTS)) {
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_package_throttle_count.attr,
 					      thermal_attr_group.name);
+		if (err)
+			goto error;
+
 		if (cpu_has(c, X86_FEATURE_PLN))
 			err = sysfs_add_file_to_group(&sys_dev->kobj,
 					&attr_package_power_limit_count.attr,
 					thermal_attr_group.name);

arch/x86/kernel/cpu/mcheck/therm_throt.c static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev, · line 242

Quoted 10 lines
arch/x86/kernel/cpu/mcheck/therm_throt.c +7 -0
+		if (err)
+			goto error;
+	}
+
+	return 0;
+error:
+	sysfs_remove_group(&sys_dev->kobj, &thermal_attr_group);
 
 	return err;
 }

This fix is incorrect. In this patch, a previous error prevents from adding any further devices. There shouldn't be such dependency among the devices.

Thanks.

-Fenghua

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#9 lore raw

Re: [Patch-next] Trival fixes in thermal_throttle_add_dev().

Hi Fenghua,

Quoted 48 lines · Fenghua Yu
Quoted 47 lines · Jin Dongming

This patch fixed the following two problems.
1. When the feature PTS is not supported by CPU, the sysfile package_power_limit_count for package should not be generated.
2. No matter whether a sysfile is failed to be created or not, the next one will be created.

As the resolving methods:
1. Add missing { and } after checking PTS feature.
2. Fix the error handling.

---
 arch/x86/kernel/cpu/mcheck/therm_throt.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/mcheck/therm_throt.c +14 -1
index d9368ee..79d563a 100644
@@ -216,14 +216,27 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_core_power_limit_count.attr,
 					      thermal_attr_group.name);
-	if (cpu_has(c, X86_FEATURE_PTS))
+	if (err)
+		goto error;
+
+	if (cpu_has(c, X86_FEATURE_PTS)) {
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_package_throttle_count.attr,
 					      thermal_attr_group.name);
+		if (err)
+			goto error;
+
 		if (cpu_has(c, X86_FEATURE_PLN))
 			err = sysfs_add_file_to_group(&sys_dev->kobj,
 					&attr_package_power_limit_count.attr,
 					thermal_attr_group.name);
+		if (err)
+			goto error;
+	}
+
+	return 0;
+error:
+	sysfs_remove_group(&sys_dev->kobj, &thermal_attr_group);
 
Quoted 5 lines

arch/x86/kernel/cpu/mcheck/therm_throt.c static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev, · line 242

Quoted 2 lines
arch/x86/kernel/cpu/mcheck/therm_throt.c +0 -0
 	return err;
 }

This fix is incorrect. In this patch, a previous error prevents from adding any further devices. There shouldn't be such dependency among the devices.

I don't quite follow you. Did you mean to write that a previous error prevents from creating further _attributes_ for the same device? This would be true.

Now I don't think this is a problem because 1* such errors should never happen anyway and 2* if they do happen then further attempts to create the other attributes are unlikely to succeed either.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#10 lore raw

Re: [Patch-next] Trival fixes in thermal_throttle_add_dev().

Quoted 39 lines · Jean Delvare
Quoted 32 lines · Fenghua Yu
Quoted 31 lines · Jin Dongming
arch/x86/kernel/cpu/mcheck/therm_throt.c +14 -1
index d9368ee..79d563a 100644
@@ -216,14 +216,27 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_core_power_limit_count.attr,
 					      thermal_attr_group.name);
-	if (cpu_has(c, X86_FEATURE_PTS))
+	if (err)
+		goto error;
+
+	if (cpu_has(c, X86_FEATURE_PTS)) {
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_package_throttle_count.attr,
 					      thermal_attr_group.name);
+		if (err)
+			goto error;
+
 		if (cpu_has(c, X86_FEATURE_PLN))
 			err = sysfs_add_file_to_group(&sys_dev->kobj,
 					&attr_package_power_limit_count.attr,
 					thermal_attr_group.name);
+		if (err)
+			goto error;
+	}
+
+	return 0;
+error:
+	sysfs_remove_group(&sys_dev->kobj, &thermal_attr_group);
 
Quoted 5 lines

arch/x86/kernel/cpu/mcheck/therm_throt.c static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev, · line 242

Quoted 2 lines
arch/x86/kernel/cpu/mcheck/therm_throt.c +0 -0
 	return err;
 }

This fix is incorrect. In this patch, a previous error prevents from adding any further devices. There shouldn't be such dependency among the devices.

Quoted 7 lines

I don't quite follow you. Did you mean to write that a previous error prevents from creating further _attributes_ for the same device? This would be true.

Now I don't think this is a problem because 1* such errors should never happen anyway and 2* if they do happen then further attempts to create the other attributes are unlikely to succeed either.

I don't think there is dependency among the count files, i.e. failure to add a count file to the group shouldn't impact other files. Other filles can still be added to the group. In this case, user application only sees part of count numbers. And kernel may just warn on the failure instead of providing nothing to user.

In the patch, any failure to add a file will remove the whole group. This is too strict. Kernel doesn't provide any count number to user application.

Agree with you that such errors should never happen anyway. So original code works fine.

If to be picky to the error handling, a patch may just ignore returning errors from sysfs_add_file_to_group. Or use err |= sysfs_add_file_to_group to collect all errors and return err but without calling sysfs_remove_group.

Thanks.

-Fenghua

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#11 lore raw

Re: [Patch-next] Trival fixes in thermal_throttle_add_dev().

Quoted 48 lines · Fenghua Yu
Quoted 39 lines · Jean Delvare
Quoted 32 lines · Fenghua Yu
Quoted 31 lines · Jin Dongming
arch/x86/kernel/cpu/mcheck/therm_throt.c +14 -1
index d9368ee..79d563a 100644
@@ -216,14 +216,27 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_core_power_limit_count.attr,
 					      thermal_attr_group.name);
-	if (cpu_has(c, X86_FEATURE_PTS))
+	if (err)
+		goto error;
+
+	if (cpu_has(c, X86_FEATURE_PTS)) {
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_package_throttle_count.attr,
 					      thermal_attr_group.name);
+		if (err)
+			goto error;
+
 		if (cpu_has(c, X86_FEATURE_PLN))
 			err = sysfs_add_file_to_group(&sys_dev->kobj,
 					&attr_package_power_limit_count.attr,
 					thermal_attr_group.name);
+		if (err)
+			goto error;
+	}
+
+	return 0;
+error:
+	sysfs_remove_group(&sys_dev->kobj, &thermal_attr_group);
 
Quoted 5 lines

arch/x86/kernel/cpu/mcheck/therm_throt.c static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev, · line 242

Quoted 2 lines
arch/x86/kernel/cpu/mcheck/therm_throt.c +0 -0
 	return err;
 }

This fix is incorrect. In this patch, a previous error prevents from adding any further devices. There shouldn't be such dependency among the devices.

Quoted 7 lines

I don't quite follow you. Did you mean to write that a previous error prevents from creating further _attributes_ for the same device? This would be true.

Now I don't think this is a problem because 1* such errors should never happen anyway and 2* if they do happen then further attempts to create the other attributes are unlikely to succeed either.

Quoted 8 lines

I don't think there is dependency among the count files, i.e. failure to add a count file to the group shouldn't impact other files. Other filles can still be added to the group. In this case, user application only sees part of count numbers. And kernel may just warn on the failure instead of providing nothing to user.

In the patch, any failure to add a file will remove the whole group. This is too strict. Kernel doesn't provide any count number to user application.

Oh, my bad. I missed the call to sysfs_remove_group() when reviewing the code. I agree with you that it shouldn't be added.

Quoted 2 lines

Agree with you that such errors should never happen anyway. So original code works fine.

The original code works indeed (except for the missing curly braces) but is confusing for the reader (which is why I raised the point and we are discussing it now). If you are voluntarily ignoring errors, you should add a comment saying so. And it is also a good practice to use a dummy variable to store the error value you'll ignore, so that the intent is clear.

Quoted 2 lines

If to be picky to the error handling, a patch may just ignore returning errors from sysfs_add_file_to_group.

This is an option, yes. Unfortunately this also means that such errors won't be even logged, while I think this would be desirable.

Quoted 2 lines

Or use err |= sysfs_add_file_to_group to collect
all errors and return err but without calling sysfs_remove_group.

Please never use |= on non-bitwise values, it can only lead to bugs and confusion.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#12 lore raw

Re: [Patch-next] Trival fixes in thermal_throttle_add_dev().

Hi Jean and Fenghua,

Sorry for replying late.

Quoted 64 lines · Jean Delvare
Quoted 48 lines · Fenghua Yu
Quoted 39 lines · Jean Delvare
Quoted 32 lines · Fenghua Yu
Quoted 31 lines · Jin Dongming
arch/x86/kernel/cpu/mcheck/therm_throt.c +14 -1
index d9368ee..79d563a 100644
@@ -216,14 +216,27 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_core_power_limit_count.attr,
 					      thermal_attr_group.name);
-	if (cpu_has(c, X86_FEATURE_PTS))
+	if (err)
+		goto error;
+
+	if (cpu_has(c, X86_FEATURE_PTS)) {
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_package_throttle_count.attr,
 					      thermal_attr_group.name);
+		if (err)
+			goto error;
+
 		if (cpu_has(c, X86_FEATURE_PLN))
 			err = sysfs_add_file_to_group(&sys_dev->kobj,
 					&attr_package_power_limit_count.attr,
 					thermal_attr_group.name);
+		if (err)
+			goto error;
+	}
+
+	return 0;
+error:
+	sysfs_remove_group(&sys_dev->kobj, &thermal_attr_group);
 
Quoted 5 lines

arch/x86/kernel/cpu/mcheck/therm_throt.c static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev, · line 242

Quoted 2 lines
arch/x86/kernel/cpu/mcheck/therm_throt.c +0 -0
 	return err;
 }

This fix is incorrect. In this patch, a previous error prevents from adding any further devices. There shouldn't be such dependency among the devices.

Quoted 7 lines

I don't quite follow you. Did you mean to write that a previous error prevents from creating further _attributes_ for the same device? This would be true.

Now I don't think this is a problem because 1* such errors should never happen anyway and 2* if they do happen then further attempts to create the other attributes are unlikely to succeed either.

Quoted 8 lines

I don't think there is dependency among the count files, i.e. failure to add a count file to the group shouldn't impact other files. Other filles can still be added to the group. In this case, user application only sees part of count numbers. And kernel may just warn on the failure instead of providing nothing to user.

In the patch, any failure to add a file will remove the whole group. This is too strict. Kernel doesn't provide any count number to user application.

Oh, my bad. I missed the call to sysfs_remove_group() when reviewing the code. I agree with you that it shouldn't be added.

Quoted 2 lines

Agree with you that such errors should never happen anyway. So original code works fine.

Quoted 7 lines

The original code works indeed (except for the missing curly braces) but is confusing for the reader (which is why I raised the point and we are discussing it now). If you are voluntarily ignoring errors, you should add a comment saying so. And it is also a good practice to use a dummy variable to store the error value you'll ignore, so that the intent is clear.

I agree with your option. So I will cancel error handling of this patch and resend a patch just for missing { and } only.

And I think Fenghua could make a new patch for a comment.

Best Regards,
Jin Dongming

Quoted 12 lines
Quoted 2 lines

If to be picky to the error handling, a patch may just ignore returning errors from sysfs_add_file_to_group.

This is an option, yes. Unfortunately this also means that such errors won't be even logged, while I think this would be desirable.

Quoted 2 lines

Or use err |= sysfs_add_file_to_group to collect
all errors and return err but without calling sysfs_remove_group.

Please never use |= on non-bitwise values, it can only lead to bugs and confusion.

#13 lore raw

Re: [Patch-next] Trival fixes in thermal_throttle_add_dev().

In reply to Jin Dongming

Hi Jin

Quoted 31 lines · Jin Dongming

This patch fixed the following two problems.
1. When the feature PTS is not supported by CPU, the sysfile package_power_limit_count for package should not be generated.
2. No matter whether a sysfile is failed to be created or not, the next one will be created.

As the resolving methods:
1. Add missing { and } after checking PTS feature.
2. Fix the error handling.

---
 arch/x86/kernel/cpu/mcheck/therm_throt.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/mcheck/therm_throt.c +4 -1
index d9368ee..79d563a 100644
@@ -216,14 +216,27 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_core_power_limit_count.attr,
 					      thermal_attr_group.name);
-	if (cpu_has(c, X86_FEATURE_PTS))
+	if (err)
+		goto error;
+
+	if (cpu_has(c, X86_FEATURE_PTS)) {
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_package_throttle_count.attr,

arch/x86/kernel/cpu/mcheck/therm_throt.c static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev, · line 234

Quoted 10 lines
arch/x86/kernel/cpu/mcheck/therm_throt.c +5 -0
 					      thermal_attr_group.name);
+		if (err)
+			goto error;
+
 		if (cpu_has(c, X86_FEATURE_PLN))
 			err = sysfs_add_file_to_group(&sys_dev->kobj,
 					&attr_package_power_limit_count.attr,
 					thermal_attr_group.name);
+		if (err)
+			goto error;

Even though you are lucky that in the end it still works, this check is misplaced. You should instead have:

		if (cpu_has(c, X86_FEATURE_PLN)) {
			err = sysfs_add_file_to_group(&sys_dev->kobj,
					&attr_package_power_limit_count.attr,
					thermal_attr_group.name);
			if (err)
				goto error;
		}
Quoted 8 lines
arch/x86/kernel/cpu/mcheck/therm_throt.c +5 -0
+	}
+
+	return 0;
+error:
+	sysfs_remove_group(&sys_dev->kobj, &thermal_attr_group);
 
 	return err;
 }
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#14 lore raw

[tip:x86/urgent] x86, mce, therm_throt.c: Fix missing curly braces in error handling logic

In reply to Jin Dongming
Commit-ID:  b62be8ea9db4048112219ff6d6ce5f183179d4dc
Gitweb:     http://git.kernel.org/tip/b62be8ea9db4048112219ff6d6ce5f183179d4dc
Author:     Jin Dongming <[email protected]>
AuthorDate: Thu, 26 Aug 2010 17:29:05 +0900
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 8 Oct 2010 10:29:20 +0200

x86, mce, therm_throt.c: Fix missing curly braces in error handling logic

When the feature PTS is not supported by CPU, the sysfile package_power_limit_count for package should not be generated.

This patch is used for fixing missing { and }.

The patch is not complete as there are other error handling problems in this function - but that can wait until the merge window.

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/cpu/mcheck/therm_throt.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/mcheck/therm_throt.c +2 -1
index d9368ee..169d880 100644
@@ -216,7 +216,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_core_power_limit_count.attr,
 					      thermal_attr_group.name);
-	if (cpu_has(c, X86_FEATURE_PTS))
+	if (cpu_has(c, X86_FEATURE_PTS)) {
 		err = sysfs_add_file_to_group(&sys_dev->kobj,
 					      &attr_package_throttle_count.attr,
 					      thermal_attr_group.name);
@@ -224,6 +224,7 @@ static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
 			err = sysfs_add_file_to_group(&sys_dev->kobj,
 					&attr_package_power_limit_count.attr,
 					thermal_attr_group.name);
+	}
 
 	return err;
 }