Skip to contentSkip to conversation

How to un-ignore a sensor?

lm-sensors George Spelvin 2 participants 6 messages Jun 29, 2009 – Jul 1, 2009 Library code

lore
Share & tools
lore
#0 lore raw

As I mentioned last year:
http://lists.lm-sensors.org/pipermail/lm-sensors/2008-September/024214.html

I have a motherboard with a sensor hooked up which is ignored in the stock sensors3.conf. (f71882fg-* temp3)

I'd like to un-ignore it, but there doesn't seem to be a way to do that. Looking at the source code, there doesn't seem to be any way to remove or mask an entry from the "ignores" list.

Assuming that feature would be useful, one possible way would be to combine that list with the labels list. An "ignore" statement would be a label with a value of NULL. (Or some other magic sentinel value.)

That way, it would be possible to override an ignore statement by providing a label.

Does that seem worthwhile?

(On another note, would it be worth it to implement a basic hash table for the various symbol lists?)

I also have two minor changes, submitted for your consideration:

commit e139389c4671e2adb3c1db117d700cce7afd75dd

Author: George Spelvin <[email protected]>
Date:   Mon Jun 29 11:53:53 2009 +0000

Consolidate strdup calls in sensors_get_label

There were multiple in-line calls that then fell through to a common exit. Instead, set up a pointer to the original strings, and have a single strdup in the common code.

lib/access.c +6 -4
index af296ab..e29664e 100644
@@ -178,7 +178,7 @@ char *sensors_get_label(const sensors_chip_name *name,
 	for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));)
 		for (i = 0; i < chip->labels_count; i++)
 			if (!strcmp(feature->name, chip->labels[i].name)) {
-				label = strdup(chip->labels[i].value);
+				label = chip->labels[i].value;
 				goto sensors_get_label_exit;
 			}
 
@@ -186,20 +186,22 @@ char *sensors_get_label(const sensors_chip_name *name,
 	snprintf(path, PATH_MAX, "%s/%s_label", name->path, feature->name);
 	
 	if ((f = fopen(path, "r"))) {
-		i = fread(buf, 1, sizeof(buf) - 1, f);
+		i = fread(buf, 1, sizeof buf - 1, f);
 		fclose(f);
 		if (i > 0) {
 			/* i - 1 to strip the '\n' at the end */
 			buf[i - 1] = 0;
-			label = strdup(buf);
+			label = buf;
 			goto sensors_get_label_exit;
 		}
 	}
 
 	/* No label, return the feature name instead */
-	label = strdup(feature->name);
+	label = feature->name;
 	
 sensors_get_label_exit:
+	label = strdup(label);
+	
 	if (!label)
 		sensors_fatal_error("sensors_get_label",
 				    "Allocating label text");

commit 0548c8edf6f939abc1ea47881bad98c26bf48e19

Author: George Spelvin <[email protected]>
Date:   Mon Jun 29 11:56:49 2009 +0000

sensors_get_label: Merge pathname and label buffers.

The lifetimes of the path and label name buffers are disjoint, so a single biffer can be used for both purposes.

lib/access.c +4 -4
index e29664e..90c1af1 100644
@@ -168,7 +168,7 @@ char *sensors_get_label(const sensors_chip_name *name,
 {
 	char *label;
 	const sensors_chip *chip;
-	char buf[128], path[PATH_MAX];
+	char buf[PATH_MAX];
 	FILE *f;
 	int i;
 
@@ -183,10 +183,10 @@ char *sensors_get_label(const sensors_chip_name *name,
 			}
 
 	/* No user specified label, check for a _label sysfs file */
-	snprintf(path, PATH_MAX, "%s/%s_label", name->path, feature->name);
+	snprintf(buf, PATH_MAX, "%s/%s_label", name->path, feature->name);
 	
-	if ((f = fopen(path, "r"))) {
-		i = fread(buf, 1, sizeof buf - 1, f);
+	if ((f = fopen(buf, "r"))) {
+		i = fread(buf, 1, sizeof buf, f);
 		fclose(f);
 		if (i > 0) {
 			/* i - 1 to strip the '\n' at the end */

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

#1 lore raw

Hi George,

Quoted 10 lines · George Spelvin

As I mentioned last year:
http://lists.lm-sensors.org/pipermail/lm-sensors/2008-September/024214.html

I have a motherboard with a sensor hooked up which is ignored in the stock sensors3.conf. (f71882fg-* temp3)

I'd like to un-ignore it, but there doesn't seem to be a way to do that. Looking at the source code, there doesn't seem to be any way to remove or mask an entry from the "ignores" list.

Quoted 8 lines

Assuming that feature would be useful, one possible way would be to combine that list with the labels list. An "ignore" statement would be a label with a value of NULL. (Or some other magic sentinel value.)

That way, it would be possible to override an ignore statement by providing a label.

Does that seem worthwhile?

No, it doesn't. The default sensors.conf file should not include any ignore statement to start with. And actually it no longer does, so the problem is already solved.

Quoted 2 lines

(On another note, would it be worth it to implement a basic hash table for the various symbol lists?)

I doubt it. With the new default configuration file being much smaller than it used to be, I do not think lists are a big problem from a performance perspective. A hash table would probably require more memory and I'd rather keep the memory footprint low.

That being said, if I am proven wrong, I have no objection to a change. If you reimplement data storage in libsensors using hash tables and it is much faster, doesn't need too much additional memory, and doesn't make the code too complex either, they why not?

Quoted 1 line

I also have two minor changes, submitted for your consideration:

Patches are easier to review and try when submitted separately.

Quoted 24 lines

commit e139389c4671e2adb3c1db117d700cce7afd75dd

Author: George Spelvin <[email protected]>
Date:   Mon Jun 29 11:53:53 2009 +0000

Consolidate strdup calls in sensors_get_label

There were multiple in-line calls that then fell through to a common exit. Instead, set up a pointer to the original strings, and have a single strdup in the common code.

lib/access.c +1 -1
index af296ab..e29664e 100644
@@ -178,7 +178,7 @@ char *sensors_get_label(const sensors_chip_name *name,
 	for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));)
 		for (i = 0; i < chip->labels_count; i++)
 			if (!strcmp(feature->name, chip->labels[i].name)) {
-				label = strdup(chip->labels[i].value);
+				label = chip->labels[i].value;
 				goto sensors_get_label_exit;
 			}
 

lib/access.c char *sensors_get_label(const sensors_chip_name *name, · line 189

Quoted 5 lines
lib/access.c +1 -1
@@ -186,20 +186,22 @@ char *sensors_get_label(const sensors_chip_name *name,
 	snprintf(path, PATH_MAX, "%s/%s_label", name->path, feature->name);
 
 	if ((f = fopen(path, "r"))) {
-		i = fread(buf, 1, sizeof(buf) - 1, f);
+		i = fread(buf, 1, sizeof buf - 1, f);

I wouldn't take that change, I prefer the syntax that uses parentheses, and it is used consistently in the library code.

Quoted 10 lines
lib/access.c +1 -1
 		fclose(f);
 		if (i > 0) {
 			/* i - 1 to strip the '\n' at the end */
 			buf[i - 1] = 0;
-			label = strdup(buf);
+			label = buf;
 			goto sensors_get_label_exit;
 		}
 	}
 

lib/access.c char *sensors_get_label(const sensors_chip_name *name, · line 207

Quoted 10 lines
lib/access.c +3 -1
 	/* No label, return the feature name instead */
-	label = strdup(feature->name);
+	label = feature->name;
 
 sensors_get_label_exit:
+	label = strdup(label);
+	
 	if (!label)
 		sensors_fatal_error("sensors_get_label",
 				    "Allocating label text");

This makes sense, I think we can apply this.

Quoted 29 lines

commit 0548c8edf6f939abc1ea47881bad98c26bf48e19

Author: George Spelvin <[email protected]>
Date:   Mon Jun 29 11:56:49 2009 +0000

sensors_get_label: Merge pathname and label buffers.

The lifetimes of the path and label name buffers are disjoint, so a single biffer can be used for both purposes.

lib/access.c +1 -1
index e29664e..90c1af1 100644
@@ -168,7 +168,7 @@ char *sensors_get_label(const sensors_chip_name *name,
 {
 	char *label;
 	const sensors_chip *chip;
-	char buf[128], path[PATH_MAX];
+	char buf[PATH_MAX];
 	FILE *f;
 	int i;
 
@@ -183,10 +183,10 @@ char *sensors_get_label(const sensors_chip_name *name,
 			}
 
 	/* No user specified label, check for a _label sysfs file */

lib/access.c char *sensors_get_label(const sensors_chip_name *name, · line 192

Quoted 10 lines
lib/access.c +3 -3
-	snprintf(path, PATH_MAX, "%s/%s_label", name->path, feature->name);
+	snprintf(buf, PATH_MAX, "%s/%s_label", name->path, feature->name);
 
-	if ((f = fopen(path, "r"))) {
-		i = fread(buf, 1, sizeof buf - 1, f);
+	if ((f = fopen(buf, "r"))) {
+		i = fread(buf, 1, sizeof buf, f);
 		fclose(f);
 		if (i > 0) {
 			/* i - 1 to strip the '\n' at the end */

Indeed, this seems a worthwhile optimization.

The license of libsensors will change from GPL to LGPL on July 1st, 2010. Before I apply your patches, please confirm that you have no objection to your code being released under the LGPL.

Thanks,

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to George Spelvin
Quoted 3 lines

No, it doesn't. The default sensors.conf file should not include any ignore statement to start with. And actually it no longer does, so the problem is already solved.

Um... okay. Is that a universal solution? Debian ships a larger config file that does include some "ignore" lines. It does seem useful to have an overridable default.

Are there plans for some more flexible include or conditional mechanism to allow segregating site-local edits?

Quoted 8 lines
Quoted 2 lines

(On another note, would it be worth it to implement a basic hash table for the various symbol lists?)

I doubt it. With the new default configuration file being much smaller than it used to be, I do not think lists are a big problem from a performance perspective. A hash table would probably require more memory and I'd rather keep the memory footprint low.

Quoted 4 lines

That being said, if I am proven wrong, I have no objection to a change. If you reimplement data storage in libsensors using hash tables and it is much faster, doesn't need too much additional memory, and doesn't make the code too complex either, they why not?

Okay, I'll poke at it if I'm motivated, but remember your priorities. It seems that there are a lot of duplicated strings ("temp3_max"), so if the overhead can be can be made small enough, interning them would save memory.

Quoted 1 line

Patches are easier to review and try when submitted separately.

Sorry.

Quoted 3 lines

The license of libsensors will change from GPL to LGPL on July 1st, 2010. Before I apply your patches, please confirm that you have no objection to your code being released under the LGPL.

Yes, of course. These changes are all in the public domain. Do whatever you like with them (even evil things).

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

#3 lore raw
In reply to George Spelvin

Hi George,

Quoted 7 lines · George Spelvin
Quoted 3 lines

No, it doesn't. The default sensors.conf file should not include any ignore statement to start with. And actually it no longer does, so the problem is already solved.

Um... okay. Is that a universal solution? Debian ships a larger config file that does include some "ignore" lines. It does seem useful to have an overridable default.

Which version of lm-sensors do the ship? The change occurred in version 3.1.0.

Quoted 2 lines

Are there plans for some more flexible include or conditional mechanism to allow segregating site-local edits?

This was implemented in lm-sensors 3.1.0 (and fixed in 3.1.1 for some filesystems.)

Quoted 13 lines
Quoted 8 lines
Quoted 2 lines

(On another note, would it be worth it to implement a basic hash table for the various symbol lists?)

I doubt it. With the new default configuration file being much smaller than it used to be, I do not think lists are a big problem from a performance perspective. A hash table would probably require more memory and I'd rather keep the memory footprint low.

Quoted 4 lines

That being said, if I am proven wrong, I have no objection to a change. If you reimplement data storage in libsensors using hash tables and it is much faster, doesn't need too much additional memory, and doesn't make the code too complex either, they why not?

Quoted 4 lines

Okay, I'll poke at it if I'm motivated, but remember your priorities. It seems that there are a lot of duplicated strings ("temp3_max"), so if the overhead can be can be made small enough, interning them would save memory.

I fear I don't quite follow you here. Which strings are duplicated exactly, and what do you mean by "interning"?

Quoted 10 lines
Quoted 1 line

Patches are easier to review and try when submitted separately.

Sorry.

Quoted 3 lines

The license of libsensors will change from GPL to LGPL on July 1st, 2010. Before I apply your patches, please confirm that you have no objection to your code being released under the LGPL.

Yes, of course. These changes are all in the public domain. Do whatever you like with them (even evil things).

Great, thanks.

I'm out to kill kittens with your patches now ;)

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#4 lore raw
In reply to George Spelvin
Quoted 6 lines
Quoted 3 lines

Um... okay. Is that a universal solution? Debian ships a larger config file that does include some "ignore" lines. It does seem useful to have an overridable default.

Which version of lm-sensors do the ship? The change occurred in version 3.1.0.

3.1.1. Would you like a copy of the tarball?

Quoted 5 lines
Quoted 2 lines

Are there plans for some more flexible include or conditional mechanism to allow segregating site-local edits?

This was implemented in lm-sensors 3.1.0 (and fixed in 3.1.1 for some filesystems.)

Is that the "/etc/sensors.d" thing? I suppose if you moved *all* of the ignore statements into there and had some sort of symlink thing.

What I was thinking was more a way to supply a board name, which would reference a chip config file, that would include a base chip configuration and customize it.

Many people could just specify a board name. Or add a new alias for an existing chip config file. Only a few would have to customize a chip config file (to reflect the creative new way the mobo has wired up the super-I/O chip), and creating a new one would be quite rare.

Quoted 7 lines
Quoted 4 lines

Okay, I'll poke at it if I'm motivated, but remember your priorities. It seems that there are a lot of duplicated strings ("temp3_max"), so if the overhead can be can be made small enough, interning them would save memory.

I fear I don't quite follow you here. Which strings are duplicated exactly, and what do you mean by "interning"?

A lot of the sensor names are duplicated a lot in different chipsets. I used "temp3_max" as an example, although "in1" is another one.

"interning" is to build a single global reference-counted string table so all copies of a given string point to a single copy. (This is *separate* from the possibility of per-chip hash tables.) This has the useful property that later string compare reduces to a pointer compare.

As long as the number of copies of each string is large enough (say, an average of two) that eliminating the duplicate copies saves more space than the hash table plus reference counts add, it's a net space savings.

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

#5 lore raw
In reply to George Spelvin

Hi George,

Quoted 8 lines · George Spelvin
Quoted 6 lines
Quoted 3 lines

Um... okay. Is that a universal solution? Debian ships a larger config file that does include some "ignore" lines. It does seem useful to have an overridable default.

Which version of lm-sensors do the ship? The change occurred in version 3.1.0.

3.1.1. Would you like a copy of the tarball?

Tarball of what?

The default configuration file which comes with lm-sensors 3.1.1 is:
http://www.lm-sensors.org/browser/lm-sensors/tags/V3-1-1/etc/sensors.conf.default

See for yourself, this file doesn't contain any "ignore" statement. If Debian ships something different, there's nothing I can do about it, go tell them they should not.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Are there plans for some more flexible include or conditional mechanism to allow segregating site-local edits?

This was implemented in lm-sensors 3.1.0 (and fixed in 3.1.1 for some filesystems.)

Is that the "/etc/sensors.d" thing?

Yes it is. Put all your local configuration changes there and you're done. This of course assumes that the default configuration file contains no non-overridable statements (and in particular no ignore statement - which is why removed them all.)

Quoted 2 lines

I suppose if you moved *all* of the
ignore statements into there and had some sort of symlink thing.

I have no clue what you're talking about.

Quoted 6 lines

What I was thinking was more a way to supply a board name, which would reference a chip config file, that would include a base chip configuration and customize it.

Many people could just specify a board name. Or add a new alias for an existing chip config file.

We have long term plans for that, but the idea would be to implement it outside of the library, rather than inside it. A configuration tool would identify the board, search for a known configuration file, and if one is found, copy it to /etc/sensors.d.

Moving the board identification into libsensors would require a lot more changes as far as I can see. For example, it would require that we extend the configuration file language with more directives, so that the user can override the library's decision. Maybe you want to modify the file configuration parser... me, this is the last part of libsensors I like to touch ;)

Quoted 3 lines

Only a few would have to customize a chip
config file (to reflect the creative new way the mobo has wired up the super-I/O chip), and creating a new one would be quite rare.

You live in a fantasy world ;) Out of the several thousand PC mainboards out there, we have configuration files for 100, top. And no two mainboards out there have the exact same configuration. With the amount of configuration files we have today, most users would still have to manually configure their chip, and only a few lucky ones would have a working system out of the box.

Of course, over time we can have the hope that the database of good configuration file grows and the balance shifts. But this will take time _and_ a good infrastructure for users to contribute, which we do not have yet.

Quoted 16 lines
Quoted 7 lines
Quoted 4 lines

Okay, I'll poke at it if I'm motivated, but remember your priorities. It seems that there are a lot of duplicated strings ("temp3_max"), so if the overhead can be can be made small enough, interning them would save memory.

I fear I don't quite follow you here. Which strings are duplicated exactly, and what do you mean by "interning"?

A lot of the sensor names are duplicated a lot in different chipsets. I used "temp3_max" as an example, although "in1" is another one.

"interning" is to build a single global reference-counted string table so all copies of a given string point to a single copy. (This is *separate* from the possibility of per-chip hash tables.) This has the useful property that later string compare reduces to a pointer compare.

Quoted 4 lines

As long as the number of copies of each string is large enough (say, an average of two) that eliminating the duplicate copies saves more space than the hash table plus reference counts add, it's a net space savings.

Ah, OK, I see what you mean now. I can't remember seeing an implementation of this. I understand this makes sense sense when handling a large amount of data you _need_ to keep. When it comes to libsensors, I'm not sure it applies. For one thing, we do not have that much data. Running "sensors" through valgrind with different configuration files, I obtain the following memory allocation numbers:

* sensors.conf.eg: 210,007 bytes allocated
* sensors.conf.default: 175,233 bytes allocated
* custom config file: 137,553 bytes allocated
* no configuration file: 145,650 bytes allocated

This is the total amount of memory allocated, not the peak of memory consumption, and not all is for the configuration file handling, but this still shows that out of the ~73 kB of memory that used to be allocated for the previous default configuration file, we have saved almost half already (~35 kB) by switching to a smaller default configuration file. There's only ~38 kB left to win. That's not much, and honestly, if you care that much about memory, you probably want to delete the default configuration file right away, and only use a custom one. So, generally speaking, I don't think there's much point in optimizing libsensors to better handle large configuration files, because we do not want to have large configuration files anyway, for performance reasons.

Anyway, if you want to look into reducing the amount of memory used by libsensors, or make it faster, you're very welcome. But you'll have to prove the benefit.

Signature · 6 lines
Jean Delvare

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