sysfs-interface 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. Naming and data format standards for sysfs files
  2. ------------------------------------------------
  3. The libsensors library offers an interface to the raw sensors data
  4. through the sysfs interface. See libsensors documentation and source for
  5. further information. As of writing this document, libsensors
  6. (from lm_sensors 2.8.3) is heavily chip-dependent. Adding or updating
  7. support for any given chip requires modifying the library's code.
  8. This is because libsensors was written for the procfs interface
  9. older kernel modules were using, which wasn't standardized enough.
  10. Recent versions of libsensors (from lm_sensors 2.8.2 and later) have
  11. support for the sysfs interface, though.
  12. The new sysfs interface was designed to be as chip-independent as
  13. possible.
  14. Note that motherboards vary widely in the connections to sensor chips.
  15. There is no standard that ensures, for example, that the second
  16. temperature sensor is connected to the CPU, or that the second fan is on
  17. the CPU. Also, some values reported by the chips need some computation
  18. before they make full sense. For example, most chips can only measure
  19. voltages between 0 and +4V. Other voltages are scaled back into that
  20. range using external resistors. Since the values of these resistors
  21. can change from motherboard to motherboard, the conversions cannot be
  22. hard coded into the driver and have to be done in user space.
  23. For this reason, even if we aim at a chip-independent libsensors, it will
  24. still require a configuration file (e.g. /etc/sensors.conf) for proper
  25. values conversion, labeling of inputs and hiding of unused inputs.
  26. An alternative method that some programs use is to access the sysfs
  27. files directly. This document briefly describes the standards that the
  28. drivers follow, so that an application program can scan for entries and
  29. access this data in a simple and consistent way. That said, such programs
  30. will have to implement conversion, labeling and hiding of inputs. For
  31. this reason, it is still not recommended to bypass the library.
  32. If you are developing a userspace application please send us feedback on
  33. this standard.
  34. Note that this standard isn't completely established yet, so it is subject
  35. to changes. If you are writing a new hardware monitoring driver those
  36. features can't seem to fit in this interface, please contact us with your
  37. extension proposal. Keep in mind that backward compatibility must be
  38. preserved.
  39. Each chip gets its own directory in the sysfs /sys/devices tree. To
  40. find all sensor chips, it is easier to follow the device symlinks from
  41. /sys/class/hwmon/hwmon*.
  42. All sysfs values are fixed point numbers.
  43. There is only one value per file, unlike the older /proc specification.
  44. The common scheme for files naming is: <type><number>_<item>. Usual
  45. types for sensor chips are "in" (voltage), "temp" (temperature) and
  46. "fan" (fan). Usual items are "input" (measured value), "max" (high
  47. threshold, "min" (low threshold). Numbering usually starts from 1,
  48. except for voltages which start from 0 (because most data sheets use
  49. this). A number is always used for elements that can be present more
  50. than once, even if there is a single element of the given type on the
  51. specific chip. Other files do not refer to a specific element, so
  52. they have a simple name, and no number.
  53. Alarms are direct indications read from the chips. The drivers do NOT
  54. make comparisons of readings to thresholds. This allows violations
  55. between readings to be caught and alarmed. The exact definition of an
  56. alarm (for example, whether a threshold must be met or must be exceeded
  57. to cause an alarm) is chip-dependent.
  58. When setting values of hwmon sysfs attributes, the string representation of
  59. the desired value must be written, note that strings which are not a number
  60. are interpreted as 0! For more on how written strings are interpreted see the
  61. "sysfs attribute writes interpretation" section at the end of this file.
  62. -------------------------------------------------------------------------
  63. [0-*] denotes any positive number starting from 0
  64. [1-*] denotes any positive number starting from 1
  65. RO read only value
  66. RW read/write value
  67. Read/write values may be read-only for some chips, depending on the
  68. hardware implementation.
  69. All entries (except name) are optional, and should only be created in a
  70. given driver if the chip has the feature.
  71. ********
  72. * Name *
  73. ********
  74. name The chip name.
  75. This should be a short, lowercase string, not containing
  76. spaces nor dashes, representing the chip name. This is
  77. the only mandatory attribute.
  78. I2C devices get this attribute created automatically.
  79. RO
  80. ************
  81. * Voltages *
  82. ************
  83. in[0-*]_min Voltage min value.
  84. Unit: millivolt
  85. RW
  86. in[0-*]_max Voltage max value.
  87. Unit: millivolt
  88. RW
  89. in[0-*]_input Voltage input value.
  90. Unit: millivolt
  91. RO
  92. Voltage measured on the chip pin.
  93. Actual voltage depends on the scaling resistors on the
  94. motherboard, as recommended in the chip datasheet.
  95. This varies by chip and by motherboard.
  96. Because of this variation, values are generally NOT scaled
  97. by the chip driver, and must be done by the application.
  98. However, some drivers (notably lm87 and via686a)
  99. do scale, because of internal resistors built into a chip.
  100. These drivers will output the actual voltage. Rule of
  101. thumb: drivers should report the voltage values at the
  102. "pins" of the chip.
  103. in[0-*]_label Suggested voltage channel label.
  104. Text string
  105. Should only be created if the driver has hints about what
  106. this voltage channel is being used for, and user-space
  107. doesn't. In all other cases, the label is provided by
  108. user-space.
  109. RO
  110. cpu[0-*]_vid CPU core reference voltage.
  111. Unit: millivolt
  112. RO
  113. Not always correct.
  114. vrm Voltage Regulator Module version number.
  115. RW (but changing it should no more be necessary)
  116. Originally the VRM standard version multiplied by 10, but now
  117. an arbitrary number, as not all standards have a version
  118. number.
  119. Affects the way the driver calculates the CPU core reference
  120. voltage from the vid pins.
  121. Also see the Alarms section for status flags associated with voltages.
  122. ********
  123. * Fans *
  124. ********
  125. fan[1-*]_min Fan minimum value
  126. Unit: revolution/min (RPM)
  127. RW
  128. fan[1-*]_input Fan input value.
  129. Unit: revolution/min (RPM)
  130. RO
  131. fan[1-*]_div Fan divisor.
  132. Integer value in powers of two (1, 2, 4, 8, 16, 32, 64, 128).
  133. RW
  134. Some chips only support values 1, 2, 4 and 8.
  135. Note that this is actually an internal clock divisor, which
  136. affects the measurable speed range, not the read value.
  137. fan[1-*]_target
  138. Desired fan speed
  139. Unit: revolution/min (RPM)
  140. RW
  141. Only makes sense if the chip supports closed-loop fan speed
  142. control based on the measured fan speed.
  143. fan[1-*]_label Suggested fan channel label.
  144. Text string
  145. Should only be created if the driver has hints about what
  146. this fan channel is being used for, and user-space doesn't.
  147. In all other cases, the label is provided by user-space.
  148. RO
  149. Also see the Alarms section for status flags associated with fans.
  150. *******
  151. * PWM *
  152. *******
  153. pwm[1-*] Pulse width modulation fan control.
  154. Integer value in the range 0 to 255
  155. RW
  156. 255 is max or 100%.
  157. pwm[1-*]_enable
  158. Fan speed control method:
  159. 0: no fan speed control (i.e. fan at full speed)
  160. 1: manual fan speed control enabled (using pwm[1-*])
  161. 2+: automatic fan speed control enabled
  162. Check individual chip documentation files for automatic mode
  163. details.
  164. RW
  165. pwm[1-*]_mode 0: DC mode (direct current)
  166. 1: PWM mode (pulse-width modulation)
  167. RW
  168. pwm[1-*]_freq Base PWM frequency in Hz.
  169. Only possibly available when pwmN_mode is PWM, but not always
  170. present even then.
  171. RW
  172. pwm[1-*]_auto_channels_temp
  173. Select which temperature channels affect this PWM output in
  174. auto mode. Bitfield, 1 is temp1, 2 is temp2, 4 is temp3 etc...
  175. Which values are possible depend on the chip used.
  176. RW
  177. pwm[1-*]_auto_point[1-*]_pwm
  178. pwm[1-*]_auto_point[1-*]_temp
  179. pwm[1-*]_auto_point[1-*]_temp_hyst
  180. Define the PWM vs temperature curve. Number of trip points is
  181. chip-dependent. Use this for chips which associate trip points
  182. to PWM output channels.
  183. RW
  184. OR
  185. temp[1-*]_auto_point[1-*]_pwm
  186. temp[1-*]_auto_point[1-*]_temp
  187. temp[1-*]_auto_point[1-*]_temp_hyst
  188. Define the PWM vs temperature curve. Number of trip points is
  189. chip-dependent. Use this for chips which associate trip points
  190. to temperature channels.
  191. RW
  192. ****************
  193. * Temperatures *
  194. ****************
  195. temp[1-*]_type Sensor type selection.
  196. Integers 1 to 6
  197. RW
  198. 1: PII/Celeron Diode
  199. 2: 3904 transistor
  200. 3: thermal diode
  201. 4: thermistor
  202. 5: AMD AMDSI
  203. 6: Intel PECI
  204. Not all types are supported by all chips
  205. temp[1-*]_max Temperature max value.
  206. Unit: millidegree Celsius (or millivolt, see below)
  207. RW
  208. temp[1-*]_min Temperature min value.
  209. Unit: millidegree Celsius
  210. RW
  211. temp[1-*]_max_hyst
  212. Temperature hysteresis value for max limit.
  213. Unit: millidegree Celsius
  214. Must be reported as an absolute temperature, NOT a delta
  215. from the max value.
  216. RW
  217. temp[1-*]_input Temperature input value.
  218. Unit: millidegree Celsius
  219. RO
  220. temp[1-*]_crit Temperature critical value, typically greater than
  221. corresponding temp_max values.
  222. Unit: millidegree Celsius
  223. RW
  224. temp[1-*]_crit_hyst
  225. Temperature hysteresis value for critical limit.
  226. Unit: millidegree Celsius
  227. Must be reported as an absolute temperature, NOT a delta
  228. from the critical value.
  229. RW
  230. temp[1-*]_offset
  231. Temperature offset which is added to the temperature reading
  232. by the chip.
  233. Unit: millidegree Celsius
  234. Read/Write value.
  235. temp[1-*]_label Suggested temperature channel label.
  236. Text string
  237. Should only be created if the driver has hints about what
  238. this temperature channel is being used for, and user-space
  239. doesn't. In all other cases, the label is provided by
  240. user-space.
  241. RO
  242. Some chips measure temperature using external thermistors and an ADC, and
  243. report the temperature measurement as a voltage. Converting this voltage
  244. back to a temperature (or the other way around for limits) requires
  245. mathematical functions not available in the kernel, so the conversion
  246. must occur in user space. For these chips, all temp* files described
  247. above should contain values expressed in millivolt instead of millidegree
  248. Celsius. In other words, such temperature channels are handled as voltage
  249. channels by the driver.
  250. Also see the Alarms section for status flags associated with temperatures.
  251. ************
  252. * Currents *
  253. ************
  254. Note that no known chip provides current measurements as of writing,
  255. so this part is theoretical, so to say.
  256. curr[1-*]_max Current max value
  257. Unit: milliampere
  258. RW
  259. curr[1-*]_min Current min value.
  260. Unit: milliampere
  261. RW
  262. curr[1-*]_input Current input value
  263. Unit: milliampere
  264. RO
  265. *********
  266. * Power *
  267. *********
  268. power[1-*]_average Average power use
  269. Unit: microWatt
  270. RO
  271. power[1-*]_average_highest Historical average maximum power use
  272. Unit: microWatt
  273. RO
  274. power[1-*]_average_lowest Historical average minimum power use
  275. Unit: microWatt
  276. RO
  277. power[1-*]_input Instantaneous power use
  278. Unit: microWatt
  279. RO
  280. power[1-*]_input_highest Historical maximum power use
  281. Unit: microWatt
  282. RO
  283. power[1-*]_input_lowest Historical minimum power use
  284. Unit: microWatt
  285. RO
  286. power[1-*]_reset_history Reset input_highest, input_lowest,
  287. average_highest and average_lowest.
  288. WO
  289. **********
  290. * Alarms *
  291. **********
  292. Each channel or limit may have an associated alarm file, containing a
  293. boolean value. 1 means than an alarm condition exists, 0 means no alarm.
  294. Usually a given chip will either use channel-related alarms, or
  295. limit-related alarms, not both. The driver should just reflect the hardware
  296. implementation.
  297. in[0-*]_alarm
  298. fan[1-*]_alarm
  299. temp[1-*]_alarm
  300. Channel alarm
  301. 0: no alarm
  302. 1: alarm
  303. RO
  304. OR
  305. in[0-*]_min_alarm
  306. in[0-*]_max_alarm
  307. fan[1-*]_min_alarm
  308. temp[1-*]_min_alarm
  309. temp[1-*]_max_alarm
  310. temp[1-*]_crit_alarm
  311. Limit alarm
  312. 0: no alarm
  313. 1: alarm
  314. RO
  315. Each input channel may have an associated fault file. This can be used
  316. to notify open diodes, unconnected fans etc. where the hardware
  317. supports it. When this boolean has value 1, the measurement for that
  318. channel should not be trusted.
  319. in[0-*]_fault
  320. fan[1-*]_fault
  321. temp[1-*]_fault
  322. Input fault condition
  323. 0: no fault occured
  324. 1: fault condition
  325. RO
  326. Some chips also offer the possibility to get beeped when an alarm occurs:
  327. beep_enable Master beep enable
  328. 0: no beeps
  329. 1: beeps
  330. RW
  331. in[0-*]_beep
  332. fan[1-*]_beep
  333. temp[1-*]_beep
  334. Channel beep
  335. 0: disable
  336. 1: enable
  337. RW
  338. In theory, a chip could provide per-limit beep masking, but no such chip
  339. was seen so far.
  340. Old drivers provided a different, non-standard interface to alarms and
  341. beeps. These interface files are deprecated, but will be kept around
  342. for compatibility reasons:
  343. alarms Alarm bitmask.
  344. RO
  345. Integer representation of one to four bytes.
  346. A '1' bit means an alarm.
  347. Chips should be programmed for 'comparator' mode so that
  348. the alarm will 'come back' after you read the register
  349. if it is still valid.
  350. Generally a direct representation of a chip's internal
  351. alarm registers; there is no standard for the position
  352. of individual bits. For this reason, the use of this
  353. interface file for new drivers is discouraged. Use
  354. individual *_alarm and *_fault files instead.
  355. Bits are defined in kernel/include/sensors.h.
  356. beep_mask Bitmask for beep.
  357. Same format as 'alarms' with the same bit locations,
  358. use discouraged for the same reason. Use individual
  359. *_beep files instead.
  360. RW
  361. sysfs attribute writes interpretation
  362. -------------------------------------
  363. hwmon sysfs attributes always contain numbers, so the first thing to do is to
  364. convert the input to a number, there are 2 ways todo this depending whether
  365. the number can be negative or not:
  366. unsigned long u = simple_strtoul(buf, NULL, 10);
  367. long s = simple_strtol(buf, NULL, 10);
  368. With buf being the buffer with the user input being passed by the kernel.
  369. Notice that we do not use the second argument of strto[u]l, and thus cannot
  370. tell when 0 is returned, if this was really 0 or is caused by invalid input.
  371. This is done deliberately as checking this everywhere would add a lot of
  372. code to the kernel.
  373. Notice that it is important to always store the converted value in an
  374. unsigned long or long, so that no wrap around can happen before any further
  375. checking.
  376. After the input string is converted to an (unsigned) long, the value should be
  377. checked if its acceptable. Be careful with further conversions on the value
  378. before checking it for validity, as these conversions could still cause a wrap
  379. around before the check. For example do not multiply the result, and only
  380. add/subtract if it has been divided before the add/subtract.
  381. What to do if a value is found to be invalid, depends on the type of the
  382. sysfs attribute that is being set. If it is a continuous setting like a
  383. tempX_max or inX_max attribute, then the value should be clamped to its
  384. limits using SENSORS_LIMIT(value, min_limit, max_limit). If it is not
  385. continuous like for example a tempX_type, then when an invalid value is
  386. written, -EINVAL should be returned.
  387. Example1, temp1_max, register is a signed 8 bit value (-128 - 127 degrees):
  388. long v = simple_strtol(buf, NULL, 10) / 1000;
  389. v = SENSORS_LIMIT(v, -128, 127);
  390. /* write v to register */
  391. Example2, fan divider setting, valid values 2, 4 and 8:
  392. unsigned long v = simple_strtoul(buf, NULL, 10);
  393. switch (v) {
  394. case 2: v = 1; break;
  395. case 4: v = 2; break;
  396. case 8: v = 3; break;
  397. default:
  398. return -EINVAL;
  399. }
  400. /* write v to register */