Scan chip features only once at initialization time, rather than on

each update. The chip list and chip features do not change until
sensors_cleanup() is called, so there's no point in doing the
same work over and over again.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4828 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2007-09-21 12:15:18 +00:00
1 parent 49649fcf05
commit 5bd020ad92
5 files changed
+80 -26

No files matched your search

+42 -10
View File
@@ -332,12 +332,11 @@ static void fillChipBeepEnable (FeatureDescriptor *beepen,
beepen->dataNumbers[1] = -1;
}
/* Note that alarms and beeps are no longer (or not yet) supported */
ChipDescriptor * generateChipDescriptor (const sensors_chip_name *chip)
static
FeatureDescriptor * generateChipFeatures (const sensors_chip_name *chip)
{
int nr, count = 1;
const sensors_feature_data *sensor;
ChipDescriptor *descriptor;
FeatureDescriptor *features;
/* How many main features do we have? */
@@ -348,14 +347,9 @@ ChipDescriptor * generateChipDescriptor (const sensors_chip_name *chip)
}
/* Allocate the memory we need */
descriptor = calloc(1, sizeof(ChipDescriptor));
features = calloc(count, sizeof(FeatureDescriptor));
if (!descriptor || !features) {
free(descriptor);
free(features);
if (!features)
return NULL;
}
descriptor->features = features;
/* Fill in the data structures */
count = 0;
@@ -387,5 +381,43 @@ ChipDescriptor * generateChipDescriptor (const sensors_chip_name *chip)
count++;
}
return descriptor;
return features;
}
ChipDescriptor * knownChips;
int initKnownChips (void)
{
int nr, count = 1;
const sensors_chip_name *name;
/* How many chips do we have? */
nr = 0;
while ((name = sensors_get_detected_chips(NULL, &nr)))
count++;
/* Allocate the memory we need */
knownChips = calloc(count, sizeof(ChipDescriptor));
if (!knownChips)
return 1;
/* Fill in the data structures */
count = 0;
nr = 0;
while ((name = sensors_get_detected_chips(NULL, &nr))) {
knownChips[count].name = name;
if ((knownChips[count].features = generateChipFeatures(name)))
count++;
}
return 0;
}
void freeKnownChips (void)
{
int index0;
for (index0 = 0; knownChips[index0].features; index0++)
free (knownChips[index0].features);
free (knownChips);
}
+12 -2
View File
@@ -116,18 +116,28 @@ loadConfig
int
loadLib
(void) {
return loadConfig (0);
int ret;
ret = loadConfig (0);
if (!ret)
ret = initKnownChips ();
return ret;
}
int
reloadLib
(void) {
return loadConfig (1);
int ret;
freeKnownChips ();
ret = loadConfig (1);
if (!ret)
ret = initKnownChips ();
return ret;
}
int
unloadLib
(void) {
freeKnownChips ();
sensors_cleanup ();
return 0;
}
+11 -6
View File
@@ -141,11 +141,18 @@ applyToFeatures
for (j = 0; (ret == 0) && (j < numChipNames); ++ j) {
while ((ret == 0) && ((chip = sensors_get_detected_chips (&chipNames[j], &i)) != NULL)) {
ChipDescriptor *descriptor;
descriptor = generateChipDescriptor (chip);
if (descriptor) {
int index0, chipindex = -1;
for (index0 = 0; knownChips[index0].features; ++ index0)
/* Trick: we compare addresses here. We know it works because both
pointers were returned by sensors_get_detected_chips(), so they
refer to libsensors internal structures, which do not move. */
if (knownChips[index0].name == chip) {
chipindex = index0;
break;
}
if (chipindex >= 0) {
const ChipDescriptor *descriptor = &knownChips[chipindex];
const FeatureDescriptor *features = descriptor->features;
int index0;
for (index0 = 0; (ret == 0) && (num < MAX_RRD_SENSORS) && features[index0].format; ++ index0) {
const FeatureDescriptor *feature = features + index0;
@@ -167,8 +174,6 @@ applyToFeatures
if (label)
free (label);
}
free (descriptor->features);
free (descriptor);
}
}
}
+11 -7
View File
@@ -168,13 +168,17 @@ doChip
if (action == DO_SET) {
ret = setChip (chip);
} else {
ChipDescriptor *descriptor;
descriptor = generateChipDescriptor (chip);
if (descriptor) {
ret = doKnownChip (chip, descriptor, action);
free (descriptor->features);
free (descriptor);
}
int index0, chipindex = -1;
for (index0 = 0; knownChips[index0].features; ++ index0)
/* Trick: we compare addresses here. We know it works because both
pointers were returned by sensors_get_detected_chips(), so they
refer to libsensors internal structures, which do not move. */
if (knownChips[index0].name == chip) {
chipindex = index0;
break;
}
if (chipindex >= 0)
ret = doKnownChip (chip, &knownChips[chipindex], action);
}
return ret;
}
+4 -1
View File
@@ -95,7 +95,10 @@ typedef struct {
} FeatureDescriptor;
typedef struct {
const sensors_chip_name *name;
FeatureDescriptor *features;
} ChipDescriptor;
extern ChipDescriptor * generateChipDescriptor (const sensors_chip_name *chip);
extern ChipDescriptor * knownChips;
extern int initKnownChips (void);
extern void freeKnownChips (void);