diff --git a/sysdeps/aix/ChangeLog b/sysdeps/aix/ChangeLog index 3429003b..8f756aa4 100644 --- a/sysdeps/aix/ChangeLog +++ b/sysdeps/aix/ChangeLog @@ -1,3 +1,29 @@ +2004-10-04 Benoît Dejean + + * Makefile.am: + * cpu.c: (glibtop_init_cpu_p), (glibtop_get_cpu_p): + * glibtop_machine.h: + * glibtop_server.h: + * mem.c: (glibtop_get_mem_s): + * netload.c: (glibtop_get_netload_p): + * procargs.c: (glibtop_get_proc_args_s): + * prockernel.c: (glibtop_get_proc_kernel_s): + * proclist.c: (glibtop_get_proclist_s): + * procmem.c: (glibtop_get_proc_mem_s): + * procsegment.c: (glibtop_get_proc_segment_s): + * procsignal.c: (glibtop_get_proc_signal_s): + * procstate.c: (glibtop_get_proc_state_s): + * proctime.c: (glibtop_get_proc_time_s): + * procuid.c: (glibtop_get_proc_uid_s): + * swap.c: (glibtop_get_swap_s): + * sysinfo.c: (add_info), (init_sysinfo): + * uptime.c: (glibtop_init_uptime_s), (glibtop_get_uptime_s): + + AIX support updated by Laurent Vivier . + + Fixed cpu/uptime/sysinfo. + Added missing calls to glibtop_init_s. + 2004-06-13 Benoît Dejean * sysinfo.c: Added missing const qualifier. diff --git a/sysdeps/aix/Makefile.am b/sysdeps/aix/Makefile.am index e354bff7..71d1e356 100644 --- a/sysdeps/aix/Makefile.am +++ b/sysdeps/aix/Makefile.am @@ -3,16 +3,18 @@ INCLUDES = @INCLUDES@ noinst_LTLIBRARIES = libgtop_sysdeps-2.0.la libgtop_sysdeps_suid-2.0.la -libgtop_sysdeps_2_0_la_SOURCES = siglist.c nosuid.c +libgtop_sysdeps_2_0_la_SOURCES = siglist.c nosuid.c mem.c swap.c uptime.c \ + procargs.c prockernel.c proclist.c procmap.c \ + procmem.c procsegment.c procsignal.c \ + proctime.c procuid.c procmem.c utils.c \ + procstate.c sysinfo.c + libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO) -libgtop_sysdeps_suid_2_0_la_SOURCES = open.c close.c cpu.c mem.c swap.c \ - uptime.c loadavg.c shm_limits.c msg_limits.c \ - sem_limits.c proclist.c procstate.c procuid.c \ - proctime.c procmem.c procsignal.c prockernel.c \ - procsegment.c procargs.c procmap.c netload.c \ - ppp.c utils.c utils.h sysinfo.c +libgtop_sysdeps_suid_2_0_la_SOURCES = open.c close.c cpu.c loadavg.c \ + msg_limits.c shm_limits.c sem_limits.c \ + netload.c ppp.c utils.c libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO) libgtop_sysdeps_suid_2_0_la_LIBADD = $(top_builddir)/sysdeps/common/libgtop_suid_common-2.0.la $(GLIB_LIBS) diff --git a/sysdeps/aix/cpu.c b/sysdeps/aix/cpu.c index ad60fdc6..eac0a5b6 100644 --- a/sysdeps/aix/cpu.c +++ b/sysdeps/aix/cpu.c @@ -52,6 +52,13 @@ glibtop_init_cpu_p (glibtop *server) server->ncpu = 0; /* means single-processor, see glibtop.h */ } + result = _glibtop_get_kmem_offset(server, "sysinfo"); + if (result == -1) + { + return; + } + server->machine.sysinfo_offset = result; + result = _glibtop_get_kmem_offset(server, "cpuinfo"); if (result == -1) { @@ -73,11 +80,27 @@ glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf) { int result; int cpu; + struct sysinfo sysinfo; glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_CPU), 0); memset (buf, 0, sizeof (glibtop_cpu)); + result = _glibtop_get_kmem_info(server, server->machine.sysinfo_offset, + &sysinfo, sizeof(struct sysinfo)); + if (result <= 0) + { + glibtop_error_io_r (server, "Cannot read sysinfo"); + return; + } + + buf->idle = sysinfo.cpu[CPU_IDLE]; + buf->user = sysinfo.cpu[CPU_USER]; + buf->sys = sysinfo.cpu[CPU_KERNEL]; + buf->nice = sysinfo.cpu[CPU_WAIT]; + + buf->total = buf->idle + buf->user + buf->sys + buf->nice ; + result = _glibtop_get_kmem_info(server, server->machine.cpuinfo_offset, server->machine.cpuinfo, _system_configuration.ncpus @@ -89,37 +112,25 @@ glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf) return; } - buf->idle = 0; - buf->user = 0; - buf->sys = 0; - buf->nice = 0; - for (cpu = 0; cpu < _system_configuration.ncpus; cpu++) + + for (cpu = 0; cpu < MIN(GLIBTOP_NCPU, _system_configuration.ncpus); cpu++) { - if (cpu < GLIBTOP_NCPU) - { - buf->xcpu_idle[cpu] = - server->machine.cpuinfo[cpu].cpu[CPU_IDLE]; - buf->xcpu_user[cpu] = - server->machine.cpuinfo[cpu].cpu[CPU_USER]; - buf->xcpu_sys[cpu] = - server->machine.cpuinfo[cpu].cpu[CPU_KERNEL]; - buf->xcpu_nice[cpu] = - server->machine.cpuinfo[cpu].cpu[CPU_WAIT]; + buf->xcpu_idle[cpu] = + server->machine.cpuinfo[cpu].cpu[CPU_IDLE]; + buf->xcpu_user[cpu] = + server->machine.cpuinfo[cpu].cpu[CPU_USER]; + buf->xcpu_sys[cpu] = + server->machine.cpuinfo[cpu].cpu[CPU_KERNEL]; + buf->xcpu_nice[cpu] = + server->machine.cpuinfo[cpu].cpu[CPU_WAIT]; - buf->xcpu_total[cpu] = buf->xcpu_idle[cpu] + - buf->xcpu_user[cpu] + - buf->xcpu_sys[cpu] + - buf->xcpu_nice[cpu]; - } - - buf->idle += server->machine.cpuinfo[cpu].cpu[CPU_IDLE]; - buf->user += server->machine.cpuinfo[cpu].cpu[CPU_USER]; - buf->sys += server->machine.cpuinfo[cpu].cpu[CPU_KERNEL]; - buf->nice += server->machine.cpuinfo[cpu].cpu[CPU_WAIT]; - - buf->total = buf->idle + buf->user + buf->sys + buf->nice ; + buf->xcpu_total[cpu] = buf->xcpu_idle[cpu] + + buf->xcpu_user[cpu] + + buf->xcpu_sys[cpu] + + buf->xcpu_nice[cpu]; } + buf->frequency = sysconf(_SC_CLK_TCK); buf->flags = _glibtop_sysdeps_cpu; } diff --git a/sysdeps/aix/glibtop_machine.h b/sysdeps/aix/glibtop_machine.h index c20fdd19..aa185c1f 100644 --- a/sysdeps/aix/glibtop_machine.h +++ b/sysdeps/aix/glibtop_machine.h @@ -38,6 +38,7 @@ struct _glibtop_machine int kmem_fd; off_t cpuinfo_offset; + off_t sysinfo_offset; off_t ifnet_offset; off_t loadavg_offset; off_t shminfo_offset; diff --git a/sysdeps/aix/glibtop_server.h b/sysdeps/aix/glibtop_server.h index ab16cc5d..3874a3e5 100644 --- a/sysdeps/aix/glibtop_server.h +++ b/sysdeps/aix/glibtop_server.h @@ -29,7 +29,7 @@ G_BEGIN_DECLS #define GLIBTOP_SUID_CPU (1 << GLIBTOP_SYSDEPS_CPU) #define GLIBTOP_SUID_MEM 0 #define GLIBTOP_SUID_SWAP 0 -#define GLIBTOP_SUID_UPTIME (1 << GLIBTOP_SYSDEPS_UPTIME) +#define GLIBTOP_SUID_UPTIME 0 #define GLIBTOP_SUID_LOADAVG (1 << GLIBTOP_SYSDEPS_LOADAVG) #define GLIBTOP_SUID_SHM_LIMITS (1 << GLIBTOP_SYSDEPS_SHM_LIMITS) #define GLIBTOP_SUID_MSG_LIMITS (1 << GLIBTOP_SYSDEPS_MSG_LIMITS) diff --git a/sysdeps/aix/mem.c b/sysdeps/aix/mem.c index 890f4fef..960b1ff3 100644 --- a/sysdeps/aix/mem.c +++ b/sysdeps/aix/mem.c @@ -49,6 +49,8 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf) int pagesize; int result; + glibtop_init_s (&server, (1L << GLIBTOP_SYSDEPS_MEM), 0); + memset (buf, 0, sizeof (glibtop_mem)); pagesize = sysconf(_SC_PAGESIZE); diff --git a/sysdeps/aix/netload.c b/sysdeps/aix/netload.c index 61c80a99..0ec8cdaf 100644 --- a/sysdeps/aix/netload.c +++ b/sysdeps/aix/netload.c @@ -119,6 +119,8 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf, long mask; char name[16]; + glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_UPTIME), 0); + memset (buf, 0, sizeof (glibtop_netload)); for ( offset = server->machine.ifnet_offset; diff --git a/sysdeps/aix/procargs.c b/sysdeps/aix/procargs.c index 5e79374a..1bae8720 100644 --- a/sysdeps/aix/procargs.c +++ b/sysdeps/aix/procargs.c @@ -62,6 +62,8 @@ glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf, int result; int len; + glibtop_init_s (&server, (1L << GLIBTOP_SYSDEPS_PROC_ARGS), 0); + memset (buf, 0, sizeof (glibtop_proc_args)); pinfo = _glibtop_get_procinfo(server, pid); diff --git a/sysdeps/aix/prockernel.c b/sysdeps/aix/prockernel.c index e8885994..fe9d41da 100644 --- a/sysdeps/aix/prockernel.c +++ b/sysdeps/aix/prockernel.c @@ -57,6 +57,8 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, tid_t thid; int result; + glibtop_init_s (&server, (1L << GLIBTOP_SYSDEPS_PROC_KERNEL), 0); + memset (buf, 0, sizeof (glibtop_proc_kernel)); pinfo = _glibtop_get_procinfo(server, pid); diff --git a/sysdeps/aix/proclist.c b/sysdeps/aix/proclist.c index eaa86fda..ecba03ad 100644 --- a/sysdeps/aix/proclist.c +++ b/sysdeps/aix/proclist.c @@ -59,6 +59,8 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf, pid_t current; int result; + glibtop_init_s (&server, (1L << GLIBTOP_SYSDEPS_PROCLIST), 0); + memset (buf, 0, sizeof (glibtop_proclist)); for( count = total = 0, current = 0 diff --git a/sysdeps/aix/procmem.c b/sysdeps/aix/procmem.c index a98afda8..947e2cd4 100644 --- a/sysdeps/aix/procmem.c +++ b/sysdeps/aix/procmem.c @@ -53,6 +53,8 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, struct procsinfo *pinfo; int pagesize; + glibtop_init_s (&server, (1L << GLIBTOP_SYSDEPS_PROC_MEM), 0); + memset (buf, 0, sizeof (glibtop_proc_mem)); pinfo = _glibtop_get_procinfo(server, pid); diff --git a/sysdeps/aix/procsegment.c b/sysdeps/aix/procsegment.c index bb1a42bd..af926d90 100644 --- a/sysdeps/aix/procsegment.c +++ b/sysdeps/aix/procsegment.c @@ -53,6 +53,8 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf, struct procsinfo *pinfo; int pagesize; + glibtop_init_s (&server, (1L << GLIBTOP_SYSDEPS_PROC_SEGMENT), 0); + memset (buf, 0, sizeof (glibtop_proc_segment)); pinfo = _glibtop_get_procinfo(server, pid); diff --git a/sysdeps/aix/procsignal.c b/sysdeps/aix/procsignal.c index 26f76336..ec58124c 100644 --- a/sysdeps/aix/procsignal.c +++ b/sysdeps/aix/procsignal.c @@ -54,6 +54,8 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, int i; long bit; + glibtop_init_s (&server, (1L << GLIBTOP_SYSDEPS_PROC_SIGNAL), 0); + memset (buf, 0, sizeof (glibtop_proc_signal)); pinfo = _glibtop_get_procinfo(server, pid); diff --git a/sysdeps/aix/procstate.c b/sysdeps/aix/procstate.c index 1bf60ba6..2e73f5df 100644 --- a/sysdeps/aix/procstate.c +++ b/sysdeps/aix/procstate.c @@ -53,6 +53,8 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, tid_t thid; int result; + glibtop_init_s (&server, (1L << GLIBTOP_SYSDEPS_PROC_STATE), 0); + memset (buf, 0, sizeof (glibtop_proc_state)); pinfo = _glibtop_get_procinfo(server, pid); diff --git a/sysdeps/aix/proctime.c b/sysdeps/aix/proctime.c index 4526a889..d62caefe 100644 --- a/sysdeps/aix/proctime.c +++ b/sysdeps/aix/proctime.c @@ -51,6 +51,8 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, { struct procsinfo *pinfo; + glibtop_init_s (&server, (1L << GLIBTOP_SYSDEPS_PROC_TIME), 0); + memset (buf, 0, sizeof (glibtop_proc_time)); pinfo = _glibtop_get_procinfo(server, pid); diff --git a/sysdeps/aix/procuid.c b/sysdeps/aix/procuid.c index f0b0115d..1d4f141d 100644 --- a/sysdeps/aix/procuid.c +++ b/sysdeps/aix/procuid.c @@ -59,6 +59,8 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, tid_t thid; int result; + glibtop_init_s (&server, (1L << GLIBTOP_SYSDEPS_PROC_UID), 0); + memset (buf, 0, sizeof (glibtop_proc_uid)); pinfo = _glibtop_get_procinfo(server, pid); diff --git a/sysdeps/aix/swap.c b/sysdeps/aix/swap.c index 85eb159b..84884a24 100644 --- a/sysdeps/aix/swap.c +++ b/sysdeps/aix/swap.c @@ -57,6 +57,8 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf) int comment = 0; int pos = 0; + glibtop_init_s (&server, (1L << GLIBTOP_SYSDEPS_SWAP), 0); + memset (buf, 0, sizeof (glibtop_swap)); pagesize = sysconf(_SC_PAGESIZE); diff --git a/sysdeps/aix/sysinfo.c b/sysdeps/aix/sysinfo.c index 24b17fdb..73f018b8 100644 --- a/sysdeps/aix/sysinfo.c +++ b/sysdeps/aix/sysinfo.c @@ -31,10 +31,16 @@ static const unsigned long _glibtop_sysdeps_sysinfo = static glibtop_sysinfo sysinfo; -static void add_info(glibtop_entry* entry, char* label, char* value) +static void add_info(glibtop_entry* entry, char* label, char* attribute) { - g_ptr_array_add(entry->labels, g_strdup(label)); - g_hash_table_insert(entry->values, label, g_strdup(value)); + char* key; + char* value; + + key = g_strdup(label); + value = g_strdup(attribute); + + g_ptr_array_add(entry->labels, key); + g_hash_table_insert(entry->values, key, value); } static void init_sysinfo(void) @@ -60,22 +66,22 @@ static void init_sysinfo(void) case POWER_RS: add_info( &sysinfo.cpuinfo[cpu] , "architecture" - , "Power Classic architecture"); + , "Power Classic"); break; case POWER_PC: add_info( &sysinfo.cpuinfo[cpu] , "architecture" - , "Power PC architecture"); + , "Power PC"); break; case IA64: add_info( &sysinfo.cpuinfo[cpu] , "architecture" - , "Intel IA64 architecture"); + , "Intel IA64"); break; default: add_info( &sysinfo.cpuinfo[cpu] , "architecture" - , "Unknown architecture"); + , "Unknown"); break; } @@ -161,7 +167,7 @@ static void init_sysinfo(void) sprintf(buf,"%d", _system_configuration.width); add_info( &sysinfo.cpuinfo[cpu], "width", buf); - if (_system_configuration.cache_attrib & (1 << 31)) + if (_system_configuration.cache_attrib & 1 ) { /* L1 cache is present */ diff --git a/sysdeps/aix/uptime.c b/sysdeps/aix/uptime.c index edf18313..3081cc4b 100644 --- a/sysdeps/aix/uptime.c +++ b/sysdeps/aix/uptime.c @@ -21,6 +21,8 @@ Boston, MA 02111-1307, USA. */ +#include + #include #include #include @@ -32,16 +34,13 @@ #include static const unsigned long _glibtop_sysdeps_uptime = -(1L << GLIBTOP_UPTIME_UPTIME) + (1L << GLIBTOP_UPTIME_IDLETIME); +(1L << GLIBTOP_UPTIME_UPTIME) + (1L << GLIBTOP_UPTIME_BOOT_TIME); -static const unsigned long _required_cpu_flags = -(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_IDLE) + -(1L << GLIBTOP_CPU_FREQUENCY); /* Init function. */ void -glibtop_init_uptime_p (glibtop *server) +glibtop_init_uptime_s (glibtop *server) { server->sysdeps.uptime = _glibtop_sysdeps_uptime; } @@ -49,28 +48,17 @@ glibtop_init_uptime_p (glibtop *server) /* Provides uptime and idle time. */ void -glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf) +glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf) { - glibtop_cpu cpu; + time_t uptime; + struct tms tbuf; - glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_UPTIME), 0); + glibtop_init_s (&server, (1L << GLIBTOP_SYSDEPS_UPTIME), 0); memset (buf, 0, sizeof (glibtop_uptime)); - /* We simply calculate it from the CPU usage. */ - - glibtop_get_cpu_p (server, &cpu); - - /* Make sure all required fields are present. */ - - if ((cpu.flags & _required_cpu_flags) != _required_cpu_flags) - return; - - /* Calculate values. */ - - buf->uptime = (double) cpu.total / (double) cpu.frequency; - buf->idletime = (double) cpu.idle / (double) cpu.frequency; + buf->uptime = (double)times(&tbuf) / (double)sysconf(_SC_CLK_TCK); buf->boot_time = (guint64) time(NULL) - (guint64) buf->uptime; - buf->flags = _glibtop_sysdeps_uptime; } +