日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

ARM Linux 如何--注册和触发--软中断

發(fā)布時間:2023/12/15 linux 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ARM Linux 如何--注册和触发--软中断 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1. 注冊軟中斷當(dāng)然是通過open_softirq

例子如下:

[cpp]?view plain?copy
  • void?__init?init_timers(void)??
  • {??
  • ????int?err?=?timer_cpu_notify(&timers_nb,?(unsigned?long)CPU_UP_PREPARE,??
  • ????????????????(void?*)(long)smp_processor_id());??
  • ??
  • ????init_timer_stats();??
  • ??
  • ????BUG_ON(err?==?NOTIFY_BAD);??
  • ????register_cpu_notifier(&timers_nb);??
  • ????open_softirq(TIMER_SOFTIRQ,?run_timer_softirq);??
  • }??
  • ??
  • void?open_softirq(int?nr,?void?(*action)(struct?softirq_action?*))??
  • {??
  • ????softirq_vec[nr].action?=?action;??
  • }??
  • 軟中斷TIMER_SOFTIRQ的中斷處理函數(shù)為:run_timer_softirq

    之所以成為softirq,是因為這些中斷是由硬件中斷來間接觸發(fā)的,如何間接觸發(fā)的呢:
    硬件中斷處理函數(shù)-->對軟中斷的相應(yīng)位置位-->喚醒ksoftirqd線程-->執(zhí)行軟中斷的中斷處理函數(shù)

    ?

    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. 如何執(zhí)行軟中斷的action<中斷處理函數(shù)>

    對于TIMER_SOFTIRQ來說,每次system clock產(chǎn)生中斷時,即一個tick 到來時,在system clock的中斷處理函數(shù)中會調(diào)用run_local_timers來設(shè)置TIMER_SOFTIRQ觸發(fā)條件;也就是當(dāng)前CPU對應(yīng)的irq_cpustat_t結(jié)構(gòu)體中的__softirq_pending成員的第TIMER_SOFTIRQ個BIT被置為1。 而當(dāng)這個條件滿足時,ksoftirqd線程(入口函數(shù)run_ksoftirqd,cpu_callback:kthread_create(run_ksoftirqd, hcpu, "ksoftirqd/%d", hotcpu);)會被喚醒,然后按照下面的流程調(diào)用TIMER_SOFTIRQ在數(shù)組softirq_vec中注冊的action,即run_timer_softirq。
    run_ksoftirqd--->do_softirq--->__do_softirq--->softirq_vec[TIMER_SOFTIRQ].action


    ?

    [cpp]?view plain?copy
  • static?int?run_ksoftirqd(void?*?__bind_cpu)??
  • {??
  • ????set_current_state(TASK_INTERRUPTIBLE);??
  • ??
  • ????while?(!kthread_should_stop())?{??
  • ????????preempt_disable();??
  • ????????if?(!local_softirq_pending())?{??
  • ????????????preempt_enable_no_resched();??
  • ????????????schedule();??
  • ????????????preempt_disable();??
  • ????????}??
  • ??
  • ????????__set_current_state(TASK_RUNNING);??
  • ??
  • ????????while?(local_softirq_pending())?{??
  • ????????????/*?Preempt?disable?stops?cpu?going?offline.?
  • ???????????????If?already?offline,?we'll?be?on?wrong?CPU:?
  • ???????????????don't?process?*/??
  • ????????????if?(cpu_is_offline((long)__bind_cpu))??
  • ????????????????goto?wait_to_die;??
  • ????????????do_softirq();??
  • ????????????preempt_enable_no_resched();??
  • ????????????cond_resched();??
  • ????????????preempt_disable();??
  • ????????????rcu_sched_qs((long)__bind_cpu);??
  • ????????}??
  • ????????preempt_enable();??
  • ????????set_current_state(TASK_INTERRUPTIBLE);??
  • ????}??
  • ????__set_current_state(TASK_RUNNING);??
  • ????return?0;??
  • ??
  • wait_to_die:??
  • ????preempt_enable();??
  • ????/*?Wait?for?kthread_stop?*/??
  • ????set_current_state(TASK_INTERRUPTIBLE);??
  • ????while?(!kthread_should_stop())?{??
  • ????????schedule();??
  • ????????set_current_state(TASK_INTERRUPTIBLE);??
  • ????}??
  • ????__set_current_state(TASK_RUNNING);??
  • ????return?0;??
  • }??

  • ?

    ?

    總結(jié)

    以上是生活随笔為你收集整理的ARM Linux 如何--注册和触发--软中断的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。