RTEMS 6.1-rc1
timetc.h
Go to the documentation of this file.
1
10/*-
11 * ----------------------------------------------------------------------------
12 * "THE BEER-WARE LICENSE" (Revision 42):
13 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
14 * can do whatever you want with this stuff. If we meet some day, and you think
15 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
16 * ----------------------------------------------------------------------------
17 *
18 * $FreeBSD: head/sys/sys/timetc.h 304285 2016-08-17 09:52:09Z kib $
19 */
20
21#ifndef _SYS_TIMETC_H_
22#define _SYS_TIMETC_H_
23
24#ifndef __rtems__
25#ifndef _KERNEL
26#error "no user-serviceable parts inside"
27#endif
28#else /* __rtems__ */
29#ifdef __cplusplus
30extern "C" {
31#endif /* __cplusplus */
32#endif /* __rtems__ */
33
34/*-
35 * `struct timecounter' is the interface between the hardware which implements
36 * a timecounter and the MI code which uses this to keep track of time.
37 *
38 * A timecounter is a binary counter which has two properties:
39 * * it runs at a fixed, known frequency.
40 * * it has sufficient bits to not roll over in less than approximately
41 * max(2 msec, 2/HZ seconds). (The value 2 here is really 1 + delta,
42 * for some indeterminate value of delta.)
43 */
44
45struct timecounter;
46struct vdso_timehands;
47struct vdso_timehands32;
48#ifndef __rtems__
49typedef u_int timecounter_get_t(struct timecounter *);
50#else /* __rtems__ */
51typedef uint32_t timecounter_get_t(struct timecounter *);
52#define tc_getfrequency _Timecounter_Get_frequency
53#endif /* __rtems__ */
54typedef void timecounter_pps_t(struct timecounter *);
55typedef uint32_t timecounter_fill_vdso_timehands_t(struct vdso_timehands *,
56 struct timecounter *);
57typedef uint32_t timecounter_fill_vdso_timehands32_t(struct vdso_timehands32 *,
58 struct timecounter *);
59
61 timecounter_get_t *tc_get_timecount;
62#ifndef __rtems__
63 /*
64 * This function reads the counter. It is not required to
65 * mask any unimplemented bits out, as long as they are
66 * constant.
67 */
68 timecounter_pps_t *tc_poll_pps;
69#endif /* __rtems__ */
70 /*
71 * This function is optional. It will be called whenever the
72 * timecounter is rewound, and is intended to check for PPS
73 * events. Normal hardware does not need it but timecounters
74 * which latch PPS in hardware (like sys/pci/xrpu.c) do.
75 */
76 uint32_t tc_counter_mask;
77 /* This mask should mask off any unimplemented bits. */
78 uint64_t tc_frequency;
79 /* Frequency of the counter in Hz. */
80 const char *tc_name;
81 /* Name of the timecounter. */
82 int tc_quality;
83#ifndef __rtems__
84 /*
85 * Used to determine if this timecounter is better than
86 * another timecounter higher means better. Negative
87 * means "only use at explicit request".
88 */
89 u_int tc_flags;
90#define TC_FLAGS_C2STOP 1 /* Timer dies in C2+. */
91#define TC_FLAGS_SUSPEND_SAFE 2 /*
92 * Timer functional across
93 * suspend/resume.
94 */
95
96 void *tc_priv;
97 /* Pointer to the timecounter's private parts. */
98 struct timecounter *tc_next;
99 /* Pointer to the next timecounter. */
100 timecounter_fill_vdso_timehands_t *tc_fill_vdso_timehands;
101 timecounter_fill_vdso_timehands32_t *tc_fill_vdso_timehands32;
102#endif /* __rtems__ */
103};
104
105extern struct timecounter *timecounter;
106extern int tc_min_ticktock_freq; /*
107 * Minimal tc_ticktock() call frequency,
108 * required to handle counter wraps.
109 */
110
111u_int64_t tc_getfrequency(void);
112void tc_init(struct timecounter *tc);
113void tc_setclock(struct timespec *ts);
114void tc_ticktock(int cnt);
115void cpu_tick_calibration(void);
116
117#ifdef SYSCTL_DECL
118SYSCTL_DECL(_kern_timecounter);
119#endif
120
121#ifdef __rtems__
122#ifdef __cplusplus
123}
124#endif /* __cplusplus */
125#endif /* __rtems__ */
126#endif /* !_SYS_TIMETC_H_ */
Definition: timetc.h:60