xref: /netbsd-src/regress/sys/uvm/pdsim/pdsim.h (revision dbdfc1f67718729a46cdc36c25659089c7795e78)
1 /*	$NetBSD: pdsim.h,v 1.1 2006/10/09 12:32:46 yamt Exp $	*/
2 
3 /*-
4  * Copyright (c)2006 YAMAMOTO Takashi,
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <sys/null.h>
30 #include <sys/hash.h>
31 #include <sys/queue.h>
32 #include <assert.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdarg.h>
37 #include <inttypes.h>
38 
39 #define	PAGE_SHIFT	12
40 #define	PAGE_SIZE	(1 << PAGE_SHIFT)
41 #define	PAGE_MASK	(PAGE_SIZE - 1)
42 
43 #define	PDPOL_EVCNT_DEFINE(name)	int pdpol_evcnt_##name = 0;
44 #define	PDPOL_EVCNT_INCR(ev)		pdpol_evcnt_##ev++
45 
46 #define	TRUE	1
47 #define	FALSE	0
48 typedef int boolean_t;
49 typedef off_t voff_t;
50 
51 struct vm_page;
52 struct vm_anon;
53 
54 struct uvm_object;
55 struct vm_anon {
56 	struct vm_page *an_page; /* XXX */
57 };
58 
59 struct vm_page {
60 	TAILQ_ENTRY(vm_page) pageq;
61 	struct uvm_object *uobject;
62 	off_t offset;
63 	int pqflags;
64 #define PQ_SWAPBACKED	(PQ_ANON|PQ_AOBJ)
65 #define PQ_FREE		0x0001
66 #define PQ_ANON		0x0002
67 #define PQ_AOBJ		0x0004
68 #define PQ_PRIVATE1	0x0100
69 #define PQ_PRIVATE2	0x0200
70 #define PQ_PRIVATE3	0x0400
71 #define PQ_PRIVATE4	0x0800
72 #define PQ_PRIVATE5	0x1000
73 #define PQ_PRIVATE6	0x2000
74 #define PQ_PRIVATE7	0x4000
75 #define PQ_PRIVATE8	0x8000
76 
77 	int _mdflags;
78 #define	MDPG_REFERENCED		1
79 #define	MDPG_SPECULATIVE	2
80 
81 	/* dummy members */
82 	struct vm_anon *uanon;
83 	int wire_count;
84 	int flags;
85 #define	PG_BUSY		1
86 };
87 
88 TAILQ_HEAD(pglist, vm_page);
89 
90 boolean_t pmap_clear_reference(struct vm_page *);
91 boolean_t pmap_is_referenced(struct vm_page *);
92 
93 struct uvmexp {
94 	int npages;
95 	int pdscans;
96 	int freetarg;
97 	int free;
98 
99 	/* XXX */
100 	int filepages;
101 	int execpages;
102 	int anonpages;
103 	int pddeact;
104 	int pdreact;
105 };
106 extern struct uvmexp uvmexp;
107 
108 #define	UVM_LOCK_ASSERT_PAGEQ()	/* nothing */
109 #define	KASSERT(x)	assert(x)
110 
111 static void panic(const char *, ...) __unused;
112 static void
panic(const char * fmt,...)113 panic(const char *fmt, ...)
114 {
115 	va_list ap;
116 
117 	va_start(ap, fmt);
118 	vfprintf(stderr, fmt, ap);
119 	va_end(ap);
120 	fprintf(stderr, "\n");
121 	abort();
122 }
123 
124 #define	MAXID	102400
125 
126 struct uvm_object {
127 	struct vm_page *pages[MAXID];
128 };
129 
130 struct uvm_pctparam {
131 	int pct_pct;
132 };
133 #define	UVM_PCTPARAM_APPLY(pct, x) \
134 	(((x) * (pct)->pct_pct) / 100)
135 #define	uvm_pctparam_init(pct, x, f)	(pct)->pct_pct = x
136 
137 #define	UVM_OBJ_IS_VTEXT(o)	FALSE
138 #define	UVM_OBJ_IS_AOBJ(o)	FALSE
139 #define	UVM_OBJ_IS_VNODE(o)	TRUE
140 
141 #define	uvm_swapisfull()	TRUE
142 #define	uvmpd_trydropswap(p)	(panic("dropswap"), 0)
143 
144 #define	MAX(a,b)	(((a) > (b)) ? (a) : (b))
145 #define	MIN(a,b)	(((a) < (b)) ? (a) : (b))
146 
147 #if ((__STDC_VERSION__ - 0) >= 199901L)
148 #define	WARN(...)	fprintf(stderr, __VA_ARGS__)
149 #else /* ((__STDC_VERSION__ - 0) >= 199901L) */
150 #define	WARN(a...)	fprintf(stderr, a)
151 #endif /* ((__STDC_VERSION__ - 0) >= 199901L) */
152 
153 #if defined(DEBUG)
154 #if ((__STDC_VERSION__ - 0) >= 199901L)
155 #define	DPRINTF(...)	printf(__VA_ARGS__)
156 #else /* ((__STDC_VERSION__ - 0) >= 199901L) */
157 #define	DPRINTF(a...)	printf(a)	/* GCC */
158 #endif /* ((__STDC_VERSION__ - 0) >= 199901L) */
159 #define	dump(s)		pdsim_dump(s)
160 void dump(const char *);
161 #else
162 #if ((__STDC_VERSION__ - 0) >= 199901L)
163 #define	DPRINTF(...)	/* nothing */
164 #else /* ((__STDC_VERSION__ - 0) >= 199901L) */
165 #define	DPRINTF(a...)	/* nothing */	/* GCC */
166 #endif /* ((__STDC_VERSION__ - 0) >= 199901L) */
167 #define	dump(s)		/* nothing */
168 #endif
169 
170 #include "uvm/uvm_pdpolicy.h"
171