Skip to content

Commit 0ebbf62

Browse files
authored
fix(XDMA): align malloc to 4K Byte for DMA receiving (#620)
Previously the boundary of DMA struct declaration is misaligned with 4K byte, causing data offset errors when receiving DMA data packets. This change uses posic_memalign to specify 4K byte alignment for malloc.
1 parent 9f8f22e commit 0ebbf62

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/test/csrc/fpga/xdma.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void FpgaXdma::stop_thansmit_thread() {
156156
}
157157

158158
void FpgaXdma::read_xdma_thread(int channel) {
159-
FpgaPackgeHead *packge = (FpgaPackgeHead *)malloc(sizeof(FpgaPackgeHead));
159+
FpgaPackgeHead *packge = (FpgaPackgeHead *)posix_memalignd_malloc(sizeof(FpgaPackgeHead));
160160
memset(packge, 0, sizeof(FpgaPackgeHead));
161161
while (running) {
162162
size_t size = read(xdma_c2h_fd[channel], packge, sizeof(FpgaPackgeHead));

src/test/csrc/fpga/xdma.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ class FpgaXdma {
7474

7575
void device_write(bool is_bypass, const char *workload, uint64_t addr, uint64_t value);
7676

77+
void *posix_memalignd_malloc(size_t size) {
78+
void *ptr = nullptr;
79+
int ret = posix_memalign(&ptr, 4096, size);
80+
if (ret != 0) {
81+
perror("posix_memalign failed");
82+
return nullptr;
83+
}
84+
return ptr;
85+
}
86+
7787
// thread api
7888
void start_transmit_thread();
7989
void stop_thansmit_thread();

0 commit comments

Comments
 (0)