ELDD读书笔记:第三章 内核组件

来源:互联网 发布:中国软件重组预期 编辑:程序博客网 时间:2024/06/15 15:59

ELDD读书笔记:第三章 内核组件

  • ELDD读书笔记第三章 内核组件
    • 内核线程
      • 1 创建内核线程
      • 2 进程状态和等待队列
      • 3 用户模式辅助程序
    • 辅助接口
      • 1链表
      • 2散列链表
      • 3工作队列
      • 4通知链
      • 5完成接口
      • 6kthread辅助接口
      • 7错误处理助手
    • 查看源代码

0 内核线程

[1] 创建内核线程

【代码清单3-1】实现内核线程 P39static DECLARE_WAIT_QUEUE_HEAD(myevent_waitqueue);rwlock_t myevent_lock;extern unsigned int myevent_id;/* Holds the identify of the troubled data structure.Populated later on */static int mykthread(void *unused){    unsigned int event_id = 0;    DECLARE_WAITQUEUE(wait,current);    /* Become a kernel thread without attached user resources */    daemonize("mythread");    /* Request delivery of SIGKILL */    allow_signal(SIGKILL);    /* The thread sleeps on this wait queue until it's woken up by parts of the kernel in charge of sensing the health of data structure of interest */    for(;;)    {        /* Relinquish the processor until the event occurs */        set_current_state(TASK_INTERRUPTIBLE);        schedule();/* Allow other parts of the kernel to run*/        /* Die if I receive SIGKILL */        if(signal_pending(current))             break;        /* Control gets here when the thread is woken up */        read_lock(&myevent_lock);/* Critical section ends */        if(myevent_id)        {            event_id = myevent_id;            read_unlock(&myevent_lock);/* Critical section ends */            /*Invoke the registered user mode helper and pass the identify code in its environment*/            run_umode_handler(event_id);/* Expanded later on */        }        else        {            read_unlock(&myevent_lock);        }    }    set_current_state(TASK_RUNING);    remove_wait_queue(&myevent_waitqueue,&wait);    return 0;}

[2] 进程状态和等待队列

[3] 用户模式辅助程序

1 辅助接口

[1]链表

[2]散列链表

[3]工作队列

[4]通知链

[5]完成接口

[6]kthread辅助接口

[7]错误处理助手

2 查看源代码

原创粉丝点击