Skip to contentSkip to conversation

sysfs names

DISCUSSION Jean Delvare 5 participants 25 messages May 19, 2005

lore
Share & tools
lore
#0 lore raw

Hi all,

The more I work with new sysfs names, the more I wonder why the naming scheme was chosen the way it is. We had features named <type><number>_<subitem> for years, and now end up with files named <type>_<subitem><number>. Not only I don't see why a change was needed, but I definitely prefer the old naming scheme. It was much more logical, since "ls" would order them in a very logical way (grouping by type and sub-grouping by "physical entity").

What's more, the libsensors tweaks would be much more simple if we had stuck to the old scheme. Most of the required conversions are just moving from old scheme to new scheme with no other change.

Since the sysfs interface is obviously still not stabilized and we are still on early 2.6 kernels, I think we should consider moving back to the "old" names for the sake of consistency, beauty and logic.

Greg, don't look at me that way please. I am serious!

I know this is quite an important change, but precisely, we'd better change before porting the missing 30 chip drivers than after. I know how much work it will be - especially since I'll obviously be the one to cope with it - still I think we should do it.

Comments, thunder and rocks welcome ;)
Thanks.

NB: May I know the name of the brilliant chooser of the new naming scheme? Not to blame him/her (oh well... ;)) but to know the reasons of his/her choice.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#1 lore raw
Quoted 3 lines · Greg KH

That would be me. See the archives for what I propsed, and why I did it. Of course I can't remember what I said back then, and no one seemed to disagree...

I don't think I was reading you back then. Shame on me.

Quoted 8 lines · Philip Pokorny

I believe that Jean is proposing switching from:

temp_max1
temp_min1
temp1

to

Quoted 7 lines

temp1_max
temp1_min
temp1

So there still won't be multiple values in one "file", but the filenames will sort naturally into groupings similar to the way they were before.

That's the idea (except that it's temp_input1 -> temp1_input, not temp1).

At the time it was decided to switch to a one-file-per-value logic (and I agree it was a good idea), it would have been clever to use the library's symbol names as the files names. For one thing, it would simplify the libsensors tweaks we do these days. For another, it means that the future libsensors would be more simple as well (symbols in sensors.conf would point to the similarly-named sysfs name).

Left apart the fact that temp1_min (for example) is how symbols were named from the beginning, please also consider the fact that, as underlined by Philip, the files will then group in a much more natural way (in my opinion at least).

I also think that we will need to extend the scheme if we want the sysfs
interface to be truly chip-independant. For example, temp1_hyst is ambiguous, since you don't know which limit the hysteresis value applies to (more likely temp1_max, but for example in lm83 it applies to temp1_crit). So it would be better named temp1_max_hyst (resp. temp1_crit_hyst). Likewise, alarms are still chip-dependant and we could consider having files like temp1_max_alarm instead, much like Reinhard Nissl proposes in the new fscher chip driver.

To make it short, I'm worried by the fact that the new sysfs interface promises so many possibilities and we don't use them to their full potential. This is what motivates my call for an interface change.

Thanks.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#2 lore raw
In reply to Jean Delvare
Quoted 9 lines · Jean Delvare

Hi all,

The more I work with new sysfs names, the more I wonder why the naming scheme was chosen the way it is. We had features named <type><number>_<subitem> for years, and now end up with files named <type>_<subitem><number>. Not only I don't see why a change was needed, but I definitely prefer the old naming scheme. It was much more logical, since "ls" would order them in a very logical way (grouping by type and sub-grouping by "physical entity").

So can you give me an example of what you want to change?

Quoted 3 lines

What's more, the libsensors tweaks would be much more simple if we had stuck to the old scheme. Most of the required conversions are just moving from old scheme to new scheme with no other change.

We had other problems with the old scheme (multiple values per files being the biggest.)

Quoted 5 lines

Since the sysfs interface is obviously still not stabilized and we are still on early 2.6 kernels, I think we should consider moving back to the "old" names for the sake of consistency, beauty and logic.

Greg, don't look at me that way please. I am serious!

Heh, sorry for not getting back to you on this, been real busy lately...

Quoted 11 lines

I know this is quite an important change, but precisely, we'd better change before porting the missing 30 chip drivers than after. I know how much work it will be - especially since I'll obviously be the one to cope with it - still I think we should do it.

Comments, thunder and rocks welcome ;)
Thanks.

NB: May I know the name of the brilliant chooser of the new naming scheme? Not to blame him/her (oh well... ;)) but to know the reasons of his/her choice.

That would be me. See the archives for what I propsed, and why I did it. Of course I can't remember what I said back then, and no one seemed to disagree...

thanks,

greg k-h

#3 lore raw
In reply to Jean Delvare
Quoted 14 lines · Greg KH
Quoted 5 lines

I know this is quite an important change, but precisely, we'd better change before porting the missing 30 chip drivers than after. I know how much work it will be - especially since I'll obviously be the one to cope with it - still I think we should do it.

Quoted 8 lines

Comments, thunder and rocks welcome ;)
Thanks.

NB: May I know the name of the brilliant chooser of the new naming scheme? Not to blame him/her (oh well... ;)) but to know the reasons of his/her choice.

Quoted 5 lines

That would be me. See the archives for what I propsed, and why I did it. Of course I can't remember what I said back then, and no one seemed to disagree...

I think I did.

I believe that Jean is proposing switching from:

temp_max1
temp_min1
temp1

to

temp1_max
temp1_min
temp1

So there still won't be multiple values in one "file", but the filenames will sort naturally into groupings similar to the way they were before.

:v)

#4 lore raw
In reply to Jean Delvare
Quoted 8 lines
Quoted 7 lines

At the time it was decided to switch to a one-file-per-value logic (and I agree it was a good idea), it would have been clever to use the library's symbol names as the files names. For one thing, it would simplify the libsensors tweaks we do these days. For another, it means that the future libsensors would be more simple as well (symbols in sensors.conf would point to the similarly-named sysfs name).

Quoted 6 lines

Sorry about this, I wasn't really looking at the libsensors code at all, to think about if it would be easier or not to do this.

If it really makes the userspace code a lot simpler, I can be persuaded to convert all of the names (persuaded with patches that is...)

OK, I'll be working on this.

Quoted 1 line

It will have to be a 2.6.4 thing, as 2.6.3-rc2 is now out.

Of course. The 2.6.3 kernel had such a short cycle that it left everyone
puzzled, methinks.

Quoted 2 lines

But it would be wise to have these patches ready to go right after 2.6.3 comes out.

OK, I'll try to be ready then.

Quoted 10 lines
Quoted 9 lines

I also think that we will need to extend the scheme if we want the sysfs interface to be truly chip-independant. For example, temp1_hyst is ambiguous, since you don't know which limit the hysteresis value applies to (more likely temp1_max, but for example in lm83 it applies to temp1_crit). So it would be better named temp1_max_hyst (resp. temp1_crit_hyst). Likewise, alarms are still chip-dependant and we could consider having files like temp1_max_alarm instead, much like Reinhard Nissl proposes in the new fscher chip driver.

Quoted 2 lines

If we know this kind of information, that makes sense. I didn't see anything like this in the original proc file description.

The procfs files were not meant to be chip-independant at all. There were simple rules about file names and items orders within the files, but that was only meant as a help for developers. So there were no benefit to split alarms over correctly named files. Now this is completely different.

I think we'll have to keep the "alarms" files for a while anyway, because this is the only easy way that the existing libsensors will handle them. I don't think there is a problem with providing the same information twice through sysfs, if it helps the transition between old and new style.

Quoted 7 lines
Quoted 4 lines

To make it short, I'm worried by the fact that the new sysfs interface promises so many possibilities and we don't use them to their full potential. This is what motivates my call for an interface change.

Fair enough. We can still change, we keep telling users to upgrade lmsensors for every other kernel update, why not one more? :)

This is what I thought too. Of course, gkrellm people will blame us for that, but I guess they'll have to admit it is better that way (in the long term at least), and after all we already told them they should use libsensors instead of accessing the files directly.

The change will be much work indeed, I know that, but I think it is worth it. This means making changes to all the drivers in 2.6, and rework the compatibility layer in the library. I'll also have to update the sysfs-interface document. Sounds feasable anyway, or I wouldn't have proposed it.

I propose to divide the changes in three distinct steps:

1* Change the base scheme (temp_min1 -> temp1_min). This is the more important change.

2* Change the hysteresis names (temp1_hyst -> temp1_max_hyst). Only some drivers are impacted. Changes required to the library as well.

3* Add the splitted alarm files. This doesn't break the interface, but on the other hand needs that we think about it a bit more so that out choices are extendable and correct for all known drivers.

Thanks.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#5 lore raw
In reply to Jean Delvare
Quoted 29 lines · Jean Delvare
Quoted 3 lines · Greg KH

That would be me. See the archives for what I propsed, and why I did it. Of course I can't remember what I said back then, and no one seemed to disagree...

I don't think I was reading you back then. Shame on me.

Quoted 8 lines · Philip Pokorny

I believe that Jean is proposing switching from:

temp_max1
temp_min1
temp1

to

Quoted 7 lines

temp1_max
temp1_min
temp1

So there still won't be multiple values in one "file", but the filenames will sort naturally into groupings similar to the way they were before.

That's the idea (except that it's temp_input1 -> temp1_input, not temp1).

Quoted 6 lines

At the time it was decided to switch to a one-file-per-value logic (and I agree it was a good idea), it would have been clever to use the library's symbol names as the files names. For one thing, it would simplify the libsensors tweaks we do these days. For another, it means that the future libsensors would be more simple as well (symbols in sensors.conf would point to the similarly-named sysfs name).

Sorry about this, I wasn't really looking at the libsensors code at all, to think about if it would be easier or not to do this.

If it really makes the userspace code a lot simpler, I can be persuaded to convert all of the names (persuaded with patches that is...)

It will have to be a 2.6.4 thing, as 2.6.3-rc2 is now out. But it would be wise to have these patches ready to go right after 2.6.3 comes out.

Quoted 5 lines

Left apart the fact that temp1_min (for example) is how symbols were named from the beginning, please also consider the fact that, as underlined by Philip, the files will then group in a much more natural way (in my opinion at least).

Quoted 9 lines

I also think that we will need to extend the scheme if we want the sysfs
interface to be truly chip-independant. For example, temp1_hyst is ambiguous, since you don't know which limit the hysteresis value applies to (more likely temp1_max, but for example in lm83 it applies to temp1_crit). So it would be better named temp1_max_hyst (resp. temp1_crit_hyst). Likewise, alarms are still chip-dependant and we could consider having files like temp1_max_alarm instead, much like Reinhard Nissl proposes in the new fscher chip driver.

If we know this kind of information, that makes sense. I didn't see anything like this in the original proc file description.

Quoted 3 lines

To make it short, I'm worried by the fact that the new sysfs interface promises so many possibilities and we don't use them to their full potential. This is what motivates my call for an interface change.

Fair enough. We can still change, we keep telling users to upgrade lmsensors for every other kernel update, why not one more? :)

thanks,

greg k-h

#6 lore raw
In reply to Jean Delvare
Quoted 8 lines · Jean Delvare
Quoted 8 lines
Quoted 7 lines

At the time it was decided to switch to a one-file-per-value logic (and I agree it was a good idea), it would have been clever to use the library's symbol names as the files names. For one thing, it would simplify the libsensors tweaks we do these days. For another, it means that the future libsensors would be more simple as well (symbols in sensors.conf would point to the similarly-named sysfs name).

Quoted 8 lines
Quoted 6 lines

Sorry about this, I wasn't really looking at the libsensors code at all, to think about if it would be easier or not to do this.

If it really makes the userspace code a lot simpler, I can be persuaded to convert all of the names (persuaded with patches that is...)

OK, I'll be working on this.

Ok, how about writing up a summary of the proposal, listing the name changes you want to make, and why, and post it to lkml so that everyone has some advance notice of what will happen. They can then discuss anything that we might not have caught.

thanks,

greg k-h

#7 lore raw
In reply to Jean Delvare
Quoted 5 lines

Some temperature sensors have two types of alarms. An over-limit (max_alarm) alarm and a sensors failed alarm.

We could do this a couple of different ways:

Quoted 7 lines

1. Name the alarm file for a sensor: temp1_alarm and have it take one of several values: "" (null string), "ALARM", "FAIL"

2. Come up with another name for the other alarm: temp1_input_failed? temp1_fail_alarm?

3. Some other idea I haven't thought of?

Thanks for pointing that out. We really need to have a global view of all drivers if we want to make it correct on the first try, and there are at least two dozen chip drivers I never took a look at, so I need assistance.

My initial idea was 2. I wasn't thingking of failed yet (although I have to admit that at least one driver I have been working on does have it - lm83 or lm90, I can't remember). I was thinking of beeps, for chips that have a beeps register matching alarms.

This means that if we consider 1, we sometimes would need more than one string, because for example alarm and beep typically occur at the same time. Although this is easy to read for a human, it is likely to require some additional parsing code in the library.

If we now consider 2, this means that the number of files will increase significantly. For example, we can easily imagine a single temperature channel needing the following files:

temp1_input
temp1_min
temp1_max
temp1_max_hyst
temp1_over
temp1_over_hyst
temp1_alarm
temp1_fail
temp1_beep

Even more if you consider that there may be different alarm bits for different limits. For example, it would make sense to have something like:

temp1_input
temp1_fail
temp1_max
temp1_max_hyst
temp1_max_alarm
temp1_max_beep
temp1_over
temp1_over_hyst
temp1_over_alarm
temp1_over_beep

We could suspect that one single beep file would be sufficent, since we already can check the individual alarm files to see which limit has been crossed. But I think that some chips allow individual beep disabling, so if two alarms have triggered, it wouldn't be possible to determine because of which the system is beeping. The question is to know if we really care, or not.

Now that we speak about it, such systems would need additional files:

temp1_max_beep_enable
temp1_over_beep_enable

Think of complete monitoring chips such as the w83781d and family, this could lead to many, many files. The list above shows that we can reasonably expect 10 files per item, and such chips can have, say, 13 items, which leads to the very approximate value of 130 files (although fans and voltages probably will have less files in average than temperatures, so let's say 100 files total).

Greg, is it correct to have such a high number of sysfs files for a driver?

If not, I have a solution 3.

We could define an arbitrary bit order for indiviual alarm files, much in the idea of current alarm files, but where the order of the bits wouldn't be chip-dependant. Example:

1<<0 = alarm
1<<1 = beep
1<<2 = fail

This leaves some root for future extensions, while still limiting the number of files and being fast to "parse" (i.e. no parsing required). One drawback over 1 is that it is less easily readable by a human, also a simple rule apply (0 = OK, else there's at least one thing wrong). One drawback over 2 is that someone (or something) parsing the sysfs directory doesn't know wether a given bit is supported by the chip (unless that bit is set at the moment).

I see the sysfs files as a very interesting way to actually describe what a chip can do or not. This begins with the items themselves, then the limits/divisors/etc that apply to them, and it would probably be great if this could be extended to just anything, including alarm bits.

I think we really need to go on thinking about it all :)

Thanks.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#8 lore raw
In reply to Jean Delvare
Quoted 2 lines · Jean Delvare

Greg, is it correct to have such a high number of sysfs files for a driver?

That's fine to do. You might want to start using attribute lists to make it easier to register all of those files :)

thanks,

greg k-h

#9 lore raw
In reply to Jean Delvare
Quoted 6 lines · Greg KH
Quoted 2 lines · Jean Delvare

Greg, is it correct to have such a high number of sysfs files for a driver?

That's fine to do. You might want to start using attribute lists to make it easier to register all of those files :)

True enough, but that's not the part that bothers me.

It'd be nice if the driver could provide a parameter to the sysfs show() and store() routines... i.e.

static ssize_t show_temp(struct device *dev, char *buf, int param);

DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 1) DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 2) DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 3)

.. and so on. Then we could end the blizzard of tiny helper functions and the macro abuse. Try 'nm --size-sort w83781d.o' some time for an illustration.

But, I can't see a way to do this without forcing a massive rewrite of all sysfs-enabled drivers - oh well.

Regards,

Signature · 2 lines
Mark M. Hoffman
[email protected]
#10 lore raw
In reply to Jean Delvare
Quoted 8 lines

It'd be nice if the driver could provide a parameter to the sysfs show() and store() routines... i.e.

static ssize_t show_temp(struct device *dev, char *buf, int param);

DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 1) DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 2) DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 3)

Much like what we had in 2.4. And this was Good.

Quoted 3 lines

.. and so on. Then we could end the blizzard of tiny helper functions and the macro abuse. Try 'nm --size-sort w83781d.o' some time for an illustration.

Oh well, I didn't need nm to tell me what of a mess it is inside. Looking at the code was enough. When you come to use macros to define functions, there *must* be something wrong in your code design.

Quoted 2 lines

But, I can't see a way to do this without forcing a massive rewrite of all sysfs-enabled drivers - oh well.

Sad but probably true. Still I'd like to hear Greg about what it would take to do so, and if there is a chance that this happens in 2.7.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#11 lore raw
In reply to Jean Delvare
Quoted 11 lines
Quoted 6 lines

The procfs files were not meant to be chip-independant at all. There were simple rules about file names and items orders within the files, but that was only meant as a help for developers. So there were no benefit to split alarms over correctly named files. Now this is completely different.

For what it's worth, I think the /proc interface strived to be chip-independent. The new sysfs interface is certainly more chip-independent, but it's an evolution. We defined standards for /proc. We improved them for sysfs.

I know there were standards defined for /proc, but practically, this wasn't sufficent to write chipset-independent library and userspace tool code. We couldn't differenciate between temp min and temp hyst, for example. And the alarms/beeps bitmasks were (and still are) mapped on the registers, chipset-dependent again. And, more importantly, the magnitudes changed from driver to driver, and even from item to item. For some reason, this information was available from procfs but not when using ioctls (if I'm not mistaking), thus preventing us from having a even partly chipset-independent library.

I'd say that unless over 95% of the features can be retrieved reliably in a chipset-independent manner, you know you'll have to write chipset-dependent code, and don't even bother with trying to centralize code. I estimated to 75% the part of libsensors code that is chipset-dependent, and 90% of sensors. This is what I would like to get rid of.

Quoted 6 lines
Quoted 2 lines

1* Change the base scheme (temp_min1 -> temp1_min). This is the more important change.

If you have the energy to do this, fine, but at this point it doesn't seem worth the effort. I don't see how having them grouped alphabetically, for example, is much of a benefit to anybody.

Just in case there were any confusion, with "important" I meant "changes in many places required", not "the change the more important".

The grouping issue is important to me and probably to a few other developpers as well, although I have to admit it is a simple matter of convention and end-users don't care. That said, I think that the sysfs file discovering code will be easier to write with the proposed new convention. As a simple example, if you want to know if a chipset has temp1, looking for files beginning with "temp1_" is likely to be easier than looking for files beginning with "temp_" and ending with a "1" preceded by a non-digit. Likewise, getting the name of subitems bacomes as easy as reading the string from an arbitrary position (6 in the case of temp1_*), while you'll need to strip the trailing digit(s) with the current convention.

Of course, it mostlty depends on the implementation, but what I propose seems to allow for simplifications in many cases for at least the way I imagine I would be doing things.

And it still should help simplifying the 2.6 glue in the current libsensors, although this alone would of course not justify the change.

Quoted 6 lines
Quoted 2 lines

2* Change the hysteresis names (temp1_hyst -> temp1_max_hyst). Only some drivers are impacted. Changes required to the library as well.

Any drivers besides lm83 have more than one hyst per sensor? This is needed for the general case but in practice the usefulness is limited. A good idea but low priority.

The lm83 has a single hyst, shared among various sensors. This hyst applies to a common critical temperature limit. The 4 temperature sensors have their own high limit, which does *not* have an hysteresis. The current convention would make it impossible to know to what the hysteresis value applies. As we speak, the 2.6 implementation of the driver doesn't quite follow the standards (shame on me). I plan to fix that after the naming convention change, if it is to occur.

In a more general way, what matters is not only sensors with more than one hysteresis, but chipsets with more than one high limit. Both the lm80 and lm90 drivers are in this case, so we have at least 3 drivers and 4 chipsets that would benefit from the change.

And, once again, this is likely to simplify the sysfs files discovering code (because an hysteresis file can only apply to one limit, so the code won't have to look for other files to decide what to do with the value).

Quoted 6 lines
Quoted 3 lines

3* Add the splitted alarm files. This doesn't break the interface, but on the other hand needs that we think about it a bit more so that out choices are extendable and correct for all known drivers.

An excellent idea that really expands the information available in a chip-independent manner.

Yes, that's the idea :)

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#12 lore raw
In reply to Jean Delvare
Quoted 4 lines

Ok, how about writing up a summary of the proposal, listing the name changes you want to make, and why, and post it to lkml so that everyone has some advance notice of what will happen. They can then discuss anything that we might not have caught.

Hm, looks like this list is the adequate place for such a discussion (and I'm glad that everyone finally took part of it, because it is so important).

Posting the proposal alone on LKML is likely to duplicate the exchanges we had here. On the other hand, adding all the suggestions Philip Pokorny, Mark Hoffman and Mark Studebaker together with my answers will make the post long and possibly hard to read, and I am not sure people will want to read it.

Would it be correct to post a summary together with a link to this thread? That way, people who want to know more can read the whole story in a convenient form.

Thanks.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#13 lore raw
In reply to Jean Delvare
Quoted 15 lines · Mark M. Hoffman
Quoted 6 lines · Greg KH
Quoted 2 lines · Jean Delvare

Greg, is it correct to have such a high number of sysfs files for a driver?

That's fine to do. You might want to start using attribute lists to make it easier to register all of those files :)

True enough, but that's not the part that bothers me.

It'd be nice if the driver could provide a parameter to the sysfs show() and store() routines... i.e.

static ssize_t show_temp(struct device *dev, char *buf, int param);

Quoted 7 lines

DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 1) DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 2) DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 3)

... and so on. Then we could end the blizzard of tiny helper functions and the macro abuse. Try 'nm --size-sort w83781d.o' some time for an illustration.

Well we can always emulate something like the above with some macros :)

In looking at these drivers they can easily be shrunk today with just a bit of rewriting of the functions and macros. I sure wasn't thinking about driver size when writing the first few ones, and it looks like everyone has copied my "style" in the rest of them.

Quoted 2 lines

But, I can't see a way to do this without forcing a massive rewrite of all sysfs-enabled drivers - oh well.

Yeah, that's not going to happen, sorry.

thanks,

greg k-h

#14 lore raw
In reply to Jean Delvare
Quoted 10 lines · Jean Delvare
Quoted 8 lines

It'd be nice if the driver could provide a parameter to the sysfs show() and store() routines... i.e.

static ssize_t show_temp(struct device *dev, char *buf, int param);

DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 1) DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 2) DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 3)

Much like what we had in 2.4. And this was Good.

But we had multiple values per file, which was not "good" at all :)

Quoted 5 lines
Quoted 2 lines

But, I can't see a way to do this without forcing a massive rewrite of all sysfs-enabled drivers - oh well.

Sad but probably true. Still I'd like to hear Greg about what it would take to do so, and if there is a chance that this happens in 2.7.

I really doubt it, as it isn't on my list of things to do, but others might want to see helpers like this, and I always take patches...

thanks,

greg k-h

#15 lore raw
In reply to Jean Delvare
Quoted 15 lines · Jean Delvare
Quoted 4 lines

Ok, how about writing up a summary of the proposal, listing the name changes you want to make, and why, and post it to lkml so that everyone has some advance notice of what will happen. They can then discuss anything that we might not have caught.

Hm, looks like this list is the adequate place for such a discussion (and I'm glad that everyone finally took part of it, because it is so important).

Posting the proposal alone on LKML is likely to duplicate the exchanges we had here. On the other hand, adding all the suggestions Philip Pokorny, Mark Hoffman and Mark Studebaker together with my answers will make the post long and possibly hard to read, and I am not sure people will want to read it.

Quoted 3 lines

Would it be correct to post a summary together with a link to this thread? That way, people who want to know more can read the whole story in a convenient form.

I doubt that would be ok. We need to let the world know why we are changing a public interface during a "stable" kernel series. Remember, there are other users of the sysfs sensor interface other than lmsensors.

So I think a summary of what we want to change, and why to lkml is still necessary. If enough people object, we might be stuck with what we currently have...

thanks,

greg k-h

#16 lore raw
In reply to Jean Delvare
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

It'd be nice if the driver could provide a parameter to the sysfs show() and store() routines... i.e.

static ssize_t show_temp(struct device *dev, char *buf, int param);

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 1) DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 2) DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 3)

Much like what we had in 2.4. And this was Good.

But we had multiple values per file, which was not "good" at all :)

These are two completely different things. What Mark and I are pointing out here is that we used to have a *single* callback function for all tempN files. The fact that this function returned more than one value is unrelated.

The difficulty here is not with DEVICE_ATTR, since I guess we could easily write a new macro with one more attribute. The real thing is wether the current architecture would let us have sysfs callback routines with one extra argument, the value of which would depend on the sysfs file. But I fear that there is no way to associate an extra value to a sysfs file, nor to retrieve its name in the callback function, so whatever we do, we'll still end up with two callback functions per sysfs file.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#17 lore raw
In reply to Jean Delvare
Quoted 4 lines

In looking at these drivers they can easily be shrunk today with just a bit of rewriting of the functions and macros. I sure wasn't thinking about driver size when writing the first few ones, and it looks like everyone has copied my "style" in the rest of them.

If you could provide an example of how to do that, I'm interested in shrinking the existing drivers.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#18 lore raw
In reply to Jean Delvare
Quoted 8 lines
Quoted 3 lines

Would it be correct to post a summary together with a link to this thread? That way, people who want to know more can read the whole story in a convenient form.

I doubt that would be ok. We need to let the world know why we are changing a public interface during a "stable" kernel series. Remember, there are other users of the sysfs sensor interface other than lmsensors.

I only know of gkrellm doing that. Remember that accessing the sysfs files directly is strongly discouraged at the moment. And the change I propose would, in fact, make it safer (although still not recommended).

Whatever changes we do, people using libsensors are not affected (else than user need to upgrade their kernel and lm_sensors in sync). This is why I am proposing the change even during a stable series.

Quoted 3 lines

So I think a summary of what we want to change, and why to lkml is still necessary. If enough people object, we might be stuck with what we currently have...

I don't see much reason why people would object, except for the principle that nothing must change in stable releases. The facts are, our sysfs interface is just stabilizing now. There are a few existing drivers not following our own recommendations (lm83 at least), and to-be-ported driver that won't fit in it, so it'll need to be extended anyway.

We already have to handle two different interfaces in libsensors and user-space tools. This would be a real pain to have a third one as Linux 2.7 will start living. This is the reason why I want the interface to be cleanly redefined before the 2.6/2.7 fork occurs.

I'll prepare a long and detailed post for the LKML, and hope it will be convincing.

Thanks.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#19 lore raw
In reply to Jean Delvare
Quoted 11 lines · Jean Delvare

I propose to divide the changes in three distinct steps:

1* Change the base scheme (temp_min1 -> temp1_min). This is the more important change.

2* Change the hysteresis names (temp1_hyst -> temp1_max_hyst). Only some drivers are impacted. Changes required to the library as well.

3* Add the splitted alarm files. This doesn't break the interface, but on the other hand needs that we think about it a bit more so that out choices are extendable and correct for all known drivers.

Some temperature sensors have two types of alarms. An over-limit (max_alarm) alarm and a sensors failed alarm.

We could do this a couple of different ways:

1. Name the alarm file for a sensor: temp1_alarm and have it take one of several values: "" (null string), "ALARM", "FAIL"

2. Come up with another name for the other alarm: temp1_input_failed? temp1_fail_alarm?

3. Some other idea I haven't thought of?

FYI,
:v)

Signature · 4 lines
Philip Pokorny, Director of Engineering
Tel: 415-358-2635   Fax: 415-358-2646   Toll Free: 888-PENGUIN
PENGUIN COMPUTING, INC.
www.penguincomputing.com
#20 lore raw
In reply to Jean Delvare

I like solution #3.

Quoted 107 lines · Jean Delvare
Quoted 5 lines

Some temperature sensors have two types of alarms. An over-limit (max_alarm) alarm and a sensors failed alarm.

We could do this a couple of different ways:

Quoted 7 lines

1. Name the alarm file for a sensor: temp1_alarm and have it take one of several values: "" (null string), "ALARM", "FAIL"

2. Come up with another name for the other alarm: temp1_input_failed? temp1_fail_alarm?

3. Some other idea I haven't thought of?

Thanks for pointing that out. We really need to have a global view of all drivers if we want to make it correct on the first try, and there are at least two dozen chip drivers I never took a look at, so I need assistance.

My initial idea was 2. I wasn't thingking of failed yet (although I have to admit that at least one driver I have been working on does have it - lm83 or lm90, I can't remember). I was thinking of beeps, for chips that have a beeps register matching alarms.

This means that if we consider 1, we sometimes would need more than one string, because for example alarm and beep typically occur at the same time. Although this is easy to read for a human, it is likely to require some additional parsing code in the library.

If we now consider 2, this means that the number of files will increase significantly. For example, we can easily imagine a single temperature channel needing the following files:

temp1_input
temp1_min
temp1_max
temp1_max_hyst
temp1_over
temp1_over_hyst
temp1_alarm
temp1_fail
temp1_beep

Even more if you consider that there may be different alarm bits for different limits. For example, it would make sense to have something like:

temp1_input
temp1_fail
temp1_max
temp1_max_hyst
temp1_max_alarm
temp1_max_beep
temp1_over
temp1_over_hyst
temp1_over_alarm
temp1_over_beep

We could suspect that one single beep file would be sufficent, since we already can check the individual alarm files to see which limit has been crossed. But I think that some chips allow individual beep disabling, so if two alarms have triggered, it wouldn't be possible to determine because of which the system is beeping. The question is to know if we really care, or not.

Now that we speak about it, such systems would need additional files:

temp1_max_beep_enable
temp1_over_beep_enable

Think of complete monitoring chips such as the w83781d and family, this could lead to many, many files. The list above shows that we can reasonably expect 10 files per item, and such chips can have, say, 13 items, which leads to the very approximate value of 130 files (although fans and voltages probably will have less files in average than temperatures, so let's say 100 files total).

Greg, is it correct to have such a high number of sysfs files for a driver?

If not, I have a solution 3.

We could define an arbitrary bit order for indiviual alarm files, much in the idea of current alarm files, but where the order of the bits wouldn't be chip-dependant. Example:

1<<0 = alarm
1<<1 = beep
1<<2 = fail

This leaves some root for future extensions, while still limiting the number of files and being fast to "parse" (i.e. no parsing required). One drawback over 1 is that it is less easily readable by a human, also a simple rule apply (0 = OK, else there's at least one thing wrong). One drawback over 2 is that someone (or something) parsing the sysfs directory doesn't know wether a given bit is supported by the chip (unless that bit is set at the moment).

I see the sysfs files as a very interesting way to actually describe what a chip can do or not. This begins with the items themselves, then the limits/divisors/etc that apply to them, and it would probably be great if this could be extended to just anything, including alarm bits.

I think we really need to go on thinking about it all :)

Thanks.

#21 lore raw
In reply to Jean Delvare
Quoted 7 lines · Jean Delvare

The procfs files were not meant to be chip-independant at all. There were simple rules about file names and items orders within the files, but that was only meant as a help for developers. So there were no benefit to split alarms over correctly named files. Now this is completely different.

For what it's worth, I think the /proc interface strived to
be chip-independent. The new sysfs interface is certainly more chip-independent, but it's an evolution. We defined standards for /proc.
We improved them for sysfs.

Quoted 4 lines

1* Change the base scheme (temp_min1 -> temp1_min). This is the more important change.

If you have the energy to do this, fine, but at this point it doesn't seem worth the effort. I don't see how having them grouped alphabetically, for example, is much of a benefit to anybody.

Quoted 3 lines

2* Change the hysteresis names (temp1_hyst -> temp1_max_hyst). Only some drivers are impacted. Changes required to the library as well.

Any drivers besides lm83 have more than one hyst per sensor?
This is needed for the general case but in practice the usefulness is limited. A good idea but low priority.

Quoted 3 lines

3* Add the splitted alarm files. This doesn't break the interface, but on the other hand needs that we think about it a bit more so that out choices are extendable and correct for all known drivers.

An excellent idea that really expands the information available in a chip-independent manner.

#22 lore raw
In reply to Jean Delvare

According to "Mark M. Hoffman":

Quoted 2 lines

One little bit of refactoring I see is this... bah, it only saves ~19 lines and 150 bytes.

This is already done in your asb100 driver, right?

How much does it save from the binary?

Quoted 1 line

Is it worth it to do this to all the drivers?

I do like the change much. Yes, I think it is worth it. (Yes, I hate code duplication.)

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#23 lore raw
In reply to Jean Delvare
Quoted 7 lines · Jean Delvare
Quoted 4 lines

In looking at these drivers they can easily be shrunk today with just a bit of rewriting of the functions and macros. I sure wasn't thinking about driver size when writing the first few ones, and it looks like everyone has copied my "style" in the rest of them.

If you could provide an example of how to do that, I'm interested in shrinking the existing drivers.

Hm, I thought I saw some drivers that could be shrunk, but at a quick glance, I was wrong. It's probably not worth the complexity...

thanks,

greg k-h

#24 lore raw
In reply to Jean Delvare
Quoted 11 lines · Greg KH
Quoted 7 lines · Jean Delvare
Quoted 4 lines

In looking at these drivers they can easily be shrunk today with just a bit of rewriting of the functions and macros. I sure wasn't thinking about driver size when writing the first few ones, and it looks like everyone has copied my "style" in the rest of them.

If you could provide an example of how to do that, I'm interested in shrinking the existing drivers.

Hm, I thought I saw some drivers that could be shrunk, but at a quick glance, I was wrong. It's probably not worth the complexity...

One little bit of refactoring I see is this... bah, it only saves ~19 lines and 150 bytes. Is it worth it to do this to all the drivers? (compiles, untested but pretty trivial)

drivers/i2c/chips/lm78.c +16 -35
@@ -223,7 +223,7 @@
 
 static int lm78_read_value(struct i2c_client *client, u8 register);
 static int lm78_write_value(struct i2c_client *client, u8 register, u8 value);
-static void lm78_update_client(struct i2c_client *client);
+static struct lm78_data *lm78_update_device(struct device *dev);
 static void lm78_init_client(struct i2c_client *client);
 
 
@@ -239,25 +239,19 @@
 /* 7 Voltages */
 static ssize_t show_in(struct device *dev, char *buf, int nr)
 {
-	struct i2c_client *client = to_i2c_client(dev);
-	struct lm78_data *data = i2c_get_clientdata(client);
-	lm78_update_client(client);
+	struct lm78_data *data = lm78_update_device(dev);
 	return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
 }
 
 static ssize_t show_in_min(struct device *dev, char *buf, int nr)
 {
-	struct i2c_client *client = to_i2c_client(dev);
-	struct lm78_data *data = i2c_get_clientdata(client);
-	lm78_update_client(client);
+	struct lm78_data *data = lm78_update_device(dev);
 	return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
 }
 
 static ssize_t show_in_max(struct device *dev, char *buf, int nr)
 {
-	struct i2c_client *client = to_i2c_client(dev);
-	struct lm78_data *data = i2c_get_clientdata(client);
-	lm78_update_client(client);
+	struct lm78_data *data = lm78_update_device(dev);
 	return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
 }
 
@@ -327,17 +321,13 @@
 /* Temperature */
 static ssize_t show_temp(struct device *dev, char *buf)
 {
-	struct i2c_client *client = to_i2c_client(dev);
-	struct lm78_data *data = i2c_get_clientdata(client);
-	lm78_update_client(client);
+	struct lm78_data *data = lm78_update_device(dev);
 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp));
 }
 
 static ssize_t show_temp_over(struct device *dev, char *buf)
 {
-	struct i2c_client *client = to_i2c_client(dev);
-	struct lm78_data *data = i2c_get_clientdata(client);
-	lm78_update_client(client);
+	struct lm78_data *data = lm78_update_device(dev);
 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over));
 }
 
@@ -353,9 +343,7 @@
 
 static ssize_t show_temp_hyst(struct device *dev, char *buf)
 {
-	struct i2c_client *client = to_i2c_client(dev);
-	struct lm78_data *data = i2c_get_clientdata(client);
-	lm78_update_client(client);
+	struct lm78_data *data = lm78_update_device(dev);
 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst));
 }
 
@@ -378,18 +366,14 @@
 /* 3 Fans */
 static ssize_t show_fan(struct device *dev, char *buf, int nr)
 {
-	struct i2c_client *client = to_i2c_client(dev);
-	struct lm78_data *data = i2c_get_clientdata(client);
-	lm78_update_client(client);
+	struct lm78_data *data = lm78_update_device(dev);
 	return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
 		DIV_FROM_REG(data->fan_div[nr])) );
 }
 
 static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
 {
-	struct i2c_client *client = to_i2c_client(dev);
-	struct lm78_data *data = i2c_get_clientdata(client);
-	lm78_update_client(client);
+	struct lm78_data *data = lm78_update_device(dev);
 	return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
 		DIV_FROM_REG(data->fan_div[nr])) );
 }
@@ -407,9 +391,7 @@
 
 static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
 {
-	struct i2c_client *client = to_i2c_client(dev);
-	struct lm78_data *data = i2c_get_clientdata(client);
-	lm78_update_client(client);
+	struct lm78_data *data = lm78_update_device(dev);
 	return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) );
 }
 
@@ -490,9 +472,7 @@
 /* VID */
 static ssize_t show_vid(struct device *dev, char *buf)
 {
-	struct i2c_client *client = to_i2c_client(dev);
-	struct lm78_data *data = i2c_get_clientdata(client);
-	lm78_update_client(client);
+	struct lm78_data *data = lm78_update_device(dev);
 	return sprintf(buf, "%d\n", VID_FROM_REG(data->vid));
 }
 static DEVICE_ATTR(vid, S_IRUGO, show_vid, NULL);
@@ -500,9 +480,7 @@
 /* Alarms */
 static ssize_t show_alarms(struct device *dev, char *buf)
 {
-	struct i2c_client *client = to_i2c_client(dev);
-	struct lm78_data *data = i2c_get_clientdata(client);
-	lm78_update_client(client);
+	struct lm78_data *data = lm78_update_device(dev);
 	return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->alarms));
 }
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
@@ -829,8 +807,9 @@
 
 }
 
-static void lm78_update_client(struct i2c_client *client)
+static struct lm78_data *lm78_update_device(struct device *dev)
 {
+	struct i2c_client *client = to_i2c_client(dev);
 	struct lm78_data *data = i2c_get_clientdata(client);
 	int i;
 
@@ -879,6 +858,8 @@
 	}
 
 	up(&data->update_lock);
+
+	return data;
 }
 
 static int __init sm_lm78_init(void)

Regards,

Signature · 2 lines
Mark M. Hoffman
[email protected]