diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c index 1a8e07832894..6a356fbf4c88 100644 --- a/sys/compat/linprocfs/linprocfs.c +++ b/sys/compat/linprocfs/linprocfs.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -118,9 +119,9 @@ linprocfs_domeminfo(curp, p, pfs, uio) unsigned long memfree; /* free memory in bytes */ unsigned long memshared; /* shared memory ??? */ unsigned long buffers, cached; /* buffer / cache memory ??? */ - unsigned long swaptotal; /* total swap space in bytes */ - unsigned long swapused; /* used swap space in bytes */ - unsigned long swapfree; /* free swap space in bytes */ + u_quad_t swaptotal; /* total swap space in bytes */ + u_quad_t swapused; /* used swap space in bytes */ + u_quad_t swapfree; /* free swap space in bytes */ vm_object_t object; if (uio->uio_rw != UIO_READ) @@ -143,8 +144,8 @@ linprocfs_domeminfo(curp, p, pfs, uio) swaptotal = 0; swapfree = 0; } else { - swaptotal = swapblist->bl_blocks * 1024; /* XXX why 1024? */ - swapfree = swapblist->bl_root->u.bmu_avail * PAGE_SIZE; + swaptotal = (u_quad_t)swapblist->bl_blocks * 1024; /* XXX why 1024? */ + swapfree = (u_quad_t)swapblist->bl_root->u.bmu_avail * PAGE_SIZE; } swapused = swaptotal - swapfree; memshared = 0; @@ -167,14 +168,14 @@ linprocfs_domeminfo(curp, p, pfs, uio) sbuf_printf(&sb, " total: used: free: shared: buffers: cached:\n" "Mem: %lu %lu %lu %lu %lu %lu\n" - "Swap: %lu %lu %lu\n" + "Swap: %llu %llu %llu\n" "MemTotal: %9lu kB\n" "MemFree: %9lu kB\n" "MemShared:%9lu kB\n" "Buffers: %9lu kB\n" "Cached: %9lu kB\n" - "SwapTotal:%9lu kB\n" - "SwapFree: %9lu kB\n", + "SwapTotal:%9llu kB\n" + "SwapFree: %9llu kB\n", memtotal, memused, memfree, memshared, buffers, cached, swaptotal, swapused, swapfree, B2K(memtotal), B2K(memfree), @@ -337,6 +338,38 @@ linprocfs_doversion(curp, p, pfs, uio) COMMON_END; } +int +linprocfs_doloadavg(curp, p, pfs, uio) + struct proc *curp; + struct proc *p; + struct pfsnode *pfs; + struct uio *uio; +{ + COMMON_START; + int lastpid, ilen; + + ilen = sizeof(lastpid); + if (kernel_sysctlbyname(p, "kern.lastpid", + &lastpid, &ilen, NULL, 0, NULL) != 0) + lastpid = -1; /* fake it */ + + sbuf_new(&sb, NULL, 128, 0); + sbuf_printf(&sb, + "%d.%02d %d.%02d %d.%02d %d/%d %d\n", + (int)(averunnable.ldavg[0] / averunnable.fscale), + (int)(averunnable.ldavg[0] * 100 / averunnable.fscale % 100), + (int)(averunnable.ldavg[1] / averunnable.fscale), + (int)(averunnable.ldavg[1] * 100 / averunnable.fscale % 100), + (int)(averunnable.ldavg[2] / averunnable.fscale), + (int)(averunnable.ldavg[2] * 100 / averunnable.fscale % 100), + 1, /* number of running tasks */ + nprocs, /* number of tasks */ + lastpid /* the last pid */ + ); + + COMMON_END; +} + int linprocfs_doprocstat(curp, p, pfs, uio) struct proc *curp; diff --git a/sys/compat/linprocfs/linprocfs.h b/sys/compat/linprocfs/linprocfs.h index 862ea19263a5..381ce21f7340 100644 --- a/sys/compat/linprocfs/linprocfs.h +++ b/sys/compat/linprocfs/linprocfs.h @@ -126,6 +126,7 @@ node_action_t linprocfs_doselflink; node_action_t linprocfs_dostat; node_action_t linprocfs_douptime; node_action_t linprocfs_doversion; +node_action_t linprocfs_doloadavg; extern node_action_t procfs_domem; extern node_action_t procfs_docmdline; diff --git a/sys/compat/linprocfs/linprocfs_misc.c b/sys/compat/linprocfs/linprocfs_misc.c index 1a8e07832894..6a356fbf4c88 100644 --- a/sys/compat/linprocfs/linprocfs_misc.c +++ b/sys/compat/linprocfs/linprocfs_misc.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -118,9 +119,9 @@ linprocfs_domeminfo(curp, p, pfs, uio) unsigned long memfree; /* free memory in bytes */ unsigned long memshared; /* shared memory ??? */ unsigned long buffers, cached; /* buffer / cache memory ??? */ - unsigned long swaptotal; /* total swap space in bytes */ - unsigned long swapused; /* used swap space in bytes */ - unsigned long swapfree; /* free swap space in bytes */ + u_quad_t swaptotal; /* total swap space in bytes */ + u_quad_t swapused; /* used swap space in bytes */ + u_quad_t swapfree; /* free swap space in bytes */ vm_object_t object; if (uio->uio_rw != UIO_READ) @@ -143,8 +144,8 @@ linprocfs_domeminfo(curp, p, pfs, uio) swaptotal = 0; swapfree = 0; } else { - swaptotal = swapblist->bl_blocks * 1024; /* XXX why 1024? */ - swapfree = swapblist->bl_root->u.bmu_avail * PAGE_SIZE; + swaptotal = (u_quad_t)swapblist->bl_blocks * 1024; /* XXX why 1024? */ + swapfree = (u_quad_t)swapblist->bl_root->u.bmu_avail * PAGE_SIZE; } swapused = swaptotal - swapfree; memshared = 0; @@ -167,14 +168,14 @@ linprocfs_domeminfo(curp, p, pfs, uio) sbuf_printf(&sb, " total: used: free: shared: buffers: cached:\n" "Mem: %lu %lu %lu %lu %lu %lu\n" - "Swap: %lu %lu %lu\n" + "Swap: %llu %llu %llu\n" "MemTotal: %9lu kB\n" "MemFree: %9lu kB\n" "MemShared:%9lu kB\n" "Buffers: %9lu kB\n" "Cached: %9lu kB\n" - "SwapTotal:%9lu kB\n" - "SwapFree: %9lu kB\n", + "SwapTotal:%9llu kB\n" + "SwapFree: %9llu kB\n", memtotal, memused, memfree, memshared, buffers, cached, swaptotal, swapused, swapfree, B2K(memtotal), B2K(memfree), @@ -337,6 +338,38 @@ linprocfs_doversion(curp, p, pfs, uio) COMMON_END; } +int +linprocfs_doloadavg(curp, p, pfs, uio) + struct proc *curp; + struct proc *p; + struct pfsnode *pfs; + struct uio *uio; +{ + COMMON_START; + int lastpid, ilen; + + ilen = sizeof(lastpid); + if (kernel_sysctlbyname(p, "kern.lastpid", + &lastpid, &ilen, NULL, 0, NULL) != 0) + lastpid = -1; /* fake it */ + + sbuf_new(&sb, NULL, 128, 0); + sbuf_printf(&sb, + "%d.%02d %d.%02d %d.%02d %d/%d %d\n", + (int)(averunnable.ldavg[0] / averunnable.fscale), + (int)(averunnable.ldavg[0] * 100 / averunnable.fscale % 100), + (int)(averunnable.ldavg[1] / averunnable.fscale), + (int)(averunnable.ldavg[1] * 100 / averunnable.fscale % 100), + (int)(averunnable.ldavg[2] / averunnable.fscale), + (int)(averunnable.ldavg[2] * 100 / averunnable.fscale % 100), + 1, /* number of running tasks */ + nprocs, /* number of tasks */ + lastpid /* the last pid */ + ); + + COMMON_END; +} + int linprocfs_doprocstat(curp, p, pfs, uio) struct proc *curp; diff --git a/sys/compat/linprocfs/linprocfs_vnops.c b/sys/compat/linprocfs/linprocfs_vnops.c index da133f36fafa..2bb824ede501 100644 --- a/sys/compat/linprocfs/linprocfs_vnops.c +++ b/sys/compat/linprocfs/linprocfs_vnops.c @@ -121,6 +121,7 @@ struct node_data root_dir[] = { { N("stat"), VREG, 0444, 0, A(dostat) }, { N("uptime"), VREG, 0444, 0, A(douptime) }, { N("version"), VREG, 0444, 0, A(doversion) }, + { N("loadavg"), VREG, 0444, 0, A(doloadavg) }, { N(""), VNON, 0000, 0, NULL }, };