Xen PV Guest interrupt

紧接这一篇:

http://blog.csdn.net/snailhit/archive/2010/12/28/6101827.aspx

 

 

当在PV Guest里运行cat /proc/interrupts查看中断设置情况是,会发现中断号不是从0开始的,而是从256开始的。典型的如下:

 

           CPU0             
256:     111925     Dynamic-irq  timer0 (VM只有一个VCPU,若是SMP-VM,则有timer1, timer2, ...)
257:          0     Dynamic-irq  resched0
258:          0     Dynamic-irq  callfunc0

-----

... timer1, resched1, callfunc1, ...

-----
259:        270     Dynamic-irq  xenbus
260:       1801     Dynamic-irq  xencons
261:       3616     Dynamic-irq  blkif
262:       7756     Dynamic-irq  eth0
NMI:         0
LOC:         0
ERR:         0
MIS:         0

 

都是dynamic-irq,那么physical irq跑哪儿去了...? 原来,在PV guest中,所有的phyisical IRQ都被cut掉了,所有的都有dynamic IRQ来负责:

#define NR_DYNIRQS  256

#define NR_IRQS   (NR_PIRQS + NR_DYNIRQS)

 

在domain 0下运行 cat /proc/interrupts:

 

           CPU0       CPU1       CPU2       CPU3      
  1:       3196          0          0          0      Phys-level     i8042 (键盘..?)
  6:          3          0          0          0      Phys-level     floppy
  8:          0          0          0          0      Phys-level     rtc0 (rtc时钟)
 12:          4          0          0          0      Phys-level     i8042 (鼠标..?)
 14:      21648      26431          0          0      Phys-level     ata_piix (硬盘)
 15:     317748      19659          0          0      Phys-level     ata_piix
 16:        407          0          0          0      Phys-level     ehci_hcd:usb2, uhci_hcd:usb3, uhci_hcd:usb6, HDA Intel
 17:          0          0          0          0      Phys-level     uhci_hcd:usb4, uhci_hcd:usb7
 18:      73797          0          0          0      Phys-level     ehci_hcd:usb1, uhci_hcd:usb5, uhci_hcd:usb8, ata_piix
------------

439:      23348          0          0          0      Phys-level     peth0
440:   30292618     929005     656343     640930   Dynamic-percpu    timer
441:     338983     738843     598292     605525   Dynamic-percpu    resched
442:         23        196        233        221   Dynamic-percpu    callfunc
443:      23559       2526       1132        865   Dynamic-percpu    call1func
444:          0          0          0          0   Dynamic-percpu    reboot
445:       1144        476        212        145   Dynamic-percpu    spinlock
446:          0          0          0          0   Dynamic-level     mce
447:        283          0          0          0   Dynamic-level     console
448:         78        463         61          0   Dynamic-level     xenbus

--
449:        804        987          0          0   Dynamic-level     blkif-backend
450:       5731       1906          0          0   Dynamic-level     vif1.0
--

451 .... blkif-backend

450 .... vif2.0

--

NMI:          0          0          0          0   Non-maskable interrupts
RES:     338983     738844     598293     605526   Rescheduling interrupts
CAL:      23582       2722       1365       1086   Function call interrupts
MCE:          0          0          0          0   Machine check exceptions
MCP:          1          1          1          1   Machine check polls

 

看Guest启动后,如何初始化irq_descriptor[NR_IRQS] (linux/driver/xen/core/evtchn.c, xen_init_IRQ):

 /* Dynamic IRQ space is currently unbound. Zero the refcnts. */
 for (i = DYNIRQ_BASE; i < (DYNIRQ_BASE + NR_DYNIRQS); i++) {
  irq_bindcount[i] = 0;

  irq_desc[i].status = IRQ_DISABLED|IRQ_NOPROBE;
  irq_desc[i].action = NULL;
  irq_desc[i].depth = 1;
  irq_desc[i].chip = &dynirq_type;
 }

 

static struct hw_interrupt_type dynirq_type = {
 .typename = "Dynamic-irq",
 .startup  = startup_dynirq,
 .shutdown = shutdown_dynirq,
 .enable   = enable_dynirq,
 .disable  = disable_dynirq,
 .ack      = ack_dynirq,
 .end      = end_dynirq,
 .set_affinity = set_affinity_irq,
 .retrigger = resend_irq_on_evtchn,
};

-----------------------

对于physical IRQ:

 /* Phys IRQ space is statically bound (1:1 mapping). Nail refcnts. */
 for (i = PIRQ_BASE; i < (PIRQ_BASE + NR_PIRQS); i++) {
  irq_bindcount[i] = 1;

  if (!identity_mapped_irq(i))
   continue;

#ifdef RTC_IRQ
  /* If not domain 0, force our RTC driver to fail its probe. */
  if (i - PIRQ_BASE == RTC_IRQ && !is_initial_xendomain())
   continue;
#endif

  irq_desc[i].status = IRQ_DISABLED;
  irq_desc[i].action = NULL;
  irq_desc[i].depth = 1;
  irq_desc[i].chip = &pirq_type;
 }

 

static struct hw_interrupt_type pirq_type = {
 .typename = "Phys-irq",
 .startup  = startup_pirq,
 .shutdown = shutdown_pirq,
 .enable   = enable_pirq,
 .disable  = disable_pirq,
 .ack      = ack_pirq,
 .end      = end_pirq,
 .set_affinity = set_affinity_irq,
 .retrigger = resend_irq_on_evtchn,
};

 

对于不是driver domain的guest VM,rtc(real-time-clock)直接被禁掉了,时钟由VIRQ_TIMER来接管 (见linux/arch/arch/i386/kernel/time-xen.c, local_setup_timer)

 

physical irq 通过evtchn_register_pirq来注册

--------------------------------------

为什么是dynamic的:每一次分配,都要先去找unbound irq

static int find_unbound_irq(void)
{
 static int warned;
 int irq;

 for (irq = DYNIRQ_BASE; irq < (DYNIRQ_BASE + NR_DYNIRQS); irq++)
  if (irq_bindcount[irq] == 0)
   return irq;

 return -ENOSPC;
}

 

找到之后,通过hypercall想去和VM的evtchn来bind (有Xen来做的事情),结果Xen也要dynamic的找get_free_port

for ( port = 0; port_is_valid(d, port); port++ )
        if ( evtchn_from_port(d, port)->state == ECS_FREE )
            return port;

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值