Ring Library_ring ossillator single-library_云端漫步的程狗子的博客-程序员宅基地

技术标签: linux  服务器  dpdk  网络编程  

The ring allows the management of queues. Instead of having a linked list of infinite size, the rte_ring has the following properties:

  1. FIFO
  2. Maximum size is fixed, the objects are stored in a table
  3. Objects can be pointers or elements of multiple of 4 byte size
  4. Lockless implementation
  5. Multi-consumer or single-consumer dequeue
  6. Multi-producer or single-producer enqueue
  7. Bulk dequeue - Dequeues the specified count of objects if successful; otherwise fails
  8. Bulk enqueue - Enqueues the specified count of objects if successful; otherwise fails
  9. Burst dequeue - Dequeue the maximum available objects if the specified count cannot be fulfilled
  10. Burst enqueue - Enqueue the maximum available objects if the specified count cannot be fulfilled
  • 1、Anatomy of a Ring Buffer

    This section explains how a ring buffer operates. The ring structure is composed of two head and tail couples; one is used by producers and one is used by the consumers. The figures of the following sections refer to them as prod_head, prod_tail, cons_head and cons_tail.

    Each figure represents a simplified state of the ring, which is a circular buffer. The content of the function local variables is represented on the top of the figure, and the content of ring structure is represented on the bottom of the figure.

    • 1.1、Single Producer Enqueue

      This section explains what occurs when a producer adds an object to the ring. In this example, only the producer head and tail (prod_head and prod_tail) are modified, and there is only one producer.

      The initial state is to have a prod_head and prod_tail pointing at the same location.

      • 1.1.1、Enqueue First Step

        First, ring->prod_head and ring->cons_tail are copied in local variables. The prod_next local variable points to the next element of the table, or several elements after in case of bulk enqueue.

      If there is not enough room in the ring (this is detected by checking cons_tail), it returns an error.
      在这里插入图片描述

      • 1.1.2、Enqueue Second Step

        The second step is to modify ring->prod_head in ring structure to point to the same location as prod_next.

        The added object is copied in the ring (obj4).
        在这里插入图片描述

      • 1.1.3、Enqueue Second Step

        Once the object is added in the ring, ring->prod_tail in the ring structure is modified to point to the same location as ring->prod_head. The enqueue operation is finished.
        在这里插入图片描述

    • 1.2、Single Consumer Dequeue

      This section explains what occurs when a consumer dequeues an object from the ring. In this example, only the consumer head and tail (cons_head and cons_tail) are modified and there is only one consumer.

      The initial state is to have a cons_head and cons_tail pointing at the same location.

      • 1.2.1、Dequeue First Step

        First, ring->cons_head and ring->prod_tail are copied in local variables.The cons_next local variable points to the next element of the table, or several elements after in the case of bulk dequeue.

        If there are not enough objects in the ring (this is detected by checking prod_tail), it returns an error.
        在这里插入图片描述

      • 1.2.2、Dequeue Second Step

        The second step is to modify ring->cons_head in the ring structure to point to the same location as cons_next.

        The dequeued object (obj1) is copied in the pointer given by the user.
        在这里插入图片描述

      • 1.2.3、Dequeue Last Step

        Finally, ring->cons_tail in the ring structure is modified to point to the same location as ring->cons_head. The dequeue operation is finished.
        在这里插入图片描述

    • 1.3、Multiple Producers Enqueue

      This section explains what occurs when two producers concurrently add an object to the ring. In this example, only the producer head and tail (prod_head and prod_tail) are modified.

      The initial state is to have a prod_head and prod_tail pointing at the same location.

      • 1.3.1、Multiple Producers Enqueue First Step

        On both cores, ring->prod_head and ring->cons_tail are copied in local variables. The prod_next local variable points to the next element of the table, or several elements after in the case of bulk enqueue.

        If there is not enough room in the ring (this is detected by checking cons_tail), it returns an error.
        在这里插入图片描述

      • 1.3.2、Multiple Producers Enqueue Second Step

        The second step is to modify ring->prod_head in the ring structure to point to the same location as prod_next. This operation is done using a Compare And Swap (CAS) instruction, which does the following operations atomically:

        1. If ring->prod_head is different to local variable prod_head, the CAS operation fails, and the code restarts at first step.
        2. Otherwise, ring->prod_head is set to local prod_next, the CAS operation is successful, and processing continues.

        In the figure, the operation succeeded on core 1, and step one restarted on core 2.
        在这里插入图片描述

      • 1.3.3、Multiple Producers Enqueue Third Step

        The CAS operation is retried on core 2 with success.

        The core 1 updates one element of the ring(obj4), and the core 2 updates another one (obj5).
        在这里插入图片描述

      • 1.3.4、Multiple Producers Enqueue Fourth Step

        Each core now wants to update ring->prod_tail. A core can only update it if ring->prod_tail is equal to the prod_head local variable. This is only true on core 1. The operation is finished on core 1.
        在这里插入图片描述

      • 1.3.5、Multiple Producers Enqueue Last Step

        Once ring->prod_tail is updated by core 1, core 2 is allowed to update it too. The operation is also finished on core 2.
        在这里插入图片描述

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/a777122/article/details/127061211

智能推荐

运用K-Lite Codec Pack插件在PowerPoint中播放FLV视频_从后面插入视频_左岸天使的博客-程序员宅基地

占个位PowerPoint好像从office2010后就不是太好插入视频了,所有电脑要装一个-Lite Codec Pack_从后面插入视频

vue中props的基本使用_props: ['selectrangedate'],-程序员宅基地

props作用:父组件向子组件传递数据1.单向数据流所有的 prop 都使得其父子 prop 之间形成了一个单向下行绑定:父级 prop 的更新会向下流动到子组件中,但是反过来则不行。这样会防止从子组件意外变更父级组件的状态,从而导致你的应用的数据流向难以理解。不要在子数组内部修改props!常见的使用方法:希望将prop 作为一个本地的 数据来使用通过定义一个本地的 data property 并将这个 prop 用作其初始值来使用props: ['initialCount_props: ['selectrangedate'],

使用Kotlin高效地开发Android App(五)完结篇-程序员宅基地

一. 单例使用 Java 来编写单例模式的话,可以写出好几种。同样,使用 Kotlin 也可以写出多种单例模式。在这里介绍的是一种使用委托属性的方式来实现单例的写法。首先...

两句话掌握python最难知识点——元类-程序员宅基地

两句话掌握python最难知识点——元类转载自: https://segmentfault.com/a/1190000011447445 文章写得比较生动,点赞。千万不要被所谓“元类是99%的python程序员不会用到的特性”这类的说辞吓住。因为每个中国人,都是天生的元类使用者学懂元类,你只需要知道两句话:道生一,一生二,二生三,三生万物。我是谁?我从哪来里?我要到哪里去?...

Javascript混淆与解混淆的那些事儿_国产的jsx在线混淆-程序员宅基地

像软件加密与解密一样,javascript的混淆与解混淆同属于同一个范畴。道高一尺,魔高一丈。没有永恒的黑,也没有永恒的白。一切都是资本市场驱动行为,现在都流行你能为人解决什么问题,这个概念。那么市场究竟能容纳多少个能解决这种问题的利益者。JS没有秘密。其实本人不赞成javascript进行hash混淆处理,一拖慢运行时速度,二体积大。JS代码前端可获取,天生赋予“开源”属性,都可以在chrome devTools下查看。JS非压缩性混淆完全违法前端优化准则。目前网络上可以搜索的JS混淆工具不外乎以_国产的jsx在线混淆

过生日_第一行为整数n,表示有n个学生,n ≤ 180。此后每行包含一个字符串和两个整数,分别-程序员宅基地

题目描述】在一个有180人的大班级中,存在两个人生日相同的概率非常大,现给出每个学生的名字,出生月日。试找出所有生日相同的学生。【输入】第一行为整数n,表示有n个学生,n ≤ 180。此后每行包含一个字符串和两个整数,分别表示学生的名字(名字第一个字母大写,其余小写,不含空格,且长度小于20)和出生月(1 ≤ m ≤ 12)日(1 ≤ d ≤ 31)。名字、月、日之间用一个空格分隔【输出】每组生日相同的学生,输出一行,其中前两个数字表示月和日,后面跟着所有在当天出生的学生的名字,数字、名字之间都用_第一行为整数n,表示有n个学生,n ≤ 180。此后每行包含一个字符串和两个整数,分别

随便推点

javaCV开发详解之18:音视频转码(音频编解码和视频编解码)_javacv 音频转码-程序员宅基地

前言在本章之前,我们已经分析了如何进行转流、转封装、像素格式转换以及音频的重采样,本章主要讲解和分析javaCV如何进行转码,其实很多小伙伴在转流章节中已经发现它已经在进行转码了,那么javaCV中的转码究竟是什么样的呢,本章就视频和音频转码进行剖析和讲解。补充:与装封装和像素格式转换不同的是,编解码比转封装更深入一层,但是并不改变像素格式,想要改变像素格式,需要经过编解码的,也即是说编解码是介于装封装和像素格式转换之间的操作。源码剖析本章主要分析FFmpegFrameGrabber和FFmp_javacv 音频转码

浅谈VPS云服务器(内含神秘大额专属特惠)-程序员宅基地

怎么做一个网站?都需要什么?要个服务器?要个域名?去哪里买?哪个好啊?有优惠吗?所有的优惠都在这里了,给自己建个网站吧,毕竟要学以致用啊!

Android intent以及Bundle用法-程序员宅基地

一、intent1. 在一个Android应用中,主要是由四种组件组成(Activities,Services,Broadcastreceivers,Content providers),而这四种组件是独立的,它们之间可以互相调用,协调工作,最终组成一个真正的Android应用。在这些组件之间的通讯主要是由Intent协助完成的。 Intent是不同组件之间相互通讯的纽带,封装

MySQL函数介绍_mysql log函数-程序员宅基地

MySQL数据库提供了很多函数包括:数学函数;字符串函数;日期和时间函数;条件判断函数;系统信息函数;加密函数;格式化函数;一、数学函数  数学函数主要用于处理数字,包括整型、浮点数等。函数作用ABS(x)返回x的绝对值  SELECT ABS(-1) -- 返回1CEIL(x),CEILING(x)返回大_mysql log函数

[Linux] Ubuntu: 登陆界面无法输入密码-程序员宅基地

Ubuntu 10.04安装在Vmware 7.01中;在图形登陆界面时,键盘失效,不能使用。解决方法:1、进入登录界面调出Universal Access Preferences面板,勾选选项“Use on-screen keyboard”,然后重启动。2、利用屏幕键盘输入密码登入系统,这时键盘就可以使用了。3、编辑配置文件/etc/default/console-...

Java的BitSet类用法_bitset类 java-程序员宅基地

1,BitSet类大小可动态改变, 取值为true或false的位集合。用于表示一组布尔标志。此类实现了一个按需增长的位向量。位 set 的每个组件都有一个 boolean 值。用非负的整数将 BitSet 的位编入索引。可以对每个编入索引的位进行测试、设置或者清除。通过逻辑与、逻辑或和逻辑异或操作,可以使用一个 BitSet 修改另一个 BitSet 的内容。默认情况下,set 中所有位的..._bitset类 java

推荐文章

热门文章

相关标签