Changeset 4761

Show
Ignore:
Timestamp:
09/05/07 10:20:35 (6 years ago)
Author:
khali
Message:

Optimize the memory consumption in sensors_read_dynamic_chip(). The
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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c

    r4760 r4761  
    3838 
    3939#define MAX_SENSORS_PER_TYPE    16 
    40 #define MAX_SUB_FEATURES        22 
     40#define MAX_SUB_FEATURES        6 
    4141/* Room for all 3 types (in, fan, temp) with all their subfeatures + VID */ 
    42 #define ALL_POSSIBLE_FEATURES   (MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 3 \ 
     42#define ALL_POSSIBLE_FEATURES   (MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 6 \ 
    4343                                 + MAX_SENSORS_PER_TYPE) 
    4444 
     
    121121                   sorted table */ 
    122122                if (type == SENSORS_FEATURE_VID) { 
    123                         i = nr + MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 3; 
     123                        i = nr + MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 6; 
    124124                } else { 
    125125                        i = (type >> 8) * MAX_SENSORS_PER_TYPE * 
    126                                 MAX_SUB_FEATURES + nr * MAX_SUB_FEATURES + 
    127                                 (type & 0xFF); 
     126                            MAX_SUB_FEATURES * 2 + nr * MAX_SUB_FEATURES * 2 + 
     127                            ((type & 0x10) >> 4) * MAX_SUB_FEATURES + 
     128                            (type & 0x0F); 
    128129                } 
    129130 
     
    145146                } else { 
    146147                        /* sub feature */ 
    147                         feature.data.mapping = i - i % MAX_SUB_FEATURES; 
     148                        feature.data.mapping = i - i % (MAX_SUB_FEATURES * 2); 
    148149                        if (!(type & 0x10)) 
    149150                                feature.data.flags |= SENSORS_COMPUTE_MAPPING;