patch-1.3.30 linux/kernel/time.c

Next file: linux/net/Changes
Previous file: linux/kernel/sched.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.29/linux/kernel/time.c linux/kernel/time.c
@@ -14,11 +14,6 @@
  *      Created file with time related functions from sched.c and adjtimex() 
  * 1993-10-08    Torsten Duwe
  *      adjtime interface update and CMOS clock write code
- * 1994-07-02    Alan Modra
- *	fixed set_rtc_mmss, fixed time.year for >= 2000, new mktime
- * 1995-03-26    Markus Kuhn
- *      fixed 500 ms bug at call to set_rtc_mmss, fixed DS12887
- *      precision CMOS clock update
  * 1995-08-13    Torsten Duwe
  *      kernel PLL updated to 1994-12-13 specs (rfc-1489)
  */
@@ -29,92 +24,8 @@
 #include <linux/param.h>
 #include <linux/string.h>
 #include <linux/mm.h>
-
-#include <asm/segment.h>
-#include <asm/io.h>
-
-#include <linux/mc146818rtc.h>
 #include <linux/timex.h>
 
-/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
- * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
- * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
- *
- * [For the Julian calendar (which was used in Russia before 1917,
- * Britain & colonies before 1752, anywhere else before 1582,
- * and is still in use by some communities) leave out the
- * -year/100+year/400 terms, and add 10.]
- *
- * This algorithm was first published by Gauss (I think).
- *
- * WARNING: this function will overflow on 2106-02-07 06:28:16 on
- * machines were long is 32-bit! (However, as time_t is signed, we
- * will already get problems at other places on 2038-01-19 03:14:08)
- */
-static inline unsigned long mktime(unsigned int year, unsigned int mon,
-	unsigned int day, unsigned int hour,
-	unsigned int min, unsigned int sec)
-{
-	if (0 >= (int) (mon -= 2)) {	/* 1..12 -> 11,12,1..10 */
-		mon += 12;	/* Puts Feb last since it has leap day */
-		year -= 1;
-	}
-	return (((
-	    (unsigned long)(year/4 - year/100 + year/400 + 367*mon/12 + day) +
-	      year*365 - 719499
-	    )*24 + hour /* now have hours */
-	   )*60 + min /* now have minutes */
-	  )*60 + sec; /* finally seconds */
-}
-
-void time_init(void)
-{
-	unsigned int year, mon, day, hour, min, sec;
-	int i;
-
-	/* The Linux interpretation of the CMOS clock register contents:
-	 * When the Update-In-Progress (UIP) flag goes from 1 to 0, the
-	 * RTC registers show the second which has precisely just started.
-	 * Let's hope other operating systems interpret the RTC the same way.
-	 */
-	/* read RTC exactly on falling edge of update flag */
-	for (i = 0 ; i < 1000000 ; i++)	/* may take up to 1 second... */
-		if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)
-			break;
-	for (i = 0 ; i < 1000000 ; i++)	/* must try at least 2.228 ms */
-		if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP))
-			break;
-	do { /* Isn't this overkill ? UIP above should guarantee consistency */
-		sec = CMOS_READ(RTC_SECONDS);
-		min = CMOS_READ(RTC_MINUTES);
-		hour = CMOS_READ(RTC_HOURS);
-		day = CMOS_READ(RTC_DAY_OF_MONTH);
-		mon = CMOS_READ(RTC_MONTH);
-		year = CMOS_READ(RTC_YEAR);
-	} while (sec != CMOS_READ(RTC_SECONDS));
-	if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
-	  {
-	    BCD_TO_BIN(sec);
-	    BCD_TO_BIN(min);
-	    BCD_TO_BIN(hour);
-	    BCD_TO_BIN(day);
-	    BCD_TO_BIN(mon);
-	    BCD_TO_BIN(year);
-	  }
-#ifdef ALPHA_PRE_V1_2_SRM_CONSOLE
-	/*
-	 * The meaning of life, the universe, and everything. Plus
-	 * this makes the year come out right on SRM consoles earlier
-	 * than v1.2.
-	 */
-	year -= 42;
-#endif
-	if ((year += 1900) < 1970)
-		year += 100;
-	xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
-	xtime.tv_usec = 0;
-}
-
 /* 
  * The timezone where the local system is located.  Used as a default by some
  * programs who obtain this value by using gettimeofday.
@@ -123,11 +34,11 @@
 
 asmlinkage int sys_time(int * tloc)
 {
-	int i, error;
+	int i;
 
 	i = CURRENT_TIME;
 	if (tloc) {
-		error = verify_area(VERIFY_WRITE, tloc, sizeof(*tloc));
+		int error = verify_area(VERIFY_WRITE, tloc, sizeof(*tloc));
 		if (error)
 			return error;
 		put_user(i,tloc);
@@ -155,81 +66,6 @@
 	return 0;
 }
 
-/* This function must be called with interrupts disabled 
- * It was inspired by Steve McCanne's microtime-i386 for BSD.  -- jrs
- * 
- * However, the pc-audio speaker driver changes the divisor so that
- * it gets interrupted rather more often - it loads 64 into the
- * counter rather than 11932! This has an adverse impact on
- * do_gettimeoffset() -- it stops working! What is also not
- * good is that the interval that our timer function gets called
- * is no longer 10.0002 ms, but 9.9767 ms. To get around this
- * would require using a different timing source. Maybe someone
- * could use the RTC - I know that this can interrupt at frequencies
- * ranging from 8192Hz to 2Hz. If I had the energy, I'd somehow fix
- * it so that at startup, the timer code in sched.c would select
- * using either the RTC or the 8253 timer. The decision would be
- * based on whether there was any other device around that needed
- * to trample on the 8253. I'd set up the RTC to interrupt at 1024 Hz,
- * and then do some jiggery to have a version of do_timer that 
- * advanced the clock by 1/1024 s. Every time that reached over 1/100
- * of a second, then do all the old code. If the time was kept correct
- * then do_gettimeoffset could just return 0 - there is no low order
- * divider that can be accessed.
- *
- * Ideally, you would be able to use the RTC for the speaker driver,
- * but it appears that the speaker driver really needs interrupt more
- * often than every 120 us or so.
- *
- * Anyway, this needs more thought....		pjsg (1993-08-28)
- * 
- * If you are really that interested, you should be reading
- * comp.protocols.time.ntp!
- */
-
-#define TICK_SIZE tick
-
-static inline unsigned long do_gettimeoffset(void)
-{
-	int count;
-	unsigned long offset = 0;
-
-	/* timer count may underflow right here */
-	outb_p(0x00, 0x43);	/* latch the count ASAP */
-	count = inb_p(0x40);	/* read the latched count */
-	count |= inb(0x40) << 8;
-	/* we know probability of underflow is always MUCH less than 1% */
-	if (count > (LATCH - LATCH/100)) {
-		/* check for pending timer interrupt */
-		outb_p(0x0a, 0x20);
-		if (inb(0x20) & 1)
-			offset = TICK_SIZE;
-	}
-	count = ((LATCH-1) - count) * TICK_SIZE;
-	count = (count + LATCH/2) / LATCH;
-	return offset + count;
-}
-
-/*
- * This version of gettimeofday has near microsecond resolution.
- */
-void do_gettimeofday(struct timeval *tv)
-{
-	unsigned long flags;
-
-	save_flags(flags);
-	cli();
-	*tv = xtime;
-#if defined (__i386__) || defined (__mips__)
-	tv->tv_usec += do_gettimeoffset();
-	if (tv->tv_usec >= 1000000) {
-		tv->tv_usec -= 1000000;
-		tv->tv_sec++;
-	}
-#endif /* !defined (__i386__) && !defined (__mips__) */
-	restore_flags(flags);
-}
-
 asmlinkage int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
 {
 	int error;
@@ -312,27 +148,8 @@
 				warp_clock();
 		}
 	}
-	if (tv) {
-		cli();
-		/* This is revolting. We need to set the xtime.tv_usec
-		 * correctly. However, the value in this location is
-		 * is value at the last tick.
-		 * Discover what correction gettimeofday
-		 * would have done, and then undo it!
-		 */
-		new_tv.tv_usec -= do_gettimeoffset();
-
-		if (new_tv.tv_usec < 0) {
-			new_tv.tv_usec += 1000000;
-			new_tv.tv_sec--;
-		}
-
-		xtime = new_tv;
-		time_state = TIME_BAD;
-		time_maxerror = 0x70000000;
-		time_esterror = 0x70000000;
-		sti();
-	}
+	if (tv)
+		do_settimeofday(&new_tv);
 	return 0;
 }
 
@@ -510,64 +327,4 @@
 
 	memcpy_tofs(txc_p, &txc, sizeof(struct timex));
 	return time_state;
-}
-
-/*
- * In order to set the CMOS clock precisely, set_rtc_mmss has to be
- * called 500 ms after the second nowtime has started, because when
- * nowtime is written into the registers of the CMOS clock, it will
- * jump to the next second precisely 500 ms later. Check the Motorola
- * MC146818A or Dallas DS12887 data sheet for details.
- */
-int set_rtc_mmss(unsigned long nowtime)
-{
-  int retval = 0;
-  int real_seconds, real_minutes, cmos_minutes;
-  unsigned char save_control, save_freq_select;
-
-  save_control = CMOS_READ(RTC_CONTROL); /* tell the clock it's being set */
-  CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL);
-
-  save_freq_select = CMOS_READ(RTC_FREQ_SELECT); /* stop and reset prescaler */
-  CMOS_WRITE((save_freq_select|RTC_DIV_RESET2), RTC_FREQ_SELECT);
-
-  cmos_minutes = CMOS_READ(RTC_MINUTES);
-  if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
-    BCD_TO_BIN(cmos_minutes);
-
-  /* since we're only adjusting minutes and seconds,
-   * don't interfere with hour overflow. This avoids
-   * messing with unknown time zones but requires your
-   * RTC not to be off by more than 15 minutes
-   */
-  real_seconds = nowtime % 60;
-  real_minutes = nowtime / 60;
-  if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1)
-    real_minutes += 30;		/* correct for half hour time zone */
-  real_minutes %= 60;
-
-  if (abs(real_minutes - cmos_minutes) < 30)
-    {
-      if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
-	{
-	  BIN_TO_BCD(real_seconds);
-	  BIN_TO_BCD(real_minutes);
-	}
-      CMOS_WRITE(real_seconds,RTC_SECONDS);
-      CMOS_WRITE(real_minutes,RTC_MINUTES);
-    }
-  else
-    retval = -1;
-
-  /* The following flags have to be released exactly in this order,
-   * otherwise the DS12887 (popular MC146818A clone with integrated
-   * battery and quartz) will not reset the oscillator and will not
-   * update precisely 500 ms later. You won't find this mentioned in
-   * the Dallas Semiconductor data sheets, but who believes data
-   * sheets anyway ...                           -- Markus Kuhn
-   */
-  CMOS_WRITE(save_control, RTC_CONTROL);
-  CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
-
-  return retval;
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this