Skip to content

Commit

Permalink
AP_Networking: speed up sendfile download
Browse files Browse the repository at this point in the history
use a multiple of sector size and DMA safe memory
  • Loading branch information
tridge authored and magicrub committed Jan 5, 2024
1 parent c5f295e commit b0bbed0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions libraries/AP_Networking/AP_Networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,15 @@ bool AP_Networking::sendfile(SocketAPM *sock, int fd)
{
WITH_SEMAPHORE(sem);
if (sendfile_buf == nullptr) {
sendfile_buf = (uint8_t *)malloc(AP_NETWORKING_SENDFILE_BUFSIZE);
uint32_t bufsize = AP_NETWORKING_SENDFILE_BUFSIZE;
do {
sendfile_buf = (uint8_t *)hal.util->malloc_type(bufsize, AP_HAL::Util::MEM_FILESYSTEM);
if (sendfile_buf != nullptr) {
sendfile_bufsize = bufsize;
break;
}
bufsize /= 2;
} while (bufsize >= 4096);
if (sendfile_buf == nullptr) {
return false;
}
Expand Down Expand Up @@ -344,7 +352,7 @@ void AP_Networking::sendfile_check(void)
if (!s.sock->pollout(0)) {
continue;
}
const auto nread = AP::FS().read(s.fd, sendfile_buf, AP_NETWORKING_SENDFILE_BUFSIZE);
const auto nread = AP::FS().read(s.fd, sendfile_buf, sendfile_bufsize);
if (nread <= 0) {
s.close();
continue;
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_Networking/AP_Networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class AP_Networking
} sendfiles[AP_NETWORKING_NUM_SENDFILES];

uint8_t *sendfile_buf;
uint32_t sendfile_bufsize;
void sendfile_check(void);
bool sendfile_thread_started;

Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_Networking/AP_Networking_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,5 @@
#endif

#ifndef AP_NETWORKING_SENDFILE_BUFSIZE
#define AP_NETWORKING_SENDFILE_BUFSIZE 10000
#define AP_NETWORKING_SENDFILE_BUFSIZE (64*512)
#endif

0 comments on commit b0bbed0

Please sign in to comment.