4 * Copyright (c) 2003 Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * $DragonFly: src/sys/sys/systimer.h,v 1.1 2004/01/30 05:42:18 dillon Exp $
31 #ifndef _SYS_SYSTIMER_H_
32 #define _SYS_SYSTIMER_H_
36 typedef __uint32_t sysclock_t;
37 typedef TAILQ_HEAD(systimerq, systimer) *systimerq_t;
38 typedef void (*systimer_func_t)(struct systimer *info);
39 typedef void (*systimer_func2_t)(struct systimer *info, struct intrframe *frame);
41 typedef struct systimer {
42 TAILQ_ENTRY(systimer) node;
44 sysclock_t time; /* absolute time next intr */
45 sysclock_t periodic; /* if non-zero */
46 systimer_func2_t func;
49 struct globaldata *gd; /* cpu owning structure */
52 #define SYSTF_ONQUEUE 0x0001
53 #define SYSTF_IPIRUNNING 0x0002
55 void systimer_intr(sysclock_t *time, struct intrframe *frame);
56 void systimer_add(systimer_t info);
57 void systimer_del(systimer_t info);
58 void systimer_init_periodic(systimer_t info, void *func, void *data, int hz);
59 void systimer_init_oneshot(systimer_t info, void *func, void *data, int us);
63 * note that cputimer_count() always returns a full-width wrapping counter.
65 sysclock_t cputimer_count(void);
66 sysclock_t cputimer_fromhz(int freq);
67 sysclock_t cputimer_fromus(int us);
68 void cputimer_intr_reload(sysclock_t clock);
71 * These variables hold the fixed cputimer frequency, determining the
72 * granularity of cputimer_count().
74 * The 64 bit versions are used for converting count values into uS or nS
77 * usec = (cputimer_freq64_usec * count) >> 32
79 extern sysclock_t cputimer_freq; /* in Hz */
80 extern int64_t cputimer_freq64_usec; /* in (1e6 << 32) / timer_freq */
81 extern int64_t cputimer_freq64_nsec; /* in (1e9 << 32) / timer_freq */