New top patch

10 views
Skip to first unread message

Richard Henderson

unread,
May 2, 1995, 3:00:00 AM5/2/95
to
With the aid of a few kind souls, I've been able to produce a version
of top that runs under A/UX 3.0.2. In the process I discovered a few
bugs that affected all systems. In any event, I'd people with the
systems that have, in the past, had the most problems with top, 3.0.x
and AWS95, to give this patch a shot.

The reference distribution can be found at

ftp://eecs.nwu.edu/pub/top/top-3.3.tar.gz

Thanks,

r~

--- display.c.orig Wed Jan 4 18:11:08 1995
+++ display.c Mon May 1 23:11:49 1995
@@ -880,7 +880,7 @@ register char **names;
if (thisname[0] == 'K' && num >= 10000)
{
/* yes: format it as megabytes, rounded */
- p = strecpy(p, itoa((num+500)/1000));
+ p = strecpy(p, itoa((num+512)/1024));

/* replace 'K' with 'M' in string to display */
*p++ = 'M';
--- utils.c.orig Tue Feb 7 23:14:49 1995
+++ utils.c Mon May 1 23:12:46 1995
@@ -405,7 +405,7 @@ int amt;

if (amt >= 10000)
{
- amt = (amt + 500) / 1000;
+ amt = (amt + 512) / 1024;
tag = 'M';
}

--- machine/m_aux31.c.orig Fri Feb 3 15:18:26 1995
+++ machine/m_aux31.c Mon May 1 23:13:14 1995
@@ -1,11 +1,10 @@
/*
* top - a top users display for Unix
*
- * SYNOPSIS: a Mac running A/UX version 3.1
+ * SYNOPSIS: a Mac running A/UX version 3.x
*
* DESCRIPTION:
- * This is the machine-dependent module for A/UX 3.1.
- * It might work on A/UX 3.0.
+ * This is the machine-dependent module for A/UX 3.0 and 3.1
* ==
* Although AUX does not generally have a renice systemcall, it can be
* implemented by tweeking kernel memory. While such a simple hack should
@@ -25,6 +24,7 @@
#include <errno.h>
#include <fcntl.h>
#include <a.out.h>
+#include <syscall.h>
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/param.h>
@@ -32,6 +32,7 @@
#include <sys/user.h>
#include <sys/sysinfo.h>
#include <sys/var.h>
+#include <sys/swap.h>

#define FSCALE 65536.0

@@ -47,22 +48,13 @@
#define X_MAXMEM 3
#define X_FREEMEM 4
#define X_AVAILRMEM 5
-#define X_AVAILSMEM 6
-
-static struct nlist nlst[] = {
- {"v"},
- {"sysinfo"},
- {"avenrun"},
- {"maxmem"},
- {"freemem"},
- {0}, /* "availrmem" */
- {0}, /* "availsmem" */
- {0}
-};
+#define NUMNAMES 6

static int kmem;
static int mem;

+static struct nlist nlst[NUMNAMES];
+
static struct var v;
static int maxmem;

@@ -72,7 +64,6 @@ static int maxmem;
#define MAXMEM_OFS (nlst[X_MAXMEM].n_value)
#define FREEMEM_OFS (nlst[X_FREEMEM].n_value)
#define AVAILRMEM_OFS (nlst[X_AVAILRMEM].n_value)
-#define AVAILSMEM_OFS (nlst[X_AVAILSMEM].n_value)

/*=SYSTEM STATE INFO====================================================*/

@@ -128,7 +119,7 @@ static char *cpustatenames[] =

static char *memorynames[] =
{
- "K real, ", "K free, ", "K free swap, ", "K locked",
+ "K mem avail, ", "K free, ", "K locked, ", "K swap free, ", "K used",
NULL
};

@@ -155,8 +146,12 @@ machine_init(statics)
}

/* get the list of symbols we want to access in the kernel */
+ strcpy(nlst[X_V].n_name, "v");
+ strcpy(nlst[X_SYSINFO].n_name, "sysinfo");
+ strcpy(nlst[X_AVENRUN].n_name, "avenrun");
+ strcpy(nlst[X_MAXMEM].n_name, "maxmem");
+ strcpy(nlst[X_FREEMEM].n_name, "freemem");
nlst[X_AVAILRMEM].n_nptr = "availrmem";
- nlst[X_AVAILSMEM].n_nptr = "availsmem";

if (nlist("/unix", nlst) < 0)
{
@@ -202,7 +197,7 @@ get_system_info(info)
{
load_avg ar[3];

- (void)getkval(AVENRUN_OFS, (char *)&ar, sizeof(ar), "avenrun");
+ (void)getkval(AVENRUN_OFS, (char *)&ar[0], sizeof(ar), "avenrun");

/* convert load averages to doubles */
info->load_avg[0] = loaddouble(ar[0]);
@@ -222,19 +217,35 @@ get_system_info(info)

/* get memory usage information */
{
- int freemem, availrmem, availsmem;
+ int freemem, availrmem, totalswap, freeswap;

(void)getkval(FREEMEM_OFS, (char *)&freemem, sizeof(freemem),
"freemem");
(void)getkval(AVAILRMEM_OFS, (char *)&availrmem, sizeof(availrmem),
"availrmem");
- (void)getkval(AVAILSMEM_OFS, (char *)&availsmem, sizeof(availsmem),
- "availsmem");
+
+ {
+ swpi_t swpi;
+ swpt_t swpt[MSFILES];
+ int i;
+
+ swpi.si_cmd = SI_LIST;
+ swpi.si_buf = (char *)&swpt[0];
+ (void)syscall(SYS_sysm68k_1, 3, &swpi);
+
+ for (i = totalswap = freeswap = 0; i < MSFILES; i++)
+ if (swpt[i].st_dev != 0 && !(swpt[i].st_flags & ST_INDEL))
+ {
+ totalswap += swpt[i].st_npgs;
+ freeswap += swpt[i].st_nfpgs;
+ }
+ }

memory_stats[0] = pagetok(availrmem - freemem);
memory_stats[1] = pagetok(freemem);
- memory_stats[2] = pagetok(availsmem - availrmem);
- memory_stats[3] = pagetok(maxmem - availrmem);
+ memory_stats[2] = pagetok(maxmem - availrmem);
+ memory_stats[3] = pagetok(freeswap);
+ memory_stats[4] = pagetok(totalswap - freeswap);
}

info->last_pid = -1;
@@ -259,7 +270,7 @@ get_process_info(si, sel, compare)
int show_idle, show_system, show_uid, show_command;

/* calculate the time difference since our last check */
- gettimeofday(&thistime);
+ gettimeofday(&thistime, NULL);
if (lasttime.tv_sec)
timediff = ((thistime.tv_sec - lasttime.tv_sec) +
(thistime.tv_usec - lasttime.tv_usec) * 1e-6);
@@ -327,7 +338,7 @@ get_process_info(si, sel, compare)
/* calculate relevant metrics */
percent_cpu(pp1) = 0.0;
if (pp1->p_pid == pp2->p_pid)
- weighted_cpu(pp1) = percent_cpu(pp2) * beta;
+ weighted_cpu(pp1) = weighted_cpu(pp2) * beta;
else
weighted_cpu(pp1) = 0.0;
}
@@ -348,15 +359,19 @@ get_process_info(si, sel, compare)
if (pp1->p_pid == pp2->p_pid)
{
percent_cpu(pp1) =
- (pp1->p_utime - pp2->p_utime +
- pp1->p_stime - pp2->p_stime) / (v.v_hz * timediff);
+ (double)(pp1->p_utime - pp2->p_utime +
+ pp1->p_stime - pp2->p_stime) /
+ (double)(v.v_hz * timediff);
weighted_cpu(pp1) =
- percent_cpu(pp2) * beta + percent_cpu(pp1) * alpha;
+ percent_cpu(pp1) * alpha + weighted_cpu(pp2) * beta;
}
else
{
- weighted_cpu(pp1) = percent_cpu(pp1) =
- (pp1->p_utime + pp1->p_stime) / (v.v_hz * timediff);
+ percent_cpu(pp1) =
+ (double)(pp1->p_utime + pp1->p_stime) /
+ (double)(v.v_hz * timediff);
+ weighted_cpu(pp1) =
+ percent_cpu(pp1) * alpha;
}
}

@@ -600,7 +615,7 @@ setpriority(which, pid, val)
errno = ENOSYS;
return -1;
#else
- int ofs, uid;
+ int ofs, euid;
struct proc *pp;

/* sanity check arguments */
@@ -621,10 +636,10 @@ setpriority(which, pid, val)
}

/* make sure we don't allow nasty people to do nasty things */
- uid = getuid();
- if (uid != 0)
+ euid = geteuid();
+ if (euid != 0)
{
- if (uid != pp->p_uid || val < pp->p_nice)
+ if ((euid != pp->p_uid && getuid() != pp->p_uid) || val < pp->p_nice)
{
errno = EACCES;
return -1;

hotz

unread,
May 2, 1995, 3:00:00 AM5/2/95
to
According to the FAQ version 3.1.1 does not work on the original Mac II
class machines. According to some discussion here, that was only
because a certain config file was left out of the updater due to space
reasons.

Given that you get a copy of that file (where exactly is it anyway)
what is the word on the latest version of A/UX on those machines? Does
it really work? Should I upgrade to 3.1 before it's too late?

Nathan Neulinger

unread,
May 3, 1995, 3:00:00 AM5/3/95
to
In article <1995May2.2...@wdl.loral.com>,
ho...@ferrari.libra.loral.com (hotz) wrote:

After speaking with Jim about this, it has been stragihtened out a bit...
According to him, there are lots of problems with the Mac os and old II
class machines with 3.1. However, I have been running 3.1.x on a Mac IIx
with 8mb of ram for months without the mac os running... It works great. I
only use the mac os occasionally for formattting drives and stuff.

-- Nathan

------------------------------------------------------------------
Nathan Neulinger Univ. of Missouri - Rolla
EMail: nn...@umr.edu Computer Center
WWW: http://www.umr.edu/~nneul SysAdmin: pluto.cc.umr.edu
WWW: http://pluto.cc.umr.edu SysAdmin: rollanet.org
------------------------------------------------------------------
These oppinions are my own. I do not speak for Computing Services.

hotz

unread,
May 5, 1995, 3:00:00 AM5/5/95
to
In article <nneul-03059...@nneul.student.umr.edu>
nn...@umr.edu (Nathan Neulinger) writes:

> After speaking with Jim about this, it has been stragihtened out a bit...
> According to him, there are lots of problems with the Mac os and old II

> class machines with 3.1. . . .

Bummer! I've got an NEC CD-Rom drive.

Hey Jim! Could I get you to mention this, and where to get the patch
file in the FAQ? I know it's pretty big already, but *I* care.

Christopher Penney

unread,
May 5, 1995, 3:00:00 AM5/5/95
to
Richard Henderson (ric...@atheist.tamu.edu) wrote:
: With the aid of a few kind souls, I've been able to produce a version

: of top that runs under A/UX 3.0.2. In the process I discovered a few
: bugs that affected all systems. In any event, I'd people with the
: systems that have, in the past, had the most problems with top, 3.0.x
: and AWS95, to give this patch a shot.
:
: The reference distribution can be found at
:
: ftp://eecs.nwu.edu/pub/top/top-3.3.tar.gz
:
: Thanks,
:
: r~

I thought I save the article on the problem with top displaying
garbage in the process name field, but I must not have. I have 3.1.1
and compiled top (from the above location) with and without the patch
and it yeilds the same result. What am I doing wrong?

-=Chris=-


Jim Jagielski

unread,
May 5, 1995, 3:00:00 AM5/5/95
to
ho...@ferrari.libra.loral.com (hotz) writes:

The stuff about 3.1.1 and the MacII is in there already.... As far as I
know, the Patch file doesn't exist anywhere :(
--
Jim Jagielski << j...@jaguNET.com >> | "Stwike him Centuwian, vewy woughwy!"
** jaguNET Access Services ** | - Pontius Piwate
++ Email: in...@jaguNET.com +++ Voice: 410-931-3157 ++
++ http://www.jaguNET.com +++ Data: 931-7060 ("guest") ++

Fred Condo

unread,
May 5, 1995, 3:00:00 AM5/5/95
to
In article <3odui5$18...@msunews.cl.msu.edu>, pen...@isl.msu.edu
(Christopher Penney) wrote:

>Richard Henderson (ric...@atheist.tamu.edu) wrote:
>: With the aid of a few kind souls, I've been able to produce a version


>: of top that runs under A/UX 3.0.2. In the process I discovered a few
>: bugs that affected all systems. In any event, I'd people with the
>: systems that have, in the past, had the most problems with top, 3.0.x
>: and AWS95, to give this patch a shot.
>:
>: The reference distribution can be found at
>:
>: ftp://eecs.nwu.edu/pub/top/top-3.3.tar.gz
>:
>: Thanks,
>:
>: r~
>

>I thought I save the article on the problem with top displaying
>garbage in the process name field, but I must not have. I have 3.1.1
>and compiled top (from the above location) with and without the patch
>and it yeilds the same result. What am I doing wrong?
>
>-=Chris=-

I don't think you're doing anything wrong. The patched version still gives
me garbage on a Q950.
--
Fred Condo + fr...@lightside.net + http://www.lightside.net/fred/
Lightside, Inc. + Internet access + http://www.lightside.net/
PGP public key: finger fr...@lightside.com

Chuq Von Rospach

unread,
May 10, 1995, 3:00:00 AM5/10/95
to
fr...@lightside.net (Fred Condo) writes:

>I don't think you're doing anything wrong. The patched version still gives
>me garbage on a Q950.

Good. It's not just me.

My first guess is that it's memory related. The same top binary worked great
on a 20 meg IIfx and a 32 meg WS95, but I have a 64 meg WS95 that it gets
garbage on. Does that correlate with other's memory footprints? it's
possible there's some internal pointer that can't handle large memory
footprints.

--
Chuq Von Rospach -=- Author, Software Gnome, and Internet Guy
Member Science Fiction & Fantasy Writers of America

Plaidworks Consulting: Writing, Editing, and Damage Control

<http://plaidworks.com/chuqui/> * GEnie:chuq * CIS:75141,1242
chu...@plaidworks.com * ch...@abs.apple.com * AOL:chuqui

Christopher Penney

unread,
May 11, 1995, 3:00:00 AM5/11/95
to
Chuq Von Rospach (chu...@plaidworks.com) wrote:
: My first guess is that it's memory related. The same top binary worked great

: on a 20 meg IIfx and a 32 meg WS95, but I have a 64 meg WS95 that it gets
: garbage on. Does that correlate with other's memory footprints? it's
: possible there's some internal pointer that can't handle large memory
: footprints.

My machine is getting garbage and it's a WGS 95 with 64mb RAM too. I
have 512k of L2 cache (though that really shouldn't matter).

-=Chris=-


Jim Jagielski

unread,
May 11, 1995, 3:00:00 AM5/11/95
to
chu...@plaidworks.com (Chuq Von Rospach) writes:

>fr...@lightside.net (Fred Condo) writes:

>>I don't think you're doing anything wrong. The patched version still gives
>>me garbage on a Q950.

>Good. It's not just me.

Not to be a ditto-head, but me too...

All my machines have at least 64MB and all show the above behavior. Haven't
tried it yet on a Q610 with 36MB... might be a good data point :)

If someone will Email the site for this complete top package, I'll try to
take a quick look...


--
Jim Jagielski << j...@jaguNET.com >> | "Stwike him Centuwian, vewy woughwy!"
** jaguNET Access Services ** | - Pontius Piwate
++ Email: in...@jaguNET.com +++ Voice: 410-931-3157 ++

++ http://www.jaguNET.com/ +++ Data: 931-7060 ("guest") ++

Fred Condo

unread,
May 12, 1995, 3:00:00 AM5/12/95
to
In article <3oqn65$l...@news.znet.com>, chu...@plaidworks.com (Chuq Von
Rospach) wrote:

>fr...@lightside.net (Fred Condo) writes:
>
>>I don't think you're doing anything wrong. The patched version still gives
>>me garbage on a Q950.
>
>Good. It's not just me.
>

>My first guess is that it's memory related. The same top binary worked great
>on a 20 meg IIfx and a 32 meg WS95, but I have a 64 meg WS95 that it gets
>garbage on. Does that correlate with other's memory footprints? it's
>possible there's some internal pointer that can't handle large memory
>footprints.
>

Our Q950 has 36 megs of RAM.

Eric Hagberg

unread,
May 13, 1995, 3:00:00 AM5/13/95
to
One of mine has 32MB, and has no trouble w/ top. The other has 40MB and
gets garbage.

-ech

______________________________________________________
Eric Hagberg Phone: 212-746-6387
User Services Manager, CUMC/OAC Fax: 212-746-8161

Neil Harkins

unread,
May 17, 1995, 3:00:00 AM5/17/95
to
Eric Hagberg (hag...@mail.med.cornell.edu) wrote:
: One of mine has 32MB, and has no trouble w/ top. The other has 40MB and
: gets garbage.

Pardon my ignorance, but what is "top"?

-Neil Harkins
st92...@dunx1.ocs.drexel.edu

Christopher Penney

unread,
May 17, 1995, 3:00:00 AM5/17/95
to
Neil Harkins (st92...@dunx1.ocs.drexel.edu) wrote:

It's like 'ps' only better. It shows you a list of processes like this:

load averages: 2.01, 1.58, 1.27 22:03:24
35 processes: 33 sleeping, 1 running, 1 stopped, 1 on cpu
Cpu states: 0.0% idle, 54.1% user, 45.9% kernel, 0.0% wait, 0.0% nice
Memory: 24M real, 12M free, 36M free swap, 30M locked

PID PGRP USERNAME PRI NICE SIZE STATE TIME WCPU CPU COMMAND
489 478 root 54 -20 17M run 479:32 99.18% 99.18% startmac
3844 3844 penney 31 -4 216K cpu 0:00 0.80% 0.41% top
490 478 root -25 -20 17M sleep 69:47 0.03% 0.41% CommandShell
1 0 root 14 0 136K sleep 0:00 0.00% 0.00% @?:@?^
204 0 root 1 0 168K sleep 0:21 0.00% 0.00% rpc.statd
278 278 root 1 0 308K sleep 0:00 0.00% 0.00% aufs
3743 3743 root 1 0 168K sleep 0:00 0.00% 0.00% in.telnetd
216 212 root 1 0 164K sleep 0:00 0.00% 0.00% in.routed
10168 10168 root 1 -4 536K sleep 0:07 0.00% 0.00% httpd
183 182 root 1 0 292K sleep 89:07 0.00% 0.00% ypserv
192 191 root 1 0 4K sleep 7:56 0.00% 0.00% nfsd
195 191 root 1 0 4K sleep 7:40 0.00% 0.00% nfsd
194 191 root 1 0 4K sleep 7:14 0.00% 0.00% nfsd
196 191 root 1 0 4K sleep 7:28 0.00% 0.00% nfsd
3744 3744 penney 14 -4 588K sleep 0:00 0.00% 0.00% tcsh

The display changes every few seconds or when you press the space bar.
It's really nice and always shows the processes in order of what is
getting the most CPU. It the above expample someone was no doubt
coping stuff from our file server.

Nice, eh? And free too...

-=Chris=-


Reply all
Reply to author
Forward
0 new messages