Thu Dec 15 00:40:03 2011 UTC ()
implement cpu idle via sigsuspend


(jmcneill)
diff -r1.52 -r1.53 src/sys/arch/usermode/dev/cpu.c
diff -r1.37 -r1.38 src/sys/arch/usermode/include/thunk.h
diff -r1.43 -r1.44 src/sys/arch/usermode/usermode/thunk.c

cvs diff -r1.52 -r1.53 src/sys/arch/usermode/dev/cpu.c (expand / switch to unified diff)

--- 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
242void 242void
243cpu_idle(void) 243cpu_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
255void 253void
256cpu_lwp_free(struct lwp *l, int proc) 254cpu_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
263void 261void
264cpu_lwp_free2(struct lwp *l) 262cpu_lwp_free2(struct lwp *l)
265{ 263{

cvs diff -r1.37 -r1.38 src/sys/arch/usermode/include/thunk.h (expand / switch to unified diff)

--- 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))
120int thunk_aio_read(struct aiocb *); 120int thunk_aio_read(struct aiocb *);
121int thunk_aio_write(struct aiocb *); 121int thunk_aio_write(struct aiocb *);
122int thunk_aio_error(const struct aiocb *); 122int thunk_aio_error(const struct aiocb *);
123int thunk_aio_return(struct aiocb *); 123int thunk_aio_return(struct aiocb *);
124 124
125void * thunk_malloc(size_t len); 125void * thunk_malloc(size_t len);
126void thunk_free(void *addr); 126void thunk_free(void *addr);
127void * thunk_sbrk(intptr_t len); 127void * thunk_sbrk(intptr_t len);
128void * thunk_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset); 128void * thunk_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset);
129int thunk_munmap(void *addr, size_t len); 129int thunk_munmap(void *addr, size_t len);
130int thunk_mprotect(void *addr, size_t len, int prot); 130int thunk_mprotect(void *addr, size_t len, int prot);
131int thunk_posix_memalign(void **, size_t, size_t); 131int thunk_posix_memalign(void **, size_t, size_t);
132 132
 133int thunk_idle(void);
 134
133char * thunk_getenv(const char *); 135char * thunk_getenv(const char *);
134vaddr_t thunk_get_vm_min_address(void); 136vaddr_t thunk_get_vm_min_address(void);
135 137
136int thunk_sdl_init(unsigned int, unsigned int, unsigned short); 138int thunk_sdl_init(unsigned int, unsigned int, unsigned short);
137void * thunk_sdl_getfb(size_t); 139void * thunk_sdl_getfb(size_t);
138int thunk_sdl_getchar(void); 140int thunk_sdl_getchar(void);
139 141
140#endif /* !_ARCH_USERMODE_INCLUDE_THUNK_H */ 142#endif /* !_ARCH_USERMODE_INCLUDE_THUNK_H */

cvs diff -r1.43 -r1.44 src/sys/arch/usermode/usermode/thunk.c (expand / switch to unified diff)

--- 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
577char * 578char *
578thunk_getenv(const char *name) 579thunk_getenv(const char *name)
579{ 580{
580 return getenv(name); 581 return getenv(name);
581} 582}
582 583
583vaddr_t 584vaddr_t
584thunk_get_vm_min_address(void) 585thunk_get_vm_min_address(void)
585{ 586{
586 return VM_MIN_ADDRESS; 587 return VM_MIN_ADDRESS;
587} 588}
588 589
 590int
 591thunk_idle(void)
 592{
 593 sigset_t sigmask;
 594
 595 sigemptyset(&sigmask);
 596
 597 return sigsuspend(&sigmask);
 598}