Skip to content

Commit bf2919b

Browse files
committed
Merge branch 'feat/improve_raw_tx' into 'feature/esp_as_mcu_host'
feat/improve_raw_tx Improve Raw Tx on host by doing zero copy See merge request app-frameworks/esp_hosted!484
2 parents 66d5371 + 50893e8 commit bf2919b

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

host/utils/stats.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#endif
2525
#include "esp_log.h"
2626

27+
// use mempool and zero copy for Tx
28+
#include "mempool.h"
29+
2730
#if ESP_PKT_STATS
2831
struct pkt_stats_t pkt_stats;
2932
void *pkt_stats_thread = NULL;
@@ -52,6 +55,13 @@ static void * raw_tp_tx_task_id = 0;
5255
static uint64_t test_raw_tx_len = 0;
5356
static uint64_t test_raw_rx_len = 0;
5457

58+
static struct mempool * buf_mp_g = NULL;
59+
60+
void stats_mempool_free(void* ptr)
61+
{
62+
mempool_free(buf_mp_g, ptr);
63+
}
64+
5565
void test_raw_tp_cleanup(void)
5666
{
5767
int ret = 0;
@@ -102,25 +112,30 @@ static void raw_tp_tx_task(void const* pvParameters)
102112
uint32_t i = 0;
103113
g_h.funcs->_h_sleep(5);
104114

115+
buf_mp_g = mempool_create(MAX_TRANSPORT_BUFFER_SIZE);
116+
#ifdef CONFIG_ESP_CACHE_MALLOC
117+
assert(channel->memp);
118+
#endif
119+
105120
while (1) {
106121

107122
#if CONFIG_H_LOWER_MEMCOPY
108123
raw_tp_tx_buf = (uint8_t*)g_h.funcs->_h_calloc(1, MAX_TRANSPORT_BUFFER_SIZE);
109124

110125
ptr = (uint32_t*) raw_tp_tx_buf;
111126
for (i=0; i<(TEST_RAW_TP__BUF_SIZE/4-1); i++, ptr++)
112-
*ptr = 0xBAADF00D;
127+
*ptr = 0xBAADF00D;
113128

114129
ret = esp_hosted_tx(ESP_TEST_IF, 0, raw_tp_tx_buf, TEST_RAW_TP__BUF_SIZE, H_BUFF_ZEROCOPY, H_DEFLT_FREE_FUNC);
115130

116131
#else
117-
raw_tp_tx_buf = (uint8_t*)g_h.funcs->_h_calloc(1, TEST_RAW_TP__BUF_SIZE);
132+
raw_tp_tx_buf = mempool_alloc(buf_mp_g, MAX_TRANSPORT_BUFFER_SIZE, true);
118133

119-
ptr = (uint32_t*) raw_tp_tx_buf;
134+
ptr = (uint32_t*) (raw_tp_tx_buf + H_ESP_PAYLOAD_HEADER_OFFSET);
120135
for (i=0; i<(TEST_RAW_TP__BUF_SIZE/4-1); i++, ptr++)
121-
*ptr = 0xBAADF00D;
136+
*ptr = 0xBAADF00D;
122137

123-
ret = esp_hosted_tx(ESP_TEST_IF, 0, raw_tp_tx_buf, TEST_RAW_TP__BUF_SIZE, H_BUFF_NO_ZEROCOPY, H_DEFLT_FREE_FUNC);
138+
ret = esp_hosted_tx(ESP_TEST_IF, 0, raw_tp_tx_buf, TEST_RAW_TP__BUF_SIZE, H_BUFF_ZEROCOPY, stats_mempool_free);
124139
#endif
125140
if (ret != STM_OK) {
126141
ESP_LOGE(TAG, "Failed to send to queue\n");

0 commit comments

Comments
 (0)