Old s-gould-np1.c
  1 /* s-gould-np1.c : has _Cptime instead of _cp_time */
  2 
  3 /*
  4  * Hugues Leroy, INRIA, RENNES France <Hugues.Leroy@irisa.fr>
  5  * added support for the Gould NP1
  6  * based on code by
  7  * Chris Siebenmann, University of Toronto <cks@sys.toronto.edu>
  8  * and
  9  * Salvador P. Abreu, U.Nova de Lisboa, PORTUGAL <spa@fctunl.rccn.pt>
 10 */
 11         
 12 /* LINTLIBRARY */
 13 #include <sys/param.h>
 14 #include <sys/dk.h>
 15 #include <nlist.h>
 16 
 17 extern int open(), read();
 18 extern long lseek();
 19 
 20 extern char *kernelSymbols;
 21 
 22 /* NPROCS is now always 2 */
 23 
 24 #define NPROCS 2
 25 
 26 long    cp_time[NPROCS][CPUSTATES];
 27 long    cp_old [NPROCS][CPUSTATES];
 28 int     kmem;                   /* file descriptor of /dev/kmem. */
 29 struct nlist    nl[] = {
 30 #define X_CP_TIME       0
 31         { "_Cptime" },
 32         { "" },
 33 };
 34 
 35 /* Called at the beginning to inquire how many bars are needed. */
 36 int
 37 num_bars()
 38 {
 39     return NPROCS;
 40 }
 41 
 42 /*
 43  * Indicates how many levels each bar has.  For most machines, each bar will
 44  * have the same stuff.  But one can, for instance, display memory use on one
 45  * bar, processor levels on others, etc.
 46  */
 47 void
 48 bar_items(nbars, items)
 49 int nbars;
 50 int items[];    /* nbars items in this */
 51 {
 52     int i;
 53 
 54     for(i = 0; i < nbars; i++)
 55         items[i] = CPUSTATES;
 56 }
 57 
 58 /* Called after num_bars to ask for the bar names */
 59 /* ARGSUSED */
 60 char **
 61 label_bars(nbars)
 62 {
 63     static char *name[NPROCS];
 64 
 65     name[0] = "CPU 1";
 66     name[1] = "CPU 2";
 67     return name;
 68 }
 69 
 70 /* 
 71  *  Called after the bars are created to perform any machine dependent
 72  *  initializations.
 73  */
 74 /* ARGSUSED */
 75 void
 76 init_bars(nbars)
 77 int nbars;
 78 {
 79     
 80     if ((kmem = open("/dev/kmem", 0)) < 0) {
 81             perror("/dev/kmem");
 82             exit(1);
 83     }
 84     (void)nlist(kernelSymbols?kernelSymbols:"/vmunix", nl);
 85     if (lseek(kmem, (long) nl[X_CP_TIME].n_value, 0) !=
 86         (long) nl[X_CP_TIME].n_value)
 87             perror("lseek");
 88     if (read(kmem, (char *) cp_old, sizeof(cp_old)) !=
 89         sizeof(cp_old))
 90             perror("read");
 91 }
 92 
 93 /* 
 94  *  This procedure gets called every interval to compute and display the
 95  *  bars. It should call draw_bar() with the bar number, the array of
 96  *  integer values to display in the bar, and the number of values in
 97  *  the array.
 98  */
 99 /* ARGSUSED */
100 void
101 display_bars(nbars)
102 {
103         int     states[CPUSTATES];
104         int     nstates;
105         int     i,j;
106 
107         
108         if (lseek(kmem, (long) nl[X_CP_TIME].n_value, 0) !=
109             (long) nl[X_CP_TIME].n_value)
110                 perror("lseek");
111         if (read(kmem, (char *) cp_time, sizeof(cp_time)) !=
112             sizeof(cp_time))
113                 perror("read");
114 
115 
116 #define delta(cpustate) ((int) (cp_time[i][(cpustate)] -
117 cp_old[i][(cpustate)]))
118 
119         for (i=0; i<NPROCS; i++) {
120         nstates = 0;
121         states[nstates++] = delta(CP_IDLE);
122         states[nstates++] = delta(CP_USER);
123         states[nstates++] = delta(CP_NICE);
124         states[nstates++] = delta(CP_SYS);
125         draw_bar(i, states, nstates);
126         }
127         for (i = 0; i < CPUSTATES; i ++)
128         for (j=0; j< NPROCS; j++)
129                 cp_old[j][i] = cp_time[j][i];
130 
131 
132 }