1 /* $NetBSD: test_callout1.c,v 1.2 2008/04/22 12:04:22 ad Exp $ */
4 * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: test_callout1.c,v 1.2 2008/04/22 12:04:22 ad Exp $");
35 #include <sys/param.h>
36 #include <sys/ioctl.h>
37 #include <sys/systm.h>
39 #include <sys/kthread.h>
40 #include <sys/kernel.h>
41 #include <sys/callout.h>
43 int testcall(struct lwp
*, void *, register_t
*);
45 void test_callout(void *);
46 void test_softint(void *);
55 test_callout(void *cookie
)
59 /* Trigger soft interrupt. */
61 softint_schedule(test_sih
);
64 mutex_enter(&test_mutex
);
66 cv_broadcast(&test_cv
);
67 mutex_exit(&test_mutex
);
71 test_softint(void *cookie
)
74 printf("l_ncsw = %d\n", (int)curlwp
->l_ncsw
);
75 callout_halt(&test_ch
, NULL
);
76 printf("l_ncsw = %d\n", (int)curlwp
->l_ncsw
);
80 testcall(struct lwp
*l
, void *uap
, register_t
*retval
)
83 printf("test: initializing\n");
85 mutex_init(&test_mutex
, MUTEX_DEFAULT
, IPL_NONE
);
86 cv_init(&test_cv
, "testcv");
87 test_sih
= softint_establish(SOFTINT_MPSAFE
| SOFTINT_SERIAL
,
89 callout_init(&test_ch
, CALLOUT_MPSAFE
);
90 callout_setfunc(&test_ch
, test_callout
, NULL
);
92 printf("test: firing\n");
93 callout_schedule(&test_ch
, hz
/ 10);
95 printf("test: waiting\n");
96 mutex_enter(&test_mutex
);
98 cv_wait(&test_cv
, &test_mutex
);
100 mutex_exit(&test_mutex
);
102 printf("test: finished\n");
104 callout_destroy(&test_ch
);
105 softint_disestablish(test_sih
);
106 mutex_destroy(&test_mutex
);
107 cv_destroy(&test_cv
);