Initialize `ncpu' on SMP systems.

1998-09-09  Martin Baulig <baulig@Stud.Informatik.uni-trier.de>

	* open.c (glibtop_init_s): Initialize `ncpu' on SMP systems.

	* cpu.c (glibtop_get_cpu_s): Added SMP support.

	* ChangeLog: New file.
This commit is contained in:
Martin Baulig
1998-09-09 15:17:12 +00:00
committed by Martin Baulig
parent 731b2879f0
commit 9d564134de
3 changed files with 86 additions and 3 deletions

View File

@@ -28,12 +28,21 @@ static const unsigned long _glibtop_sysdeps_cpu =
(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
(1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY);
static const unsigned long _glibtop_sysdeps_cpu_smp =
(1 << GLIBTOP_XCPU_TOTAL) + (1 << GLIBTOP_XCPU_USER) +
(1 << GLIBTOP_XCPU_NICE) + (1 << GLIBTOP_XCPU_SYS) +
(1 << GLIBTOP_XCPU_IDLE);
/* Init function. */
void
glibtop_init_cpu_s (glibtop *server)
{
#if HAVE_LIBGTOP_SMP
server->sysdeps.cpu = _glibtop_sysdeps_cpu | _glibtop_sysdeps_cpu_smp;
#else
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
#endif
}
/* Provides information about cpu usage. */
@@ -44,14 +53,12 @@ void
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{
char buffer [BUFSIZ], *p;
int fd, len;
int fd, len, i;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
memset (buf, 0, sizeof (glibtop_cpu));
buf->flags = _glibtop_sysdeps_cpu;
fd = open (FILENAME, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", FILENAME);
@@ -74,4 +81,30 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
buf->total = buf->user + buf->nice + buf->sys + buf->idle;
buf->frequency = 100;
buf->flags = _glibtop_sysdeps_cpu;
#if HAVE_LIBGTOP_SMP
for (i = 0; i < GLIBTOP_NCPU; i++) {
u_int64_t user, nice, sys, idle;
if (strncmp (p+1, "cpu", 3) || !isdigit (p [4]))
break;
p += 6;
user = strtoul (p, &p, 0);
nice = strtoul (p, &p, 0);
sys = strtoul (p, &p, 0);
idle = strtoul (p, &p, 0);
buf->xcpu_user [i] = strtoul (p, &p, 0);
buf->xcpu_nice [i] = strtoul (p, &p, 0);
buf->xcpu_sys [i] = strtoul (p, &p, 0);
buf->xcpu_idle [i] = strtoul (p, &p, 0);
buf->xcpu_total [i] = buf->xcpu_user [i] + buf->xcpu_nice [i] +
buf->xcpu_sys [i] + buf->xcpu_idle [i];
}
buf->flags |= _glibtop_sysdeps_cpu_smp;
#endif
}