1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| #include <linux/module.h> #include <linux/sched.h> #include <linux/uaccess.h> #include <linux/proc_fs.h> #include <linux/fs.h> #include <linux/mm.h> #include <linux/seq_file.h> #include <linux/slab.h> #include <linux/kernel.h> #include <linux/timer.h> #include <linux/jiffies.h> #include <stdarg.h>
extern unsigned long volatile pfcount; static struct timer_list test_timer; static unsigned long pfcount_last; static unsigned long pfcount_in_2; static int count = 0;
MODULE_LICENSE("GPL");
static int my_proc_show(struct seq_file *m, void *v) {
seq_printf(m, "[latest] Number of page fault interrupts in 2 seconds: %ld !\n", pfcount_in_2); return 0; }
static void irq_test_timer_function(struct timer_list *timer) {
printk("%d Number of page fault interrupts in 2 seconds: %ld\n",count,pfcount - pfcount_last); pfcount_in_2 = pfcount - pfcount_last;
pfcount_last = pfcount; mod_timer(&test_timer, jiffies + 2 * HZ); count++; }
static int my_proc_open(struct inode *inode, struct file *file) { return single_open(file, my_proc_show, NULL); }
static struct proc_ops my_fops = { .proc_open = my_proc_open, .proc_read = seq_read, .proc_lseek = seq_lseek, .proc_release = single_release, };
static int __init my_init(void) {
struct proc_dir_entry *file; struct proc_dir_entry *parent = proc_mkdir("3190608027",NULL);
file = proc_create("readpfcount", 0644, parent, &my_fops); if(!file) return -ENOMEM;
pfcount_last = pfcount; test_timer.expires = jiffies + 2 * HZ; timer_setup(&test_timer, irq_test_timer_function, 0);
add_timer(&test_timer);
printk(KERN_INFO "already init and add timer\n"); return 0; }
static void __exit my_exit(void) { printk(KERN_INFO "exit timer drv\n"); del_timer(&test_timer); remove_proc_entry("readpfcount", NULL); }
module_init(my_init); module_exit(my_exit);
|