zoukankan      html  css  js  c++  java
  • ARM Linux 如何--注册和触发--软中断

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

    例子如下:

    [cpp] view plain copy
     
    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.   
    6.     init_timer_stats();  
    7.   
    8.     BUG_ON(err == NOTIFY_BAD);  
    9.     register_cpu_notifier(&timers_nb);  
    10.     open_softirq(TIMER_SOFTIRQ, run_timer_softirq);  
    11. }  
    12.   
    13. void open_softirq(int nr, void (*action)(struct softirq_action *))  
    14. {  
    15.     softirq_vec[nr].action = action;  
    16. }  

    软中断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


     

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


     

  • 相关阅读:
    高中数学相关的专业术语
    数学-高数2
    python+unittest+xlrd+request搭建API测试框架
    接口自动化,断言方法,深度定位错误
    python+requests+unittest API接口测试
    python+unittest框架整理(一点点学习前辈们的封装思路,一点点成长。。。)
    学习python的第一个小目标:通过requests+xlrd实现简单接口测试,将测试用例维护在表格中,与脚本分开。
    队列 —— 先入先出的数据结构
    卷积神经网络的简单可视化
    HOG 特征提取算法(实践篇)
  • 原文地址:https://www.cnblogs.com/lidabo/p/5312856.html
Copyright © 2011-2022 走看看