免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4103 | 回复: 9
打印 上一主题 下一主题

关于do_irq的疑问 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-05-03 22:06 |只看该作者 |倒序浏览
2.4情景内核分析里面do_irq这部分216页提到对同一通道的中断处理会串行化,问一下会丢失中断么?因为它只靠一个irq_pending标志位来表示,而且没处理一次就会清一次这个标志,如果同一通道有多个中断,怎么办?

论坛徽章:
4
酉鸡
日期:2014-03-21 23:19:50狮子座
日期:2014-08-01 22:11:40酉鸡
日期:2015-01-10 21:31:442015年辞旧岁徽章
日期:2015-03-03 16:54:15
2 [报告]
发表于 2011-05-03 22:30 |只看该作者
1.不会丢,即使此轮没有处理,下轮也会处理,因为已经将irq_pending位置上了.
2.同一通道的多个中断,会在循环中处理,直到irq_pending位不为1退出.

论坛徽章:
22
丑牛
日期:2014-08-15 14:32:0015-16赛季CBA联赛之同曦
日期:2017-12-14 15:28:14黑曼巴
日期:2017-08-10 08:14:342017金鸡报晓
日期:2017-02-08 10:39:42黑曼巴
日期:2016-11-15 15:48:38CU十四周年纪念徽章
日期:2016-11-09 13:19:1015-16赛季CBA联赛之同曦
日期:2016-04-08 18:00:03平安夜徽章
日期:2015-12-26 00:06:30程序设计版块每日发帖之星
日期:2015-12-03 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-09 06:20:002015亚冠之吉达阿赫利
日期:2015-07-03 08:39:42
3 [报告]
发表于 2011-05-04 08:37 |只看该作者
2.6.10的__do_irq:
  1. /*
  2. * do_IRQ handles all normal device IRQ's (the special
  3. * SMP cross-CPU interrupts have their own specific
  4. * handlers).
  5. */
  6. fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
  7. {
  8.         irq_desc_t *desc = irq_desc + irq;
  9.         struct irqaction * action;
  10.         unsigned int status;

  11.         kstat_this_cpu.irqs[irq]++;
  12.         if (desc->status & IRQ_PER_CPU) {  
  13.                 irqreturn_t action_ret;

  14.                 /*
  15.                  * No locking required for CPU-local interrupts:
  16.                  */
  17.                 desc->handler->ack(irq);
  18.                 action_ret = handle_IRQ_event(irq, regs, desc->action);
  19.                 if (!noirqdebug)
  20.                         note_interrupt(irq, desc, action_ret);
  21.                 desc->handler->end(irq);
  22.                 return 1;
  23.         }

  24.         spin_lock(&desc->lock);
  25.         desc->handler->ack(irq);
  26.         /*
  27.          * REPLAY is when Linux resends an IRQ that was dropped earlier
  28.          * WAITING is used by probe to mark irqs that are being tested
  29.          */
  30.         status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
  31.         status |= IRQ_PENDING; /* we _want_ to handle it */

  32.         /*
  33.          * If the IRQ is disabled for whatever reason, we cannot
  34.          * use the action we have.
  35.          */
  36.         action = NULL;
  37.         if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
  38.                 action = desc->action;
  39.                 status &= ~IRQ_PENDING; /* we commit to handling */
  40.                 status |= IRQ_INPROGRESS; /* we are handling it */
  41.         }
  42.         desc->status = status;

  43.         /*
  44.          * If there is no IRQ handler or it was disabled, exit early.
  45.          * Since we set PENDING, if another processor is handling
  46.          * a different instance of this same irq, the other processor
  47.          * will take care of it.
  48.          */
  49.         if (unlikely(!action))
  50.                 goto out;

  51.         /*
  52.          * Edge triggered interrupts need to remember
  53.          * pending events.
  54.          * This applies to any hw interrupts that allow a second
  55.          * instance of the same irq to arrive while we are in do_IRQ
  56.          * or in the handler. But the code here only handles the _second_
  57.          * instance of the irq, not the third or fourth. So it is mostly
  58.          * useful for irq hardware that does not mask cleanly in an
  59.          * SMP environment.
  60.          */
  61.         for (;;) {
  62.                 irqreturn_t action_ret;

  63.                 spin_unlock(&desc->lock);

  64.                 action_ret = handle_IRQ_event(irq, regs, action);

  65.                 spin_lock(&desc->lock);
  66.                 if (!noirqdebug)
  67.                         note_interrupt(irq, desc, action_ret);
  68.                 if (likely(!(desc->status & IRQ_PENDING)))
  69.                         break;
  70.                 desc->status &= ~IRQ_PENDING;
  71.         }
  72.         desc->status &= ~IRQ_INPROGRESS;

  73. out:
  74.         /*
  75.          * The ->end() handler has to deal with interrupts which got
  76.          * disabled while the handler was running.
  77.          */
  78.         desc->handler->end(irq);
  79.         spin_unlock(&desc->lock);

  80.         return 1;
  81. }
复制代码
注意到设置irq_pending标志位是有锁保护的,也就是说就算有中断发生也不会马上设置这个标志。也是顺序等待响应过之后才设置。

论坛徽章:
0
4 [报告]
发表于 2011-05-04 12:33 |只看该作者
2.6.10的__do_irq:注意到设置irq_pending标志位是有锁保护的,也就是说就算有中断发生也不会马上设置这个标 ...
amarant 发表于 2011-05-04 08:37

如果在handle_irq_event的时候发生了不只一次的中断 怎么搞 这个函数执行前是解锁的 如果此时触发多个同通道中断 都是置为pending

论坛徽章:
0
5 [报告]
发表于 2011-05-04 12:45 |只看该作者
回复 2# chishanmingshen


    http://www.linuxforum.net/forum/ ... 260&type=thread 网上看到了这个

论坛徽章:
22
丑牛
日期:2014-08-15 14:32:0015-16赛季CBA联赛之同曦
日期:2017-12-14 15:28:14黑曼巴
日期:2017-08-10 08:14:342017金鸡报晓
日期:2017-02-08 10:39:42黑曼巴
日期:2016-11-15 15:48:38CU十四周年纪念徽章
日期:2016-11-09 13:19:1015-16赛季CBA联赛之同曦
日期:2016-04-08 18:00:03平安夜徽章
日期:2015-12-26 00:06:30程序设计版块每日发帖之星
日期:2015-12-03 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-09 06:20:002015亚冠之吉达阿赫利
日期:2015-07-03 08:39:42
6 [报告]
发表于 2011-05-04 13:19 |只看该作者
回复 4# 木叉叉木大


    我的理解,如果不同CPU在这期间发生中断,那么就好几个CPU同时执行这里的代码,由于锁的保护,仍旧实现串形执行。
    如果同一个CPU在这期间两个中断源同时发生中断,我就不知道了

论坛徽章:
0
7 [报告]
发表于 2011-05-04 13:46 |只看该作者
回复  木叉叉木大


    我的理解,如果不同CPU在这期间发生中断,那么就好几个CPU同时执行这里的代码, ...
amarant 发表于 2011-05-04 13:19



    多个cpu 如果一个cpu在handle_irq_event 那么这时是不持有锁得,如果cpu2发生同一通道的中断,只会简单的把irq_desc[irq]->status的pending位置1,然后返回,这期间也是spin_lock spin_unlock对吧 如果之后cpu3来个同一通道的中断,怎么搞? 第一个中断还没有退出handle_irq_event

论坛徽章:
22
丑牛
日期:2014-08-15 14:32:0015-16赛季CBA联赛之同曦
日期:2017-12-14 15:28:14黑曼巴
日期:2017-08-10 08:14:342017金鸡报晓
日期:2017-02-08 10:39:42黑曼巴
日期:2016-11-15 15:48:38CU十四周年纪念徽章
日期:2016-11-09 13:19:1015-16赛季CBA联赛之同曦
日期:2016-04-08 18:00:03平安夜徽章
日期:2015-12-26 00:06:30程序设计版块每日发帖之星
日期:2015-12-03 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-09 06:20:002015亚冠之吉达阿赫利
日期:2015-07-03 08:39:42
8 [报告]
发表于 2011-05-04 13:51 |只看该作者
回复 7# 木叉叉木大


    发生中断到设置irq_pending还是要一步一步来,通过do_irq --> __do_irq,那么在设置irq_pending之前还是要上锁吧

论坛徽章:
4
酉鸡
日期:2014-03-21 23:19:50狮子座
日期:2014-08-01 22:11:40酉鸡
日期:2015-01-10 21:31:442015年辞旧岁徽章
日期:2015-03-03 16:54:15
9 [报告]
发表于 2011-10-15 21:55 |只看该作者
我的理解也是这样的:
通过自旋锁来保护pending标志位(多核之间共享), 目的是将所有cpu的同一通道的中断都在第一个处理程序中
串行处理.

论坛徽章:
0
10 [报告]
发表于 2011-10-15 22:24 |只看该作者
这个现在已经基本不用了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP