From 7973d81b694bac7845354f6041f4e48ab30f2ee1 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Fri, 3 Oct 2025 10:18:25 +0800 Subject: [PATCH] struct fast_task_info add fields: is_client and op_type for io_uring --- .gitignore | 1 + make.sh | 10 ++++++++++ src/fast_task_queue.h | 13 +++++++++++-- src/fast_timer.h | 3 --- src/ioevent.h | 1 + src/ioevent_loop.c | 4 ++++ src/ioevent_loop.h | 1 + src/tests/{Makefile => Makefile.in} | 4 ++-- 8 files changed, 30 insertions(+), 7 deletions(-) rename src/tests/{Makefile => Makefile.in} (93%) diff --git a/.gitignore b/.gitignore index d0a20d0..e2a0726 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Makefile.in src/Makefile +src/tests/Makefile # Prerequisites *.d diff --git a/make.sh b/make.sh index 47e1553..d65518c 100755 --- a/make.sh +++ b/make.sh @@ -119,6 +119,7 @@ if [ "$uname" = "Linux" ]; then out=$(grep -F IORING_OP_SEND_ZC /usr/include/liburing/io_uring.h) if [ -n "$out" ]; then IOEVENT_USE=IOEVENT_USE_URING + LIBS="$LIBS -luring" else IOEVENT_USE=IOEVENT_USE_EPOLL fi @@ -276,3 +277,12 @@ make $1 $2 $3 if [ "$1" = "clean" ]; then /bin/rm -f Makefile _os_define.h fi + +cd tests +cp Makefile.in Makefile +sed_replace "s#\\\$(CC)#gcc#g" Makefile +sed_replace "s#\\\$(INCS)#$INCS#g" Makefile +sed_replace "s#\\\$(LIBS)#$LIBS#g" Makefile +if [ "$1" = "clean" ]; then + /bin/rm -f Makefile +fi diff --git a/src/fast_task_queue.h b/src/fast_task_queue.h index f5b5281..f9e58c2 100644 --- a/src/fast_task_queue.h +++ b/src/fast_task_queue.h @@ -49,7 +49,8 @@ struct sf_network_handler; struct fast_task_info; #if IOEVENT_USE_URING -#define FC_URING_OP_TYPE(task) (task)->event.timer.op_type +#define FC_URING_OP_TYPE(task) (task)->uring.op_type +#define FC_URING_IS_CLIENT(task) (task)->uring.is_client #endif typedef struct ioevent_entry @@ -126,12 +127,20 @@ struct fast_task_info struct fast_net_buffer_wrapper recv; //recv buffer uint16_t port; //peer port + +#if IOEVENT_USE_URING + struct { + int8_t is_client; + uint8_t op_type; + } uring; //since v1.0.81 +#endif + struct { uint8_t current; volatile uint8_t notify; } nio_stages; //stages for network IO - volatile int8_t reffer_count; volatile int8_t canceled; //if task canceled + volatile int reffer_count; int pending_send_count; int64_t req_count; //request count struct { diff --git a/src/fast_timer.h b/src/fast_timer.h index 8727878..e7ee7c5 100644 --- a/src/fast_timer.h +++ b/src/fast_timer.h @@ -27,9 +27,6 @@ typedef struct fast_timer_entry { struct fast_timer_entry *next; int slot_index; bool rehash; -#if IOEVENT_USE_URING - short op_type; -#endif } FastTimerEntry; typedef struct fast_timer_slot { diff --git a/src/ioevent.h b/src/ioevent.h index 3c70629..37741f8 100644 --- a/src/ioevent.h +++ b/src/ioevent.h @@ -33,6 +33,7 @@ #define IOEVENT_ERROR (EPOLLERR | EPOLLPRI | EPOLLHUP) #elif IOEVENT_USE_URING +#include #include #define IOEVENT_READ POLLIN #define IOEVENT_WRITE POLLOUT diff --git a/src/ioevent_loop.c b/src/ioevent_loop.c index 654c03c..3695cad 100644 --- a/src/ioevent_loop.c +++ b/src/ioevent_loop.c @@ -286,6 +286,10 @@ int ioevent_set(struct fast_task_info *task, struct nio_thread_data *pThread, __LINE__, sock, result, STRERROR(result)); return result; } + } else { + logInfo("file: "__FILE__", line: %d, " + "skip uring_prep_recv, fd: %d, port: %d, in progress op type: %d, timeout: %"PRId64, + __LINE__, sock, task->port, FC_URING_OP_TYPE(task), task->event.timer.expires); } } else { #endif diff --git a/src/ioevent_loop.h b/src/ioevent_loop.h index 79b6a8a..c8377d1 100644 --- a/src/ioevent_loop.h +++ b/src/ioevent_loop.h @@ -23,6 +23,7 @@ #define fc_hold_task_ex(task, inc_count) __sync_add_and_fetch( \ &task->reffer_count, inc_count) + #define fc_hold_task(task) fc_hold_task_ex(task, 1) #ifdef __cplusplus diff --git a/src/tests/Makefile b/src/tests/Makefile.in similarity index 93% rename from src/tests/Makefile rename to src/tests/Makefile.in index 3ea0d10..669659d 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile.in @@ -1,8 +1,8 @@ .SUFFIXES: .c .o COMPILE = $(CC) -g -O3 -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -DDEBUG_FLAG -INC_PATH = -I/usr/local/include -LIB_PATH = -lfastcommon -lpthread +INC_PATH = $(INCS) +LIB_PATH = -lfastcommon $(LIBS) ALL_PRGS = test_allocator test_skiplist test_multi_skiplist test_mblock test_blocked_queue \ test_id_generator test_ini_parser test_char_convert test_char_convert_loader \