| 1 |
/* |
| 2 |
* pstat() interface |
| 3 |
* e.g. HP-UX |
| 4 |
*/ |
| 5 |
#include <net-snmp/net-snmp-config.h> |
| 6 |
#include <net-snmp/net-snmp-includes.h> |
| 7 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 8 |
#include <net-snmp/agent/hardware/cpu.h> |
| 9 |
|
| 10 |
#include <stdlib.h> |
| 11 |
#include <unistd.h> |
| 12 |
#include <sys/types.h> |
| 13 |
|
| 14 |
#include <sys/pstat.h> |
| 15 |
#include <sys/dk.h> |
| 16 |
|
| 17 |
|
| 18 |
/* |
| 19 |
* Initialise the list of CPUs on the system |
| 20 |
* (including descriptions) |
| 21 |
*/ |
| 22 |
void init_cpu_pstat( void ) { |
| 23 |
int i, cpuversion; |
| 24 |
struct pst_dynamic psd; |
| 25 |
struct pst_processor *psp; |
| 26 |
char descr[ SNMP_MAXBUF ]; |
| 27 |
netsnmp_cpu_info *cpu = netsnmp_cpu_get_byIdx( -1, 1 ); |
| 28 |
strcpy(cpu->name, "Overall CPU statistics"); |
| 29 |
|
| 30 |
#ifdef _SC_CPU_VERSION |
| 31 |
cpuversion = sysconf( _SC_CPU_VERSION ); |
| 32 |
switch (cpuversion) { |
| 33 |
case CPU_HP_MC68020: |
| 34 |
snprintf(descr, SNMP_MAXBUF, " Motorola MC68020 "); |
| 35 |
break; |
| 36 |
case CPU_HP_MC68030: |
| 37 |
snprintf(descr, SNMP_MAXBUF, " Motorola MC68030 "); |
| 38 |
break; |
| 39 |
case CPU_HP_MC68040: |
| 40 |
snprintf(descr, SNMP_MAXBUF, " Motorola MC68040 "); |
| 41 |
break; |
| 42 |
case CPU_PA_RISC1_0: |
| 43 |
snprintf(descr, SNMP_MAXBUF, " HP PA-RISC 1.0 "); |
| 44 |
break; |
| 45 |
case CPU_PA_RISC1_1: |
| 46 |
snprintf(descr, SNMP_MAXBUF, " HP PA-RISC 1.1 "); |
| 47 |
break; |
| 48 |
case CPU_PA_RISC1_2: |
| 49 |
snprintf(descr, SNMP_MAXBUF, " HP PA-RISC 1.2 "); |
| 50 |
break; |
| 51 |
case CPU_PA_RISC2_0: |
| 52 |
snprintf(descr, SNMP_MAXBUF, " HP PA-RISC 2.0 "); |
| 53 |
break; |
| 54 |
default: |
| 55 |
snprintf(descr, SNMP_MAXBUF, "An electronic chip with an HP label"); |
| 56 |
break; |
| 57 |
} |
| 58 |
#else |
| 59 |
snprintf(descr, SNMP_MAXBUF, "An electronic chip without(?) an HP label"); |
| 60 |
#endif |
| 61 |
|
| 62 |
(void)memset(&psd, 0, sizeof(struct pst_dynamic)); |
| 63 |
if (pstat_getdynamic(&psd, sizeof(psd), 1, 0) > 0) { |
| 64 |
size_t nspu = psd.psd_max_proc_cnt; |
| 65 |
psp = (struct pst_processor *) |
| 66 |
malloc(nspu * sizeof(struct pst_processor)); |
| 67 |
(void)memset(psp, 0, nspu * sizeof(struct pst_processor)); |
| 68 |
if (pstat_getprocessor(psp, sizeof(struct pst_processor), nspu, 0) != -1) { |
| 69 |
for (i = 0; i < nspu; i++) { |
| 70 |
if (psp[i].psp_processor_state == PSP_SPU_ENABLED) { |
| 71 |
cpu = netsnmp_cpu_get_byIdx( i, 1 ); |
| 72 |
sprintf( cpu->name, "cpu%d", i ); |
| 73 |
sprintf( cpu->descr, descr ); |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
free(psp); |
| 78 |
} |
| 79 |
cpu_num = psd.psd_proc_cnt; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
/* |
| 84 |
* Load the latest CPU usage statistics |
| 85 |
*/ |
| 86 |
int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) |
| 87 |
{ |
| 88 |
int i; |
| 89 |
struct pst_dynamic psd; |
| 90 |
struct pst_processor *psp; |
| 91 |
struct pst_vminfo psv; |
| 92 |
netsnmp_cpu_info *cpu = netsnmp_cpu_get_byIdx( -1, 0 ); |
| 93 |
|
| 94 |
if (pstat_getdynamic(&psd, sizeof(psd), 1, 0) > 0) { |
| 95 |
size_t nspu = psd.psd_max_proc_cnt; |
| 96 |
/* XXX - Compare cpu_num against psd.psd_proc_cnt */ |
| 97 |
cpu->user_ticks = (unsigned long long)psd.psd_cpu_time[CP_USER]; |
| 98 |
cpu->nice_ticks = (unsigned long long)psd.psd_cpu_time[CP_NICE]; |
| 99 |
cpu->sys2_ticks = (unsigned long long)psd.psd_cpu_time[CP_SYS]+ |
| 100 |
(unsigned long long)psd.psd_cpu_time[CP_WAIT]; |
| 101 |
cpu->idle_ticks = (unsigned long long)psd.psd_cpu_time[CP_IDLE]; |
| 102 |
cpu->wait_ticks = (unsigned long long)psd.psd_cpu_time[CP_WAIT]; |
| 103 |
cpu->kern_ticks = (unsigned long long)psd.psd_cpu_time[CP_SYS]; |
| 104 |
/* XXX - record (sum of) "all other ticks" */ |
| 105 |
/* intrpt_ticks, sirq_ticks unused */ |
| 106 |
|
| 107 |
/* |
| 108 |
* Interrupt/Context Switch statistics |
| 109 |
* XXX - Do these really belong here ? |
| 110 |
*/ |
| 111 |
pstat_getvminfo(&psv, sizeof(psv), 1, 0); |
| 112 |
cpu->swapIn = (unsigned long long)psv.psv_sswpin; |
| 113 |
cpu->swapOut = (unsigned long long)psv.psv_sswpout; |
| 114 |
cpu->nInterrupts = (unsigned long long)psv.psv_sintr; |
| 115 |
cpu->nCtxSwitches = (unsigned long long)psv.psv_sswtch; |
| 116 |
|
| 117 |
psp = (struct pst_processor *) |
| 118 |
malloc(nspu * sizeof(struct pst_processor)); |
| 119 |
(void)memset(psp, 0, nspu * sizeof(struct pst_processor)); |
| 120 |
|
| 121 |
if (pstat_getprocessor(psp, sizeof(struct pst_processor), nspu, 0) != -1) { |
| 122 |
for (i = 0; i < nspu; i++) { |
| 123 |
if (psp[i].psp_processor_state == PSP_SPU_ENABLED) { |
| 124 |
cpu = netsnmp_cpu_get_byIdx( i, 0 ); |
| 125 |
cpu->user_ticks = (unsigned long long)psp[i].psp_cpu_time[CP_USER]; |
| 126 |
cpu->nice_ticks = (unsigned long long)psp[i].psp_cpu_time[CP_NICE]; |
| 127 |
cpu->sys2_ticks = (unsigned long long)psp[i].psp_cpu_time[CP_SYS]+ |
| 128 |
(unsigned long long)psp[i].psp_cpu_time[CP_WAIT]; |
| 129 |
cpu->idle_ticks = (unsigned long long)psp[i].psp_cpu_time[CP_IDLE]; |
| 130 |
cpu->wait_ticks = (unsigned long long)psp[i].psp_cpu_time[CP_WAIT]; |
| 131 |
cpu->kern_ticks = (unsigned long long)psp[i].psp_cpu_time[CP_SYS]; |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
free(psp); |
| 136 |
} |
| 137 |
|
| 138 |
return 0; |
| 139 |
} |