<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>i.MX ProcessorsのトピックRe: RPMsg vqueue /vring shared memory overhead and data buffers</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/RPMsg-vqueue-vring-shared-memory-overhead-and-data-buffers/m-p/832936#M127956</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The throughput of RPMsg is about 5 Mbps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Nov 2019 08:13:03 GMT</pubDate>
    <dc:creator>b36401</dc:creator>
    <dc:date>2019-11-14T08:13:03Z</dc:date>
    <item>
      <title>RPMsg vqueue /vring shared memory overhead and data buffers</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RPMsg-vqueue-vring-shared-memory-overhead-and-data-buffers/m-p/832934#M127954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;UPDATED&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the context of iMX7D Linux and FreeRTOS&amp;nbsp; OpenAMP RPMsg implementation, as provided by NXP (un-modified, and not alternative Lite version):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the default Linux devtree, total of 0x10000 / 64KB reserved for the vrings, half-half for Tx, Rx 0x8000 / 32KB each (the&amp;nbsp;0x8000&amp;nbsp;is hardcoded imx_rpmsg.c).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This fixed location&amp;nbsp;for vrings is only the management overhead from the vrings&amp;nbsp; - is this correct?&lt;/P&gt;&lt;P&gt;The buffers for the actual data are allocated by the kernel&amp;nbsp; (virtio_rpmsg_bus.c, dma_alloc_coherent), from another memory, and this is 512 buffers x 512 buffer size = 256KB (for Tx &amp;amp; Rx).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the vrings, from Linux&amp;nbsp;imx_rpmsg.c &amp;nbsp;it says:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;/* With 256 buffers, our vring will &lt;EM&gt;&lt;STRONG&gt;occupy 3 pages&lt;/STRONG&gt;&lt;/EM&gt; */&lt;BR /&gt;#define RPMSG_RING_SIZE ((DIV_ROUND_UP(vring_size(RPMSG_NUM_BUFS / 2, \&lt;BR /&gt; RPMSG_VRING_ALIGN), PAGE_SIZE)) * PAGE_SIZE)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That is 3 x&amp;nbsp;0x1000 = 0x3000 / 12228, or ~12KB per vring&amp;nbsp; / per&amp;nbsp;Tx /Rx.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why then 32KB is reserved in devtree for each queue ...?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also,&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;*&lt;BR /&gt; * For now, allocate 256 buffers of 512 bytes for each side. each buffer&lt;BR /&gt; * will then have &lt;EM&gt;&lt;STRONG&gt;16B for the msg header&lt;/STRONG&gt;&lt;/EM&gt; and 496B for the payload.&lt;BR /&gt; * This will require a total space of 256KB for the buffers themselves, and&lt;BR /&gt; * 3 pages for every vring (the size of the vring depends on the number of&lt;BR /&gt; * buffers it supports).&lt;BR /&gt; */&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is the total space overhead in this setup then:&lt;/P&gt;&lt;P&gt;512 * 16 = 8192 / 0x2000&amp;nbsp; for total&amp;nbsp; RPMsg messages (Tx &amp;amp; Rx queues)&amp;nbsp; +&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;2 * 0x3000&amp;nbsp; = 0x6000 / 24576 for&amp;nbsp;vrings&lt;/P&gt;&lt;P&gt;&amp;nbsp;= 0x8000&amp;nbsp; / 32KB,&amp;nbsp; which is 12,5%&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this right or something is missing?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can't calculate&amp;nbsp;why&amp;nbsp;64KB is reserved for vrings reserved in devtree though ...Where does it come from?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In addition&amp;nbsp;(first time I didn't) count for virtqueues per each shared vring, which are allocated for management in Linux&lt;/P&gt;&lt;P&gt;(rp_find_vq, calls vring_new_virtqueue). Tracing that, for default setup of 256 buffers,&amp;nbsp; at least another 2132 bytes per virtqueue allocated (it's at least because virtqueue has other&amp;nbsp;data pointers in it, which may be assigned allocated mem by other parts of code I didn't trace).&amp;nbsp; Thus&amp;nbsp; another 4264 bytes for 2 vqueues for management on Linux.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On FreeRTOS side it creates virtqueues for vrings, (rpmsg_rdev_create_virtqueues in remote_device.c), and that's traced to&amp;nbsp;4224 (after malloc alignment)&amp;nbsp;per queue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Adding up ‭32768‬ + 12712 = 45480, or about ~45KB . (There is also other state management stuff, like rdevs, channels, etc..)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So now&amp;nbsp; ~ 17% overhead, with 256KB data space.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Oct 2018 12:43:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RPMsg-vqueue-vring-shared-memory-overhead-and-data-buffers/m-p/832934#M127954</guid>
      <dc:creator>dry</dc:creator>
      <dc:date>2018-10-25T12:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: RPMsg vqueue /vring shared memory overhead and data buffers</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RPMsg-vqueue-vring-shared-memory-overhead-and-data-buffers/m-p/832935#M127955</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Also, the shared vring size should be same, for both sides.. But there is a slight size difference between Linux calculation and FreeRTOS one:&lt;/P&gt;&lt;P&gt;Linux :&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="font-size: 15px;"&gt;static inline unsigned vring_size(unsigned int num, unsigned long align)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 15px;"&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 15px;"&gt; return ((sizeof(struct vring_desc) * num + sizeof(__virtio16) * (3 + num)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 15px;"&gt; + align - 1) &amp;amp; ~(align - 1))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 15px;"&gt; + sizeof(__virtio16) * 3 + sizeof(struct vring_used_elem) * num;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 15px;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Runtime this gives&amp;nbsp;10246&lt;/P&gt;&lt;P&gt;FreeRTOS:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;static inline int vring_size(unsigned int num, unsigned long align)&lt;BR /&gt;{&lt;BR /&gt; int size;&lt;/P&gt;&lt;P&gt;size = num * sizeof(struct vring_desc);&lt;BR /&gt; size += sizeof(struct vring_avail) + (num * sizeof(uint16_t)) +&lt;BR /&gt; sizeof(uint16_t);&lt;BR /&gt; size = (size + align - 1) &amp;amp; ~(align - 1);&lt;BR /&gt; size += sizeof(struct vring_used) +&lt;BR /&gt; (num * sizeof(struct vring_used_elem)) + sizeof(uint16_t);&lt;BR /&gt; return (size);&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This gives&amp;nbsp;10254,&amp;nbsp; 8 bytes more.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Align is 4096 in both cases.&amp;nbsp; If I use protocol definition (&lt;A class="link-titled" href="https://github.com/OpenAMP/open-amp/wiki/RPMsg-Messaging-Protocol" title="https://github.com/OpenAMP/open-amp/wiki/RPMsg-Messaging-Protocol"&gt;RPMsg Messaging Protocol · OpenAMP/open-amp Wiki · GitHub&lt;/A&gt;&amp;nbsp;) and align after avail buffer (as done above), I&amp;nbsp;get&lt;/P&gt;&lt;P&gt;10244&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Shouldn't&lt;/EM&gt; &lt;/STRONG&gt;they be identical .. ? This is the size of the type in shared memory. ..&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;( Align helps between avail and used ring buffers, and also each vring fixed at address at an 'extra' offset/margin from each other .. so you don't care for a few extra bytes, as long as it's more ?)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2018 11:09:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RPMsg-vqueue-vring-shared-memory-overhead-and-data-buffers/m-p/832935#M127955</guid>
      <dc:creator>dry</dc:creator>
      <dc:date>2018-10-26T11:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: RPMsg vqueue /vring shared memory overhead and data buffers</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RPMsg-vqueue-vring-shared-memory-overhead-and-data-buffers/m-p/832936#M127956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The throughput of RPMsg is about 5 Mbps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2019 08:13:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RPMsg-vqueue-vring-shared-memory-overhead-and-data-buffers/m-p/832936#M127956</guid>
      <dc:creator>b36401</dc:creator>
      <dc:date>2019-11-14T08:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: RPMsg vqueue /vring shared memory overhead and data buffers</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RPMsg-vqueue-vring-shared-memory-overhead-and-data-buffers/m-p/832937#M127957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Victor,&lt;/P&gt;&lt;P&gt;How did you measure, and whats your test system?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also wanted to do a test but never got to it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Jan 2020 01:44:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RPMsg-vqueue-vring-shared-memory-overhead-and-data-buffers/m-p/832937#M127957</guid>
      <dc:creator>dry</dc:creator>
      <dc:date>2020-01-12T01:44:30Z</dc:date>
    </item>
  </channel>
</rss>

