Changeset 5183

Show
Ignore:
Timestamp:
04/17/08 03:27:22 (7 months ago)
Author:
djwong
Message:

Subject: [PATCH 1/3 v3] libsensors: Support energy and power meters

Add power and sensor meters to libsensors, with minor tweaks and
documentation updates as suggested by Jean Delvare.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lm-sensors/branches/lm-sensors-3.0.0/CHANGES

    r5180 r5183  
    77              Late compute statements override early ones 
    88              Support virtual hwmon devices (#2309) 
     9              Support power and energy sensors 
    910  pwmconfig: Don't create the configuration file before it's needed 
    1011             Don't preserve configuration file customizations 
  • lm-sensors/branches/lm-sensors-3.0.0/doc/libsensors-API.txt

    r5176 r5183  
    77given new feature. 
    88 
     90x402   lm-sensors SVN 
     10* Added support for power and energy sensors 
     11SENSORS_FEATURE_POWER = 3 
     12SENSORS_FEATURE_ENERGY = 4 
     13SENSORS_SUBFEATURE_POWER_AVERAGE 
     14SENSORS_SUBFEATURE_POWER_AVERAGE_HIGHEST 
     15SENSORS_SUBFEATURE_POWER_AVERAGE_LOWEST 
     16SENSORS_SUBFEATURE_POWER_AVERAGE_INTERVAL 
     17SENSORS_SUBFEATURE_ENERGY_INPUT 
     18 
    9190x401   lm-sensors SVN 
    1020* Added bus type "virtual": 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sensors.h

    r5177 r5183  
    133133        SENSORS_FEATURE_FAN             = 0x01, 
    134134        SENSORS_FEATURE_TEMP            = 0x02, 
     135        SENSORS_FEATURE_POWER           = 0x03, 
     136        SENSORS_FEATURE_ENERGY          = 0x04, 
    135137        SENSORS_FEATURE_VID             = 0x10, 
    136138        SENSORS_FEATURE_BEEP_ENABLE     = 0x18, 
     
    170172        SENSORS_SUBFEATURE_TEMP_OFFSET, 
    171173        SENSORS_SUBFEATURE_TEMP_BEEP, 
     174 
     175        SENSORS_SUBFEATURE_POWER_AVERAGE = SENSORS_FEATURE_POWER << 8, 
     176        SENSORS_SUBFEATURE_POWER_AVERAGE_HIGHEST, 
     177        SENSORS_SUBFEATURE_POWER_AVERAGE_LOWEST, 
     178 
     179        SENSORS_SUBFEATURE_POWER_AVERAGE_INTERVAL = (SENSORS_FEATURE_POWER << 8) | 0x80, 
     180 
     181        SENSORS_SUBFEATURE_ENERGY_INPUT = SENSORS_FEATURE_ENERGY << 8, 
    172182 
    173183        SENSORS_SUBFEATURE_VID = SENSORS_FEATURE_VID << 8, 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c

    r5176 r5183  
    139139#define MAX_SENSORS_PER_TYPE    20 
    140140#define MAX_SUBFEATURES         8 
    141 /* Room for all 3 types (in, fan, temp) with all their subfeatures + VID 
    142    + misc features */ 
     141#define MAX_SENSOR_TYPES        5 
     142/* Room for all 5 types (in, fan, temp, power, energy) with all their 
     143   subfeatures + VID + misc features */ 
    143144#define ALL_POSSIBLE_SUBFEATURES \ 
    144                                 (MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 6 \ 
    145                                  + MAX_SENSORS_PER_TYPE + 1) 
     145                                (MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * \ 
     146                                 MAX_SENSOR_TYPES * 2 + \ 
     147                                 MAX_SENSORS_PER_TYPE + 1) 
    146148 
    147149static 
    148150int get_type_scaling(sensors_subfeature_type type) 
    149151{ 
     152        /* Multipliers for subfeatures */ 
    150153        switch (type & 0xFF80) { 
    151154        case SENSORS_SUBFEATURE_IN_INPUT: 
     
    154157        case SENSORS_SUBFEATURE_FAN_INPUT: 
    155158                return 1; 
    156         } 
    157  
     159        case SENSORS_SUBFEATURE_POWER_AVERAGE: 
     160        case SENSORS_SUBFEATURE_ENERGY_INPUT: 
     161                return 1000000; 
     162        } 
     163 
     164        /* Multipliers for second class subfeatures 
     165           that need their own multiplier */ 
    158166        switch (type) { 
     167        case SENSORS_SUBFEATURE_POWER_AVERAGE_INTERVAL: 
    159168        case SENSORS_SUBFEATURE_VID: 
    160169        case SENSORS_SUBFEATURE_TEMP_OFFSET: 
     
    174183        case SENSORS_FEATURE_FAN: 
    175184        case SENSORS_FEATURE_TEMP: 
     185        case SENSORS_FEATURE_POWER: 
     186        case SENSORS_FEATURE_ENERGY: 
    176187                underscore = strchr(sfname, '_'); 
    177188                name = strndup(sfname, underscore - sfname); 
     
    233244}; 
    234245 
     246static const struct subfeature_type_match power_matches[] = { 
     247        { "average", SENSORS_SUBFEATURE_POWER_AVERAGE }, 
     248        { "average_highest", SENSORS_SUBFEATURE_POWER_AVERAGE_HIGHEST }, 
     249        { "average_lowest", SENSORS_SUBFEATURE_POWER_AVERAGE_LOWEST }, 
     250        { "average_interval", SENSORS_SUBFEATURE_POWER_AVERAGE_INTERVAL }, 
     251        { NULL, 0 } 
     252}; 
     253 
     254static const struct subfeature_type_match energy_matches[] = { 
     255        { "input", SENSORS_SUBFEATURE_ENERGY_INPUT }, 
     256        { NULL, 0 } 
     257}; 
     258 
    235259static const struct subfeature_type_match cpu_matches[] = { 
    236260        { "vid", SENSORS_SUBFEATURE_VID }, 
     
    243267        { "fan%d%c", fan_matches }, 
    244268        { "cpu%d%c", cpu_matches }, 
     269        { "power%d%c", power_matches }, 
     270        { "energy%d%c", energy_matches }, 
    245271}; 
    246272 
     
    328354                /* Adjust the channel number */ 
    329355                switch (sftype & 0xFF00) { 
    330                         case SENSORS_SUBFEATURE_FAN_INPUT: 
    331                         case SENSORS_SUBFEATURE_TEMP_INPUT: 
    332                                 nr--; 
    333                                 break; 
     356                case SENSORS_SUBFEATURE_FAN_INPUT: 
     357                case SENSORS_SUBFEATURE_TEMP_INPUT: 
     358                case SENSORS_SUBFEATURE_POWER_AVERAGE: 
     359                case SENSORS_SUBFEATURE_ENERGY_INPUT: 
     360                        nr--; 
     361                        break; 
    334362                } 
    335363 
     
    348376                switch (sftype) { 
    349377                case SENSORS_SUBFEATURE_VID: 
    350                         i = nr + MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 6; 
     378                        i = nr + MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 
     379                            MAX_SENSOR_TYPES * 2; 
    351380                        break; 
    352381                case SENSORS_SUBFEATURE_BEEP_ENABLE: 
    353                         i = MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 6 + 
    354                             MAX_SENSORS_PER_TYPE; 
     382                        i = MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 
     383                            MAX_SENSOR_TYPES * 2 + MAX_SENSORS_PER_TYPE; 
    355384                        break; 
    356385                default: 
     
    390419                        continue; 
    391420 
    392                 if (i >= MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 6 || 
     421                if (i >= MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 
     422                    MAX_SENSOR_TYPES * 2 || 
    393423                    i / (MAX_SUBFEATURES * 2) != prev_slot) { 
    394424                        fnum++; 
     
    411441 
    412442                /* New main feature? */ 
    413                 if (i >= MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 6 || 
     443                if (i >= MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 
     444                    MAX_SENSOR_TYPES * 2 || 
    414445                    i / (MAX_SUBFEATURES * 2) != prev_slot) { 
    415446                        ftype = all_subfeatures[i].type >> 8;