libgtop r2748 - in trunk: . examples include/glibtop lib src/daemon sysdeps/common sysdeps/linux
- From: bdejean svn gnome org
- To: svn-commits-list gnome org
- Subject: libgtop r2748 - in trunk: . examples include/glibtop lib src/daemon sysdeps/common sysdeps/linux
- Date: Sat, 24 May 2008 09:50:04 +0000 (UTC)
Author: bdejean
Date: Sat May 24 09:50:04 2008
New Revision: 2748
URL: http://svn.gnome.org/viewvc/libgtop?rev=2748&view=rev
Log:
New API to retrieve process CPU affinity.
Linux implementation.
Modified:
trunk/examples/Makefile.am
trunk/examples/affinity.c
trunk/features.def
trunk/include/glibtop/Makefile.am
trunk/include/glibtop/command.h
trunk/include/glibtop/procaffinity.h
trunk/include/glibtop/sysdeps.h
trunk/include/glibtop/union.h
trunk/lib/libgtop.sym
trunk/lib/sysdeps.c
trunk/src/daemon/server.c
trunk/sysdeps/common/default.c
trunk/sysdeps/linux/Makefile.am
trunk/sysdeps/linux/glibtop_server.h
trunk/sysdeps/linux/procaffinity.c
Modified: trunk/examples/Makefile.am
==============================================================================
--- trunk/examples/Makefile.am (original)
+++ trunk/examples/Makefile.am Sat May 24 09:50:04 2008
@@ -8,7 +8,7 @@
noinst_PROGRAMS = first second pprint procargs df netlist \
mountlist procmap netload sysdeps timings \
- openfiles smp proclist mem wd
+ openfiles smp proclist mem wd affinity
first_SOURCES = first.c
first_LDADD = $(top_builddir)/lib/libgtop-2.0.la
@@ -58,3 +58,5 @@
mem_SOURCE = mem.c
mem_LDADD = $(top_builddir)/lib/libgtop-2.0.la
+affinity_SOURCES = affinity.c
+affinity_LDADD = $(top_builddir)/lib/libgtop-2.0.la
Modified: trunk/examples/affinity.c
==============================================================================
--- trunk/examples/affinity.c (original)
+++ trunk/examples/affinity.c Sat May 24 09:50:04 2008
@@ -0,0 +1,34 @@
+#include <glibtop.h>
+#include <glibtop/procaffinity.h>
+
+#include <glib.h>
+#include <unistd.h>
+
+int main(int argc, char **argv)
+{
+ pid_t pid;
+ glibtop_proc_affinity buf;
+ guint16 *cpus;
+ size_t i;
+
+ if (argc < 2 || !(pid = strtoul(argv[1], NULL, 0)))
+ pid = getpid();
+
+ glibtop_init();
+
+ cpus = glibtop_get_proc_affinity(&buf, pid);
+
+ g_print("Process %u:\n"
+ " - all: %d\n",
+ (unsigned)pid, buf.all);
+
+ for (i = 0; i != buf.number; ++i)
+ g_print(" - CPU#%u is set\n", cpus[i]);
+
+ g_free(cpus);
+
+ glibtop_close();
+
+ return 0;
+}
+
Modified: trunk/features.def
==============================================================================
--- trunk/features.def (original)
+++ trunk/features.def Sat May 24 09:50:04 2008
@@ -23,4 +23,5 @@
void|ppp|ulong(state,bytes_in,bytes_out)|ushort(device)
char **|netlist|unsigned(number)
char **|proc_wd|ulong(number),str(root),str(exe)|pid_t(pid)
+guint16*|proc_affinity|ulong(number),int(all)|pid_t(pid)
Modified: trunk/include/glibtop/Makefile.am
==============================================================================
--- trunk/include/glibtop/Makefile.am (original)
+++ trunk/include/glibtop/Makefile.am Sat May 24 09:50:04 2008
@@ -8,7 +8,7 @@
procsignal.h union.h gnuserv.h \
parameter.h mountlist.h fsusage.h procmap.h signal.h \
sysinfo.h ppp.h procargs.h netload.h \
- procwd.h \
+ procwd.h procaffinity.h \
netlist.h procopenfiles.h open.h
noinst_HEADERS = error.h write.h read_data.h read.h init_hooks.h
Modified: trunk/include/glibtop/command.h
==============================================================================
--- trunk/include/glibtop/command.h (original)
+++ trunk/include/glibtop/command.h Sat May 24 09:50:04 2008
@@ -58,8 +58,9 @@
#define GLIBTOP_CMND_NETLIST 24
#define GLIBTOP_CMND_PROC_OPEN_FILES 25
#define GLIBTOP_CMND_PROC_WD 26
+#define GLIBTOP_CMND_PROC_AFFINITY 27
-#define GLIBTOP_MAX_CMND 27
+#define GLIBTOP_MAX_CMND 28
#define _GLIBTOP_PARAM_SIZE 16
Modified: trunk/include/glibtop/procaffinity.h
==============================================================================
--- trunk/include/glibtop/procaffinity.h (original)
+++ trunk/include/glibtop/procaffinity.h Sat May 24 09:50:04 2008
@@ -0,0 +1,61 @@
+/* Copyright (C) 2007 BenoÃt Dejean
+ This file is part of LibGTop 2.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __GLIBTOP_PROCAFFINITY_H__
+#define __GLIBTOP_PROCAFFINITY_H__
+
+#include <glibtop.h>
+#include <glibtop/global.h>
+
+G_BEGIN_DECLS
+
+typedef struct _glibtop_proc_affinity glibtop_proc_affinity;
+
+#define GLIBTOP_PROC_AFFINITY_NUMBER 0
+#define GLIBTOP_PROC_AFFINITY_ALL 1
+
+struct _glibtop_proc_affinity
+{
+ guint64 flags;
+ guint32 number;
+ gboolean all;
+};
+
+
+guint16 * glibtop_get_proc_affinity(glibtop_proc_affinity *buf, pid_t pid);
+guint16 * glibtop_get_proc_affinity_l(glibtop *server, glibtop_proc_affinity *buf, pid_t pid);
+
+
+#if GLIBTOP_SUID_PROC_AFFINITY
+
+#define glibtop_get_proc_affinity_r glibtop_get_proc_affinity_p
+void _glibtop_init_proc_affinity_p(glibtop *server);
+guint16 * glibtop_get_proc_affinity_p(glibtop *server, glibtop_proc_affinity *buf, pid_t pid);
+
+#else
+
+#define glibtop_get_proc_affinity_r glibtop_get_proc_affinity_s
+void _glibtop_init_proc_affinity_s(glibtop *server);
+guint16 * glibtop_get_proc_affinity_s(glibtop *server, glibtop_proc_affinity *buf, pid_t pid);
+
+#endif
+
+G_END_DECLS
+
+#endif
Modified: trunk/include/glibtop/sysdeps.h
==============================================================================
--- trunk/include/glibtop/sysdeps.h (original)
+++ trunk/include/glibtop/sysdeps.h Sat May 24 09:50:04 2008
@@ -52,8 +52,9 @@
#define GLIBTOP_SYSDEPS_NETLIST 23
#define GLIBTOP_SYSDEPS_PROC_OPEN_FILES 24
#define GLIBTOP_SYSDEPS_PROC_WD 25
+#define GLIBTOP_SYSDEPS_PROC_AFFINITY 26
-#define GLIBTOP_MAX_SYSDEPS 26
+#define GLIBTOP_MAX_SYSDEPS 27
#define GLIBTOP_SYSDEPS_ALL ((1 << GLIBTOP_MAX_SYSDEPS) - 1)
@@ -88,6 +89,7 @@
guint64 netload; /* glibtop_netload */
guint64 ppp; /* glibtop_ppp */
guint64 proc_wd; /* glibtop_proc_wd */
+ guint64 proc_affinity; /* glibtop_proc_affinity */
};
void glibtop_get_sysdeps (glibtop_sysdeps *buf);
Modified: trunk/include/glibtop/union.h
==============================================================================
--- trunk/include/glibtop/union.h (original)
+++ trunk/include/glibtop/union.h Sat May 24 09:50:04 2008
@@ -43,6 +43,7 @@
#include <glibtop/procmap.h>
#include <glibtop/procopenfiles.h>
#include <glibtop/procwd.h>
+#include <glibtop/procaffinity.h>
#include <glibtop/mountlist.h>
#include <glibtop/fsusage.h>
@@ -82,6 +83,7 @@
glibtop_ppp ppp;
glibtop_proc_open_files proc_open_files;
glibtop_proc_wd proc_wd;
+ glibtop_proc_affinity proc_affinity;
};
G_END_DECLS
Modified: trunk/lib/libgtop.sym
==============================================================================
--- trunk/lib/libgtop.sym (original)
+++ trunk/lib/libgtop.sym Sat May 24 09:50:04 2008
@@ -50,6 +50,8 @@
glibtop_get_sem_limits_l
glibtop_get_shm_limits
glibtop_get_shm_limits_l
+glibtop_get_proc_affinity
+glibtop_get_proc_affinity_l
glibtop_get_swap
glibtop_get_swap_l
glibtop_get_sysdeps
Modified: trunk/lib/sysdeps.c
==============================================================================
--- trunk/lib/sysdeps.c (original)
+++ trunk/lib/sysdeps.c Sat May 24 09:50:04 2008
@@ -47,6 +47,7 @@
GLIBTOP_SUID_NETLOAD +
GLIBTOP_SUID_NETLIST +
GLIBTOP_SUID_PROC_WD +
+GLIBTOP_SUID_PROC_AFFINITY +
GLIBTOP_SUID_PPP;
const _glibtop_init_func_t _glibtop_init_hook_s [] = {
@@ -113,6 +114,9 @@
#if !GLIBTOP_SUID_PROC_WD
_glibtop_init_proc_wd_s,
#endif
+#if !GLIBTOP_SUID_PROC_AFFINITY
+ _glibtop_init_proc_affinity_s,
+#endif
#if !GLIBTOP_SUID_PPP
_glibtop_init_ppp_s,
#endif
@@ -183,6 +187,9 @@
#if GLIBTOP_SUID_PROC_WD
_glibtop_init_proc_wd_p,
#endif
+#if GLIBTOP_SUID_PROC_AFFINITY
+ _glibtop_init_proc_affinity_p,
+#endif
#if GLIBTOP_SUID_PPP
_glibtop_init_ppp_p,
#endif
Modified: trunk/src/daemon/server.c
==============================================================================
--- trunk/src/daemon/server.c (original)
+++ trunk/src/daemon/server.c Sat May 24 09:50:04 2008
@@ -53,6 +53,7 @@
GLIBTOP_SUID_NETLOAD +
GLIBTOP_SUID_NETLIST +
GLIBTOP_SUID_PROC_WD +
+GLIBTOP_SUID_PROC_AFFINITY +
GLIBTOP_SUID_PPP;
#include <fcntl.h>
Modified: trunk/sysdeps/common/default.c
==============================================================================
--- trunk/sysdeps/common/default.c (original)
+++ trunk/sysdeps/common/default.c Sat May 24 09:50:04 2008
@@ -368,3 +368,17 @@
}
+/**
+ * glibtop_get_proc_affinity:
+ * @buf:
+ * @pid: Process id to get the affinity
+ *
+ * Get the processor affinity list for a process
+ *
+ * Returns: A list of processor ID of 'buf.number' elements.
+ */
+guint16 *
+glibtop_get_proc_affinity(glibtop_proc_affinity *buf, pid_t pid)
+{
+ return glibtop_get_proc_affinity_l(glibtop_global_server, buf, pid);
+}
Modified: trunk/sysdeps/linux/Makefile.am
==============================================================================
--- trunk/sysdeps/linux/Makefile.am (original)
+++ trunk/sysdeps/linux/Makefile.am Sat May 24 09:50:04 2008
@@ -8,7 +8,7 @@
proctime.c procmem.c procsignal.c prockernel.c \
procsegment.c procargs.c procmap.c siglist.c \
sysinfo.c netload.c ppp.c glibtop_private.c \
- mountlist.c \
+ mountlist.c procaffinity.c \
fsusage.c netlist.c procopenfiles.c procwd.c
libgtop_sysdeps_2_0_la_LIBADD = @GLIB_LIBS@
Modified: trunk/sysdeps/linux/glibtop_server.h
==============================================================================
--- trunk/sysdeps/linux/glibtop_server.h (original)
+++ trunk/sysdeps/linux/glibtop_server.h Sat May 24 09:50:04 2008
@@ -43,6 +43,7 @@
#define GLIBTOP_SUID_NETLOAD 0
#define GLIBTOP_SUID_NETLIST 0
#define GLIBTOP_SUID_PROC_WD 0
+#define GLIBTOP_SUID_PROC_AFFINITY 0
#define GLIBTOP_SUID_PPP 0
#define GLIBTOP_SUID_PROC_FILE 0
Modified: trunk/sysdeps/linux/procaffinity.c
==============================================================================
--- trunk/sysdeps/linux/procaffinity.c (original)
+++ trunk/sysdeps/linux/procaffinity.c Sat May 24 09:50:04 2008
@@ -0,0 +1,69 @@
+/* Copyright (C) 2007 BenoÃt Dejean
+ This file is part of LibGTop 2.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop/procaffinity.h>
+#include <glibtop/error.h>
+
+#include <glibtop_private.h>
+
+#include <sched.h>
+
+
+void
+_glibtop_init_proc_affinity_s(glibtop *server)
+{
+ server->sysdeps.proc_affinity =
+ (1 << GLIBTOP_PROC_AFFINITY_NUMBER) |
+ (1 << GLIBTOP_PROC_AFFINITY_ALL);
+
+}
+
+
+guint16 *
+glibtop_get_proc_affinity_s(glibtop *server, glibtop_proc_affinity *buf, pid_t pid)
+{
+ cpu_set_t set;
+ size_t i;
+ GArray* cpus;
+
+ memset(buf, 0, sizeof *buf);
+
+ if (sched_getaffinity(pid, sizeof set, &set) == -1) {
+ glibtop_error_r(server, "sched_getaffinity failed");
+ return NULL;
+ }
+
+ cpus = g_array_new(FALSE, FALSE, sizeof(guint16));
+
+ for (i = 0; i < MIN(CPU_SETSIZE, (size_t)(server->ncpu + 1)); i++) {
+ if (CPU_ISSET(i, &set)) {
+ guint16 n = i;
+ g_array_append_val(cpus, n);
+ }
+ }
+
+ buf->number = cpus->len;
+ buf->all = (cpus->len == (size_t)(server->ncpu + 1));
+ buf->flags = (1 << GLIBTOP_PROC_AFFINITY_NUMBER)
+ | (1 << GLIBTOP_PROC_AFFINITY_ALL);
+
+ return (guint16*) g_array_free(cpus, FALSE);
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]