Linux 内核WorkQueue阅读笔记
1. Workqueue
Workqueue的名字就和他的功能一样:需要处理的工作列表和工作的添加删除(貌似没有看到如何删除的)、以及工作的调度执行。
需要处理的工作列表通常都维护在内核对象workqueue_struct里面。系统里面可以有多个workqueue_struct。内核部分的工作添加到了工作队列keventd_wq。而fs/aio.c里面实现了自己的工作队列aio_wq。
workqueue_struct是双向循环链表。里面的单元是work_struct。
驱动接口:
create_workqueue:创建工作队列结构和内核处理线程。
schedule_work/schedule_delayed_work:调度执行一个具体的任务,执行的任务将会被挂入Linux系统提供的workqueue keventd_wq。请注意,调度执行并不等于立刻执行。而是指示worker_thread在下次处理工作队列的时候执行该工作;
queue_work/queue_delayed_work:调度执行一个指定workqueue中的任务。内核本身提供了一个工作队列keventd_wq。但是,系统里面也可以有其他的工作队列。所以就有了schedule_work和queue_work的区分。
1.1 schedule_work
从schedule_work的实现看,其和queue_work的实现区别并不大:
int schedule_work(struct work_struct *work)
{
return queue_work(keventd_wq, work);
}
int queue_work(struct workqueue_struct *wq, struct work_struct *work)
{
int ret;
ret = queue_work_on(get_cpu(), wq, work);
put_cpu();
return ret;
}
int
queue_work_on(int cpu, struct workqueue_struct *wq, struct work_struct *work)
{
int ret = 0;
相关文档:
用Linux下的LVS软件实现Linux集群
德英
发表于2010年03月15日 18:22
阅读( ......
所需文件hello.c, main.c, hello.h, Makefile,在同一个目录下
hello.c:
#include <stdio.h>
void hello(char name[])
{
printf("Hello %s!\n", name);
}
main.c:
#include "stdio.h"
#include "hello.h"
// The second
int main()
{
hello("GCC");
printf("Haha Linux Ubuntu!\n");
......
文件在两个文件夹:
inc/hello.h
main/hello.c, main.c, Makefile
文件内容:
hello.h
void hello(char name[]);
hello.c
#include <stdio.h>
void hello(char name[])
{
printf("Hello %s!\n", name);
}
main.c
#include <stdio.h>
#include "../inc/hello.h"
// The second
int main( ......
复制以下内容,保存为 py 后缀的文件,拷贝到wallpaper文件夹,进入文件夹,以python运行,选取xml为壁纸
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
# Ubuntu 9.10 dynamic wallpaper maker_Can be used in all the distributions of linux
#
# Auto generate a configuration file which you can use ......