2
0
mirror of https://github.com/lm-sensors/lm-sensors synced 2025-08-30 22:05:11 +00:00

Use sensors_lookup_chip() to speed up sensors_lookup_subfeature_name()

as well.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4844 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare
2007-09-23 12:23:38 +00:00
parent 36f5b0dc4d
commit e55b84392b

View File

@@ -28,7 +28,7 @@
#include "sysfs.h" #include "sysfs.h"
#include "general.h" #include "general.h"
static int sensors_eval_expr(const sensors_chip_name *name, static int sensors_eval_expr(const sensors_chip_features *chip_features,
const sensors_expr *expr, const sensors_expr *expr,
double val, double *result); double val, double *result);
@@ -126,23 +126,18 @@ sensors_lookup_feature_nr(const sensors_chip_features *chip, int feat_nr)
return chip->feature + feat_nr; return chip->feature + feat_nr;
} }
/* Look up a resource in the intern chip list, and return a pointer to it. /* Look up a subfeature by name, and return a pointer to it.
Do not modify the struct the return value points to! Returns NULL if Do not modify the struct the return value points to! Returns NULL if
not found.*/ not found.*/
static const sensors_subfeature * static const sensors_subfeature *
sensors_lookup_subfeature_name(const sensors_chip_name *chip, sensors_lookup_subfeature_name(const sensors_chip_features *chip,
const char *name) const char *name)
{ {
int i, j; int j;
const sensors_subfeature *subfeatures;
for (i = 0; i < sensors_proc_chips_count; i++) for (j = 0; j < chip->subfeature_count; j++)
if (sensors_match_chip(&sensors_proc_chips[i].chip, chip)) { if (!strcmp(chip->subfeature[j].name, name))
subfeatures = sensors_proc_chips[i].subfeature; return chip->subfeature + j;
for (j = 0; j < sensors_proc_chips[i].subfeature_count; j++)
if (!strcmp(subfeatures[j].name, name))
return subfeatures + j;
}
return NULL; return NULL;
} }
@@ -267,7 +262,7 @@ int sensors_get_value(const sensors_chip_name *name, int subfeat_nr,
return -SENSORS_ERR_PROC; return -SENSORS_ERR_PROC;
if (!expr) if (!expr)
*result = val; *result = val;
else if ((res = sensors_eval_expr(name, expr, val, result))) else if ((res = sensors_eval_expr(chip_features, expr, val, result)))
return res; return res;
return 0; return 0;
} }
@@ -315,7 +310,8 @@ int sensors_set_value(const sensors_chip_name *name, int subfeat_nr,
to_write = value; to_write = value;
if (expr) if (expr)
if ((res = sensors_eval_expr(name, expr, value, &to_write))) if ((res = sensors_eval_expr(chip_features, expr,
value, &to_write)))
return res; return res;
if (sensors_write_sysfs_attr(name, subfeature, to_write)) if (sensors_write_sysfs_attr(name, subfeature, to_write))
return -SENSORS_ERR_PROC; return -SENSORS_ERR_PROC;
@@ -402,7 +398,7 @@ sensors_get_all_subfeatures(const sensors_chip_name *name,
} }
/* Evaluate an expression */ /* Evaluate an expression */
int sensors_eval_expr(const sensors_chip_name *name, int sensors_eval_expr(const sensors_chip_features *chip_features,
const sensors_expr *expr, const sensors_expr *expr,
double val, double *result) double val, double *result)
{ {
@@ -419,18 +415,20 @@ int sensors_eval_expr(const sensors_chip_name *name,
return 0; return 0;
} }
if (expr->kind == sensors_kind_var) { if (expr->kind == sensors_kind_var) {
if (!(subfeature = sensors_lookup_subfeature_name(name, if (!(subfeature = sensors_lookup_subfeature_name(chip_features,
expr->data.var))) expr->data.var)))
return SENSORS_ERR_NO_ENTRY; return SENSORS_ERR_NO_ENTRY;
if (!(res = sensors_get_value(name, subfeature->number, if (!(res = sensors_get_value(&chip_features->chip,
result))) subfeature->number, result)))
return res; return res;
return 0; return 0;
} }
if ((res = sensors_eval_expr(name, expr->data.subexpr.sub1, val, &res1))) if ((res = sensors_eval_expr(chip_features, expr->data.subexpr.sub1,
val, &res1)))
return res; return res;
if (expr->data.subexpr.sub2 && if (expr->data.subexpr.sub2 &&
(res = sensors_eval_expr(name, expr->data.subexpr.sub2, val, &res2))) (res = sensors_eval_expr(chip_features, expr->data.subexpr.sub2,
val, &res2)))
return res; return res;
switch (expr->data.subexpr.op) { switch (expr->data.subexpr.op) {
case sensors_add: case sensors_add:
@@ -467,15 +465,18 @@ int sensors_eval_expr(const sensors_chip_name *name,
failure. */ failure. */
static int sensors_do_this_chip_sets(const sensors_chip_name *name) static int sensors_do_this_chip_sets(const sensors_chip_name *name)
{ {
const sensors_chip_features *chip_features;
sensors_chip *chip; sensors_chip *chip;
double value; double value;
int i; int i;
int err = 0, res; int err = 0, res;
const sensors_subfeature *subfeature; const sensors_subfeature *subfeature;
chip_features = sensors_lookup_chip(name); /* Can't fail */
for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));) for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));)
for (i = 0; i < chip->sets_count; i++) { for (i = 0; i < chip->sets_count; i++) {
subfeature = sensors_lookup_subfeature_name(name, subfeature = sensors_lookup_subfeature_name(chip_features,
chip->sets[i].name); chip->sets[i].name);
if (!subfeature) { if (!subfeature) {
sensors_parse_error("Unknown feature name", sensors_parse_error("Unknown feature name",
@@ -484,8 +485,9 @@ static int sensors_do_this_chip_sets(const sensors_chip_name *name)
continue; continue;
} }
res = sensors_eval_expr(name, chip->sets[i].value, 0, res = sensors_eval_expr(chip_features,
&value); chip->sets[i].value, 0,
&value);
if (res) { if (res) {
sensors_parse_error("Error parsing expression", sensors_parse_error("Error parsing expression",
chip->sets[i].lineno); chip->sets[i].lineno);