1 /* $NetBSD: alloc.c,v 1.1 2010/06/14 21:06:09 pooka Exp $ */
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: alloc.c,v 1.1 2010/06/14 21:06:09 pooka Exp $");
35 #include <sys/param.h>
36 #include <sys/condvar.h>
38 #include <sys/kthread.h>
39 #include <sys/mutex.h>
45 #include <rump/rumpuser.h>
46 #include "kernspace.h"
48 static void *store
[32];
49 static struct pool pp1
, pp2
;
52 static kcondvar_t kcv
;
68 /* try to guarantee that the sleep is triggered in PR_WAITOK */
69 while ((kernel_map
->flags
& VM_MAP_WANTVA
) == 0)
70 kpause("take5", false, 1, NULL
);
72 for (i
= 0; i
< __arraycount(store
); i
++) {
73 pool_put(&pp1
, store
[i
]);
80 rumptest_alloc(size_t thelimit
)
85 mutex_init(&mtx
, MUTEX_DEFAULT
, IPL_NONE
);
86 cv_init(&kcv
, "venailu");
88 kthread_create(PRI_NONE
, KTHREAD_MPSAFE
, NULL
, hthr
, NULL
, NULL
, "h");
90 pool_init(&pp1
, 1024, 0, 0, 0, "vara-allas",
91 &pool_allocator_nointr
, IPL_NONE
);
92 pool_init(&pp2
, 1024, 0, 0, 0, "allas",
93 &pool_allocator_nointr
, IPL_NONE
);
95 for (i
= 0; i
< __arraycount(store
); i
++) {
96 store
[i
] = pool_get(&pp1
, PR_NOWAIT
);
97 if (store
[i
] == NULL
) {
98 panic("pool_get store failed");
102 /* wait until other thread runs */
108 for (succ
= 0;; succ
++) {
109 if (succ
* 1024 > thelimit
)
110 panic("managed to allocate over limit");
111 if ((c
= pool_get(&pp2
, PR_NOWAIT
)) == NULL
) {
116 if (pool_get(&pp2
, PR_WAITOK
) == NULL
)
117 panic("pool get PR_WAITOK failed");