perf: 将marsio_send_burst_with_options替换成marsio_send_burst和marsio_buff_set_metadata(MR_BUFF_REHASH_INDEX)以降低CPU

This commit is contained in:
luwenpeng
2023-11-21 19:08:30 +08:00
parent 332fe52650
commit c3bd2fb939
4 changed files with 25 additions and 11 deletions

View File

@@ -47,6 +47,7 @@ struct metadata
{
int write_ref;
uint64_t session_id;
uint32_t rehash_index;
char *raw_data;
int raw_len;

View File

@@ -96,6 +96,12 @@ int mbuff_get_metadata(marsio_buff_t *rx_buff, struct metadata *meta)
return -1;
}
if (marsio_buff_get_metadata(rx_buff, MR_BUFF_REHASH_INDEX, &(meta->rehash_index), sizeof(meta->rehash_index)) <= 0)
{
LOG_ERROR("%s: unable to get rehash_index from metadata", LOG_TAG_PKTIO);
return -1;
}
// 1: E2I
// 0: I2E
if (marsio_buff_get_metadata(rx_buff, MR_BUFF_DIR, &(meta->is_e2i_dir), sizeof(meta->is_e2i_dir)) <= 0)
@@ -512,7 +518,8 @@ static inline int send_packet_to_sf(struct session_ctx *session_ctx, marsio_buff
session_ctx->vxlan_src_port, meta->raw_len,
meta->is_e2i_dir, meta->is_decrypted, sf->sf_index);
nsend = marsio_buff_datalen(mbuff);
marsio_send_burst_with_options(packet_io->dev_endpoint_l3.mr_path, thread_ctx->thread_index, &mbuff, 1, MARSIO_SEND_OPT_REHASH);
marsio_buff_set_metadata(mbuff, MR_BUFF_REHASH_INDEX, &(session_ctx->ctrl_meta->rehash_index), sizeof(session_ctx->ctrl_meta->rehash_index));
marsio_send_burst(packet_io->dev_endpoint_l3.mr_path, thread_ctx->thread_index, &mbuff, 1);
throughput_metrics_inc(&(thread_metrics->device.endpoint_vxlan_tx), 1, nsend);
break;
case ENCAPSULATE_METHOD_LAYER2_SWITCH:
@@ -520,7 +527,8 @@ static inline int send_packet_to_sf(struct session_ctx *session_ctx, marsio_buff
meta->is_e2i_dir ? sf->sf_connectivity.ext_vlan_tag : sf->sf_connectivity.int_vlan_tag,
packet_io->config.vlan_encapsulate_replace_orig_vlan_header);
nsend = marsio_buff_datalen(mbuff);
marsio_send_burst_with_options(packet_io->dev_endpoint_l2.mr_path, thread_ctx->thread_index, &mbuff, 1, MARSIO_SEND_OPT_REHASH);
marsio_buff_set_metadata(mbuff, MR_BUFF_REHASH_INDEX, &(session_ctx->ctrl_meta->rehash_index), sizeof(session_ctx->ctrl_meta->rehash_index));
marsio_send_burst(packet_io->dev_endpoint_l2.mr_path, thread_ctx->thread_index, &mbuff, 1);
throughput_metrics_inc(&(thread_metrics->device.endpoint_vlan_tx), 1, nsend);
break;
case ENCAPSULATE_METHOD_LAYER3_SWITCH:

View File

@@ -32,6 +32,7 @@ void metadata_shallow_copy(struct metadata *dst, struct metadata *src)
{
dst->write_ref++;
dst->session_id = src->session_id;
dst->rehash_index = src->rehash_index;
dst->raw_data = NULL;
dst->raw_len = 0;
dst->l7offset = src->l7offset;
@@ -45,18 +46,11 @@ void metadata_shallow_copy(struct metadata *dst, struct metadata *src)
void metadata_deep_copy(struct metadata *dst, struct metadata *src)
{
dst->write_ref++;
dst->session_id = src->session_id;
metadata_shallow_copy(dst, src);
dst->raw_data = (char *)calloc(src->raw_len + 1, sizeof(char));
memcpy(dst->raw_data, src->raw_data, src->raw_len);
dst->raw_len = src->raw_len;
dst->l7offset = src->l7offset;
dst->is_e2i_dir = src->is_e2i_dir;
dst->is_ctrl_pkt = src->is_ctrl_pkt;
dst->is_decrypted = src->is_decrypted;
sids_copy(&dst->sids, &src->sids);
route_ctx_copy(&dst->route_ctx, &src->route_ctx);
}
void metadata_free(struct metadata *meta)

View File

@@ -55,6 +55,7 @@ struct mrb_metadata
uint16_t link_db_index;
uint16_t user_data_0;
uint32_t hash_usr;
};
struct mock_marsio_buff_t
@@ -154,6 +155,9 @@ int marsio_buff_set_metadata(marsio_buff_t *m, enum mr_buff_metadata_type type,
switch (type)
{
case MR_BUFF_REHASH_INDEX:
mrb_metadata->hash_usr = *(uint32_t *)data;
return 0;
case MR_BUFF_ROUTE_CTX:
route_ctx = (struct mrb_metadata_route_ctx *)data;
assert(route_ctx != NULL);
@@ -189,6 +193,13 @@ int marsio_buff_get_metadata(marsio_buff_t *m, enum mr_buff_metadata_type type,
switch (type)
{
case MR_BUFF_REHASH_INDEX:
if (sz_data < sizeof(uint32_t))
{
return -1;
}
*(uint32_t *)(data) = mrb_metadata->hash_usr;
return sizeof(uint32_t);
case MR_BUFF_ROUTE_CTX:
if (sz_data < sizeof(struct mrb_metadata_route_ctx))
{