From Jim.Pirzyk@disney.com  Thu May 10 11:06:33 2001
Return-Path: <Jim.Pirzyk@disney.com>
Received: from mail.disney.com (mail.disney.com [204.128.192.15])
	by hub.freebsd.org (Postfix) with ESMTP id 771AF37B422
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 10 May 2001 11:06:33 -0700 (PDT)
	(envelope-from Jim.Pirzyk@disney.com)
Received: from pain10.corp.disney.com (root@pain10.corp.disney.com [153.7.110.100])
	by mail.disney.com (Switch-2.0.1/Switch-2.0.1) with SMTP id f4AI5vA28423
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 10 May 2001 11:05:57 -0700 (PDT)
Received: from louie.fa.disney.com by pain.corp.disney.com with ESMTP for FreeBSD-gnats-submit@freebsd.org; Thu, 10 May 2001 11:07:13 -0700
Received: from plio.fan.fa.disney.com (plio.fan.fa.disney.com [153.7.118.2])
	by louie.fa.disney.com (8.9.2/8.9.2) with ESMTP id LAA02987
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 10 May 2001 11:06:25 -0700 (PDT)
	(envelope-from Jim.Pirzyk@fa.disney.com)
Received: from snoopy.fan.fa.disney.com (snoopy.fan.fa.disney.com [153.7.117.170])
	by plio.fan.fa.disney.com (8.9.2/8.9.2) with ESMTP id LAA05789
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 10 May 2001 11:06:25 -0700 (PDT)
	(envelope-from Jim.Pirzyk@fa.disney.com)
Received: (from Jim.Pirzyk@localhost)
	by snoopy.fan.fa.disney.com (8.11.3/8.9.3) id f4AI6OM38175;
	Thu, 10 May 2001 11:06:24 -0700 (PDT)
	(envelope-from Jim.Pirzyk@fa.disney.com)
Message-Id: <200105101806.f4AI6OM38175@snoopy.fan.fa.disney.com>
Date: Thu, 10 May 2001 11:06:24 -0700 (PDT)
From: Jim.Pirzyk@disney.com
Reply-To: Jim.Pirzyk@disney.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: linprocfs does not have /proc/loadavg
X-Send-Pr-Version: 3.113

>Number:         27253
>Category:       kern
>Synopsis:       linprocfs does not implement the loadavg file.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pirzyk
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 10 11:10:03 PDT 2001
>Closed-Date:    Mon Jun 25 12:47:13 PDT 2001
>Last-Modified:  Mon Jun 25 12:48:33 PDT 2001
>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:
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: dwmalone 
Responsible-Changed-When: Thu May 10 14:10:55 PDT 2001 
Responsible-Changed-Why:  
Another linprocfs file for DES. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=27253 
State-Changed-From-To: open->feedback 
State-Changed-By: des 
State-Changed-When: Sun May 27 06:15:27 PDT 2001 
State-Changed-Why:  
Fixed in -CURRENT. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=27253 

From: Jim Pirzyk <Jim.Pirzyk@disney.com>
To: freebsd-gnats-submit@FreeBSD.org, Jim.Pirzyk@disney.com
Cc:  
Subject: Re: kern/27253: linprocfs does not implement the loadavg file.
Date: Tue, 29 May 2001 13:40:37 -0700

 Checked it out in -current and it looks good.  Glad to see you added
 the numprocs variable.  So the only number I could say may not be
 correct is the number of running processes.  So when will it be
 MFC'ed?
 -- 
 --- @(#) $Id: dot.signature,v 1.10 2001/05/17 23:38:49 Jim.Pirzyk Exp $
     __o   Jim.Pirzyk@disney.com ------------- pirzyk@freebsd.org
  _'\<,_   Senior Systems Engineer, Walt Disney Feature Animation 
 (*)/ (*)
State-Changed-From-To: feedback->closed 
State-Changed-By: pirzyk 
State-Changed-When: Mon Jun 25 12:47:13 PDT 2001 
State-Changed-Why:  
Applied the patches for /proc/loadavg 



Responsible-Changed-From-To: des->pirzyk 
Responsible-Changed-By: pirzyk 
Responsible-Changed-When: Mon Jun 25 12:47:13 PDT 2001 
Responsible-Changed-Why:  

I applied my own patches with des' approval. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=27253 
>Unformatted:
