From nobody Tue Jan 14 15:49:23 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YXYTc1F7Bz5kqD1; Tue, 14 Jan 2025 15:49:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YXYTb5sfDz3sRS; Tue, 14 Jan 2025 15:49:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736869763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FsBwwvdmbShOp3xkq5eEclm/ccvZ4hvrx5O9UiNgm3Y=; b=PXSNiDoO4f1CcAGOcvvYfrgHCWjqN5ZBFiO9reS9/JjyRsfvT0FGtW/eC9P7c1jlM0UKUg 081YGgad9cN3DHZgrlqfAvrO49b7u7dnLjO41RqObsoK9j1z1IOg+CYNpAuKKvAz7vABRX GlhMsgkXGXdxxzJBylLDrIuFIhiuctn/LlyxrbNbbsJYTWsRs3nhEpP9xnY/cbNadxkbcL 3lJYkLm8mOk34rXVwyVgDQYhjz/pUoczMWJEOwbwrLcrTYEr3DG24Y7NmyF9dD+jVgKg86 N4dBbfQCTTvC1DD+IhQzLCnnwuUNvaH8l2RlqcoawBkjusPP+LEU1UORlFI+oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736869763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FsBwwvdmbShOp3xkq5eEclm/ccvZ4hvrx5O9UiNgm3Y=; b=oED2HH47QJ+NxAZPyP3nFsRc82mspHuoizyhN4np9pN4pBfYPaDmWapROKqWP3eqFYM7ng njKfvUQBG+GyAouPQ7uEIrxkwWDv60vElrdW+MT9RAPd3WdVzrIPS4pBWPu6rp8qOzVq25 AJsIx983O/q5YRJnBe2WoQuWb6REHVwfunxlcGbCLPFugGBBrjov1cb5PdSK9WyX9XIM+q ytvcsUEjTDUGPqBfMjRH0dueq3BR7IQHjTTd/mkAEyYEoDtxDMK55dD8V5pXdCtNEs4DqK zvmyUej/w5MGh1kv/Rp+tDQisGjk+ycR5s1zMJkLPgd37Yq/OmvlCrhnarAF4g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736869763; a=rsa-sha256; cv=none; b=A46OeX7oeq10cQZK+2H+iafoBLSMjPx3e2YUo3aBLu1R8dZajv3zqX4M6huN2PqNW4/uDt xluXS6rYkr+dGxGsLbPaJjYo9DKSpsnV6mQG3XT71/GU2B4+kcahN9MHAoIkckoumtziNH yotVu3wS1wqupsJ7pGtIcaq9jGCuKnk/1yIlMcleQJFN/vwNXE6Z9Ec5UfrP4UH+GJGgVK PMHysTldJKCkfW8DKgrnHm9AwYoBE5AJz9mQEpuGisqqaEZdpOXyjpqU4dETX5xPutD65B 8wHElktCEuVM+sA/YsIo8CpF3uyWRH9exgiwMyMkxozWSyc0TJLOF3U8KimKmw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YXYTb5Jcvz1M9G; Tue, 14 Jan 2025 15:49:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50EFnNOY030058; Tue, 14 Jan 2025 15:49:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50EFnNxf030055; Tue, 14 Jan 2025 15:49:23 GMT (envelope-from git) Date: Tue, 14 Jan 2025 15:49:23 GMT Message-Id: <202501141549.50EFnNxf030055@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 660331da7a75 - main - Centralize and simpify implemention of some VM macros List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 660331da7a75e897ae9710c9933962d82f0a194c Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=660331da7a75e897ae9710c9933962d82f0a194c commit 660331da7a75e897ae9710c9933962d82f0a194c Author: Brooks Davis AuthorDate: 2025-01-14 15:48:07 +0000 Commit: John Baldwin CommitDate: 2025-01-14 15:48:07 +0000 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 --- sys/amd64/amd64/pmap.c | 2 +- sys/amd64/include/param.h | 7 ------- sys/arm/arm/minidump_machdep.c | 3 ++- sys/arm/include/param.h | 7 ------- sys/arm64/include/param.h | 8 -------- sys/i386/include/param.h | 7 ------- sys/powerpc/include/param.h | 7 ------- sys/riscv/include/param.h | 8 -------- sys/sys/param.h | 11 +++++++++++ usr.bin/systat/sysput.c | 3 +-- 10 files changed, 15 insertions(+), 48 deletions(-) diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c index 265d48e26c0b..5d31ad0dd495 100644 --- a/sys/amd64/amd64/pmap.c +++ b/sys/amd64/amd64/pmap.c @@ -2499,7 +2499,7 @@ pmap_init(void) ret = vm_page_blacklist_add(0x40000000 + ptoa(i), false); if (!ret && bootverbose) - printf("page at %#lx already used\n", + printf("page at %#x already used\n", 0x40000000 + ptoa(i)); } } diff --git a/sys/amd64/include/param.h b/sys/amd64/include/param.h index 8ad1c0e93c6a..371128c6fe20 100644 --- a/sys/amd64/include/param.h +++ b/sys/amd64/include/param.h @@ -142,20 +142,13 @@ /* * Mach derived conversion macros */ -#define round_page(x) ((((unsigned long)(x)) + PAGE_MASK) & ~(PAGE_MASK)) -#define trunc_page(x) ((unsigned long)(x) & ~(PAGE_MASK)) #define trunc_2mpage(x) ((unsigned long)(x) & ~PDRMASK) #define round_2mpage(x) ((((unsigned long)(x)) + PDRMASK) & ~PDRMASK) #define trunc_1gpage(x) ((unsigned long)(x) & ~PDPMASK) -#define atop(x) ((unsigned long)(x) >> PAGE_SHIFT) -#define ptoa(x) ((unsigned long)(x) << PAGE_SHIFT) - #define amd64_btop(x) ((unsigned long)(x) >> PAGE_SHIFT) #define amd64_ptob(x) ((unsigned long)(x) << PAGE_SHIFT) -#define pgtok(x) ((unsigned long)(x) * (PAGE_SIZE / 1024)) - #define INKERNEL(va) (((va) >= DMAP_MIN_ADDRESS && (va) < DMAP_MAX_ADDRESS) \ || ((va) >= VM_MIN_KERNEL_ADDRESS && (va) < VM_MAX_KERNEL_ADDRESS)) diff --git a/sys/arm/arm/minidump_machdep.c b/sys/arm/arm/minidump_machdep.c index 802b3184ed06..2e7fe6ebc51d 100644 --- a/sys/arm/arm/minidump_machdep.c +++ b/sys/arm/arm/minidump_machdep.c @@ -221,7 +221,8 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state) if (error != 0) goto fail; - printf("Physical memory: %u MB\n", ptoa((uintmax_t)physmem) / 1048576); + printf("Physical memory: %ju MB\n", + ptoa((uintmax_t)physmem) / 1048576); printf("Dumping %llu MB:", (long long)dumpsize >> 20); /* Dump my header */ diff --git a/sys/arm/include/param.h b/sys/arm/include/param.h index 3e1503e17709..03131ebcb436 100644 --- a/sys/arm/include/param.h +++ b/sys/arm/include/param.h @@ -123,17 +123,10 @@ /* * Mach derived conversion macros */ -#define trunc_page(x) ((x) & ~PAGE_MASK) -#define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK) #define trunc_1mpage(x) ((unsigned)(x) & ~PDRMASK) #define round_1mpage(x) ((((unsigned)(x)) + PDRMASK) & ~PDRMASK) -#define atop(x) ((unsigned)(x) >> PAGE_SHIFT) -#define ptoa(x) ((unsigned)(x) << PAGE_SHIFT) - #define arm32_btop(x) ((unsigned)(x) >> PAGE_SHIFT) #define arm32_ptob(x) ((unsigned)(x) << PAGE_SHIFT) -#define pgtok(x) ((x) * (PAGE_SIZE / 1024)) - #endif /* !_ARM_INCLUDE_PARAM_H_ */ diff --git a/sys/arm64/include/param.h b/sys/arm64/include/param.h index 6eb58a69dba1..c3f6990db79b 100644 --- a/sys/arm64/include/param.h +++ b/sys/arm64/include/param.h @@ -119,17 +119,9 @@ /* * Mach derived conversion macros */ -#define round_page(x) (((unsigned long)(x) + PAGE_MASK) & ~PAGE_MASK) -#define trunc_page(x) ((unsigned long)(x) & ~PAGE_MASK) - -#define atop(x) ((unsigned long)(x) >> PAGE_SHIFT) -#define ptoa(x) ((unsigned long)(x) << PAGE_SHIFT) - #define arm64_btop(x) ((unsigned long)(x) >> PAGE_SHIFT) #define arm64_ptob(x) ((unsigned long)(x) << PAGE_SHIFT) -#define pgtok(x) ((unsigned long)(x) * (PAGE_SIZE / 1024)) - #endif /* !_MACHINE_PARAM_H_ */ #endif /* !__arm__ */ diff --git a/sys/i386/include/param.h b/sys/i386/include/param.h index 2b9982324d19..79b6eee9db69 100644 --- a/sys/i386/include/param.h +++ b/sys/i386/include/param.h @@ -144,19 +144,12 @@ /* * Mach derived conversion macros */ -#define trunc_page(x) ((x) & ~PAGE_MASK) -#define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK) #define trunc_4mpage(x) ((x) & ~PDRMASK) #define round_4mpage(x) ((((x)) + PDRMASK) & ~PDRMASK) -#define atop(x) ((x) >> PAGE_SHIFT) -#define ptoa(x) ((x) << PAGE_SHIFT) - #define i386_btop(x) ((x) >> PAGE_SHIFT) #define i386_ptob(x) ((x) << PAGE_SHIFT) -#define pgtok(x) ((x) * (PAGE_SIZE / 1024)) - #define INKERNEL(va) (TRUE) #endif /* !_I386_INCLUDE_PARAM_H_ */ diff --git a/sys/powerpc/include/param.h b/sys/powerpc/include/param.h index 56a7308a21b3..b40ada24ad11 100644 --- a/sys/powerpc/include/param.h +++ b/sys/powerpc/include/param.h @@ -141,20 +141,13 @@ /* * Mach derived conversion macros */ -#define trunc_page(x) ((x) & ~(PAGE_MASK)) -#define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK) #define trunc_2mpage(x) ((unsigned long)(x) & ~L3_PAGE_MASK) #define round_2mpage(x) ((((unsigned long)(x)) + L3_PAGE_MASK) & ~L3_PAGE_MASK) #define trunc_1gpage(x) ((unsigned long)(x) & ~L2_PAGE_MASK) -#define atop(x) ((x) >> PAGE_SHIFT) -#define ptoa(x) ((x) << PAGE_SHIFT) - #define powerpc_btop(x) ((x) >> PAGE_SHIFT) #define powerpc_ptob(x) ((x) << PAGE_SHIFT) -#define pgtok(x) ((x) * (PAGE_SIZE / 1024UL)) - #define btoc(x) ((vm_offset_t)(((x)+PAGE_MASK)>>PAGE_SHIFT)) #endif /* !_POWERPC_INCLUDE_PARAM_H_ */ diff --git a/sys/riscv/include/param.h b/sys/riscv/include/param.h index d06bd0663bac..ca9c91f3f981 100644 --- a/sys/riscv/include/param.h +++ b/sys/riscv/include/param.h @@ -93,15 +93,7 @@ /* * Mach derived conversion macros */ -#define round_page(x) (((unsigned long)(x) + PAGE_MASK) & ~PAGE_MASK) -#define trunc_page(x) ((unsigned long)(x) & ~PAGE_MASK) - -#define atop(x) ((unsigned long)(x) >> PAGE_SHIFT) -#define ptoa(x) ((unsigned long)(x) << PAGE_SHIFT) - #define riscv_btop(x) ((unsigned long)(x) >> PAGE_SHIFT) #define riscv_ptob(x) ((unsigned long)(x) << PAGE_SHIFT) -#define pgtok(x) ((unsigned long)(x) * (PAGE_SIZE / 1024)) - #endif /* !_MACHINE_PARAM_H_ */ diff --git a/sys/sys/param.h b/sys/sys/param.h index d2aad1ff98a1..6d611f251add 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -200,6 +200,17 @@ #define MJUM9BYTES (9 * 1024) /* jumbo cluster 9k */ #define MJUM16BYTES (16 * 1024) /* jumbo cluster 16k */ +/* + * Mach derived conversion macros + */ +#define round_page(x) roundup2(x, PAGE_SIZE) +#define trunc_page(x) rounddown2(x, PAGE_SIZE) + +#define atop(x) ((x) >> PAGE_SHIFT) +#define ptoa(x) ((x) << PAGE_SHIFT) + +#define pgtok(x) ((x) * (PAGE_SIZE / 1024)) + /* * Some macros for units conversion */ diff --git a/usr.bin/systat/sysput.c b/usr.bin/systat/sysput.c index 4053037236f4..6ae0075bb54d 100644 --- a/usr.bin/systat/sysput.c +++ b/usr.bin/systat/sysput.c @@ -25,13 +25,12 @@ * SUCH DAMAGE. */ -#include +#include #include #include #include #include -#include #include #include "systat.h"