sysfs-interface 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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. -------------------------------------------------------------------------
  58. [0-*] denotes any positive number starting from 0
  59. [1-*] denotes any positive number starting from 1
  60. RO read only value
  61. WO write only value
  62. RW read/write value
  63. Read/write values may be read-only for some chips, depending on the
  64. hardware implementation.
  65. All entries (except name) are optional, and should only be created in a
  66. given driver if the chip has the feature.
  67. *********************
  68. * Global attributes *
  69. *********************
  70. name The chip name.
  71. This should be a short, lowercase string, not containing
  72. spaces nor dashes, representing the chip name. This is
  73. the only mandatory attribute.
  74. I2C devices get this attribute created automatically.
  75. RO
  76. update_interval The interval at which the chip will update readings.
  77. Unit: millisecond
  78. RW
  79. Some devices have a variable update rate or interval.
  80. This attribute can be used to change it to the desired value.
  81. ************
  82. * Voltages *
  83. ************
  84. in[0-*]_min Voltage min value.
  85. Unit: millivolt
  86. RW
  87. in[0-*]_lcrit Voltage critical min value.
  88. Unit: millivolt
  89. RW
  90. If voltage drops to or below this limit, the system may
  91. take drastic action such as power down or reset. At the very
  92. least, it should report a fault.
  93. in[0-*]_max Voltage max value.
  94. Unit: millivolt
  95. RW
  96. in[0-*]_crit Voltage critical max value.
  97. Unit: millivolt
  98. RW
  99. If voltage reaches or exceeds this limit, the system may
  100. take drastic action such as power down or reset. At the very
  101. least, it should report a fault.
  102. in[0-*]_input Voltage input value.
  103. Unit: millivolt
  104. RO
  105. Voltage measured on the chip pin.
  106. Actual voltage depends on the scaling resistors on the
  107. motherboard, as recommended in the chip datasheet.
  108. This varies by chip and by motherboard.
  109. Because of this variation, values are generally NOT scaled
  110. by the chip driver, and must be done by the application.
  111. However, some drivers (notably lm87 and via686a)
  112. do scale, because of internal resistors built into a chip.
  113. These drivers will output the actual voltage. Rule of
  114. thumb: drivers should report the voltage values at the
  115. "pins" of the chip.
  116. in[0-*]_label Suggested voltage channel label.
  117. Text string
  118. Should only be created if the driver has hints about what
  119. this voltage channel is being used for, and user-space
  120. doesn't. In all other cases, the label is provided by
  121. user-space.
  122. RO
  123. cpu[0-*]_vid CPU core reference voltage.
  124. Unit: millivolt
  125. RO
  126. Not always correct.
  127. vrm Voltage Regulator Module version number.
  128. RW (but changing it should no more be necessary)
  129. Originally the VRM standard version multiplied by 10, but now
  130. an arbitrary number, as not all standards have a version
  131. number.
  132. Affects the way the driver calculates the CPU core reference
  133. voltage from the vid pins.
  134. Also see the Alarms section for status flags associated with voltages.
  135. ********
  136. * Fans *
  137. ********
  138. fan[1-*]_min Fan minimum value
  139. Unit: revolution/min (RPM)
  140. RW
  141. fan[1-*]_max Fan maximum value
  142. Unit: revolution/min (RPM)
  143. Only rarely supported by the hardware.
  144. RW
  145. fan[1-*]_input Fan input value.
  146. Unit: revolution/min (RPM)
  147. RO
  148. fan[1-*]_div Fan divisor.
  149. Integer value in powers of two (1, 2, 4, 8, 16, 32, 64, 128).
  150. RW
  151. Some chips only support values 1, 2, 4 and 8.
  152. Note that this is actually an internal clock divisor, which
  153. affects the measurable speed range, not the read value.
  154. fan[1-*]_pulses Number of tachometer pulses per fan revolution.
  155. Integer value, typically between 1 and 4.
  156. RW
  157. This value is a characteristic of the fan connected to the
  158. device's input, so it has to be set in accordance with the fan
  159. model.
  160. Should only be created if the chip has a register to configure
  161. the number of pulses. In the absence of such a register (and
  162. thus attribute) the value assumed by all devices is 2 pulses
  163. per fan revolution.
  164. fan[1-*]_target
  165. Desired fan speed
  166. Unit: revolution/min (RPM)
  167. RW
  168. Only makes sense if the chip supports closed-loop fan speed
  169. control based on the measured fan speed.
  170. fan[1-*]_label Suggested fan channel label.
  171. Text string
  172. Should only be created if the driver has hints about what
  173. this fan channel is being used for, and user-space doesn't.
  174. In all other cases, the label is provided by user-space.
  175. RO
  176. Also see the Alarms section for status flags associated with fans.
  177. *******
  178. * PWM *
  179. *******
  180. pwm[1-*] Pulse width modulation fan control.
  181. Integer value in the range 0 to 255
  182. RW
  183. 255 is max or 100%.
  184. pwm[1-*]_enable
  185. Fan speed control method:
  186. 0: no fan speed control (i.e. fan at full speed)
  187. 1: manual fan speed control enabled (using pwm[1-*])
  188. 2+: automatic fan speed control enabled
  189. Check individual chip documentation files for automatic mode
  190. details.
  191. RW
  192. pwm[1-*]_mode 0: DC mode (direct current)
  193. 1: PWM mode (pulse-width modulation)
  194. RW
  195. pwm[1-*]_freq Base PWM frequency in Hz.
  196. Only possibly available when pwmN_mode is PWM, but not always
  197. present even then.
  198. RW
  199. pwm[1-*]_auto_channels_temp
  200. Select which temperature channels affect this PWM output in
  201. auto mode. Bitfield, 1 is temp1, 2 is temp2, 4 is temp3 etc...
  202. Which values are possible depend on the chip used.
  203. RW
  204. pwm[1-*]_auto_point[1-*]_pwm
  205. pwm[1-*]_auto_point[1-*]_temp
  206. pwm[1-*]_auto_point[1-*]_temp_hyst
  207. Define the PWM vs temperature curve. Number of trip points is
  208. chip-dependent. Use this for chips which associate trip points
  209. to PWM output channels.
  210. RW
  211. temp[1-*]_auto_point[1-*]_pwm
  212. temp[1-*]_auto_point[1-*]_temp
  213. temp[1-*]_auto_point[1-*]_temp_hyst
  214. Define the PWM vs temperature curve. Number of trip points is
  215. chip-dependent. Use this for chips which associate trip points
  216. to temperature channels.
  217. RW
  218. There is a third case where trip points are associated to both PWM output
  219. channels and temperature channels: the PWM values are associated to PWM
  220. output channels while the temperature values are associated to temperature
  221. channels. In that case, the result is determined by the mapping between
  222. temperature inputs and PWM outputs. When several temperature inputs are
  223. mapped to a given PWM output, this leads to several candidate PWM values.
  224. The actual result is up to the chip, but in general the highest candidate
  225. value (fastest fan speed) wins.
  226. ****************
  227. * Temperatures *
  228. ****************
  229. temp[1-*]_type Sensor type selection.
  230. Integers 1 to 6
  231. RW
  232. 1: PII/Celeron Diode
  233. 2: 3904 transistor
  234. 3: thermal diode
  235. 4: thermistor
  236. 5: AMD AMDSI
  237. 6: Intel PECI
  238. Not all types are supported by all chips
  239. temp[1-*]_max Temperature max value.
  240. Unit: millidegree Celsius (or millivolt, see below)
  241. RW
  242. temp[1-*]_min Temperature min value.
  243. Unit: millidegree Celsius
  244. RW
  245. temp[1-*]_max_hyst
  246. Temperature hysteresis value for max limit.
  247. Unit: millidegree Celsius
  248. Must be reported as an absolute temperature, NOT a delta
  249. from the max value.
  250. RW
  251. temp[1-*]_input Temperature input value.
  252. Unit: millidegree Celsius
  253. RO
  254. temp[1-*]_crit Temperature critical max value, typically greater than
  255. corresponding temp_max values.
  256. Unit: millidegree Celsius
  257. RW
  258. temp[1-*]_crit_hyst
  259. Temperature hysteresis value for critical limit.
  260. Unit: millidegree Celsius
  261. Must be reported as an absolute temperature, NOT a delta
  262. from the critical value.
  263. RW
  264. temp[1-*]_emergency
  265. Temperature emergency max value, for chips supporting more than
  266. two upper temperature limits. Must be equal or greater than
  267. corresponding temp_crit values.
  268. Unit: millidegree Celsius
  269. RW
  270. temp[1-*]_emergency_hyst
  271. Temperature hysteresis value for emergency limit.
  272. Unit: millidegree Celsius
  273. Must be reported as an absolute temperature, NOT a delta
  274. from the emergency value.
  275. RW
  276. temp[1-*]_lcrit Temperature critical min value, typically lower than
  277. corresponding temp_min values.
  278. Unit: millidegree Celsius
  279. RW
  280. temp[1-*]_offset
  281. Temperature offset which is added to the temperature reading
  282. by the chip.
  283. Unit: millidegree Celsius
  284. Read/Write value.
  285. temp[1-*]_label Suggested temperature channel label.
  286. Text string
  287. Should only be created if the driver has hints about what
  288. this temperature channel is being used for, and user-space
  289. doesn't. In all other cases, the label is provided by
  290. user-space.
  291. RO
  292. temp[1-*]_lowest
  293. Historical minimum temperature
  294. Unit: millidegree Celsius
  295. RO
  296. temp[1-*]_highest
  297. Historical maximum temperature
  298. Unit: millidegree Celsius
  299. RO
  300. temp[1-*]_reset_history
  301. Reset temp_lowest and temp_highest
  302. WO
  303. temp_reset_history
  304. Reset temp_lowest and temp_highest for all sensors
  305. WO
  306. Some chips measure temperature using external thermistors and an ADC, and
  307. report the temperature measurement as a voltage. Converting this voltage
  308. back to a temperature (or the other way around for limits) requires
  309. mathematical functions not available in the kernel, so the conversion
  310. must occur in user space. For these chips, all temp* files described
  311. above should contain values expressed in millivolt instead of millidegree
  312. Celsius. In other words, such temperature channels are handled as voltage
  313. channels by the driver.
  314. Also see the Alarms section for status flags associated with temperatures.
  315. ************
  316. * Currents *
  317. ************
  318. curr[1-*]_max Current max value
  319. Unit: milliampere
  320. RW
  321. curr[1-*]_min Current min value.
  322. Unit: milliampere
  323. RW
  324. curr[1-*]_lcrit Current critical low value
  325. Unit: milliampere
  326. RW
  327. curr[1-*]_crit Current critical high value.
  328. Unit: milliampere
  329. RW
  330. curr[1-*]_input Current input value
  331. Unit: milliampere
  332. RO
  333. Also see the Alarms section for status flags associated with currents.
  334. *********
  335. * Power *
  336. *********
  337. power[1-*]_average Average power use
  338. Unit: microWatt
  339. RO
  340. power[1-*]_average_interval Power use averaging interval. A poll
  341. notification is sent to this file if the
  342. hardware changes the averaging interval.
  343. Unit: milliseconds
  344. RW
  345. power[1-*]_average_interval_max Maximum power use averaging interval
  346. Unit: milliseconds
  347. RO
  348. power[1-*]_average_interval_min Minimum power use averaging interval
  349. Unit: milliseconds
  350. RO
  351. power[1-*]_average_highest Historical average maximum power use
  352. Unit: microWatt
  353. RO
  354. power[1-*]_average_lowest Historical average minimum power use
  355. Unit: microWatt
  356. RO
  357. power[1-*]_average_max A poll notification is sent to
  358. power[1-*]_average when power use
  359. rises above this value.
  360. Unit: microWatt
  361. RW
  362. power[1-*]_average_min A poll notification is sent to
  363. power[1-*]_average when power use
  364. sinks below this value.
  365. Unit: microWatt
  366. RW
  367. power[1-*]_input Instantaneous power use
  368. Unit: microWatt
  369. RO
  370. power[1-*]_input_highest Historical maximum power use
  371. Unit: microWatt
  372. RO
  373. power[1-*]_input_lowest Historical minimum power use
  374. Unit: microWatt
  375. RO
  376. power[1-*]_reset_history Reset input_highest, input_lowest,
  377. average_highest and average_lowest.
  378. WO
  379. power[1-*]_accuracy Accuracy of the power meter.
  380. Unit: Percent
  381. RO
  382. power[1-*]_cap If power use rises above this limit, the
  383. system should take action to reduce power use.
  384. A poll notification is sent to this file if the
  385. cap is changed by the hardware. The *_cap
  386. files only appear if the cap is known to be
  387. enforced by hardware.
  388. Unit: microWatt
  389. RW
  390. power[1-*]_cap_hyst Margin of hysteresis built around capping and
  391. notification.
  392. Unit: microWatt
  393. RW
  394. power[1-*]_cap_max Maximum cap that can be set.
  395. Unit: microWatt
  396. RO
  397. power[1-*]_cap_min Minimum cap that can be set.
  398. Unit: microWatt
  399. RO
  400. power[1-*]_max Maximum power.
  401. Unit: microWatt
  402. RW
  403. power[1-*]_crit Critical maximum power.
  404. If power rises to or above this limit, the
  405. system is expected take drastic action to reduce
  406. power consumption, such as a system shutdown or
  407. a forced powerdown of some devices.
  408. Unit: microWatt
  409. RW
  410. Also see the Alarms section for status flags associated with power readings.
  411. **********
  412. * Energy *
  413. **********
  414. energy[1-*]_input Cumulative energy use
  415. Unit: microJoule
  416. RO
  417. ************
  418. * Humidity *
  419. ************
  420. humidity[1-*]_input Humidity
  421. Unit: milli-percent (per cent mille, pcm)
  422. RO
  423. **********
  424. * Alarms *
  425. **********
  426. Each channel or limit may have an associated alarm file, containing a
  427. boolean value. 1 means than an alarm condition exists, 0 means no alarm.
  428. Usually a given chip will either use channel-related alarms, or
  429. limit-related alarms, not both. The driver should just reflect the hardware
  430. implementation.
  431. in[0-*]_alarm
  432. curr[1-*]_alarm
  433. power[1-*]_alarm
  434. fan[1-*]_alarm
  435. temp[1-*]_alarm
  436. Channel alarm
  437. 0: no alarm
  438. 1: alarm
  439. RO
  440. OR
  441. in[0-*]_min_alarm
  442. in[0-*]_max_alarm
  443. in[0-*]_lcrit_alarm
  444. in[0-*]_crit_alarm
  445. curr[1-*]_min_alarm
  446. curr[1-*]_max_alarm
  447. curr[1-*]_lcrit_alarm
  448. curr[1-*]_crit_alarm
  449. power[1-*]_cap_alarm
  450. power[1-*]_max_alarm
  451. power[1-*]_crit_alarm
  452. fan[1-*]_min_alarm
  453. fan[1-*]_max_alarm
  454. temp[1-*]_min_alarm
  455. temp[1-*]_max_alarm
  456. temp[1-*]_lcrit_alarm
  457. temp[1-*]_crit_alarm
  458. temp[1-*]_emergency_alarm
  459. Limit alarm
  460. 0: no alarm
  461. 1: alarm
  462. RO
  463. Each input channel may have an associated fault file. This can be used
  464. to notify open diodes, unconnected fans etc. where the hardware
  465. supports it. When this boolean has value 1, the measurement for that
  466. channel should not be trusted.
  467. fan[1-*]_fault
  468. temp[1-*]_fault
  469. Input fault condition
  470. 0: no fault occurred
  471. 1: fault condition
  472. RO
  473. Some chips also offer the possibility to get beeped when an alarm occurs:
  474. beep_enable Master beep enable
  475. 0: no beeps
  476. 1: beeps
  477. RW
  478. in[0-*]_beep
  479. curr[1-*]_beep
  480. fan[1-*]_beep
  481. temp[1-*]_beep
  482. Channel beep
  483. 0: disable
  484. 1: enable
  485. RW
  486. In theory, a chip could provide per-limit beep masking, but no such chip
  487. was seen so far.
  488. Old drivers provided a different, non-standard interface to alarms and
  489. beeps. These interface files are deprecated, but will be kept around
  490. for compatibility reasons:
  491. alarms Alarm bitmask.
  492. RO
  493. Integer representation of one to four bytes.
  494. A '1' bit means an alarm.
  495. Chips should be programmed for 'comparator' mode so that
  496. the alarm will 'come back' after you read the register
  497. if it is still valid.
  498. Generally a direct representation of a chip's internal
  499. alarm registers; there is no standard for the position
  500. of individual bits. For this reason, the use of this
  501. interface file for new drivers is discouraged. Use
  502. individual *_alarm and *_fault files instead.
  503. Bits are defined in kernel/include/sensors.h.
  504. beep_mask Bitmask for beep.
  505. Same format as 'alarms' with the same bit locations,
  506. use discouraged for the same reason. Use individual
  507. *_beep files instead.
  508. RW
  509. ***********************
  510. * Intrusion detection *
  511. ***********************
  512. intrusion[0-*]_alarm
  513. Chassis intrusion detection
  514. 0: OK
  515. 1: intrusion detected
  516. RW
  517. Contrary to regular alarm flags which clear themselves
  518. automatically when read, this one sticks until cleared by
  519. the user. This is done by writing 0 to the file. Writing
  520. other values is unsupported.
  521. intrusion[0-*]_beep
  522. Chassis intrusion beep
  523. 0: disable
  524. 1: enable
  525. RW
  526. sysfs attribute writes interpretation
  527. -------------------------------------
  528. hwmon sysfs attributes always contain numbers, so the first thing to do is to
  529. convert the input to a number, there are 2 ways todo this depending whether
  530. the number can be negative or not:
  531. unsigned long u = simple_strtoul(buf, NULL, 10);
  532. long s = simple_strtol(buf, NULL, 10);
  533. With buf being the buffer with the user input being passed by the kernel.
  534. Notice that we do not use the second argument of strto[u]l, and thus cannot
  535. tell when 0 is returned, if this was really 0 or is caused by invalid input.
  536. This is done deliberately as checking this everywhere would add a lot of
  537. code to the kernel.
  538. Notice that it is important to always store the converted value in an
  539. unsigned long or long, so that no wrap around can happen before any further
  540. checking.
  541. After the input string is converted to an (unsigned) long, the value should be
  542. checked if its acceptable. Be careful with further conversions on the value
  543. before checking it for validity, as these conversions could still cause a wrap
  544. around before the check. For example do not multiply the result, and only
  545. add/subtract if it has been divided before the add/subtract.
  546. What to do if a value is found to be invalid, depends on the type of the
  547. sysfs attribute that is being set. If it is a continuous setting like a
  548. tempX_max or inX_max attribute, then the value should be clamped to its
  549. limits using SENSORS_LIMIT(value, min_limit, max_limit). If it is not
  550. continuous like for example a tempX_type, then when an invalid value is
  551. written, -EINVAL should be returned.
  552. Example1, temp1_max, register is a signed 8 bit value (-128 - 127 degrees):
  553. long v = simple_strtol(buf, NULL, 10) / 1000;
  554. v = SENSORS_LIMIT(v, -128, 127);
  555. /* write v to register */
  556. Example2, fan divider setting, valid values 2, 4 and 8:
  557. unsigned long v = simple_strtoul(buf, NULL, 10);
  558. switch (v) {
  559. case 2: v = 1; break;
  560. case 4: v = 2; break;
  561. case 8: v = 3; break;
  562. default:
  563. return -EINVAL;
  564. }
  565. /* write v to register */