mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-24 20:21:43 +00:00
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:
1 parent
49649fcf05
commit
5bd020ad92
5 files changed
+80
-26
No files matched your search
+42
-10
@@ -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
@@ -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
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
Reference in new issue
Block a user