Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Jul 2007 14:19:28 GMT
From:      Attilio Rao <attilio@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 123652 for review
Message-ID:  <200707171419.l6HEJSw6018602@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123652

Change 123652 by attilio@attilio_xen on 2007/07/17 14:18:39

	- Sort macro, variables and functions in the style-suggested way
	- Give the correctlty needed linkage to variables
	- Make xen_disable_rtc_set as sysctl tunable
	- Remove unuseful rtc_statusb
	- Rename fast_gettimeoffset_quotient in cached_gtm since it is
	  too long
	- Introduce i8254_init() for xen too since it should handle mutex
	  building.
	
	XXX: Xen is still no MP safe.

Affected files ...

.. //depot/projects/xen3/src/sys/i386-xen/i386-xen/clock.c#16 edit
.. //depot/projects/xen3/src/sys/i386-xen/i386-xen/machdep.c#16 edit

Differences ...

==== //depot/projects/xen3/src/sys/i386-xen/i386-xen/clock.c#16 (text+ko) ====

@@ -93,48 +93,41 @@
 #define	LEAPYEAR(y)	(!((y) % 4))
 #define	DAYSPERYEAR	(28+30*4+31*7)
 
-int	adjkerntz;		/* local offset from GMT in seconds */
-int	clkintr_pending;
-int	xen_disable_rtc_set = 1;	/* disable resettodr() if != 0 */
-int	pscnt = 1;
-int	psdiv = 1;
-int	statclock_disable;
 #ifndef TIMER_FREQ
-#define TIMER_FREQ   1193182
+#define	TIMER_FREQ	1193182
 #endif
-int     wall_cmos_clock;
-int     independent_wallclock;
-u_int	timer_freq = TIMER_FREQ;
-struct mtx clock_lock;
-#define	RTC_LOCK	mtx_lock_spin(&clock_lock)
-#define	RTC_UNLOCK	mtx_unlock_spin(&clock_lock)
-
-static	const u_char daysinmonth[] = {31,28,31,30,31,30,31,31,30,31,30,31};
-static  u_char  rtc_statusb = RTCSB_24HR;
 
-
 /* Values for timerX_state: */
 #define	RELEASED	0
 #define	RELEASE_PENDING	1
 #define	ACQUIRED	2
 #define	ACQUIRE_PENDING	3
 
-static	u_char	timer2_state;
+#define	RTC_LOCK_INIT	mtx_init(&clock_lock, "clk", NULL, MTX_SPIN);
+#define	RTC_LOCK	mtx_lock_spin(&clock_lock)
+#define	RTC_UNLOCK	mtx_unlock_spin(&clock_lock)
 
-/* Cached *multiplier* to convert TSC counts to microseconds.
- * (see the equation below).
- * Equal to 2^32 * (1 / (clocks per usec) ).
- * Initialized in time_init.
- */
-static unsigned long fast_gettimeoffset_quotient;
-
-/* These are peridically updated in shared_info, and then copied here. */
+int adjkerntz;		/* local offset from GMT in seconds */
+int clkintr_pending;
+int pscnt = 1;
+int psdiv = 1;
+int statclock_disable;
+int wall_cmos_clock;
+u_int timer_freq = TIMER_FREQ;
+static int independent_wallclock;
+static int xen_disable_rtc_set;
+static u_long cached_gtm;	/* cached quotient for TSC -> microseconds */
+static u_char timer2_state = RELEASED;
 static struct timespec shadow_tv;
+static uint32_t shadow_tv_version;	/* XXX: lazy locking */
+static struct mtx clock_lock;
 
-uint32_t shadow_tv_version;
+static	const u_char daysinmonth[] = {31,28,31,30,31,30,31,31,30,31,30,31};
 
 SYSCTL_INT(_machdep, OID_AUTO, independent_wallclock,
-	   CTLFLAG_RW, &independent_wallclock, 0, "");
+    CTLFLAG_RW, &independent_wallclock, 0, "");
+SYSCTL_INT(_machdep, OID_AUTO, xen_disable_rtc_set,
+    CTLFLAG_RW, &xen_disable_rtc_set, 1, "");
 
 
 #define do_div(n,base) ({ \
@@ -356,6 +349,16 @@
 
 
 /*
+ * XXX: timer needs more SMP work.
+ */
+void
+i8254_init(void)
+{
+
+	RTC_LOCK_INIT;
+}
+
+/*
  * Wait "n" microseconds.
  * Relies on timer 1 counting down from (timer_freq / hz)
  * Note: timer had better have been programmed before this is first used!
@@ -500,7 +503,7 @@
 	{	
 		unsigned long eax=0, edx=1000;
 		__asm__("divl %2"
-			:"=a" (fast_gettimeoffset_quotient), "=d" (edx)
+			:"=a" (cached_gtm), "=d" (edx)
 			:"r" (cpu_khz),
 			"0" (eax), "1" (edx));
 	}
@@ -763,7 +766,7 @@
 	writertc(RTC_DAY, bin2bcd(tm + 1));             /* Write back Month Day */
 
 	/* Reenable RTC updates and interrupts. */
-	writertc(RTC_STATUSB, rtc_statusb);
+	writertc(RTC_STATUSB, RTCSB_24HR);
 	rtcin(RTC_INTR);
 }
 
@@ -889,7 +892,7 @@
 	eax -= shadow_tsc_stamp;
 
 	/*
-	 * Time offset = (tsc_low delta) * fast_gettimeoffset_quotient
+	 * Time offset = (tsc_low delta) * cached_gtm
 	 *             = (tsc_low delta) * (usecs_per_clock)
 	 *             = (tsc_low delta) * (usecs_per_jiffy / clocks_per_jiffy)
 	 *
@@ -899,7 +902,7 @@
 
 	__asm__("mull %2"
 		:"=a" (eax), "=d" (edx)
-		:"rm" (fast_gettimeoffset_quotient),
+		:"rm" (cached_gtm),
 		"0" (eax));
 
 	/* our adjusted time offset in microseconds */

==== //depot/projects/xen3/src/sys/i386-xen/i386-xen/machdep.c#16 (text+ko) ====

@@ -2389,6 +2389,8 @@
 	}
 #endif /* XBOX */
 
+	i8254_init();
+
 	/*
 	 * Initialize the console before we print anything out.
 	 */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707171419.l6HEJSw6018602>