IMX8M RPMSG Lite Increase Buffer Size

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IMX8M RPMSG Lite Increase Buffer Size

Jump to solution
1,587 Views
Swiss2
Contributor II

Hi,
I am trying to increase the buffer size of the rpmsg lite since I am not able to achieve higher transfer rates between the M and A cores (I need around 200kBytes/s, achieving around 90kBytes/s). 

I am using a Verdin Mini Board from Toradex with the imx_rpmsg.c driver from here  and running the FreeRTOS with rpmsg on M4 from the SDK_2_12_1_MIMX8MM6xxxKZ

On the linux side, the buffer values inside imx_rpmsg.c are here:

#define RPMSG_NUM_BUFS (512) #define RPMSG_BUF_SIZE (512) 
#define RPMSG_BUFS_SPACE (RPMSG_NUM_BUFS * RPMSG_BUF_SIZE) 
#define RPMSG_VRING_ALIGN (4096) 
#define RPMSG_RING_SIZE ((DIV_ROUND_UP(vring_size(RPMSG_NUM_BUFS / 2, \ RPMSG_VRING_ALIGN), PAGE_SIZE)) * PAGE_SIZE)

then inside imx_rpmsg_tty.c:

/* this needs to be less then (RPMSG_BUF_SIZE - sizeof(struct rpmsg_hdr)) */
#define RPMSG_MAX_SIZE		256

and inside virtio_rpmsg_bus.c :

/*
 * We're allocating buffers of 512 bytes each for communications. The
 * number of buffers will be computed from the number of buffers supported
 * by the vring, upto a maximum of 512 buffers (256 in each direction).
 *
 * Each buffer will have 16 bytes for the msg header and 496 bytes for
 * the payload.
 *
 * This will utilize a maximum total space of 256KB for the buffers.
 *
 * We might also want to add support for user-provided buffers in time.
 * This will allow bigger buffer size flexibility, and can also be used
 * to achieve zero-copy messaging.
 *
 * Note that these numbers are purely a decision of this driver - we
 * can change this without changing anything in the firmware of the remote
 * processor.
 */
#define MAX_RPMSG_NUM_BUFS	(512)
#define MAX_RPMSG_BUF_SIZE	(512)

On the M4 side, there is rpmsg_config.h :

//! @def RL_BUFFER_PAYLOAD_SIZE
//!
//! Size of the buffer payload, it must be equal to (240, 496, 1008, ...)
//! [2^n - 16]. Ensure the same value is defined on both sides of rpmsg
//! communication. The default value is 496U.
#define RL_BUFFER_PAYLOAD_SIZE (496U)

//! @def RL_BUFFER_COUNT
//!
//! Number of the buffers, it must be power of two (2, 4, ...).
//! The default value is 2U.
//! Note this value defines the buffer count for one direction of the rpmsg
//! communication only, i.e. if the default value of 2 is used
//! in rpmsg_config.h files for the master and the remote side, 4 buffers
//! in total are created in the shared memory.
#define RL_BUFFER_COUNT (256)

 

I find the naming system confusing, since buffer count sometimes reffers to whole ring buffer, and sometimes to one half (tx or rx half). Since I allocate 128kb of memory for the ring buffers in my device tree, if I double the buffer size I also divide the buffer count in half (512x512 to 1024x256 etc.).

My first tests show: changing the linux side does nothing, M4 still receives 496
bytes hello world message. As soon as I change the rpmsg_config.h on the M4 side, even just halving the number of buffers to 128, hello world message is not received anymore and the driver isn’t working.

I found many similiar topics but none of them seem solved or are using an older version of the rpmsg so the solutions cannot be directly applied. The same issue is reported in this thread but it is left unsolved.

Thanks in advance!

I posted the same question on toradex forum and you can track it here .

 

Labels (2)
Tags (3)
0 Kudos
Reply
1 Solution
1,562 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @Swiss2,

In M4 SDK buffer count refers to half of the total(buffer count for one direction) and in Linux Kernel source code it refers to the total buffer count(for both directions).

As you are changing ring sizes in the kernel device tree. (however ring size is hard coded in the kernel), have you modified the same(VRING_SIZE) in SDK for M4 core at middleware/multicore/rpmsg_lite/lib/include/platform/imx8mn_m7/rpmsg_platform.h?

The rpmsg buffer sizes must be the same on both sides of the rpmsg communication. (in SDK RL_BUFFER_PAYLOAD_SIZE is deducted by 16 for the rpmsg header,)
in SDK buffer size is defined below,
#define RL_BUFFER_SIZE (RL_BUFFER_PAYLOAD_SIZE + 16UL)

If you are increasing RPMSG_BUF_SIZE to 1024 in the kernel, you should also modify RL_BUFFER_PAYLOAD_SIZE to 1008 in rpmsg_config.h

 

I hope it helps!

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

 

Thanks & Regards,
Dhruvit.

View solution in original post

0 Kudos
Reply
2 Replies
1,563 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @Swiss2,

In M4 SDK buffer count refers to half of the total(buffer count for one direction) and in Linux Kernel source code it refers to the total buffer count(for both directions).

As you are changing ring sizes in the kernel device tree. (however ring size is hard coded in the kernel), have you modified the same(VRING_SIZE) in SDK for M4 core at middleware/multicore/rpmsg_lite/lib/include/platform/imx8mn_m7/rpmsg_platform.h?

The rpmsg buffer sizes must be the same on both sides of the rpmsg communication. (in SDK RL_BUFFER_PAYLOAD_SIZE is deducted by 16 for the rpmsg header,)
in SDK buffer size is defined below,
#define RL_BUFFER_SIZE (RL_BUFFER_PAYLOAD_SIZE + 16UL)

If you are increasing RPMSG_BUF_SIZE to 1024 in the kernel, you should also modify RL_BUFFER_PAYLOAD_SIZE to 1008 in rpmsg_config.h

 

I hope it helps!

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

 

Thanks & Regards,
Dhruvit.

0 Kudos
Reply
1,551 Views
Swiss2
Contributor II
Hi @Dhruvit,
Actually my issue was using the Toradex "torizon core builder" that allows to make changes to the linux kernel modules without the need of building your own linux kernel. It does work on imx_rpmsg_tty.c file but not not on the imx_rpmsg.c file, for this I need to build a custom linux kernel, which I will try to aviod and get the speed between the cores some other way
Your answer was clear though, it is important to see that the ring size is actually hard coded in the kernel, so thanks for your answer.
0 Kudos
Reply