Date: Tue, 2 Oct 2001 12:29:14 -0500 (CDT) From: Mike Silbersack <silby@silby.com> To: Dan Nelson <dnelson@allantgroup.com> Cc: <freebsd-arch@FreeBSD.ORG> Subject: Re: Reading physical memory in a cross-platform way Message-ID: <20011002122651.P16126-200000@achilles.silby.com> In-Reply-To: <20011001224604.A29573@dan.emsphone.com>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --]
On Mon, 1 Oct 2001, Dan Nelson wrote:
> > physmem != hw.physmem. The sysctl is actually the output of a function,
> > not a simple int or the like.
>
> Yeah, but look at the function (i386 as an example):
>
> static int
> sysctl_hw_physmem(SYSCTL_HANDLER_ARGS)
> {
> int error = sysctl_handle_int(oidp, 0, ctob(physmem), req);
> return (error);
> }
>
> So the physmem value is just in pages; even though the different
> platforms use ctob() or <mach>_ptob(), the macros all expand to
> ((x) << PAGE_SHIFT).
True, but I still don't want to spread MD-ish code across the kernel. So,
I whipped up the patch I proposed. This introduces "maxmembytes", which
contains the size of ram in bytes. I think I've updated all architectures
properly, but I've only tested on i386. Could someone working on
alpha/ia64/sparc check to make sure that it doesn't break compilation?
Unless there are objections, I'll probably commit it in a few days.
Thanks,
Mike "Silby" Silbersack
[-- Attachment #2 --]
diff -u -r sys/alpha/alpha/machdep.c sys.new/alpha/alpha/machdep.c
--- sys/alpha/alpha/machdep.c Wed Sep 12 08:36:53 2001
+++ sys.new/alpha/alpha/machdep.c Tue Oct 2 12:24:19 2001
@@ -189,6 +189,7 @@
struct msgbuf *msgbufp=0;
int Maxmem = 0;
+u_int64_t maxmembytes = 0;
long dumplo;
int totalphysmem; /* total amount of physical memory in system */
@@ -846,6 +847,8 @@
else
Maxmem = alpha_btop(AllowMem);
}
+
+ maxmembytes = alpha_ptob(Maxmem);
while (physmem > Maxmem) {
int i = phys_avail_cnt - 2;
diff -u -r sys/i386/i386/machdep.c sys.new/i386/i386/machdep.c
--- sys/i386/i386/machdep.c Wed Sep 12 08:37:29 2001
+++ sys.new/i386/i386/machdep.c Tue Oct 2 12:24:39 2001
@@ -156,6 +156,7 @@
SYSCTL_INT(_machdep, OID_AUTO, ispc98, CTLFLAG_RD, &ispc98, 0, "");
int physmem = 0;
+u_int64_t maxmembytes = 0;
int cold = 1;
#ifdef COMPAT_43
@@ -1655,6 +1656,8 @@
phys_avail[pa_indx] -= round_page(MSGBUF_SIZE);
avail_end = phys_avail[pa_indx];
+
+ maxmembytes = ptoa(Maxmem);
}
void
diff -u -r sys/ia64/ia64/machdep.c sys.new/ia64/ia64/machdep.c
--- sys/ia64/ia64/machdep.c Sat Sep 29 11:43:36 2001
+++ sys.new/ia64/ia64/machdep.c Tue Oct 2 12:09:20 2001
@@ -129,6 +129,7 @@
struct msgbuf *msgbufp=0;
int bootverbose = 0, Maxmem = 0;
+u_int64_t maxmembytes;
long dumplo;
int totalphysmem; /* total amount of physical memory in system */
@@ -716,6 +717,7 @@
phys_avail[phys_avail_cnt] = 0;
Maxmem = physmem;
+ maxmembytes = ia64_ptob(Maxmem);
/*
* Initialize error message buffer (at end of core).
diff -u -r sys/powerpc/powerpc/machdep.c sys.new/powerpc/powerpc/machdep.c
--- sys/powerpc/powerpc/machdep.c Mon Sep 24 02:58:49 2001
+++ sys.new/powerpc/powerpc/machdep.c Tue Oct 2 12:09:36 2001
@@ -113,6 +113,7 @@
#include <machine/sigframe.h>
int physmem = 0;
+u_int64_t maxmembytes = 0;
int cold = 1;
struct mtx sched_lock;
diff -u -r sys/sparc64/sparc64/machdep.c sys.new/sparc64/sparc64/machdep.c
--- sys/sparc64/sparc64/machdep.c Sun Sep 30 18:48:37 2001
+++ sys.new/sparc64/sparc64/machdep.c Tue Oct 2 12:07:07 2001
@@ -98,6 +98,7 @@
int cold = 1;
long dumplo;
int Maxmem;
+u_int64_t maxmembytes;
u_long debug_mask;
diff -u -r sys/sys/systm.h sys.new/sys/systm.h
--- sys/sys/systm.h Thu Sep 20 21:45:31 2001
+++ sys.new/sys/systm.h Tue Oct 2 12:09:26 2001
@@ -60,6 +60,7 @@
extern struct cv selwait; /* select conditional variable */
extern int physmem; /* physical memory */
+extern u_int64_t maxmembytes; /* maximum memory in bytes */
extern dev_t dumpdev; /* dump device */
extern long dumplo; /* offset into dumpdev */
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011002122651.P16126-200000>
