summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2008-03-16 19:56:28 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2008-03-16 19:56:28 +0000
commita76f94c31f5e1b2da03a560e6b379595e0077e1f (patch)
treef749a404534ef084386b5488b7a3958676e48a3a
parent184652f0aac51db18e318953058474a7ac4493b6 (diff)
Add the semi-standard _SC_PHYS_PAGES and _SC_AVPHYS_PAGES, sysconf(3) variable.
ok espie@
-rw-r--r--lib/libc/gen/sysconf.38
-rw-r--r--lib/libc/gen/sysconf.c28
-rw-r--r--sys/sys/unistd.h5
3 files changed, 37 insertions, 4 deletions
diff --git a/lib/libc/gen/sysconf.3 b/lib/libc/gen/sysconf.3
index 7bfc70fe446..a083149c00f 100644
--- a/lib/libc/gen/sysconf.3
+++ b/lib/libc/gen/sysconf.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sysconf.3,v 1.22 2007/05/31 19:19:28 jmc Exp $
+.\" $OpenBSD: sysconf.3,v 1.23 2008/03/16 19:56:27 kettenis Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: March 16 2008 $
.Dt SYSCONF 3
.Os
.Sh NAME
@@ -148,6 +148,10 @@ does not support the Semaphores Option.
.It Li _SC_SEM_VALUE_MAX
The maximum value a semaphore may have or \-1 if the system
does not support the Semaphores Option.
+.It Li _SC_PHYS_PAGES
+The number of pages of physical memory.
+.It Li _SC_AVPHYS_PAGES
+The number of pages of physical memory not currently in use by the system.
.El
.Sh RETURN VALUES
If the call to
diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c
index 16dbc8c6673..f888ab4c780 100644
--- a/lib/libc/gen/sysconf.c
+++ b/lib/libc/gen/sysconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sysconf.c,v 1.8 2005/08/08 08:05:34 espie Exp $ */
+/* $OpenBSD: sysconf.c,v 1.9 2008/03/16 19:56:27 kettenis Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@@ -36,6 +36,7 @@
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/resource.h>
+#include <sys/vmmeter.h>
#include <errno.h>
#include <unistd.h>
@@ -198,6 +199,31 @@ yesno: if (sysctl(mib, namelen, &value, &len, NULL, 0) == -1)
KERN_SEMINFO_SEMMNS : KERN_SEMINFO_SEMVMX;
namelen = 3;
break;
+
+/* Extensions */
+ case _SC_PHYS_PAGES:
+ {
+ int64_t physmem;
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_PHYSMEM64;
+ len = sizeof(physmem);
+ if (sysctl(mib, namelen, &physmem, &len, NULL, 0) == -1)
+ return (-1);
+ return (physmem / getpagesize());
+ }
+ case _SC_AVPHYS_PAGES:
+ {
+ struct vmtotal vmtotal;
+
+ mib[0] = CTL_VM;
+ mib[1] = VM_METER;
+ len = sizeof(vmtotal);
+ if (sysctl(mib, namelen, &vmtotal, &len, NULL, 0) == -1)
+ return (-1);
+ return (vmtotal.t_free);
+ }
+
default:
errno = EINVAL;
return (-1);
diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h
index 88a77bcf42e..6d436a9d65b 100644
--- a/sys/sys/unistd.h
+++ b/sys/sys/unistd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: unistd.h,v 1.13 2005/12/13 00:35:24 millert Exp $ */
+/* $OpenBSD: unistd.h,v 1.14 2008/03/16 19:56:27 kettenis Exp $ */
/* $NetBSD: unistd.h,v 1.10 1994/06/29 06:46:06 cgd Exp $ */
/*
@@ -139,6 +139,9 @@
#define _SC_THREAD_SAFE_FUNCTIONS
#endif
+#define _SC_PHYS_PAGES 500
+#define _SC_AVPHYS_PAGES 501
+
/* configurable system strings */
#define _CS_PATH 1