diff --git a/Makefile b/Makefile index 1c6214f..767dd84 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,11 @@ KDIR=/mnt/mainline #KDIR=/usr/src/kernels/$(shell uname -r) -obj-m += demo.o -obj-m += blk_kprobe.o -obj-m += kobject-example.o -obj-m += kprobe_trace.o +#obj-m += demo.o +#obj-m += blk_kprobe.o +#obj-m += kobject-example.o +#obj-m += kprobe_trace.o +obj-m += lockup.o all: make -C $(KDIR) M=$(shell pwd) modules diff --git a/kprobe_trace.c b/kprobe_trace.c index 755607c..a001155 100644 --- a/kprobe_trace.c +++ b/kprobe_trace.c @@ -17,6 +17,7 @@ void test_func2(struct test_struct p); void test_func1(struct test_struct *p) { + printk("%d\n", p->val); printk("%s\n", p->name); printk("%s\n", p->pname); printk("%d\n", p->arr[1]); @@ -25,6 +26,7 @@ void test_func1(struct test_struct *p) void test_func2(struct test_struct p) { + printk("%d\n", p.val); printk("%s\n", p.name); printk("%s\n", p.pname); printk("%d\n", p.arr[1]); diff --git a/lockup.c b/lockup.c new file mode 100644 index 0000000..277b7b1 --- /dev/null +++ b/lockup.c @@ -0,0 +1,120 @@ +#include +#include +#include +#include + +MODULE_LICENSE("GPL v2"); + +static struct work_struct dwork; +static struct workqueue_struct *wq; + +static void demo_work(struct work_struct * unused) +{ + int i = 0, j = 0; + + // set_worker_desc("hwc"); + printk("[cpu%d]: %s %d\n", raw_smp_processor_id(), __func__, __LINE__); + while(j < 2000) { + for (i = 0; i < 10000000; i++) + if (i % 100000 == 0) + printk("[cpu%d]: %s %d, i is %d, j is %d\n", raw_smp_processor_id(), __func__, __LINE__, i, j); + + j++; + } +} + +static ssize_t demo_read(struct file *filp, char __user *buff, size_t size, loff_t *pos) +{ + preempt_disable(); + printk("[cpu%d]: %s %d\n", raw_smp_processor_id(), __func__, __LINE__); + while(1); + return size; +} + +static ssize_t demo_write(struct file *filp, const char __user *buff, size_t size, loff_t *pos) +{ + printk("[cpu%d]: %s %d\n", raw_smp_processor_id(), __func__, __LINE__); + local_irq_disable(); + while(1); + printk("[cpu%d]: %s %d\n", raw_smp_processor_id(), __func__, __LINE__); + + return size; +} + +static int demo_open(struct inode *inode, struct file *filp) +{ + printk("%s %d\n", __func__, __LINE__); + return 0; +} + +static int demo_release(struct inode *inode, struct file *filp) +{ + printk("%s %d\n", __func__, __LINE__); + return 0; +} + +struct file_operations demo_fops = { + .owner = THIS_MODULE, + .read = demo_read, + .write = demo_write, + .open = demo_open, + .release = demo_release, +}; + +static dev_t dev; +static struct cdev *cdev; + +static int demo_init(void) +{ + int rc; + + INIT_WORK(&dwork, demo_work); + + rc = alloc_chrdev_region(&dev, 0, 1, "demo"); + if (rc) { + printk("failed to alloc chrdev number\n"); + return rc; + } + + cdev = cdev_alloc(); + if (!cdev) { + printk("failed to alloc cdev\n"); + rc = -ENOMEM; + goto out_unregister_chrdev; + } + + cdev->owner = THIS_MODULE; + cdev_init(cdev, &demo_fops); + + rc = cdev_add(cdev, dev, 1); + if (rc) { + printk("failed to add char device\n"); + goto out_free_cdev; + } + + wq = create_workqueue("demo123456789abcdefghijklmnopq"); + + queue_work(wq, &dwork); + + return 0; + +out_free_cdev: + kobject_put(&cdev->kobj); + +out_unregister_chrdev: + unregister_chrdev_region(dev, 1); + + return rc; +} + +static void demo_exit(void) +{ + cdev_del(cdev); + + unregister_chrdev_region(dev, 1); + + destroy_workqueue(wq); +} + +module_init(demo_init); +module_exit(demo_exit); diff --git a/mknod.sh b/mknod.sh index 982b644..d9eb594 100755 --- a/mknod.sh +++ b/mknod.sh @@ -1,6 +1,6 @@ #!/bin/sh -major=$(cat /proc/devices | grep demo) +major=$(cat /proc/devices | grep demo | awk '{print $1}') -mknode /dev/demo c $major 0 +mknod /dev/demo c $major 0