sysfs-interface 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. * Name *
  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. ************
  77. * Voltages *
  78. ************
  79. in[0-*]_min Voltage min value.
  80. Unit: millivolt
  81. RW
  82. in[0-*]_max Voltage max value.
  83. Unit: millivolt
  84. RW
  85. in[0-*]_input Voltage input value.
  86. Unit: millivolt
  87. RO
  88. Voltage measured on the chip pin.
  89. Actual voltage depends on the scaling resistors on the
  90. motherboard, as recommended in the chip datasheet.
  91. This varies by chip and by motherboard.
  92. Because of this variation, values are generally NOT scaled
  93. by the chip driver, and must be done by the application.
  94. However, some drivers (notably lm87 and via686a)
  95. do scale, because of internal resistors built into a chip.
  96. These drivers will output the actual voltage. Rule of
  97. thumb: drivers should report the voltage values at the
  98. "pins" of the chip.
  99. in[0-*]_label Suggested voltage channel label.
  100. Text string
  101. Should only be created if the driver has hints about what
  102. this voltage channel is being used for, and user-space
  103. doesn't. In all other cases, the label is provided by
  104. user-space.
  105. RO
  106. cpu[0-*]_vid CPU core reference voltage.
  107. Unit: millivolt
  108. RO
  109. Not always correct.
  110. vrm Voltage Regulator Module version number.
  111. RW (but changing it should no more be necessary)
  112. Originally the VRM standard version multiplied by 10, but now
  113. an arbitrary number, as not all standards have a version
  114. number.
  115. Affects the way the driver calculates the CPU core reference
  116. voltage from the vid pins.
  117. Also see the Alarms section for status flags associated with voltages.
  118. ********
  119. * Fans *
  120. ********
  121. fan[1-*]_min Fan minimum value
  122. Unit: revolution/min (RPM)
  123. RW
  124. fan[1-*]_max Fan maximum value
  125. Unit: revolution/min (RPM)
  126. Only rarely supported by the hardware.
  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. temp[1-*]_auto_point[1-*]_pwm
  185. temp[1-*]_auto_point[1-*]_temp
  186. temp[1-*]_auto_point[1-*]_temp_hyst
  187. Define the PWM vs temperature curve. Number of trip points is
  188. chip-dependent. Use this for chips which associate trip points
  189. to temperature channels.
  190. RW
  191. There is a third case where trip points are associated to both PWM output
  192. channels and temperature channels: the PWM values are associated to PWM
  193. output channels while the temperature values are associated to temperature
  194. channels. In that case, the result is determined by the mapping between
  195. temperature inputs and PWM outputs. When several temperature inputs are
  196. mapped to a given PWM output, this leads to several candidate PWM values.
  197. The actual result is up to the chip, but in general the highest candidate
  198. value (fastest fan speed) wins.
  199. ****************
  200. * Temperatures *
  201. ****************
  202. temp[1-*]_type Sensor type selection.
  203. Integers 1 to 6
  204. RW
  205. 1: PII/Celeron Diode
  206. 2: 3904 transistor
  207. 3: thermal diode
  208. 4: thermistor
  209. 5: AMD AMDSI
  210. 6: Intel PECI
  211. Not all types are supported by all chips
  212. temp[1-*]_max Temperature max value.
  213. Unit: millidegree Celsius (or millivolt, see below)
  214. RW
  215. temp[1-*]_min Temperature min value.
  216. Unit: millidegree Celsius
  217. RW
  218. temp[1-*]_max_hyst
  219. Temperature hysteresis value for max limit.
  220. Unit: millidegree Celsius
  221. Must be reported as an absolute temperature, NOT a delta
  222. from the max value.
  223. RW
  224. temp[1-*]_input Temperature input value.
  225. Unit: millidegree Celsius
  226. RO
  227. temp[1-*]_crit Temperature critical value, typically greater than
  228. corresponding temp_max values.
  229. Unit: millidegree Celsius
  230. RW
  231. temp[1-*]_crit_hyst
  232. Temperature hysteresis value for critical limit.
  233. Unit: millidegree Celsius
  234. Must be reported as an absolute temperature, NOT a delta
  235. from the critical value.
  236. RW
  237. temp[1-*]_offset
  238. Temperature offset which is added to the temperature reading
  239. by the chip.
  240. Unit: millidegree Celsius
  241. Read/Write value.
  242. temp[1-*]_label Suggested temperature channel label.
  243. Text string
  244. Should only be created if the driver has hints about what
  245. this temperature channel is being used for, and user-space
  246. doesn't. In all other cases, the label is provided by
  247. user-space.
  248. RO
  249. temp[1-*]_lowest
  250. Historical minimum temperature
  251. Unit: millidegree Celsius
  252. RO
  253. temp[1-*]_highest
  254. Historical maximum temperature
  255. Unit: millidegree Celsius
  256. RO
  257. temp[1-*]_reset_history
  258. Reset temp_lowest and temp_highest
  259. WO
  260. temp_reset_history
  261. Reset temp_lowest and temp_highest for all sensors
  262. WO
  263. Some chips measure temperature using external thermistors and an ADC, and
  264. report the temperature measurement as a voltage. Converting this voltage
  265. back to a temperature (or the other way around for limits) requires
  266. mathematical functions not available in the kernel, so the conversion
  267. must occur in user space. For these chips, all temp* files described
  268. above should contain values expressed in millivolt instead of millidegree
  269. Celsius. In other words, such temperature channels are handled as voltage
  270. channels by the driver.
  271. Also see the Alarms section for status flags associated with temperatures.
  272. ************
  273. * Currents *
  274. ************
  275. Note that no known chip provides current measurements as of writing,
  276. so this part is theoretical, so to say.
  277. curr[1-*]_max Current max value
  278. Unit: milliampere
  279. RW
  280. curr[1-*]_min Current min value.
  281. Unit: milliampere
  282. RW
  283. curr[1-*]_input Current input value
  284. Unit: milliampere
  285. RO
  286. *********
  287. * Power *
  288. *********
  289. power[1-*]_average Average power use
  290. Unit: microWatt
  291. RO
  292. power[1-*]_average_interval Power use averaging interval. A poll
  293. notification is sent to this file if the
  294. hardware changes the averaging interval.
  295. Unit: milliseconds
  296. RW
  297. power[1-*]_average_interval_max Maximum power use averaging interval
  298. Unit: milliseconds
  299. RO
  300. power[1-*]_average_interval_min Minimum power use averaging interval
  301. Unit: milliseconds
  302. RO
  303. power[1-*]_average_highest Historical average maximum power use
  304. Unit: microWatt
  305. RO
  306. power[1-*]_average_lowest Historical average minimum power use
  307. Unit: microWatt
  308. RO
  309. power[1-*]_average_max A poll notification is sent to
  310. power[1-*]_average when power use
  311. rises above this value.
  312. Unit: microWatt
  313. RW
  314. power[1-*]_average_min A poll notification is sent to
  315. power[1-*]_average when power use
  316. sinks below this value.
  317. Unit: microWatt
  318. RW
  319. power[1-*]_input Instantaneous power use
  320. Unit: microWatt
  321. RO
  322. power[1-*]_input_highest Historical maximum power use
  323. Unit: microWatt
  324. RO
  325. power[1-*]_input_lowest Historical minimum power use
  326. Unit: microWatt
  327. RO
  328. power[1-*]_reset_history Reset input_highest, input_lowest,
  329. average_highest and average_lowest.
  330. WO
  331. power[1-*]_accuracy Accuracy of the power meter.
  332. Unit: Percent
  333. RO
  334. power[1-*]_alarm 1 if the system is drawing more power than the
  335. cap allows; 0 otherwise. A poll notification is
  336. sent to this file when the power use exceeds the
  337. cap. This file only appears if the cap is known
  338. to be enforced by hardware.
  339. RO
  340. power[1-*]_cap If power use rises above this limit, the
  341. system should take action to reduce power use.
  342. A poll notification is sent to this file if the
  343. cap is changed by the hardware. The *_cap
  344. files only appear if the cap is known to be
  345. enforced by hardware.
  346. Unit: microWatt
  347. RW
  348. power[1-*]_cap_hyst Margin of hysteresis built around capping and
  349. notification.
  350. Unit: microWatt
  351. RW
  352. power[1-*]_cap_max Maximum cap that can be set.
  353. Unit: microWatt
  354. RO
  355. power[1-*]_cap_min Minimum cap that can be set.
  356. Unit: microWatt
  357. RO
  358. **********
  359. * Energy *
  360. **********
  361. energy[1-*]_input Cumulative energy use
  362. Unit: microJoule
  363. RO
  364. **********
  365. * Alarms *
  366. **********
  367. Each channel or limit may have an associated alarm file, containing a
  368. boolean value. 1 means than an alarm condition exists, 0 means no alarm.
  369. Usually a given chip will either use channel-related alarms, or
  370. limit-related alarms, not both. The driver should just reflect the hardware
  371. implementation.
  372. in[0-*]_alarm
  373. fan[1-*]_alarm
  374. temp[1-*]_alarm
  375. Channel alarm
  376. 0: no alarm
  377. 1: alarm
  378. RO
  379. OR
  380. in[0-*]_min_alarm
  381. in[0-*]_max_alarm
  382. fan[1-*]_min_alarm
  383. fan[1-*]_max_alarm
  384. temp[1-*]_min_alarm
  385. temp[1-*]_max_alarm
  386. temp[1-*]_crit_alarm
  387. Limit alarm
  388. 0: no alarm
  389. 1: alarm
  390. RO
  391. Each input channel may have an associated fault file. This can be used
  392. to notify open diodes, unconnected fans etc. where the hardware
  393. supports it. When this boolean has value 1, the measurement for that
  394. channel should not be trusted.
  395. in[0-*]_fault
  396. fan[1-*]_fault
  397. temp[1-*]_fault
  398. Input fault condition
  399. 0: no fault occured
  400. 1: fault condition
  401. RO
  402. Some chips also offer the possibility to get beeped when an alarm occurs:
  403. beep_enable Master beep enable
  404. 0: no beeps
  405. 1: beeps
  406. RW
  407. in[0-*]_beep
  408. fan[1-*]_beep
  409. temp[1-*]_beep
  410. Channel beep
  411. 0: disable
  412. 1: enable
  413. RW
  414. In theory, a chip could provide per-limit beep masking, but no such chip
  415. was seen so far.
  416. Old drivers provided a different, non-standard interface to alarms and
  417. beeps. These interface files are deprecated, but will be kept around
  418. for compatibility reasons:
  419. alarms Alarm bitmask.
  420. RO
  421. Integer representation of one to four bytes.
  422. A '1' bit means an alarm.
  423. Chips should be programmed for 'comparator' mode so that
  424. the alarm will 'come back' after you read the register
  425. if it is still valid.
  426. Generally a direct representation of a chip's internal
  427. alarm registers; there is no standard for the position
  428. of individual bits. For this reason, the use of this
  429. interface file for new drivers is discouraged. Use
  430. individual *_alarm and *_fault files instead.
  431. Bits are defined in kernel/include/sensors.h.
  432. beep_mask Bitmask for beep.
  433. Same format as 'alarms' with the same bit locations,
  434. use discouraged for the same reason. Use individual
  435. *_beep files instead.
  436. RW
  437. ***********************
  438. * Intrusion detection *
  439. ***********************
  440. intrusion[0-*]_alarm
  441. Chassis intrusion detection
  442. 0: OK
  443. 1: intrusion detected
  444. RW
  445. Contrary to regular alarm flags which clear themselves
  446. automatically when read, this one sticks until cleared by
  447. the user. This is done by writing 0 to the file. Writing
  448. other values is unsupported.
  449. intrusion[0-*]_beep
  450. Chassis intrusion beep
  451. 0: disable
  452. 1: enable
  453. RW
  454. sysfs attribute writes interpretation
  455. -------------------------------------
  456. hwmon sysfs attributes always contain numbers, so the first thing to do is to
  457. convert the input to a number, there are 2 ways todo this depending whether
  458. the number can be negative or not:
  459. unsigned long u = simple_strtoul(buf, NULL, 10);
  460. long s = simple_strtol(buf, NULL, 10);
  461. With buf being the buffer with the user input being passed by the kernel.
  462. Notice that we do not use the second argument of strto[u]l, and thus cannot
  463. tell when 0 is returned, if this was really 0 or is caused by invalid input.
  464. This is done deliberately as checking this everywhere would add a lot of
  465. code to the kernel.
  466. Notice that it is important to always store the converted value in an
  467. unsigned long or long, so that no wrap around can happen before any further
  468. checking.
  469. After the input string is converted to an (unsigned) long, the value should be
  470. checked if its acceptable. Be careful with further conversions on the value
  471. before checking it for validity, as these conversions could still cause a wrap
  472. around before the check. For example do not multiply the result, and only
  473. add/subtract if it has been divided before the add/subtract.
  474. What to do if a value is found to be invalid, depends on the type of the
  475. sysfs attribute that is being set. If it is a continuous setting like a
  476. tempX_max or inX_max attribute, then the value should be clamped to its
  477. limits using SENSORS_LIMIT(value, min_limit, max_limit). If it is not
  478. continuous like for example a tempX_type, then when an invalid value is
  479. written, -EINVAL should be returned.
  480. Example1, temp1_max, register is a signed 8 bit value (-128 - 127 degrees):
  481. long v = simple_strtol(buf, NULL, 10) / 1000;
  482. v = SENSORS_LIMIT(v, -128, 127);
  483. /* write v to register */
  484. Example2, fan divider setting, valid values 2, 4 and 8:
  485. unsigned long v = simple_strtoul(buf, NULL, 10);
  486. switch (v) {
  487. case 2: v = 1; break;
  488. case 4: v = 2; break;
  489. case 8: v = 3; break;
  490. default:
  491. return -EINVAL;
  492. }
  493. /* write v to register */