17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27c48ec423SBryan Cantrill /*
28c48ec423SBryan Cantrill * Copyright (c) 2012, Joyent Inc. All rights reserved.
29c48ec423SBryan Cantrill */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #include <sys/timer.h>
327c478bd9Sstevel@tonic-gate #include <sys/systm.h>
337c478bd9Sstevel@tonic-gate #include <sys/param.h>
347c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
357c478bd9Sstevel@tonic-gate #include <sys/debug.h>
367c478bd9Sstevel@tonic-gate #include <sys/cyclic.h>
377c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
387c478bd9Sstevel@tonic-gate #include <sys/pset.h>
397c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
407c478bd9Sstevel@tonic-gate #include <sys/policy.h>
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate static clock_backend_t clock_highres;
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate /*ARGSUSED*/
457c478bd9Sstevel@tonic-gate static int
clock_highres_settime(timespec_t * ts)467c478bd9Sstevel@tonic-gate clock_highres_settime(timespec_t *ts)
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate return (EINVAL);
497c478bd9Sstevel@tonic-gate }
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate static int
clock_highres_gettime(timespec_t * ts)527c478bd9Sstevel@tonic-gate clock_highres_gettime(timespec_t *ts)
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate hrt2ts(gethrtime(), (timestruc_t *)ts);
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate return (0);
577c478bd9Sstevel@tonic-gate }
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate static int
clock_highres_getres(timespec_t * ts)607c478bd9Sstevel@tonic-gate clock_highres_getres(timespec_t *ts)
617c478bd9Sstevel@tonic-gate {
627c478bd9Sstevel@tonic-gate hrt2ts(cyclic_getres(), (timestruc_t *)ts);
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate return (0);
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate /*ARGSUSED*/
687c478bd9Sstevel@tonic-gate static int
clock_highres_timer_create(itimer_t * it,struct sigevent * ev)697c478bd9Sstevel@tonic-gate clock_highres_timer_create(itimer_t *it, struct sigevent *ev)
707c478bd9Sstevel@tonic-gate {
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate * CLOCK_HIGHRES timers of sufficiently high resolution can deny
737c478bd9Sstevel@tonic-gate * service; only allow privileged users to create such timers.
747c478bd9Sstevel@tonic-gate * Sites that do not wish to have this restriction should
757c478bd9Sstevel@tonic-gate * give users the "proc_clock_highres" privilege.
767c478bd9Sstevel@tonic-gate */
777c478bd9Sstevel@tonic-gate if (secpolicy_clock_highres(CRED()) != 0) {
787c478bd9Sstevel@tonic-gate it->it_arg = NULL;
797c478bd9Sstevel@tonic-gate return (EPERM);
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate it->it_arg = kmem_zalloc(sizeof (cyclic_id_t), KM_SLEEP);
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate return (0);
857c478bd9Sstevel@tonic-gate }
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate static void
clock_highres_fire(void * arg)887c478bd9Sstevel@tonic-gate clock_highres_fire(void *arg)
897c478bd9Sstevel@tonic-gate {
907c478bd9Sstevel@tonic-gate itimer_t *it = (itimer_t *)arg;
917c478bd9Sstevel@tonic-gate hrtime_t *addr = &it->it_hrtime;
927c478bd9Sstevel@tonic-gate hrtime_t old = *addr, new = gethrtime();
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate do {
957c478bd9Sstevel@tonic-gate old = *addr;
96*75d94465SJosef 'Jeff' Sipek } while (atomic_cas_64((uint64_t *)addr, old, new) != old);
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate timer_fire(it);
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate static int
clock_highres_timer_settime(itimer_t * it,int flags,const struct itimerspec * when)1027c478bd9Sstevel@tonic-gate clock_highres_timer_settime(itimer_t *it, int flags,
1037c478bd9Sstevel@tonic-gate const struct itimerspec *when)
1047c478bd9Sstevel@tonic-gate {
1057c478bd9Sstevel@tonic-gate cyclic_id_t cyc, *cycp = it->it_arg;
1067c478bd9Sstevel@tonic-gate proc_t *p = curproc;
1077c478bd9Sstevel@tonic-gate kthread_t *t = curthread;
1087c478bd9Sstevel@tonic-gate cyc_time_t cyctime;
1097c478bd9Sstevel@tonic-gate cyc_handler_t hdlr;
1107c478bd9Sstevel@tonic-gate cpu_t *cpu;
1117c478bd9Sstevel@tonic-gate cpupart_t *cpupart;
1127c478bd9Sstevel@tonic-gate int pset;
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate cyctime.cyt_when = ts2hrt(&when->it_value);
1157c478bd9Sstevel@tonic-gate cyctime.cyt_interval = ts2hrt(&when->it_interval);
1167c478bd9Sstevel@tonic-gate
117c48ec423SBryan Cantrill if (cyctime.cyt_when != 0 && cyctime.cyt_interval == 0 &&
118c48ec423SBryan Cantrill it->it_itime.it_interval.tv_sec == 0 &&
119c48ec423SBryan Cantrill it->it_itime.it_interval.tv_nsec == 0 &&
120c48ec423SBryan Cantrill (cyc = *cycp) != CYCLIC_NONE) {
121c48ec423SBryan Cantrill /*
122c48ec423SBryan Cantrill * If our existing timer is a one-shot and our new timer is a
123c48ec423SBryan Cantrill * one-shot, we'll save ourselves a world of grief and just
124c48ec423SBryan Cantrill * reprogram the cyclic.
125c48ec423SBryan Cantrill */
126c48ec423SBryan Cantrill it->it_itime = *when;
127c48ec423SBryan Cantrill
128c48ec423SBryan Cantrill if (!(flags & TIMER_ABSTIME))
129c48ec423SBryan Cantrill cyctime.cyt_when += gethrtime();
130c48ec423SBryan Cantrill
131c48ec423SBryan Cantrill hrt2ts(cyctime.cyt_when, &it->it_itime.it_value);
132c48ec423SBryan Cantrill (void) cyclic_reprogram(cyc, cyctime.cyt_when);
133c48ec423SBryan Cantrill return (0);
134c48ec423SBryan Cantrill }
135c48ec423SBryan Cantrill
1367c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock);
1377c478bd9Sstevel@tonic-gate if ((cyc = *cycp) != CYCLIC_NONE) {
1387c478bd9Sstevel@tonic-gate cyclic_remove(cyc);
1397c478bd9Sstevel@tonic-gate *cycp = CYCLIC_NONE;
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate if (cyctime.cyt_when == 0) {
1437c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock);
1447c478bd9Sstevel@tonic-gate return (0);
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate if (!(flags & TIMER_ABSTIME))
1487c478bd9Sstevel@tonic-gate cyctime.cyt_when += gethrtime();
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate * Now we will check for overflow (that is, we will check to see
1527c478bd9Sstevel@tonic-gate * that the start time plus the interval time doesn't exceed
1537c478bd9Sstevel@tonic-gate * INT64_MAX). The astute code reviewer will observe that this
1547c478bd9Sstevel@tonic-gate * one-time check doesn't guarantee that a future expiration
1557c478bd9Sstevel@tonic-gate * will not wrap. We wish to prove, then, that if a future
1567c478bd9Sstevel@tonic-gate * expiration does wrap, the earliest the problem can be encountered
1577c478bd9Sstevel@tonic-gate * is (INT64_MAX / 2) nanoseconds (191 years) after boot. Formally:
1587c478bd9Sstevel@tonic-gate *
1597c478bd9Sstevel@tonic-gate * Given: s + i < m s > 0 i > 0
1607c478bd9Sstevel@tonic-gate * s + ni > m n > 1
1617c478bd9Sstevel@tonic-gate *
1627c478bd9Sstevel@tonic-gate * (where "s" is the start time, "i" is the interval, "n" is the
1637c478bd9Sstevel@tonic-gate * number of times the cyclic has fired and "m" is INT64_MAX)
1647c478bd9Sstevel@tonic-gate *
1657c478bd9Sstevel@tonic-gate * Prove:
1667c478bd9Sstevel@tonic-gate * (a) s + (n - 1)i > (m / 2)
1677c478bd9Sstevel@tonic-gate * (b) s + (n - 1)i < m
1687c478bd9Sstevel@tonic-gate *
1697c478bd9Sstevel@tonic-gate * That is, prove that we must have fired at least once 191 years
1707c478bd9Sstevel@tonic-gate * after boot. The proof is very straightforward; since the left
1717c478bd9Sstevel@tonic-gate * side of (a) is minimized when i is small, it is sufficient to show
1727c478bd9Sstevel@tonic-gate * that the statement is true for i's smallest possible value
1737c478bd9Sstevel@tonic-gate * (((m - s) / n) + epsilon). The same goes for (b); showing that the
1747c478bd9Sstevel@tonic-gate * statement is true for i's largest possible value (m - s + epsilon)
1757c478bd9Sstevel@tonic-gate * is sufficient to prove the statement.
1767c478bd9Sstevel@tonic-gate *
1777c478bd9Sstevel@tonic-gate * The actual arithmetic manipulation is left up to reader.
1787c478bd9Sstevel@tonic-gate */
1797c478bd9Sstevel@tonic-gate if (cyctime.cyt_when > INT64_MAX - cyctime.cyt_interval) {
1807c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock);
1817c478bd9Sstevel@tonic-gate return (EOVERFLOW);
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate if (cyctime.cyt_interval == 0) {
1857c478bd9Sstevel@tonic-gate /*
186c48ec423SBryan Cantrill * If this is a one-shot, then we set the interval to be
187c48ec423SBryan Cantrill * inifinite. If this timer is never touched, this cyclic will
188c48ec423SBryan Cantrill * simply consume space in the cyclic subsystem. As soon as
1897c478bd9Sstevel@tonic-gate * timer_settime() or timer_delete() is called, the cyclic is
1907c478bd9Sstevel@tonic-gate * removed (so it's not possible to run the machine out
1917c478bd9Sstevel@tonic-gate * of resources by creating one-shots).
1927c478bd9Sstevel@tonic-gate */
193c48ec423SBryan Cantrill cyctime.cyt_interval = CY_INFINITY;
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate it->it_itime = *when;
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate hrt2ts(cyctime.cyt_when, &it->it_itime.it_value);
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate hdlr.cyh_func = (cyc_func_t)clock_highres_fire;
2017c478bd9Sstevel@tonic-gate hdlr.cyh_arg = it;
2027c478bd9Sstevel@tonic-gate hdlr.cyh_level = CY_LOW_LEVEL;
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate if (cyctime.cyt_when != 0)
2057c478bd9Sstevel@tonic-gate *cycp = cyc = cyclic_add(&hdlr, &cyctime);
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate * Now that we have the cyclic created, we need to bind it to our
2097c478bd9Sstevel@tonic-gate * bound CPU and processor set (if any).
2107c478bd9Sstevel@tonic-gate */
2117c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock);
2127c478bd9Sstevel@tonic-gate cpu = t->t_bound_cpu;
2137c478bd9Sstevel@tonic-gate cpupart = t->t_cpupart;
2147c478bd9Sstevel@tonic-gate pset = t->t_bind_pset;
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock);
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate cyclic_bind(cyc, cpu, pset == PS_NONE ? NULL : cpupart);
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock);
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate return (0);
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate static int
clock_highres_timer_gettime(itimer_t * it,struct itimerspec * when)2267c478bd9Sstevel@tonic-gate clock_highres_timer_gettime(itimer_t *it, struct itimerspec *when)
2277c478bd9Sstevel@tonic-gate {
2287c478bd9Sstevel@tonic-gate /*
2297c478bd9Sstevel@tonic-gate * CLOCK_HIGHRES doesn't update it_itime.
2307c478bd9Sstevel@tonic-gate */
2317c478bd9Sstevel@tonic-gate hrtime_t start = ts2hrt(&it->it_itime.it_value);
2327c478bd9Sstevel@tonic-gate hrtime_t interval = ts2hrt(&it->it_itime.it_interval);
2337c478bd9Sstevel@tonic-gate hrtime_t diff, now = gethrtime();
2347c478bd9Sstevel@tonic-gate hrtime_t *addr = &it->it_hrtime;
2357c478bd9Sstevel@tonic-gate hrtime_t last;
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate /*
238*75d94465SJosef 'Jeff' Sipek * We're using atomic_cas_64() here only to assure that we slurp the
239*75d94465SJosef 'Jeff' Sipek * entire timestamp atomically.
2407c478bd9Sstevel@tonic-gate */
241*75d94465SJosef 'Jeff' Sipek last = atomic_cas_64((uint64_t *)addr, 0, 0);
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate *when = it->it_itime;
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate if (!timerspecisset(&when->it_value))
2467c478bd9Sstevel@tonic-gate return (0);
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate if (start > now) {
2497c478bd9Sstevel@tonic-gate /*
2507c478bd9Sstevel@tonic-gate * We haven't gone off yet...
2517c478bd9Sstevel@tonic-gate */
2527c478bd9Sstevel@tonic-gate diff = start - now;
2537c478bd9Sstevel@tonic-gate } else {
2547c478bd9Sstevel@tonic-gate if (interval == 0) {
2557c478bd9Sstevel@tonic-gate /*
2567c478bd9Sstevel@tonic-gate * This is a one-shot which should have already
2577c478bd9Sstevel@tonic-gate * fired; set it_value to 0.
2587c478bd9Sstevel@tonic-gate */
2597c478bd9Sstevel@tonic-gate timerspecclear(&when->it_value);
2607c478bd9Sstevel@tonic-gate return (0);
2617c478bd9Sstevel@tonic-gate }
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate /*
2647c478bd9Sstevel@tonic-gate * Calculate how far we are into this interval.
2657c478bd9Sstevel@tonic-gate */
2667c478bd9Sstevel@tonic-gate diff = (now - start) % interval;
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate /*
2697c478bd9Sstevel@tonic-gate * Now check to see if we've dealt with the last interval
2707c478bd9Sstevel@tonic-gate * yet.
2717c478bd9Sstevel@tonic-gate */
2727c478bd9Sstevel@tonic-gate if (now - diff > last) {
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate * The last interval hasn't fired; set it_value to 0.
2757c478bd9Sstevel@tonic-gate */
2767c478bd9Sstevel@tonic-gate timerspecclear(&when->it_value);
2777c478bd9Sstevel@tonic-gate return (0);
2787c478bd9Sstevel@tonic-gate }
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate /*
2817c478bd9Sstevel@tonic-gate * The last interval _has_ fired; we can return the amount
2827c478bd9Sstevel@tonic-gate * of time left in this interval.
2837c478bd9Sstevel@tonic-gate */
2847c478bd9Sstevel@tonic-gate diff = interval - diff;
2857c478bd9Sstevel@tonic-gate }
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gate hrt2ts(diff, &when->it_value);
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate return (0);
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate static int
clock_highres_timer_delete(itimer_t * it)2937c478bd9Sstevel@tonic-gate clock_highres_timer_delete(itimer_t *it)
2947c478bd9Sstevel@tonic-gate {
2957c478bd9Sstevel@tonic-gate cyclic_id_t cyc;
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate if (it->it_arg == NULL) {
2987c478bd9Sstevel@tonic-gate /*
2997c478bd9Sstevel@tonic-gate * This timer was never fully created; we must have failed
3007c478bd9Sstevel@tonic-gate * in the clock_highres_timer_create() routine.
3017c478bd9Sstevel@tonic-gate */
3027c478bd9Sstevel@tonic-gate return (0);
3037c478bd9Sstevel@tonic-gate }
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock);
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate if ((cyc = *((cyclic_id_t *)it->it_arg)) != CYCLIC_NONE)
3087c478bd9Sstevel@tonic-gate cyclic_remove(cyc);
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock);
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate kmem_free(it->it_arg, sizeof (cyclic_id_t));
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate return (0);
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate static void
clock_highres_timer_lwpbind(itimer_t * it)3187c478bd9Sstevel@tonic-gate clock_highres_timer_lwpbind(itimer_t *it)
3197c478bd9Sstevel@tonic-gate {
3207c478bd9Sstevel@tonic-gate proc_t *p = curproc;
3217c478bd9Sstevel@tonic-gate kthread_t *t = curthread;
3227c478bd9Sstevel@tonic-gate cyclic_id_t cyc = *((cyclic_id_t *)it->it_arg);
3237c478bd9Sstevel@tonic-gate cpu_t *cpu;
3247c478bd9Sstevel@tonic-gate cpupart_t *cpupart;
3257c478bd9Sstevel@tonic-gate int pset;
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate if (cyc == CYCLIC_NONE)
3287c478bd9Sstevel@tonic-gate return;
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock);
3317c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock);
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate /*
3347c478bd9Sstevel@tonic-gate * Okay, now we can safely look at the bindings.
3357c478bd9Sstevel@tonic-gate */
3367c478bd9Sstevel@tonic-gate cpu = t->t_bound_cpu;
3377c478bd9Sstevel@tonic-gate cpupart = t->t_cpupart;
3387c478bd9Sstevel@tonic-gate pset = t->t_bind_pset;
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate /*
3417c478bd9Sstevel@tonic-gate * Now we drop p_lock. We haven't dropped cpu_lock; we're guaranteed
3427c478bd9Sstevel@tonic-gate * that even if the bindings change, the CPU and/or processor set
3437c478bd9Sstevel@tonic-gate * that this timer was bound to remain valid (and the combination
3447c478bd9Sstevel@tonic-gate * remains self-consistent).
3457c478bd9Sstevel@tonic-gate */
3467c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock);
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate cyclic_bind(cyc, cpu, pset == PS_NONE ? NULL : cpupart);
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock);
3517c478bd9Sstevel@tonic-gate }
3527c478bd9Sstevel@tonic-gate
3537c478bd9Sstevel@tonic-gate void
clock_highres_init()3547c478bd9Sstevel@tonic-gate clock_highres_init()
3557c478bd9Sstevel@tonic-gate {
3567c478bd9Sstevel@tonic-gate clock_backend_t *be = &clock_highres;
3577c478bd9Sstevel@tonic-gate struct sigevent *ev = &be->clk_default;
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate ev->sigev_signo = SIGALRM;
3607c478bd9Sstevel@tonic-gate ev->sigev_notify = SIGEV_SIGNAL;
3617c478bd9Sstevel@tonic-gate ev->sigev_value.sival_ptr = NULL;
3627c478bd9Sstevel@tonic-gate
3637c478bd9Sstevel@tonic-gate be->clk_clock_settime = clock_highres_settime;
3647c478bd9Sstevel@tonic-gate be->clk_clock_gettime = clock_highres_gettime;
3657c478bd9Sstevel@tonic-gate be->clk_clock_getres = clock_highres_getres;
3667c478bd9Sstevel@tonic-gate be->clk_timer_create = clock_highres_timer_create;
3677c478bd9Sstevel@tonic-gate be->clk_timer_gettime = clock_highres_timer_gettime;
3687c478bd9Sstevel@tonic-gate be->clk_timer_settime = clock_highres_timer_settime;
3697c478bd9Sstevel@tonic-gate be->clk_timer_delete = clock_highres_timer_delete;
3707c478bd9Sstevel@tonic-gate be->clk_timer_lwpbind = clock_highres_timer_lwpbind;
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate clock_add_backend(CLOCK_HIGHRES, &clock_highres);
3737c478bd9Sstevel@tonic-gate }
374