The way we use sensors_feature_get_type() is rather suboptimal. It is

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
This commit is contained in:
Jean Delvare committed 2007-07-19 20:46:09 +00:00
1 parent ac5ae18fe7
commit 70317e1a0e
5 files changed
+29 -30

No files matched your search

+2
View File
@@ -29,4 +29,6 @@
extern const sensors_chip_feature *sensors_lookup_feature_nr(const sensors_chip_name *chip,
int feature);
sensors_feature_type sensors_feature_get_type(const sensors_feature_data *feature);
#endif /* def LIB_SENSORS_ACCESS_H */
+3 -1
View File
@@ -117,10 +117,12 @@ This structure is used when you want to get all features of a specific chip.
int number;
.br
const char *name;
.br
sensors_feature_type type;
.br
int mapping;
.br
int unused;
int compute_mapping;
.br
int mode;
.br
+21 -23
View File
@@ -125,27 +125,6 @@ extern const sensors_chip_name *sensors_get_detected_chips(int *nr);
mapping is available */
#define SENSORS_NO_MAPPING -1
/* This structure is used when you want to get all features of a specific
chip. */
typedef struct sensors_feature_data {
int number;
char *name;
int mapping;
int compute_mapping;
int mode;
} sensors_feature_data;
/* This returns all features of a specific chip. They are returned in
bunches: everything with the same mapping is returned just after each
other, with the master feature in front (that feature does not map to
itself, but has SENSORS_NO_MAPPING as mapping field). nr1 and nr2 are
two internally used variables. Set both to zero to start again at the
begin of the list. If no more features are found NULL is returned.
Do not try to change the returned structure; you will corrupt internal
data structures. */
extern const sensors_feature_data *sensors_get_all_features
(sensors_chip_name name, int *nr1,int *nr2);
/* 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
@@ -186,8 +165,27 @@ typedef enum sensors_feature_type {
SENSORS_FEATURE_MAX_SUB_FEATURES = 22
} sensors_feature_type;
sensors_feature_type sensors_feature_get_type
(const sensors_feature_data *feature);
/* This structure is used when you want to get all features of a specific
chip. */
typedef struct sensors_feature_data {
int number;
char *name;
sensors_feature_type type;
int mapping;
int compute_mapping;
int mode;
} sensors_feature_data;
/* This returns all features of a specific chip. They are returned in
bunches: everything with the same mapping is returned just after each
other, with the master feature in front (that feature does not map to
itself, but has SENSORS_NO_MAPPING as mapping field). nr1 and nr2 are
two internally used variables. Set both to zero to start again at the
begin of the list. If no more features are found NULL is returned.
Do not try to change the returned structure; you will corrupt internal
data structures. */
extern const sensors_feature_data *sensors_get_all_features
(sensors_chip_name name, int *nr1,int *nr2);
#ifdef __cplusplus
}
+1
View File
@@ -148,6 +148,7 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
/* fill in the other feature members */
feature.data.number = i + 1;
feature.data.type = type;
if ((type & 0x00FF) == 0) {
/* main feature */
+2 -6
View File
@@ -46,13 +46,9 @@ static void sensors_get_available_features(const sensors_chip_name *name,
while((iter = sensors_get_all_features(*name, &i, &j)) &&
iter->mapping != SENSORS_NO_MAPPING &&
iter->mapping == feature->number) {
sensors_feature_type type = sensors_feature_get_type(iter);
int indx;
if (type == SENSORS_FEATURE_UNKNOWN)
continue;
indx = type - first_val - 1;
indx = iter->type - first_val - 1;
if (indx < 0 || indx >= size) {
printf("ERROR: Bug in sensors: index out of bound");
return;
@@ -345,7 +341,7 @@ void print_generic_chip(const sensors_chip_name *name)
if (feature->mapping != SENSORS_NO_MAPPING)
continue;
switch(sensors_feature_get_type(feature)) {
switch (feature->type) {
case SENSORS_FEATURE_TEMP:
print_generic_chip_temp(name, feature, i, j, label_size); break;
case SENSORS_FEATURE_IN: