mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-28 12:40:42 +00:00
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
This commit is contained in:
1 parent
23f4274010
commit
ed480f2edd
1 file changed
+7
-6
+7
-6
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user