[comp.unix.ultrix] xcpustate for Ultrix multiprocessors

spa@fctunl.rccn.pt (Salvador Pinto Abreu) (03/15/90)

This patches s.c and adds a new file s-ultrix.c that draws separate
bars for all the active processors on the system.

Apply the patch file (patch <s.c.diff) and recompile. It relies on
the cpp symbol `ultrix' being defined, I think this is true on both
VAX and RISC.

I tried it on a VAXstation 3540 (4 CPUs) but I expect it to work on
other configurations as well (DECsystem 5820 anyone?).

Enjoy,
/.salvador
------------------------------------------------------------------------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  s.c.diff s-ultrix.c
# Wrapped by sources@zen on Wed Mar 14 19:31:40 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f s.c.diff -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"s.c.diff\"
else
echo shar: Extracting \"s.c.diff\" \(337 characters\)
sed "s/^X//" >s.c.diff <<'END_OF_s.c.diff'
X*** /usr/users/sources/.backup/s.c	Wed Mar 14 12:34:58 1990
X--- s.c	Wed Mar 14 19:21:52 1990
X***************
X*** 15,20 ****
X--- 15,25 ----
X  # define s_included
X  #endif
X  
X+ #ifdef ultrix
X+ # include "s-ultrix.c"
X+ # define s_included
X+ #endif
X+ 
X  /* This should work on most BSD machines */
X  #ifndef s_included
X  # include "s-bsd.c"
END_OF_s.c.diff
if test 337 -ne `wc -c <s.c.diff`; then
    echo shar: \"s.c.diff\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f s-ultrix.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"s-ultrix.c\"
else
echo shar: Extracting \"s-ultrix.c\" \(3320 characters\)
sed "s/^X//" >s-ultrix.c <<'END_OF_s-ultrix.c'
X/*
X * System dependent file for BSD derivatives that have _cp_time in their
X * kernels to hold the CPU states. Seen to work on SunOS and Ultrix.
X */
X/* Salvador P. Abreu, U.Nova de Lisboa, PORTUGAL <spa@fctunl.rccn.pt>
X	based on code by
X   Chris Siebenmann, CSRI, University of Toronto <cks@white.toronto.edu> */
X/* LINTLIBRARY */
X#include <sys/param.h>
X#include <sys/dk.h>
X#include <sys/cpudata.h>
X#include <nlist.h>
X
X#define kmseek(N) if (lseek(kmem, (long) (N), 0) != (long) (N)) perror ("lseek kmem");
X
Xextern char *xmalloc(/* int nbytes */);
X
Xextern int open(), read();
Xextern long lseek();
X
Xstruct cpudata *cpu_data = NULL;
Xlong **cptime_old = NULL;
X
Xint	kmem;			/* file descriptor of /dev/kmem. */
Xstruct nlist	nl[] = {
X#define X_ACTIVECPU 0
X	{ "_activecpu" },	/* number of active CPUs */
X#define X_CPUDATA 1
X	{ "_cpudata" },		/* cpudata[] array */
X	{ 0 },
X};
X
Xint activecpu;
X
X/* Called at the beginning to inquire how many bars are needed. */
Xint
Xnum_bars()
X{
X    if ((kmem = open("/dev/kmem", 0)) < 0) {
X	perror("/dev/kmem");
X	exit(1);
X    }
X    (void) nlist("/vmunix", nl);
X
X    kmseek (nl[X_ACTIVECPU].n_value);
X    if (read (kmem, (char *) &activecpu, sizeof (activecpu)) !=
X	sizeof (activecpu))
X	perror ("read kmem");
X    return (activecpu);
X}
X
X/* Called after num_bars to ask for the bar names */
X/* ARGSUSED */
Xchar **
Xlabel_bars(nbars)
X{
X    static char **names;
X    static char hname[MAXHOSTNAMELEN];
X    int i;
X
X    names = (char **) malloc (nbars * sizeof (char *));
X    for (i=0; i<nbars; i++) {
X	names[i] = (char *) malloc (strlen("cpuxxx")+1);
X	sprintf (names[i], "cpu%d", i);
X    }
X    return names;
X}
X
X/* 
X *  Called after the bars are created to perform any machine dependent
X *  initializations.
X */
X/* ARGSUSED */
Xvoid init_bars(nbars)
X    int nbars;
X{
X    int cpu, i;
X
X    cpu_data = (struct cpudata *) malloc (nbars * sizeof(struct cpudata));
X    
X    kmseek (nl[X_CPUDATA].n_value);
X
X    if (read(kmem, (char *) cpu_data, nbars*sizeof(struct cpudata)) !=
X	nbars*sizeof(struct cpudata))
X	perror("read");
X	
X    cptime_old = (long **) malloc (nbars * sizeof (long *));
X    for (cpu=0; cpu<nbars; ++cpu) {
X	cptime_old[cpu] = (long *) malloc (CPUSTATES * sizeof (long));
X	for (i = 0; i < CPUSTATES; i ++)
X	    cptime_old[cpu][i] = cpu_data[cpu].c_cptime[i];
X    }
X}
X
X/* 
X *  This procedure gets called every interval to compute and display the
X *  bars. It should call draw_bar() with the bar number, the array of
X *  integer values to display in the bar, and the number of values in
X *  the array.
X */
X/* ARGSUSED */
Xvoid
Xdisplay_bars(nbars)
X{
X    int	states[CPUSTATES];
X    int	nstates;
X    int	i, cpu;
X    extern void draw_bar(	/*int bar_num, int *states, int num_states*/);
X	
X    kmseek (nl[X_CPUDATA].n_value);
X
X    if (read(kmem, (char *) cpu_data, nbars*sizeof(struct cpudata)) !=
X	nbars*sizeof(struct cpudata))
X	perror("read");
X
X#define delta(cpu, cpustate) \
X    ((int) (cpu_data[cpu].c_cptime[(cpustate)] - cptime_old[cpu][(cpustate)]))
X
X    for (cpu=0; cpu<nbars; ++cpu) {
X	nstates = 0;
X	states[nstates++] = delta(cpu, CP_IDLE);
X	states[nstates++] = delta(cpu, CP_USER);
X	states[nstates++] = delta(cpu, CP_NICE);
X	states[nstates++] = delta(cpu, CP_SYS);
X
X	draw_bar(cpu, states, nstates);
X
X	for (i = 0; i < CPUSTATES; i ++)
X	    cptime_old[cpu][i] = cpu_data[cpu].c_cptime[i];
X    }
X}
END_OF_s-ultrix.c
if test 3320 -ne `wc -c <s-ultrix.c`; then
    echo shar: \"s-ultrix.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
--
---
Salvador Pinto