Skip to content

Commit f825729

Browse files
committed
feat(sgdma): R/W the status only, not the whole desc
1 parent 2abb378 commit f825729

3 files changed

Lines changed: 32 additions & 20 deletions

File tree

inc/udmaio/UioMemSgdma.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#pragma once
1313

14+
#include <cstddef>
15+
1416
#include "DmaBufferAbstract.hpp"
1517
#include "RegAccessor.hpp"
1618

@@ -65,10 +67,17 @@ class UioMemSgdma : public UioIf {
6567

6668
// set excessively high number of 1024 descriptors, b/c the actual number is not known at compile time
6769
RegAccessorArray<S2mmDesc, 0, 1024, DESC_ADDR_STEP> descriptors{this};
70+
// Make a separate accessor for the statuses only, so we don't have to read/write the whole descriptor when we only want the status
71+
RegAccessorArray<S2mmDescStatus, offsetof(S2mmDesc, status), 1024, DESC_ADDR_STEP>
72+
desc_statuses{this};
6873

6974
size_t _nr_cyc_desc;
7075
size_t _next_readable_buf;
7176

77+
// Cache buffer addrs/sizes in order to not have to pull it from BRAM all the time
78+
std::vector<uint64_t> _buf_addrs;
79+
size_t _buf_size;
80+
7281
void write_cyc_mode(const std::vector<UioRegion>& dst_bufs);
7382

7483
public:

src/UioMemSgdma.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,18 @@ void UioMemSgdma::write_cyc_mode(const std::vector<UioRegion>& dst_bufs) {
4646
void UioMemSgdma::init_buffers(DmaBufferAbstract& mem, size_t num_buffers, size_t buf_size) {
4747
// FIXME: enforce alignment constraints?
4848
std::vector<UioRegion> dst_bufs;
49+
_buf_addrs.clear();
4950
for (size_t i = 0; i < num_buffers; i++) {
51+
uint64_t addr = mem.get_phys_region().addr + i * buf_size;
5052
dst_bufs.push_back({
51-
.addr = mem.get_phys_region().addr + i * buf_size,
53+
.addr = addr,
5254
.size = buf_size,
5355
});
56+
_buf_addrs.push_back(addr);
5457
};
5558

5659
write_cyc_mode(dst_bufs);
60+
_buf_size = buf_size;
5761
}
5862

5963
void UioMemSgdma::print_desc(const S2mmDesc& desc) const {
@@ -97,30 +101,29 @@ std::vector<UioRegion> UioMemSgdma::get_full_buffers() {
97101
std::vector<UioRegion> bufs;
98102
99103
for (size_t i = 0; i < _nr_cyc_desc; i++) {
100-
S2mmDesc desc = descriptors[_next_readable_buf].rd();
101-
if (!desc.status.cmplt) {
104+
auto stat = desc_statuses[_next_readable_buf].rd();
105+
if (!stat.cmplt) {
102106
break;
103107
}
104108
105-
if ((!desc.status.rxeof && (desc.status.num_stored_bytes != desc.control.buffer_len)) ||
106-
desc.status.num_stored_bytes == 0) {
109+
if ((!stat.rxeof && (stat.num_stored_bytes != _buf_size)) || stat.num_stored_bytes == 0) {
107110
BOOST_LOG_SEV(_lg, bls::error)
108-
<< "Descriptor #" << i << " size mismatch (expected " << desc.control.buffer_len
109-
<< ", received " << desc.status.num_stored_bytes << "), skipping";
111+
<< "Descriptor #" << i << " size mismatch (expected " << _buf_size << ", received "
112+
<< stat.num_stored_bytes << "), skipping";
110113

111-
print_desc(desc);
114+
print_desc(descriptors[_next_readable_buf].rd());
112115
continue;
113116
}
114117

115-
desc.status.cmplt = 0;
116-
descriptors[_next_readable_buf].wr(desc);
118+
stat.cmplt = 0;
119+
desc_statuses[_next_readable_buf].wr(stat);
117120

118-
bufs.emplace_back(
119-
UioRegion{static_cast<uintptr_t>(desc.buffer_addr), desc.status.num_stored_bytes});
121+
const uint64_t buf_addr = _buf_addrs[_next_readable_buf];
122+
bufs.emplace_back(UioRegion{static_cast<uintptr_t>(buf_addr), stat.num_stored_bytes});
120123

121124
BOOST_LOG_SEV(_lg, bls::trace)
122-
<< "save buf #" << _next_readable_buf << " (" << desc.status.num_stored_bytes
123-
<< " bytes) @ 0x" << std::hex << desc.buffer_addr;
125+
<< "save buf #" << _next_readable_buf << " (" << stat.num_stored_bytes << " bytes) @ 0x"
126+
<< std::hex << buf_addr;
124127

125128
_next_readable_buf++;
126129
_next_readable_buf %= _nr_cyc_desc;

tests/test_UioMemSgdma.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ BOOST_FIXTURE_TEST_CASE(init_buffers, UioMemSgdmaTest) {
4141
"Descriptor address mismatch");
4242
}
4343

44-
void fill_buffer(HwAccessorPtr& mem, uintptr_t offs, size_t size) {
45-
assert(offs % sizeof(uint32_t) == 0);
44+
void fill_buffer(HwAccessorPtr& mem, uintptr_t addr, uint32_t start_count, size_t size) {
45+
assert(addr % sizeof(uint32_t) == 0);
4646
assert(size % sizeof(uint32_t) == 0);
4747

48-
while (offs < size) {
49-
mem->_wr32(offs, offs);
50-
offs += sizeof(uint32_t);
48+
while (addr < size) {
49+
mem->_wr32(addr, addr + start_count);
50+
addr += sizeof(uint32_t);
5151
}
5252
}
5353

@@ -67,7 +67,7 @@ BOOST_FIXTURE_TEST_CASE(full_buffers, UioMemSgdmaTest) {
6767
BOOST_CHECK_MESSAGE(empty_bufs.size() == 0, "Empty buffers result not empty");
6868

6969
// Fill first buffer
70-
fill_buffer(hw_fpga_mem, 0, buf_size);
70+
fill_buffer(hw_fpga_mem, 0x00000000, 0, buf_size);
7171

7272
auto desc = descriptors[0].rd();
7373
desc.status.cmplt = true;

0 commit comments

Comments
 (0)