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

@@ -15,7 +15,7 @@ struct marsio_io
struct mr_vdev *mr_dev;
struct mr_sendpath *mr_path;
struct io_stat stat;
struct io_stat stat[MAX_THREAD_NUM];
};
/******************************************************************************
@@ -118,11 +118,6 @@ void marsio_io_free(struct marsio_io *handle)
}
}
struct io_stat *marsio_io_get_stat(struct marsio_io *handle)
{
return &handle->stat;
}
int marsio_io_init(struct marsio_io *handle, uint16_t thr_idx)
{
if (marsio_thread_init(handle->mr_ins) != 0)
@@ -139,6 +134,7 @@ int marsio_io_ingress(struct marsio_io *handle, uint16_t thr_idx, struct packet
struct packet *pkt;
marsio_buff_t *mbuff;
marsio_buff_t *rx_buffs[RX_BURST_MAX];
struct io_stat *stat = &handle->stat[thr_idx];
int nr_recv;
int nr_parsed = 0;
int len;
@@ -156,16 +152,16 @@ int marsio_io_ingress(struct marsio_io *handle, uint16_t thr_idx, struct packet
data = marsio_buff_mtod(mbuff);
len = marsio_buff_datalen(mbuff);
ATOMIC_ADD(&handle->stat.dev_rx_pkts, 1);
ATOMIC_ADD(&handle->stat.dev_rx_bytes, len);
stat->dev_rx_pkts++;
stat->dev_rx_bytes += len;
if (is_keepalive_packet(data, len))
{
ATOMIC_ADD(&handle->stat.keep_alive_pkts, 1);
ATOMIC_ADD(&handle->stat.keep_alive_bytes, len);
stat->keep_alive_pkts++;
stat->keep_alive_bytes += len;
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;
marsio_send_burst(handle->mr_path, thr_idx, &mbuff, 1);
continue;
@@ -181,13 +177,13 @@ int marsio_io_ingress(struct marsio_io *handle, uint16_t thr_idx, struct packet
if (marsio_buff_is_ctrlbuf(mbuff))
{
packet_set_ctrl(pkt);
ATOMIC_ADD(&handle->stat.ctrl_rx_pkts, 1);
ATOMIC_ADD(&handle->stat.ctrl_rx_bytes, len);
stat->ctrl_rx_pkts++;
stat->ctrl_rx_bytes += len;
}
else
{
ATOMIC_ADD(&handle->stat.raw_rx_pkts, 1);
ATOMIC_ADD(&handle->stat.raw_rx_bytes, len);
stat->raw_rx_pkts++;
stat->raw_rx_bytes += len;
}
}
@@ -198,6 +194,7 @@ void marsio_io_egress(struct marsio_io *handle, uint16_t thr_idx, struct packet
{
struct packet *pkt;
marsio_buff_t *mbuff;
struct io_stat *stat = &handle->stat[thr_idx];
int len;
for (int i = 0; i < nr_pkts; i++)
@@ -205,21 +202,21 @@ void marsio_io_egress(struct marsio_io *handle, uint16_t thr_idx, struct packet
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;
mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
assert(mbuff != NULL);
if (marsio_buff_is_ctrlbuf(mbuff))
{
ATOMIC_ADD(&handle->stat.ctrl_tx_pkts, 1);
ATOMIC_ADD(&handle->stat.ctrl_tx_bytes, len);
stat->ctrl_tx_pkts++;
stat->ctrl_tx_bytes += len;
}
else
{
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;
}
marsio_send_burst(handle->mr_path, thr_idx, &mbuff, 1);
@@ -242,4 +239,18 @@ void marsio_io_drop(struct marsio_io *handle, uint16_t thr_idx, struct packet *p
}
packet_free(pkt);
}
}
}
void marsio_io_yield(struct marsio_io *handle, uint16_t thr_idx, uint64_t timeout_ms)
{
struct mr_vdev *vdevs[1] = {
handle->mr_dev,
};
marsio_poll_wait(handle->mr_ins, vdevs, 1, thr_idx, timeout_ms);
}
struct io_stat *marsio_io_stat(struct marsio_io *handle, uint16_t thr_idx)
{
return &handle->stat[thr_idx];
}