implement cpu idle via sigsuspenddiff -r1.52 -r1.53 src/sys/arch/usermode/dev/cpu.c
(jmcneill)
--- src/sys/arch/usermode/dev/cpu.c 2011/12/14 12:29:59 1.52
+++ src/sys/arch/usermode/dev/cpu.c 2011/12/15 00:40:03 1.53
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: cpu.c,v 1.52 2011/12/14 12:29:59 jmcneill Exp $ */ | 1 | /* $NetBSD: cpu.c,v 1.53 2011/12/15 00:40:03 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | 4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -20,27 +20,27 @@ | @@ -20,27 +20,27 @@ | |||
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | 26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #include "opt_cpu.h" | 29 | #include "opt_cpu.h" | |
30 | #include "opt_hz.h" | 30 | #include "opt_hz.h" | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.52 2011/12/14 12:29:59 jmcneill Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.53 2011/12/15 00:40:03 jmcneill Exp $"); | |
34 | 34 | |||
35 | #include <sys/param.h> | 35 | #include <sys/param.h> | |
36 | #include <sys/conf.h> | 36 | #include <sys/conf.h> | |
37 | #include <sys/proc.h> | 37 | #include <sys/proc.h> | |
38 | #include <sys/systm.h> | 38 | #include <sys/systm.h> | |
39 | #include <sys/device.h> | 39 | #include <sys/device.h> | |
40 | #include <sys/reboot.h> | 40 | #include <sys/reboot.h> | |
41 | #include <sys/lwp.h> | 41 | #include <sys/lwp.h> | |
42 | #include <sys/cpu.h> | 42 | #include <sys/cpu.h> | |
43 | #include <sys/mbuf.h> | 43 | #include <sys/mbuf.h> | |
44 | #include <sys/msgbuf.h> | 44 | #include <sys/msgbuf.h> | |
45 | 45 | |||
46 | #include <dev/cons.h> | 46 | #include <dev/cons.h> | |
@@ -237,29 +237,27 @@ cpu_setmcontext(struct lwp *l, const mco | @@ -237,29 +237,27 @@ cpu_setmcontext(struct lwp *l, const mco | |||
237 | dprintf_debug("cpu_setmcontext\n"); | 237 | dprintf_debug("cpu_setmcontext\n"); | |
238 | #endif | 238 | #endif | |
239 | return 0; | 239 | return 0; | |
240 | } | 240 | } | |
241 | 241 | |||
242 | void | 242 | void | |
243 | cpu_idle(void) | 243 | cpu_idle(void) | |
244 | { | 244 | { | |
245 | struct cpu_info *ci = curcpu(); | 245 | struct cpu_info *ci = curcpu(); | |
246 | 246 | |||
247 | if (ci->ci_want_resched) | 247 | if (ci->ci_want_resched) | |
248 | return; | 248 | return; | |
249 | 249 | |||
250 | #if notyet | 250 | thunk_idle(); | |
251 | thunk_usleep(10000); | |||
252 | #endif | |||
253 | } | 251 | } | |
254 | 252 | |||
255 | void | 253 | void | |
256 | cpu_lwp_free(struct lwp *l, int proc) | 254 | cpu_lwp_free(struct lwp *l, int proc) | |
257 | { | 255 | { | |
258 | #ifdef CPU_DEBUG | 256 | #ifdef CPU_DEBUG | |
259 | dprintf_debug("cpu_lwp_free (dummy)\n"); | 257 | dprintf_debug("cpu_lwp_free (dummy)\n"); | |
260 | #endif | 258 | #endif | |
261 | } | 259 | } | |
262 | 260 | |||
263 | void | 261 | void | |
264 | cpu_lwp_free2(struct lwp *l) | 262 | cpu_lwp_free2(struct lwp *l) | |
265 | { | 263 | { |
--- src/sys/arch/usermode/include/thunk.h 2011/12/12 16:39:16 1.37
+++ src/sys/arch/usermode/include/thunk.h 2011/12/15 00:40:03 1.38
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: thunk.h,v 1.37 2011/12/12 16:39:16 jmcneill Exp $ */ | 1 | /* $NetBSD: thunk.h,v 1.38 2011/12/15 00:40:03 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> | 4 | * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -120,21 +120,23 @@ int thunk_atexit(void (*function)(void)) | @@ -120,21 +120,23 @@ int thunk_atexit(void (*function)(void)) | |||
120 | int thunk_aio_read(struct aiocb *); | 120 | int thunk_aio_read(struct aiocb *); | |
121 | int thunk_aio_write(struct aiocb *); | 121 | int thunk_aio_write(struct aiocb *); | |
122 | int thunk_aio_error(const struct aiocb *); | 122 | int thunk_aio_error(const struct aiocb *); | |
123 | int thunk_aio_return(struct aiocb *); | 123 | int thunk_aio_return(struct aiocb *); | |
124 | 124 | |||
125 | void * thunk_malloc(size_t len); | 125 | void * thunk_malloc(size_t len); | |
126 | void thunk_free(void *addr); | 126 | void thunk_free(void *addr); | |
127 | void * thunk_sbrk(intptr_t len); | 127 | void * thunk_sbrk(intptr_t len); | |
128 | void * thunk_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset); | 128 | void * thunk_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset); | |
129 | int thunk_munmap(void *addr, size_t len); | 129 | int thunk_munmap(void *addr, size_t len); | |
130 | int thunk_mprotect(void *addr, size_t len, int prot); | 130 | int thunk_mprotect(void *addr, size_t len, int prot); | |
131 | int thunk_posix_memalign(void **, size_t, size_t); | 131 | int thunk_posix_memalign(void **, size_t, size_t); | |
132 | 132 | |||
133 | int thunk_idle(void); | |||
134 | ||||
133 | char * thunk_getenv(const char *); | 135 | char * thunk_getenv(const char *); | |
134 | vaddr_t thunk_get_vm_min_address(void); | 136 | vaddr_t thunk_get_vm_min_address(void); | |
135 | 137 | |||
136 | int thunk_sdl_init(unsigned int, unsigned int, unsigned short); | 138 | int thunk_sdl_init(unsigned int, unsigned int, unsigned short); | |
137 | void * thunk_sdl_getfb(size_t); | 139 | void * thunk_sdl_getfb(size_t); | |
138 | int thunk_sdl_getchar(void); | 140 | int thunk_sdl_getchar(void); | |
139 | 141 | |||
140 | #endif /* !_ARCH_USERMODE_INCLUDE_THUNK_H */ | 142 | #endif /* !_ARCH_USERMODE_INCLUDE_THUNK_H */ |
--- src/sys/arch/usermode/usermode/thunk.c 2011/12/13 22:22:08 1.43
+++ src/sys/arch/usermode/usermode/thunk.c 2011/12/15 00:40:03 1.44
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: thunk.c,v 1.43 2011/12/13 22:22:08 jmcneill Exp $ */ | 1 | /* $NetBSD: thunk.c,v 1.44 2011/12/15 00:40:03 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> | 4 | * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -18,39 +18,40 @@ | @@ -18,39 +18,40 @@ | |||
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | 26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #include <sys/cdefs.h> | 29 | #include <sys/cdefs.h> | |
30 | #ifdef __NetBSD__ | 30 | #ifdef __NetBSD__ | |
31 | __RCSID("$NetBSD: thunk.c,v 1.43 2011/12/13 22:22:08 jmcneill Exp $"); | 31 | __RCSID("$NetBSD: thunk.c,v 1.44 2011/12/15 00:40:03 jmcneill Exp $"); | |
32 | #endif | 32 | #endif | |
33 | 33 | |||
34 | #include <sys/types.h> | 34 | #include <sys/types.h> | |
35 | #include <sys/mman.h> | 35 | #include <sys/mman.h> | |
36 | #include <sys/reboot.h> | 36 | #include <sys/reboot.h> | |
37 | #include <sys/poll.h> | 37 | #include <sys/poll.h> | |
38 | #include <machine/vmparam.h> | 38 | #include <machine/vmparam.h> | |
39 | 39 | |||
40 | #include <aio.h> | 40 | #include <aio.h> | |
41 | #include <assert.h> | 41 | #include <assert.h> | |
42 | #include <errno.h> | 42 | #include <errno.h> | |
43 | #include <fcntl.h> | 43 | #include <fcntl.h> | |
44 | #include <sched.h> | |||
44 | #include <stdarg.h> | 45 | #include <stdarg.h> | |
45 | #include <stdint.h> | 46 | #include <stdint.h> | |
46 | #include <stdio.h> | 47 | #include <stdio.h> | |
47 | #include <stdlib.h> | 48 | #include <stdlib.h> | |
48 | #include <signal.h> | 49 | #include <signal.h> | |
49 | #include <string.h> | 50 | #include <string.h> | |
50 | #include <termios.h> | 51 | #include <termios.h> | |
51 | #include <time.h> | 52 | #include <time.h> | |
52 | #include <ucontext.h> | 53 | #include <ucontext.h> | |
53 | #include <unistd.h> | 54 | #include <unistd.h> | |
54 | 55 | |||
55 | #include "../include/thunk.h" | 56 | #include "../include/thunk.h" | |
56 | 57 | |||
@@ -576,13 +577,22 @@ thunk_posix_memalign(void **ptr, size_t | @@ -576,13 +577,22 @@ thunk_posix_memalign(void **ptr, size_t | |||
576 | 577 | |||
577 | char * | 578 | char * | |
578 | thunk_getenv(const char *name) | 579 | thunk_getenv(const char *name) | |
579 | { | 580 | { | |
580 | return getenv(name); | 581 | return getenv(name); | |
581 | } | 582 | } | |
582 | 583 | |||
583 | vaddr_t | 584 | vaddr_t | |
584 | thunk_get_vm_min_address(void) | 585 | thunk_get_vm_min_address(void) | |
585 | { | 586 | { | |
586 | return VM_MIN_ADDRESS; | 587 | return VM_MIN_ADDRESS; | |
587 | } | 588 | } | |
588 | 589 | |||
590 | int | |||
591 | thunk_idle(void) | |||
592 | { | |||
593 | sigset_t sigmask; | |||
594 | ||||
595 | sigemptyset(&sigmask); | |||
596 | ||||
597 | return sigsuspend(&sigmask); | |||
598 | } |