Module Name:    src
Committed By:   pgoyette
Date:           Thu Dec 30 04:00:00 UTC 2010

Modified Files:
        src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c
            sysmon_envsysvar.h

Log Message:
When the user updates the sensor device's refresh timer, reset the
callout immediately rather than waiting for the previous timer to
expire.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.96 -r1.97 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/sysmon/sysmon_envsysvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sysmon/sysmon_envsys.c
diff -u src/sys/dev/sysmon/sysmon_envsys.c:1.111 src/sys/dev/sysmon/sysmon_envsys.c:1.112
--- src/sys/dev/sysmon/sysmon_envsys.c:1.111	Thu Dec 16 16:08:57 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Thu Dec 30 03:59:59 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.111 2010/12/16 16:08:57 njoly Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.112 2010/12/30 03:59:59 pgoyette 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.111 2010/12/16 16:08:57 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.112 2010/12/30 03:59:59 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -1175,6 +1175,7 @@
 		 * Restore default timeout value.
 		 */
 		sme->sme_events_timeout = SME_EVENTS_DEFTIMEOUT;
+		sme_schedule_callout(sme);
 		sysmon_envsys_release(sme, false);
 	}
 	mutex_exit(&sme_global_mtx);
@@ -1214,8 +1215,10 @@
 	 * 	...
 	 *
 	 */
-	if (!sme->sme_events_timeout)
+	if (sme->sme_events_timeout == 0) {
 		sme->sme_events_timeout = SME_EVENTS_DEFTIMEOUT;
+		sme_schedule_callout(sme);
+	}
 
 	if (!prop_dictionary_set_uint64(pdict, "refresh-timeout",
 					sme->sme_events_timeout)) {
@@ -1805,7 +1808,10 @@
 				error = EINVAL;
 			else {
 				mutex_enter(&sme->sme_mtx);
-				sme->sme_events_timeout = refresh_timo;
+				if (sme->sme_events_timeout != refresh_timo) {
+					sme->sme_events_timeout = refresh_timo;
+					sme_schedule_callout(sme);
+				}
 				mutex_exit(&sme->sme_mtx);
 		}
 		}

Index: src/sys/dev/sysmon/sysmon_envsys_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.96 src/sys/dev/sysmon/sysmon_envsys_events.c:1.97
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.96	Wed Dec 15 17:17:17 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Thu Dec 30 03:59:59 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.96 2010/12/15 17:17:17 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.97 2010/12/30 03:59:59 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.96 2010/12/15 17:17:17 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.97 2010/12/30 03:59:59 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -486,16 +486,10 @@
 sme_events_init(struct sysmon_envsys *sme)
 {
 	int error = 0;
-	uint64_t timo;
 
 	KASSERT(sme != NULL);
 	KASSERT(mutex_owned(&sme->sme_mtx));
 
-	if (sme->sme_events_timeout)
-		timo = sme->sme_events_timeout * hz;
-	else
-		timo = SME_EVTIMO;
-
 	error = workqueue_create(&sme->sme_wq, sme->sme_name,
 	    sme_events_worker, sme, PRI_NONE, IPL_SOFTCLOCK, WQ_MPSAFE);
 	if (error)
@@ -504,8 +498,8 @@
 	mutex_init(&sme->sme_callout_mtx, MUTEX_DEFAULT, IPL_SOFTCLOCK);
 	callout_init(&sme->sme_callout, CALLOUT_MPSAFE);
 	callout_setfunc(&sme->sme_callout, sme_events_check, sme);
-	callout_schedule(&sme->sme_callout, timo);
 	sme->sme_flags |= SME_CALLOUT_INITIALIZED;
+	sme_schedule_callout(sme);
 	DPRINTF(("%s: events framework initialized for '%s'\n",
 	    __func__, sme->sme_name));
 
@@ -513,6 +507,30 @@
 }
 
 /*
+ * sme_schedule_callout
+ *
+ *	(Re)-schedule the device's callout timer
+ */
+void
+sme_schedule_callout(struct sysmon_envsys *sme)
+{
+	uint64_t timo;
+
+	KASSERT(sme != NULL);
+
+	if ((sme->sme_flags & SME_CALLOUT_INITIALIZED) == 0)
+		return;
+
+	if (sme->sme_events_timeout)
+		timo = sme->sme_events_timeout * hz;
+	else
+		timo = SME_EVTIMO;
+
+	callout_stop(&sme->sme_callout);
+	callout_schedule(&sme->sme_callout, timo);
+}
+
+/*
  * sme_events_destroy:
  *
  * 	+ Destroys the event framework for this device: callout
@@ -630,7 +648,7 @@
 	else
 		timo = SME_EVTIMO;
 	if (!sysmon_low_power)
-		callout_schedule(&sme->sme_callout, timo);
+		sme_schedule_callout(sme);
 	mutex_exit(&sme->sme_callout_mtx);
 }
 

Index: src/sys/dev/sysmon/sysmon_envsysvar.h
diff -u src/sys/dev/sysmon/sysmon_envsysvar.h:1.37 src/sys/dev/sysmon/sysmon_envsysvar.h:1.38
--- src/sys/dev/sysmon/sysmon_envsysvar.h:1.37	Wed Dec 15 17:17:17 2010
+++ src/sys/dev/sysmon/sysmon_envsysvar.h	Thu Dec 30 03:59:59 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.37 2010/12/15 17:17:17 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsysvar.h,v 1.38 2010/12/30 03:59:59 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -133,6 +133,7 @@
 void	sme_events_worker(struct work *, void *);
 void	sme_deliver_event(sme_event_t *);
 int	sme_update_limits(struct sysmon_envsys *, envsys_data_t *);
+void	sme_schedule_callout(struct sysmon_envsys *);
 
 /* 
  * common functions to create/update objects in a dictionary.

Reply via email to