Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/sysmon Replace a couple of many-line #define with eq...
details: https://anonhg.NetBSD.org/src/rev/af648e4055b6
branches: trunk
changeset: 783214:af648e4055b6
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Tue Dec 11 15:39:06 2012 +0000
description:
Replace a couple of many-line #define with equivalent code loops.
No functional change intended, and atf tests (using swsensor(4)) still
pass 100%
diffstat:
sys/dev/sysmon/sysmon_envsys_events.c | 152 +++++++++++++++++----------------
sys/dev/sysmon/sysmonvar.h | 31 +++++-
2 files changed, 102 insertions(+), 81 deletions(-)
diffs (254 lines):
diff -r 15b72a132965 -r af648e4055b6 sys/dev/sysmon/sysmon_envsys_events.c
--- a/sys/dev/sysmon/sysmon_envsys_events.c Tue Dec 11 12:59:03 2012 +0000
+++ b/sys/dev/sysmon/sysmon_envsys_events.c Tue Dec 11 15:39:06 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.106 2012/10/31 05:42:47 macallan Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.107 2012/12/11 15:39:06 pgoyette Exp $ */
/*-
* Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.106 2012/10/31 05:42:47 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.107 2012/12/11 15:39:06 pgoyette Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -65,6 +65,37 @@
{ -1, -1 }
};
+struct op_t {
+ const char *name;
+ enum envsys_lims idx;
+ uint32_t prop;
+} limit_ops[] = {
+ /* Value-based limits */
+ { "critical-max", ENVSYS_LIM_CRITMAX, PROP_CRITMAX },
+ { "warning-max", ENVSYS_LIM_WARNMAX, PROP_WARNMAX },
+ { "warning-min", ENVSYS_LIM_WARNMIN, PROP_WARNMIN },
+ { "critical-min", ENVSYS_LIM_CRITMIN, PROP_CRITMIN },
+
+ /* %Capacity-based limits */
+ { "maximum-capacity", ENVSYS_LIM_CRITMAX, PROP_BATTMAX },
+ { "high-capacity", ENVSYS_LIM_WARNMAX, PROP_BATTHIGH },
+ { "warning-capacity", ENVSYS_LIM_WARNMIN, PROP_BATTWARN },
+ { "critical-capacity", ENVSYS_LIM_CRITMIN, PROP_BATTCAP },
+ { NULL, 0, 0 }
+};
+
+struct ev_reg_t {
+ uint32_t crittype;
+ uint32_t powertype;
+ const char *name;
+} reg_events[] = {
+ { ENVSYS_FMONCRITICAL, PENVSYS_EVENT_CRITICAL, "critical" },
+ { ENVSYS_FMONSTCHANGED, PENVSYS_EVENT_STATE_CHANGED, "state-changed" },
+ { ENVSYS_FMONLIMITS, PENVSYS_EVENT_LIMITS, "hw-range-limits" },
+ { ENVSYS_FHAS_ENTROPY, PENVSYS_EVENT_NULL, "refresh-event" },
+ { 0, 0, NULL }
+};
+
static bool sysmon_low_power;
#define SME_EVTIMO (SME_EVENTS_DEFTIMEOUT * hz)
@@ -91,6 +122,7 @@
prop_object_t obj;
int error = 0;
const char *objkey;
+ struct op_t *op;
KASSERT(sdict != NULL);
KASSERT(edata != NULL);
@@ -244,41 +276,30 @@
/*
* Limit operation requested.
*/
-#define LIMIT_OP(k, l, p) \
- if (props & p) { \
- objkey = k; \
- obj = prop_dictionary_get(sdict, objkey); \
- if (obj != NULL && \
- prop_object_type(obj) != PROP_TYPE_NUMBER) { \
- DPRINTF(("%s: (%s) %s object no TYPE_NUMBER\n", \
- __func__, sme->sme_name, objkey)); \
- error = ENOTSUP; \
- } else { \
- edata->limits.l = lims->l; \
- error = sme_sensor_upint32(sdict, objkey,lims->l); \
- DPRINTF(("%s: (%s) event [sensor=%s type=%d] " \
- "(%s updated)\n", __func__, sme->sme_name, \
- edata->desc, crittype, objkey)); \
- } \
- if (error && error != EEXIST) \
- goto out; \
- edata->upropset |= p; \
+ for (op = limit_ops; op->name != NULL; op++) {
+ if (props & op->prop) {
+ objkey = op->name;
+ obj = prop_dictionary_get(sdict, objkey);
+ if (obj != NULL &&
+ prop_object_type(obj) != PROP_TYPE_NUMBER) {
+ DPRINTF(("%s: (%s) %s object not TYPE_NUMBER\n",
+ __func__, sme->sme_name, objkey));
+ error = ENOTSUP;
+ } else {
+ edata->limits.sel_limit_list[op->idx] =
+ lims->sel_limit_list[op->idx];
+ error = sme_sensor_upint32(sdict, objkey,
+ lims->sel_limit_list[op->idx]);
+ DPRINTF(("%s: (%s) event [sensor=%s type=%d] "
+ "(%s updated)\n", __func__, sme->sme_name,
+ edata->desc, crittype, objkey));
+ }
+ if (error && error != EEXIST)
+ goto out;
+ edata->upropset |= op->prop;
+ }
}
- /* Value-based limits */
- LIMIT_OP("critical-max", sel_critmax, PROP_CRITMAX);
- LIMIT_OP("warning-max", sel_warnmax, PROP_WARNMAX);
- LIMIT_OP("warning-min", sel_warnmin, PROP_WARNMIN);
- LIMIT_OP("critical-min", sel_critmin, PROP_CRITMIN);
-
- /* %Capacity-based limits */
- LIMIT_OP("maximum-capacity", sel_critmax, PROP_BATTMAX);
- LIMIT_OP("high-capacity", sel_warnmax, PROP_BATTHIGH);
- LIMIT_OP("warning-capacity", sel_warnmin, PROP_BATTWARN);
- LIMIT_OP("critical-capacity", sel_critmin, PROP_BATTCAP);
-
-#undef LIMIT_OP
-
if (props & PROP_DRIVER_LIMITS)
edata->upropset |= PROP_DRIVER_LIMITS;
else
@@ -474,34 +495,10 @@
sysmon_envsys_lim_t lims;
uint32_t props;
int error = 0;
+ struct ev_reg_t *reg;
KASSERT(sed_t != NULL);
-#define SEE_REGEVENT(a, b, c) \
-do { \
- if (sed_t->sed_edata->flags & (a)) { \
- char str[ENVSYS_DESCLEN] = "monitoring-state-"; \
- \
- error = sme_event_register(sed_t->sed_sdict, \
- sed_t->sed_edata, \
- sed_t->sed_sme, \
- &lims, props, \
- (b), \
- sed_t->sed_powertype); \
- if (error && error != EEXIST) \
- printf("%s: failed to add event! " \
- "error=%d sensor=%s event=%s\n", \
- __func__, error, \
- sed_t->sed_edata->desc, (c)); \
- else { \
- (void)strlcat(str, (c), sizeof(str)); \
- prop_dictionary_set_bool(sed_t->sed_sdict, \
- str, \
- true); \
- } \
- } \
-} while (/* CONSTCOND */ 0)
-
/*
* If driver provides a method to retrieve its internal limit
* values, call it and use those returned values as initial
@@ -522,21 +519,28 @@
/* Register the events that were specified */
- SEE_REGEVENT(ENVSYS_FMONCRITICAL,
- PENVSYS_EVENT_CRITICAL,
- "critical");
-
- SEE_REGEVENT(ENVSYS_FMONSTCHANGED,
- PENVSYS_EVENT_STATE_CHANGED,
- "state-changed");
+ for (reg = reg_events; reg->name != NULL; reg++) {
+ if (sed_t->sed_edata->flags & reg->crittype) {
- SEE_REGEVENT(ENVSYS_FMONLIMITS,
- PENVSYS_EVENT_LIMITS,
- "hw-range-limits");
-
- SEE_REGEVENT(ENVSYS_FHAS_ENTROPY,
- PENVSYS_EVENT_NULL,
- "refresh-event");
+ error = sme_event_register(sed_t->sed_sdict,
+ sed_t->sed_edata,
+ sed_t->sed_sme,
+ &lims, props,
+ reg->powertype,
+ sed_t->sed_powertype);
+ if (error && error != EEXIST)
+ printf("%s: failed to add event! "
+ "error=%d sensor=%s event=%s\n",
+ __func__, error,
+ sed_t->sed_edata->desc, reg->name);
+ else {
+ char str[ENVSYS_DESCLEN] = "monitoring-state-";
+ (void)strlcat(str, reg->name, sizeof(str));
+ prop_dictionary_set_bool(sed_t->sed_sdict,
+ str, true);
+ }
+ }
+ }
/*
* we are done, free memory now.
diff -r 15b72a132965 -r af648e4055b6 sys/dev/sysmon/sysmonvar.h
--- a/sys/dev/sysmon/sysmonvar.h Tue Dec 11 12:59:03 2012 +0000
+++ b/sys/dev/sysmon/sysmonvar.h Tue Dec 11 15:39:06 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmonvar.h,v 1.43 2012/07/16 13:55:01 pgoyette Exp $ */
+/* $NetBSD: sysmonvar.h,v 1.44 2012/12/11 15:39:06 pgoyette Exp $ */
/*-
* Copyright (c) 2000 Zembu Labs, Inc.
@@ -63,14 +63,31 @@
/*
* Thresholds/limits that are being monitored
*/
-struct sysmon_envsys_lim {
- int32_t sel_critmax;
- int32_t sel_warnmax;
- int32_t sel_warnmin;
- int32_t sel_critmin;
+
+enum envsys_lims {
+ ENVSYS_LIM_CRITMAX,
+ ENVSYS_LIM_WARNMAX,
+ ENVSYS_LIM_WARNMIN,
+ ENVSYS_LIM_CRITMIN,
+ ENVSYS_LIM_LASTLIM
};
-typedef struct sysmon_envsys_lim sysmon_envsys_lim_t;
+struct sysmon_envsys_lim {
+ int32_t critmax;
+ int32_t warnmax;
+ int32_t warnmin;
+ int32_t critmin;
+};
+
+typedef union {
+ int32_t sel_limit_list[ENVSYS_LIM_LASTLIM];
+ struct sysmon_envsys_lim sel_limits;
+} sysmon_envsys_lim_t;
+
+#define sel_critmax sel_limits.critmax
+#define sel_warnmax sel_limits.warnmax
+#define sel_warnmin sel_limits.warnmin
+#define sel_critmin sel_limits.critmin
/* struct used by a sensor */
struct envsys_data {
Home |
Main Index |
Thread Index |
Old Index