中国建设银行网站登录不了,asp网页编辑器,网站建设销售员工作内容,photoshop手机版在线使用tasklet
tasklet机制是内核定义的几种softirq之一(常用)
根据优先级不同内核将tasklet分成两种#xff1a;TASKLET_SOFTIRQ 和 HI_SOFTIRQ (后者优先级高)
执行时机通常是上半部分返回的时候。
1.1 tasklet机制初始化
在linux系统内核初始化的时候#xff0c;通过调用softirq…tasklettasklet机制是内核定义的几种softirq之一(常用)根据优先级不同内核将tasklet分成两种TASKLET_SOFTIRQ 和 HI_SOFTIRQ (后者优先级高)执行时机通常是上半部分返回的时候。1.1 tasklet机制初始化在linux系统内核初始化的时候通过调用softirq_init( )为TASKLET_SOFTIRQ 和 HI_SOFTIRQ安装了执行函数。1.2 相关的操作struct tasklet_struct{struct tasklet_struct *next; //用来将系统中tasklet链接成链表unsigned long state; //记录在系统中tasklet的状态atomic_t count; //如果为0则不可被调度执行void (*func)(unsigned long); //在tasklet上执行函数或者延迟函数unsigned long data; //将data传递给fun指向的函数};1.2.1 初始化tasklet声明并初始化一个静态的tasklet对象//struct tasklet_struct name;//void func(unsigned long);//unsingned long data;DECLARE_TASKLET(name, func, data);动态初始化tasklet对象void tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long), unsigned long data)–tasklet_init(name, fun, data);1.2.2 提交一个tasklet在声明和初始化一个tasklet对象之后驱动程序需要调用tasklet_schedule来向系统提交tasklet(一般在中断处理程序中提交)void tasklet_schedule(struct tasklet_struct *t)tasklet_schedule(name);工作队列使用内核自己带的工作队列工作队列执行的上下文是内核线程因此可以调度和睡眠在Workqueue机制中Linux系统在初始化的时候通过init_workqueues(void)函数创建了一个workqueue队列——events用户可以直接初始化一个work_struct对象然后在该队列中进行调度使用更加方便。//定义一个工作节点structwork_sturctmy_wrok;//定一个处理函数voidmy_wq_func(structwork_struct*work);/*初始化工作节点并和处理函数绑定*/INIT_WORK(my_work,my_wq_func)/*使用内核自己创建的工作队列-events和处理线程, 提交工作节点(一般在中断处理函数中)*/schedule_work(my_wq)---queue_work(system_wq,work);使用自己创建工作队列首先创建工作队列#define create_workqueue(name)alloc_workqueue((name), WQ_MEM_RECLAIM, 1)—struct workqueue_struct* myworkqueue create_workqueue(“mywq”); /创建工作队列和处理线程/提交工作int queue_work(struct workqueue_struct *wq, struct work_struct *work)–queue_work(myworkqueue, my_work);#definecreate_workqueue(name)\alloc_workqueue(%s,__WQ_LEGACY|WQ_MEM_RECLAIM,1,(name))structworkqueue_struct*alloc_workqueue(constchar*fmt,unsignedintflags,intmax_active,...){size_ttbl_size0;va_list args;structworkqueue_struct*wq;structpool_workqueue*pwq;/* * Unbound max_active 1 used to imply ordered, which is no * longer the case on NUMA machines due to per-node pools. While * alloc_ordered_workqueue() is the right way to create an ordered * workqueue, keep the previous behavior to avoid subtle breakages * on NUMA. */if((flagsWQ_UNBOUND)max_active1)flags|__WQ_ORDERED;/* see the comment above the definition of WQ_POWER_EFFICIENT */if((flagsWQ_POWER_EFFICIENT)wq_power_efficient)flags|WQ_UNBOUND;/* allocate wq and format name */if(flagsWQ_UNBOUND)tbl_sizenr_node_ids*sizeof(wq-numa_pwq_tbl[0]);wqkzalloc(sizeof(*wq)tbl_size,GFP_KERNEL);if(!wq)returnNULL;if(flagsWQ_UNBOUND){wq-unbound_attrsalloc_workqueue_attrs();if(!wq-unbound_attrs)gotoerr_free_wq;}va_start(args,max_active);vsnprintf(wq-name,sizeof(wq-name),fmt,args);va_end(args);max_activemax_active?:WQ_DFL_ACTIVE;max_activewq_clamp_max_active(max_active,flags,wq-name);/* init wq */wq-flagsflags;wq-saved_max_activemax_active;mutex_init(wq-mutex);atomic_set(wq-nr_pwqs_to_flush,0);INIT_LIST_HEAD(wq-pwqs);INIT_LIST_HEAD(wq-flusher_queue);INIT_LIST_HEAD(wq-flusher_overflow);INIT_LIST_HEAD(wq-maydays);wq_init_lockdep(wq);INIT_LIST_HEAD(wq-list);if(alloc_and_link_pwqs(wq)0)gotoerr_unreg_lockdep;if(wq_onlineinit_rescuer(wq)0)gotoerr_destroy;if((wq-flagsWQ_SYSFS)workqueue_sysfs_register(wq))gotoerr_destroy;/* * wq_pool_mutex protects global freeze state and workqueues list. * Grab it, adjust max_active and add the new wq to workqueues * list. */mutex_lock(wq_pool_mutex);mutex_lock(wq-mutex);for_each_pwq(pwq,wq)pwq_adjust_max_active(pwq);mutex_unlock(wq-mutex);list_add_tail_rcu(wq-list,workqueues);mutex_unlock(wq_pool_mutex);returnwq;err_unreg_lockdep:wq_unregister_lockdep(wq);wq_free_lockdep(wq);err_free_wq:free_workqueue_attrs(wq-unbound_attrs);kfree(wq);returnNULL;err_destroy:destroy_workqueue(wq);returnNULL;}EXPORT_SYMBOL_GPL(alloc_workqueue);queue_work/* not bound to any CPU, prefer the local CPU */,//WORK_CPU_UNBOUND NR_CPUS,staticinlineboolqueue_work(structworkqueue_struct*wq,structwork_struct*work){returnqueue_work_on(WORK_CPU_UNBOUND,wq,work);}