DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] dmadev: fix structure alignment
@ 2024-03-08  5:37 Wenwu Ma
  2024-03-08  7:01 ` fengchengwen
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Wenwu Ma @ 2024-03-08  5:37 UTC (permalink / raw)
  To: dev, fengchengwen; +Cc: songx.jiale, Wenwu Ma, stable

The structure rte_dma_dev needs cacheline alignment, but the return
value of malloc may not be aligned to the cacheline. Therefore,
extra memory is applied for realignment.

Fixes: b36970f2e13e ("dmadev: introduce DMA device library")
Cc: stable@dpdk.org

Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
---
 lib/dmadev/rte_dmadev.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c
index 5953a77bd6..61e106d574 100644
--- a/lib/dmadev/rte_dmadev.c
+++ b/lib/dmadev/rte_dmadev.c
@@ -160,15 +160,25 @@ static int
 dma_dev_data_prepare(void)
 {
 	size_t size;
+	void *ptr;
 
 	if (rte_dma_devices != NULL)
 		return 0;
 
-	size = dma_devices_max * sizeof(struct rte_dma_dev);
-	rte_dma_devices = malloc(size);
-	if (rte_dma_devices == NULL)
+	/* The dma device object is expected to align cacheline, but
+	 * the return value of malloc may not be aligned to the cache line.
+	 * Therefore, extra memory is applied for realignment.
+	 * note: We do not call posix_memalign/aligned_alloc because it is
+	 * version dependent on libc.
+	 */
+	size = dma_devices_max * sizeof(struct rte_dma_dev) +
+		RTE_CACHE_LINE_SIZE;
+	ptr = malloc(size);
+	if (ptr == NULL)
 		return -ENOMEM;
-	memset(rte_dma_devices, 0, size);
+	memset(ptr, 0, size);
+
+	rte_dma_devices = RTE_PTR_ALIGN(ptr, RTE_CACHE_LINE_SIZE);
 
 	return 0;
 }
-- 
2.25.1


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2024-06-27 12:52 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-08  5:37 [PATCH] dmadev: fix structure alignment Wenwu Ma
2024-03-08  7:01 ` fengchengwen
2024-03-15  1:43 ` [PATCH v2] " Wenwu Ma
2024-03-15  6:02   ` Tyler Retzlaff
2024-03-15  6:06   ` fengchengwen
2024-03-15  6:25     ` Ma, WenwuX
2024-03-15  7:44       ` Ma, WenwuX
2024-03-15  8:31         ` fengchengwen
2024-03-15  9:27           ` Ma, WenwuX
2024-03-20  4:11             ` fengchengwen
2024-03-20  7:34               ` Ma, WenwuX
2024-03-19  9:48   ` Jiale, SongX
2024-03-20  7:23 ` [PATCH v3] " Wenwu Ma
2024-03-20  9:31   ` fengchengwen
2024-06-27 12:46     ` Thomas Monjalon
2024-03-20 11:37   ` Thomas Monjalon
2024-03-21  1:25     ` Ma, WenwuX
2024-03-21  8:30       ` Thomas Monjalon
2024-03-21  8:57         ` Ma, WenwuX
2024-03-21  9:18         ` Ma, WenwuX
2024-03-21 10:06           ` Thomas Monjalon
2024-03-21 16:05             ` Tyler Retzlaff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).