Skip to content

Commit 660331d

Browse files
brooksdavisbsdjhb
authored andcommitted
Centralize and simpify implemention of some VM macros
These macros have substantially identical implementations on each platform. Use roundup2/rounddown2 for round_page/trunc_page. This version standardizes on not using explicit casts and instead preserving the original type. A couple of tweaks were required to make this work. Reviewed by: brooks, kib, markj Obtained from: CheriBSD Differential Revision: https://reviews.freebsd.org/D48450
1 parent de11299 commit 660331d

File tree

10 files changed

+15
-48
lines changed

10 files changed

+15
-48
lines changed

sys/amd64/amd64/pmap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2499,7 +2499,7 @@ pmap_init(void)
24992499
ret = vm_page_blacklist_add(0x40000000 +
25002500
ptoa(i), false);
25012501
if (!ret && bootverbose)
2502-
printf("page at %#lx already used\n",
2502+
printf("page at %#x already used\n",
25032503
0x40000000 + ptoa(i));
25042504
}
25052505
}

sys/amd64/include/param.h

-7
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,13 @@
142142
/*
143143
* Mach derived conversion macros
144144
*/
145-
#define round_page(x) ((((unsigned long)(x)) + PAGE_MASK) & ~(PAGE_MASK))
146-
#define trunc_page(x) ((unsigned long)(x) & ~(PAGE_MASK))
147145
#define trunc_2mpage(x) ((unsigned long)(x) & ~PDRMASK)
148146
#define round_2mpage(x) ((((unsigned long)(x)) + PDRMASK) & ~PDRMASK)
149147
#define trunc_1gpage(x) ((unsigned long)(x) & ~PDPMASK)
150148

151-
#define atop(x) ((unsigned long)(x) >> PAGE_SHIFT)
152-
#define ptoa(x) ((unsigned long)(x) << PAGE_SHIFT)
153-
154149
#define amd64_btop(x) ((unsigned long)(x) >> PAGE_SHIFT)
155150
#define amd64_ptob(x) ((unsigned long)(x) << PAGE_SHIFT)
156151

157-
#define pgtok(x) ((unsigned long)(x) * (PAGE_SIZE / 1024))
158-
159152
#define INKERNEL(va) (((va) >= DMAP_MIN_ADDRESS && (va) < DMAP_MAX_ADDRESS) \
160153
|| ((va) >= VM_MIN_KERNEL_ADDRESS && (va) < VM_MAX_KERNEL_ADDRESS))
161154

sys/arm/arm/minidump_machdep.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
221221
if (error != 0)
222222
goto fail;
223223

224-
printf("Physical memory: %u MB\n", ptoa((uintmax_t)physmem) / 1048576);
224+
printf("Physical memory: %ju MB\n",
225+
ptoa((uintmax_t)physmem) / 1048576);
225226
printf("Dumping %llu MB:", (long long)dumpsize >> 20);
226227

227228
/* Dump my header */

sys/arm/include/param.h

-7
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,10 @@
123123
/*
124124
* Mach derived conversion macros
125125
*/
126-
#define trunc_page(x) ((x) & ~PAGE_MASK)
127-
#define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK)
128126
#define trunc_1mpage(x) ((unsigned)(x) & ~PDRMASK)
129127
#define round_1mpage(x) ((((unsigned)(x)) + PDRMASK) & ~PDRMASK)
130128

131-
#define atop(x) ((unsigned)(x) >> PAGE_SHIFT)
132-
#define ptoa(x) ((unsigned)(x) << PAGE_SHIFT)
133-
134129
#define arm32_btop(x) ((unsigned)(x) >> PAGE_SHIFT)
135130
#define arm32_ptob(x) ((unsigned)(x) << PAGE_SHIFT)
136131

137-
#define pgtok(x) ((x) * (PAGE_SIZE / 1024))
138-
139132
#endif /* !_ARM_INCLUDE_PARAM_H_ */

sys/arm64/include/param.h

-8
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,9 @@
119119
/*
120120
* Mach derived conversion macros
121121
*/
122-
#define round_page(x) (((unsigned long)(x) + PAGE_MASK) & ~PAGE_MASK)
123-
#define trunc_page(x) ((unsigned long)(x) & ~PAGE_MASK)
124-
125-
#define atop(x) ((unsigned long)(x) >> PAGE_SHIFT)
126-
#define ptoa(x) ((unsigned long)(x) << PAGE_SHIFT)
127-
128122
#define arm64_btop(x) ((unsigned long)(x) >> PAGE_SHIFT)
129123
#define arm64_ptob(x) ((unsigned long)(x) << PAGE_SHIFT)
130124

131-
#define pgtok(x) ((unsigned long)(x) * (PAGE_SIZE / 1024))
132-
133125
#endif /* !_MACHINE_PARAM_H_ */
134126

135127
#endif /* !__arm__ */

sys/i386/include/param.h

-7
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,12 @@
144144
/*
145145
* Mach derived conversion macros
146146
*/
147-
#define trunc_page(x) ((x) & ~PAGE_MASK)
148-
#define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK)
149147
#define trunc_4mpage(x) ((x) & ~PDRMASK)
150148
#define round_4mpage(x) ((((x)) + PDRMASK) & ~PDRMASK)
151149

152-
#define atop(x) ((x) >> PAGE_SHIFT)
153-
#define ptoa(x) ((x) << PAGE_SHIFT)
154-
155150
#define i386_btop(x) ((x) >> PAGE_SHIFT)
156151
#define i386_ptob(x) ((x) << PAGE_SHIFT)
157152

158-
#define pgtok(x) ((x) * (PAGE_SIZE / 1024))
159-
160153
#define INKERNEL(va) (TRUE)
161154

162155
#endif /* !_I386_INCLUDE_PARAM_H_ */

sys/powerpc/include/param.h

-7
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,13 @@
141141
/*
142142
* Mach derived conversion macros
143143
*/
144-
#define trunc_page(x) ((x) & ~(PAGE_MASK))
145-
#define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK)
146144
#define trunc_2mpage(x) ((unsigned long)(x) & ~L3_PAGE_MASK)
147145
#define round_2mpage(x) ((((unsigned long)(x)) + L3_PAGE_MASK) & ~L3_PAGE_MASK)
148146
#define trunc_1gpage(x) ((unsigned long)(x) & ~L2_PAGE_MASK)
149147

150-
#define atop(x) ((x) >> PAGE_SHIFT)
151-
#define ptoa(x) ((x) << PAGE_SHIFT)
152-
153148
#define powerpc_btop(x) ((x) >> PAGE_SHIFT)
154149
#define powerpc_ptob(x) ((x) << PAGE_SHIFT)
155150

156-
#define pgtok(x) ((x) * (PAGE_SIZE / 1024UL))
157-
158151
#define btoc(x) ((vm_offset_t)(((x)+PAGE_MASK)>>PAGE_SHIFT))
159152

160153
#endif /* !_POWERPC_INCLUDE_PARAM_H_ */

sys/riscv/include/param.h

-8
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,7 @@
9393
/*
9494
* Mach derived conversion macros
9595
*/
96-
#define round_page(x) (((unsigned long)(x) + PAGE_MASK) & ~PAGE_MASK)
97-
#define trunc_page(x) ((unsigned long)(x) & ~PAGE_MASK)
98-
99-
#define atop(x) ((unsigned long)(x) >> PAGE_SHIFT)
100-
#define ptoa(x) ((unsigned long)(x) << PAGE_SHIFT)
101-
10296
#define riscv_btop(x) ((unsigned long)(x) >> PAGE_SHIFT)
10397
#define riscv_ptob(x) ((unsigned long)(x) << PAGE_SHIFT)
10498

105-
#define pgtok(x) ((unsigned long)(x) * (PAGE_SIZE / 1024))
106-
10799
#endif /* !_MACHINE_PARAM_H_ */

sys/sys/param.h

+11
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,17 @@
200200
#define MJUM9BYTES (9 * 1024) /* jumbo cluster 9k */
201201
#define MJUM16BYTES (16 * 1024) /* jumbo cluster 16k */
202202

203+
/*
204+
* Mach derived conversion macros
205+
*/
206+
#define round_page(x) roundup2(x, PAGE_SIZE)
207+
#define trunc_page(x) rounddown2(x, PAGE_SIZE)
208+
209+
#define atop(x) ((x) >> PAGE_SHIFT)
210+
#define ptoa(x) ((x) << PAGE_SHIFT)
211+
212+
#define pgtok(x) ((x) * (PAGE_SIZE / 1024))
213+
203214
/*
204215
* Some macros for units conversion
205216
*/

usr.bin/systat/sysput.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@
2525
* SUCH DAMAGE.
2626
*/
2727

28-
#include <sys/types.h>
28+
#include <sys/param.h>
2929
#include <sys/sysctl.h>
3030

3131
#include <err.h>
3232
#include <inttypes.h>
3333
#include <libutil.h>
34-
#include <machine/param.h>
3534
#include <string.h>
3635

3736
#include "systat.h"

0 commit comments

Comments
 (0)