move use_io_uring and use_send_zc to struct sf_context

master
YuQing 2025-11-04 15:40:00 +08:00
parent 688211fbcd
commit fa32972052
6 changed files with 74 additions and 113 deletions

View File

@ -217,7 +217,9 @@ int idempotency_client_channel_check_reconnect(
char formatted_ip[FORMATTED_IP_SIZE]; char formatted_ip[FORMATTED_IP_SIZE];
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (FC_ATOMIC_GET(channel->task->reffer_count) > 1) { struct fast_task_info *task;
task = channel->task;
if (SF_CTX->use_io_uring && FC_ATOMIC_GET(task->reffer_count) > 1) {
return 0; return 0;
} }
#endif #endif

View File

@ -47,8 +47,12 @@ SFGlobalVariables g_sf_global_vars = {
{0, 0}, NULL, {NULL, 0} {0, 0}, NULL, {NULL, 0}
}; };
SFContext g_sf_context = {{'\0'}, NULL, 0, false, sf_address_family_auto, SFContext g_sf_context = {{'\0'}, NULL, 0, false,
{{AF_UNSPEC, {{true, fc_comm_type_sock}, {false, fc_comm_type_rdma}}}, #if IOEVENT_USE_URING
false, false,
#endif
sf_address_family_auto, {{AF_UNSPEC, {{true, fc_comm_type_sock},
{false, fc_comm_type_rdma}}},
{AF_UNSPEC, {{true, fc_comm_type_sock}, {false, fc_comm_type_rdma}}}}, {AF_UNSPEC, {{true, fc_comm_type_sock}, {false, fc_comm_type_rdma}}}},
{DEFAULT_MAX_CONNECTONS, SF_DEF_MAX_PACKAGE_SIZE, SF_DEF_MIN_BUFF_SIZE, {DEFAULT_MAX_CONNECTONS, SF_DEF_MAX_PACKAGE_SIZE, SF_DEF_MIN_BUFF_SIZE,
SF_DEF_MAX_BUFF_SIZE}, 1, DEFAULT_WORK_THREADS, 0, true, true, SF_DEF_MAX_BUFF_SIZE}, 1, DEFAULT_WORK_THREADS, 0, true, true,
@ -477,8 +481,7 @@ static int load_rdma_apis(SFContext *sf_context, SFNetworkHandler *handler)
} }
static int init_network_handler(SFContext *sf_context, static int init_network_handler(SFContext *sf_context,
SFNetworkHandler *handler, SFAddressFamilyHandler *fh, SFNetworkHandler *handler, SFAddressFamilyHandler *fh)
const bool use_send_zc)
{ {
handler->fh = fh; handler->fh = fh;
handler->inner.handler = handler; handler->inner.handler = handler;
@ -499,18 +502,10 @@ static int init_network_handler(SFContext *sf_context,
handler->send_data = sf_socket_send_data; handler->send_data = sf_socket_send_data;
handler->recv_data = sf_socket_recv_data; handler->recv_data = sf_socket_recv_data;
handler->post_recv = NULL; handler->post_recv = NULL;
#if IOEVENT_USE_URING
handler->use_io_uring = true;
handler->use_send_zc = use_send_zc;
#else
handler->use_io_uring = false;
handler->use_send_zc = false;
#endif
return 0; return 0;
} else { } else {
handler->inner.id = NULL; handler->inner.id = NULL;
handler->outer.id = NULL; handler->outer.id = NULL;
handler->use_io_uring = false;
return load_rdma_apis(sf_context, handler); return load_rdma_apis(sf_context, handler);
} }
} }
@ -748,9 +743,7 @@ int sf_load_context_from_config_ex(SFContext *sf_context,
if (!handler->enabled) { if (!handler->enabled) {
continue; continue;
} }
if ((result=init_network_handler(sf_context, handler, if ((result=init_network_handler(sf_context, handler, fh)) != 0) {
fh, use_send_zc)) != 0)
{
return result; return result;
} }
} }
@ -769,9 +762,13 @@ int sf_load_context_from_config_ex(SFContext *sf_context,
rdma_handler->inner.enabled = sock_handler->inner.enabled; rdma_handler->inner.enabled = sock_handler->inner.enabled;
rdma_handler->outer.port = sock_handler->outer.port; rdma_handler->outer.port = sock_handler->outer.port;
rdma_handler->outer.enabled = sock_handler->outer.enabled; rdma_handler->outer.enabled = sock_handler->outer.enabled;
} }
#if IOEVENT_USE_URING
sf_context->use_io_uring = (config->comm_type == fc_comm_type_sock);
sf_context->use_send_zc = use_send_zc;
#endif
sf_context->accept_threads = iniGetIntValue( sf_context->accept_threads = iniGetIntValue(
config->ini_ctx.section_name, config->ini_ctx.section_name,
"accept_threads", config->ini_ctx.context, 1); "accept_threads", config->ini_ctx.context, 1);
@ -907,31 +904,6 @@ static const char *get_address_family_caption(
} }
} }
#if IOEVENT_USE_URING
static void get_io_uring_configs(const SFContext *sf_context,
bool *use_io_uring, bool *use_send_zc)
{
int i;
const SFAddressFamilyHandler *fh;
const SFNetworkHandler *handler;
const SFNetworkHandler *end;
*use_io_uring = false;
*use_send_zc = false;
for (i=0; i<SF_ADDRESS_FAMILY_COUNT; i++) {
fh = sf_context->handlers + i;
end = fh->handlers + SF_NETWORK_HANDLER_COUNT;
for (handler=fh->handlers; handler<end; handler++) {
if (handler->enabled && handler->use_io_uring) {
*use_io_uring = true;
*use_send_zc = handler->use_send_zc;
return;
}
}
}
}
#endif
void sf_context_config_to_string(const SFContext *sf_context, void sf_context_config_to_string(const SFContext *sf_context,
char *output, const int size) char *output, const int size)
{ {
@ -941,10 +913,6 @@ void sf_context_config_to_string(const SFContext *sf_context,
char outer_bind_addr[2 * IP_ADDRESS_SIZE + 2]; char outer_bind_addr[2 * IP_ADDRESS_SIZE + 2];
int i; int i;
int len; int len;
#if IOEVENT_USE_URING
bool use_io_uring;
bool use_send_zc;
#endif
*inner_bind_addr = '\0'; *inner_bind_addr = '\0';
*outer_bind_addr = '\0'; *outer_bind_addr = '\0';
@ -987,9 +955,9 @@ void sf_context_config_to_string(const SFContext *sf_context,
sf_context->accept_threads, sf_context->work_threads); sf_context->accept_threads, sf_context->work_threads);
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
get_io_uring_configs(sf_context, &use_io_uring, &use_send_zc); len += snprintf(output + len, size - len, ", use_io_uring=%d, "
len += snprintf(output + len, size - len, ", use_io_uring=%d" "use_send_zc=%d", sf_context->use_io_uring,
", use_send_zc=%d", use_io_uring, use_send_zc); sf_context->use_send_zc);
#endif #endif
} }
@ -1040,10 +1008,6 @@ void sf_global_config_to_string_ex(const char *max_pkg_size_item_nm,
int max_pkg_size; int max_pkg_size;
int min_buff_size; int min_buff_size;
int max_buff_size; int max_buff_size;
#if IOEVENT_USE_URING
bool use_io_uring;
bool use_send_zc;
#endif
char pkg_buff[256]; char pkg_buff[256];
max_pkg_size = g_sf_global_vars.net_buffer_cfg.max_pkg_size - max_pkg_size = g_sf_global_vars.net_buffer_cfg.max_pkg_size -
@ -1073,10 +1037,9 @@ void sf_global_config_to_string_ex(const char *max_pkg_size_item_nm,
g_sf_global_vars.thread_stack_size / 1024, pkg_buff); g_sf_global_vars.thread_stack_size / 1024, pkg_buff);
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
get_io_uring_configs(&g_sf_context, &use_io_uring, &use_send_zc); len += snprintf(output + len, size - len, "use_io_uring=%d, "
len += snprintf(output + len, size - len, "use_send_zc=%d, ", g_sf_context.use_io_uring,
"use_io_uring=%d, use_send_zc=%d, ", g_sf_context.use_send_zc);
use_io_uring, use_send_zc);
#endif #endif
len += snprintf(output + len, size - len, len += snprintf(output + len, size - len,

View File

@ -73,12 +73,8 @@ static int sf_uring_cancel_done(int sock, const int event, void *arg)
task = (struct fast_task_info *)arg; task = (struct fast_task_info *)arg;
if (event != IOEVENT_TIMEOUT) { if (event != IOEVENT_TIMEOUT) {
if (task->handler->use_io_uring || (FC_URING_OP_TYPE(task) !=
IORING_OP_NOP && task->event.res == -ECANCELED))
{
CLEAR_OP_TYPE_AND_RELEASE_TASK(task); CLEAR_OP_TYPE_AND_RELEASE_TASK(task);
} }
}
return 0; return 0;
} }
#endif #endif
@ -86,18 +82,16 @@ static int sf_uring_cancel_done(int sock, const int event, void *arg)
void sf_task_detach_thread(struct fast_task_info *task) void sf_task_detach_thread(struct fast_task_info *task)
{ {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
bool need_cancel; if (SF_CTX->use_io_uring) {
if (task->handler->use_io_uring) { if (FC_URING_OP_TYPE(task) != IORING_OP_NOP) {
need_cancel = (FC_URING_OP_TYPE(task) != IORING_OP_NOP);
} else {
need_cancel = true;
}
if (need_cancel) {
task->event.callback = (IOEventCallback)sf_uring_cancel_done; task->event.callback = (IOEventCallback)sf_uring_cancel_done;
uring_prep_cancel(task); uring_prep_cancel(task);
} }
#else } else {
#endif
ioevent_detach(&task->thread_data->ev_puller, task->event.fd); ioevent_detach(&task->thread_data->ev_puller, task->event.fd);
#if IOEVENT_USE_URING
}
#endif #endif
if (task->event.timer.expires > 0) { if (task->event.timer.expires > 0) {
@ -128,7 +122,7 @@ static inline void release_iovec_buffer(struct fast_task_info *task)
void sf_socket_close_connection(struct fast_task_info *task) void sf_socket_close_connection(struct fast_task_info *task)
{ {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
if (uring_prep_close_fd(task) != 0) { if (uring_prep_close_fd(task) != 0) {
close(task->event.fd); close(task->event.fd);
} }
@ -152,7 +146,7 @@ void sf_task_finish_clean_up(struct fast_task_info *task)
sf_task_detach_thread(task); sf_task_detach_thread(task);
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (!task->handler->use_io_uring) { if (!SF_CTX->use_io_uring) {
#endif #endif
task->handler->close_connection(task); task->handler->close_connection(task);
__sync_fetch_and_sub(&g_sf_global_vars. __sync_fetch_and_sub(&g_sf_global_vars.
@ -225,7 +219,7 @@ static inline int set_read_event(struct fast_task_info *task)
int result; int result;
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
if (FC_URING_OP_TYPE(task) != IORING_OP_NOP) { if (FC_URING_OP_TYPE(task) != IORING_OP_NOP) {
if (FC_URING_OP_TYPE(task) == IORING_OP_RECV) { if (FC_URING_OP_TYPE(task) == IORING_OP_RECV) {
logWarning("file: "__FILE__", line: %d, " logWarning("file: "__FILE__", line: %d, "
@ -276,7 +270,7 @@ static inline int set_read_event(struct fast_task_info *task)
int sf_set_read_event(struct fast_task_info *task) int sf_set_read_event(struct fast_task_info *task)
{ {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
return 0; return 0;
} }
#endif #endif
@ -295,8 +289,7 @@ static inline int sf_ioevent_add(struct fast_task_info *task)
result = ioevent_set(task, task->thread_data, task->event.fd, result = ioevent_set(task, task->thread_data, task->event.fd,
IOEVENT_READ, (IOEventCallback)sf_client_sock_read, IOEVENT_READ, (IOEventCallback)sf_client_sock_read,
SF_CTX->net_buffer_cfg.network_timeout, SF_CTX->net_buffer_cfg.network_timeout);
task->handler->use_io_uring);
return result > 0 ? -1 * result : result; return result > 0 ? -1 * result : result;
} }
@ -338,7 +331,7 @@ static int sf_client_connect_done(int sock, const int event, void *arg)
task = (struct fast_task_info *)arg; task = (struct fast_task_info *)arg;
if (task->canceled) { if (task->canceled) {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring && event != IOEVENT_TIMEOUT) { if (SF_CTX->use_io_uring && event != IOEVENT_TIMEOUT) {
CLEAR_OP_TYPE_AND_RELEASE_TASK(task); CLEAR_OP_TYPE_AND_RELEASE_TASK(task);
} }
#endif #endif
@ -349,7 +342,7 @@ static int sf_client_connect_done(int sock, const int event, void *arg)
result = ETIMEDOUT; result = ETIMEDOUT;
} else { } else {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
CLEAR_OP_TYPE_AND_RELEASE_TASK(task); CLEAR_OP_TYPE_AND_RELEASE_TASK(task);
result = (task->event.res < 0 ? -1 * task->event.res : result = (task->event.res < 0 ? -1 * task->event.res :
task->event.res); task->event.res);
@ -394,7 +387,7 @@ int sf_socket_async_connect_server(struct fast_task_info *task)
int result; int result;
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
if ((result=uring_prep_connect(task)) != 0) { if ((result=uring_prep_connect(task)) != 0) {
return result; return result;
} }
@ -423,7 +416,7 @@ static int sf_async_connect_server(struct fast_task_info *task)
result = ioevent_set(task, task->thread_data, task->event.fd, result = ioevent_set(task, task->thread_data, task->event.fd,
IOEVENT_READ | IOEVENT_WRITE, (IOEventCallback) IOEVENT_READ | IOEVENT_WRITE, (IOEventCallback)
sf_client_connect_done, SF_CTX->net_buffer_cfg. sf_client_connect_done, SF_CTX->net_buffer_cfg.
connect_timeout, task->handler->use_io_uring); connect_timeout);
return result > 0 ? -1 * result : result; return result > 0 ? -1 * result : result;
} else { } else {
if (SF_CTX->callbacks.connect_done != NULL) { if (SF_CTX->callbacks.connect_done != NULL) {
@ -472,7 +465,7 @@ static int sf_nio_deal_task(struct fast_task_info *task, const int stage)
case SF_NIO_STAGE_RECV: case SF_NIO_STAGE_RECV:
task->nio_stages.current = SF_NIO_STAGE_RECV; task->nio_stages.current = SF_NIO_STAGE_RECV;
if ((result=set_read_event(task)) == 0) { if ((result=set_read_event(task)) == 0) {
if (!task->handler->use_io_uring) { if (!SF_CTX->use_io_uring) {
if (sf_client_sock_read(task->event.fd, if (sf_client_sock_read(task->event.fd,
IOEVENT_READ, task) < 0) IOEVENT_READ, task) < 0)
{ {
@ -655,11 +648,11 @@ int sf_send_add_event(struct fast_task_info *task)
/* direct send */ /* direct send */
task->nio_stages.current = SF_NIO_STAGE_SEND; task->nio_stages.current = SF_NIO_STAGE_SEND;
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
if (task->event.callback != (IOEventCallback)sf_client_sock_write) { if (task->event.callback != (IOEventCallback)sf_client_sock_write) {
task->event.callback = (IOEventCallback)sf_client_sock_write; task->event.callback = (IOEventCallback)sf_client_sock_write;
} }
if (task->handler->use_send_zc) { if (SF_CTX->use_send_zc) {
return uring_prep_first_send_zc(task); return uring_prep_first_send_zc(task);
} else { } else {
return uring_prep_first_send(task); return uring_prep_first_send(task);
@ -699,7 +692,7 @@ static inline int check_task(struct fast_task_info *task,
} }
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
logWarning("file: "__FILE__", line: %d, " logWarning("file: "__FILE__", line: %d, "
"client ip: %s, event: %d, expect stage: %d, " "client ip: %s, event: %d, expect stage: %d, "
"but current stage: %d, close connection", "but current stage: %d, close connection",
@ -729,7 +722,7 @@ static inline int check_task(struct fast_task_info *task,
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
static inline int prepare_next_send(struct fast_task_info *task) static inline int prepare_next_send(struct fast_task_info *task)
{ {
if (task->handler->use_send_zc) { if (SF_CTX->use_send_zc) {
return uring_prep_next_send_zc(task); return uring_prep_next_send_zc(task);
} else { } else {
return uring_prep_next_send(task); return uring_prep_next_send(task);
@ -744,7 +737,7 @@ ssize_t sf_socket_send_data(struct fast_task_info *task,
int result; int result;
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
bytes = task->event.res; bytes = task->event.res;
} else { } else {
#endif #endif
@ -762,7 +755,7 @@ ssize_t sf_socket_send_data(struct fast_task_info *task,
if (bytes < 0) { if (bytes < 0) {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
result = -bytes; result = -bytes;
} else { } else {
#endif #endif
@ -772,7 +765,7 @@ ssize_t sf_socket_send_data(struct fast_task_info *task,
#endif #endif
if (result == EAGAIN || result == EWOULDBLOCK) { if (result == EAGAIN || result == EWOULDBLOCK) {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
if (prepare_next_send(task) != 0) { if (prepare_next_send(task) != 0) {
return -1; return -1;
} }
@ -787,7 +780,7 @@ ssize_t sf_socket_send_data(struct fast_task_info *task,
*action = sf_comm_action_break; *action = sf_comm_action_break;
return 0; return 0;
} else if (result == EINTR && !task->handler->use_io_uring) { } else if (result == EINTR && !SF_CTX->use_io_uring) {
/* should try again */ /* should try again */
logDebug("file: "__FILE__", line: %d, " logDebug("file: "__FILE__", line: %d, "
"client ip: %s, ignore interupt signal", "client ip: %s, ignore interupt signal",
@ -814,8 +807,8 @@ ssize_t sf_socket_send_data(struct fast_task_info *task,
task->send.ptr->offset += bytes; task->send.ptr->offset += bytes;
if (task->send.ptr->offset >= task->send.ptr->length) { if (task->send.ptr->offset >= task->send.ptr->length) {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (FC_URING_IS_SEND_ZC(task) && task->thread_data-> if (SF_CTX->use_io_uring && FC_URING_IS_SEND_ZC(task) &&
ev_puller.send_zc_done_notify) task->thread_data->ev_puller.send_zc_done_notify)
{ {
*action = sf_comm_action_break; *action = sf_comm_action_break;
*send_done = false; *send_done = false;
@ -863,7 +856,7 @@ ssize_t sf_socket_send_data(struct fast_task_info *task,
} }
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
if (!(FC_URING_IS_SEND_ZC(task) && task->thread_data-> if (!(FC_URING_IS_SEND_ZC(task) && task->thread_data->
ev_puller.send_zc_done_notify)) ev_puller.send_zc_done_notify))
{ {
@ -894,7 +887,7 @@ ssize_t sf_socket_recv_data(struct fast_task_info *task,
bool new_alloc; bool new_alloc;
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
bytes = task->event.res; bytes = task->event.res;
} else { } else {
#endif #endif
@ -919,7 +912,7 @@ ssize_t sf_socket_recv_data(struct fast_task_info *task,
if (bytes < 0) { if (bytes < 0) {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
result = -bytes; result = -bytes;
} else { } else {
#endif #endif
@ -929,7 +922,7 @@ ssize_t sf_socket_recv_data(struct fast_task_info *task,
#endif #endif
if (result == EAGAIN || result == EWOULDBLOCK) { if (result == EAGAIN || result == EWOULDBLOCK) {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
if (prepare_next_recv(task) != 0) { if (prepare_next_recv(task) != 0) {
return -1; return -1;
} }
@ -937,7 +930,7 @@ ssize_t sf_socket_recv_data(struct fast_task_info *task,
#endif #endif
*action = sf_comm_action_break; *action = sf_comm_action_break;
return 0; return 0;
} else if (result == EINTR && !task->handler->use_io_uring) { } else if (result == EINTR && !SF_CTX->use_io_uring) {
/* should try again */ /* should try again */
logDebug("file: "__FILE__", line: %d, " logDebug("file: "__FILE__", line: %d, "
"client ip: %s, ignore interupt signal", "client ip: %s, ignore interupt signal",
@ -982,7 +975,7 @@ ssize_t sf_socket_recv_data(struct fast_task_info *task,
if (task->recv.ptr->length == 0) { //pkg header if (task->recv.ptr->length == 0) { //pkg header
if (task->recv.ptr->offset < SF_CTX->header_size) { if (task->recv.ptr->offset < SF_CTX->header_size) {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
if (prepare_next_recv(task) != 0) { if (prepare_next_recv(task) != 0) {
return -1; return -1;
} }
@ -1046,7 +1039,7 @@ ssize_t sf_socket_recv_data(struct fast_task_info *task,
*action = sf_comm_action_finish; *action = sf_comm_action_finish;
} else { } else {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
if (prepare_next_recv(task) != 0) { if (prepare_next_recv(task) != 0) {
return -1; return -1;
} }
@ -1205,7 +1198,7 @@ static int sf_client_sock_read(int sock, const int event, void *arg)
task = (struct fast_task_info *)arg; task = (struct fast_task_info *)arg;
if ((result=check_task(task, event, SF_NIO_STAGE_RECV)) != 0) { if ((result=check_task(task, event, SF_NIO_STAGE_RECV)) != 0) {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring && event != IOEVENT_TIMEOUT) { if (SF_CTX->use_io_uring && event != IOEVENT_TIMEOUT) {
CLEAR_OP_TYPE_AND_RELEASE_TASK(task); CLEAR_OP_TYPE_AND_RELEASE_TASK(task);
} }
#endif #endif
@ -1245,7 +1238,7 @@ static int sf_client_sock_read(int sock, const int event, void *arg)
} }
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
CLEAR_OP_TYPE_AND_RELEASE_TASK(task); CLEAR_OP_TYPE_AND_RELEASE_TASK(task);
} }
#endif #endif
@ -1320,7 +1313,7 @@ static int sock_write_done(struct fast_task_info *task,
} }
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (!task->handler->use_io_uring || task->nio_stages. if (!SF_CTX->use_io_uring || task->nio_stages.
current == SF_NIO_STAGE_RECV) current == SF_NIO_STAGE_RECV)
{ {
#endif #endif
@ -1349,7 +1342,7 @@ static int sf_client_sock_write(int sock, const int event, void *arg)
task = (struct fast_task_info *)arg; task = (struct fast_task_info *)arg;
if ((result=check_task(task, event, SF_NIO_STAGE_SEND)) != 0) { if ((result=check_task(task, event, SF_NIO_STAGE_SEND)) != 0) {
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring && event != IOEVENT_TIMEOUT) { if (SF_CTX->use_io_uring && event != IOEVENT_TIMEOUT) {
if (event == IOEVENT_NOTIFY || !(FC_URING_IS_SEND_ZC(task) && if (event == IOEVENT_NOTIFY || !(FC_URING_IS_SEND_ZC(task) &&
task->thread_data->ev_puller.send_zc_done_notify)) task->thread_data->ev_puller.send_zc_done_notify))
{ {
@ -1398,7 +1391,7 @@ static int sf_client_sock_write(int sock, const int event, void *arg)
return result == 0 ? 0 : -1; return result == 0 ? 0 : -1;
} }
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
if (!(FC_URING_IS_SEND_ZC(task) && task->thread_data-> if (!(FC_URING_IS_SEND_ZC(task) && task->thread_data->
ev_puller.send_zc_done_notify)) ev_puller.send_zc_done_notify))
{ {

View File

@ -33,7 +33,6 @@
#include "fastcommon/sched_thread.h" #include "fastcommon/sched_thread.h"
#include "fastcommon/ioevent_loop.h" #include "fastcommon/ioevent_loop.h"
#include "fastcommon/fc_memory.h" #include "fastcommon/fc_memory.h"
#include "sf_nio.h"
#include "sf_proto.h" #include "sf_proto.h"
#include "sf_util.h" #include "sf_util.h"
#include "sf_service.h" #include "sf_service.h"
@ -242,8 +241,9 @@ int sf_service_init_ex2(SFContext *sf_context, const char *name,
thread_data->arg = NULL; thread_data->arg = NULL;
} }
if ((result=ioevent_init(&thread_data->ev_puller, sf_context->name, if ((result=ioevent_init(&thread_data->ev_puller, sf_context->
max_entries, net_timeout_ms, extra_events)) != 0) name, sf_context->use_io_uring, max_entries,
net_timeout_ms, extra_events)) != 0)
{ {
char prompt[256]; char prompt[256];
#if IOEVENT_USE_URING #if IOEVENT_USE_URING

View File

@ -27,6 +27,7 @@
#include "sf_types.h" #include "sf_types.h"
#include "sf_proto.h" #include "sf_proto.h"
#include "sf_global.h" #include "sf_global.h"
#include "sf_nio.h"
typedef void* (*sf_alloc_thread_extra_data_callback)(const int thread_index); typedef void* (*sf_alloc_thread_extra_data_callback)(const int thread_index);
typedef void (*sf_sig_quit_handler)(int sig); typedef void (*sf_sig_quit_handler)(int sig);
@ -225,7 +226,7 @@ static inline void sf_release_task(struct fast_task_info *task)
*/ */
#if IOEVENT_USE_URING #if IOEVENT_USE_URING
if (task->handler->use_io_uring) { if (SF_CTX->use_io_uring) {
task->handler->close_connection(task); task->handler->close_connection(task);
__sync_fetch_and_sub(&g_sf_global_vars. __sync_fetch_and_sub(&g_sf_global_vars.
connection_stat.current_count, 1); connection_stat.current_count, 1);

View File

@ -119,8 +119,6 @@ struct sf_address_family_handler;
typedef struct sf_network_handler { typedef struct sf_network_handler {
bool enabled; bool enabled;
bool explicit_post_recv; bool explicit_post_recv;
bool use_io_uring; //since v1.2.9
bool use_send_zc; //since v1.2.9
FCCommunicationType comm_type; FCCommunicationType comm_type;
struct sf_address_family_handler *fh; struct sf_address_family_handler *fh;
struct ibv_pd *pd; struct ibv_pd *pd;
@ -183,6 +181,10 @@ typedef struct sf_context {
volatile int thread_count; volatile int thread_count;
bool is_client; //since v1.2.5 bool is_client; //since v1.2.5
#if IOEVENT_USE_URING
bool use_io_uring; //since v1.2.9
bool use_send_zc; //since v1.2.9
#endif
SFAddressFamily address_family; SFAddressFamily address_family;
SFAddressFamilyHandler handlers[SF_ADDRESS_FAMILY_COUNT]; SFAddressFamilyHandler handlers[SF_ADDRESS_FAMILY_COUNT];