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
22 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
29 */
30
31 #include <sys/timer.h>
32 #include <sys/systm.h>
33 #include <sys/param.h>
34 #include <sys/kmem.h>
35 #include <sys/debug.h>
36 #include <sys/policy.h>
37 #include <sys/port_impl.h>
38 #include <sys/port_kernel.h>
39 #include <sys/contract/process_impl.h>
40
41 static kmem_cache_t *clock_timer_cache;
42 static clock_backend_t *clock_backend[CLOCK_MAX];
43 static int timer_port_callback(void *, int *, pid_t, int, void *);
44 static void timer_close_port(void *, int, pid_t, int);
45
46 #define CLOCK_BACKEND(clk) \
47 ((clk) < CLOCK_MAX && (clk) >= 0 ? clock_backend[(clk)] : NULL)
48
49 /*
50 * Tunable to increase the maximum number of POSIX timers per-process. This
51 * may _only_ be tuned in /etc/system or by patching the kernel binary; it
52 * _cannot_ be tuned on a running system.
53 */
54 int timer_max = _TIMER_MAX;
55
56 /*
57 * timer_lock() locks the specified interval timer. It doesn't look at the
58 * ITLK_REMOVE bit; it's up to callers to look at this if they need to
59 * care. p_lock must be held on entry; it may be dropped and reaquired,
60 * but timer_lock() will always return with p_lock held.
61 *
62 * Note that timer_create() doesn't call timer_lock(); it creates timers
63 * with the ITLK_LOCKED bit explictly set.
64 */
65 static void
66 timer_lock(proc_t *p, itimer_t *it)
67 {
68 ASSERT(MUTEX_HELD(&p->p_lock));
69
70 while (it->it_lock & ITLK_LOCKED) {
71 it->it_blockers++;
72 cv_wait(&it->it_cv, &p->p_lock);
73 it->it_blockers--;
74 }
|
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
22 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
29 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
30 */
31
32 #include <sys/timer.h>
33 #include <sys/systm.h>
34 #include <sys/param.h>
35 #include <sys/kmem.h>
36 #include <sys/debug.h>
37 #include <sys/policy.h>
38 #include <sys/port_impl.h>
39 #include <sys/port_kernel.h>
40 #include <sys/contract/process_impl.h>
41
42 static kmem_cache_t *clock_timer_cache;
43 static clock_backend_t *clock_backend[CLOCK_MAX];
44 static int timer_port_callback(void *, int *, pid_t, int, void *);
45 static void timer_close_port(void *, int, pid_t, int);
46
47 #define CLOCK_BACKEND(clk) \
48 ((clk) < CLOCK_MAX && (clk) >= 0 ? clock_backend[(clk)] : NULL)
49
50 /*
51 * Tunable to increase the maximum number of POSIX timers per-process. This
52 * may _only_ be tuned in /etc/system or by patching the kernel binary; it
53 * _cannot_ be tuned on a running system.
54 */
55 volatile int timer_max = _TIMER_MAX;
56
57 /*
58 * timer_lock() locks the specified interval timer. It doesn't look at the
59 * ITLK_REMOVE bit; it's up to callers to look at this if they need to
60 * care. p_lock must be held on entry; it may be dropped and reaquired,
61 * but timer_lock() will always return with p_lock held.
62 *
63 * Note that timer_create() doesn't call timer_lock(); it creates timers
64 * with the ITLK_LOCKED bit explictly set.
65 */
66 static void
67 timer_lock(proc_t *p, itimer_t *it)
68 {
69 ASSERT(MUTEX_HELD(&p->p_lock));
70
71 while (it->it_lock & ITLK_LOCKED) {
72 it->it_blockers++;
73 cv_wait(&it->it_cv, &p->p_lock);
74 it->it_blockers--;
75 }
|