packet io增加fieldstat状态统计
This commit is contained in:
@@ -21,34 +21,35 @@
|
||||
#include "tfe_session_table.h"
|
||||
|
||||
|
||||
static int tfe_tap_read_per_thread(int tap_fd, char *buff, int buff_size, void *logger)
|
||||
void * g_packet_io_logger = NULL;
|
||||
|
||||
static int tap_read(int tap_fd, char *buff, int buff_size, void *logger)
|
||||
{
|
||||
int ret = read(tap_fd, buff, buff_size);
|
||||
if (ret < 0)
|
||||
{
|
||||
if (errno != EWOULDBLOCK && errno != EAGAIN)
|
||||
{
|
||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to read data from tapfd %d, aborting: %s", LOG_TAG_PKTIO, tap_fd, strerror(errno));
|
||||
TFE_LOG_ERROR(logger, "%s: unable to read data from tapfd %d, aborting: %s", LOG_TAG_PKTIO, tap_fd, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void acceptor_ctx_destory(struct acceptor_kni_v4 * ctx)
|
||||
void acceptor_kni_v4_destroy(struct acceptor_kni_v4 *ctx)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
packet_io_destory(ctx->io);
|
||||
packet_io_fs_destory(ctx->packet_io_fs);
|
||||
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
struct acceptor_kni_v4 *acceptor_ctx_create(const char *profile)
|
||||
struct acceptor_kni_v4 *acceptor_ctx_create(const char *profile, void *logger)
|
||||
{
|
||||
struct acceptor_kni_v4 *ctx = ALLOC(struct acceptor_kni_v4, 1);
|
||||
|
||||
@@ -66,13 +67,13 @@ struct acceptor_kni_v4 *acceptor_ctx_create(const char *profile)
|
||||
CPU_SET(cpu_id, &ctx->coremask);
|
||||
}
|
||||
|
||||
ctx->io = packet_io_create(profile, ctx->nr_worker_threads, &ctx->coremask);
|
||||
ctx->io = packet_io_create(profile, ctx->nr_worker_threads, &ctx->coremask, logger);
|
||||
if (ctx->io == NULL)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
ctx->packet_io_fs = packet_io_fs_create();
|
||||
ctx->packet_io_fs = packet_io_fs_create(profile);
|
||||
if (ctx->packet_io_fs == NULL)
|
||||
{
|
||||
goto error_out;
|
||||
@@ -81,7 +82,7 @@ struct acceptor_kni_v4 *acceptor_ctx_create(const char *profile)
|
||||
return ctx;
|
||||
|
||||
error_out:
|
||||
acceptor_ctx_destory(ctx);
|
||||
acceptor_kni_v4_destroy(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -89,18 +90,19 @@ static void *worker_thread_cycle(void *arg)
|
||||
{
|
||||
struct packet_io_thread_ctx *thread_ctx = (struct packet_io_thread_ctx *)arg;
|
||||
struct packet_io *handle = thread_ctx->ref_io;
|
||||
void * logger = thread_ctx->logger;
|
||||
|
||||
int pkg_len = 0;
|
||||
char thread_name[16];
|
||||
char thread_name[32];
|
||||
int n_pkt_recv_from_nf = 0;
|
||||
int n_pkt_recv_from_tap = 0;
|
||||
int n_pkt_recv_from_tap_c = 0;
|
||||
int n_pkt_recv_from_tap_s = 0;
|
||||
|
||||
snprintf(thread_name, sizeof(thread_name), "kni:worker-%d", thread_ctx->thread_index);
|
||||
snprintf(thread_name, sizeof(thread_name), "packet-io:worker-%d", thread_ctx->thread_index);
|
||||
prctl(PR_SET_NAME, (unsigned long long)thread_name, NULL, NULL, NULL);
|
||||
|
||||
if (packet_io_thread_init(handle, thread_ctx) != 0)
|
||||
if (packet_io_thread_init(handle, thread_ctx, logger) != 0)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
@@ -115,7 +117,7 @@ static void *worker_thread_cycle(void *arg)
|
||||
thread_ctx->tap_ctx->buff = ALLOC(char, thread_ctx->tap_ctx->buff_size);
|
||||
}
|
||||
|
||||
TFE_LOG_INFO(g_default_logger, "%s: worker thread %d is running", "LOG_TAG_KNI", thread_ctx->thread_index);
|
||||
TFE_LOG_INFO(logger, "%s: worker thread %d is running", "LOG_TAG_KNI", thread_ctx->thread_index);
|
||||
|
||||
while(1) {
|
||||
n_pkt_recv_from_nf = packet_io_polling_nf_interface(handle, thread_ctx->thread_index, thread_ctx);
|
||||
@@ -125,22 +127,21 @@ static void *worker_thread_cycle(void *arg)
|
||||
n_pkt_recv_from_tap_s = io_uring_peek_ready_entrys(thread_ctx->tap_ctx->io_uring_s);
|
||||
}
|
||||
else {
|
||||
if ((pkg_len = tfe_tap_read_per_thread(thread_ctx->tap_ctx->tap_fd, thread_ctx->tap_ctx->buff, thread_ctx->tap_ctx->buff_size, g_default_logger)) > 0)
|
||||
if ((pkg_len = tap_read(thread_ctx->tap_ctx->tap_fd, thread_ctx->tap_ctx->buff, thread_ctx->tap_ctx->buff_size, logger)) > 0)
|
||||
{
|
||||
handle_raw_packet_from_tap(thread_ctx->tap_ctx->buff, pkg_len, thread_ctx);
|
||||
}
|
||||
|
||||
if ((pkg_len = tfe_tap_read_per_thread(thread_ctx->tap_ctx->tap_c, thread_ctx->tap_ctx->buff, thread_ctx->tap_ctx->buff_size, g_default_logger)) > 0)
|
||||
if ((pkg_len = tap_read(thread_ctx->tap_ctx->tap_c, thread_ctx->tap_ctx->buff, thread_ctx->tap_ctx->buff_size, logger)) > 0)
|
||||
{
|
||||
handle_decryption_packet_from_tap(thread_ctx->tap_ctx->buff, pkg_len, thread_ctx);
|
||||
}
|
||||
|
||||
if ((pkg_len = tfe_tap_read_per_thread(thread_ctx->tap_ctx->tap_s, thread_ctx->tap_ctx->buff, thread_ctx->tap_ctx->buff_size, g_default_logger)) > 0)
|
||||
if ((pkg_len = tap_read(thread_ctx->tap_ctx->tap_s, thread_ctx->tap_ctx->buff, thread_ctx->tap_ctx->buff_size, logger)) > 0)
|
||||
{
|
||||
handle_decryption_packet_from_tap(thread_ctx->tap_ctx->buff, pkg_len, thread_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (n_pkt_recv_from_nf == 0 && n_pkt_recv_from_tap == 0 && n_pkt_recv_from_tap_c == 0 && n_pkt_recv_from_tap_s == 0)
|
||||
{
|
||||
@@ -155,25 +156,18 @@ static void *worker_thread_cycle(void *arg)
|
||||
}
|
||||
|
||||
error_out:
|
||||
TFE_LOG_ERROR(g_default_logger, "%s: worker thread %d exiting", LOG_TAG_SCE, thread_ctx->thread_index);
|
||||
TFE_LOG_ERROR(logger, "%s: worker thread %d exiting", LOG_TAG_SCE, thread_ctx->thread_index);
|
||||
return (void *)NULL;
|
||||
}
|
||||
|
||||
void acceptor_kni_v4_destroy(struct acceptor_kni_v4 *ctx)
|
||||
struct acceptor_kni_v4 *acceptor_kni_v4_create(struct tfe_proxy *proxy, const char *profile)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
packet_io_destory(ctx->io);
|
||||
void *packet_io_logger = NULL;
|
||||
packet_io_logger = MESA_create_runtime_log_handle("packet_io", RLOG_LV_DEBUG);
|
||||
assert(packet_io_logger != NULL);
|
||||
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
struct acceptor_kni_v4 *acceptor_kni_v4_create(struct tfe_proxy *proxy, const char *profile, void *logger)
|
||||
{
|
||||
struct acceptor_kni_v4 *acceptor_ctx = acceptor_ctx_create(profile);
|
||||
g_packet_io_logger = packet_io_logger;
|
||||
struct acceptor_kni_v4 *acceptor_ctx = acceptor_ctx_create(profile, packet_io_logger);
|
||||
if (acceptor_ctx == NULL)
|
||||
goto error_out;
|
||||
|
||||
@@ -181,6 +175,7 @@ struct acceptor_kni_v4 *acceptor_kni_v4_create(struct tfe_proxy *proxy, const ch
|
||||
for (int i = 0; i < acceptor_ctx->nr_worker_threads; i++) {
|
||||
acceptor_ctx->work_threads[i].tid = 0;
|
||||
acceptor_ctx->work_threads[i].thread_index = i;
|
||||
acceptor_ctx->work_threads[i].ref_io = acceptor_ctx->io;
|
||||
acceptor_ctx->work_threads[i].ref_acceptor_ctx = acceptor_ctx;
|
||||
|
||||
acceptor_ctx->work_threads[i].tap_ctx = tfe_tap_ctx_create(&acceptor_ctx->work_threads[i]);
|
||||
@@ -188,10 +183,9 @@ struct acceptor_kni_v4 *acceptor_kni_v4_create(struct tfe_proxy *proxy, const ch
|
||||
goto error_out;
|
||||
|
||||
acceptor_ctx->work_threads[i].session_table = session_table_create();
|
||||
acceptor_ctx->work_threads[i].ref_io = acceptor_ctx->io;
|
||||
acceptor_ctx->work_threads[i].ref_proxy = proxy;
|
||||
acceptor_ctx->work_threads[i].ret_fs_state = acceptor_ctx->packet_io_fs;
|
||||
acceptor_ctx->work_threads[i].ref_acceptor_ctx = acceptor_ctx;
|
||||
acceptor_ctx->work_threads[i].logger = packet_io_logger;
|
||||
acceptor_ctx->work_threads[i].session_table_need_reset = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user