Mathieu Desnoyers | 31155bc | 2007-10-18 23:41:08 -0700 | [diff] [blame] | 1 | /* probe-example.c |
| 2 | * |
| 3 | * Connects two functions to marker call sites. |
| 4 | * |
| 5 | * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> |
| 6 | * |
| 7 | * This file is released under the GPLv2. |
| 8 | * See the file COPYING for more details. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/sched.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/marker.h> |
| 15 | #include <asm/atomic.h> |
| 16 | |
| 17 | struct probe_data { |
| 18 | const char *name; |
| 19 | const char *format; |
| 20 | marker_probe_func *probe_func; |
| 21 | }; |
| 22 | |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 23 | void probe_subsystem_event(void *probe_data, void *call_data, |
| 24 | const char *format, va_list *args) |
Mathieu Desnoyers | 31155bc | 2007-10-18 23:41:08 -0700 | [diff] [blame] | 25 | { |
Mathieu Desnoyers | 31155bc | 2007-10-18 23:41:08 -0700 | [diff] [blame] | 26 | /* Declare args */ |
| 27 | unsigned int value; |
| 28 | const char *mystr; |
| 29 | |
| 30 | /* Assign args */ |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 31 | value = va_arg(*args, typeof(value)); |
| 32 | mystr = va_arg(*args, typeof(mystr)); |
Mathieu Desnoyers | 31155bc | 2007-10-18 23:41:08 -0700 | [diff] [blame] | 33 | |
| 34 | /* Call printk */ |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 35 | printk(KERN_INFO "Value %u, string %s\n", value, mystr); |
Mathieu Desnoyers | 31155bc | 2007-10-18 23:41:08 -0700 | [diff] [blame] | 36 | |
| 37 | /* or count, check rights, serialize data in a buffer */ |
Mathieu Desnoyers | 31155bc | 2007-10-18 23:41:08 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | atomic_t eventb_count = ATOMIC_INIT(0); |
| 41 | |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 42 | void probe_subsystem_eventb(void *probe_data, void *call_data, |
| 43 | const char *format, va_list *args) |
Mathieu Desnoyers | 31155bc | 2007-10-18 23:41:08 -0700 | [diff] [blame] | 44 | { |
| 45 | /* Increment counter */ |
| 46 | atomic_inc(&eventb_count); |
| 47 | } |
| 48 | |
| 49 | static struct probe_data probe_array[] = |
| 50 | { |
| 51 | { .name = "subsystem_event", |
Mathieu Desnoyers | cc9f2f8 | 2007-11-14 16:59:50 -0800 | [diff] [blame] | 52 | .format = "integer %d string %s", |
Mathieu Desnoyers | 31155bc | 2007-10-18 23:41:08 -0700 | [diff] [blame] | 53 | .probe_func = probe_subsystem_event }, |
| 54 | { .name = "subsystem_eventb", |
| 55 | .format = MARK_NOARGS, |
| 56 | .probe_func = probe_subsystem_eventb }, |
| 57 | }; |
| 58 | |
| 59 | static int __init probe_init(void) |
| 60 | { |
| 61 | int result; |
| 62 | int i; |
| 63 | |
| 64 | for (i = 0; i < ARRAY_SIZE(probe_array); i++) { |
| 65 | result = marker_probe_register(probe_array[i].name, |
| 66 | probe_array[i].format, |
| 67 | probe_array[i].probe_func, &probe_array[i]); |
| 68 | if (result) |
| 69 | printk(KERN_INFO "Unable to register probe %s\n", |
| 70 | probe_array[i].name); |
Mathieu Desnoyers | 31155bc | 2007-10-18 23:41:08 -0700 | [diff] [blame] | 71 | } |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | static void __exit probe_fini(void) |
| 76 | { |
| 77 | int i; |
| 78 | |
| 79 | for (i = 0; i < ARRAY_SIZE(probe_array); i++) |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 80 | marker_probe_unregister(probe_array[i].name, |
| 81 | probe_array[i].probe_func, &probe_array[i]); |
Mathieu Desnoyers | 31155bc | 2007-10-18 23:41:08 -0700 | [diff] [blame] | 82 | printk(KERN_INFO "Number of event b : %u\n", |
| 83 | atomic_read(&eventb_count)); |
Mathieu Desnoyers | 531d297 | 2008-09-29 11:09:15 -0400 | [diff] [blame] | 84 | marker_synchronize_unregister(); |
Mathieu Desnoyers | 31155bc | 2007-10-18 23:41:08 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | module_init(probe_init); |
| 88 | module_exit(probe_fini); |
| 89 | |
| 90 | MODULE_LICENSE("GPL"); |
| 91 | MODULE_AUTHOR("Mathieu Desnoyers"); |
| 92 | MODULE_DESCRIPTION("SUBSYSTEM Probe"); |