Skip to contentSkip to conversation

2.6.15.1 Kernel patch for hardware monitoring support

lm-sensors Hartmut Rick 2 participants 5 messages Feb 28, 2006 – Mar 1, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi Jean,

thanks a lot for your advice and encouragement.

Quoted 7 lines · Jean Delvare
Quoted 1 line

/* Alarms */

For newer designs, we try to have one sysfs file per alarm type (here, one for voltages and one for temperatures) with bits sorted for userspace. That way userspace doesn't need to know about the chip internals. Can you try to do that in your driver? You'd have one alarms_in file and one alarms_temp file.

What would I do with temperature sensor faults? Create another file? What would it be called?
temp_faults ?
alarms_temp_faults ?
faults_temp ?
... ?
I've used the first for now, but there's no problem to change that.

Otherwise I think I've included all your comments and suggestions. The patch for 2.6.15.1 kernel is attached to this email.

I'll send documentation for the chip driver later.

Best regards,
Hartmut
-------------- next part --------------

Documentation/hwmon/sysfs-interface +14 -1
diff -uprN1 linux-2.6.15.1/Documentation/hwmon/sysfs-interface linux-2.6.15.1_changed/Documentation/hwmon/sysfs-interface
@@ -219,2 +219,8 @@ temp[1-2]_crit_hyst
 
+temp[1-4]_offset
+		Temperature offset which is added to the temperature reading
+		by the chip.
+		Unit: millidegree Celcius
+		Read/Write only value.
+
 		If there are multiple temperature sensors, temp1_* is
@@ -226,3 +232,2 @@ temp[1-2]_crit_hyst
 
-
 ************
@@ -263,2 +268,10 @@ alarms		Alarm bitmask.
 
+alarms_in	Alarm bit pattern for voltages, bits sorted in the order
+		of the in[0-8]_input. Bit 0 is the alarm for in0_input.
+alarms_temp	Alarm bit pattern for temperatures temp[1-4].
+		Bit 0 is the alarm for temp1_input.
+temp_faults	Bit pattern of detected temperature sensor faults
+		Bit 0 is the fault indicator for the temp1_input sensor.
+		A '1' bit means a sensor fault has been detected.
+
 beep_enable	Beep/interrupt enable
drivers/hwmon/Kconfig +11 -0
diff -uprN1 linux-2.6.15.1/drivers/hwmon/Kconfig linux-2.6.15.1_changed/drivers/hwmon/Kconfig
@@ -341,2 +341,13 @@ config SENSORS_SMSC47B397
 
+config SENSORS_SMSC47M192
+	tristate "SMSC LPC47M192 and compatibles"
+	depends on HWMON && I2C && EXPERIMENTAL
+	select HWMON_VID
+	help
+	  If you say yes here you get support for the hardware sensor
+	  capabilities of the SMSC LPC47M192 and LPC47M997 chips.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called smsc47m192.
+
 config SENSORS_VIA686A
drivers/hwmon/Makefile +1 -0
diff -uprN1 linux-2.6.15.1/drivers/hwmon/Makefile linux-2.6.15.1_changed/drivers/hwmon/Makefile
@@ -41,2 +41,3 @@ obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc4
 obj-$(CONFIG_SENSORS_SMSC47M1)	+= smsc47m1.o
+obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
 obj-$(CONFIG_SENSORS_VIA686A)	+= via686a.o
drivers/hwmon/smsc47m192.c +596 -0

596 lines not on this page · raw message

#1 lore raw

[lm-sensors] 2.6.15.1 Kernel patch for hardware monitoring

Hallo Hartmut,

Quoted 6 lines · Hartmut Rick
Quoted 5 lines

For newer designs, we try to have one sysfs file per alarm type (here, one for voltages and one for temperatures) with bits sorted for userspace. That way userspace doesn't need to know about the chip internals. Can you try to do that in your driver? You'd have one alarms_in file and one alarms_temp file.

Quoted 7 lines

What would I do with temperature sensor faults? Create another file? What would it be called?
temp_faults ?
alarms_temp_faults ?
faults_temp ?
... ?
I've used the first for now, but there's no problem to change that.

I didn't know that this chip had such a feature, and here again other drivers do not export these values in a standard way. I remember that the pc87360 driver exports tempN_status files, which contain three
flags: low limit crossed, high limit crossed, and open diode. The bit order matches the hardware registers rather than a defined standard, though. The FSC drivers also have "state" files, but the bits meaning differs.

So at this point we have several possibilities:
* Go with an alarms-like file, grouping by event and sensor type. If we follow the naming scheme, it would be named fault_temp.
* Go with a status file, grouping by channel; it would be named tempN_status. We'd need to standardize the meaning of each bit, and update the pc87360 and fsc* drivers accordingly where needed.
* Go with individual files: tempN_status_fault. These would hold boolean values (or almost-boolean if there are several possible fault cases).

Each of these possibilities has advantages and drawbacks in terms of driver size, speed, and interface compatibility.

My personal preference goes to the choice #3 (individual files) especially now that we have the dynamic sysfs callbacks in place. It's also convenient in the temperature sensor case as usually only some sensors will have a fault bit (external diodes). That being said, my previous attempt to define a standard sysfs interface wasn't exactly a success so I probably shouldn't be the one deciding. Comments/suggestions anyone?

Quoted 2 lines

Otherwise I think I've included all your comments and suggestions. The patch for 2.6.15.1 kernel is attached to this email.

Great, that was quick :)

Quoted 1 line

I'll send documentation for the chip driver later.

OK, thanks.

My comments follow:

Documentation/hwmon/sysfs-interface temp[1-2]_crit_hyst · line 233

Quoted 6 lines
Documentation/hwmon/sysfs-interface +0 -1
@@ -226,3 +232,2 @@ temp[1-2]_crit_hyst
 
-
 ************

Please avoid such whitespace changes in your patches, as they make the changes look bigger than they really are and make the review harder.

Documentation/hwmon/sysfs-interface alarms Alarm bitmask. · line 272

Quoted 6 lines
Documentation/hwmon/sysfs-interface +4 -0
@@ -263,2 +268,10 @@ alarms		Alarm bitmask.
 
+alarms_in	Alarm bit pattern for voltages, bits sorted in the order
+		of the in[0-8]_input. Bit 0 is the alarm for in0_input.
+alarms_temp	Alarm bit pattern for temperatures temp[1-4].
+		Bit 0 is the alarm for temp1_input.

These were already added in 2.6.16-rc3, please don't add them again.

drivers/hwmon/Kconfig config SENSORS_SMSC47B397 · line 348

Quoted 11 lines
drivers/hwmon/Kconfig +7 -0
@@ -341,2 +341,13 @@ config SENSORS_SMSC47B397
 
+config SENSORS_SMSC47M192
+	tristate "SMSC LPC47M192 and compatibles"
+	depends on HWMON && I2C && EXPERIMENTAL
+	select HWMON_VID
+	help
+	  If you say yes here you get support for the hardware sensor
+	  capabilities of the SMSC LPC47M192 and LPC47M997 chips.

It should be made clearer that this driver handles the temperature and voltage sensors, while the older smsc47m1 driver handles the fans. Some chips support both (47M15x and 47M192 I think), some will support only one of the drivers (anyone knows if the 47M997 has fan monitoring and control capabilities?)

At any rate, this option should immediately follow the smsc47m1 entry in the configuration menu, to make it even clearer that both drivers are related.

drivers/hwmon/Kconfig config SENSORS_SMSC47B397

Quoted 11 lines
drivers/hwmon/Kconfig +11 -0
+#define show_temp_index(index)					\
+static SENSOR_DEVICE_ATTR(temp##index##_input, S_IRUGO, 		\
+			show_temp, NULL, index);		\
+static SENSOR_DEVICE_ATTR(temp##index##_min, S_IRUGO | S_IWUSR,	\
+		show_temp_min, set_temp_min, index);		\
+static SENSOR_DEVICE_ATTR(temp##index##_max, S_IRUGO | S_IWUSR,	\
+		show_temp_max, set_temp_max, index);
+
+show_temp_index(1);
+show_temp_index(2);
+show_temp_index(3);

By slightly changing the SMSC47M192_REG_TEMP* macros, you should be able to internally number your temperature channels from 0, moving the -1/+1 offset from all the callback and update functions to the attribute declarations above, making it a bit more efficient. At your option though, it's not critical either.

drivers/hwmon/Kconfig

Quoted 4 lines
drivers/hwmon/Kconfig +4 -0
+static SENSOR_DEVICE_ATTR(temp2_offset, S_IRUGO | S_IWUSR,
+		show_temp_offset, set_temp_offset, 2);
+static SENSOR_DEVICE_ATTR(temp3_offset, S_IRUGO | S_IWUSR,
+		show_temp_offset, set_temp_offset, 3);

From your original post I had understood that temp1 and temp3 had offsets, rather than temp2 and temp3 as your code now has. Typo?

Note that I might have been misleading you with a previous comment about adding an unused u8 in the structure to make the temperature offset code more simple. On second reading, it is not necessary to do so, so I'm glad you didn't ;) But you still have a few offsets here and there, which should not be necessary.

I might provide an incremental later to tidy it all if you don't want to change it now.

drivers/hwmon/Kconfig

Quoted 7 lines
drivers/hwmon/Kconfig +7 -0
+static ssize_t show_raw_alarms(struct device *dev,
+			struct device_attribute *attr, char *buf)
+{
+	struct smsc47m192_data *data = smsc47m192_update_device(dev);
+	return sprintf(buf, "%u\n", data->raw_alarms);
+}
+static DEVICE_ATTR(alarms, S_IRUGO, show_raw_alarms, NULL);

Otherwise I'm quite happy with your code, thanks for the good work. There are a few more coding style issues I'll handle when pushing your script upwards, together with a few recent changes which are required for 2.6.16 compatibility.

--
Jean Delvare

#2 lore raw

[lm-sensors] 2.6.15.1 Kernel patch for hardware monitoring

In reply to Hartmut Rick

Hallo Hartmut,

Quoted 2 lines · Hartmut Rick

Otherwise I think I've included all your comments and suggestions. The patch for 2.6.15.1 kernel is attached to this email.

I've just read the datasheet and noticed a few things which your driver may not always be handling properly. Please comment on the following points, and update your driver code where needs be.

1* The LPC47M192 chip has two sampling modes, which can be selected using the bit 1 of register 0x4F. Currently your driver leaves the chip in the mode in which it was found. However, given that we do not allow the user to refresh the data more often than every 1.5 second, wouldn't it make sense to switch the device to "cycle mode" so as to save some power?

2* Bit 4 of register 0x4F may be used to make the second offset register (0x1F) apply to the internal temperature channel rather than the first external channel. If an external source (e.g. the BIOS) did this, then your driver will misbehave with regards to this offset register. A simple fix would be to create either temp1_offset or temp2_offset depending on the value of this bit.

3* The datasheet suggests that limits are left uninitialized at power-up. If so, your device initialization sequence should set the limits to sane values before it enables monitoring. By "sane", I mean register values of 0x00 for low limits and 0xff for high limits. The idea is to prevent random alarms from triggering on driver load. User-space tools may then be used to set more useful limit values.

If you happen not to need to start monitoring during the initialization step (i.e. the chip is already running) then you should not write the limit values to the registers so as to preserve the previous settings (possibly set by the BIOS.)

Thanks,
--
Jean Delvare

#3 lore raw

[lm-sensors] 2.6.15.1 Kernel patch for hardware monitoring

In reply to Hartmut Rick

Hi Jean,

Thanks a lot for your detailed comments and advice.

Quoted 11 lines · Jean Delvare

I've just read the datasheet and noticed a few things which your driver may not always be handling properly. Please comment on the following points, and update your driver code where needs be.

1* The LPC47M192 chip has two sampling modes, which can be selected using the bit 1 of register 0x4F. Currently your driver leaves the chip in the mode in which it was found. However, given that we do not allow the user to refresh the data more often than every 1.5 second, wouldn't it make sense to switch the device to "cycle mode" so as to save some power?

I have to admit that I've been a bit sloppy at my first attempt at the chip driver. I didn't bother to worry about power consumption, since the hardware monitoring block needs typically 1.2mA at a voltage of 3.3V, which makes a total of about 4mW. And it needs about half a second in order to complete all the conversions, so there is not much time during which it would not be active anyway.

But of course you're right, as long as we don't read it more often anyway we don't need it to sample more frequently.
I will change that.

There are more options, the sampling can be completed 8 times faster, with fewer conversions averaged. One could imagine to give the user access to configuration registers in order to choose these things. You could read the faster and (probably) noisier value and average in software in order to increase the resolution beyond the 1 degC level. I didn't plan to implement anything like this, though.

Quoted 7 lines

2* Bit 4 of register 0x4F may be used to make the second offset register (0x1F) apply to the internal temperature channel rather than the first external channel. If an external source (e.g. the BIOS) did this, then your driver will misbehave with regards to this offset register. A simple fix would be to create either temp1_offset or temp2_offset depending on the value of this bit.

Yes, I was wondering how to handle this one. If the user chooses to change the configuration bit, would this make the file temp2_offset disappear and temp1_offset to appear instead?
Of course an option is to simply not allow her to change that bit.

After thinking about this question, a possibility could be to actually create all 3 tempN_offset files. After all, the chip has the capability to add offsets to any of the temperature readings, just not to all of them simultaneously. The currently inactive offset reads as zero, and writing it with a nonzero value flips the configuration bit.
Thus writing a non-zero value to temp1_offset would reset temp2_offset to zero. Other than that, everything would work as expected, you can set an offset for any single temperature channel.
The configuration bit would not directly be accessible by the user.

Quoted 1 line

3* The datasheet suggests that limits are left uninitialized at power-up.

You're right, I will add the initialization you're suggesting.

Concerning the naming scheme of temperature fault files:

Quoted 13 lines

So at this point we have several possibilities:
* Go with an alarms-like file, grouping by event and sensor type. If we follow the naming scheme, it would be named fault_temp.
* Go with a status file, grouping by channel; it would be named tempN_status. We'd need to standardize the meaning of each bit, and update the pc87360 and fsc* drivers accordingly where needed.
* Go with individual files: tempN_status_fault. These would hold boolean values (or almost-boolean if there are several possible fault cases).

Each of these possibilities has advantages and drawbacks in terms of driver size, speed, and interface compatibility.

Quoted 8 lines

My personal preference goes to the choice #3 (individual files) especially now that we have the dynamic sysfs callbacks in place. It's also convenient in the temperature sensor case as usually only some sensors will have a fault bit (external diodes). That being said, my previous attempt to define a standard sysfs interface wasn't exactly a success so I probably shouldn't be the one deciding. Comments/suggestions anyone?

I like the idea of having separate files. A coherent and flexible convention would be to call the files tempN_input, tempN_max, tempN_min, tempN_offset, tempN_alarm, tempN_fault, tempN_ ...
This makes a large number of files, but all features that involve the temp1 channel would start with temp1_*, so they would appear grouped in the directory listing. Without ever reading any documentation, just listing the directory contents you can probably guess what's in each of these files.
A general userspace program can determine which files exist and thus which features this channel offers.
The file content would not necessarily need to be limited to one bit, so more than one kind of alarm or fault condition could be coded.

Now it seems that the alarms_temp file with one bit per channel has already been agreed upon, so the logical extension of this would be another file with the same bit assignment, called faults_temp. I feel like faults and alarms are somehow similar concepts. The disadvantage is that the file content does not allow to distinguish between 'no fault' and 'no information', the userspace program would have to obtain such information from some other source (configuration file?).

Quoted 2 lines
Quoted 1 line

From your original post I had understood that temp1 and temp3 had

offsets, rather than temp2 and temp3 as your code now has. Typo?

No, I really changed the numbering deliberately. The reason is that I've read the sysfs-interface documentation between my two posts :) It says that temp1 is supposed to be the temperature on the sensor chip. In the first version I had just ordered the channels by register address, so temp1 was CPU temperature.

Quoted 7 lines

drivers/hwmon/smsc47m192.c line 353

Quoted 7 lines
drivers/hwmon/smsc47m192.c +7 -0
+static ssize_t show_raw_alarms(struct device *dev,
+                     struct device_attribute *attr, char *buf)
+{
+     struct smsc47m192_data *data = smsc47m192_update_device(dev);
+     return sprintf(buf, "%u\n", data->raw_alarms);
+}
+static DEVICE_ATTR(alarms, S_IRUGO, show_raw_alarms, NULL);

You quoted this one but did not comment on it. I suppose you wanted to suggest to remove it?

I will implement all the other changes you suggested and send another patch, but I would prefer to do that after we agreed on the names and number of sysfs files.

Best wishes,
Hartmut

#4 lore raw

[lm-sensors] 2.6.15.1 Kernel patch for hardware monitoring

In reply to Hartmut Rick

Hi Hartmut,

Quoted 14 lines · Hartmut Rick
Quoted 6 lines

1* The LPC47M192 chip has two sampling modes, which can be selected using the bit 1 of register 0x4F. Currently your driver leaves the chip in the mode in which it was found. However, given that we do not allow the user to refresh the data more often than every 1.5 second, wouldn't it make sense to switch the device to "cycle mode" so as to save some power?

I have to admit that I've been a bit sloppy at my first attempt at the chip driver. I didn't bother to worry about power consumption, since the hardware monitoring block needs typically 1.2mA at a voltage of 3.3V, which makes a total of about 4mW. And it needs about half a second in order to complete all the conversions, so there is not much time during which it would not be active anyway.

Quoted 3 lines

But of course you're right, as long as we don't read it more often anyway we don't need it to sample more frequently.
I will change that.

Your analysis is correct and I admit it won't change that much the overall power consumption. But every saving we can get for free is good, so let's do it still.

Quoted 6 lines

There are more options, the sampling can be completed 8 times faster, with fewer conversions averaged. One could imagine to give the user access to configuration registers in order to choose these things. You could read the faster and (probably) noisier value and average in software in order to increase the resolution beyond the 1 degC level. I didn't plan to implement anything like this, though.

I see little point in the fast sampling mode due to our register cache implementation. Averaging in software is not buying you anything. In continuous mode you don't even save power. In cycle mode, the averaging won't work (sample frequency being too low.)

So I wouldn't provide the user with an option to change the averaging mode.
Just keep the mode your found the chip in, so as to preserve possible BIOS settings. The power-on default is averaging enabled, which is what we want.

Quoted 12 lines
Quoted 6 lines

2* Bit 4 of register 0x4F may be used to make the second offset register (0x1F) apply to the internal temperature channel rather than the first external channel. If an external source (e.g. the BIOS) did this, then your driver will misbehave with regards to this offset register. A simple fix would be to create either temp1_offset or temp2_offset depending on the value of this bit.

Yes, I was wondering how to handle this one. If the user chooses to change the configuration bit, would this make the file temp2_offset disappear and temp1_offset to appear instead?
Of course an option is to simply not allow her to change that bit.

Quoted 9 lines

After thinking about this question, a possibility could be to actually create all 3 tempN_offset files. After all, the chip has the capability to add offsets to any of the temperature readings, just not to all of them simultaneously. The currently inactive offset reads as zero, and writing it with a nonzero value flips the configuration bit.
Thus writing a non-zero value to temp1_offset would reset temp2_offset to zero. Other than that, everything would work as expected, you can set an offset for any single temperature channel.
The configuration bit would not directly be accessible by the user.

It might be a bit confusing to the user that setting a value arbitrarily kills another value. Given the little interest of the feature in the first place, I would go for the more simple approach of keeping the default/BIOS setting, and only create either temp1_offset or temp2_offset at driver load time, not allowing the user to change it afterwards. But the decision is really up to you, I don't care that much.

Quoted 4 lines

Concerning the naming scheme of temperature fault files:
(...)
I like the idea of having separate files. A coherent and flexible convention would be to call the files tempN_input, tempN_max, tempN_min,

Quoted 8 lines

tempN_offset, tempN_alarm, tempN_fault, tempN_ ...
This makes a large number of files, but all features that involve the temp1 channel would start with temp1_*, so they would appear grouped in the directory listing. Without ever reading any documentation, just listing the directory contents you can probably guess what's in each of these files.
A general userspace program can determine which files exist and thus which features this channel offers.

This was the whole point of the sysfs interface in the first place, but we failed for some points, in particular the chip status (alarm/fault/beep etc.) :( Good if we can get it right for the smsc47m192 driver right away.

Quoted 2 lines

The file content would not necessarily need to be limited to one bit, so more than one kind of alarm or fault condition could be coded.

True. This is how the _status files are working in pc87360 and fsc*, except that the meaning of each bit should be standardized across all driver. Also, a difference is that _status files were grouping alarms and faults, while you propose separate files.

Quoted 7 lines

Now it seems that the alarms_temp file with one bit per channel has already been agreed upon, so the logical extension of this would be another file with the same bit assignment, called faults_temp. I feel like faults and alarms are somehow similar concepts. The disadvantage is that the file content does not allow to distinguish between 'no fault' and 'no information', the userspace program would have to obtain such information from some other source (configuration file?).

The alarm_temp/_in/_fan files is something very recent and mostly mine - not really something that was collectively agreed upon. It was just not collectively disagreed upon ;) I introduced that as the most simple change to convert arbitrarily ordered alarm files we had before, to a chip-independant alarm representation. If we move to individual files, fine with me, as the aim is the same (chip-independant interface). Note that there is nothing preventing both representations to coexist for some time so we can move from one to the other relatively smoothly.

Quoted 8 lines
Quoted 2 lines

From your original post I had understood that temp1 and temp3 had offsets, rather than temp2 and temp3 as your code now has. Typo?

No, I really changed the numbering deliberately. The reason is that I've read the sysfs-interface documentation between my two posts :) It says that temp1 is supposed to be the temperature on the sensor chip. In the first version I had just ordered the channels by register address, so temp1 was CPU temperature.

Ah, this comment is somewhat misleading. It is (or was) referring to the most frequent natural order from a hardware point of view, and it happens that the drivers usually follow the hardware order. This comment was not meant as an invitation to reorder the temperature inputs at the driver level. So this order is really up to you; whatever makes the driver easier to write or makes more sense to you.

I'll go fix that comment, it's not even relevant with recent chips design.

Quoted 10 lines

drivers/hwmon/smsc47m192.c line 353

Quoted 7 lines
drivers/hwmon/smsc47m192.c +7 -0
+static ssize_t show_raw_alarms(struct device *dev,
+                     struct device_attribute *attr, char *buf)
+{
+     struct smsc47m192_data *data = smsc47m192_update_device(dev);
+     return sprintf(buf, "%u\n", data->raw_alarms);
+}
+static DEVICE_ATTR(alarms, S_IRUGO, show_raw_alarms, NULL);

You quoted this one but did not comment on it. I suppose you wanted to suggest to remove it?

Ah, yes, you're right, that's exactly what I wanted to suggest.

Quoted 3 lines

I will implement all the other changes you suggested and send another patch, but I would prefer to do that after we agreed on the names and number of sysfs files.

Sure. It seems that we both agree on the superiority of the individual files approach, so you can go with that and we'll see how the code looks like. It should be quite elegant, and you may even be able to have a single callback for all individual alarm and fault files. Just set the integer value associated to each file to the bit position in the status word, and that should do it. If it works well in your driver, it'll be a clear indication that most other drivers can be converted in the same way (even if we keep the old "alarms" file for compatibility reasons.)

If you have more questions, or if I have not been clear on some point, just tell me.

Thanks,
--
Jean Delvare