Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/sysmon Add a convenience function to find the maximu...



details:   https://anonhg.NetBSD.org/src/rev/1a678e4b324d
branches:  trunk
changeset: 751329:1a678e4b324d
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Jan 31 21:36:38 2010 +0000

description:
Add a convenience function to find the maximum value currently reported
by a set (selected via a passed callback predicate) of sensors.
This provides an easy way to query the current temperature of a thermal
zone, for example, from within the kernel - assuming the caller knows
the topology.

diffstat:

 sys/dev/sysmon/sysmon_envsys.c |  71 ++++++++++++++++++++++++++++++++++++++++-
 sys/dev/sysmon/sysmonvar.h     |   4 +-
 2 files changed, 72 insertions(+), 3 deletions(-)

diffs (117 lines):

diff -r 0fa06e54c5a9 -r 1a678e4b324d sys/dev/sysmon/sysmon_envsys.c
--- a/sys/dev/sysmon/sysmon_envsys.c    Sun Jan 31 21:25:51 2010 +0000
+++ b/sys/dev/sysmon/sysmon_envsys.c    Sun Jan 31 21:36:38 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysmon_envsys.c,v 1.91 2010/01/30 02:46:52 pgoyette Exp $      */
+/*     $NetBSD: sysmon_envsys.c,v 1.92 2010/01/31 21:36:38 martin Exp $        */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.91 2010/01/30 02:46:52 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.92 2010/01/31 21:36:38 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -93,6 +93,8 @@
 static int sme_add_property_dictionary(struct sysmon_envsys *, prop_array_t,
                                       prop_dictionary_t);
 static void sme_initial_refresh(void *);
+static uint32_t sme_get_max_value(struct sysmon_envsys *,
+     bool (*)(const envsys_data_t*), bool);
 
 /*
  * sysmon_envsys_init:
@@ -1412,6 +1414,71 @@
 }
 
 /*
+ * Find the maximum of all currently reported values.
+ * The provided callback decides wether a sensor is part of the
+ * maximum calculation (by returning true) or ignored (callback
+ * returns false). Example usage: callback selects temperature
+ * sensors in a given thermal zone, the function calculates the
+ * maximum currently reported temperature in this zone.
+ * If the parameter "refresh" is true, new values will be aquired
+ * from the hardware, if not, the last reported value will be used.
+ */
+uint32_t
+sysmon_envsys_get_max_value(bool (*predicate)(const envsys_data_t*),
+       bool refresh)
+{
+       struct sysmon_envsys *sme;
+       uint32_t maxv, v;
+
+       maxv = 0;
+       mutex_enter(&sme_global_mtx);
+       LIST_FOREACH(sme, &sysmon_envsys_list, sme_list) {
+               sysmon_envsys_acquire(sme, false);
+               v = sme_get_max_value(sme, predicate, refresh);
+               sysmon_envsys_release(sme, false);
+               if (v > maxv)
+                       maxv = v;
+       }
+       mutex_exit(&sme_global_mtx);
+       return maxv;
+}
+
+static uint32_t
+sme_get_max_value(struct sysmon_envsys *sme,
+    bool (*predicate)(const envsys_data_t*),
+    bool refresh)
+{
+       envsys_data_t *edata;
+       uint32_t maxv, v;
+
+       /* 
+        * iterate over all sensors and find temperature ones.
+        */
+       maxv = 0;
+       TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) {
+               if (!(*predicate)(edata))
+                       continue;
+
+               /* 
+                * refresh sensor data via sme_refresh only if the
+                * flag is not set.
+                */
+               if (refresh && (sme->sme_flags & SME_DISABLE_REFRESH) == 0) {
+                       mutex_enter(&sme->sme_mtx);
+                       (*sme->sme_refresh)(sme, edata);
+                       mutex_exit(&sme->sme_mtx);
+               }
+
+               v = edata->value_cur;
+               if (v > maxv)
+                       maxv = v;
+
+       }
+
+       return maxv;
+}
+
+/*
  * sme_update_dictionary:
  *
  *     + Update per-sensor dictionaries with new values if there were
diff -r 0fa06e54c5a9 -r 1a678e4b324d sys/dev/sysmon/sysmonvar.h
--- a/sys/dev/sysmon/sysmonvar.h        Sun Jan 31 21:25:51 2010 +0000
+++ b/sys/dev/sysmon/sysmonvar.h        Sun Jan 31 21:36:38 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysmonvar.h,v 1.29 2009/06/14 19:43:12 pgoyette Exp $  */
+/*     $NetBSD: sysmonvar.h,v 1.30 2010/01/31 21:36:38 martin Exp $    */
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -134,6 +134,8 @@
 int    sysmon_envsys_sensor_attach(struct sysmon_envsys *, envsys_data_t *);
 int    sysmon_envsys_sensor_detach(struct sysmon_envsys *, envsys_data_t *);
 
+uint32_t       sysmon_envsys_get_max_value(bool (*)(const envsys_data_t*), bool);
+
 void   sysmon_envsys_init(void);
 
 /*****************************************************************************



Home | Main Index | Thread Index | Old Index