1. 注册软中断当然是通过open_softirq

例子如下:

  1. void __init init_timers(void)
  2. {
  3. int err = timer_cpu_notify(&timers_nb, (unsigned long)CPU_UP_PREPARE,
  4. (void *)(long)smp_processor_id());
  5. init_timer_stats();
  6. BUG_ON(err == NOTIFY_BAD);
  7. register_cpu_notifier(&timers_nb);
  8. open_softirq(TIMER_SOFTIRQ, run_timer_softirq);
  9. }
  10. void open_softirq(int nr, void (*action)(struct softirq_action *))
  11. {
  12. softirq_vec[nr].action = action;
  13. }

软中断TIMER_SOFTIRQ的中断处理函数为:run_timer_softirq

之所以成为softirq,是因为这些中断是由硬件中断来间接触发的,如何间接触发的呢:
硬件中断处理函数-->对软中断的相应位置位-->唤醒ksoftirqd线程-->执行软中断的中断处理函数

2. 硬件中断如何通过置位唤醒ksoftirqd线程

timer interrupt handler->
timer_tick->
update_process_times->
run_local_timers->
hrtimer_run_queues()和raise_softirq(TIMER_SOFTIRQ)->
raise_softirq_irqoff->
__raise_softirq_irqoff { or_softirq_pending(1UL << (nr)); }
即(local_softirq_pending() |= (x))

3. 如何执行软中断的action<中断处理函数>

对于TIMER_SOFTIRQ来说,每次system clock产生中断时,即一个tick 到来时,在system clock的中断处理函数中会调用run_local_timers来设置TIMER_SOFTIRQ触发条件;也就是当前CPU对应的irq_cpustat_t结构体中的__softirq_pending成员的第TIMER_SOFTIRQ个BIT被置为1。 而当这个条件满足时,ksoftirqd线程(入口函数run_ksoftirqd,cpu_callback:kthread_create(run_ksoftirqd, hcpu, "ksoftirqd/%d", hotcpu);)会被唤醒,然后按照下面的流程调用TIMER_SOFTIRQ在数组softirq_vec中注册的action,即run_timer_softirq。
run_ksoftirqd--->do_softirq--->__do_softirq--->softirq_vec[TIMER_SOFTIRQ].action

  1. static int run_ksoftirqd(void * __bind_cpu)
  2. {
  3. set_current_state(TASK_INTERRUPTIBLE);
  4. while (!kthread_should_stop()) {
  5. preempt_disable();
  6. if (!local_softirq_pending()) {
  7. preempt_enable_no_resched();
  8. schedule();
  9. preempt_disable();
  10. }
  11. __set_current_state(TASK_RUNNING);
  12. while (local_softirq_pending()) {
  13. /* Preempt disable stops cpu going offline.
  14. If already offline, we'll be on wrong CPU:
  15. don't process */
  16. if (cpu_is_offline((long)__bind_cpu))
  17. goto wait_to_die;
  18. do_softirq();
  19. preempt_enable_no_resched();
  20. cond_resched();
  21. preempt_disable();
  22. rcu_sched_qs((long)__bind_cpu);
  23. }
  24. preempt_enable();
  25. set_current_state(TASK_INTERRUPTIBLE);
  26. }
  27. __set_current_state(TASK_RUNNING);
  28. return 0;
  29. wait_to_die:
  30. preempt_enable();
  31. /* Wait for kthread_stop */
  32. set_current_state(TASK_INTERRUPTIBLE);
  33. while (!kthread_should_stop()) {
  34. schedule();
  35. set_current_state(TASK_INTERRUPTIBLE);
  36. }
  37. __set_current_state(TASK_RUNNING);
  38. return 0;
  39. }

ARM Linux 如何--注册和触发--软中断的更多相关文章

  1. ARM Linux 3.x的设备树(Device Tree)

    http://blog.csdn.net/21cnbao/article/details/8457546 宋宝华 Barry Song <21cnbao@gmail.com> 1.     ...

  2. ARM Linux 3.x的设备树(Device Tree)

    1. ARM Device Tree起源 Linus Torvalds在2011年3月17日的ARM Linux邮件列表宣称“this whole ARM thing is a f*cking pai ...

  3. 【转】 ARM Linux 3.x的设备树(Device Tree)

    1.    ARM Device Tree起源 http://blog.csdn.net/21cnbao/article/details/8457546 Linus Torvalds在2011年3月1 ...

  4. 【转】ARM Linux 3.x的设备树(Device Tree)

    原文网址:http://blog.csdn.net/21cnbao/article/details/8457546 1.    ARM Device Tree起源 Linus Torvalds在201 ...

  5. ARM Linux 3.x的设备树(Device Tree)【转】

    转自:http://blog.csdn.net/21cnbao/article/details/8457546 宋宝华 Barry Song <21cnbao@gmail.com> 1.  ...

  6. ARM Linux 大小核切换 ——cortex-A7 big.LITTLE 大小核 切换代码分析

    ARM Linux 大小核切换——cortex-A7 big.LITTLE 大小切换代码分析 8核CPU或者是更多核的处理器,这些CPU有可能不完全对称.有的是4个A15和4个A7,或者是4个A57和 ...

  7. Arm Linux系统调用流程详细解析

    Linux系统通过向内核发出系统调用(system call)实现了用户态进程和硬件设备之间的大部分接口. 系统调用是操作系统提供的服务,用户程序通过各种系统调用,来引用内核提供的各种服务,系统调用的 ...

  8. Linux GPIO 注册和应用

    Linux GPIO 注册和应用 Linux Kernel, GPIO, ARM 于Linux kernel代码.经常使用 GPIO 作为一个特殊的信号,如芯片片选信号. GPIO 功能应用,我们经常 ...

  9. ARM Linux驱动篇 学习温度传感器ds18b20的驱动编写过程

    ARM Linux驱动篇 学习温度传感器ds18b20的驱动编写过程 原文地址:http://www.cnblogs.com/NickQ/p/9026545.html 一.开发板与ds18b20的入门 ...

随机推荐

  1. PDF ITextSharp

    示例源码 //Document:(文档)生成pdf必备的一个对象,生成一个Document示例 Document document = new Document(PageSize.A4, 30, 30 ...

  2. C# 构造函数中调用虚方法的问题

    请看下面代码: using System; public class A{ public A(){ M1(); } public virtual void M1(){} } public class ...

  3. GDataXMLNode创建和解析XML

    GDataXMLNode创建xml: #import <Foundation/Foundation.h> 2 #import "GDataXMLNode.h" 3 4 ...

  4. doc下批处理文件的感想

    这段时间忙着为我们的爬虫程序做一个守护进程,想来想去还是用脚本比较好,所以用了点时间仔细的研究了一下,这里有一点点经验想分享给大家,也不能说是经验了,只能说是我写这个的时候所用到的知识: 1.task ...

  5. 玩转Log4Net

    玩转Log4Net 下载Log4Net 下载地址:http://logging.apache.org/log4net/download_log4net.cgi 把下载的  log4net-1.2.11 ...

  6. 1185: [HNOI2007]最小矩形覆盖 - BZOJ

      就是一道凸包(枚举凸包的边作为矩形的一条边)的裸题,只是不太好打,所以犹豫到今天才打 不说了,说起AC都是泪啊,因为没有精度判断,没有判重(算距离时除0了)错了好久 拍了好久都和标称是一样的,因为 ...

  7. hibernate.cfg.xml配置(Oracle+c3p0)

    说明:数据库:Oracle10g:连接池:c3p0 结构: 一.配置hibernate.cfg.xml <?xml version="1.0" encoding=" ...

  8. 解决Oracle ORA-00984: column not allowed here

    某列是字符列,结果忘记加单引号了 INSERT INTO prt_document_present (company_code, doc_no, seq_no, field_name, desc_ms ...

  9. MySQL exist

    http://www.cnblogs.com/glory-jzx/archive/2012/07/19/2599215.html http://www.w3school.com.cn/sql/func ...

  10. HDU4502吉哥系列故事——临时工计划

    http://acm.hdu.edu.cn/showproblem.php?pid=4502 题意 :这个是中文题,我就不再详述了. 思路 : 以前做过一个活动区间选择,结果就按着那个思路敲了,后来发 ...