linprocfs.c revision 59412
159412Smsmith/* 259412Smsmith * Copyright (c) 1993 Jan-Simon Pendry 359412Smsmith * Copyright (c) 1993 459412Smsmith * The Regents of the University of California. All rights reserved. 559412Smsmith * 659412Smsmith * This code is derived from software contributed to Berkeley by 759412Smsmith * Jan-Simon Pendry. 859412Smsmith * 959412Smsmith * Redistribution and use in source and binary forms, with or without 1059412Smsmith * modification, are permitted provided that the following conditions 1159412Smsmith * are met: 1259412Smsmith * 1. Redistributions of source code must retain the above copyright 1359412Smsmith * notice, this list of conditions and the following disclaimer. 1459412Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1559412Smsmith * notice, this list of conditions and the following disclaimer in the 1659412Smsmith * documentation and/or other materials provided with the distribution. 1759412Smsmith * 3. All advertising materials mentioning features or use of this software 1859412Smsmith * must display the following acknowledgement: 1959412Smsmith * This product includes software developed by the University of 2059412Smsmith * California, Berkeley and its contributors. 2159412Smsmith * 4. Neither the name of the University nor the names of its contributors 2259412Smsmith * may be used to endorse or promote products derived from this software 2359412Smsmith * without specific prior written permission. 2459412Smsmith * 2559412Smsmith * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2659412Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2759412Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2859412Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2959412Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3059412Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3159412Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3259412Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3359412Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3459412Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3559412Smsmith * SUCH DAMAGE. 3659412Smsmith * 3759412Smsmith * @(#)procfs_status.c 8.4 (Berkeley) 6/15/94 3859412Smsmith * 3959412Smsmith * $FreeBSD: head/sys/compat/linprocfs/linprocfs.c 59412 2000-04-20 03:54:27Z msmith $ 4059412Smsmith */ 4159412Smsmith 4259412Smsmith#include <sys/param.h> 4359412Smsmith#include <sys/systm.h> 4459412Smsmith#include <sys/proc.h> 4559412Smsmith#include <sys/jail.h> 4659412Smsmith#include <sys/vnode.h> 4759412Smsmith#include <sys/blist.h> 4859412Smsmith#include <sys/tty.h> 4959412Smsmith#include <sys/resourcevar.h> 5059412Smsmith#include <miscfs/linprocfs/linprocfs.h> 5159412Smsmith 5259412Smsmith#include <vm/vm.h> 5359412Smsmith#include <vm/pmap.h> 5459412Smsmith#include <vm/vm_param.h> 5559412Smsmith#include <vm/swap_pager.h> 5659412Smsmith#include <sys/vmmeter.h> 5759412Smsmith#include <sys/exec.h> 5859412Smsmith 5959412Smsmith#include <machine/md_var.h> 6059412Smsmith#include <machine/cputypes.h> 6159412Smsmith 6259412Smsmithstruct proc; 6359412Smsmith 6459412Smsmithint 6559412Smsmithlinprocfs_domeminfo(curp, p, pfs, uio) 6659412Smsmith struct proc *curp; 6759412Smsmith struct proc *p; 6859412Smsmith struct pfsnode *pfs; 6959412Smsmith struct uio *uio; 7059412Smsmith{ 7159412Smsmith char *ps; 7259412Smsmith int xlen; 7359412Smsmith int error; 7459412Smsmith char psbuf[512]; /* XXX - conservative */ 7559412Smsmith unsigned long memtotal; /* total memory in bytes */ 7659412Smsmith unsigned long memused; /* used memory in bytes */ 7759412Smsmith unsigned long memfree; /* free memory in bytes */ 7859412Smsmith unsigned long memshared; /* shared memory ??? */ 7959412Smsmith unsigned long buffers, cached; /* buffer / cache memory ??? */ 8059412Smsmith unsigned long swaptotal; /* total swap space in bytes */ 8159412Smsmith unsigned long swapused; /* used swap space in bytes */ 8259412Smsmith unsigned long swapfree; /* free swap space in bytes */ 8359412Smsmith 8459412Smsmith if (uio->uio_rw != UIO_READ) 8559412Smsmith return (EOPNOTSUPP); 8659412Smsmith 8759412Smsmith memtotal = physmem * PAGE_SIZE; 8859412Smsmith /* 8959412Smsmith * The correct thing here would be: 9059412Smsmith * 9159412Smsmith memfree = cnt.v_free_count * PAGE_SIZE; 9259412Smsmith memused = memtotal - memfree; 9359412Smsmith * 9459412Smsmith * but it might mislead linux binaries into thinking there 9559412Smsmith * is very little memory left, so we cheat and tell them that 9659412Smsmith * all memory that isn't wired down is free. 9759412Smsmith */ 9859412Smsmith memused = cnt.v_wire_count * PAGE_SIZE; 9959412Smsmith memfree = memtotal - memused; 10059412Smsmith swaptotal = swapblist->bl_blocks * 1024; /* XXX why 1024? */ 10159412Smsmith swapfree = swapblist->bl_root->u.bmu_avail * PAGE_SIZE; 10259412Smsmith swapused = swaptotal - swapfree; 10359412Smsmith memshared = 0; /* XXX what's this supposed to be? */ 10459412Smsmith /* 10559412Smsmith * We'd love to be able to write: 10659412Smsmith * 10759412Smsmith buffers = bufspace; 10859412Smsmith * 10959412Smsmith * but bufspace is internal to vfs_bio.c and we don't feel 11059412Smsmith * like unstaticizing it just for linprocfs's sake. 11159412Smsmith */ 11259412Smsmith buffers = 0; 11359412Smsmith cached = cnt.v_cache_count * PAGE_SIZE; 11459412Smsmith 11559412Smsmith ps = psbuf; 11659412Smsmith ps += sprintf(ps, 11759412Smsmith " total: used: free: shared: buffers: cached:\n" 11859412Smsmith "Mem: %lu %lu %lu %lu %lu %lu\n" 11959412Smsmith "Swap: %lu %lu %lu\n" 12059412Smsmith "MemTotal: %9lu kB\n" 12159412Smsmith "MemFree: %9lu kB\n" 12259412Smsmith "MemShared:%9lu kB\n" 12359412Smsmith "Buffers: %9lu kB\n" 12459412Smsmith "Cached: %9lu kB\n" 12559412Smsmith "SwapTotal:%9lu kB\n" 12659412Smsmith "SwapFree: %9lu kB\n", 12759412Smsmith memtotal, memused, memfree, memshared, buffers, cached, 12859412Smsmith swaptotal, swapused, swapfree, 12959412Smsmith memtotal >> 10, memfree >> 10, 13059412Smsmith memshared >> 10, buffers >> 10, cached >> 10, 13159412Smsmith swaptotal >> 10, swapfree >> 10); 13259412Smsmith 13359412Smsmith xlen = ps - psbuf; 13459412Smsmith xlen -= uio->uio_offset; 13559412Smsmith ps = psbuf + uio->uio_offset; 13659412Smsmith xlen = imin(xlen, uio->uio_resid); 13759412Smsmith if (xlen <= 0) 13859412Smsmith error = 0; 13959412Smsmith else 14059412Smsmith error = uiomove(ps, xlen, uio); 14159412Smsmith return (error); 14259412Smsmith} 14359412Smsmith 14459412Smsmithint 14559412Smsmithlinprocfs_docpuinfo(curp, p, pfs, uio) 14659412Smsmith struct proc *curp; 14759412Smsmith struct proc *p; 14859412Smsmith struct pfsnode *pfs; 14959412Smsmith struct uio *uio; 15059412Smsmith{ 15159412Smsmith char *ps; 15259412Smsmith int xlen; 15359412Smsmith int error; 15459412Smsmith char psbuf[512]; /* XXX - conservative */ 15559412Smsmith char *class; 15659412Smsmith#if 0 15759412Smsmith extern char *cpu_model; /* Yuck */ 15859412Smsmith#endif 15959412Smsmith 16059412Smsmith if (uio->uio_rw != UIO_READ) 16159412Smsmith return (EOPNOTSUPP); 16259412Smsmith 16359412Smsmith switch (cpu_class) { 16459412Smsmith case CPUCLASS_286: 16559412Smsmith class = "286"; 16659412Smsmith break; 16759412Smsmith case CPUCLASS_386: 16859412Smsmith class = "386"; 16959412Smsmith break; 17059412Smsmith case CPUCLASS_486: 17159412Smsmith class = "486"; 17259412Smsmith break; 17359412Smsmith case CPUCLASS_586: 17459412Smsmith class = "586"; 17559412Smsmith break; 17659412Smsmith case CPUCLASS_686: 17759412Smsmith class = "686"; 17859412Smsmith break; 17959412Smsmith default: 18059412Smsmith class = "unknown"; 18159412Smsmith break; 18259412Smsmith } 18359412Smsmith 18459412Smsmith ps = psbuf; 18559412Smsmith ps += sprintf(ps, 18659412Smsmith "processor : %d\n" 18759412Smsmith "cpu : %.3s\n" 18859412Smsmith "model : %.20s\n" 18959412Smsmith "vendor_id : %.20s\n" 19059412Smsmith "stepping : %d\n", 19159412Smsmith 0, class, "unknown", cpu_vendor, cpu_id); 19259412Smsmith 19359412Smsmith xlen = ps - psbuf; 19459412Smsmith xlen -= uio->uio_offset; 19559412Smsmith ps = psbuf + uio->uio_offset; 19659412Smsmith xlen = imin(xlen, uio->uio_resid); 19759412Smsmith if (xlen <= 0) 19859412Smsmith error = 0; 19959412Smsmith else 20059412Smsmith error = uiomove(ps, xlen, uio); 20159412Smsmith return (error); 20259412Smsmith} 203