Signed-off-by: CAI Qian <[email protected]>
---
v2: code cleanup and skip 32-bit since there is no guarantee of running out of
    virtual memory address space there.

 testcases/kernel/mem/oom/oom02.c |  312 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 312 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/mem/oom/oom02.c

diff --git a/testcases/kernel/mem/oom/oom02.c b/testcases/kernel/mem/oom/oom02.c
new file mode 100644
index 0000000..d5f241a
--- /dev/null
+++ b/testcases/kernel/mem/oom/oom02.c
@@ -0,0 +1,312 @@
+/*
+ * Out Of Memory (OOM) for NUMA
+ *
+ * The program is designed to cope with unpredictable like amount and
+ * system physical memory, swap size and other VMM technology like KSM,
+ * memcg, memory hotplug and so on which may affect the OOM
+ * behaviours. It simply increase the memory consumption 3G each time
+ * until all the available memory is consumed and OOM is triggered.
+ *
+ * Copyright (C) 2010  Red Hat, Inc.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+#include "test.h"
+#include "usctest.h"
+#include "config.h"
+
+char *TCID = "oom02";
+int TST_TOTAL = 1;
+extern int Tst_count;
+
+#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
+       && HAVE_MPOL_CONSTANTS
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <sys/mount.h>
+#include <numaif.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+#include <stdarg.h>
+
+#define SYSFS_OVER             "/proc/sys/vm/overcommit_memory"
+#define MAXNODES               512
+#define CPATH                  "/dev/cpuset"
+#define CPATH_NEW              CPATH "/1"
+#define _PATH_SYS_SYSTEM       "/sys/devices/system"
+#define LENGTH                 (3UL<<30)
+#define NORMAL                 1
+#define MLOCK                  2
+#define KSM                    3
+
+static char overcommit[BUFSIZ];
+
+static void setup(void);
+static void cleanup(void) LTP_ATTRIBUTE_NORETURN;
+static void oom(int testcase, int mempolicy);
+static long count_numa(void);
+static int path_exist(const char *path, ...);
+static void testoom(int mempolicy);
+static void gather_cpus(char *cpus);
+
+int main(int argc, char *argv[])
+{
+       char *msg;
+       int lc, fd;
+       unsigned long nnodes = 1;
+
+       msg = parse_opts(argc, argv, NULL, NULL);
+       if (msg != (char *)NULL)
+               tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+
+#ifdef __i386__
+       tst_brkm(TCONF, tst_exit,
+               "test is not designed for 32-bit system.");
+#endif /* __i386__ */
+
+       nnodes = count_numa();
+       if (count_numa() == 1)
+               tst_brkm(TCONF, tst_exit, "required a NUMA system.");
+
+       setup();
+
+       for (lc = 0; TEST_LOOPING(lc); lc++) {
+               Tst_count = 0;
+               fd = open(SYSFS_OVER, O_WRONLY);
+               if (fd == -1)
+                       tst_brkm(TBROK|TERRNO, cleanup, "open");
+               if (write(fd, "1", 1) != 1)
+                       tst_brkm(TBROK|TERRNO, cleanup, "write");
+               close(fd);
+
+               tst_resm(TINFO, "process mempolicy.");
+               testoom(1);
+
+               tst_resm(TINFO, "process cpuset.");
+               testoom(0);
+       }
+       cleanup();
+}
+
+void testoom(int mempolicy)
+{
+       int fd;
+       char buf[BUFSIZ] = "";
+       char cpus[BUFSIZ] = "";
+
+       if (!mempolicy) {
+               gather_cpus(cpus);
+               tst_resm(TINFO, "CPU list for 2nd node is %s.", cpus);
+
+               snprintf(buf, BUFSIZ, "%s/cpuset.mems", CPATH_NEW);
+               fd = open(buf, O_WRONLY);
+               if (fd == -1)
+                       tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+               if (write(fd, "1", 1) != 1)
+                       tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+               close(fd);
+
+               snprintf(buf, BUFSIZ, "%s/cpuset.cpus", CPATH_NEW);
+               fd = open(buf, O_WRONLY);
+               if (fd == -1)
+                       tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+               if (write(fd, cpus, strlen(cpus)) != strlen(cpus))
+                       tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+               close(fd);
+
+               snprintf(buf, BUFSIZ, "%s/tasks", CPATH);
+               fd = open(buf, O_WRONLY);
+               if (fd == -1)
+                       tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+               snprintf(buf, BUFSIZ, "%d", getpid());
+               if (write(fd, buf, strlen(buf)) != strlen(buf))
+                       tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+               close(fd);
+       }
+       tst_resm(TINFO, "start normal OOM testing.");
+       oom(NORMAL, mempolicy);
+
+       tst_resm(TINFO, "start OOM testing for mlocked pages.");
+       oom(MLOCK, mempolicy);
+
+       tst_resm(TINFO, "start OOM testing for KSM pages.");
+       oom(KSM, mempolicy);
+}
+
+void setup(void)
+{
+       int fd;
+
+       tst_sig(FORK, DEF_HANDLER, cleanup);
+       TEST_PAUSE;
+
+       fd = open(SYSFS_OVER, O_RDONLY);
+       if (fd == -1)
+               tst_brkm(TBROK|TERRNO, cleanup, "open");
+       if (read(fd, &overcommit, 1) != 1)
+               tst_brkm(TBROK|TERRNO, cleanup, "read");
+       close(fd);
+
+       if (mkdir(CPATH, 0777) == -1)
+               tst_brkm(TBROK|TERRNO, cleanup, "mkdir %s", CPATH);
+       if (mount("cpuset", CPATH, "cpuset", 0, NULL) == -1)
+               tst_brkm(TBROK|TERRNO, cleanup, "mount %s", CPATH);
+       if (mkdir(CPATH_NEW, 0777) == -1)
+               tst_brkm(TBROK|TERRNO, cleanup, "mkdir %s", CPATH_NEW);
+}
+
+void cleanup(void)
+{
+       FILE *fp;
+       int fd;
+       char s_new[BUFSIZ], s[BUFSIZ], value[BUFSIZ];
+
+       fd = open(SYSFS_OVER, O_WRONLY);
+       if (fd == -1)
+               tst_brkm(TBROK|TERRNO, cleanup, "open");
+       if (write(fd, &overcommit, 1) != 1)
+               tst_brkm(TBROK|TERRNO, cleanup, "write");
+       close(fd);
+
+       /* Move all processes in task to its parent cpuset node. */
+       snprintf(s, BUFSIZ, "%s/tasks", CPATH);
+       fd = open(s, O_WRONLY);
+       if (fd == -1)
+               tst_resm(TWARN|TERRNO, "open %s", s);
+       snprintf(s_new, BUFSIZ, "%s/tasks", CPATH_NEW);
+
+       fp = fopen(s_new, "r");
+       if (fp == NULL)
+               tst_resm(TWARN|TERRNO, "fopen %s", s_new);
+       if ((fd != -1) && (fp != NULL)) {
+               while (fgets(value, BUFSIZ, fp) != NULL)
+                       if (write(fd, value, strlen(value) - 1)
+                               != strlen(value) - 1)
+                               tst_resm(TWARN|TERRNO, "write %s", s);
+       }
+       if (fd != -1)
+               close(fd);
+       if (fp != NULL)
+               fclose(fp);
+       if (rmdir(CPATH_NEW) == -1)
+               tst_resm(TWARN|TERRNO, "rmdir %s", CPATH_NEW);
+       if (umount(CPATH) == -1)
+               tst_resm(TWARN|TERRNO, "umount %s", CPATH);
+       if (rmdir(CPATH) == -1)
+               tst_resm(TWARN|TERRNO, "rmdir %s", CPATH);
+
+       TEST_CLEANUP;
+       tst_exit();
+}
+
+void oom(int testcase, int mempolicy)
+{
+       pid_t pid;
+       int status;
+       void *s;
+       unsigned long nmask = 2;
+
+       switch(pid = fork()) {
+       case -1:
+               tst_brkm(TBROK|TERRNO, cleanup, "fork");
+       case 0:
+               if (mempolicy)
+                       if (set_mempolicy(MPOL_BIND, &nmask, MAXNODES) == -1)
+                               tst_brkm(TBROK|TERRNO, cleanup,
+                                       "set_mempolicy");
+               while(1) {
+                       s = mmap(NULL, LENGTH, PROT_READ|PROT_WRITE,
+                               MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+                       if (s == MAP_FAILED)
+                               tst_brkm(TBROK|TERRNO, cleanup, "mmap");
+                       if (testcase == MLOCK && mlock(s, LENGTH) == -1)
+                               tst_brkm(TINFO|TERRNO, cleanup, "mlock");
+                       if (testcase == KSM
+                               && madvise(s, LENGTH, MADV_MERGEABLE) == -1)
+                               tst_brkm(TBROK|TERRNO, cleanup, "madvise");
+                       memset(s, '\a', LENGTH);
+               }
+               exit(0);
+       default:
+               break;
+       }
+       tst_resm(TINFO, "expected victim is %d.", pid);
+       if (waitpid(-1, &status, 0) == -1)
+               tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+
+       if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGKILL)
+               tst_resm(TFAIL, "the victim unexpectedly failed: %d", status);
+}
+
+long count_numa(void)
+{
+       int nnodes = 0;
+
+       while(path_exist(_PATH_SYS_SYSTEM "/node/node%d", nnodes))
+               nnodes++;
+
+       return nnodes;
+}
+
+int path_exist(const char *path, ...)
+{
+       va_list ap;
+       char pathbuf[PATH_MAX];
+
+       va_start(ap, path);
+       vsnprintf(pathbuf, sizeof(pathbuf), path, ap);
+       va_end(ap);
+
+       return access(pathbuf, F_OK) == 0;
+}
+
+void gather_cpus(char *cpus)
+{
+       int ncpus = 0;
+       int i;
+       char buf[BUFSIZ];
+
+       while(path_exist(_PATH_SYS_SYSTEM "/cpu/cpu%d", ncpus))
+               ncpus++;
+
+       for (i = 0; i < ncpus; i++)
+               if (path_exist(_PATH_SYS_SYSTEM "/node/node1/cpu%d", i)) {
+                       sprintf(buf, "%d,", i);
+                       strcat(cpus, buf);
+               }
+       /* Remove the trailing comma. */
+       cpus[strlen(cpus) - 1] = '\0';
+}
+
+#else /* no NUMA */
+int main(void) {
+       tst_resm(TCONF, "no NUMA development packages installed.");
+       tst_exit();
+}
+#endif
-- 
1.7.3.2
From da9230b9d3ebb009ef9e921b764fc14020bbf977 Mon Sep 17 00:00:00 2001
From: CAI Qian <[email protected]>
Date: Tue, 21 Dec 2010 10:32:59 +0800
Subject: [PATCH v2 2/5] oom02: test OOM for NUMA using mempolicy and cpuset


Signed-off-by: CAI Qian <[email protected]>
---
v2: code cleanup and skip 32-bit since there is no guarantee of running out of
    virtual memory address space there.

 testcases/kernel/mem/oom/oom02.c |  312 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 312 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/mem/oom/oom02.c

diff --git a/testcases/kernel/mem/oom/oom02.c b/testcases/kernel/mem/oom/oom02.c
new file mode 100644
index 0000000..d5f241a
--- /dev/null
+++ b/testcases/kernel/mem/oom/oom02.c
@@ -0,0 +1,312 @@
+/*
+ * Out Of Memory (OOM) for NUMA
+ *
+ * The program is designed to cope with unpredictable like amount and
+ * system physical memory, swap size and other VMM technology like KSM,
+ * memcg, memory hotplug and so on which may affect the OOM
+ * behaviours. It simply increase the memory consumption 3G each time
+ * until all the available memory is consumed and OOM is triggered.
+ *
+ * Copyright (C) 2010  Red Hat, Inc.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+#include "test.h"
+#include "usctest.h"
+#include "config.h"
+
+char *TCID = "oom02";
+int TST_TOTAL = 1;
+extern int Tst_count;
+
+#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
+	&& HAVE_MPOL_CONSTANTS
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <sys/mount.h>
+#include <numaif.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+#include <stdarg.h>
+
+#define SYSFS_OVER		"/proc/sys/vm/overcommit_memory"
+#define MAXNODES		512
+#define CPATH			"/dev/cpuset"
+#define CPATH_NEW		CPATH "/1"
+#define _PATH_SYS_SYSTEM	"/sys/devices/system"
+#define LENGTH			(3UL<<30)
+#define NORMAL			1
+#define MLOCK			2
+#define KSM			3
+
+static char overcommit[BUFSIZ];
+
+static void setup(void);
+static void cleanup(void) LTP_ATTRIBUTE_NORETURN;
+static void oom(int testcase, int mempolicy);
+static long count_numa(void);
+static int path_exist(const char *path, ...);
+static void testoom(int mempolicy);
+static void gather_cpus(char *cpus);
+
+int main(int argc, char *argv[])
+{
+	char *msg;
+	int lc, fd;
+	unsigned long nnodes = 1;
+
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != (char *)NULL)
+		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+
+#ifdef __i386__
+	tst_brkm(TCONF, tst_exit,
+		"test is not designed for 32-bit system.");
+#endif /* __i386__ */
+
+	nnodes = count_numa();
+	if (count_numa() == 1)
+		tst_brkm(TCONF, tst_exit, "required a NUMA system.");
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		Tst_count = 0;
+		fd = open(SYSFS_OVER, O_WRONLY);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open");
+		if (write(fd, "1", 1) != 1)
+			tst_brkm(TBROK|TERRNO, cleanup, "write");
+		close(fd);
+
+		tst_resm(TINFO, "process mempolicy.");
+		testoom(1);
+
+		tst_resm(TINFO, "process cpuset.");
+		testoom(0);
+	}
+	cleanup();
+}
+
+void testoom(int mempolicy)
+{
+	int fd;
+	char buf[BUFSIZ] = "";
+	char cpus[BUFSIZ] = "";
+
+	if (!mempolicy) {
+		gather_cpus(cpus);
+		tst_resm(TINFO, "CPU list for 2nd node is %s.", cpus);
+
+		snprintf(buf, BUFSIZ, "%s/cpuset.mems", CPATH_NEW);
+		fd = open(buf, O_WRONLY);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+		if (write(fd, "1", 1) != 1)
+			tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+		close(fd);
+
+		snprintf(buf, BUFSIZ, "%s/cpuset.cpus", CPATH_NEW);
+		fd = open(buf, O_WRONLY);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+		if (write(fd, cpus, strlen(cpus)) != strlen(cpus))
+			tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+		close(fd);
+
+		snprintf(buf, BUFSIZ, "%s/tasks", CPATH);
+		fd = open(buf, O_WRONLY);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+		snprintf(buf, BUFSIZ, "%d", getpid());
+		if (write(fd, buf, strlen(buf)) != strlen(buf))
+			tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+		close(fd);
+	}
+	tst_resm(TINFO, "start normal OOM testing.");
+	oom(NORMAL, mempolicy);
+
+	tst_resm(TINFO, "start OOM testing for mlocked pages.");
+	oom(MLOCK, mempolicy);
+
+	tst_resm(TINFO, "start OOM testing for KSM pages.");
+	oom(KSM, mempolicy);
+}
+
+void setup(void)
+{
+	int fd;
+
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+	TEST_PAUSE;
+
+	fd = open(SYSFS_OVER, O_RDONLY);
+	if (fd == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "open");
+	if (read(fd, &overcommit, 1) != 1)
+		tst_brkm(TBROK|TERRNO, cleanup, "read");
+	close(fd);
+
+	if (mkdir(CPATH, 0777) == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "mkdir %s", CPATH);
+	if (mount("cpuset", CPATH, "cpuset", 0, NULL) == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "mount %s", CPATH);
+	if (mkdir(CPATH_NEW, 0777) == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "mkdir %s", CPATH_NEW);
+}
+
+void cleanup(void)
+{
+	FILE *fp;
+	int fd;
+	char s_new[BUFSIZ], s[BUFSIZ], value[BUFSIZ];
+
+	fd = open(SYSFS_OVER, O_WRONLY);
+	if (fd == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "open");
+	if (write(fd, &overcommit, 1) != 1)
+		tst_brkm(TBROK|TERRNO, cleanup, "write");
+	close(fd);
+
+	/* Move all processes in task to its parent cpuset node. */
+	snprintf(s, BUFSIZ, "%s/tasks", CPATH);
+	fd = open(s, O_WRONLY);
+	if (fd == -1)
+		tst_resm(TWARN|TERRNO, "open %s", s);
+	snprintf(s_new, BUFSIZ, "%s/tasks", CPATH_NEW);
+
+	fp = fopen(s_new, "r");
+	if (fp == NULL)
+		tst_resm(TWARN|TERRNO, "fopen %s", s_new);
+	if ((fd != -1) && (fp != NULL)) {
+		while (fgets(value, BUFSIZ, fp) != NULL)
+			if (write(fd, value, strlen(value) - 1)
+				!= strlen(value) - 1)
+				tst_resm(TWARN|TERRNO, "write %s", s);
+	}
+	if (fd != -1)
+		close(fd);
+	if (fp != NULL)
+		fclose(fp);
+	if (rmdir(CPATH_NEW) == -1)
+		tst_resm(TWARN|TERRNO, "rmdir %s", CPATH_NEW);
+	if (umount(CPATH) == -1)
+		tst_resm(TWARN|TERRNO, "umount %s", CPATH);
+	if (rmdir(CPATH) == -1)
+		tst_resm(TWARN|TERRNO, "rmdir %s", CPATH);
+
+	TEST_CLEANUP;
+	tst_exit();
+}
+
+void oom(int testcase, int mempolicy)
+{
+	pid_t pid;
+	int status;
+	void *s;
+	unsigned long nmask = 2;
+
+	switch(pid = fork()) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+	case 0:
+		if (mempolicy)
+			if (set_mempolicy(MPOL_BIND, &nmask, MAXNODES) == -1)
+				tst_brkm(TBROK|TERRNO, cleanup,
+					"set_mempolicy");
+		while(1) {
+			s = mmap(NULL, LENGTH, PROT_READ|PROT_WRITE,
+				MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+			if (s == MAP_FAILED)
+				tst_brkm(TBROK|TERRNO, cleanup, "mmap");
+			if (testcase == MLOCK && mlock(s, LENGTH) == -1)
+				tst_brkm(TINFO|TERRNO, cleanup, "mlock");
+			if (testcase == KSM
+				&& madvise(s, LENGTH, MADV_MERGEABLE) == -1)
+				tst_brkm(TBROK|TERRNO, cleanup, "madvise");
+			memset(s, '\a', LENGTH);
+		}
+		exit(0);
+	default:
+		break;
+	}
+	tst_resm(TINFO, "expected victim is %d.", pid);
+	if (waitpid(-1, &status, 0) == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+
+	if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGKILL)
+		tst_resm(TFAIL, "the victim unexpectedly failed: %d", status);
+}
+
+long count_numa(void)
+{
+	int nnodes = 0;
+
+	while(path_exist(_PATH_SYS_SYSTEM "/node/node%d", nnodes))
+		nnodes++;
+
+	return nnodes;
+}
+
+int path_exist(const char *path, ...)
+{
+	va_list ap;
+	char pathbuf[PATH_MAX];
+
+	va_start(ap, path);
+	vsnprintf(pathbuf, sizeof(pathbuf), path, ap);
+	va_end(ap);
+
+	return access(pathbuf, F_OK) == 0;
+}
+
+void gather_cpus(char *cpus)
+{
+	int ncpus = 0;
+	int i;
+	char buf[BUFSIZ];
+
+	while(path_exist(_PATH_SYS_SYSTEM "/cpu/cpu%d", ncpus))
+		ncpus++;
+
+	for (i = 0; i < ncpus; i++)
+		if (path_exist(_PATH_SYS_SYSTEM "/node/node1/cpu%d", i)) {
+			sprintf(buf, "%d,", i);
+			strcat(cpus, buf);
+		}
+	/* Remove the trailing comma. */
+	cpus[strlen(cpus) - 1] = '\0';
+}
+
+#else /* no NUMA */
+int main(void) {
+	tst_resm(TCONF, "no NUMA development packages installed.");
+	tst_exit();
+}
+#endif
-- 
1.7.3.2

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to