From bf92567e5fd0f7f1aea3a8be70a0eb2d59cc47fe Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Thu, 18 Sep 2014 11:48:25 -0400 Subject: [PATCH] a bit of reorg and showing the jiffies around fib --- mod_hello.c | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/mod_hello.c b/mod_hello.c index 75e2d8c..9cb7331 100644 --- a/mod_hello.c +++ b/mod_hello.c @@ -2,22 +2,19 @@ #include /* provides initialization routines */ #include +#include -static char __initdata hello_hellomsg[] = KERN_NOTICE "Hello, Kernel, I'm in\n"; -static char __exitdata hello_byemsg[] = KERN_NOTICE "Bye, I'm out\n"; +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Vincent Batts "); +MODULE_DESCRIPTION("just getting familiar"); +MODULE_VERSION("1.0"); + +//static char __initdata hello_hellomsg[] = KERN_NOTICE "Hello, Kernel, I'm in\n"; +//static char __exitdata hello_byemsg[] = KERN_NOTICE "Bye, I'm out\n"; static int hello_print_hello(void) { - unsigned long i; - char *symbol_name; - - printk(hello_hellomsg); - - symbol_name = "free_pages"; - printk("looking up '%s'\n", symbol_name); - i = kallsyms_lookup_name(symbol_name); - printk("%s 0x%lx\n", symbol_name, i); - + printk(KERN_INFO "[%s] module loaded.\n", __this_module.name); return 0; } @@ -39,32 +36,42 @@ long hello_fib(long times, long n1, long n2) return next; } -static int __init start_hello_world(void) +static int __init hello_init(void) { long f_int, f_cap, f_start1, f_start2; + unsigned long sym_addr; + char *sym_name; + char filename[255]; - MODULE_LICENSE("GPL"); - MODULE_AUTHOR("Vincent Batts "); - MODULE_DESCRIPTION("just getting familiar"); - MODULE_VERSION("1.0"); hello_print_hello(); + sym_name = "files"; + printk("looking up '%s'\n", sym_name); + sym_addr = kallsyms_lookup_name(sym_name); + printk("%s 0x%lx\n", sym_name, sym_addr); + + strncpy(filename, (char *)sym_addr, 255); + printk(KERN_INFO "[%s] %s (0x%lx): %s\n", __this_module.name, sym_name, sym_addr, filename); + + + printk("[%s] jiffies: %lu\n", __this_module.name, jiffies); f_cap = 10000000; f_start1 = 0; f_start2 = 1; f_int = hello_fib(f_cap, f_start1, f_start2); printk("fib of %ld and %ld (up to %ld): %ld\n", f_start1, f_start2, f_cap, f_int); + printk("[%s] jiffies: %lu\n", __this_module.name, jiffies); return 0; } -static void __exit hello_go_away(void) +static void __exit hello_cleanup(void) { - printk(hello_byemsg); + printk(KERN_INFO "[%s] module unloaded.\n", __this_module.name); } -module_init(start_hello_world); -module_exit(hello_go_away); +module_init(hello_init); +module_exit(hello_cleanup); // vim:set shiftwidth=4 softtabstop=4 expandtab: