From ed480f2eddbc20a9b0388b3e165437383c4ce55e Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 5 Sep 2007 08:20:35 +0000 Subject: [PATCH] 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. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4761 7894878c-1315-0410-8ee3-d5d059ff63e0 --- lib/sysfs.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/sysfs.c b/lib/sysfs.c index 9d66cf65..f9d28eb3 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -37,9 +37,9 @@ char sensors_sysfs_mount[NAME_MAX]; #define MAX_SENSORS_PER_TYPE 16 -#define MAX_SUB_FEATURES 22 +#define MAX_SUB_FEATURES 6 /* Room for all 3 types (in, fan, temp) with all their subfeatures + VID */ -#define ALL_POSSIBLE_FEATURES (MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 3 \ +#define ALL_POSSIBLE_FEATURES (MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 6 \ + MAX_SENSORS_PER_TYPE) static @@ -120,11 +120,12 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, /* "calculate" a place to store the feature in our sparse, sorted table */ if (type == SENSORS_FEATURE_VID) { - i = nr + MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 3; + i = nr + MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 6; } else { i = (type >> 8) * MAX_SENSORS_PER_TYPE * - MAX_SUB_FEATURES + nr * MAX_SUB_FEATURES + - (type & 0xFF); + MAX_SUB_FEATURES * 2 + nr * MAX_SUB_FEATURES * 2 + + ((type & 0x10) >> 4) * MAX_SUB_FEATURES + + (type & 0x0F); } if (features[i].data.name) { @@ -144,7 +145,7 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, feature.data.mapping = SENSORS_NO_MAPPING; } else { /* sub feature */ - feature.data.mapping = i - i % MAX_SUB_FEATURES; + feature.data.mapping = i - i % (MAX_SUB_FEATURES * 2); if (!(type & 0x10)) feature.data.flags |= SENSORS_COMPUTE_MAPPING; }