Old s-unicos.c
  1 /*
  2  * System dependent file for Cray Unicos >= 5.1 Systems
  3  * Walter D. Poxon, Cray Research, Inc., Eagan, MN  <wdp@cray.com>
  4  */
  5 
  6 #include <nlist.h>
  7 #include <sys/types.h>
  8 #include <sys/fcntl.h>
  9 #include <sys/unistd.h>
 10 #include <sys/param.h>
 11 #include <sys/pws.h>
 12 #include <errno.h>
 13 
 14 #define UNICOS "/unicos"
 15 #define KMEM "/dev/kmem"
 16 
 17 #define NSTATES 6
 18 #define NCPUSTATES 3
 19 
 20 int num_bars(void);
 21 void bar_items(int nbars, int items[]);
 22 char ** label_bars(int nbars);
 23 void init_bars(int nbars);
 24 void display_bars(int nbars);
 25 
 26 static struct nlist nl[] = { {"cpuw"},{0} };
 27 int kmem;
 28 long bytes;
 29 struct pw cpuw;
 30 
 31 extern int sep_wait;
 32 extern char *kernelSymbols;
 33 
 34 extern char *xmalloc(/* int nbytes */);
 35 
 36 union cpu_name {
 37         word wval;
 38         struct {
 39                 uint : 32,
 40                 c    : 8,
 41                 p    : 8,
 42                 u    : 8,
 43                 no   : 8;
 44         } cval;
 45 };
 46 
 47 
 48 /* Called at the beginning to inquire how many bars are needed. */
 49 int
 50 num_bars(void)
 51 {
 52         bzero(&cpuw,sizeof(cpuw));
 53 
 54         if (nlist(kernelSymbols?kernelSymbols:UNICOS,nl) == -1) {
 55                 perror("nlist");
 56                 return 0;
 57         }
 58 
 59         bytes = nl[0].n_value;
 60         
 61         if ((kmem = open(KMEM, O_RDONLY)) <0) {
 62                 perror("open");
 63                 return 0;
 64         }
 65 
 66         if (lseek(kmem, bytes, SEEK_SET) != bytes) {
 67                 perror("lseek");
 68                 return 0;
 69         }
 70         
 71 
 72         if (read(kmem, &cpuw, sizeof(cpuw)) != sizeof(cpuw)){
 73                 perror("read");
 74                 return 0;
 75         }
 76 
 77         return cpuw.pw_ccpu;       /* Number of CPU's configured in UNICOS */
 78 }
 79 
 80 
 81 /*
 82  * Indicates how many levels each bar has.  For most machines, each bar will
 83  * have the same stuff.  But one can, for instance, display memory use on one
 84  * bar, processor levels on others, etc.
 85  */
 86 void
 87 bar_items(int nbars, int items[])
 88 {
 89         int i;
 90         
 91         for (i = 0; i < nbars; i++)
 92                 items[i] = NCPUSTATES;
 93 }
 94 
 95 
 96 char **
 97 label_bars(int nbars)          /* Called after num_bars to ask for bar names */
 98 {
 99         char **names;
100         int i;
101         extern char *strcpy(/* char *, const char * */);
102         union cpu_name c;
103 
104         names = (char **) xmalloc(nbars * sizeof(char *));
105 
106         for (i = 0; i < nbars; i++) {
107                 char buf[8];
108                 c.wval = cpuw.pws[i].pw_cpu;
109                 sprintf(buf, "%c%c%c%c", c.cval.c, c.cval.p, c.cval.u,
110                         c.cval.no);
111                 names[i] = strcpy(xmalloc(strlen(buf)+1), buf);
112         }
113 
114         return names;
115 }
116 
117 
118 /* 
119  *  Called after the bars are created to perform any machine dependent
120  *  initializations.
121  */
122 void
123 init_bars(int nbars)
124 {
125         display_bars(nbars);
126 }
127 
128 
129 /* 
130  *  This procedure gets called every interval to compute and display the
131  *  bars. It should call draw_bar() with the bar number, the array of
132  *  integer values to display in the bar, and the number of values in
133  *  the array.
134  */
135 
136 #define delta(cpustate) \
137   ((int) (si[i]->cpu[(cpustate)] - last_si[i]->cpu[(cpustate)]))
138 
139 void
140 display_bars(int nbars)
141 {
142         int states[NSTATES];
143         int nstates;
144         int cpu;
145         extern void draw_bar(/*int bar_num, int *states, int num_states*/);
146 
147         if (lseek(kmem, bytes, SEEK_SET) != bytes) {
148                 perror("lseek");
149                 return;
150         }
151         
152     
153         if (read(kmem, &cpuw, sizeof(cpuw)) != sizeof(cpuw)) {
154                 perror("read");
155                 return;
156         }
157         
158 
159         for (cpu=0; cpu < nbars; cpu++) {
160                 nstates = 0;
161 
162                 if(sep_wait){
163                         states[nstates++] = cpuw.pws[cpu].pw_idlee;
164                         states[nstates++] = cpuw.pws[cpu].pw_syswe;
165                 } else {        
166                         states[nstates++] = cpuw.pws[cpu].pw_syswe
167                                 + cpuw.pws[cpu].pw_idlee;
168                 }
169                 states[nstates++] = cpuw.pws[cpu].pw_usere;
170                 states[nstates++] = cpuw.pws[cpu].pw_unixe;
171 
172                 draw_bar(cpu, states, nstates);
173         }
174 }