DPDK通过在线程中使用epoll模型,监听UIO设备的事件,来模拟操作系统的中断处理。

一、中断初始化

在rte_eal_intr_init()函数中初始化中断。具体如下:

1、首先初始化intr_sources链表。所有UIO设备的中断都挂在这个链表上,中断处理线程通过遍历这个链表,来执行设备的中断。

2、创建intr_pipe管道,用于epoll模型的消息通知。

3、创建线程intr_thread,线程的执行体是eal_intr_thread_main()函数,创建epoll模型,遍历intr_sources链表,监听已注册的所有UIO设备的中断事件,并调用对应UIO设备的中断处理函数。

 int
rte_eal_intr_init(void)
{
int ret = ; /* init the global interrupt source head */
TAILQ_INIT(&intr_sources); /**
* create a pipe which will be waited by epoll and notified to
* rebuild the wait list of epoll.
*/
if (pipe(intr_pipe.pipefd) < )
return -; /* create the host thread to wait/handle the interrupt */
ret = pthread_create(&intr_thread, NULL,
eal_intr_thread_main, NULL);
if (ret != )
RTE_LOG(ERR, EAL,
"Failed to create thread for interrupt handling\n"); return -ret;
}

中断线程执行主体eal_intr_thread_main()函数具体如下:

1、epoll_create()创建epoll模型。

2、将intr_pipe管道加入到epoll中。

3、遍历intr_sources链表,将所有UIO设备加入到epoll中。

4、在eal_intr_handle_interrupts()函数中,在一个for(;;)死循环中,调用epoll_wait()阻塞模式监听事件。如果有事件发生,则调用eal_intr_process_interrupts()函数,最终会调用到相应UIO设备注册的中断处理函数。

 static __attribute__((noreturn)) void *
eal_intr_thread_main(__rte_unused void *arg)
{
struct epoll_event ev; /* host thread, never break out */
for (;;) {
/* build up the epoll fd with all descriptors we are to
* wait on then pass it to the handle_interrupts function
*/
static struct epoll_event pipe_event = {
.events = EPOLLIN | EPOLLPRI,
};
struct rte_intr_source *src;
unsigned numfds = ; /* create epoll fd */
int pfd = epoll_create();
if (pfd < )
rte_panic("Cannot create epoll instance\n"); pipe_event.data.fd = intr_pipe.readfd;
/**
* add pipe fd into wait list, this pipe is used to
* rebuild the wait list.
*/
if (epoll_ctl(pfd, EPOLL_CTL_ADD, intr_pipe.readfd,
&pipe_event) < ) {
rte_panic("Error adding fd to %d epoll_ctl, %s\n",
intr_pipe.readfd, strerror(errno));
}
numfds++; rte_spinlock_lock(&intr_lock); TAILQ_FOREACH(src, &intr_sources, next) {
if (src->callbacks.tqh_first == NULL)
continue; /* skip those with no callbacks */
ev.events = EPOLLIN | EPOLLPRI;
ev.data.fd = src->intr_handle.fd; /**
* add all the uio device file descriptor
* into wait list.
*/
if (epoll_ctl(pfd, EPOLL_CTL_ADD,
src->intr_handle.fd, &ev) < ){
rte_panic("Error adding fd %d epoll_ctl, %s\n",
src->intr_handle.fd, strerror(errno));
}
else
numfds++;
}
rte_spinlock_unlock(&intr_lock);
/* serve the interrupt */
eal_intr_handle_interrupts(pfd, numfds); /**
* when we return, we need to rebuild the
* list of fds to monitor.
*/
close(pfd);
}
}

 二、中断注册

以e1000网卡为例说明。在网卡初始化的时候,会调用rte_eth_dev_init()--->eth_igb_dev_init()--->rte_intr_callback_register()注册中断处理函数。

 rte_intr_callback_register(&(pci_dev->intr_handle),
eth_igb_interrupt_handler, (void *)eth_dev);

rte_intr_callback_register()函数,主要工作如下:

1、首先申请一个struct rte_intr_source变量。

 struct rte_intr_source {
TAILQ_ENTRY(rte_intr_source) next;
struct rte_intr_handle intr_handle; /**< interrupt handle */
struct rte_intr_cb_list callbacks; /**< user callbacks */
uint32_t active;
};

2、将中断处理函数eth_igb_interrupt_handler,添加到rte_intr_source->callbacks链表中。

3、再将该rte_intr_source挂到全局intr_sources链表中,方便中断处理线程遍历调用。

错误之处,欢迎指出。

转载请标明转自http://www.cnblogs.com/MerlinJ/p/4104039.html

DPDK中断机制简析的更多相关文章

  1. 简析.NET Core 以及与 .NET Framework的关系

    简析.NET Core 以及与 .NET Framework的关系 一 .NET 的 Framework 们 二 .NET Core的到来 1. Runtime 2. Unified BCL 3. W ...

  2. 简析 .NET Core 构成体系

    简析 .NET Core 构成体系 Roslyn 编译器 RyuJIT 编译器 CoreCLR & CoreRT CoreFX(.NET Core Libraries) .NET Core 代 ...

  3. RecycleView + CardView 控件简析

    今天使用了V7包加入的RecycleView 和 CardView,写篇简析. 先上效果图: 原理图: 这是RecycleView的工作原理: 1.LayoutManager用来处理RecycleVi ...

  4. Java Android 注解(Annotation) 及几个常用开源项目注解原理简析

    不少开源库(ButterKnife.Retrofit.ActiveAndroid等等)都用到了注解的方式来简化代码提高开发效率. 本文简单介绍下 Annotation 示例.概念及作用.分类.自定义. ...

  5. PHP的错误报错级别设置原理简析

    原理简析 摘录php.ini文件的默认配置(php5.4): ; Common Values: ; E_ALL (Show all errors, warnings and notices inclu ...

  6. Android 启动过程简析

    首先我们先来看android构架图: android系统是构建在linux系统上面的. 所以android设备启动经历3个过程. Boot Loader,Linux Kernel & Andr ...

  7. Android RecycleView + CardView 控件简析

    今天使用了V7包加入的RecycleView 和 CardView,写篇简析. 先上效果图: 原理图: 这是RecycleView的工作原理: 1.LayoutManager用来处理RecycleVi ...

  8. Java Annotation 及几个常用开源项目注解原理简析

    PDF 版: Java Annotation.pdf, PPT 版:Java Annotation.pptx, Keynote 版:Java Annotation.key 一.Annotation 示 ...

  9. 【ACM/ICPC2013】POJ基础图论题简析(一)

    前言:昨天contest4的惨败经历让我懂得要想在ACM领域拿到好成绩,必须要真正的下苦功夫,不能再浪了!暑假还有一半,还有时间!今天找了POJ的分类题库,做了简单题目类型中的图论专题,还剩下二分图和 ...

随机推荐

  1. 拥抱高效、拥抱 Bugtags 之来自用户的声音(五)

    Bugtags使用心得(创业公司场景篇) ——成都嘿嘿科技有限公司 作者:小花 一.产品定义 关于手机客户端产品(APP)的 bug 提交.监测及管理且具有团队协作性质的系统. 二.使用环境 公司:初 ...

  2. 根据职位名,自动生成jd

    代码本身就是最好的解释,不赘述. 文本聚类输出: cluster.py #!/usr/bin/env python # coding=utf-8 import jieba,re from gensim ...

  3. .NET技术+25台服务器怎样支撑世界第54大网站(转)

    [编者按]StackOverflow是一个IT技术问答网站,用户可以在网站上 提交和回答问题.当下的StackOverflow已拥有400万个用户,4000万个回答,月PV5.6亿,世界排行第54.然 ...

  4. 解决insmod: error inserting 'hello.ko': -1 Invalid module format

    编译自己的内核模块后,insmod出现error:error inserting 'hello.ko': -1 Invalid module format 出现这种情况的原因是因为Makefile种使 ...

  5. 不能使用 snapshot 的解决方式

    http://www.mzone.cc/article/654.html 有两种方法可以解决: 1.第一种方法是在项目的pom文件中进行配置,如下: <repositories> < ...

  6. @SessionAttributes与HttpSession

    SessionAttributes注解将model中与它同名的属性保存在HttpSession中. 在controller的方法执行完毕后处理SessionAttributes注解并保存的,是Hand ...

  7. hbase的regionserver宕机

    错误日志: regionserver.HRegionServer: Failed deleting my ephemeral node zookeeper.RecoverableZooKeeper: ...

  8. ASP.NET MVC开发微信(四)

  9. 菜鸟-手把手教你把Acegi应用到实际项目中(5)

    在实际企业应用中,用户密码一般都会进行加密处理,这样才能使企业应用更加安全.既然密码的加密如此之重要,那么Acegi(Spring Security)作为成熟的安全框架,当然也我们提供了相应的处理方式 ...

  10. Android——inflate 将一个xml中定义的布局找出来

    通俗的说,inflate就相当于将一个xml中定义的布局找出来. 因为在一个Activity里如果直接用findViewById()的话,对应的是setConentView()的那个layout里的组 ...