Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/sysmon 1. Enable use of FMONSTCHANGED events for IND...



details:   https://anonhg.NetBSD.org/src/rev/71b84055f702
branches:  trunk
changeset: 781222:71b84055f702
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Mon Aug 27 21:42:04 2012 +0000

description:
1. Enable use of FMONSTCHANGED events for INDICATOR sensors
2. Update handling of FMONCRITICAL event reporting.   The state
   transition does not require a corresponding change in value.

With these changes, you can now have an INDICATOR sensor that
reports the presence or absence of a device, and (if the device
is present) separately monitor it for proper functioning.

Should address the concerns expressed recently with the commit
of changes to wmi(4) BBU handling.

diffstat:

 sys/dev/sysmon/sysmon_envsys_events.c |  50 ++++++++++++++++++++++------------
 sys/dev/sysmon/sysmon_envsys_tables.c |  16 +++++++++-
 sys/dev/sysmon/sysmon_envsysvar.h     |   8 +++--
 3 files changed, 51 insertions(+), 23 deletions(-)

diffs (205 lines):

diff -r 8fc8e4cdb535 -r 71b84055f702 sys/dev/sysmon/sysmon_envsys_events.c
--- a/sys/dev/sysmon/sysmon_envsys_events.c     Mon Aug 27 21:07:33 2012 +0000
+++ b/sys/dev/sysmon/sysmon_envsys_events.c     Mon Aug 27 21:42:04 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.103 2012/07/19 13:30:01 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.104 2012/08/27 21:42:04 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.103 2012/07/19 13:30:01 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.104 2012/08/27 21:42:04 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -215,26 +215,28 @@
                see->see_pes.pes_type = powertype;
 
                switch (crittype) {
-               case PENVSYS_EVENT_LIMITS:
-                       see->see_evsent = ENVSYS_SVALID;
-                       break;
                case PENVSYS_EVENT_CAPACITY:
-                       see->see_evsent = ENVSYS_BATTERY_CAPACITY_NORMAL;
+                       see->see_evstate = ENVSYS_BATTERY_CAPACITY_NORMAL;
                        break;
                case PENVSYS_EVENT_STATE_CHANGED:
                        if (edata->units == ENVSYS_BATTERY_CAPACITY)
-                               see->see_evsent = ENVSYS_BATTERY_CAPACITY_NORMAL;
+                               see->see_evstate = 
+                                   ENVSYS_BATTERY_CAPACITY_NORMAL;
                        else if (edata->units == ENVSYS_DRIVE)
-                               see->see_evsent = ENVSYS_DRIVE_EMPTY;
+                               see->see_evstate = ENVSYS_DRIVE_EMPTY;
+                       else if (edata->units == ENVSYS_INDICATOR)
+                               see->see_evstate = ENVSYS_SVALID;
                        else
                                panic("%s: bad units for "
                                      "PENVSYS_EVENT_STATE_CHANGED", __func__);
                        break;
                case PENVSYS_EVENT_CRITICAL:
+               case PENVSYS_EVENT_LIMITS:
                default:
-                       see->see_evsent = 0;
+                       see->see_evstate = ENVSYS_SVALID;
                        break;
                }
+               see->see_evvalue = 0;
 
                (void)strlcpy(see->see_pes.pes_dvname, sme->sme_name,
                    sizeof(see->see_pes.pes_dvname));
@@ -846,7 +848,7 @@
                /*
                 * Send event if state has changed
                 */
-               if (edata->state == see->see_evsent)
+               if (edata->state == see->see_evstate)
                        break;
 
                for (i = 0; sse[i].state != -1; i++)
@@ -862,7 +864,7 @@
                else
                        sysmon_penvsys_event(&see->see_pes, sse[i].event);
 
-               see->see_evsent = edata->state;
+               see->see_evstate = edata->state;
                DPRINTFOBJ(("%s: (%s) desc=%s sensor=%d state=%d send_ev=%d\n",
                    __func__, see->see_sme->sme_name, edata->desc,
                    edata->sensor, edata->state,
@@ -878,17 +880,24 @@
         *      State has returned from CRITICAL to non-CRITICAL
         */
        case PENVSYS_EVENT_CRITICAL:
+               DPRINTF(("%s: CRITICAL: old/new state %d/%d, old/new value "
+                   "%d/%d\n", __func__, see->see_evstate, edata->state,
+                   see->see_evvalue, edata->value_cur));
                if (edata->state == ENVSYS_SVALID &&
-                   see->see_evsent != 0) {
+                   see->see_evstate != ENVSYS_SVALID) {
                        sysmon_penvsys_event(&see->see_pes,
                                             PENVSYS_EVENT_NORMAL);
-                       see->see_evsent = 0;
-               } else if (edata->state == ENVSYS_SCRITICAL &&
-                   see->see_evsent != edata->value_cur) {
+                       see->see_evstate = ENVSYS_SVALID;
+                       break;
+               } else if (edata->state != ENVSYS_SCRITICAL)
+                       break;
+               if (see->see_evstate != ENVSYS_SCRITICAL ||
+                   see->see_evvalue != edata->value_cur) {
                        sysmon_penvsys_event(&see->see_pes,
                                             PENVSYS_EVENT_CRITICAL);
-                       see->see_evsent = edata->value_cur;
+                       see->see_evstate = ENVSYS_SCRITICAL;
                }
+               see->see_evvalue = edata->value_cur;
                break;
 
        /*
@@ -899,7 +908,7 @@
                /* 
                 * the state has not been changed, just ignore the event.
                 */
-               if (edata->value_cur == see->see_evsent)
+               if (edata->value_cur == see->see_evvalue)
                        break;
 
                switch (edata->units) {
@@ -913,6 +922,11 @@
                            edata->value_cur);
                        state = ENVSYS_BATTERY_CAPACITY_NORMAL;
                        break;
+               case ENVSYS_INDICATOR:
+                       sdt = sme_find_table_entry(SME_DESC_INDICATOR,
+                           edata->value_cur);
+                       state = see->see_evvalue;       /* force state change */
+                       break;
                default:
                        panic("%s: bad units for PENVSYS_EVENT_STATE_CHANGED",
                            __func__);
@@ -939,7 +953,7 @@
                         */
                        sysmon_penvsys_event(&see->see_pes, see->see_type);
 
-               see->see_evsent = edata->value_cur;
+               see->see_evvalue = edata->value_cur;
 
                /* 
                 * There's no need to continue if it's a drive sensor.
diff -r 8fc8e4cdb535 -r 71b84055f702 sys/dev/sysmon/sysmon_envsys_tables.c
--- a/sys/dev/sysmon/sysmon_envsys_tables.c     Mon Aug 27 21:07:33 2012 +0000
+++ b/sys/dev/sysmon/sysmon_envsys_tables.c     Mon Aug 27 21:42:04 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_tables.c,v 1.10 2011/06/19 05:26:31 nonaka Exp $ */
+/* $NetBSD: sysmon_envsys_tables.c,v 1.11 2012/08/27 21:42:04 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007 Juan Romero Pardines.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.10 2011/06/19 05:26:31 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.11 2012/08/27 21:42:04 pgoyette Exp $");
 
 #include <sys/types.h>
 
@@ -100,6 +100,15 @@
        { -1,                                   -1,     "UNKNOWN" }
 };
 
+/*
+ * Available indicator descriptions.
+ */
+static const struct sme_descr_entry sme_indicator_description[] = {
+       { ENVSYS_INDICATOR_FALSE,               -1,     "FALSE" },
+       { ENVSYS_INDICATOR_TRUE,                -1,     "TRUE" },
+       { -1,                                   -1,     "UNKNOWN" }
+};
+
 static const struct sme_descr_entry *
 sme_find_table(enum sme_descr_type table_id)
 {
@@ -116,6 +125,9 @@
        case SME_DESC_BATTERY_CAPACITY:
                return sme_batterycap_description;
                break;
+       case SME_DESC_INDICATOR:
+               return sme_indicator_description;
+               break;
        default:
                return NULL;
        }
diff -r 8fc8e4cdb535 -r 71b84055f702 sys/dev/sysmon/sysmon_envsysvar.h
--- a/sys/dev/sysmon/sysmon_envsysvar.h Mon Aug 27 21:07:33 2012 +0000
+++ b/sys/dev/sysmon/sysmon_envsysvar.h Mon Aug 27 21:42:04 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.42 2012/07/15 17:41:39 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsysvar.h,v 1.43 2012/08/27 21:42:04 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -44,7 +44,8 @@
        SME_DESC_UNITS = 1,
        SME_DESC_STATES,
        SME_DESC_DRIVE_STATES,
-       SME_DESC_BATTERY_CAPACITY
+       SME_DESC_BATTERY_CAPACITY,
+       SME_DESC_INDICATOR
 };
 
 #ifdef ENVSYS_DEBUG
@@ -75,7 +76,8 @@
        envsys_data_t           *see_edata;     /* our sensor data */
        sysmon_envsys_lim_t     see_lims;       /* limit values */
        int                     see_type;       /* type of the event */
-       int                     see_evsent;     /* event already sent */
+       int                     see_evstate;    /* state of prev event */
+       int                     see_evvalue;    /* value of prev event */
        int                     see_flags;      /* see above */
 #define SEE_EVENT_WORKING      0x0001          /* This event is busy */
 } sme_event_t;



Home | Main Index | Thread Index | Old Index