Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 May 2001 11:06:24 -0700 (PDT)
From:      Jim.Pirzyk@disney.com
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   kern/27253: linprocfs does not have /proc/loadavg
Message-ID:  <200105101806.f4AI6OM38175@snoopy.fan.fa.disney.com>

next in thread | raw e-mail | index | archive | help

>Number:         27253
>Category:       kern
>Synopsis:       linprocfs does not implement the loadavg file.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 10 11:10:03 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Jim Pirzyk
>Release:        FreeBSD 4.3-RELEASE i386
>Organization:
>Environment:
System: FreeBSD snoopy.fan.fa.disney.com 4.3-RELEASE FreeBSD 4.3-RELEASE #4: Fri Apr 27 01:14:59 PDT 2001 root@snoopy.fan.fa.disney.com:/auto/roy/dist/pub/FreeBSD/4.3-RELEASE/sys/compile/UP_WORKSTATION i386


	
>Description:
	We have linux binaries that need to access /proc/loadavg to get
	status of the system so we need this file.

>How-To-Repeat:
	mount -t linprocfs /compat/linux/proc
	ls -la /compat/linux/proc/loadavg
>Fix:

*** ./sys/i386/linux/linprocfs/linprocfs.h.orig	Mon Oct 30 11:57:04 2000
--- ./sys/i386/linux/linprocfs/linprocfs.h	Tue May  8 09:09:50 2001
***************
*** 57,62 ****
--- 57,63 ----
  	Pstat,	        /* kernel/system statistics */
  	Puptime,	/* system uptime */
  	Pversion,	/* system version */
+ 	Ploadavg,	/* system load average */
  } pfstype;
  
  /*
***************
*** 132,137 ****
--- 133,139 ----
  int linprocfs_doversion __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
  int linprocfs_doprocstat __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
  int linprocfs_doprocstatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
+ int linprocfs_doloadavg __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
  
  /* functions to check whether or not files should be displayed */
  int linprocfs_validfile __P((struct proc *));
*** ./sys/i386/linux/linprocfs/linprocfs_misc.c.orig	Thu Dec  7 05:17:55 2000
--- ./sys/i386/linux/linprocfs/linprocfs_misc.c	Tue May  8 16:09:17 2001
***************
*** 495,498 ****
--- 495,531 ----
  	ps = psbuf + uio->uio_offset;
  	xlen = imin(xlen, uio->uio_resid);
  	return (xlen <= 0 ? 0 : uiomove(ps, xlen, uio));
+ }
+ 
+ int
+ linprocfs_doloadavg(curp, p, pfs, uio)
+ 	struct proc *curp;
+ 	struct proc *p;
+ 	struct pfsnode *pfs;
+ 	struct uio *uio;
+ {
+      char *ps, psbuf[512];
+      int xlen;
+ 	extern int nextpid;
+ 
+ 	ps=psbuf;
+ 
+ 	ps += sprintf(ps,
+ 		"%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 */
+ 		-1,			/* number of tasks */
+ 		nextpid		/* The last pid */
+ 	);
+ 
+ 	xlen = ps - psbuf;
+ 	xlen -= uio->uio_offset;
+ 	ps = psbuf + uio->uio_offset;
+ 	xlen = imin(xlen, uio->uio_resid);
+      return (xlen <= 0 ? 0 : uiomove(ps, xlen, uio));
  }
*** ./sys/i386/linux/linprocfs/linprocfs_subr.c.orig	Mon Oct 30 11:57:04 2000
--- ./sys/i386/linux/linprocfs/linprocfs_subr.c	Tue May  8 09:13:20 2001
***************
*** 184,189 ****
--- 184,190 ----
  	case Pstat:
  	case Puptime:
  	case Pversion:
+ 	case Ploadavg:
  		pfs->pfs_mode = (VREAD) |
  				(VREAD >> 3) |
  				(VREAD >> 6);
***************
*** 275,280 ****
--- 276,284 ----
  		break;
  	case Pversion:
  		rtval = linprocfs_doversion(curp, p, pfs, uio);
+ 		break;
+ 	case Ploadavg:
+ 		rtval = linprocfs_doloadavg(curp, p, pfs, uio);
  		break;
  	default:
  		rtval = EOPNOTSUPP;
*** ./sys/i386/linux/linprocfs/linprocfs_vnops.c.orig	Mon Oct 30 11:57:04 2000
--- ./sys/i386/linux/linprocfs/linprocfs_vnops.c	Tue May  8 09:14:47 2001
***************
*** 529,534 ****
--- 529,535 ----
  	case Pstat:
  	case Puptime:
  	case Pversion:
+ 	case Ploadavg:
  		vap->va_bytes = vap->va_size = 0;
  		vap->va_uid = 0;
  		vap->va_gid = 0;
***************
*** 706,711 ****
--- 707,714 ----
  			return (linprocfs_allocvp(dvp->v_mount, vpp, 0, Puptime));
  		if (CNEQ(cnp, "version", 7))
  			return (linprocfs_allocvp(dvp->v_mount, vpp, 0, Pversion));
+ 		if (CNEQ(cnp, "loadavg", 7))
+ 			return (linprocfs_allocvp(dvp->v_mount, vpp, 0, Ploadavg));
  
  		pid = atopid(pname, cnp->cn_namelen);
  		if (pid == NO_PID)
***************
*** 901,906 ****
--- 904,917 ----
  				bcopy("version", dp->d_name, 8);
  				dp->d_type = DT_REG;
  				break;
+ 
+ 			case 8:
+ 				dp->d_fileno = PROCFS_FILENO(0, Ploadavg);
+ 				dp->d_namlen = 7;
+ 				bcopy("loadavg", dp->d_name, 8);
+ 				dp->d_type = DT_REG;
+ 				break;
+ 
  
  			default:
  				while (pcnt < i) {

>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200105101806.f4AI6OM38175>