In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Linux interrupt programming is divided into the top half and the bottom half of the interrupt.
Interrupt the top half: do something urgent and time-consuming, and start the interrupt bottom part at the same time.
The bottom half of the interrupt: do a time-consuming event that can be interrupted during execution.
The realization method of interrupt bottom half: tasklet, work queue, soft interrupt and other mechanisms. In fact, it is to postpone the execution of time-consuming events, not interrupting the execution of the program.
What is tasklet?
The original meaning of the word Tasklet is "small task", which refers to a small piece of executable code, usually in the form of a function. This tasklet-bound function can only run on one CPU at a time. The tasklet (small tasks) mechanism is the most commonly used method for the lower half of interrupt handling, and its use is also very simple. An interrupt program that uses tasklet will first quickly complete the upper part of the work by executing the interrupt handler, and then make the lower part of the work complete by calling tasklet. As you can see, the lower part is called by the upper part, and it is the job of the kernel as to when the lower part is executed.
Tasklet mechanism core data structure Interrupt.h linux-3.5\ include\ Linuxstruct tasklet_struct {struct tasklet_struct * next; / / tasklet_struct structure linked list unsigned long state; / / whether the current tasklet has been scheduled atomic_t count; void (* func) (unsigned long); / / pointer to the function bound by tasklet unsigned long data; / / parameters passed to the function bound by tasklet}; tasklet related API
Initialization correlation
1) static initialization of DECLARE_TASKLET (name, func, data)
Function: define a tasklet_struct structure variable named name and initialize the structure. The tasklet defined can be scheduled and is enabled by default.
2) static initialization of DECLARE_TASKLET_DISABLED (name, func, data)
Function: define a tasklet_struct structure variable named name and initialize the structure. The defined tasklet cannot be scheduled and is disabled by default. To schedule this tasklet, you need to enable it first.
3) dynamic initialization
Void tasklet_init (struct tasklet_struct * t func void (* func) (unsigned long), unsigned long data)
Function: initialize a tasklet_struct structure variable. The initialized structure is active by default and can be scheduled. Tasklet_disable enable function
1. Void tasklet_disable (struct tasklet_struct * t)
Function: the function activates the given tasklet to be scheduled by tasklet_schedule
2. Void tasklet_enable (struct tasklet_struct * t)
Function: function forbids a given tasklet to be scheduled by tasklet_schedule
Tasklet scheduling function
Void tasklet_schedule (struct tasklet_struct * t)
Function: call the tasklet_schedule function to notify the kernel to help us schedule the bound function
Void tasklet_kill (struct tasklet_struct * t)
Function: cancel the scheduling function
Programming step Step1 defines and statically initializes the tasklet_struct structure variable Step2 to write the tasklet service function Step3 to schedule in the appropriate place Step4 to cancel the scheduling development platform Xinling SinlinxA33 development board Taobao store: [https://sinlinx.taobao.com/]()
Embedded linux development board communicates QQ:641395230
Driver code:
# include # include # include void tasklet_fun (unsigned long data); / / Step1 defines and statically initializes the tasklet_struct structure variable DECLARE_TASKLET (mytasklet, tasklet_fun, 651); / / Step2 tasklet service function void tasklet_fun (unsigned long data) {static unsigned long count = 0; printk ("count:%lu,%s is call! Data:%lu\ r\ n ", count++,__FUNCTION__,data); tasklet_schedule (& mytasklet); / / reschedule yourself in the working function, which will call tasklet_fun} static int _ init mytasklet_init (void) {/ / Step3 to start scheduling mytasklet tasklet_schedule (& mytasklet); printk ("% s is call!\ r\ n ", _ _ FUNCTION__); return 0 } static void _ exit mytasklet_exit (void) / / Module exit function specified by module_exit () {/ / Step4 delete tasklet tasklet_kill (& mytasklet);} module_init (mytasklet_init); module_exit (mytasklet_exit); MODULE_LICENSE ("GPL")
Makefile code
KERN_DIR = / work/lichee/linux-3.4all: make-C $(KERN_DIR) M = `pwd` modules arm-none-linux-gnueabi-gcc btntest.c-o btntestclean: make-C $(KERN_DIR) M = `pwd` modules clean rm- rf modules.orderobj-m + = tasklet_drv.o Experimental phenomenon cycle call tasklet_fun function
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.