7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 /* All Rights Reserved */
23
24 /*
25 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
26 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
27 */
28
29 #include <sys/param.h>
30 #include <sys/t_lock.h>
31 #include <sys/types.h>
32 #include <sys/tuneable.h>
33 #include <sys/sysmacros.h>
34 #include <sys/systm.h>
35 #include <sys/cpuvar.h>
36 #include <sys/lgrp.h>
37 #include <sys/user.h>
38 #include <sys/proc.h>
39 #include <sys/callo.h>
40 #include <sys/kmem.h>
41 #include <sys/var.h>
42 #include <sys/cmn_err.h>
43 #include <sys/swap.h>
44 #include <sys/vmsystm.h>
45 #include <sys/class.h>
46 #include <sys/time.h>
297 static boolean_t lbolt_cyc_only = B_FALSE;
298
299 /*
300 * Cache aligned, per CPU structure with lbolt usage statistics.
301 */
302 static lbolt_cpu_t *lb_cpu;
303
304 /*
305 * Single, cache aligned, structure with all the information required by
306 * the lbolt implementation.
307 */
308 lbolt_info_t *lb_info;
309
310
311 int one_sec = 1; /* turned on once every second */
312 static int fsflushcnt; /* counter for t_fsflushr */
313 int dosynctodr = 1; /* patchable; enable/disable sync to TOD chip */
314 int tod_needsync = 0; /* need to sync tod chip with software time */
315 static int tod_broken = 0; /* clock chip doesn't work */
316 time_t boot_time = 0; /* Boot time in seconds since 1970 */
317 cyclic_id_t clock_cyclic; /* clock()'s cyclic_id */
318 cyclic_id_t deadman_cyclic; /* deadman()'s cyclic_id */
319
320 extern void clock_tick_schedule(int);
321
322 static int lgrp_ticks; /* counter to schedule lgrp load calcs */
323
324 /*
325 * for tod fault detection
326 */
327 #define TOD_REF_FREQ ((longlong_t)(NANOSEC))
328 #define TOD_STALL_THRESHOLD (TOD_REF_FREQ * 3 / 2)
329 #define TOD_JUMP_THRESHOLD (TOD_REF_FREQ / 2)
330 #define TOD_FILTER_N 4
331 #define TOD_FILTER_SETTLE (4 * TOD_FILTER_N)
332 static enum tod_fault_type tod_faulted = TOD_NOFAULT;
333
334 static int tod_status_flag = 0; /* used by tod_validate() */
335
336 static hrtime_t prev_set_tick = 0; /* gethrtime() prior to tod_set() */
1886 spl = splhi();
1887 tod_set(ts);
1888 tmp = tod_get();
1889 splx(spl);
1890
1891 if (tmp.tv_sec != ts.tv_sec && tmp.tv_sec != ts.tv_sec + 1) {
1892 tod_broken = 1;
1893 dosynctodr = 0;
1894 cmn_err(CE_WARN, "Time-of-day chip unresponsive.");
1895 } else {
1896 cmn_err(CE_WARN, "Time-of-day chip had "
1897 "incorrect date; check and reset.");
1898 }
1899 set_clock = 1;
1900 }
1901
1902 if (!boot_time) {
1903 boot_time = ts.tv_sec;
1904 set_clock = 1;
1905 }
1906
1907 if (set_clock)
1908 set_hrestime(&ts);
1909
1910 mutex_exit(&tod_lock);
1911 }
1912
1913 int timechanged; /* for testing if the system time has been reset */
1914
1915 void
1916 set_hrestime(timestruc_t *ts)
1917 {
1918 int spl = hr_clock_lock();
1919 hrestime = *ts;
1920 membar_enter(); /* hrestime must be visible before timechanged++ */
1921 timedelta = 0;
1922 timechanged++;
1923 hr_clock_unlock(spl);
1924 callout_hrestime();
1925 }
|
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 /* All Rights Reserved */
23
24 /*
25 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
26 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
27 * Copyright 2016 Garrett D'Amore
28 */
29
30 #include <sys/param.h>
31 #include <sys/t_lock.h>
32 #include <sys/types.h>
33 #include <sys/tuneable.h>
34 #include <sys/sysmacros.h>
35 #include <sys/systm.h>
36 #include <sys/cpuvar.h>
37 #include <sys/lgrp.h>
38 #include <sys/user.h>
39 #include <sys/proc.h>
40 #include <sys/callo.h>
41 #include <sys/kmem.h>
42 #include <sys/var.h>
43 #include <sys/cmn_err.h>
44 #include <sys/swap.h>
45 #include <sys/vmsystm.h>
46 #include <sys/class.h>
47 #include <sys/time.h>
298 static boolean_t lbolt_cyc_only = B_FALSE;
299
300 /*
301 * Cache aligned, per CPU structure with lbolt usage statistics.
302 */
303 static lbolt_cpu_t *lb_cpu;
304
305 /*
306 * Single, cache aligned, structure with all the information required by
307 * the lbolt implementation.
308 */
309 lbolt_info_t *lb_info;
310
311
312 int one_sec = 1; /* turned on once every second */
313 static int fsflushcnt; /* counter for t_fsflushr */
314 int dosynctodr = 1; /* patchable; enable/disable sync to TOD chip */
315 int tod_needsync = 0; /* need to sync tod chip with software time */
316 static int tod_broken = 0; /* clock chip doesn't work */
317 time_t boot_time = 0; /* Boot time in seconds since 1970 */
318 hrtime_t boot_hrtime = 0; /* gethrtime() at boot */
319 cyclic_id_t clock_cyclic; /* clock()'s cyclic_id */
320 cyclic_id_t deadman_cyclic; /* deadman()'s cyclic_id */
321
322 extern void clock_tick_schedule(int);
323
324 static int lgrp_ticks; /* counter to schedule lgrp load calcs */
325
326 /*
327 * for tod fault detection
328 */
329 #define TOD_REF_FREQ ((longlong_t)(NANOSEC))
330 #define TOD_STALL_THRESHOLD (TOD_REF_FREQ * 3 / 2)
331 #define TOD_JUMP_THRESHOLD (TOD_REF_FREQ / 2)
332 #define TOD_FILTER_N 4
333 #define TOD_FILTER_SETTLE (4 * TOD_FILTER_N)
334 static enum tod_fault_type tod_faulted = TOD_NOFAULT;
335
336 static int tod_status_flag = 0; /* used by tod_validate() */
337
338 static hrtime_t prev_set_tick = 0; /* gethrtime() prior to tod_set() */
1888 spl = splhi();
1889 tod_set(ts);
1890 tmp = tod_get();
1891 splx(spl);
1892
1893 if (tmp.tv_sec != ts.tv_sec && tmp.tv_sec != ts.tv_sec + 1) {
1894 tod_broken = 1;
1895 dosynctodr = 0;
1896 cmn_err(CE_WARN, "Time-of-day chip unresponsive.");
1897 } else {
1898 cmn_err(CE_WARN, "Time-of-day chip had "
1899 "incorrect date; check and reset.");
1900 }
1901 set_clock = 1;
1902 }
1903
1904 if (!boot_time) {
1905 boot_time = ts.tv_sec;
1906 set_clock = 1;
1907 }
1908 if (!boot_hrtime) {
1909 boot_hrtime = gethrtime();
1910 }
1911
1912 if (set_clock)
1913 set_hrestime(&ts);
1914
1915 mutex_exit(&tod_lock);
1916 }
1917
1918 int timechanged; /* for testing if the system time has been reset */
1919
1920 void
1921 set_hrestime(timestruc_t *ts)
1922 {
1923 int spl = hr_clock_lock();
1924 hrestime = *ts;
1925 membar_enter(); /* hrestime must be visible before timechanged++ */
1926 timedelta = 0;
1927 timechanged++;
1928 hr_clock_unlock(spl);
1929 callout_hrestime();
1930 }
|