2
0
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:
Jean Delvare 2007-09-05 08:17:22 +00:00
parent 87efbc06c5
commit 20c98f41b7
5 changed files with 22 additions and 28 deletions

View File

@ -190,7 +190,7 @@ sensors_get_label_exit:
/* Looks up whether a feature should be ignored. Returns /* Looks up whether a feature should be ignored. Returns
1 if it should be ignored, 0 if not. This function takes 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, static int sensors_get_ignored(const sensors_chip_name *name,
const sensors_chip_feature *feature) 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))) if (!(main_feature = sensors_lookup_feature_nr(name, feature)))
return -SENSORS_ERR_NO_ENTRY; return -SENSORS_ERR_NO_ENTRY;
if (main_feature->data.compute_mapping == SENSORS_NO_MAPPING) if (main_feature->data.flags & SENSORS_COMPUTE_MAPPING)
alt_feature = NULL;
else
alt_feature = sensors_lookup_feature_nr(name, 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)) if (!(main_feature->data.flags & SENSORS_MODE_R))
return -SENSORS_ERR_ACCESS_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))) if (!(main_feature = sensors_lookup_feature_nr(name, feature)))
return -SENSORS_ERR_NO_ENTRY; return -SENSORS_ERR_NO_ENTRY;
if (main_feature->data.compute_mapping == SENSORS_NO_MAPPING) if (main_feature->data.flags & SENSORS_COMPUTE_MAPPING)
alt_feature = NULL;
else
alt_feature = sensors_lookup_feature_nr(name, 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)) if (!(main_feature->data.flags & SENSORS_MODE_W))
return -SENSORS_ERR_ACCESS_W; return -SENSORS_ERR_ACCESS_W;

View File

@ -125,15 +125,13 @@ typedef struct sensors_bus {
files and through user functions); files and through user functions);
number is the internal feature number, used in many functions to refer number is the internal feature number, used in many functions to refer
to this feature 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 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 this feature is logically grouped (a group could be fan, fan_max and
fan_div) fan_div)
compute_mapping is like logical_mapping, only it refers to another flags is a bitfield, its value is a combination of SENSORS_MODE_R (readable),
feature whose compute line will be inherited (a group could be fan and SENSORS_MODE_W (writable) and SENSORS_COMPUTE_MAPPING (affected by the
fan_max, but not fan_div) computation rules of the main feature).
flags is a bitfield, its value is a combination of SENSORS_MODE_R (readable)
and SENSORS_MODE_W (writable).
scaling is the number of decimal points to scale by. scaling is the number of decimal points to scale by.
Divide the read value by 10**scaling to get the real value. */ Divide the read value by 10**scaling to get the real value. */
typedef struct sensors_chip_feature { typedef struct sensors_chip_feature {

View File

@ -112,15 +112,14 @@ This structure is used when you want to get all features of a specific chip.
sensors_feature_type type; sensors_feature_type type;
.br .br
int mapping; int mapping;
.br
int compute_mapping;
.br .br
unsigned int flags; unsigned int flags;
.br .br
} sensors_feature_data;\fP } sensors_feature_data;\fP
.br .br
The flags field is a bitfield, its value is a combination of 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 \fBconst sensors_feature_data *sensors_get_all_features
(const sensors_chip_name *name, int *nr);\fP (const sensors_chip_name *name, int *nr);\fP

View File

@ -113,8 +113,9 @@ const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name
*match, int *nr); *match, int *nr);
/* These defines are used in the flags field of sensors_feature_data */ /* These defines are used in the flags field of sensors_feature_data */
#define SENSORS_MODE_R 1 #define SENSORS_MODE_R 1
#define SENSORS_MODE_W 2 #define SENSORS_MODE_W 2
#define SENSORS_COMPUTE_MAPPING 4
/* This define is used in the mapping field of sensors_feature_data if no /* This define is used in the mapping field of sensors_feature_data if no
mapping is available */ 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 /* 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 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. */ the _input feature start at 0x?10. */
typedef enum sensors_feature_type { typedef enum sensors_feature_type {
SENSORS_FEATURE_IN = 0x000, SENSORS_FEATURE_IN = 0x000,
@ -163,7 +164,6 @@ typedef struct sensors_feature_data {
int number; int number;
sensors_feature_type type; sensors_feature_type type;
int mapping; int mapping;
int compute_mapping;
unsigned int flags; unsigned int flags;
} sensors_feature_data; } sensors_feature_data;

View File

@ -142,14 +142,11 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
if ((type & 0x00FF) == 0) { if ((type & 0x00FF) == 0) {
/* main feature */ /* main feature */
feature.data.mapping = SENSORS_NO_MAPPING; 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 { } else {
/* sub feature */
feature.data.mapping = i - i % MAX_SUB_FEATURES; 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) if (attr->method & SYSFS_METHOD_SHOW)