sysfs-interface.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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. Since lm-sensors 3.0.0, libsensors is
  5. completely chip-independent. It assumes that all the kernel drivers
  6. implement the standard sysfs interface described in this document.
  7. This makes adding or updating support for any given chip very easy, as
  8. libsensors, and applications using it, do not need to be modified.
  9. This is a major improvement compared to lm-sensors 2.
  10. Note that motherboards vary widely in the connections to sensor chips.
  11. There is no standard that ensures, for example, that the second
  12. temperature sensor is connected to the CPU, or that the second fan is on
  13. the CPU. Also, some values reported by the chips need some computation
  14. before they make full sense. For example, most chips can only measure
  15. voltages between 0 and +4V. Other voltages are scaled back into that
  16. range using external resistors. Since the values of these resistors
  17. can change from motherboard to motherboard, the conversions cannot be
  18. hard coded into the driver and have to be done in user space.
  19. For this reason, even if we aim at a chip-independent libsensors, it will
  20. still require a configuration file (e.g. /etc/sensors.conf) for proper
  21. values conversion, labeling of inputs and hiding of unused inputs.
  22. An alternative method that some programs use is to access the sysfs
  23. files directly. This document briefly describes the standards that the
  24. drivers follow, so that an application program can scan for entries and
  25. access this data in a simple and consistent way. That said, such programs
  26. will have to implement conversion, labeling and hiding of inputs. For
  27. this reason, it is still not recommended to bypass the library.
  28. Each chip gets its own directory in the sysfs /sys/devices tree. To
  29. find all sensor chips, it is easier to follow the device symlinks from
  30. `/sys/class/hwmon/hwmon*`.
  31. Up to lm-sensors 3.0.0, libsensors looks for hardware monitoring attributes
  32. in the "physical" device directory. Since lm-sensors 3.0.1, attributes found
  33. in the hwmon "class" device directory are also supported. Complex drivers
  34. (e.g. drivers for multifunction chips) may want to use this possibility to
  35. avoid namespace pollution. The only drawback will be that older versions of
  36. libsensors won't support the driver in question.
  37. All sysfs values are fixed point numbers.
  38. There is only one value per file, unlike the older /proc specification.
  39. The common scheme for files naming is: <type><number>_<item>. Usual
  40. types for sensor chips are "in" (voltage), "temp" (temperature) and
  41. "fan" (fan). Usual items are "input" (measured value), "max" (high
  42. threshold, "min" (low threshold). Numbering usually starts from 1,
  43. except for voltages which start from 0 (because most data sheets use
  44. this). A number is always used for elements that can be present more
  45. than once, even if there is a single element of the given type on the
  46. specific chip. Other files do not refer to a specific element, so
  47. they have a simple name, and no number.
  48. Alarms are direct indications read from the chips. The drivers do NOT
  49. make comparisons of readings to thresholds. This allows violations
  50. between readings to be caught and alarmed. The exact definition of an
  51. alarm (for example, whether a threshold must be met or must be exceeded
  52. to cause an alarm) is chip-dependent.
  53. When setting values of hwmon sysfs attributes, the string representation of
  54. the desired value must be written, note that strings which are not a number
  55. are interpreted as 0! For more on how written strings are interpreted see the
  56. "sysfs attribute writes interpretation" section at the end of this file.
  57. Attribute access
  58. ----------------
  59. Hardware monitoring sysfs attributes are displayed by unrestricted userspace
  60. applications. For this reason, all standard ABI attributes shall be world
  61. readable. Writeable standard ABI attributes shall be writeable only for
  62. privileged users.
  63. -------------------------------------------------------------------------
  64. ======= ===========================================
  65. `[0-*]` denotes any positive number starting from 0
  66. `[1-*]` denotes any positive number starting from 1
  67. RO read only value
  68. WO write only value
  69. RW read/write value
  70. ======= ===========================================
  71. Read/write values may be read-only for some chips, depending on the
  72. hardware implementation.
  73. All entries (except name) are optional, and should only be created in a
  74. given driver if the chip has the feature.
  75. See Documentation/ABI/testing/sysfs-class-hwmon for a complete description
  76. of the attributes.
  77. *****************
  78. Global attributes
  79. *****************
  80. `name`
  81. The chip name.
  82. `label`
  83. A descriptive label that allows to uniquely identify a device
  84. within the system.
  85. `update_interval`
  86. The interval at which the chip will update readings.
  87. ********
  88. Voltages
  89. ********
  90. `in[0-*]_min`
  91. Voltage min value.
  92. `in[0-*]_lcrit`
  93. Voltage critical min value.
  94. `in[0-*]_max`
  95. Voltage max value.
  96. `in[0-*]_crit`
  97. Voltage critical max value.
  98. `in[0-*]_input`
  99. Voltage input value.
  100. `in[0-*]_average`
  101. Average voltage
  102. `in[0-*]_lowest`
  103. Historical minimum voltage
  104. `in[0-*]_highest`
  105. Historical maximum voltage
  106. `in[0-*]_reset_history`
  107. Reset inX_lowest and inX_highest
  108. `in_reset_history`
  109. Reset inX_lowest and inX_highest for all sensors
  110. `in[0-*]_label`
  111. Suggested voltage channel label.
  112. `in[0-*]_enable`
  113. Enable or disable the sensors.
  114. `cpu[0-*]_vid`
  115. CPU core reference voltage.
  116. `vrm`
  117. Voltage Regulator Module version number.
  118. `in[0-*]_rated_min`
  119. Minimum rated voltage.
  120. `in[0-*]_rated_max`
  121. Maximum rated voltage.
  122. Also see the Alarms section for status flags associated with voltages.
  123. ****
  124. Fans
  125. ****
  126. `fan[1-*]_min`
  127. Fan minimum value
  128. `fan[1-*]_max`
  129. Fan maximum value
  130. `fan[1-*]_input`
  131. Fan input value.
  132. `fan[1-*]_div`
  133. Fan divisor.
  134. `fan[1-*]_pulses`
  135. Number of tachometer pulses per fan revolution.
  136. `fan[1-*]_target`
  137. Desired fan speed
  138. `fan[1-*]_label`
  139. Suggested fan channel label.
  140. `fan[1-*]_enable`
  141. Enable or disable the sensors.
  142. Also see the Alarms section for status flags associated with fans.
  143. ***
  144. PWM
  145. ***
  146. `pwm[1-*]`
  147. Pulse width modulation fan control.
  148. `pwm[1-*]_enable`
  149. Fan speed control method:
  150. `pwm[1-*]_mode`
  151. direct current or pulse-width modulation.
  152. `pwm[1-*]_freq`
  153. Base PWM frequency in Hz.
  154. `pwm[1-*]_auto_channels_temp`
  155. Select which temperature channels affect this PWM output in
  156. auto mode.
  157. `pwm[1-*]_auto_point[1-*]_pwm` / `pwm[1-*]_auto_point[1-*]_temp` / `pwm[1-*]_auto_point[1-*]_temp_hyst`
  158. Define the PWM vs temperature curve.
  159. `temp[1-*]_auto_point[1-*]_pwm` / `temp[1-*]_auto_point[1-*]_temp` / `temp[1-*]_auto_point[1-*]_temp_hyst`
  160. Define the PWM vs temperature curve.
  161. There is a third case where trip points are associated to both PWM output
  162. channels and temperature channels: the PWM values are associated to PWM
  163. output channels while the temperature values are associated to temperature
  164. channels. In that case, the result is determined by the mapping between
  165. temperature inputs and PWM outputs. When several temperature inputs are
  166. mapped to a given PWM output, this leads to several candidate PWM values.
  167. The actual result is up to the chip, but in general the highest candidate
  168. value (fastest fan speed) wins.
  169. ************
  170. Temperatures
  171. ************
  172. `temp[1-*]_type`
  173. Sensor type selection.
  174. `temp[1-*]_max`
  175. Temperature max value.
  176. `temp[1-*]_min`
  177. Temperature min value.
  178. `temp[1-*]_max_hyst`
  179. Temperature hysteresis value for max limit.
  180. `temp[1-*]_min_hyst`
  181. Temperature hysteresis value for min limit.
  182. `temp[1-*]_input`
  183. Temperature input value.
  184. `temp[1-*]_crit`
  185. Temperature critical max value, typically greater than
  186. corresponding temp_max values.
  187. `temp[1-*]_crit_hyst`
  188. Temperature hysteresis value for critical limit.
  189. `temp[1-*]_emergency`
  190. Temperature emergency max value, for chips supporting more than
  191. two upper temperature limits.
  192. `temp[1-*]_emergency_hyst`
  193. Temperature hysteresis value for emergency limit.
  194. `temp[1-*]_lcrit`
  195. Temperature critical min value, typically lower than
  196. corresponding temp_min values.
  197. `temp[1-*]_lcrit_hyst`
  198. Temperature hysteresis value for critical min limit.
  199. `temp[1-*]_offset`
  200. Temperature offset which is added to the temperature reading
  201. by the chip.
  202. `temp[1-*]_label`
  203. Suggested temperature channel label.
  204. `temp[1-*]_lowest`
  205. Historical minimum temperature
  206. `temp[1-*]_highest`
  207. Historical maximum temperature
  208. `temp[1-*]_reset_history`
  209. Reset temp_lowest and temp_highest
  210. `temp_reset_history`
  211. Reset temp_lowest and temp_highest for all sensors
  212. `temp[1-*]_enable`
  213. Enable or disable the sensors.
  214. `temp[1-*]_rated_min`
  215. Minimum rated temperature.
  216. `temp[1-*]_rated_max`
  217. Maximum rated temperature.
  218. Some chips measure temperature using external thermistors and an ADC, and
  219. report the temperature measurement as a voltage. Converting this voltage
  220. back to a temperature (or the other way around for limits) requires
  221. mathematical functions not available in the kernel, so the conversion
  222. must occur in user space. For these chips, all temp* files described
  223. above should contain values expressed in millivolt instead of millidegree
  224. Celsius. In other words, such temperature channels are handled as voltage
  225. channels by the driver.
  226. Also see the Alarms section for status flags associated with temperatures.
  227. ********
  228. Currents
  229. ********
  230. `curr[1-*]_max`
  231. Current max value.
  232. `curr[1-*]_min`
  233. Current min value.
  234. `curr[1-*]_lcrit`
  235. Current critical low value
  236. `curr[1-*]_crit`
  237. Current critical high value.
  238. `curr[1-*]_input`
  239. Current input value.
  240. `curr[1-*]_average`
  241. Average current use.
  242. `curr[1-*]_lowest`
  243. Historical minimum current.
  244. `curr[1-*]_highest`
  245. Historical maximum current.
  246. `curr[1-*]_reset_history`
  247. Reset currX_lowest and currX_highest
  248. WO
  249. `curr_reset_history`
  250. Reset currX_lowest and currX_highest for all sensors.
  251. `curr[1-*]_enable`
  252. Enable or disable the sensors.
  253. `curr[1-*]_rated_min`
  254. Minimum rated current.
  255. `curr[1-*]_rated_max`
  256. Maximum rated current.
  257. Also see the Alarms section for status flags associated with currents.
  258. *****
  259. Power
  260. *****
  261. `power[1-*]_average`
  262. Average power use.
  263. `power[1-*]_average_interval`
  264. Power use averaging interval.
  265. `power[1-*]_average_interval_max`
  266. Maximum power use averaging interval.
  267. `power[1-*]_average_interval_min`
  268. Minimum power use averaging interval.
  269. `power[1-*]_average_highest`
  270. Historical average maximum power use
  271. `power[1-*]_average_lowest`
  272. Historical average minimum power use
  273. `power[1-*]_average_max`
  274. A poll notification is sent to `power[1-*]_average` when
  275. power use rises above this value.
  276. `power[1-*]_average_min`
  277. A poll notification is sent to `power[1-*]_average` when
  278. power use sinks below this value.
  279. `power[1-*]_input`
  280. Instantaneous power use.
  281. `power[1-*]_input_highest`
  282. Historical maximum power use
  283. `power[1-*]_input_lowest`
  284. Historical minimum power use.
  285. `power[1-*]_reset_history`
  286. Reset input_highest, input_lowest, average_highest and
  287. average_lowest.
  288. `power[1-*]_accuracy`
  289. Accuracy of the power meter.
  290. `power[1-*]_cap`
  291. If power use rises above this limit, the
  292. system should take action to reduce power use.
  293. `power[1-*]_cap_hyst`
  294. Margin of hysteresis built around capping and notification.
  295. `power[1-*]_cap_max`
  296. Maximum cap that can be set.
  297. `power[1-*]_cap_min`
  298. Minimum cap that can be set.
  299. `power[1-*]_max`
  300. Maximum power.
  301. `power[1-*]_crit`
  302. Critical maximum power.
  303. If power rises to or above this limit, the
  304. system is expected take drastic action to reduce
  305. power consumption, such as a system shutdown or
  306. a forced powerdown of some devices.
  307. Unit: microWatt
  308. RW
  309. `power[1-*]_enable`
  310. Enable or disable the sensors.
  311. When disabled the sensor read will return
  312. -ENODATA.
  313. - 1: Enable
  314. - 0: Disable
  315. RW
  316. `power[1-*]_rated_min`
  317. Minimum rated power.
  318. Unit: microWatt
  319. RO
  320. `power[1-*]_rated_max`
  321. Maximum rated power.
  322. Unit: microWatt
  323. RO
  324. Also see the Alarms section for status flags associated with power readings.
  325. ******
  326. Energy
  327. ******
  328. `energy[1-*]_input`
  329. Cumulative energy use
  330. Unit: microJoule
  331. RO
  332. `energy[1-*]_enable`
  333. Enable or disable the sensors.
  334. When disabled the sensor read will return
  335. -ENODATA.
  336. - 1: Enable
  337. - 0: Disable
  338. RW
  339. ********
  340. Humidity
  341. ********
  342. `humidity[1-*]_input`
  343. Humidity.
  344. `humidity[1-*]_enable`
  345. Enable or disable the sensors.
  346. `humidity[1-*]_rated_min`
  347. Minimum rated humidity.
  348. `humidity[1-*]_rated_max`
  349. Maximum rated humidity.
  350. ******
  351. Alarms
  352. ******
  353. Each channel or limit may have an associated alarm file, containing a
  354. boolean value. 1 means than an alarm condition exists, 0 means no alarm.
  355. Usually a given chip will either use channel-related alarms, or
  356. limit-related alarms, not both. The driver should just reflect the hardware
  357. implementation.
  358. +-------------------------------+-----------------------+
  359. | **`in[0-*]_alarm`, | Channel alarm |
  360. | `curr[1-*]_alarm`, | |
  361. | `power[1-*]_alarm`, | - 0: no alarm |
  362. | `fan[1-*]_alarm`, | - 1: alarm |
  363. | `temp[1-*]_alarm`** | |
  364. | | RO |
  365. +-------------------------------+-----------------------+
  366. **OR**
  367. +-------------------------------+-----------------------+
  368. | **`in[0-*]_min_alarm`, | Limit alarm |
  369. | `in[0-*]_max_alarm`, | |
  370. | `in[0-*]_lcrit_alarm`, | - 0: no alarm |
  371. | `in[0-*]_crit_alarm`, | - 1: alarm |
  372. | `curr[1-*]_min_alarm`, | |
  373. | `curr[1-*]_max_alarm`, | RO |
  374. | `curr[1-*]_lcrit_alarm`, | |
  375. | `curr[1-*]_crit_alarm`, | |
  376. | `power[1-*]_cap_alarm`, | |
  377. | `power[1-*]_max_alarm`, | |
  378. | `power[1-*]_crit_alarm`, | |
  379. | `fan[1-*]_min_alarm`, | |
  380. | `fan[1-*]_max_alarm`, | |
  381. | `temp[1-*]_min_alarm`, | |
  382. | `temp[1-*]_max_alarm`, | |
  383. | `temp[1-*]_lcrit_alarm`, | |
  384. | `temp[1-*]_crit_alarm`, | |
  385. | `temp[1-*]_emergency_alarm`** | |
  386. +-------------------------------+-----------------------+
  387. Each input channel may have an associated fault file. This can be used
  388. to notify open diodes, unconnected fans etc. where the hardware
  389. supports it. When this boolean has value 1, the measurement for that
  390. channel should not be trusted.
  391. `fan[1-*]_fault` / `temp[1-*]_fault`
  392. Input fault condition.
  393. Some chips also offer the possibility to get beeped when an alarm occurs:
  394. `beep_enable`
  395. Master beep enable.
  396. `in[0-*]_beep`, `curr[1-*]_beep`, `fan[1-*]_beep`, `temp[1-*]_beep`,
  397. Channel beep.
  398. In theory, a chip could provide per-limit beep masking, but no such chip
  399. was seen so far.
  400. Old drivers provided a different, non-standard interface to alarms and
  401. beeps. These interface files are deprecated, but will be kept around
  402. for compatibility reasons:
  403. `alarms`
  404. Alarm bitmask.
  405. `beep_mask`
  406. Bitmask for beep.
  407. *******************
  408. Intrusion detection
  409. *******************
  410. `intrusion[0-*]_alarm`
  411. Chassis intrusion detection.
  412. `intrusion[0-*]_beep`
  413. Chassis intrusion beep.
  414. ****************************
  415. Average sample configuration
  416. ****************************
  417. Devices allowing for reading {in,power,curr,temp}_average values may export
  418. attributes for controlling number of samples used to compute average.
  419. +--------------+---------------------------------------------------------------+
  420. | samples | Sets number of average samples for all types of measurements. |
  421. | | |
  422. | | RW |
  423. +--------------+---------------------------------------------------------------+
  424. | in_samples | Sets number of average samples for specific type of |
  425. | power_samples| measurements. |
  426. | curr_samples | |
  427. | temp_samples | Note that on some devices it won't be possible to set all of |
  428. | | them to different values so changing one might also change |
  429. | | some others. |
  430. | | |
  431. | | RW |
  432. +--------------+---------------------------------------------------------------+
  433. sysfs attribute writes interpretation
  434. -------------------------------------
  435. hwmon sysfs attributes always contain numbers, so the first thing to do is to
  436. convert the input to a number, there are 2 ways todo this depending whether
  437. the number can be negative or not::
  438. unsigned long u = simple_strtoul(buf, NULL, 10);
  439. long s = simple_strtol(buf, NULL, 10);
  440. With buf being the buffer with the user input being passed by the kernel.
  441. Notice that we do not use the second argument of strto[u]l, and thus cannot
  442. tell when 0 is returned, if this was really 0 or is caused by invalid input.
  443. This is done deliberately as checking this everywhere would add a lot of
  444. code to the kernel.
  445. Notice that it is important to always store the converted value in an
  446. unsigned long or long, so that no wrap around can happen before any further
  447. checking.
  448. After the input string is converted to an (unsigned) long, the value should be
  449. checked if its acceptable. Be careful with further conversions on the value
  450. before checking it for validity, as these conversions could still cause a wrap
  451. around before the check. For example do not multiply the result, and only
  452. add/subtract if it has been divided before the add/subtract.
  453. What to do if a value is found to be invalid, depends on the type of the
  454. sysfs attribute that is being set. If it is a continuous setting like a
  455. tempX_max or inX_max attribute, then the value should be clamped to its
  456. limits using clamp_val(value, min_limit, max_limit). If it is not continuous
  457. like for example a tempX_type, then when an invalid value is written,
  458. -EINVAL should be returned.
  459. Example1, temp1_max, register is a signed 8 bit value (-128 - 127 degrees)::
  460. long v = simple_strtol(buf, NULL, 10) / 1000;
  461. v = clamp_val(v, -128, 127);
  462. /* write v to register */
  463. Example2, fan divider setting, valid values 2, 4 and 8::
  464. unsigned long v = simple_strtoul(buf, NULL, 10);
  465. switch (v) {
  466. case 2: v = 1; break;
  467. case 4: v = 2; break;
  468. case 8: v = 3; break;
  469. default:
  470. return -EINVAL;
  471. }
  472. /* write v to register */