From Jim.Pirzyk@disney.com  Tue May 29 18:02:44 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 6E26F37B423
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 29 May 2001 18:02:44 -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 f4U126A08487
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 29 May 2001 18:02:06 -0700 (PDT)
Received: from louie.fa.disney.com by pain.corp.disney.com with ESMTP for FreeBSD-gnats-submit@freebsd.org; Tue, 29 May 2001 18:03:33 -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 SAA01770
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 29 May 2001 18:02:43 -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 SAA00971
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 29 May 2001 18:02:42 -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 f4U12gc11399;
	Tue, 29 May 2001 18:02:42 -0700 (PDT)
	(envelope-from Jim.Pirzyk@fa.disney.com)
Message-Id: <200105300102.f4U12gc11399@snoopy.fan.fa.disney.com>
Date: Tue, 29 May 2001 18:02:42 -0700 (PDT)
From: Jim.Pirzyk@disney.com
Reply-To: Jim.Pirzyk@disney.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: linux module does not support sysinfo system call
X-Send-Pr-Version: 3.113

>Number:         27759
>Category:       kern
>Synopsis:       linux sysinfo system call is needed for maya batch mode to work.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pirzyk
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 29 18:10:00 PDT 2001
>Closed-Date:    Sun Jul 22 23:26:24 PDT 2001
>Last-Modified:  Sun Jul 22 23:26:54 PDT 2001
>Originator:     
>Release:        FreeBSD 4.3-RELEASE i386
>Organization:
>Environment:
System: FreeBSD snoopy 4.3-RELEASE FreeBSD 4.3-RELEASE #6: Tue May 29 10:01:46 PDT 2001 root@snoopy:/auto/roy/dist/pub/FreeBSD/4.3-RELEASE/sys/compile/UP_WORKSTATION i386


	
>Description:
	The maya batch mode renderer uses sysinfo from the linux kernel to
	get information about memory & etc from the system.  The linux
	kernel module does not have this system call.
>How-To-Repeat:
	Run a maya render and you get error messages of the following...

	linux: syscall %s is obsoleted or not implemented (pid=%ld)

>Fix:

	This patch was sent to me by Charles Henrich <henrich@sigbus.com>


*** ./sys/i386/linux/linux_dummy.c.orig	Wed Jul 19 22:31:56 2000
--- ./sys/i386/linux/linux_dummy.c	Fri Dec  1 08:51:52 2000
***************
*** 74,80 ****
  DUMMY(idle);
  DUMMY(vm86old);
  DUMMY(swapoff);
- DUMMY(sysinfo);
  DUMMY(adjtimex);
  DUMMY(create_module);
  DUMMY(init_module);
--- 74,79 ----
***************
*** 109,112 ****
  DUMMY(ftruncate64);
  DUMMY(stat64);
  DUMMY(lstat64);
- DUMMY(fstat64);
--- 108,110 ----
*** ./sys/i386/linux/linux_sysent.c.orig	Tue Aug  8 16:28:16 2000
--- ./sys/i386/linux/linux_sysent.c	Thu Nov 30 17:42:29 2000
***************
*** 133,139 ****
  	{ 0, (sy_call_t *)linux_vm86old },		/* 113 = linux_vm86old */
  	{ AS(linux_wait4_args), (sy_call_t *)linux_wait4 },	/* 114 = linux_wait4 */
  	{ 0, (sy_call_t *)linux_swapoff },		/* 115 = linux_swapoff */
! 	{ 0, (sy_call_t *)linux_sysinfo },		/* 116 = linux_sysinfo */
  	{ AS(linux_ipc_args), (sy_call_t *)linux_ipc },	/* 117 = linux_ipc */
  	{ AS(fsync_args), (sy_call_t *)fsync },		/* 118 = fsync */
  	{ AS(linux_sigreturn_args), (sy_call_t *)linux_sigreturn },	/* 119 = linux_sigreturn */
--- 133,139 ----
  	{ 0, (sy_call_t *)linux_vm86old },		/* 113 = linux_vm86old */
  	{ AS(linux_wait4_args), (sy_call_t *)linux_wait4 },	/* 114 = linux_wait4 */
  	{ 0, (sy_call_t *)linux_swapoff },		/* 115 = linux_swapoff */
! 	{ AS(linux_sysinfo_args), (sy_call_t *)linux_sysinfo },		/* 116 = linux_sysinfo */
  	{ AS(linux_ipc_args), (sy_call_t *)linux_ipc },	/* 117 = linux_ipc */
  	{ AS(fsync_args), (sy_call_t *)fsync },		/* 118 = fsync */
  	{ AS(linux_sigreturn_args), (sy_call_t *)linux_sigreturn },	/* 119 = linux_sigreturn */
*** ./sys/i386/linux/linux_proto.h.orig	Tue Aug  8 16:28:16 2000
--- ./sys/i386/linux/linux_proto.h	Thu Nov 30 17:41:12 2000
***************
*** 312,318 ****
  	register_t dummy;
  };
  struct	linux_sysinfo_args {
! 	register_t dummy;
  };
  struct	linux_ipc_args {
  	int	what;	char what_[PAD_(int)];
--- 312,318 ----
  	register_t dummy;
  };
  struct	linux_sysinfo_args {
! 	struct linux_sysinfo *  buf;    char buf_[PAD_(struct linux_sysinfo *)];
  };
  struct	linux_ipc_args {
  	int	what;	char what_[PAD_(int)];
*** ./sys/compat/linux/linux_misc.c.orig	Tue Mar 27 18:33:47 2001
--- ./sys/compat/linux/linux_misc.c	Fri May  4 15:53:46 2001
***************
*** 40,45 ****
--- 40,46 ----
  #include <sys/imgact_aout.h>
  #include <sys/mount.h>
  #include <sys/namei.h>
+ #include <sys/resource.h>
  #include <sys/resourcevar.h>
  #include <sys/stat.h>
  #include <sys/sysctl.h>
***************
*** 48,59 ****
--- 49,64 ----
  #include <sys/wait.h>
  #include <sys/time.h>
  #include <sys/signalvar.h>
+ #include <sys/blist.h>
+ #include <sys/vmmeter.h>
  
  #include <vm/vm.h>
  #include <vm/pmap.h>
  #include <vm/vm_kern.h>
  #include <vm/vm_map.h>
  #include <vm/vm_extern.h>
+ #include <vm/vm_object.h>
+ #include <vm/swap_pager.h>
  
  #include <machine/frame.h>
  #include <machine/limits.h>
***************
*** 93,98 ****
--- 98,176 ----
    RLIMIT_MEMLOCK, -1
  };
  #endif /*!__alpha__*/
+ 
+ struct linux_sysinfo {
+      long uptime;              /* Seconds since boot */
+      unsigned long loads[3];   /* 1, 5, and 15 minute load averages */
+      unsigned long totalram;   /* Total usable main memory size */
+      unsigned long freeram;    /* Available memory size */
+      unsigned long sharedram;  /* Amount of shared memory */
+      unsigned long bufferram;  /* Memory used by buffers */
+      unsigned long totalswap;  /* Total swap space size */
+      unsigned long freeswap;   /* swap space still available */
+      unsigned short procs;     /* Number of current processes */
+      char _f[22];              /* Pads structure to 64 bytes */
+ };
+ 
+ int
+ linux_sysinfo(struct proc *p, struct linux_sysinfo_args *args)
+ {
+ 	struct linux_sysinfo sysinfo;
+ 	vm_object_t object;
+ 	int i;
+ 	struct timespec ts;
+ 
+ 	/* Uptime is copied out of print_uptime() procedure in kern_shutdown.c */
+ 	getnanouptime(&ts);
+      i = 0;
+      if (ts.tv_sec >= 86400) {
+           printf("%ldd", ts.tv_sec / 86400);
+           ts.tv_sec %= 86400;
+           i = 1;
+      }
+      if (i || ts.tv_sec >= 3600) {
+           printf("%ldh", ts.tv_sec / 3600);
+           ts.tv_sec %= 3600;
+           i = 1;
+      }
+      if (i || ts.tv_sec >= 60) {
+           printf("%ldm", ts.tv_sec / 60);
+           ts.tv_sec %= 60;
+           i = 1;
+      }
+ 	sysinfo.uptime=ts.tv_sec;
+ 
+ 	/* Use the information from the mib to get our load averages */
+ 	for (i = 0; i < 3; i++)
+ 		sysinfo.loads[i] = (double) averunnable.ldavg[i] / averunnable.fscale;
+ 
+ 	sysinfo.totalram = physmem * PAGE_SIZE;
+ 	sysinfo.freeram = sysinfo.totalram - cnt.v_wire_count * PAGE_SIZE;
+ 
+ 	sysinfo.sharedram = 0;
+ 	for (object = TAILQ_FIRST(&vm_object_list); object != NULL;
+      	object = TAILQ_NEXT(object, object_list))
+               	if (object->shadow_count > 1)
+                   	sysinfo.sharedram += object->resident_page_count;
+ 
+ 	sysinfo.sharedram *= PAGE_SIZE;
+ 
+ 	sysinfo.bufferram = 0;
+ 
+ 	if (swapblist == NULL) {
+      	sysinfo.totalswap= 0;
+      	sysinfo.freeswap = 0;
+ 	} else {
+      	sysinfo.totalswap = swapblist->bl_blocks * 1024;
+      	sysinfo.freeswap = swapblist->bl_root->u.bmu_avail * PAGE_SIZE;
+ 	}
+ 
+ 	sysinfo.procs = 20; /* Hack */
+ 
+ 	return copyout((caddr_t)&sysinfo, (caddr_t)args->buf,
+                sizeof(struct linux_sysinfo));
+ }
+ 
  
  #ifndef __alpha__
  int
>Release-Note:
>Audit-Trail:

From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To: Jim.Pirzyk@disney.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: kern/27759: linux module does not support sysinfo system call
Date: Wed, 30 May 2001 12:11:44 -0400 (EDT)

 <<On Tue, 29 May 2001 18:02:42 -0700 (PDT), Jim.Pirzyk@disney.com said:
 
 > + 		sysinfo.loads[i] = (double) averunnable.ldavg[i] / averunnable.fscale;
 
 Can't use floating-point math in the kernel.
 
 -GAWollman
 

From: Jim Pirzyk <Jim.Pirzyk@disney.com>
To: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>,
	Jim.Pirzyk@disney.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/27759: linux module does not support sysinfo system call
Date: Wed, 30 May 2001 10:27:29 -0700

 On Wednesday 30 May 2001 09:11 am, Garrett Wollman wrote:
 > <<On Tue, 29 May 2001 18:02:42 -0700 (PDT), Jim.Pirzyk@disney.com said:
 > > + 		sysinfo.loads[i] = (double) averunnable.ldavg[i] /
 > > averunnable.fscale;
 >
 > Can't use floating-point math in the kernel.
 
 Upon further inspection, all we need is this:
 
 		sysinfo.loads[i] = averunnable.ldavg[i];
 
 Since both sysinfo.loads and averunnable.ldavg are both arrays
 of longs.
 
 - JimP
 
 -- 
 --- @(#) $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 
 (*)/ (*)  
Responsible-Changed-From-To: freebsd-bugs->pirzyk 
Responsible-Changed-By: pirzyk 
Responsible-Changed-When: Sat Jul 14 22:27:56 PDT 2001 
Responsible-Changed-Why:  
Yet another of my PRs 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=27759 
State-Changed-From-To: open->closed 
State-Changed-By: pirzyk 
State-Changed-When: Sun Jul 22 23:26:24 PDT 2001 
State-Changed-Why:  
Commited a modified patch (removed the printf's) to -current 


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