Optimize packet I/O and timeouts

- Introduce per-thread I/O statistics for packet I/O to reduce performance overhead.
- Implement packet_io_yield() for better thread management during I/O operations.
- Refactor time wheel management:
  - Replace timeouts-based cron tasks with (now_ts - last_ts > timeout) for scheduled tasks.
  - Update the time wheel every 5 ms for improved time management.
This commit is contained in:
luwenpeng
2024-04-18 14:20:28 +08:00
parent 892842c61b
commit 5508454a1b
32 changed files with 377 additions and 540 deletions

View File

@@ -20,7 +20,7 @@ struct dumpfile_io
pcap_t *pcap;
struct lock_free_queue *queue[MAX_THREAD_NUM];
struct io_stat stat;
struct io_stat stat[MAX_THREAD_NUM];
uint64_t io_thread_need_exit;
uint64_t io_thread_is_runing;
};
@@ -193,11 +193,6 @@ void dumpfile_io_free(struct dumpfile_io *handle)
}
}
struct io_stat *dumpfile_io_get_stat(struct dumpfile_io *handle)
{
return &handle->stat;
}
int dumpfile_io_init(struct dumpfile_io *handle, uint16_t thr_idx)
{
return 0;
@@ -206,6 +201,7 @@ int dumpfile_io_init(struct dumpfile_io *handle, uint16_t thr_idx)
int dumpfile_io_ingress(struct dumpfile_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
{
struct lock_free_queue *queue = handle->queue[thr_idx];
struct io_stat *stat = &handle->stat[thr_idx];
struct pcap_pkt *pcap_pkt = NULL;
struct packet *pkt;
int nr_parsed = 0;
@@ -219,11 +215,11 @@ int dumpfile_io_ingress(struct dumpfile_io *handle, uint16_t thr_idx, struct pac
}
else
{
ATOMIC_ADD(&handle->stat.dev_rx_pkts, 1);
ATOMIC_ADD(&handle->stat.dev_rx_bytes, pcap_pkt->len);
stat->dev_rx_pkts++;
stat->dev_rx_bytes += pcap_pkt->len;
ATOMIC_ADD(&handle->stat.raw_rx_pkts, 1);
ATOMIC_ADD(&handle->stat.raw_rx_bytes, pcap_pkt->len);
stat->raw_rx_pkts++;
stat->raw_rx_bytes += pcap_pkt->len;
pkt = &pkts[nr_parsed];
memset(pkt, 0, sizeof(struct packet));
@@ -241,16 +237,18 @@ void dumpfile_io_egress(struct dumpfile_io *handle, uint16_t thr_idx, struct pac
{
int len;
struct packet *pkt = NULL;
struct io_stat *stat = &handle->stat[thr_idx];
for (int i = 0; i < nr_pkts; i++)
{
pkt = &pkts[i];
len = packet_get_len(pkt);
ATOMIC_ADD(&handle->stat.dev_tx_pkts, 1);
ATOMIC_ADD(&handle->stat.dev_tx_bytes, len);
stat->dev_tx_pkts++;
stat->dev_tx_bytes += len;
ATOMIC_ADD(&handle->stat.raw_tx_pkts, 1);
ATOMIC_ADD(&handle->stat.raw_tx_bytes, len);
stat->raw_tx_pkts++;
stat->raw_tx_bytes += len;
struct pcap_pkt *pcap_pkt = (struct pcap_pkt *)packet_get_io_ctx(pkt);
if (pcap_pkt)
@@ -275,3 +273,13 @@ void dumpfile_io_drop(struct dumpfile_io *handle, uint16_t thr_idx, struct packe
packet_free(pkt);
}
}
void dumpfile_io_yield(struct dumpfile_io *handle, uint16_t thr_idx, uint64_t timeout_ms)
{
return;
}
struct io_stat *dumpfile_io_stat(struct dumpfile_io *handle, uint16_t thr_idx)
{
return &handle->stat[thr_idx];
}