Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys PR/49207: Kamil Rytarowski: Add sys/clock.h with generic...
details: https://anonhg.NetBSD.org/src/rev/18a93a224c65
branches: trunk
changeset: 333802:18a93a224c65
user: christos <christos%NetBSD.org@localhost>
date: Mon Nov 17 02:15:48 2014 +0000
description:
PR/49207: Kamil Rytarowski: Add sys/clock.h with generic time macros
(derived from clock_subr.h). Keep clock_subr.h with the kernel structures
and functions to reduce diffs, and have clock.h only include standalone
constants and macros.
diffstat:
sys/arch/atari/dev/clockreg.h | 6 +--
sys/arch/dreamcast/dev/g2/g2rtc.c | 6 +-
sys/arch/hp300/stand/common/clock.c | 21 +++--------
sys/arch/hpcmips/vr/rtc.c | 8 ++--
sys/arch/hpcmips/vr/rtcreg.h | 5 +--
sys/arch/mvme68k/stand/libsa/chiptotime.c | 12 ++---
sys/arch/mvme68k/stand/libsa/clock.c | 12 ++---
sys/arch/mvmeppc/stand/libsa/clock.c | 13 +++---
sys/arch/vax/include/clock.h | 10 +-----
sys/arch/vax/vax/clock.c | 8 ++--
sys/arch/x68k/stand/libsa/clock.c | 13 +++---
sys/dev/clock_subr.c | 55 ++++++------------------------
sys/dev/clock_subr.h | 23 +++++-------
sys/dev/dec/mcclock.c | 12 +++---
sys/fs/smbfs/smbfs_subr.c | 8 ++--
sys/kern/kern_todr.c | 18 +++++-----
sys/sys/Makefile | 4 +-
17 files changed, 83 insertions(+), 151 deletions(-)
diffs (truncated from 713 to 300 lines):
diff -r c9c91c2d6f6e -r 18a93a224c65 sys/arch/atari/dev/clockreg.h
--- a/sys/arch/atari/dev/clockreg.h Mon Nov 17 01:38:00 2014 +0000
+++ b/sys/arch/atari/dev/clockreg.h Mon Nov 17 02:15:48 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clockreg.h,v 1.6 2009/10/20 19:10:10 snj Exp $ */
+/* $NetBSD: clockreg.h,v 1.7 2014/11/17 02:15:48 christos Exp $ */
/*
* Copyright (c) 1995 Leo Weppelman.
@@ -56,10 +56,6 @@
/*
* Some useful constants/macros
*/
-#define is_leap(x) (!(x % 4) && ((x % 100) || !(x % 1000)))
#define range_test(n, l, h) ((n) < (l) || (n) > (h))
-#define SECS_DAY 86400L
-#define SECS_HOUR 3600L
#define GEMSTARTOFTIME ((machineid & ATARI_CLKBROKEN) ? 1970 : 1968)
-#define BSDSTARTOFTIME 1970
#endif /* _CLOCKREG_H */
diff -r c9c91c2d6f6e -r 18a93a224c65 sys/arch/dreamcast/dev/g2/g2rtc.c
--- a/sys/arch/dreamcast/dev/g2/g2rtc.c Mon Nov 17 01:38:00 2014 +0000
+++ b/sys/arch/dreamcast/dev/g2/g2rtc.c Mon Nov 17 02:15:48 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: g2rtc.c,v 1.6 2011/07/19 15:52:29 dyoung Exp $ */
+/* $NetBSD: g2rtc.c,v 1.7 2014/11/17 02:15:48 christos Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: g2rtc.c,v 1.6 2011/07/19 15:52:29 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: g2rtc.c,v 1.7 2014/11/17 02:15:48 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -43,7 +43,7 @@
#define G2RTC_REG_SIZE 12
/* Offset by 20 years, 5 of them are leap */
-#define G2RTC_OFFSET (20 * SECYR + 5 * SECDAY)
+#define G2RTC_OFFSET (20 * SECS_PER_COMMON_YEAR + 5 * SECS_PER_DAY)
struct g2rtc_softc {
device_t sc_dev;
diff -r c9c91c2d6f6e -r 18a93a224c65 sys/arch/hp300/stand/common/clock.c
--- a/sys/arch/hp300/stand/common/clock.c Mon Nov 17 01:38:00 2014 +0000
+++ b/sys/arch/hp300/stand/common/clock.c Mon Nov 17 02:15:48 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clock.c,v 1.12 2014/04/19 06:04:58 tsutsui Exp $ */
+/* $NetBSD: clock.c,v 1.13 2014/11/17 02:15:48 christos Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@@ -49,31 +49,22 @@
#include <hp300/dev/frodoreg.h> /* for APCI offsets */
#include <hp300/dev/intioreg.h> /* for frodo offsets */
#include <dev/ic/mc146818reg.h>
+#include <dev/clock_subr.h>
#include <lib/libsa/stand.h>
#include <lib/libsa/net.h>
#include <hp300/stand/common/samachdep.h>
#define FEBRUARY 2
-#define STARTOFTIME 1970
-#define SECDAY (60L * 60L * 24L)
-#define SECYR (SECDAY * 365)
#define BBC_SET_REG 0xe0
#define BBC_WRITE_REG 0xc2
#define BBC_READ_REG 0xc3
#define NUM_BBC_REGS 12
-#define leapyear(year) ((year) % 4 == 0)
#define range_test(n, l, h) if ((n) < (l) || (n) > (h)) return false
-#define days_in_year(a) (leapyear(a) ? 366 : 365)
-#define days_in_month(a) (month_days[(a) - 1])
#define bbc_to_decimal(a,b) (bbc_registers[a] * 10 + bbc_registers[b])
-static const int month_days[12] = {
- 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
-};
-
static uint8_t bbc_registers[13];
static struct hil_dev *bbcaddr = BBCADDR;
@@ -133,7 +124,7 @@
year = bbc_to_decimal(12, 11) + 1900;
}
- if (year < STARTOFTIME)
+ if (year < POSIX_BASE_YEAR)
year += 100;
#ifdef CLOCK_DEBUG
@@ -147,9 +138,9 @@
tmp = 0;
- for (i = STARTOFTIME; i < year; i++)
- tmp += days_in_year(i);
- if (leapyear(year) && month > FEBRUARY)
+ for (i = POSIX_BASE_YEAR; i < year; i++)
+ tmp += days_per_year(i);
+ if (is_leap_year(year) && month > FEBRUARY)
tmp++;
for (i = 1; i < month; i++)
diff -r c9c91c2d6f6e -r 18a93a224c65 sys/arch/hpcmips/vr/rtc.c
--- a/sys/arch/hpcmips/vr/rtc.c Mon Nov 17 01:38:00 2014 +0000
+++ b/sys/arch/hpcmips/vr/rtc.c Mon Nov 17 02:15:48 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rtc.c,v 1.32 2011/03/18 15:31:38 tsutsui Exp $ */
+/* $NetBSD: rtc.c,v 1.33 2014/11/17 02:15:48 christos Exp $ */
/*-
* Copyright (c) 1999 Shin Takemura. All rights reserved.
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtc.c,v 1.32 2011/03/18 15:31:38 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtc.c,v 1.33 2014/11/17 02:15:48 christos Exp $");
#include "opt_vr41xx.h"
@@ -203,10 +203,10 @@
* be on Jan 1.
*/
for (year = EPOCHYEAR; year < POSIX_BASE_YEAR; year++) {
- sc->sc_epoch += LEAPYEAR4(year) ? SECYR + SECDAY : SECYR;
+ sc->sc_epoch += days_per_year(year) * SECS_PER_YEAR;
}
for (year = POSIX_BASE_YEAR; year < EPOCHYEAR; year++) {
- sc->sc_epoch -= LEAPYEAR4(year) ? SECYR + SECDAY : SECYR;
+ sc->sc_epoch -= days_per_year(year) * SECS_PER_YEAR;
}
/*
diff -r c9c91c2d6f6e -r 18a93a224c65 sys/arch/hpcmips/vr/rtcreg.h
--- a/sys/arch/hpcmips/vr/rtcreg.h Mon Nov 17 01:38:00 2014 +0000
+++ b/sys/arch/hpcmips/vr/rtcreg.h Mon Nov 17 02:15:48 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rtcreg.h,v 1.9 2006/09/16 02:14:57 gdamore Exp $ */
+/* $NetBSD: rtcreg.h,v 1.10 2014/11/17 02:15:48 christos Exp $ */
/*-
* Copyright (c) 1999 Shin Takemura. All rights reserved.
@@ -42,9 +42,6 @@
#define EPOCHMONTH 1 /* WINCE epoch month of year */
#define EPOCHDATE 1 /* WINCE epoch date of month */
-#define LEAPYEAR4(year) ((((year) % 4) == 0 && ((year) % 100) != 0) || ((year%400)) == 0)
-#define LEAPYEAR2(year) (((year) % 4) == 0)
-
/*
* RTC (Real Time Clock Unit) Registers definitions.
* start 0x0B0000C0 (Vr4102-4121)
diff -r c9c91c2d6f6e -r 18a93a224c65 sys/arch/mvme68k/stand/libsa/chiptotime.c
--- a/sys/arch/mvme68k/stand/libsa/chiptotime.c Mon Nov 17 01:38:00 2014 +0000
+++ b/sys/arch/mvme68k/stand/libsa/chiptotime.c Mon Nov 17 02:15:48 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: chiptotime.c,v 1.4 2008/01/12 09:54:32 tsutsui Exp $ */
+/* $NetBSD: chiptotime.c,v 1.5 2014/11/17 02:15:48 christos Exp $ */
#include <sys/types.h>
@@ -15,9 +15,6 @@
#define TOBCD(x) (int)((((unsigned int)(x)) / 10 * 16) +\
(((unsigned int)(x)) % 10))
-#define SECDAY (24 * 60 * 60)
-#define SECYR (SECDAY * 365)
-#define LEAPYEAR(y) (((y) & 3) == 0)
#define YEAR0 68
/*
@@ -46,10 +43,11 @@
return (0);
days = 0;
for (yr = 70; yr < year; yr++)
- days += LEAPYEAR(yr) ? 366 : 365;
+ days += days_per_year(yr);
days += dayyr[mon - 1] + day - 1;
- if (LEAPYEAR(yr) && mon > 2)
+ if (is_leap_year(yr) && mon > 2)
days++;
/* now have days since Jan 1, 1970; the rest is easy... */
- return days * SECDAY + hour * 3600 + min * 60 + sec;
+ return days * SECS_PER_DAY + hour * SECS_PER_HOUR
+ + min * SECS_PER_MINUTE + sec;
}
diff -r c9c91c2d6f6e -r 18a93a224c65 sys/arch/mvme68k/stand/libsa/clock.c
--- a/sys/arch/mvme68k/stand/libsa/clock.c Mon Nov 17 01:38:00 2014 +0000
+++ b/sys/arch/mvme68k/stand/libsa/clock.c Mon Nov 17 02:15:48 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clock.c,v 1.9 2009/01/12 11:32:44 tsutsui Exp $ */
+/* $NetBSD: clock.c,v 1.10 2014/11/17 02:15:48 christos Exp $ */
#include <sys/types.h>
#include <machine/prom.h>
@@ -15,9 +15,6 @@
#define TOBCD(x) (int)((((unsigned int)(x)) / 10 * 16) +\
(((unsigned int)(x)) % 10))
-#define SECDAY (24 * 60 * 60)
-#define SECYR (SECDAY * 365)
-#define LEAPYEAR(y) (((y) & 3) == 0)
#define YEAR0 68
/*
@@ -46,12 +43,13 @@
return (0);
days = 0;
for (yr = 70; yr < year; yr++)
- days += LEAPYEAR(yr) ? 366 : 365;
+ days += days_per_year(yr);
days += dayyr[mon - 1] + day - 1;
- if (LEAPYEAR(yr) && mon > 2)
+ if (is_leap_year(yr) && mon > 2)
days++;
/* now have days since Jan 1, 1970; the rest is easy... */
- return days * SECDAY + hour * 3600 + min * 60 + sec;
+ return days * SECS_PER_DAY + hour * SECS_PER_HOUR
+ + min * SECS_PER_MINUTE + sec;
}
satime_t
diff -r c9c91c2d6f6e -r 18a93a224c65 sys/arch/mvmeppc/stand/libsa/clock.c
--- a/sys/arch/mvmeppc/stand/libsa/clock.c Mon Nov 17 01:38:00 2014 +0000
+++ b/sys/arch/mvmeppc/stand/libsa/clock.c Mon Nov 17 02:15:48 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clock.c,v 1.3 2009/03/18 10:22:33 cegger Exp $ */
+/* $NetBSD: clock.c,v 1.4 2014/11/17 02:15:49 christos Exp $ */
/*
* This is a slightly modified version of mvme68k's standalone clock.c.
@@ -7,6 +7,7 @@
*/
#include <sys/types.h>
+#include <dev/clock_subr.h>
#include "stand.h"
#include "net.h"
@@ -16,9 +17,6 @@
#define FROMBCD(x) (int)((((unsigned int)(x)) >> 4) * 10 +\
(((unsigned int)(x)) & 0xf))
-#define SECDAY (24 * 60 * 60)
-#define SECYR (SECDAY * 365)
-#define LEAPYEAR(y) (((y) & 3) == 0)
#define YEAR0 68
/*
@@ -47,12 +45,13 @@
return (0);
days = 0;
for (yr = 70; yr < year; yr++)
- days += LEAPYEAR(yr) ? 366 : 365;
+ days += days_per_year(yr);
days += dayyr[mon - 1] + day - 1;
- if (LEAPYEAR(yr) && mon > 2)
+ if (is_leap_year(yr) && mon > 2)
days++;
/* now have days since Jan 1, 1970; the rest is easy... */
- return (days * SECDAY + hour * 3600 + min * 60 + sec);
+ return days * SECS_PER_DAY + hour * SECS_PER_HOUR
+ + min * SECS_PER_MINUTE + sec;
}
satime_t
diff -r c9c91c2d6f6e -r 18a93a224c65 sys/arch/vax/include/clock.h
--- a/sys/arch/vax/include/clock.h Mon Nov 17 01:38:00 2014 +0000
+++ b/sys/arch/vax/include/clock.h Mon Nov 17 02:15:48 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clock.h,v 1.8 2010/11/19 03:31:24 uwe Exp $ */
+/* $NetBSD: clock.h,v 1.9 2014/11/17 02:15:49 christos Exp $ */
/*
* Copyright (c) 1996 Ludd, University of Lule}, Sweden.
* All rights reserved.
@@ -37,14 +37,6 @@
/*
* Time constants. These are unlikely to change.
*/
-#define IS_LEAPYEAR(y) ((((y % 4) == 0) && ((y % 100) != 0)) || ((y % 400) == 0))
-
-#define SEC_PER_MIN (60)
-#define SEC_PER_HOUR (SEC_PER_MIN * 60)
-#define SEC_PER_DAY (SEC_PER_HOUR * 24)
-#define DAYSPERYEAR(y) (IS_LEAPYEAR(y) ? 366 : 365)
-#define SECPERYEAR(y) (DAYSPERYEAR(y) * SEC_PER_DAY)
-
#define TODRBASE (1 << 28) /* Rumours says it comes from VMS */
#define SEC_OFF 0
diff -r c9c91c2d6f6e -r 18a93a224c65 sys/arch/vax/vax/clock.c
Home |
Main Index |
Thread Index |
Old Index