How to document dimension units for virtual files?
Pavel, Ingo,
Pavel Machek <[email protected]> wrote on 10/28/2006 07:40:48 PM:
Quoted 8 lines
Hi!
Quoted 6 lines
Quoted 1 line
Quoted 1 line
2. Encode dimension unit into filename (e.g.
onlinetime_msor
memory_kb)Quoted 4 lines
This is the recommended one.
- simple to implement and understand on both sides
[snip]
Quoted 11 lines
Quoted 9 lines
I also think that this is the best solution. It would be nice to have that documented somewhere. Maybe in the Documentation directory something like:
Howto export data in virtual files
==================================If you want to export data to userspace via virtual filesystems like procfs, sysfs, debugfs etc., the following rules are recommended:
...yes please... such patch would be nice.
What about the following ...
Michael
---
Documentation/filesystems/00-INDEX | 2 + Documentation/filesystems/ExportData | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
Documentation/filesystems/00-INDEX +2 -0
@@ -1,5 +1,7 @@ 00-INDEX - this file (info on some of the filesystems supported by linux). +ExportData + - recommendation of how to export data via virtual File Systems. Exporting - explanation of how to make filesystems exportable. Locking
Documentation/filesystems/ExportData +47 -0
47 lines not on this page · raw message
Quoted 51 lines · On Wed, 8 Nov 2006 17:54:12 +0100 Michael Holzheu wrote:
Pavel, Ingo,
Pavel Machek <[email protected]> wrote on 10/28/2006 07:40:48 PM:
Quoted 8 lines
Hi!
Quoted 6 lines
Quoted 1 line
Quoted 1 line
2. Encode dimension unit into filename (e.g.
onlinetime_msor
memory_kb)Quoted 4 lines
This is the recommended one.
- simple to implement and understand on both sides[snip]
Quoted 11 lines
Quoted 9 lines
I also think that this is the best solution. It would be nice to have that documented somewhere. Maybe in the Documentation directory something like:
Howto export data in virtual files
==================================If you want to export data to userspace via virtual filesystems like procfs, sysfs, debugfs etc., the following rules are recommended:
...yes please... such patch would be nice.
What about the following ...
Michael
---
Documentation/filesystems/00-INDEX | 2 + Documentation/filesystems/ExportData | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)diff -Naur linux-2.6.18/Documentation/filesystems/00-INDEX linux-2.6.18-exp-data-doc/Documentation/filesystems/00-INDEX
Documentation/filesystems/00-INDEX +2
-0@@ -1,5 +1,7 @@ 00-INDEX - this file (info on some of the filesystems supported by linux). +ExportData + - recommendation of how to export data via virtual File Systems. Exporting - explanation of how to make filesystems exportable. Lockingdiff -Naur linux-2.6.18/Documentation/filesystems/ExportData linux-2.6.18-exp-data-doc/Documentation/filesystems/ExportData
Documentation/filesystems/ExportData line 8
Quoted 8 lines
Documentation/filesystems/ExportData +8
-0@@ -0,0 +1,47 @@ + +Export data via virtual File Systems +==================================== + +If you want to export data to userspace via virtual filesystems +like procfs, sysfs, debugfs etc., the following rules are recommended: + +- Export only one value in one virtual file.
I don't think that makes sense for procfs. It's too late, but even it weren't, we don't need a large increase in the number of procfs files.
And debugfs shouldn't be constrained either.
It's not a regular user interface like sysfs is.
Documentation/filesystems/ExportData line 10
Quoted 2 lines
Documentation/filesystems/ExportData +2
-0+- Data format should be as simple as possible. +- Use ASCII formated strings, no binary data if possible.
* formatted
Quoted 28 lines
Documentation/filesystems/ExportData +28
-0+- If data has dimension units, encode that in the filename. + +Please use the following prefixes, when dimension units are required (According +to IEC 60027-2 and SI/International System of Units): + +Storage size (SI prefixes) +-------------------------- +* kB: kilobyte (10^3 Byte) +* MB: megabyte (10^6 Byte) +* GB: gigabyte (10^9 Byte) +* TB: terabyte (10^12 Byte) +* PB: petabyte (10^15 Byte) + +Storage size (Binary prefixes) +------------------------------ +* KiB: kibibyte (2^10 Byte) +* MiB: mebibyte (2^20 Byte) +* GiB: gibibyte (2^30 Byte) +* TiB: tebibyte (2^40 Byte) +* PiB: pebibyte (2^50 Byte) + +Time (SI pefixes) +----------------- +* s: Second +* ms: Millisecond (10^-3 Seconds) +* us: Microsecond (10^-6 Seconds) +* ns: Nanosecond (10^-9 Seconds) +
Documentation/filesystems/ExportData
Quoted 10 lines
Documentation/filesystems/ExportData +9
-1+Examples: +--------- +> ls /sys/kernel/debug/sysinfo +free_mem_KiB +online_time_ms +cpu_time_us + +> cat /sys/kernel/debug/free_mem_KiB +147536 -
---
~Randy
Randy,
Randy Dunlap <[email protected]> wrote on 11/08/2006 06:04:54 PM:
Quoted 1 line · On Wed, 8 Nov 2006 17:54:12 +0100 Michael Holzheu wrote:
[snip]
Quoted 17 lines
01:00:00.000000000 +0100
Quoted 1 line
+++ linux-2.6.18-exp-data-doc/Documentation/filesystems/ExportData
2006-11-08 17:44:59.000000000 +0100Documentation/filesystems/ExportData line 8
Quoted 9 lines
Documentation/filesystems/ExportData +8
-0@@ -0,0 +1,47 @@ + +Export data via virtual File Systems +==================================== + +If you want to export data to userspace via virtual filesystems +like procfs, sysfs, debugfs etc., the following rules are recommended: + +- Export only one value in one virtual file.I don't think that makes sense for procfs. It's too late, but even it weren't, we don't need a large increase in the number of procfs files.
Quoted 3 lines
And debugfs shouldn't be constrained either.
It's not a regular user interface like sysfs is.
Ok, fine:
If you want to export data to userspace via a virtual filesystem like sysfs, the following rules are recommended:
....
Michael
Quoted 2 lines · Michael Holzheu
If you want to export data to userspace via a virtual filesystem like sysfs, the following rules are recommended:
Um, does this mean you expect us to change all of the currently existing sysfs file names? And people get mad at me when I just move sysfs symlinks around...
Look at the hwmon drivers, and the documentation in Documentation/hwmon/sysfs-interface for a description of how we have been documenting this already.
In short, I don't really think we need to encode the units in the file name, somehow we have done pretty well without it so far :)
thanks,
greg k-h
Greg,
Greg KH <[email protected]> wrote on 11/10/2006 07:53:36 AM:
Quoted 7 lines · Michael Holzheu
Quoted 2 lines
If you want to export data to userspace via a virtual filesystem like sysfs, the following rules are recommended:
Um, does this mean you expect us to change all of the currently existing sysfs file names? And people get mad at me when I just move sysfs symlinks around...
No, of course we should not change existing kernel interfaces.
Quoted 3 lines
Look at the hwmon drivers, and the documentation in
Documentation/hwmon/sysfs-interfacefor a description of how we have been documenting this already.
Yes, it is an option to document units in seperate files. But I personally think,
that this is only the second best solution. Especially since normally documentation is not read.
Quoted 3 lines
In short, I don't really think we need to encode the units in the file name, somehow we have done pretty well without it so far :)
Why not trying to make things better than they used to be?
At least for our s390_hypfs I would like to use the suggested naming scheme. It is new and therefore not burdened with other naming conventions. Ok?
So, no "Documentation/filesystems/ExportData" patch?
Michael
Quoted 5 lines · Michael Holzheu
At least for our
s390_hypfsI would like to use the suggested naming scheme. It is new and therefore not burdened with other naming conventions. Ok?So, no "
Documentation/filesystems/ExportData" patch?
For now, I would not think so. Just document the file units in the Documentation/ABI/ directory and you should be fine.
thanks,
greg k-h
Hi!
Quoted 7 lines
Quoted 2 lines
If you want to export data to userspace via a virtual filesystem like sysfs, the following rules are recommended:
Um, does this mean you expect us to change all of the currently existing sysfs file names? And people get mad at me when I just move sysfs symlinks around...
Quoted 6 lines
Look at the hwmon drivers, and the documentation in
Documentation/hwmon/sysfs-interfacefor a description of how we have been documenting this already.In short, I don't really think we need to encode the units in the file name, somehow we have done pretty well without it so far :)
Well, problem is that some notebooks have battery capacity in mAh, and some in mWh, and you can't convert between those.
We could do something like
battery_stored_energy and battery_stored_current
(mWh) (mAh)
...but it looks ugly, and battery_capacity:mAh does not sound that bad for a new interface.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 4 lines · Pavel Machek
We could do something like
battery_stored_energyandbattery_stored_current
(mWh) (mAh)
"Energy" and "charge", please. You cannot store "current", it is an unit used to measure flows. Anyway, we are just repeating arguments that were made already in the battery thread...
And, please let's follow the SBS spec naming if possible for the attributes. They put a lot of thought on the way they named things. Again, this is already in the battery thread...
Quoted 2 lines
...but it looks ugly, and battery_capacity:mAh does not sound that bad for a new interface.
Indeed, battery_capacity:mWh and battery_capacity:mAh would work just fine and it does look better. But unless Greg changes his mind, it looks like we shall do without units in the filenames, which will also work just fine, if small enough units are choosen...
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Henrique de Moraes Holschuh <[email protected]> wrote on 11/13/2006 06:46:21 PM:
Quoted 1 line
and it does look better. But unless Greg changes his mind, it looks like
we
Quoted 1 line
shall do without units in the filenames, which will also work just fine,
if
Quoted 2 lines
small enough units are choosen...
As Arnd already said, at least for memory sizes this will work perfectly. There is no
smaller unit than a byte :-)
Michael
Jörn Engel
Acked-by Joern EngelQuoted 2 lines · Michael Holzheu
What about the following ...
Awesome. The next time someone flames me over this subject, I can simly refer to this file.
One could nitpick that a) this applies to any interface, so it also includes kernel command line and module parameters and b) there are existing interfaces that interpret "kb" as 2^10 bytes, etc. Maybe this could be noted somehow, but it's not too important imho.
Quoted 68 lines
Documentation/filesystems/00-INDEX | 2 + Documentation/filesystems/ExportData | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)diff -Naur linux-2.6.18/Documentation/filesystems/00-INDEX linux-2.6.18-exp-data-doc/Documentation/filesystems/00-INDEX
Documentation/filesystems/00-INDEX +2
-0@@ -1,5 +1,7 @@ 00-INDEX - this file (info on some of the filesystems supported by linux). +ExportData + - recommendation of how to export data via virtual File Systems. Exporting - explanation of how to make filesystems exportable. Lockingdiff -Naur linux-2.6.18/Documentation/filesystems/ExportData linux-2.6.18-exp-data-doc/Documentation/filesystems/ExportData
Documentation/filesystems/ExportData +47
-1@@ -0,0 +1,47 @@ + +Export data via virtual File Systems +==================================== + +If you want to export data to userspace via virtual filesystems +like procfs, sysfs, debugfs etc., the following rules are recommended: + +- Export only one value in one virtual file. +- Data format should be as simple as possible. +- Use ASCII formated strings, no binary data if possible. +- If data has dimension units, encode that in the filename. + +Please use the following prefixes, when dimension units are required (According +to IEC 60027-2 and SI/International System of Units): + +Storage size (SI prefixes) +-------------------------- +* kB: kilobyte (10^3 Byte) +* MB: megabyte (10^6 Byte) +* GB: gigabyte (10^9 Byte) +* TB: terabyte (10^12 Byte) +* PB: petabyte (10^15 Byte) + +Storage size (Binary prefixes) +------------------------------ +* KiB: kibibyte (2^10 Byte) +* MiB: mebibyte (2^20 Byte) +* GiB: gibibyte (2^30 Byte) +* TiB: tebibyte (2^40 Byte) +* PiB: pebibyte (2^50 Byte) + +Time (SI pefixes) +----------------- +* s: Second +* ms: Millisecond (10^-3 Seconds) +* us: Microsecond (10^-6 Seconds) +* ns: Nanosecond (10^-9 Seconds) + +Examples: +--------- +> ls /sys/kernel/debug/sysinfo +free_mem_KiB +online_time_ms +cpu_time_us + +> cat /sys/kernel/debug/free_mem_KiB +147536 -
Quoted 4 lines
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Jörn
Signature · 3 lines
Courage is not the absence of fear, but rather the judgement that something else is more important than fear. -- Ambrose Redmoon
Jörn Engel <[email protected]> wrote on 11/08/2006 06:09:16 PM:
Quoted 12 lines · Michael Holzheu
Quoted 2 lines
What about the following ...
Awesome. The next time someone flames me over this subject, I can simly refer to this file.
One could nitpick that a) this applies to any interface, so it also includes kernel command line and module parameters and b) there are existing interfaces that interpret "kb" as 2^10 bytes, etc. Maybe this could be noted somehow, but it's not too important imho.
a) Right, that is a more general "problem". But I am not sure, if I want to solve/decide that.
b) I wanted to document the recommendations, I didn't want to document what currently is done.
Michael
Quoted 1 line · Michael Holzheu
+- If data has dimension units, encode that in the filename.
Can we please encode units in the filename using a separator other than "_"? the reason for this is that _ is already_used_to_separate_words in the entries, and it gets difficult to know if something is part of the entry name or an unit.
Please consider using ":" to separate units and other specific qualifiers (e.g. led colors) from the main attribute name. This helps userspace applications to behave better when faced with stuff like "a_b_c:unit1" and "a_b_c:unit2" at the same time.
That said, AFAIK using units is explicitly discouraged on hwmon-style sysfs classes. The recent thread about a battery class illustrates this. Please keep this in mind.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Henrique,
Henrique de Moraes Holschuh <[email protected]> wrote on 11/08/2006 07:01:54 PM:
Quoted 4 lines · Michael Holzheu
Please consider using ":" to separate units and other specific qualifiers (e.g. led colors) from the main attribute name. This helps userspace applications to behave better when faced with stuff like "a_b_c:unit1"
and
Quoted 1 line
"a_b_c:unit2" at the same time.
":" is probably not a good idea. I think it is treated by the bash as a special
character. Try:
# touch test:ms # ls test <press tab> # ls test\:ms
Michael
Quoted 9 lines · Michael Holzheu
Quoted 4 lines
Please consider using ":" to separate units and other specific qualifiers (e.g. led colors) from the main attribute name. This helps userspace applications to behave better when faced with stuff like "a_b_c:unit1"
and
Quoted 1 line
"a_b_c:unit2" at the same time.
":" is probably not a good idea. I think it is treated by the bash as a special character. Try:
We could use some other char (but in that case, it is best to change what the led sysfs class is doing, they are already using ":", and that's why I suggested ":"). As long as it is not "_"...
That said, is it just a problem for the bash completion or does it *really* process the : to be something else?
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Hi!
Quoted 1 line
What about the following ...
Looks good to me.
Documentation/filesystems/ExportData line 47
Quoted 7 lines
+> ls
/sys/kernel/debug/sysinfoDocumentation/filesystems/ExportData +6
-0+free_mem_KiB +online_time_ms +cpu_time_us + +> cat /sys/kernel/debug/free_mem_KiB +147536
Someone had idea of free_mem:KiB ... which is quite neat.
Anyway, Greg's opinion was that we should just document units in documentation and not pollute names with that. I'm not sure if it works for battery (because of current:mA vs. current:mW confusion).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 1 line · Pavel Machek
Anyway, Greg's opinion was that we should just document units in documentation and not pollute names with that. I'm not sure if it works for battery (because of current:mA vs. current:mW confusion).
Well, IMO you should never have "current:mW" in any form whatsoever anyways. Electrically it makes no sense; it's like saying "height:grams". Watts are an indication of power emitted or consumed per unit time (as opposed to current/amperage which counts only the number of electrons and not the change in energy), so perhaps "power_flow:mW" or "power_consumption:mW" would make more sense?
I can conceivably see a need for a "current:mJ_per_s" versus "current:mW" depending on the hardware-reported units, but never both at the same time.
Cheers,
Kyle Moffett
Quoted 3 lines · Kyle Moffett
Well, IMO you should never have "current:mW" in any form whatsoever anyways. Electrically it makes no sense; it's like saying "height:grams".
Agreed!
Quoted 4 lines
Watts are an indication of power emitted or consumed per unit time (as opposed to current/amperage which counts only the number of electrons and not the change in energy), so perhaps "power_flow:mW" or "power_consumption:mW" would make more sense?
Current is flow of charge, in other words, charge per time. Flow has the notion of "per time" built into it. So "power flow" contains an extra "per time" compared to what you're looking for. Power, being energy per time, is already a flow (it's a flow of energy).
Perhaps because I'm writing a textbook on _The Art of Approximation_ (and finding formulas using dimensions is a main part of the art), I like to distinguish a quantity's dimensions from its units. The dimensions are universal, like energy or length or power; the units are their implementation in a particular system of measurement. In the SI system of units (a.k.a. the metric system), energy is measured in Joules, time in seconds, and power in Joules/seconds or Watts.
So all of the following make sense:
* "Power:mW"
* "energy flow: mW" (more verbose but equivalent)
* "energy flow: mJ/s" (even more verbose but also equivalent)
Quoted 3 lines
I can conceivably see a need for a "current:mJ_per_s" versus "current:mW" depending on the hardware-reported units, but never both at the same time.
I got lost here. mJ/s is the same as mW, so with either current:mW or current:mJ/s you're back in the soup of measuring current using units of power. If the hardware reports current, use "current: mA". If the hardware reports power, use "power: mW". Then applications can easily find out what's being reported and use it accordingly.
-Sanjoy
`Never underestimate the evil of which men of power are capable.'
--Bertrand Russell, _War Crimes in Vietnam_, chapter 1.
Quoted 7 lines · Sanjoy Mahajan
Quoted 1 line
Watts are an indication of power emitted or consumed per unit time (as opposed to current/amperage which counts only the number of electrons and not the change in energy), so perhaps "power_flow:mW" or "power_consumption:mW" would make more sense?
So all of the following make sense:
* "Power:mW"
* "energy flow: mW" (more verbose but equivalent)
* "energy flow: mJ/s" (even more verbose but also equivalent)
In this case the name is a sysfs file to indicate the load on the battery; so spaces are frowned upon and "load:mW" would probably work the best.
Quoted 3 lines
Quoted 1 line
I can conceivably see a need for a "current:mJ_per_s" versus "current:mW" depending on the hardware-reported units, but never both at the same time.
I got lost here. mJ/s is the same as mW, so with either current:mW or current:mJ/s you're back in the soup of measuring current using units of power
Whoops; sorry, I was writing this too early in the morning without my caffeine and got myself turned around. What I _meant_ to say was this:
"I conceivably see a need for a "load:mC_s" versus "load:mW", depending on the hardware-reported units, but never both at the same time."
Essentially if the hardware reports units of milli-watts or milli-Calories-per-second or whatever, then we should report that directly and let userspace convert as appropriate; keeping the floating-point out of the kernel.
Cheers,
Kyle Moffett