This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.
This commit is contained in:
parent
eb14e86676
commit
a2d850baf8
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: procfs.h,v 1.40 2003/01/18 09:18:06 thorpej Exp $ */
|
||||
/* $NetBSD: procfs.h,v 1.41 2003/02/25 21:00:31 jrf Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Jan-Simon Pendry
|
||||
|
@ -64,6 +64,7 @@ typedef enum {
|
|||
Pcpuinfo, /* CPU info (if -o linux) */
|
||||
Pmaps, /* memory map, Linux style (if -o linux) */
|
||||
Pfd, /* a directory containing the processes open fd's */
|
||||
Puptime, /* elapsed time since (if -o linux) */
|
||||
#ifdef __HAVE_PROCFS_MACHDEP
|
||||
PROCFS_MACHDEP_NODE_TYPES
|
||||
#endif
|
||||
|
@ -160,6 +161,8 @@ int procfs_docpuinfo __P((struct proc *, struct proc *, struct pfsnode *,
|
|||
struct uio *));
|
||||
int procfs_dofd __P((struct proc *, struct proc *, struct pfsnode *,
|
||||
struct uio *));
|
||||
int procfs_douptime __P((struct proc *, struct proc *, struct pfsnode *,
|
||||
struct uio *));
|
||||
|
||||
void procfs_revoke_vnodes __P((struct proc *, void *));
|
||||
void procfs_hashinit __P((void));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: procfs_linux.c,v 1.4 2001/12/09 03:07:44 chs Exp $ */
|
||||
/* $NetBSD: procfs_linux.c,v 1.5 2003/02/25 21:00:31 jrf Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001 Wasabi Systems, Inc.
|
||||
|
@ -36,7 +36,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.4 2001/12/09 03:07:44 chs Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.5 2003/02/25 21:00:31 jrf Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -127,3 +127,31 @@ procfs_docpuinfo(struct proc *curp, struct proc *p, struct pfsnode *pfs,
|
|||
error = uiomove(cp, len, uio);
|
||||
return error;
|
||||
}
|
||||
|
||||
int
|
||||
procfs_douptime(struct proc *curp, struct proc *p, struct pfsnode *pfs,
|
||||
struct uio *uio)
|
||||
{
|
||||
char buf[512], *cp;
|
||||
int len, error;
|
||||
struct timeval runtime;
|
||||
u_int64_t idle;
|
||||
|
||||
timersub(&curcpu()->ci_schedstate.spc_runtime, &boottime, &runtime);
|
||||
idle = curcpu()->ci_schedstate.spc_cp_time[CP_IDLE];
|
||||
len = sprintf(buf, "%lu.%02lu %llu.%02llu\n",
|
||||
runtime.tv_sec, runtime.tv_usec / 10000,
|
||||
idle / hz, (((idle % hz) * 100) / hz) % 100);
|
||||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
len -= uio->uio_offset;
|
||||
cp = buf + uio->uio_offset;
|
||||
len = imin(len, uio->uio_resid);
|
||||
if (len <= 0)
|
||||
error = 0;
|
||||
else
|
||||
error = uiomove(cp, len, uio);
|
||||
return error;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: procfs_subr.c,v 1.45 2003/02/03 22:29:07 jdolecek Exp $ */
|
||||
/* $NetBSD: procfs_subr.c,v 1.46 2003/02/25 21:00:32 jrf Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994 Christopher G. Demetriou. All rights reserved.
|
||||
|
@ -41,7 +41,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.45 2003/02/03 22:29:07 jdolecek Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.46 2003/02/25 21:00:32 jrf Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -316,6 +316,9 @@ procfs_rw(v)
|
|||
case Pfd:
|
||||
return (procfs_dofd(curp, p, pfs, uio));
|
||||
|
||||
case Puptime:
|
||||
return (procfs_douptime(curp, p, pfs, uio));
|
||||
|
||||
#ifdef __HAVE_PROCFS_MACHDEP
|
||||
PROCFS_MACHDEP_NODETYPE_CASES
|
||||
return (procfs_machdep_rw(curp, l, pfs, uio));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: procfs_vnops.c,v 1.93 2003/01/04 15:42:35 martin Exp $ */
|
||||
/* $NetBSD: procfs_vnops.c,v 1.94 2003/02/25 21:00:32 jrf Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Jan-Simon Pendry
|
||||
|
@ -44,7 +44,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.93 2003/01/04 15:42:35 martin Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.94 2003/02/25 21:00:32 jrf Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -121,6 +121,7 @@ struct proc_target proc_root_targets[] = {
|
|||
/* name type validp */
|
||||
{ DT_REG, N("meminfo"), Pmeminfo, procfs_validfile_linux },
|
||||
{ DT_REG, N("cpuinfo"), Pcpuinfo, procfs_validfile_linux },
|
||||
{ DT_REG, N("uptime"), Puptime, procfs_validfile_linux },
|
||||
#undef N
|
||||
};
|
||||
static int nproc_root_targets =
|
||||
|
@ -542,6 +543,7 @@ procfs_getattr(v)
|
|||
break;
|
||||
case Pmeminfo:
|
||||
case Pcpuinfo:
|
||||
case Puptime:
|
||||
vap->va_nlink = 1;
|
||||
vap->va_uid = vap->va_gid = 0;
|
||||
break;
|
||||
|
@ -645,6 +647,7 @@ procfs_getattr(v)
|
|||
case Pcmdline:
|
||||
case Pmeminfo:
|
||||
case Pcpuinfo:
|
||||
case Puptime:
|
||||
vap->va_bytes = vap->va_size = 0;
|
||||
break;
|
||||
case Pmap:
|
||||
|
|
Loading…
Reference in New Issue