Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat/linux/common Implement sysinfo.



details:   https://anonhg.NetBSD.org/src/rev/06745d3718b9
branches:  trunk
changeset: 500551:06745d3718b9
user:      augustss <augustss%NetBSD.org@localhost>
date:      Wed Dec 13 21:41:23 2000 +0000

description:
Implement sysinfo.

diffstat:

 sys/compat/linux/common/linux_misc.c |  39 +++++++++++++++++++++++++++++++++++-
 sys/compat/linux/common/linux_misc.h |  20 +++++++++++++++++-
 2 files changed, 57 insertions(+), 2 deletions(-)

diffs (84 lines):

diff -r f0346383e048 -r 06745d3718b9 sys/compat/linux/common/linux_misc.c
--- a/sys/compat/linux/common/linux_misc.c      Wed Dec 13 21:00:53 2000 +0000
+++ b/sys/compat/linux/common/linux_misc.c      Wed Dec 13 21:41:23 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_misc.c,v 1.76 2000/12/02 16:43:51 jdolecek Exp $ */
+/*     $NetBSD: linux_misc.c,v 1.77 2000/12/13 21:41:23 augustss Exp $ */
 
 /*-
  * Copyright (c) 1995, 1998, 1999 The NetBSD Foundation, Inc.
@@ -1232,3 +1232,40 @@
        return (kern_sysctl(&name, 1, 0, 0, SCARG(uap, domainname),
                            SCARG(uap, len), p));
 }
+
+/*
+ * sysinfo()
+ */
+/* ARGSUSED */
+int
+linux_sys_sysinfo(p, v, retval)
+       struct proc *p;
+       void *v;
+       register_t *retval;
+{
+       struct linux_sys_sysinfo_args /* {
+               syscallarg(struct linux_sysinfo *) arg;
+       } */ *uap = v;
+       struct linux_sysinfo si;
+       struct loadavg *la;
+
+       si.uptime = time.tv_sec - boottime.tv_sec;
+       la = &averunnable;
+       si.loads[0] = la->ldavg[0] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
+       si.loads[1] = la->ldavg[1] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
+       si.loads[2] = la->ldavg[2] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
+       si.totalram = ctob(physmem);
+       si.freeram = uvmexp.free * uvmexp.pagesize;
+       si.sharedram = 0;       /* XXX */
+       si.bufferram = uvmexp.vnodepages * uvmexp.pagesize;
+       si.totalswap = uvmexp.swpages * uvmexp.pagesize;
+       si.freeswap = (uvmexp.swpages - uvmexp.swpginuse) * uvmexp.pagesize;
+       si.procs = nprocs;
+
+       /* The following are only present in newer Linux kernels. */
+       si.totalbig = 0;
+       si.freebig = 0;
+       si.mem_unit = 1;
+
+       return (copyout(&si, SCARG(uap, arg), sizeof si));
+}
diff -r f0346383e048 -r 06745d3718b9 sys/compat/linux/common/linux_misc.h
--- a/sys/compat/linux/common/linux_misc.h      Wed Dec 13 21:00:53 2000 +0000
+++ b/sys/compat/linux/common/linux_misc.h      Wed Dec 13 21:41:23 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_misc.h,v 1.3 1999/05/13 00:31:57 thorpej Exp $   */
+/*     $NetBSD: linux_misc.h,v 1.4 2000/12/13 21:41:24 augustss Exp $  */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -46,6 +46,24 @@
 #define        LINUX_WAIT4_WUNTRACED   0x00000002
 #define        LINUX_WAIT4_WCLONE      0x80000000
 
+/* This looks very unportable to me, but this is how Linux defines it. */
+struct linux_sysinfo {
+       long uptime;
+       unsigned long loads[3];
+#define LINUX_SYSINFO_LOADS_SCALE 65536
+       unsigned long totalram;
+       unsigned long freeram;
+       unsigned long sharedram;
+       unsigned long bufferram;
+       unsigned long totalswap;
+       unsigned long freeswap;
+       unsigned short procs;
+       unsigned long totalbig;
+       unsigned long freebig;
+       unsigned int mem_unit;
+       char _f[20-2*sizeof(long)-sizeof(int)];
+};
+
 #ifdef _KERNEL
 __BEGIN_DECLS
 void bsd_to_linux_wstat __P((int *));



Home | Main Index | Thread Index | Old Index