From b871dab562aeb10317ecdbb73291de6cf817740f Mon Sep 17 00:00:00 2001 From: Cheng Jian Date: Fri, 26 Jul 2019 16:45:36 +0800 Subject: [PATCH] update schedule 09-tuning --- study/driver/00-code/hello/hello.c | 5 +- study/driver/00-code/hello/hello2.c | 47 ----------- study/driver/00-code/hello/hello2.c~ | 47 ----------- .../00-code/scheduling_while_atomic/Makefile | 78 +++++++++++++++++++ .../00-code/scheduling_while_atomic/hello.c | 42 ++++++++++ 5 files changed, 124 insertions(+), 95 deletions(-) delete mode 100644 study/driver/00-code/hello/hello2.c delete mode 100644 study/driver/00-code/hello/hello2.c~ create mode 100644 study/kernel/01-process/00-code/scheduling_while_atomic/Makefile create mode 100644 study/kernel/01-process/00-code/scheduling_while_atomic/hello.c diff --git a/study/driver/00-code/hello/hello.c b/study/driver/00-code/hello/hello.c index 3f17770..9c0076c 100644 --- a/study/driver/00-code/hello/hello.c +++ b/study/driver/00-code/hello/hello.c @@ -13,7 +13,10 @@ MODULE_DESCRIPTION("hello world"); static int hello_init(void) { - return 0; + set_current_state(TASK_UNINTERRUPTIBLE); + schedule(); + + return 0; } diff --git a/study/driver/00-code/hello/hello2.c b/study/driver/00-code/hello/hello2.c deleted file mode 100644 index 5456733..0000000 --- a/study/driver/00-code/hello/hello2.c +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include -//#include -//#include -//#include - -MODULE_LICENSE("Dual BSD/GPL"); -MODULE_AUTHOR("Gatieme"); -MODULE_DESCRIPTION("hello world"); - -/* - * print the module information - */ -static void print_module(void) -{ - struct module *mod; - - printk(KERN_ALERT "this module: %p==%p\n", &__this_module, THIS_MODULE); - printk(KERN_ALERT "module state: %d\n", THIS_MODULE->state); - printk(KERN_ALERT "module name: %s\n", THIS_MODULE->name); - - list_for_each_entry(mod, *(&THIS_MODULE->list.prev), list); - printk(KERN_ALERT "module name: %s\n", mod->name); - printk(KERN_ALERT "module state: %d\n", THIS_MODULE->state); -} - -static int hello_init(void) -{ - print_module(); - - printk(KERN_ALERT "run in cpu %d\n", get_cpu()); - - printk(KERN_ALERT "PAGE_OFFSET : 0x%lx, TASK_SIZE : 0x%lx", PAGE_OFFSET, - TASK_SIZE); - - return 0; -} - -static void hello_exit(void) -{ - printk(KERN_ERR "exit"); -} - -module_init(hello_init); -module_exit(hello_exit); diff --git a/study/driver/00-code/hello/hello2.c~ b/study/driver/00-code/hello/hello2.c~ deleted file mode 100644 index 5456733..0000000 --- a/study/driver/00-code/hello/hello2.c~ +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include -//#include -//#include -//#include - -MODULE_LICENSE("Dual BSD/GPL"); -MODULE_AUTHOR("Gatieme"); -MODULE_DESCRIPTION("hello world"); - -/* - * print the module information - */ -static void print_module(void) -{ - struct module *mod; - - printk(KERN_ALERT "this module: %p==%p\n", &__this_module, THIS_MODULE); - printk(KERN_ALERT "module state: %d\n", THIS_MODULE->state); - printk(KERN_ALERT "module name: %s\n", THIS_MODULE->name); - - list_for_each_entry(mod, *(&THIS_MODULE->list.prev), list); - printk(KERN_ALERT "module name: %s\n", mod->name); - printk(KERN_ALERT "module state: %d\n", THIS_MODULE->state); -} - -static int hello_init(void) -{ - print_module(); - - printk(KERN_ALERT "run in cpu %d\n", get_cpu()); - - printk(KERN_ALERT "PAGE_OFFSET : 0x%lx, TASK_SIZE : 0x%lx", PAGE_OFFSET, - TASK_SIZE); - - return 0; -} - -static void hello_exit(void) -{ - printk(KERN_ERR "exit"); -} - -module_init(hello_init); -module_exit(hello_exit); diff --git a/study/kernel/01-process/00-code/scheduling_while_atomic/Makefile b/study/kernel/01-process/00-code/scheduling_while_atomic/Makefile new file mode 100644 index 0000000..807729b --- /dev/null +++ b/study/kernel/01-process/00-code/scheduling_while_atomic/Makefile @@ -0,0 +1,78 @@ +# ------------------------------------------------------------------------------ +# +# Makefile for the LDD-LinuxDeviceDrivers. +# +# Author: gatieme +# Create: 2016-07-29 15:50:46 +# Last modified: 2016-07-29 16:10:29 +# Description: +# This program is loaded as a kernel(v2.6.18 or later) module. +# Use "make install" to load it into kernel. +# Use "make remove" to remove the module out of kernel. +# +# ------------------------------------------------------------------------------ + + +ROOT=.. +#PLATFORM=$(shell $(ROOT)/systype.sh) +#include $(ROOT)/Make.defines.$(PLATFORM) + +# my driver description +DRIVER_VERSION := "1.0.0" +DRIVER_AUTHOR := "Gatieme @ AderStep Inc..." +DRIVER_DESC := "Linux input module for Elo MultiTouch(MT) devices" +DRIVER_LICENSE := "Dual BSD/GPL" + + +MODULE_NAME := hello + +ifneq ($(KERNELRELEASE),) + +#CFG_FLAGS += -O2 -I./ +#EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC) + + + +obj-m := $(MODULE_NAME).o #print_vmarea.o + +else + +KERNELDIR ?= /lib/modules/$(shell uname -r)/build + +PWD := $(shell pwd) + +modules: + make -C $(KERNELDIR) M=$(PWD) modules + +modules_install: + make -C $(KERNELDIR) M=$(PWD) modules_install + + + +insmod: + sudo insmod $(MODULE_NAME).ko + +reinsmod: + sudo rmmod $(MODULE_NAME) + sudo insmod $(MODULE_NAME).ko + +github: + cd $(ROOT) && make github + +rmmod: + sudo rmmod $(MODULE_NAME) + +test : + sudo ../injector/memInjector -l stack -m random -t word_0 --time 1 --timeout 3 -p 1 + +clean: + make -C $(KERNELDIR) M=$(PWD) clean + rm -f modules.order Module.symvers Module.markers + +.PHNOY: + modules modules_install clean + + + +endif + diff --git a/study/kernel/01-process/00-code/scheduling_while_atomic/hello.c b/study/kernel/01-process/00-code/scheduling_while_atomic/hello.c new file mode 100644 index 0000000..0424edd --- /dev/null +++ b/study/kernel/01-process/00-code/scheduling_while_atomic/hello.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include + +DEFINE_SPINLOCK(lock); + +static void scheduling(struct irq_work *work) +{ + schedule(); +} + + +DEFINE_IRQ_WORK(irq_work, scheduling); +static int __init hello_init(void) +{ + irq_work_queue(&irq_work); + + return 0; +} + +module_init(hello_init); + +static void __exit hello_exit(void) +{ +} + +module_exit(hello_exit); + +/* Driver Information */ +#define DRIVER_VERSION "1.0.0" +#define DRIVER_AUTHOR "Gatieme @ AderStep Inc..." +#define DRIVER_DESC "Linux input module for Elo MultiTouch(MT) devices" +#define DRIVER_LICENSE "Dual BSD/GPL" + +/* Kernel Module Information */ +MODULE_VERSION(DRIVER_VERSION); +MODULE_AUTHOR(DRIVER_AUTHOR); +MODULE_DESCRIPTION(DRIVER_DESC); +MODULE_LICENSE(DRIVER_LICENSE);