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:
committed by
Martin Baulig
parent
731b2879f0
commit
9d564134de
8
sysdeps/linux/ChangeLog
Normal file
8
sysdeps/linux/ChangeLog
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
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.
|
||||||
|
|
@@ -28,12 +28,21 @@ static const unsigned long _glibtop_sysdeps_cpu =
|
|||||||
(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
|
(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
|
||||||
(1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY);
|
(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. */
|
/* Init function. */
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_init_cpu_s (glibtop *server)
|
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;
|
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides information about cpu usage. */
|
/* Provides information about cpu usage. */
|
||||||
@@ -44,14 +53,12 @@ void
|
|||||||
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||||
{
|
{
|
||||||
char buffer [BUFSIZ], *p;
|
char buffer [BUFSIZ], *p;
|
||||||
int fd, len;
|
int fd, len, i;
|
||||||
|
|
||||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
|
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_cpu));
|
memset (buf, 0, sizeof (glibtop_cpu));
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_cpu;
|
|
||||||
|
|
||||||
fd = open (FILENAME, O_RDONLY);
|
fd = open (FILENAME, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
glibtop_error_io_r (server, "open (%s)", FILENAME);
|
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->total = buf->user + buf->nice + buf->sys + buf->idle;
|
||||||
|
|
||||||
buf->frequency = 100;
|
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
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,8 @@
|
|||||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
Boston, MA 02111-1307, USA. */
|
Boston, MA 02111-1307, USA. */
|
||||||
|
|
||||||
|
#include <glibtop.h>
|
||||||
|
#include <glibtop/cpu.h>
|
||||||
#include <glibtop/open.h>
|
#include <glibtop/open.h>
|
||||||
|
|
||||||
/* =====================================================
|
/* =====================================================
|
||||||
@@ -50,12 +52,52 @@ static void set_linux_version(void) {
|
|||||||
|
|
||||||
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
|
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
|
||||||
|
|
||||||
|
#define FILENAME "/proc/stat"
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_open_s (glibtop *server, const char *program_name,
|
glibtop_open_s (glibtop *server, const char *program_name,
|
||||||
const unsigned long features, const unsigned flags)
|
const unsigned long features, const unsigned flags)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_LIBGTOP_SMP
|
||||||
|
char buffer [BUFSIZ], *p;
|
||||||
|
int fd, len, i;
|
||||||
|
#endif
|
||||||
|
|
||||||
server->name = program_name;
|
server->name = program_name;
|
||||||
|
|
||||||
set_linux_version ();
|
set_linux_version ();
|
||||||
server->os_version_code = (unsigned long) linux_version_code;
|
server->os_version_code = (unsigned long) linux_version_code;
|
||||||
|
|
||||||
|
server->ncpu = 0;
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBGTOP_SMP
|
||||||
|
fd = open (FILENAME, O_RDONLY);
|
||||||
|
if (fd < 0)
|
||||||
|
glibtop_error_io_r (server, "open (%s)", FILENAME);
|
||||||
|
|
||||||
|
len = read (fd, buffer, BUFSIZ-1);
|
||||||
|
if (len < 0)
|
||||||
|
glibtop_error_io_r (server, "read (%s)", FILENAME);
|
||||||
|
|
||||||
|
close (fd);
|
||||||
|
|
||||||
|
buffer [len] = '\0';
|
||||||
|
|
||||||
|
p = skip_multiple_token (buffer, 5) + 1;
|
||||||
|
|
||||||
|
for (i = 0; i < GLIBTOP_NCPU; i++) {
|
||||||
|
|
||||||
|
if (strncmp (p, "cpu", 3) || !isdigit (p [3]))
|
||||||
|
break;
|
||||||
|
|
||||||
|
server->ncpu++;
|
||||||
|
|
||||||
|
p = skip_multiple_token (p, 5) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
printf ("\nThis machine has %d CPUs.\n\n", server->ncpu);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user