2 * cpu_irix.c - module to get cpu usage, for IRIX 6.5 and IRIX64 6.5
4 * Copyright (C) 2002 Jonathan C. Patschke <jp@celestrion.net>
5 * Copyright (C) 2002 Seiichi SATO <ssato@sh.rim.or.jp>
7 * licensed under the GPL
20 #include <sys/types.h>
21 #include <sys/sysmp.h>
22 #include <sys/sysinfo.h>
23 #include <sys/sysget.h>
30 cpuCount
= (int)sysmp(MP_NPROCS
);
34 /* returns current CPU usage in percent */
36 cpu_get_usage(cpu_options
*opts
)
38 struct sgt_cookie cookie
;
40 long cpuload
, cputotal
;
41 static long ocpuload
, ocputotal
;
44 if (opts
->cpu_number
>= cpuCount
) return 0;
45 SGT_COOKIE_INIT(&cookie
);
46 if (opts
->cpu_number
< 1) {
47 /* Get stats for all CPUs */
50 for (i
= 0 ; i
< cpuCount
; i
++) {
51 SGT_COOKIE_SET_CPU(&cookie
, i
);
52 memset(((void *)&info
), 0x00, sizeof(info
));
53 sysget(SGT_SINFO_CPU
, ((char *)&info
), sizeof(info
),
55 cpuload
+= info
.cpu
[CPU_USER
] + info
.cpu
[CPU_KERNEL
] +
56 info
.cpu
[CPU_WAIT
] + info
.cpu
[CPU_SXBRK
] +
58 cputotal
+= cpuload
+ info
.cpu
[CPU_IDLE
];
61 SGT_COOKIE_SET_CPU(&cookie
, opts
->cpu_number
);
62 memset(((void *)&info
), 0x00, sizeof(info
));
63 sysget(SGT_SINFO_CPU
, ((char *)&info
), sizeof(info
),
65 cpuload
= info
.cpu
[CPU_USER
] + info
.cpu
[CPU_KERNEL
] +
66 info
.cpu
[CPU_WAIT
] + info
.cpu
[CPU_SXBRK
] +
68 cputotal
= cpuload
+ info
.cpu
[CPU_IDLE
];
71 fprintf(stderr
, "!!!%d/%d: %d, %d, %d, %d, %d, %d\n", opts
->cpu_number
,
72 cpuCount
, info
.cpu
[CPU_USER
], info
.cpu
[CPU_KERNEL
], info
.cpu
[CPU_WAIT
],
73 info
.cpu
[CPU_SXBRK
], info
.cpu
[CPU_INTR
], info
.cpu
[CPU_IDLE
]);
76 result
= ((cpuload
- ocpuload
) * 100) / (cputotal
- ocputotal
);