perf: 减少marsio_buff_datalen的调用以提升性能
This commit is contained in:
@@ -80,16 +80,6 @@ void sce_packet_get_innermost_tuple(const struct packet *handler, struct four_tu
|
||||
// return -1 : error
|
||||
int mbuff_get_metadata(marsio_buff_t *rx_buff, struct metadata *meta)
|
||||
{
|
||||
memset(meta, 0, sizeof(struct metadata));
|
||||
|
||||
meta->raw_len = marsio_buff_datalen(rx_buff);
|
||||
meta->raw_data = marsio_buff_mtod(rx_buff);
|
||||
if (meta->raw_data == NULL || meta->raw_len == 0)
|
||||
{
|
||||
LOG_ERROR("%s: unable to get raw_data from metadata", LOG_TAG_PKTIO);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (marsio_buff_get_metadata(rx_buff, MR_BUFF_SESSION_ID, &(meta->session_id), sizeof(meta->session_id)) <= 0)
|
||||
{
|
||||
LOG_ERROR("%s: unable to get session_id from metadata", LOG_TAG_PKTIO);
|
||||
@@ -303,9 +293,8 @@ static void update_metadata_by_session(struct session_ctx *ctx, struct metadata
|
||||
|
||||
// return 0 : not keepalive packet
|
||||
// return 1 : is keepalive packet
|
||||
static int is_downlink_keepalive_packet(marsio_buff_t *rx_buff)
|
||||
static int is_downlink_keepalive_packet(marsio_buff_t *rx_buff, int raw_len)
|
||||
{
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
char *raw_data = marsio_buff_mtod(rx_buff);
|
||||
if (raw_data == NULL || raw_len < (int)(sizeof(struct ethhdr)))
|
||||
{
|
||||
@@ -325,9 +314,8 @@ static int is_downlink_keepalive_packet(marsio_buff_t *rx_buff)
|
||||
|
||||
// return 0 : not keepalive packet
|
||||
// return 1 : is keepalive packet
|
||||
static int is_uplink_keepalive_packet(marsio_buff_t *rx_buff)
|
||||
static int is_uplink_keepalive_packet(marsio_buff_t *rx_buff, int raw_len)
|
||||
{
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
char *raw_data = marsio_buff_mtod(rx_buff);
|
||||
if (raw_data == NULL || raw_len < (int)(sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udphdr)))
|
||||
{
|
||||
@@ -501,7 +489,6 @@ void vlan_encapsulate(marsio_buff_t *mbuff, int vlan_id, int replace_orig_vlan_h
|
||||
|
||||
static inline int send_packet_to_sf(struct session_ctx *session_ctx, marsio_buff_t *mbuff, struct metadata *meta, struct selected_sf *sf, struct thread_ctx *thread_ctx)
|
||||
{
|
||||
thread_ctx->tx_packets_ipid++;
|
||||
int nsend = 0;
|
||||
char *buffer = NULL;
|
||||
struct packet_io *packet_io = thread_ctx->ref_io;
|
||||
@@ -511,6 +498,7 @@ static inline int send_packet_to_sf(struct session_ctx *session_ctx, marsio_buff
|
||||
switch (sf->sf_connectivity.method)
|
||||
{
|
||||
case ENCAPSULATE_METHOD_VXLAN_G:
|
||||
thread_ctx->tx_packets_ipid++;
|
||||
buffer = marsio_buff_prepend(mbuff, VXLAN_FRAME_HDR_LEN);
|
||||
vxlan_frame_encode(buffer,
|
||||
packet_io->config.dev_endpoint_l3_mac, sf->sf_dst_mac,
|
||||
@@ -560,8 +548,7 @@ static inline void action_err_block(marsio_buff_t *rx_buff, struct metadata *met
|
||||
struct packet_io *packet_io = thread_ctx->ref_io;
|
||||
int thread_index = thread_ctx->thread_index;
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.error_block), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.error_block), 1, meta->raw_len);
|
||||
marsio_buff_free(packet_io->instance, &rx_buff, 1, 0, thread_index);
|
||||
}
|
||||
|
||||
@@ -579,26 +566,23 @@ static inline int action_nf_inject(marsio_buff_t *rx_buff, struct metadata *meta
|
||||
return 0;
|
||||
}
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
marsio_send_burst(packet_io->dev_nf.mr_path, thread_index, &rx_buff, 1);
|
||||
throughput_metrics_inc(&(thread_metrics->device.nf_tx), 1, raw_len);
|
||||
return raw_len;
|
||||
throughput_metrics_inc(&(thread_metrics->device.nf_tx), 1, meta->raw_len);
|
||||
return meta->raw_len;
|
||||
}
|
||||
|
||||
static inline void action_mirr_bypass(marsio_buff_t *rx_buff, struct metadata *meta, struct selected_sf *sf, struct thread_ctx *thread_ctx)
|
||||
{
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.mirr_bypass), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.mirr_bypass), 1, meta->raw_len);
|
||||
}
|
||||
|
||||
static inline void action_mirr_block(marsio_buff_t *rx_buff, struct metadata *meta, struct selected_sf *sf, struct thread_ctx *thread_ctx)
|
||||
{
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.mirr_block), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.mirr_block), 1, meta->raw_len);
|
||||
}
|
||||
|
||||
static inline void action_mirr_forward(struct session_ctx *session_ctx, marsio_buff_t *rx_buff, struct metadata *meta, struct selected_sf *sf, struct thread_ctx *thread_ctx)
|
||||
@@ -607,7 +591,6 @@ static inline void action_mirr_forward(struct session_ctx *session_ctx, marsio_b
|
||||
struct packet_io *packet_io = thread_ctx->ref_io;
|
||||
int thread_index = thread_ctx->thread_index;
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
char *raw_data = marsio_buff_mtod(rx_buff);
|
||||
|
||||
marsio_buff_t *new_buff = NULL;
|
||||
@@ -617,11 +600,11 @@ static inline void action_mirr_forward(struct session_ctx *session_ctx, marsio_b
|
||||
return;
|
||||
}
|
||||
|
||||
char *copy_ptr = marsio_buff_append(new_buff, raw_len);
|
||||
memcpy(copy_ptr, raw_data, raw_len);
|
||||
char *copy_ptr = marsio_buff_append(new_buff, meta->raw_len);
|
||||
memcpy(copy_ptr, raw_data, meta->raw_len);
|
||||
|
||||
int nsend = send_packet_to_sf(session_ctx, new_buff, meta, sf, thread_ctx);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.mirr_tx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.mirr_tx), 1, meta->raw_len);
|
||||
throughput_metrics_inc(&sf->tx, 1, nsend);
|
||||
struct sf_metrics_key key = {0};
|
||||
key.rule_id = sf->rule_id;
|
||||
@@ -635,8 +618,7 @@ static inline void action_stee_bypass(marsio_buff_t *rx_buff, struct metadata *m
|
||||
{
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.stee_bypass), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.stee_bypass), 1, meta->raw_len);
|
||||
}
|
||||
|
||||
static inline void action_stee_block(marsio_buff_t *rx_buff, struct metadata *meta, struct selected_sf *sf, struct thread_ctx *thread_ctx)
|
||||
@@ -645,8 +627,7 @@ static inline void action_stee_block(marsio_buff_t *rx_buff, struct metadata *me
|
||||
struct packet_io *packet_io = thread_ctx->ref_io;
|
||||
int thread_index = thread_ctx->thread_index;
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.stee_block), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.stee_block), 1, meta->raw_len);
|
||||
marsio_buff_free(packet_io->instance, &rx_buff, 1, 0, thread_index);
|
||||
}
|
||||
|
||||
@@ -654,9 +635,8 @@ static inline void action_stee_forward(struct session_ctx *session_ctx, marsio_b
|
||||
{
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
int nsend = send_packet_to_sf(session_ctx, rx_buff, meta, sf, thread_ctx);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.stee_tx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->data_pkt.stee_tx), 1, meta->raw_len);
|
||||
throughput_metrics_inc(&sf->tx, 1, nsend);
|
||||
struct sf_metrics_key key = {0};
|
||||
key.rule_id = sf->rule_id;
|
||||
@@ -1053,12 +1033,15 @@ static void handle_session_resetall(struct metadata *meta, struct control_packet
|
||||
* handle control/raw/inject packet
|
||||
******************************************************************************/
|
||||
|
||||
static void handle_control_packet(marsio_buff_t *rx_buff, struct thread_ctx *thread_ctx)
|
||||
static void handle_control_packet(marsio_buff_t *rx_buff, struct thread_ctx *thread_ctx, int raw_len)
|
||||
{
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
struct metadata meta;
|
||||
struct control_packet ctrl_pkt;
|
||||
|
||||
memset(&meta, 0, sizeof(struct metadata));
|
||||
meta.raw_len = raw_len;
|
||||
meta.raw_data = marsio_buff_mtod(rx_buff);
|
||||
if (mbuff_get_metadata(rx_buff, &meta) == -1)
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet, unable to get metadata", LOG_TAG_PKTIO);
|
||||
@@ -1106,7 +1089,7 @@ error_ctrl_pkt:
|
||||
return;
|
||||
}
|
||||
|
||||
static void handle_data_packet(marsio_buff_t *rx_buff, struct thread_ctx *thread_ctx)
|
||||
static void handle_data_packet(marsio_buff_t *rx_buff, struct thread_ctx *thread_ctx, int raw_len)
|
||||
{
|
||||
struct session_table *session_table = thread_ctx->session_table;
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
@@ -1115,6 +1098,9 @@ static void handle_data_packet(marsio_buff_t *rx_buff, struct thread_ctx *thread
|
||||
struct session_ctx *session_ctx = NULL;
|
||||
struct selected_chaining *chaining = NULL;
|
||||
|
||||
memset(&meta, 0, sizeof(struct metadata));
|
||||
meta.raw_len = raw_len;
|
||||
meta.raw_data = marsio_buff_mtod(rx_buff);
|
||||
if (mbuff_get_metadata(rx_buff, &meta) == -1)
|
||||
{
|
||||
LOG_ERROR("%s: unexpected raw packet, unable to get metadata, bypass !!!", LOG_TAG_PKTIO);
|
||||
@@ -1167,7 +1153,7 @@ error_bypass:
|
||||
action_err_bypass(rx_buff, &meta, NULL, thread_ctx);
|
||||
}
|
||||
|
||||
static void handle_inject_vxlan_packet(marsio_buff_t *rx_buff, struct thread_ctx *thread_ctx)
|
||||
static void handle_inject_vxlan_packet(marsio_buff_t *rx_buff, struct thread_ctx *thread_ctx, int raw_len)
|
||||
{
|
||||
struct session_table *session_table = thread_ctx->session_table;
|
||||
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
|
||||
@@ -1179,11 +1165,11 @@ static void handle_inject_vxlan_packet(marsio_buff_t *rx_buff, struct thread_ctx
|
||||
memset(&meta, 0, sizeof(struct metadata));
|
||||
|
||||
int sf_index = 0;
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
char *raw_data = marsio_buff_mtod(rx_buff);
|
||||
if (vxlan_frame_decode(&vxlan_hdr, raw_data, raw_len) == -1)
|
||||
{
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vxlan_drop), 1, raw_len);
|
||||
meta.raw_len = raw_len;
|
||||
action_err_block(rx_buff, &meta, NULL, thread_ctx);
|
||||
return;
|
||||
}
|
||||
@@ -1527,7 +1513,7 @@ int packet_io_thread_polling_nf(struct packet_io *handle, struct thread_ctx *thr
|
||||
marsio_buff_t *rx_buff = rx_buffs[j];
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
|
||||
if (is_downlink_keepalive_packet(rx_buff))
|
||||
if (is_downlink_keepalive_packet(rx_buff, raw_len))
|
||||
{
|
||||
throughput_metrics_inc(&(thread_metrics->device.nf_rx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->device.nf_tx), 1, raw_len);
|
||||
@@ -1545,14 +1531,14 @@ int packet_io_thread_polling_nf(struct packet_io *handle, struct thread_ctx *thr
|
||||
throughput_metrics_inc(&(thread_metrics->ctrl_pkt.rx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->ctrl_pkt.tx), 1, raw_len);
|
||||
|
||||
handle_control_packet(rx_buff, thread_ctx);
|
||||
handle_control_packet(rx_buff, thread_ctx, raw_len);
|
||||
marsio_send_burst(handle->dev_nf.mr_path, thread_index, &rx_buff, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
throughput_metrics_inc(&(thread_metrics->device.nf_rx), 1, raw_len);
|
||||
|
||||
handle_data_packet(rx_buff, thread_ctx);
|
||||
handle_data_packet(rx_buff, thread_ctx, raw_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1590,7 +1576,7 @@ int packet_io_thread_polling_endpoint_l3(struct packet_io *handle, struct thread
|
||||
marsio_buff_t *rx_buff = rx_buffs[j];
|
||||
int raw_len = marsio_buff_datalen(rx_buff);
|
||||
|
||||
if (is_uplink_keepalive_packet(rx_buff))
|
||||
if (is_uplink_keepalive_packet(rx_buff, raw_len))
|
||||
{
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vxlan_rx), 1, raw_len);
|
||||
throughput_metrics_inc(&(thread_metrics->kee_pkt.uplink_rx), 1, raw_len);
|
||||
@@ -1602,7 +1588,7 @@ int packet_io_thread_polling_endpoint_l3(struct packet_io *handle, struct thread
|
||||
{
|
||||
throughput_metrics_inc(&(thread_metrics->device.endpoint_vxlan_rx), 1, raw_len);
|
||||
|
||||
handle_inject_vxlan_packet(rx_buff, thread_ctx);
|
||||
handle_inject_vxlan_packet(rx_buff, thread_ctx, raw_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user