mirror of
https://github.com/lm-sensors/lm-sensors
synced 2025-08-29 13:28:01 +00:00
The compute mapping value is either SENSORS_NO_MAPPING or the same
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
This commit is contained in:
parent
87efbc06c5
commit
20c98f41b7
18
lib/access.c
18
lib/access.c
@ -190,7 +190,7 @@ sensors_get_label_exit:
|
||||
|
||||
/* Looks up whether a feature should be ignored. Returns
|
||||
1 if it should be ignored, 0 if not. This function takes
|
||||
logical mappings into account. */
|
||||
mappings into account. */
|
||||
static int sensors_get_ignored(const sensors_chip_name *name,
|
||||
const sensors_chip_feature *feature)
|
||||
{
|
||||
@ -232,11 +232,11 @@ int sensors_get_value(const sensors_chip_name *name, int feature,
|
||||
if (!(main_feature = sensors_lookup_feature_nr(name, feature)))
|
||||
return -SENSORS_ERR_NO_ENTRY;
|
||||
|
||||
if (main_feature->data.compute_mapping == SENSORS_NO_MAPPING)
|
||||
alt_feature = NULL;
|
||||
else
|
||||
if (main_feature->data.flags & SENSORS_COMPUTE_MAPPING)
|
||||
alt_feature = sensors_lookup_feature_nr(name,
|
||||
main_feature->data.compute_mapping);
|
||||
main_feature->data.mapping);
|
||||
else
|
||||
alt_feature = NULL;
|
||||
|
||||
if (!(main_feature->data.flags & SENSORS_MODE_R))
|
||||
return -SENSORS_ERR_ACCESS_R;
|
||||
@ -279,11 +279,11 @@ int sensors_set_value(const sensors_chip_name *name, int feature,
|
||||
if (!(main_feature = sensors_lookup_feature_nr(name, feature)))
|
||||
return -SENSORS_ERR_NO_ENTRY;
|
||||
|
||||
if (main_feature->data.compute_mapping == SENSORS_NO_MAPPING)
|
||||
alt_feature = NULL;
|
||||
else
|
||||
if (main_feature->data.flags & SENSORS_COMPUTE_MAPPING)
|
||||
alt_feature = sensors_lookup_feature_nr(name,
|
||||
main_feature->data.compute_mapping);
|
||||
main_feature->data.mapping);
|
||||
else
|
||||
alt_feature = NULL;
|
||||
|
||||
if (!(main_feature->data.flags & SENSORS_MODE_W))
|
||||
return -SENSORS_ERR_ACCESS_W;
|
||||
|
10
lib/data.h
10
lib/data.h
@ -125,15 +125,13 @@ typedef struct sensors_bus {
|
||||
files and through user functions);
|
||||
number is the internal feature number, used in many functions to refer
|
||||
to this feature
|
||||
logical_mapping is either SENSORS_NO_MAPPING if this is feature is the
|
||||
mapping is either SENSORS_NO_MAPPING if this is feature is the
|
||||
main element of category; or it is the number of a feature with which
|
||||
this feature is logically grouped (a group could be fan, fan_max and
|
||||
fan_div)
|
||||
compute_mapping is like logical_mapping, only it refers to another
|
||||
feature whose compute line will be inherited (a group could be fan and
|
||||
fan_max, but not fan_div)
|
||||
flags is a bitfield, its value is a combination of SENSORS_MODE_R (readable)
|
||||
and SENSORS_MODE_W (writable).
|
||||
flags is a bitfield, its value is a combination of SENSORS_MODE_R (readable),
|
||||
SENSORS_MODE_W (writable) and SENSORS_COMPUTE_MAPPING (affected by the
|
||||
computation rules of the main feature).
|
||||
scaling is the number of decimal points to scale by.
|
||||
Divide the read value by 10**scaling to get the real value. */
|
||||
typedef struct sensors_chip_feature {
|
||||
|
@ -112,15 +112,14 @@ This structure is used when you want to get all features of a specific chip.
|
||||
sensors_feature_type type;
|
||||
.br
|
||||
int mapping;
|
||||
.br
|
||||
int compute_mapping;
|
||||
.br
|
||||
unsigned int flags;
|
||||
.br
|
||||
} sensors_feature_data;\fP
|
||||
.br
|
||||
The flags field is a bitfield, its value is a combination of
|
||||
SENSORS_MODE_R (readable) and SENSORS_MODE_W (writable).
|
||||
SENSORS_MODE_R (readable), SENSORS_MODE_W (writable) and SENSORS_COMPUTE_MAPPING
|
||||
(affected by the computation rules of the main feature).
|
||||
|
||||
\fBconst sensors_feature_data *sensors_get_all_features
|
||||
(const sensors_chip_name *name, int *nr);\fP
|
||||
|
@ -115,6 +115,7 @@ const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name
|
||||
/* These defines are used in the flags field of sensors_feature_data */
|
||||
#define SENSORS_MODE_R 1
|
||||
#define SENSORS_MODE_W 2
|
||||
#define SENSORS_COMPUTE_MAPPING 4
|
||||
|
||||
/* This define is used in the mapping field of sensors_feature_data if no
|
||||
mapping is available */
|
||||
@ -122,7 +123,7 @@ const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name
|
||||
|
||||
/* This enum contains some "magic" used by sensors_read_dynamic_chip() from
|
||||
lib/sysfs.c. All the sensor types (in, fan, temp, vid) are a multiple of
|
||||
0x100 apart, and sensor features which should not have a compute_mapping to
|
||||
0x100 apart, and sensor features which should not have a compute mapping to
|
||||
the _input feature start at 0x?10. */
|
||||
typedef enum sensors_feature_type {
|
||||
SENSORS_FEATURE_IN = 0x000,
|
||||
@ -163,7 +164,6 @@ typedef struct sensors_feature_data {
|
||||
int number;
|
||||
sensors_feature_type type;
|
||||
int mapping;
|
||||
int compute_mapping;
|
||||
unsigned int flags;
|
||||
} sensors_feature_data;
|
||||
|
||||
|
@ -142,14 +142,11 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
||||
if ((type & 0x00FF) == 0) {
|
||||
/* main feature */
|
||||
feature.data.mapping = SENSORS_NO_MAPPING;
|
||||
feature.data.compute_mapping = SENSORS_NO_MAPPING;
|
||||
} else if (type & 0x10) {
|
||||
/* sub feature without compute mapping */
|
||||
feature.data.mapping = i - i % MAX_SUB_FEATURES;
|
||||
feature.data.compute_mapping = SENSORS_NO_MAPPING;
|
||||
} else {
|
||||
/* sub feature */
|
||||
feature.data.mapping = i - i % MAX_SUB_FEATURES;
|
||||
feature.data.compute_mapping = feature.data.mapping;
|
||||
if (!(type & 0x10))
|
||||
feature.data.flags |= SENSORS_COMPUTE_MAPPING;
|
||||
}
|
||||
|
||||
if (attr->method & SYSFS_METHOD_SHOW)
|
||||
|
Loading…
x
Reference in New Issue
Block a user