PATCH: cpu freq notifiers and eventhandler register from SYSINIT

Nate Lawson nate at root.org
Sun Mar 18 05:35:29 UTC 2007


Nate Lawson wrote:
> Attached is an updated patch for handling cpu freq changes.  It updates
> tsc_freq and all direct consumers of it.
> 
> I also would like to add something to eventhandler.h.  As I was doing
> this, I really wanted a way to declare an eventhandler tag and call
> eventhandler_register() from a SYSINIT.  I ended up doing that manually
> in a lot of cases where I couldn't register up front because it was too
> early in boot (i.e. identcpu).  Comments on adding this macro, similar
> to TASQUEUE_DEFINE in taskqueue.h?  Maybe EVENTHANDLER_REGISTER_INIT()?

Attached is the patch and an example of how EVENTHANDLER_DECLARE() would
be used.  It creates a handle and uses a SYSINIT to register the
callback function.

-- 
Nate
-------------- next part --------------
Index: sys/sys/eventhandler.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/eventhandler.h,v
retrieving revision 1.35
diff -u -r1.35 eventhandler.h
--- sys/sys/eventhandler.h	15 Aug 2006 12:10:57 -0000	1.35
+++ sys/sys/eventhandler.h	18 Mar 2007 04:29:51 -0000
@@ -104,6 +104,17 @@
 };									\
 struct __hack
 
+#define EVENTHANDLER_DEFINE(name, func, arg, priority)			\
+	static eventhandler_tag name ## _tag;				\
+	static void name ## _evh_init(void *ctx)			\
+	{								\
+		name ## _tag = EVENTHANDLER_REGISTER(name, func, ctx,	\
+		    priority);						\
+	}								\
+	SYSINIT(name ## _evh_init, SI_SUB_CONFIGURE, SI_ORDER_ANY,	\
+	    name ## _evh_init, arg)					\
+	struct __hack
+
 #define EVENTHANDLER_INVOKE(name, ...)					\
 do {									\
 	struct eventhandler_list *_el;					\

Index: sys/i386/i386/identcpu.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/identcpu.c,v
retrieving revision 1.172
diff -u -r1.172 identcpu.c
--- sys/i386/i386/identcpu.c	12 Mar 2007 20:27:21 -0000	1.172
+++ sys/i386/i386/identcpu.c	18 Mar 2007 04:33:02 -0000
@@ -45,6 +45,8 @@
 
 #include <sys/param.h>
 #include <sys/bus.h>
+#include <sys/cpu.h>
+#include <sys/eventhandler.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/sysctl.h>
@@ -1077,6 +1079,21 @@
 	write_eflags(eflags);
 }
 
+/* Update TSC freq with the value indicated by the caller. */
+static void
+tsc_freq_changed(void *arg, const struct cf_level *level, int status)
+{
+	/* If there was an error during the transition, don't do anything. */
+	if (status != 0)
+		return;
+
+	/* Total setting for this level gives the new frequency in MHz. */
+	hw_clockrate = level->total_set.freq;
+}
+
+EVENTHANDLER_DEFINE(cpufreq_post_change, tsc_freq_changed, NULL,
+    EVENTHANDLER_PRI_ANY);
+
 /*
  * Final stage of CPU identification. -- Should I check TI?
  */


More information about the freebsd-arch mailing list