diff --git a/include/tx_desc.h b/include/tx_desc.h index a830d11..d75867c 100644 --- a/include/tx_desc.h +++ b/include/tx_desc.h @@ -39,12 +39,14 @@ struct tx_desc { void *pkt; } __attribute__((__aligned__(64))); -#define tx_desc_done(desc, pool) do { \ - if ((desc)->flags & TX_DESC_FLAG_MEM_FROM_MBUF) \ +#define tx_desc_done(desc, worker) do { \ + if ((desc)->flags & TX_DESC_FLAG_MEM_FROM_MBUF) { \ packet_free(desc->pkt); \ + worker->nr_write_mbuf -= 1; \ + } \ if ((desc)->write_done) \ desc->write_done(desc->base, desc->param); \ - tx_desc_free(pool, desc); \ + tx_desc_free(worker->tx_desc_pool, desc); \ } while (0) diff --git a/src/sock.c b/src/sock.c index 2b7b0fc..9553d35 100644 --- a/src/sock.c +++ b/src/sock.c @@ -437,7 +437,7 @@ static void reclaim_txq(struct tcp_sock *tsock) break; debug_assert(i <= tsock->txq.size); - tx_desc_done(desc, tsock->worker->tx_desc_pool); + tx_desc_done(desc, tsock->worker); } free(tsock->txq.descs); diff --git a/src/tcp/tcp_input.c b/src/tcp/tcp_input.c index 11e8c8f..7ca5052 100644 --- a/src/tcp/tcp_input.c +++ b/src/tcp/tcp_input.c @@ -754,11 +754,8 @@ static inline int ack_sent_data(struct tpa_worker *worker, struct tcp_sock *tsoc tsock_write_latency_update(tsock, desc, now); } - if (desc->flags & TX_DESC_FLAG_MEM_FROM_MBUF) - worker->nr_write_mbuf -= 1; - nr_acked_pkt += 1; - tx_desc_done(desc, worker->tx_desc_pool); + tx_desc_done(desc, worker); } while (acked_len > 0); /* diff --git a/test/unit/tcp_timeout_rto.c b/test/unit/tcp_timeout_rto.c index 1db96fd..6fc0bdc 100644 --- a/test/unit/tcp_timeout_rto.c +++ b/test/unit/tcp_timeout_rto.c @@ -82,8 +82,9 @@ static void test_tcp_timeout_rto_timeout(void) } /* TODO: speed up it */ + tcp_cfg.retries = 3; start_ts_us = worker->ts_us; - while (tsock->rto_shift < 3) { + while (tsock->rto_shift < tcp_cfg.retries) { pkt = NULL; assert(ut_tcp_output(&pkt, 1) <= 1); { assert((uint32_t)(tsock->snd_nxt - tsock->snd_una) == sizeof(buf)); @@ -96,7 +97,12 @@ static void test_tcp_timeout_rto_timeout(void) } } - ut_close(tsock, CLOSE_TYPE_4WAY); + ut_close(tsock, CLOSE_TYPE_CLOSE_DIRECTLY); + /* + * make sure nr_write_mbuf is updated correctly + * after sock txq reclaim. + */ + assert(worker->nr_write_mbuf == 0); } /*