[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/4] Add tools/tests/offline_module



From: Don Slutz <dslutz@xxxxxxxxxxx>

This is a quick and dirty linux kernel module to offline some cpus
as far as Xen knows.

This can be used to re-create the bug in hvm_save_one about
returning the wrong data.

Signed-off-by: Don Slutz <dslutz@xxxxxxxxxxx>
---
 tools/tests/offline_module/.gitignore |  8 ++++
 tools/tests/offline_module/Makefile   | 10 ++++
 tools/tests/offline_module/README     | 37 +++++++++++++++
 tools/tests/offline_module/offline.c  | 89 +++++++++++++++++++++++++++++++++++
 4 files changed, 144 insertions(+)
 create mode 100644 tools/tests/offline_module/.gitignore
 create mode 100644 tools/tests/offline_module/Makefile
 create mode 100644 tools/tests/offline_module/README
 create mode 100644 tools/tests/offline_module/offline.c

diff --git a/tools/tests/offline_module/.gitignore 
b/tools/tests/offline_module/.gitignore
new file mode 100644
index 0000000..0a0b67b
--- /dev/null
+++ b/tools/tests/offline_module/.gitignore
@@ -0,0 +1,8 @@
+.offline.ko.cmd
+.offline.mod.o.cmd
+.offline.o.cmd
+.tmp_versions
+Module.symvers
+modules.order
+offline.ko
+offline.mod.c
diff --git a/tools/tests/offline_module/Makefile 
b/tools/tests/offline_module/Makefile
new file mode 100644
index 0000000..8fd246f
--- /dev/null
+++ b/tools/tests/offline_module/Makefile
@@ -0,0 +1,10 @@
+obj-m  := offline.o
+
+KDIR   := /lib/modules/$(shell uname -r)/build
+PWD    := $(shell pwd)
+
+all:
+       make -C $(KDIR) SUBDIRS=$(PWD) modules
+
+clean:
+       make -C $(KDIR) SUBDIRS=$(PWD) clean
diff --git a/tools/tests/offline_module/README 
b/tools/tests/offline_module/README
new file mode 100644
index 0000000..9bc0e01
--- /dev/null
+++ b/tools/tests/offline_module/README
@@ -0,0 +1,37 @@
+This is a quick and dirty linux kernel module to offline some cpus
+as far as Xen knows.
+
+This can be used to re-create the bug in hvm_save_one about
+returning the wrong data.
+
+You only need the 2 files: Makefile and offline.c alone in some
+directory on DomU.  "make" should build the kernel module.
+
+to leave just cpu 3 (id #2) of 8 (id #0-#7) running:
+
+taskset 0x4 insmod offline.ko who=0xff
+
+
+Note: Not sure when, but older kernels (2.6.18 for example) have:
+
+/*
+ * smp_call_function - run a function on all other CPUs.
+ * @func: The function to run. This must be fast and non-blocking.
+ * @info: An arbitrary pointer to pass to the function.
+ * @nonatomic: currently unused.
+ * @wait: If true, wait (atomically) until function has completed on other
+ *        CPUs.
+ * Returns 0 on success, else a negative status code. Does not return until
+ * remote CPUs are nearly ready to execute func or are or have executed.
+
+
+Instead of:
+
+/**                                                                            
 
+ * smp_call_function(): Run a function on all other CPUs.                      
 
+ * @func: The function to run. This must be fast and non-blocking.             
 
+ * @info: An arbitrary pointer to pass to the function.                        
 
+ * @wait: If true, wait (atomically) until function has completed              
 
+ *        on other CPUs.                                                       
 
+ *                                                                             
 
+ * Returns 0.                                                                  
 
diff --git a/tools/tests/offline_module/offline.c 
b/tools/tests/offline_module/offline.c
new file mode 100644
index 0000000..c538848
--- /dev/null
+++ b/tools/tests/offline_module/offline.c
@@ -0,0 +1,89 @@
+/* offline
+ *
+ * Copyright (C) 2013 by Cloud Switch, Inc.
+ * Copyright (C) 2013 by Terremark.
+ * Copyright (C) 2013 by Verizon.
+ *
+ * This program 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.
+ *
+ * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <linux/module.h>     /* needed by all modules */
+#include <linux/init.h>       /* needed for macros */
+#include <linux/kernel.h>     /* needed for printk */
+#include <linux/dmi.h>        /* needed for dmi_name_in_vendors */
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Don Slutz");
+MODULE_DESCRIPTION("offline some cpus for xen testing");
+
+static int debug = 0;
+module_param(debug, int, 0);
+MODULE_PARM_DESC(debug, "Debug level (0=none,1=all)");
+
+static int who = 0;
+module_param(who, int, 0);
+MODULE_PARM_DESC(who, "Bit mask of cpus to off line. Max is 32 bits");
+
+static int wait = 0;
+module_param(wait, int, 0);
+MODULE_PARM_DESC(wait, "Wait for offlined cpus");
+
+static void offline_self(void *v)
+{
+    int cpu = smp_processor_id();
+
+    if (cpu < (sizeof(wait) * 8))
+        if (who & (1 << cpu))
+            __asm__ ("cli\n\thlt");
+}
+
+int init_module(void)
+{
+
+    char *version = "$Revision: 1.0 $";
+    int   verLen = strlen(version);
+    int   cpu = smp_processor_id();
+
+    if (debug)
+        printk(KERN_WARNING "offline%.*s who=0x%x wait=%d cpu=%d\n",
+               verLen - 12, version + 10, who, wait, cpu);
+
+    if (cpu < (sizeof(wait) * 8))
+        who &= ~(1 << cpu);
+#ifdef OLD_KERNEL
+    smp_call_function(offline_self, NULL, 0, wait);
+#else
+    smp_call_function(offline_self, NULL, wait);
+#endif
+    if (debug)
+        printk(KERN_WARNING "offline done who=0x%x\n", who);
+
+    return 0;
+}
+
+void cleanup_module(void)
+{
+    if (debug)
+        printk(KERN_WARNING "offline removed\n");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
-- 
1.8.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.