Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc64/dev Limit reading from registers at most on...



details:   https://anonhg.NetBSD.org/src/rev/c844b69a11e3
branches:  trunk
changeset: 766263:c844b69a11e3
user:      nakayama <nakayama%NetBSD.org@localhost>
date:      Sun Jun 19 21:37:10 2011 +0000

description:
Limit reading from registers at most once every second with using
ratecheck(9).

diffstat:

 sys/arch/sparc64/dev/lom.c |  62 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 44 insertions(+), 18 deletions(-)

diffs (120 lines):

diff -r 6acfffb185d6 -r c844b69a11e3 sys/arch/sparc64/dev/lom.c
--- a/sys/arch/sparc64/dev/lom.c        Sun Jun 19 18:29:25 2011 +0000
+++ b/sys/arch/sparc64/dev/lom.c        Sun Jun 19 21:37:10 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lom.c,v 1.7 2011/02/28 14:29:29 nakayama Exp $ */
+/*     $NetBSD: lom.c,v 1.8 2011/06/19 21:37:10 nakayama Exp $ */
 /*     $OpenBSD: lom.c,v 1.21 2010/02/28 20:44:39 kettenis Exp $       */
 /*
  * Copyright (c) 2009 Mark Kettenis
@@ -17,7 +17,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lom.c,v 1.7 2011/02/28 14:29:29 nakayama Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lom.c,v 1.8 2011/06/19 21:37:10 nakayama Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -171,6 +171,12 @@
 
        int32_t                 sc_sysctl_num[LOM_MAX_ALARM];
 
+       struct timeval          sc_alarm_lastread;
+       uint8_t                 sc_alarm_lastval;
+       struct timeval          sc_fan_lastread[LOM_MAX_FAN];
+       struct timeval          sc_psu_lastread[LOM_MAX_PSU];
+       struct timeval          sc_temp_lastread[LOM_MAX_TEMP];
+
        uint8_t                 sc_fan_cal[LOM_MAX_FAN];
        uint8_t                 sc_fan_low[LOM_MAX_FAN];
 
@@ -239,6 +245,7 @@
 static const char *nodedesc[LOM_MAX_ALARM] =
     { "Fault LED status", "Alarm1 status", "Alarm2 status ", "Alarm3 status" };
 #endif
+static const struct timeval refresh_interval = { 1, 0 };
 
 static int
 lom_match(device_t parent, cfdata_t match, void *aux)
@@ -1002,24 +1009,31 @@
        /* Fault LED or Alarms */
        KASSERT(i < sc->sc_num_alarm);
 
-       if (lom_read(sc, LOM_IDX_ALARM, &val)) {
-               edata->state = ENVSYS_SINVALID;
+       /* Read new value at most once every second. */
+       if (ratecheck(&sc->sc_alarm_lastread, &refresh_interval)) {
+               if (lom_read(sc, LOM_IDX_ALARM, &val)) {
+                       edata->state = ENVSYS_SINVALID;
+                       return;
+               }
+               sc->sc_alarm_lastval = val;
        } else {
-               if (i == 0) {
-                       /* Fault LED */
-                       if ((val & LOM_ALARM_FAULT) == LOM_ALARM_FAULT)
-                               edata->value_cur = 0;
-                       else
-                               edata->value_cur = 1;
-               } else {
-                       /* Alarms */
-                       if ((val & (LOM_ALARM_1 << (i - 1))) == 0)
-                               edata->value_cur = 0;
-                       else
-                               edata->value_cur = 1;
-               }
-               edata->state = ENVSYS_SVALID;
+               val = sc->sc_alarm_lastval;
        }
+
+       if (i == 0) {
+               /* Fault LED */
+               if ((val & LOM_ALARM_FAULT) == LOM_ALARM_FAULT)
+                       edata->value_cur = 0;
+               else
+                       edata->value_cur = 1;
+       } else {
+               /* Alarms */
+               if ((val & (LOM_ALARM_1 << (i - 1))) == 0)
+                       edata->value_cur = 0;
+               else
+                       edata->value_cur = 1;
+       }
+       edata->state = ENVSYS_SVALID;
 }
 
 static void
@@ -1030,6 +1044,10 @@
        /* Fan speed */
        KASSERT(i < sc->sc_num_fan);
 
+       /* Read new value at most once every second. */
+       if (!ratecheck(&sc->sc_fan_lastread[i], &refresh_interval))
+               return;
+
        if (lom_read(sc, LOM_IDX_FAN1 + i, &val)) {
                edata->state = ENVSYS_SINVALID;
        } else {
@@ -1049,6 +1067,10 @@
        /* PSU status */
        KASSERT(i < sc->sc_num_psu);
 
+       /* Read new value at most once every second. */
+       if (!ratecheck(&sc->sc_psu_lastread[i], &refresh_interval))
+               return;
+
        if (lom_read(sc, LOM_IDX_PSU1 + i, &val) ||
            !ISSET(val, LOM_PSU_PRESENT)) {
                edata->state = ENVSYS_SINVALID;
@@ -1076,6 +1098,10 @@
        /* Temperature */
        KASSERT(i < sc->sc_num_temp);
 
+       /* Read new value at most once every second. */
+       if (!ratecheck(&sc->sc_temp_lastread[i], &refresh_interval))
+               return;
+
        if (lom_read(sc, LOM_IDX_TEMP1 + i, &val)) {
                edata->state = ENVSYS_SINVALID;
        } else {



Home | Main Index | Thread Index | Old Index