Changeset 4629

Show
Ignore:
Timestamp:
07/19/07 22:46:09 (1 year ago)
Author:
khali
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lm-sensors/branches/lm-sensors-3.0.0/lib/access.h

    r4545 r4629  
    3030                                                             int feature); 
    3131 
     32sensors_feature_type sensors_feature_get_type(const sensors_feature_data *feature); 
     33 
    3234#endif /* def LIB_SENSORS_ACCESS_H */ 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/libsensors.3

    r4602 r4629  
    119119  const char *name; 
    120120.br 
     121  sensors_feature_type type; 
     122.br 
    121123  int mapping; 
    122124.br 
    123   int unused
     125  int compute_mapping
    124126.br 
    125127  int mode; 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sensors.h

    r4602 r4629  
    126126#define SENSORS_NO_MAPPING -1 
    127127 
    128 /* This structure is used when you want to get all features of a specific 
    129    chip. */ 
    130 typedef struct sensors_feature_data { 
    131   int number; 
    132   char *name; 
    133   int mapping; 
    134   int compute_mapping; 
    135   int mode; 
    136 } sensors_feature_data; 
    137  
    138 /* This returns all features of a specific chip. They are returned in  
    139    bunches: everything with the same mapping is returned just after each 
    140    other, with the master feature in front (that feature does not map to 
    141    itself, but has SENSORS_NO_MAPPING as mapping field). nr1 and nr2 are 
    142    two internally used variables. Set both to zero to start again at the 
    143    begin of the list. If no more features are found NULL is returned. 
    144    Do not try to change the returned structure; you will corrupt internal 
    145    data structures. */ 
    146 extern const sensors_feature_data *sensors_get_all_features  
    147              (sensors_chip_name name, int *nr1,int *nr2); 
    148  
    149128/* This enum contains some "magic" used by sensors_read_dynamic_chip() from 
    150129   lib/sysfs.c. All the sensor types (in, fan, temp, vid) are a multiple of 
     
    187166} sensors_feature_type; 
    188167 
    189 sensors_feature_type sensors_feature_get_type 
    190              (const sensors_feature_data *feature); 
     168/* This structure is used when you want to get all features of a specific 
     169   chip. */ 
     170typedef struct sensors_feature_data { 
     171  int number; 
     172  char *name; 
     173  sensors_feature_type type; 
     174  int mapping; 
     175  int compute_mapping; 
     176  int mode; 
     177} sensors_feature_data; 
     178 
     179/* This returns all features of a specific chip. They are returned in 
     180   bunches: everything with the same mapping is returned just after each 
     181   other, with the master feature in front (that feature does not map to 
     182   itself, but has SENSORS_NO_MAPPING as mapping field). nr1 and nr2 are 
     183   two internally used variables. Set both to zero to start again at the 
     184   begin of the list. If no more features are found NULL is returned. 
     185   Do not try to change the returned structure; you will corrupt internal 
     186   data structures. */ 
     187extern const sensors_feature_data *sensors_get_all_features 
     188             (sensors_chip_name name, int *nr1,int *nr2); 
    191189 
    192190#ifdef __cplusplus 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c

    r4616 r4629  
    149149                /* fill in the other feature members */ 
    150150                feature.data.number = i + 1; 
     151                feature.data.type = type; 
    151152                         
    152153                if ((type & 0x00FF) == 0) { 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensors/chips_generic.c

    r4598 r4629  
    4747      iter->mapping != SENSORS_NO_MAPPING && 
    4848      iter->mapping == feature->number) { 
    49     sensors_feature_type type = sensors_feature_get_type(iter); 
    5049    int indx; 
    5150     
    52     if (type == SENSORS_FEATURE_UNKNOWN) 
    53       continue; 
    54      
    55     indx = type - first_val - 1; 
     51    indx = iter->type - first_val - 1; 
    5652    if (indx < 0 || indx >= size) { 
    5753      printf("ERROR: Bug in sensors: index out of bound"); 
     
    346342      continue; 
    347343     
    348     switch(sensors_feature_get_type(feature)) { 
     344    switch (feature->type) { 
    349345      case SENSORS_FEATURE_TEMP: 
    350346        print_generic_chip_temp(name, feature, i, j, label_size); break;