Kernel module source -------------------- sjc-lds-154$ cat Makefile obj-m := hellom.o hellom-objs := hello.o hello1.o sjc-lds-154$ cat hello.c #include #include #include #include #include #include MODULE_DESCRIPTION("simple hello world module"); MODULE_LICENSE("GPL"); static struct task_struct *my_kthread; int count_down = 100; void print_value (int i) { printk("print_value received %d\n", i); } unsigned int bar; void do_atomic_things (unsigned int i, unsigned int *p); void foo (int mask) { do_atomic_things(1, &bar); if (mask & 0x1) { print_value(5); } else if (mask & 0x2) { print_value(4); } else if (mask & 0x4) { print_value(3); } else if (mask & (0x8 | 0x10)) { print_value(2); } } int hellom_start_func1 (int p) { printk("hellom: %s called, p = %d\n", __FUNCTION__, p); foo(p); return p * p; } int hellom_start_func2 (int p) { printk("hellom: %s called, p = %d\n", __FUNCTION__, p); return hellom_start_func1(p); } int hellom_start_func3 (int p) { printk("hellom: %s called, p = %d\n", __FUNCTION__, p); return hellom_start_func2(p); } static int mythread(void *arg) { while (!kthread_should_stop()) { printk("mythread wakeup: count_doun = %d\n", count_down); schedule_timeout_interruptible(3 * HZ); count_down--; hellom_start_func3(count_down); } return 0; } void create_mythread (void) { my_kthread = kthread_run(mythread, NULL, "hello"); } static int __init init_hello(void) { printk("hello module loaded\n"); create_mythread(); hellom_start_func3(5); return 0; } int hellom_end_func1 (int p) { printk("hellom: %s called, p = %d\n", __FUNCTION__, p); return p * p; } int hellom_end_func2 (int p) { printk("hellom: %s called, p = %d\n", __FUNCTION__, p); return hellom_end_func1(p); } int hellom_end_func3 (int p) { printk("hellom: %s called, p = %d\n", __FUNCTION__, p); return hellom_end_func2(p); } static void __exit exit_hello(void) { hellom_end_func3(6); printk("hello module removed\n"); } module_init(init_hello); module_exit(exit_hello); sjc-lds-154$ cat hello1.c static __inline__ void my_atomic_sub(unsigned int *p, unsigned int v) { unsigned int temp; __asm__ __volatile__ ( ".set push\n\t" ".set noreorder\n\t" "1:\tll %0, %3\n\t" /* load old value */ "subu %0, %0, %2\n\t" /* calculate new value */ "sc %0, %1\n\t" /* attempt to store */ "beqz %0, 1b\n\t" /* spin if failed */ "nop\n\t" ".set pop\n\t" : "=&r" (temp), "=m" (*p) : "r" (v), "m" (*p) : "memory"); } int k1; int k2; int l1; int l2; void do_atomic_things (unsigned int i, unsigned int *p) { k1 += 1; k2 += 2; my_atomic_sub(p, i); l2 -= 2; l1 -= 3; } Tracing Script -------------- sjc-lds-154$ cat atomicm_foo.stp probe module("hellom").function("*").call { printf ("%s -> %s\n", thread_indent(1), probefunc()) } probe module("hellom").function("*").return { printf ("%s <- %s\n", thread_indent(-1), probefunc()) } probe module("hellom").function("*").inline { printf ("%s => %s\n", thread_indent(1), probefunc()) thread_indent(-1) } Run logs -------- When script activated without fixes it keeps printing my_atomic_sub forever: [my6300:~]$ staprun atomicm_foo.ko 0 hello(3807): -> hellom_start_func3 17 hello(3807): -> hellom_start_func2 25 hello(3807): -> hellom_start_func1 33 hello(3807): -> foo 39 hello(3807): -> do_atomic_things 44 hello(3807): => my_atomic_sub 51 hello(3807): => my_atomic_sub 58 hello(3807): => my_atomic_sub 65 hello(3807): => my_atomic_sub 72 hello(3807): => my_atomic_sub 79 hello(3807): => my_atomic_sub 86 hello(3807): => my_atomic_sub 93 hello(3807): => my_atomic_sub 100 hello(3807): => my_atomic_sub 107 hello(3807): => my_atomic_sub 114 hello(3807): => my_atomic_sub 121 hello(3807): => my_atomic_sub 128 hello(3807): => my_atomic_sub ... After the fix: [my6300:~]$ staprun atomicm_foo.ko WARNING: probe module("hellom").function("my_atomic_sub@/ws/kamensky-sjc/nova/atomicm/hello1.c:3").inline (address 0xffffffffc0212408) registration error (rc -22) 0 hello(5605): -> hellom_start_func3 24 hello(5605): -> hellom_start_func2 33 hello(5605): -> hellom_start_func1 42 hello(5605): -> foo 48 hello(5605): -> do_atomic_things 54 hello(5605): <- do_atomic_things 60 hello(5605): => print_value 68 hello(5605): => print_value 77 hello(5605): <- foo 82 hello(5605): <- hellom_start_func1 86 hello(5605): <- hellom_start_func2 90 hello(5605): <- hellom_start_func3 0 hello(5605): -> hellom_start_func3 23 hello(5605): -> hellom_start_func2 32 hello(5605): -> hellom_start_func1 41 hello(5605): -> foo 46 hello(5605): -> do_atomic_things 53 hello(5605): <- do_atomic_things 59 hello(5605): => print_value 66 hello(5605): => print_value 75 hello(5605): <- foo 80 hello(5605): <- hellom_start_func1 84 hello(5605): <- hellom_start_func2 89 hello(5605): <- hellom_start_func3 from dmegs atomicm_foo: systemtap: 1.4/0.152, base: ffffffffc0218000, memory: 23data/28text/58ctx/13net/262alloc kb, probes: 27 Kprobes for ll and sc instructions are not supported