From 84ceee3fee2097c90e0c94ef207c5167df534233 Mon Sep 17 00:00:00 2001 From: kettenis Date: Sat, 24 Jul 2010 21:27:57 +0000 Subject: [PATCH] Switch hppa64 to timecounters. --- sys/arch/hppa64/dev/clock.c | 34 ++++++++++++++++++++++++++------ sys/arch/hppa64/hppa64/machdep.c | 18 +++++++++++------ sys/arch/hppa64/include/_types.h | 5 ++++- sys/arch/hppa64/include/cpu.h | 4 +++- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/sys/arch/hppa64/dev/clock.c b/sys/arch/hppa64/dev/clock.c index 2c68f463ca2..5100f9869e2 100644 --- a/sys/arch/hppa64/dev/clock.c +++ b/sys/arch/hppa64/dev/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.1 2005/04/01 10:40:47 mickey Exp $ */ +/* $OpenBSD: clock.c,v 1.2 2010/07/24 21:27:57 kettenis Exp $ */ /* * Copyright (c) 2005 Michael Shalayeff @@ -20,24 +20,46 @@ #include #include #include -#include +#include + +#include +#include #include +u_long cpu_hzticks; + +u_int itmr_get_timecount(struct timecounter *); + +struct timecounter itmr_timecounter = { + itmr_get_timecount, NULL, 0xffffffff, 0, "itmr", 0, NULL +}; + void cpu_initclocks() { + struct cpu_info *ci = curcpu(); + u_long __itmr; + + cpu_hzticks = (PAGE0->mem_10msec * 100) / hz; + itmr_timecounter.tc_frequency = PAGE0->mem_10msec * 100; + tc_init(&itmr_timecounter); + + __itmr = mfctl(CR_ITMR); + ci->ci_itmr = __itmr; + __itmr += cpu_hzticks; + mtctl(__itmr, CR_ITMR); } void setstatclockrate(int newhz) { - + /* nothing we can do */ } -void -microtime(struct timeval *tv) +u_int +itmr_get_timecount(struct timecounter *tc) { - + return (mfctl(CR_ITMR)); } diff --git a/sys/arch/hppa64/hppa64/machdep.c b/sys/arch/hppa64/hppa64/machdep.c index a2ebc2f89db..68e9788f868 100644 --- a/sys/arch/hppa64/hppa64/machdep.c +++ b/sys/arch/hppa64/hppa64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.25 2010/07/01 05:09:27 jsing Exp $ */ +/* $OpenBSD: machdep.c,v 1.26 2010/07/24 21:27:57 kettenis Exp $ */ /* * Copyright (c) 2005 Michael Shalayeff @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -434,6 +435,7 @@ inittodr(t) { struct pdc_tod tod PDC_ALIGNMENT; int error, tbad = 0; + struct timespec ts; if (t < 12*SECYR) { printf ("WARNING: preposterous time in file system"); @@ -445,18 +447,19 @@ inittodr(t) 1, PDC_TOD, PDC_TOD_READ, &tod, 0, 0, 0, 0, 0))) printf("clock: failed to fetch (%d)\n", error); - time.tv_sec = tod.sec; - time.tv_usec = tod.usec; + ts.tv_sec = tod.sec; + ts.tv_nsec = tod.usec * 1000; + tc_setclock(&ts); if (!tbad) { u_long dt; - dt = (time.tv_sec < t)? t - time.tv_sec : time.tv_sec - t; + dt = (tod.sec < t)? t - tod.sec : tod.sec - t; if (dt < 2 * SECDAY) return; printf("WARNING: clock %s %ld days", - time.tv_sec < t? "lost" : "gained", dt / SECDAY); + tod.sec < t? "lost" : "gained", dt / SECDAY); } printf (" -- CHECK AND RESET THE DATE!\n"); @@ -468,10 +471,13 @@ inittodr(t) void resettodr() { + struct timeval tv; int error; + microtime(&tv); + if ((error = pdc_call((iodcio_t)pdc, 1, PDC_TOD, PDC_TOD_WRITE, - time.tv_sec, time.tv_usec))) + tv.tv_sec, tv.tv_usec))) printf("clock: failed to save (%d)\n", error); } diff --git a/sys/arch/hppa64/include/_types.h b/sys/arch/hppa64/include/_types.h index 540fc9bd27d..f6d4586f18a 100644 --- a/sys/arch/hppa64/include/_types.h +++ b/sys/arch/hppa64/include/_types.h @@ -1,4 +1,4 @@ -/* $OpenBSD: _types.h,v 1.4 2008/07/21 20:50:54 martynas Exp $ */ +/* $OpenBSD: _types.h,v 1.5 2010/07/24 21:27:57 kettenis Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -120,4 +120,7 @@ typedef int __rune_t; typedef void * __wctrans_t; typedef void * __wctype_t; +/* Feature test macros */ +#define __HAVE_TIMECOUNTER + #endif /* _HPPA64__TYPES_H_ */ diff --git a/sys/arch/hppa64/include/cpu.h b/sys/arch/hppa64/include/cpu.h index fa530c00c71..76bf2fca2a0 100644 --- a/sys/arch/hppa64/include/cpu.h +++ b/sys/arch/hppa64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.16 2009/11/25 23:18:14 jsing Exp $ */ +/* $OpenBSD: cpu.h,v 1.17 2010/07/24 21:27:57 kettenis Exp $ */ /* * Copyright (c) 2005 Michael Shalayeff @@ -135,6 +135,8 @@ struct cpu_info { /* Spinning up the CPU */ void (*ci_spinup)(void); /* spinup routine */ void *ci_initstack; + + u_long ci_itmr; }; struct cpu_info *curcpu(void); -- 2.20.1