summaryrefslogtreecommitdiff
path: root/lib/sysfs.c
Commit message (Collapse)AuthorAgeFilesLines
...
* libsensors: minor cleanupMark M. Hoffman2007-12-161-9/+9
| | | | git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@5075 7894878c-1315-0410-8ee3-d5d059ff63e0
* libsensors: No longer depend on libsysfs.Jean Delvare2007-12-101-134/+191
| | | | | | | | | | | | | | | | | Instead, access sysfs directly, using 3 embedded helper functions. My motivations for doing this are: * As far as I know, libsysfs is no longer maintained. * libsysfs does much more than we need. For example, when asking for a device attribute list, libsysfs will read the contents and permissions of all attributes. Not only does this waste CPU cycles per se, but in the case of hwmon driver it also triggers register reads, which can be slow for SMBus chips. * libsysfs enforces the difference between devices and class devices, while future changes will be easier if we can handle both types alike. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@5067 7894878c-1315-0410-8ee3-d5d059ff63e0
* libsensors: Report I/O errors as such.Jean Delvare2007-09-291-6/+34
| | | | git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4899 7894878c-1315-0410-8ee3-d5d059ff63e0
* libsensors: Differentiate between different read error types.Jean Delvare2007-09-291-3/+2
| | | | git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4896 7894878c-1315-0410-8ee3-d5d059ff63e0
* libsensors: Notify the caller when writing a value fails.Jean Delvare2007-09-291-2/+4
| | | | git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4895 7894878c-1315-0410-8ee3-d5d059ff63e0
* Drop SENSORS_ERR_NO_DEVS: we return success, not error, when no deviceJean Delvare2007-09-241-4/+4
| | | | | | | is found. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4879 7894878c-1315-0410-8ee3-d5d059ff63e0
* Add support for platform devices with no ID.Jean Delvare2007-09-241-2/+6
| | | | git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4878 7894878c-1315-0410-8ee3-d5d059ff63e0
* Renumber feature and subfeature types to leave more room if we laterJean Delvare2007-09-231-4/+4
| | | | | | | need to add more feature or subfeature types. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4858 7894878c-1315-0410-8ee3-d5d059ff63e0
* Don't arbitrarily write errors to stderr. In production mode,Jean Delvare2007-09-231-9/+12
| | | | | | | | | | | | | simply ignore the errors. In debug mode, call sensors_fatal_error(). As a side note, there is certainly room for improvement in the way errors are reported by libsensors. sensors_fatal_error() is fatal, and sensors_parse_error() is too specific, so we lack a more general error reporting function. printf-like formatting for error messages would also be a good idea. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4855 7894878c-1315-0410-8ee3-d5d059ff63e0
* Delete unused SENSORS_ERR_ACCESS.Jean Delvare2007-09-231-10/+10
| | | | | | | | | | Rename SENSORS_ERR_PROC to the more neutral SENSORS_ERR_KERNEL. Introduce SENSORS_ERR_NO_DEVS for finer-grained error reporting. Use SENSORS_ERR_KERNEL and SENSORS_ERR_NO_DEVS where appropriate. No error message for invalid error codes. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4854 7894878c-1315-0410-8ee3-d5d059ff63e0
* Better prototype for get_type_scaling().Jean Delvare2007-09-231-1/+1
| | | | git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4850 7894878c-1315-0410-8ee3-d5d059ff63e0
* Pass a subfeature structure to sensors_read_sysfs_attr() andJean Delvare2007-09-231-10/+4
| | | | | | | | sensors_write_sysfs_attr(), rather than a subfeature number, so that we do not have to lookup the feature number again. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4841 7894878c-1315-0410-8ee3-d5d059ff63e0
* Introduce a separate type for main features. Make subfeatures map toJean Delvare2007-09-231-89/+76
| | | | | | | the real main feature rather than the first subfeature. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4838 7894878c-1315-0410-8ee3-d5d059ff63e0
* Rename subfeature types from *_FEATURE_* to *_SUBFEATURE_*, to betterJean Delvare2007-09-231-53/+53
| | | | | | | reflect what they represent. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4837 7894878c-1315-0410-8ee3-d5d059ff63e0
* Update the comments and symbols in the whole library code to refer toJean Delvare2007-09-231-53/+55
| | | | | | | features and subfeatures as appropriate. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4836 7894878c-1315-0410-8ee3-d5d059ff63e0
* Define a separate structure to represent main features. This allowsJean Delvare2007-09-231-0/+26
| | | | | | | | | | for faster main features lookup. One side effect of this change is that subfeatures can no longer have labels nor be ignored. I do not think that this is a problem in practice, and actually this makes a lot of sense. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4834 7894878c-1315-0410-8ee3-d5d059ff63e0
* Rename struct sensors_feature_data to sensors_subfeature. This is aJean Delvare2007-09-231-17/+17
| | | | | | | | first step towards a clean separation between main features and subfeatures. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4832 7894878c-1315-0410-8ee3-d5d059ff63e0
* sensors_feature_data and sensors_chip_feature are now the exactJean Delvare2007-09-231-29/+29
| | | | | | | same structure, so we can get rid of the former for simpler code. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4830 7894878c-1315-0410-8ee3-d5d059ff63e0
* Fix compilation breakage with non-C99 compilers.Jean Delvare2007-09-211-2/+1
| | | | git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4829 7894878c-1315-0410-8ee3-d5d059ff63e0
* Add support for beep features.Jean Delvare2007-09-201-1/+1
| | | | git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4826 7894878c-1315-0410-8ee3-d5d059ff63e0
* Move sensors_feature_get_type() from access.c to sysfs.c, it's only calledJean Delvare2007-09-051-0/+91
| | | | | | | from this file. This lets the compiler do additional optimizations. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4776 7894878c-1315-0410-8ee3-d5d059ff63e0
* Add support for temperature offset files, which are part of theJean Delvare2007-09-051-1/+3
| | | | | | | | | | | | | standard sysfs interface. I don't think it makes much sense to display the offset values as part of the output of "sensors" (it would even probably confuse people) but having support for these in libsensors makes it possible to adjust the offsets in sensors.conf, which is convenient. This closes ticket #2248. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4769 7894878c-1315-0410-8ee3-d5d059ff63e0
* Add support for the standard beep_enable attribute (#2248).Jean Delvare2007-09-051-4/+11
| | | | git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4766 7894878c-1315-0410-8ee3-d5d059ff63e0
* Increase MAX_SENSORS_PER_TYPE from 16 to 20: the ADM1026 can have upJean Delvare2007-09-051-1/+1
| | | | | | | | to 17 voltage inputs, and bmcsensors used to support up to 20 voltage values. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4765 7894878c-1315-0410-8ee3-d5d059ff63e0
* Another minor optimization to sensors_read_dynamic_chip():Jean Delvare2007-09-051-18/+13
| | | | | | | | | * We don't need a temporary structure for the feature being currently processed. Instead we can work on the large sparse array directly. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4764 7894878c-1315-0410-8ee3-d5d059ff63e0
* Minor optimizations in sensors_read_dynamic_chip():Jean Delvare2007-09-051-9/+9
| | | | | | | | | | | * We don't need to compute the mapping during the first pass: this field is overwritten when renumbering the features anyway. * Only main features have features mapping to them. * Only subfeatures have mappings, so we can stop the scan at the next main feature. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4763 7894878c-1315-0410-8ee3-d5d059ff63e0
* Now that we can deduce the scaling factor required for each featureJean Delvare2007-09-051-12/+6
| | | | | | | | | | from its type, there's no need to store this scaling factor. We can instead compute it at runtime. This saves some memory (about 10 kB in my real-world test), and the runtime overhead is totally negligible. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4762 7894878c-1315-0410-8ee3-d5d059ff63e0
* Optimize the memory consumption in sensors_read_dynamic_chip(). TheJean Delvare2007-09-051-6/+7
| | | | | | | | | | | | | | idea is to have separate indexing for subfeatures with a compute mapping and for subfeatures without it. They still follow each other in the big table but this avoids wasting memory due to the numbering gap between them. This cuts the amount of memory (temporarily) allocated by sensors_read_dynamic_chip() almost by half, and also speeds it up a little as it now takes less iterations to walk the sparse array. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4761 7894878c-1315-0410-8ee3-d5d059ff63e0
* Store the feature list length separately instead of null-terminatingJean Delvare2007-09-051-2/+3
| | | | | | | | the list. This make it possible to check for out-of-bound indexes without walking the entire list, so that direct look-ups are safer. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4760 7894878c-1315-0410-8ee3-d5d059ff63e0
* Renumber the features linearly, so that feature number N is atJean Delvare2007-09-051-0/+15
| | | | | | | | | | position N in the array. This allows for O(1) look-ups, as opposed to O(N) before. This makes sensors_lookup_feature_nr() 2.4 times faster in my real-world tests, resulting in a 6% performance boost on average in the runtime part of "sensors". git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4759 7894878c-1315-0410-8ee3-d5d059ff63e0
* The compute mapping value is either SENSORS_NO_MAPPING or the sameJean Delvare2007-09-051-6/+3
| | | | | | | | | | feature number as the logical mapping. This means that the compute mapping can be turned into a simple boolean flag. Doing so makes struct sensors_feature_data smaller, which saves some memory (about 17 kB in my tests.) git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4758 7894878c-1315-0410-8ee3-d5d059ff63e0
* Rename sensors_feature_data.mode to flags, as we plan to use it toJean Delvare2007-09-051-2/+2
| | | | | | | store non-mode flags soon. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4757 7894878c-1315-0410-8ee3-d5d059ff63e0
* Start numbering the features at 0, not 1. There's nothing wrong withJean Delvare2007-09-021-3/+3
| | | | | | | having a feature number 0, and this makes the code slightly simpler. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4744 7894878c-1315-0410-8ee3-d5d059ff63e0
* Use the feature type rather than the feature name to figure out whetherJean Delvare2007-09-021-10/+6
| | | | | | | | | we need to add "_input" to get the correct sysfs file name. This is much faster. This is still a ugly hack I'd like to get rid of, but at least now the slowdown is acceptable. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4743 7894878c-1315-0410-8ee3-d5d059ff63e0
* Drop useless return.Jean Delvare2007-09-021-2/+0
| | | | git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4742 7894878c-1315-0410-8ee3-d5d059ff63e0
* Mass reindent, coding style and whitespace cleanups.Jean Delvare2007-08-311-20/+20
| | | | git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4736 7894878c-1315-0410-8ee3-d5d059ff63e0
* Make SENSORS_FEATURE_MAX_SUB_FEATURES private (and rename it toJean Delvare2007-08-301-10/+6
| | | | | | | | | | MAX_SUB_FEATURES in the process.) This value could change in the future so it's not safe to make it part of the libsensors API. And it isn't needed either, applications shouldn't need to use this value. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4732 7894878c-1315-0410-8ee3-d5d059ff63e0
* Allocate the large sparse feature table in sensors_read_dynamic_chip()Jean Delvare2007-08-301-11/+16
| | | | | | | | dynamically. Having large amounts of data on the stack is generally not recommended. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4731 7894878c-1315-0410-8ee3-d5d059ff63e0
* Add support for hardware monitoring chips on SPI buses.Jean Delvare2007-08-191-0/+4
| | | | | | | | | SPI bus statements in the configuration file are not yet supported, as SPI buses don't have a name attribute yet, it's not possible to identify them and thus no substitution is possible. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4689 7894878c-1315-0410-8ee3-d5d059ff63e0
* Support more bus types (part 2 of 2). Originally libsensors was veryJean Delvare2007-08-191-2/+3
| | | | | | | | | | | | i2c-centric. Make it more neutral so that we can cleanly support additional bus types such as SPI or One-Wire. This second part updates sensors_bus to use sensors_bus_id. Thanks to Mark M. Hoffman for showing me how the configuration file parser could be modified to support that change. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4687 7894878c-1315-0410-8ee3-d5d059ff63e0
* Support more bus types (part 1 of 2). Originally libsensors was veryJean Delvare2007-08-191-9/+15
| | | | | | | | | | | i2c-centric. Make it more neutral so that we can cleanly support additional bus types such as SPI or One-Wire. This first part introduces sensors_bus_id, and updates sensors_chip_name to use it. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4686 7894878c-1315-0410-8ee3-d5d059ff63e0
* Don't handle the isa bus in sensors_parse_i2cbus_name(). We reallyJean Delvare2007-08-161-6/+4
| | | | | | | | don't need to, as there is a single ISA bus, there's no need for substituting anything. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4674 7894878c-1315-0410-8ee3-d5d059ff63e0
* Rename sensors_chip_name.busname to path, as this is what we are usingJean Delvare2007-08-161-5/+5
| | | | | | | it for by now. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4673 7894878c-1315-0410-8ee3-d5d059ff63e0
* Drop support for "dummy" bus type. The kernel no longer supportsJean Delvare2007-08-161-1/+1
| | | | | | | | such fake i2c buses, so neither should we. Instead, non-i2c buses are handled explicitly. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4672 7894878c-1315-0410-8ee3-d5d059ff63e0
* Pass the structures by reference inside libsensors. Again a smallJean Delvare2007-08-131-6/+8
| | | | | | | | performance gain, and this makes the internal code consistent with the public functions. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4667 7894878c-1315-0410-8ee3-d5d059ff63e0
* No need to explicitly discard subclients. With the hwmon class, they won'tJean Delvare2007-07-221-5/+0
| | | | | | | | even be found. For earlier kernels, they will be discarded anyway because they expose zero feature. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4638 7894878c-1315-0410-8ee3-d5d059ff63e0
* Discard devices with zero feature.Jean Delvare2007-07-211-1/+11
| | | | git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4637 7894878c-1315-0410-8ee3-d5d059ff63e0
* Fix a memory leak in sensors_read_one_sysfs_chip() when an error occurs.Jean Delvare2007-07-211-4/+11
| | | | git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4636 7894878c-1315-0410-8ee3-d5d059ff63e0
* Now that sensors_feature_get_type() is an internal function, we canJean Delvare2007-07-191-21/+11
| | | | | | | | | | | | | | | | | | | | adjust it to fit our needs better: * Call sensors_feature_get_type() before allocating memory for the feature name. The allocation will be reverted for all sysfs files which are not valid libsensors attributes, and there can be a lot of these. So this saves a few memory allocations. But this means that we want to pass a simple string to sensors_feature_get_type() rather than a struct sensors_feature_data. This also means that sensors_feature_get_type() gets the raw attribute name ("_input" not stripped.) * Get the channel number from sensors_feature_get_type() too. We get it for free from sscanf(), so it's more efficient to return it than to parse it again in sensors_read_dynamic_chip(). git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4630 7894878c-1315-0410-8ee3-d5d059ff63e0
* The way we use sensors_feature_get_type() is rather suboptimal. It isJean Delvare2007-07-191-0/+1
| | | | | | | | | | | | | | | | | | | | | | | first called during the library initialization to generate the feature tables. Then it is called again by sensors itself. This is because we do not store the result the first time. I propose that we add a type field to struct sensors_feature_data, where libsensors would store the result of sensors_feature_get_type(). That way, the application can get the information without calling sensors_feature_get_type() again. This change has the following benefits: * Obviously, a small speed-up. * sensors_feature_get_type() can be removed from the public interface. This means that we can turn it into something that fits the libsensors needs better, allowing for more optimizations (see next patches.) Note: the patch looks bigger that it really is, because I had to move definitions around in sensors.h. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4629 7894878c-1315-0410-8ee3-d5d059ff63e0