From: Konrad Rzeszutek Wilk Date: Fri, 19 Jul 2013 18:50:25 +0000 (-0400) Subject: spinlock_hog: A simple module that hogs all of the CPUs doing X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=d49c9060a9b5b36f8a5be2d3f19ed8d415e5ca52;p=xentesttools%2Fbootstrap.git spinlock_hog: A simple module that hogs all of the CPUs doing spinlock/unlock. Will cause the 'softlockup' splat to show up. Signed-off-by: Konrad Rzeszutek Wilk --- diff --git a/root_image/drivers/Makefile b/root_image/drivers/Makefile index 22c4000..209a3c3 100644 --- a/root_image/drivers/Makefile +++ b/root_image/drivers/Makefile @@ -1,6 +1,7 @@ obj-m += dma_test/ obj-m += wb_to_wc/ obj-m += xen_diag/ +obj-m += spinlock_hog/ .PHONY: distclean distclean: clean diff --git a/root_image/drivers/spinlock_hog/Makefile b/root_image/drivers/spinlock_hog/Makefile new file mode 100644 index 0000000..aa3771f --- /dev/null +++ b/root_image/drivers/spinlock_hog/Makefile @@ -0,0 +1,37 @@ +# Comment/uncomment the following line to disable/enable debugging +#DEBUG = y + +# Add your debugging flag (or not) to CFLAGS +ifeq ($(DEBUG),y) + DEBFLAGS = -O -g # "-O" is needed to expand inlines +else + DEBFLAGS = -O2 +endif + +EXTRA_CFLAGS += $(DEBFLAGS) -I$(LDDINCDIR) + +ifneq ($(KERNELRELEASE),) +# call from kernel build system + +obj-m := spinlock_hog.o + +else + +KERNELDIR ?= /lib/modules/$(shell uname -r)/build +PWD := $(shell pwd) + +default: + $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINCDIR=$(PWD)/../include modules + +endif + +clean: + rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions + +depend .depend dep: + $(CC) $(CFLAGS) -M *.c > .depend + + +ifeq (.depend,$(wildcard .depend)) +include .depend +endif diff --git a/root_image/drivers/spinlock_hog/spinlock_hog.c b/root_image/drivers/spinlock_hog/spinlock_hog.c new file mode 100644 index 0000000..040a154 --- /dev/null +++ b/root_image/drivers/spinlock_hog/spinlock_hog.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include +MODULE_AUTHOR("Konrad Rzeszutek Wilk "); +MODULE_DESCRIPTION("spinlock"); +MODULE_LICENSE("GPL"); +MODULE_VERSION("0.1"); +unsigned long loops = 10000000; + + +module_param(loops, ulong, 0644); +MODULE_PARM_DESC(loops, "How many loops (default is 10000000)"); + +static DEFINE_SPINLOCK(lock); + +static void take_lock(void *arg) +{ + spin_lock(&lock); + spin_unlock(&lock); +} +static int __init spinlock_hog_init(void) +{ + + cycles_t start, end; + unsigned long long i; + + start = get_cycles(); + for (i = 0; i < loops; i++ ) + (void)smp_call_function(take_lock, NULL, 1); + end = get_cycles(); + printk("cycles: %lld\n", (unsigned long long)end - start); + return -EIO; /* Just so we don't get loaded. */ +} +static void __exit spinlock_hog_exit(void) +{ +} +module_init(spinlock_hog_init); +module_exit(spinlock_hog_exit);