1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
/* System dependent file for Silicon Graphics Iris4d systems */
/* Mark Moraes, ANT, University of Toronto <moraes@cs.toronto.edu> */
/* LINTLIBRARY */
#include <stdio.h>
#include <sys/types.h>
#include <sys/sysmp.h>
#include <sys/sysinfo.h>
extern int sysmp(/* int opcode, opcode_specific_args */);
extern char *xmalloc(/* int nbytes */);
static int *errs;
static struct sysinfo **si;
static struct sysinfo **last_si;
static struct sysinfo **tmp_si;
/* Called at the beginning to inquire how many bars are needed. */
int
num_bars()
{
return sysmp(MP_NPROCS);
}
/* Called after num_bars to ask for the bar names */
/* ARGSUSED */
char **
label_bars(nbars)
{
char **names;
int i;
extern char *strcpy(/* char *, const char * */);
names = (char **) xmalloc(nbars * sizeof(char *));
for(i = 0; i < nbars; i++) {
#define CPUNAME "%d"
char buf[sizeof(CPUNAME) + 32];
(void) sprintf(buf, CPUNAME, i);
names[i] = strcpy(xmalloc(strlen(buf) + 1), buf);
}
return names;
}
/*
* Called after the bars are created to perform any machine dependent
* initializations.
*/
void
init_bars(nbars)
int nbars;
{
int i;
int ret;
/* Initialize sysinfo by taking first reading */
last_si = (struct sysinfo **) xmalloc(nbars * sizeof(struct sysinfo *));
si = (struct sysinfo **) xmalloc(nbars * sizeof(struct sysinfo *));
errs = (int *) xmalloc(nbars * sizeof(int));
for(i = 0; i < nbars; i++) {
last_si[i] = (struct sysinfo *) xmalloc(sizeof(struct sysinfo));
si[i] = (struct sysinfo *) xmalloc(sizeof(struct sysinfo));
errs[i] = 0;
ret = sysmp(MP_SAGET1, MPSA_SINFO, (int) last_si[i],
sizeof(struct sysinfo), i);
if (ret != 0) {
(void) fprintf(stderr,
"sysmp(MP_SAGET1, MPSA_SINFO) returned %d on processor %d\n",
ret, i);
(void) fflush(stderr);
errs[i]++;
continue;
}
}
}
/*
* This procedure gets called every interval to compute and display the
* bars. It should call draw_bar() with the bar number, the array of
* integer values to display in the bar, and the number of values in
* the array.
*/
/* ARGSUSED */
void
display_bars(nbars)
{
struct sysinfo dummy;
int states[sizeof(dummy.cpu)/sizeof(time_t)];
int nstates;
int ret;
int i;
extern void draw_bar(/*int bar_num, int *states, int num_states*/);
for(i = 0; i < nbars; i++) {
if (errs[i] != 0)
continue;
ret = sysmp(MP_SAGET1, MPSA_SINFO, (int) si[i],
sizeof(struct sysinfo), i);
if (ret != 0) {
(void) fprintf(stderr,
"sysmp(MP_SAGET1, MPSA_SINFO) returned %d on processor %d\n",
ret, i);
(void) fflush(stderr);
errs[i]++;
continue;
}
#define delta(cpustate) \
((int) (si[i]->cpu[(cpustate)] - last_si[i]->cpu[(cpustate)]))
nstates = 0;
states[nstates++] = delta(CPU_IDLE) + delta(CPU_WAIT);
states[nstates++] = delta(CPU_USER);
states[nstates++] = delta(CPU_KERNEL);
states[nstates++] = delta(CPU_SXBRK);
states[nstates++] = delta(CPU_INTR);
draw_bar(i, states, nstates);
}
tmp_si = last_si;
last_si = si;
si = tmp_si;
}
|