From 3ddef29a76ea8141d718b61c7248a579da4edfdb Mon Sep 17 00:00:00 2001 From: yan-mingzhen Date: Sat, 3 Aug 2024 16:01:16 +0800 Subject: [PATCH 01/33] fix: add fd dfx Signed-off-by: yan-mingzhen --- src/heap-inl.h | 11 +++++++++-- src/threadpool.c | 4 ++++ src/unix/signal.c | 35 +++++++++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/heap-inl.h b/src/heap-inl.h index 1e2ed60..cbe6a47 100644 --- a/src/heap-inl.h +++ b/src/heap-inl.h @@ -178,12 +178,19 @@ HEAP_EXPORT(void heap_remove(struct heap* heap, k -= 1; } - heap->nelts -= 1; - /* Unlink the max node. */ child = *max; *max = NULL; +#ifdef OHOS_USE_DFX + if (child == NULL) { + UV_LOGF("Child is NULL, this may be due to multi-threaded calls."); + return; + } +#endif + + heap->nelts -= 1; + if (child == node) { /* We're removing either the max or the last node in the tree. */ if (child == heap->min) { diff --git a/src/threadpool.c b/src/threadpool.c index 4a1ac04..3aefe7c 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -313,9 +313,13 @@ int is_uv_loop_good_magic(const uv_loop_t* loop) { void on_uv_loop_close(uv_loop_t* loop) { time_t t1, t2; time(&t1); + uv_start_trace(UV_TRACE_TAG, "Get Write Lock"); uv_rwlock_wrlock(&g_closed_uv_loop_rwlock); + uv_end_trace(UV_TRACE_TAG); loop->magic = ~UV_LOOP_MAGIC; + uv_start_trace(UV_TRACE_TAG, "Release Write Lock"); uv_rwlock_wrunlock(&g_closed_uv_loop_rwlock); + uv_end_trace(UV_TRACE_TAG); time(&t2); UV_LOGI("uv_loop(%{public}zu) closed in %{public}zds", (size_t)loop, (ssize_t)(t2 - t1)); } diff --git a/src/unix/signal.c b/src/unix/signal.c index bc4206e..ceaef6d 100644 --- a/src/unix/signal.c +++ b/src/unix/signal.c @@ -103,8 +103,15 @@ static void uv__signal_global_reinit(void) { if (uv__make_pipe(uv__signal_lock_pipefd, 0)) abort(); - if (uv__signal_unlock()) + if (uv__signal_unlock()) { +#ifdef OHOS_USE_DFX + UV_LOGF("errno is %d, uv__signal_lock_pipefd[1] is %d (%s:%s:%d)", + errno, uv__signal_lock_pipefd[1], __FILE__, __func__, __LINE__); + return; +#else abort(); +#endif + } } @@ -148,14 +155,27 @@ static void uv__signal_block_and_lock(sigset_t* saved_sigmask) { if (pthread_sigmask(SIG_SETMASK, &new_mask, saved_sigmask)) abort(); - if (uv__signal_lock()) + if (uv__signal_lock()) { +#ifdef OHOS_USE_DFX + UV_LOGF("errno is %d, uv__signal_lock_pipefd[0] is %d (%s:%s:%d)", + errno, uv__signal_lock_pipefd[0], __FILE__, __func__, __LINE__); + return; +#else abort(); +#endif + } } static void uv__signal_unlock_and_unblock(sigset_t* saved_sigmask) { - if (uv__signal_unlock()) + if (uv__signal_unlock()) { +#ifdef OHOS_USE_DFX + UV_LOGF("errno is %d, uv__signal_lock_pipefd[1] is %d (%s:%s:%d)", + errno, uv__signal_lock_pipefd[1], __FILE__, __func__, __LINE__); + return; +#else abort(); +#endif if (pthread_sigmask(SIG_SETMASK, saved_sigmask, NULL)) abort(); @@ -461,8 +481,15 @@ static void uv__signal_event(uv_loop_t* loop, } /* Other errors really should never happen. */ - if (r == -1) + if (r == -1) { +#ifdef OHOS_USE_DFX + UV_LOGF("errno is %d, loop->signal_pipefd[0] is %d (%s:%s:%d)", + errno, loop->signal_pipefd[0], __FILE__, __func__, __LINE__); + return; +#else abort(); +#endif + } bytes += r; -- Gitee From c846567c9f7f81580f8cde75970e325ce147fa01 Mon Sep 17 00:00:00 2001 From: yan-mingzhen Date: Sat, 3 Aug 2024 16:31:18 +0800 Subject: [PATCH 02/33] fix: fix typo Signed-off-by: yan-mingzhen --- src/unix/signal.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unix/signal.c b/src/unix/signal.c index ceaef6d..6b39f65 100644 --- a/src/unix/signal.c +++ b/src/unix/signal.c @@ -176,6 +176,7 @@ static void uv__signal_unlock_and_unblock(sigset_t* saved_sigmask) { #else abort(); #endif + } if (pthread_sigmask(SIG_SETMASK, saved_sigmask, NULL)) abort(); -- Gitee From 4ce248b133966f25a2f0cedfac91e32accf71bdd Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Mon, 5 Aug 2024 09:26:07 +0800 Subject: [PATCH 03/33] back heap_inl modify Signed-off-by: liaoxingxing --- src/heap-inl.h | 11 ++--------- src/unix/signal.c | 21 +++++++++------------ 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/heap-inl.h b/src/heap-inl.h index cbe6a47..939a523 100644 --- a/src/heap-inl.h +++ b/src/heap-inl.h @@ -177,20 +177,13 @@ HEAP_EXPORT(void heap_remove(struct heap* heap, path >>= 1; k -= 1; } + + heap->nelts -= 1; /* Unlink the max node. */ child = *max; *max = NULL; -#ifdef OHOS_USE_DFX - if (child == NULL) { - UV_LOGF("Child is NULL, this may be due to multi-threaded calls."); - return; - } -#endif - - heap->nelts -= 1; - if (child == node) { /* We're removing either the max or the last node in the tree. */ if (child == heap->min) { diff --git a/src/unix/signal.c b/src/unix/signal.c index 6b39f65..d69829b 100644 --- a/src/unix/signal.c +++ b/src/unix/signal.c @@ -20,6 +20,7 @@ #include "uv.h" #include "internal.h" +#include "uv_log.h" #include #include @@ -104,9 +105,8 @@ static void uv__signal_global_reinit(void) { abort(); if (uv__signal_unlock()) { -#ifdef OHOS_USE_DFX - UV_LOGF("errno is %d, uv__signal_lock_pipefd[1] is %d (%s:%s:%d)", - errno, uv__signal_lock_pipefd[1], __FILE__, __func__, __LINE__); +#ifdef USE_OHOS_DFX + UV_LOGF("errno is %{public}d, uv__signal_lock_pipefd[1] is %{public}d", errno, uv__signal_lock_pipefd[1]); return; #else abort(); @@ -156,9 +156,8 @@ static void uv__signal_block_and_lock(sigset_t* saved_sigmask) { abort(); if (uv__signal_lock()) { -#ifdef OHOS_USE_DFX - UV_LOGF("errno is %d, uv__signal_lock_pipefd[0] is %d (%s:%s:%d)", - errno, uv__signal_lock_pipefd[0], __FILE__, __func__, __LINE__); +#ifdef USE_OHOS_DFX + UV_LOGF("errno is %{public}d, uv__signal_lock_pipefd[0] is %{public}d", errno, uv__signal_lock_pipefd[0]); return; #else abort(); @@ -169,9 +168,8 @@ static void uv__signal_block_and_lock(sigset_t* saved_sigmask) { static void uv__signal_unlock_and_unblock(sigset_t* saved_sigmask) { if (uv__signal_unlock()) { -#ifdef OHOS_USE_DFX - UV_LOGF("errno is %d, uv__signal_lock_pipefd[1] is %d (%s:%s:%d)", - errno, uv__signal_lock_pipefd[1], __FILE__, __func__, __LINE__); +#ifdef USE_OHOS_DFX + UV_LOGF("errno is %{public}d, uv__signal_lock_pipefd[1] is %{public}d", errno, uv__signal_lock_pipefd[1]); return; #else abort(); @@ -483,9 +481,8 @@ static void uv__signal_event(uv_loop_t* loop, /* Other errors really should never happen. */ if (r == -1) { -#ifdef OHOS_USE_DFX - UV_LOGF("errno is %d, loop->signal_pipefd[0] is %d (%s:%s:%d)", - errno, loop->signal_pipefd[0], __FILE__, __func__, __LINE__); +#ifdef USE_OHOS_DFX + UV_LOGF("errno is %{public}d, loop->signal_pipefd[0] is %{public}d", errno, loop->signal_pipefd[0]); return; #else abort(); -- Gitee From 97421f38f4f5d5803559d6cf78f2e65d0b49ef6b Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Thu, 8 Aug 2024 09:19:30 +0800 Subject: [PATCH 04/33] remove rwlock in uv__work_done Signed-off-by: liaoxingxing --- src/threadpool.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/threadpool.c b/src/threadpool.c index 3aefe7c..4d3fcc3 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -666,6 +666,8 @@ void uv__work_done(uv_async_t* handle) { rdunlock_closed_uv_loop_rwlock(); return; } + rdunlock_closed_uv_loop_rwlock(); + uv_mutex_lock(&loop->wq_mutex); #ifndef USE_FFRT uv__queue_move(&loop->wq, &wq); @@ -713,7 +715,6 @@ void uv__work_done(uv_async_t* handle) { #endif } uv_end_trace(UV_TRACE_TAG); - rdunlock_closed_uv_loop_rwlock(); /* This check accomplishes 2 things: * 1. Even if the queue was empty, the call to uv__work_done() should count -- Gitee From 980c351dec60c771ab4f5ce03ac174bca4d2fafb Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Fri, 16 Aug 2024 11:21:13 +0800 Subject: [PATCH 05/33] add log for emulator Signed-off-by: liaoxingxing --- BUILD.gn | 5 +++- src/unix/ohos/log_ohos.c | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/unix/ohos/log_ohos.c diff --git a/BUILD.gn b/BUILD.gn index 268d1e5..a0dde3f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -194,7 +194,7 @@ if (defined(ohos_lite)) { [ "-Wno-frame-address" ] # for use of __builtin_return_address } - if (use_ohos_dfx && is_ohos) { + if (use_ohos_dfx && is_ohos && !is_emulator) { defines += [ "USE_OHOS_DFX" ] } } else if (is_mingw || is_win) { @@ -299,6 +299,9 @@ if (defined(ohos_lite)) { } if (is_ohos) { sources += [ "src/unix/ohos/trace_ohos.c" ] + if (is_emulator) { + sources += [ "src/unix/ohos/log_ohos.c" ] + } external_deps += [ "hilog:libhilog", "hitrace:hitrace_meter", diff --git a/src/unix/ohos/log_ohos.c b/src/unix/ohos/log_ohos.c new file mode 100644 index 0000000..e08c339 --- /dev/null +++ b/src/unix/ohos/log_ohos.c @@ -0,0 +1,53 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv_log.h" +#include "hilog/log.h" + +#include + +extern int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, + const char *fmt, va_list ap); + +LogLevel convert_uv_log_level(enum uv__log_level level) { + switch (level) + { + case UV_DEBUG: + return LOG_DEBUG; + case UV_INFO: + return LOG_INFO; + case UV_WARN: + return LOG_WARN; + case UV_ERROR: + return LOG_ERROR; + case UV_FATAL: + return LOG_FATAL; + default: + return LOG_LEVEL_MIN; + } +} + +int uv__log_impl(enum uv__log_level level, const char *fmt, ...) { + va_list args; + va_start(args, fmt); + int ret = HiLogPrintArgs(LOG_CORE, convert_uv_log_level(level), 0xD003301, "UV", fmt, args); + va_end(args); + return ret; +} -- Gitee From f48a45e0b16bf7a4b6fff801ff6547b4e52fa475 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Fri, 16 Aug 2024 11:23:43 +0800 Subject: [PATCH 06/33] add log for emulator Signed-off-by: liaoxingxing --- src/unix/ohos/log_ohos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/ohos/log_ohos.c b/src/unix/ohos/log_ohos.c index e08c339..78779fa 100644 --- a/src/unix/ohos/log_ohos.c +++ b/src/unix/ohos/log_ohos.c @@ -47,7 +47,7 @@ LogLevel convert_uv_log_level(enum uv__log_level level) { int uv__log_impl(enum uv__log_level level, const char *fmt, ...) { va_list args; va_start(args, fmt); - int ret = HiLogPrintArgs(LOG_CORE, convert_uv_log_level(level), 0xD003301, "UV", fmt, args); + int ret = HiLogPrintArgs(LOG_CORE, convert_uv_log_level(level), 0xD003301, "LIBUV", fmt, args); va_end(args); return ret; } -- Gitee From 0db1ed9bfa2326fdd6348e28d25675d29af11412 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Sat, 17 Aug 2024 17:16:37 +0800 Subject: [PATCH 07/33] add log for uv close Signed-off-by: liaoxingxing --- src/uv-common.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/uv-common.c b/src/uv-common.c index 35581c9..5bfe45c 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -21,6 +21,7 @@ #include "uv.h" #include "uv-common.h" +#include "uv_log.h" #include #include @@ -855,14 +856,25 @@ int uv_loop_close(uv_loop_t* loop) { #ifndef NDEBUG void* saved_data; #endif +#ifdef USE_OHOS_DFX + UV_LOGI("Loop %{public}zu going to close", (size_t)loop); +#endif - if (uv__has_active_reqs(loop)) + if (uv__has_active_reqs(loop)) { +#ifdef USE_OHOS_DFX + UV_LOGI("Unable to close loop %{public}zu, %{public}d active request(s) remains", (size_t)loop, loop->active_reqs.count); +#endif return UV_EBUSY; + } uv__queue_foreach(q, &loop->handle_queue) { h = uv__queue_data(q, uv_handle_t, handle_queue); - if (!(h->flags & UV_HANDLE_INTERNAL)) + if (!(h->flags & UV_HANDLE_INTERNAL)) { +#ifdef USE_OHOS_DFX + UV_LOGI("Unable to close loop %{public}zu, handle %{public}zu active", (size_t)loop, (size_t)h); +#endif return UV_EBUSY; + } } on_uv_loop_close(loop); -- Gitee From 4f61260f7095c3c48b3e91d14f3039a3e1df53b0 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Wed, 21 Aug 2024 14:48:41 +0800 Subject: [PATCH 08/33] =?UTF-8?q?=E5=A2=9E=E5=8A=A0uv=5Fasync=5Fsend?= =?UTF-8?q?=E4=B8=ADhandle=E5=88=A4=E7=A9=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- src/threadpool.c | 5 ++--- src/unix/async.c | 17 +++++++++++------ src/unix/core.c | 4 ++-- src/unix/linux.c | 2 +- src/unix/loop.c | 10 ++-------- src/unix/signal.c | 8 ++++---- src/uv-common.c | 16 ++++++++++++---- 7 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/threadpool.c b/src/threadpool.c index 4d3fcc3..6b777d0 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -44,7 +44,6 @@ static uv_once_t once = UV_ONCE_INIT; static uv_cond_t cond; static uv_mutex_t mutex; static unsigned int idle_threads; -static unsigned int slow_io_work_running; static unsigned int nthreads; static uv_thread_t* threads; static uv_thread_t default_threads[4]; @@ -305,7 +304,7 @@ int is_uv_loop_good_magic(const uv_loop_t* loop) { if (loop->magic == UV_LOOP_MAGIC) { return 1; } - UV_LOGE("uv_loop(%{public}zu:%{public}#x) is invalid", (size_t)loop, loop->magic); + UV_LOGE("loop:(%{public}zu:%{public}#x) invalid", (size_t)loop, loop->magic); return 0; } @@ -321,7 +320,7 @@ void on_uv_loop_close(uv_loop_t* loop) { uv_rwlock_wrunlock(&g_closed_uv_loop_rwlock); uv_end_trace(UV_TRACE_TAG); time(&t2); - UV_LOGI("uv_loop(%{public}zu) closed in %{public}zds", (size_t)loop, (ssize_t)(t2 - t1)); + UV_LOGI("loop:(%{public}zu) closed in %{public}zds", (size_t)loop, (ssize_t)(t2 - t1)); } diff --git a/src/unix/async.c b/src/unix/async.c index e0d9bb7..7f744c4 100644 --- a/src/unix/async.c +++ b/src/unix/async.c @@ -64,6 +64,13 @@ int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) { int uv_async_send(uv_async_t* handle) { _Atomic int* pending; +#ifdef USE_OHOS_DFX + if (handle == NULL) { + UV_LOGF("handle is NULL"); + return -1; + } +#endif + pending = (_Atomic int*) &handle->pending; @@ -151,7 +158,7 @@ static void uv__async_send(uv_async_t* handle) { uv_loop_t* loop = handle->loop; if (loop == NULL) { - UV_LOGE("fatal error! loop is NULL"); + UV_LOGF("loop is NULL"); return; } @@ -214,8 +221,7 @@ static int uv__async_start(uv_loop_t* loop) { uv__io_init(&loop->async_io_watcher, uv__async_io, pipefd[0]); uv__io_start(loop, &loop->async_io_watcher, POLLIN); loop->async_wfd = pipefd[1]; - UV_LOGI("open: loop addr is %{public}zu, loop->async_wfd is %{public}d," - "loop->async_io_watcher.fd is %{public}d", (size_t)loop, loop->async_wfd, pipefd[0]); + UV_LOGI("open:%{public}zu, pipefd[0]:%{public}d", (size_t)loop, pipefd[0]); return 0; } @@ -236,7 +242,7 @@ void uv__async_stop(uv_loop_t* loop) { if (loop->async_wfd != -1) { if (loop->async_wfd != loop->async_io_watcher.fd) { - UV_LOGI("close: loop addr is %{public}zu, loop->async_wfd is %{public}d", (size_t)loop, loop->async_wfd); + UV_LOGI("close:%{public}zu, async_wfd:%{public}d", (size_t)loop, loop->async_wfd); uv__close(loop->async_wfd); } loop->async_wfd = -1; @@ -248,8 +254,7 @@ void uv__async_stop(uv_loop_t* loop) { #else uv__close(loop->async_io_watcher.fd); #endif - UV_LOGI("close: loop addr is %{public}zu, loop->async_io_watcher.fd is %{public}d", - (size_t)loop, loop->async_io_watcher.fd); + UV_LOGI("close:%{public}zu, async_io_wfd:%{public}d", (size_t)loop, loop->async_io_watcher.fd); loop->async_io_watcher.fd = -1; } diff --git a/src/unix/core.c b/src/unix/core.c index e38ac55..359ceeb 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -1938,7 +1938,7 @@ int uv_register_task_to_event(struct uv_loop_s* loop, uv_post_task func, void* h if (data == NULL) return -1; if ((uint64_t)data >> UV_EVENT_MAGIC_OFFSETBITS != 0x0) { - UV_LOGE("malloc address error!"); + UV_LOGE("malloc address error"); free(data); return -1; } @@ -1979,7 +1979,7 @@ int uv_check_data_valid(struct uv_loop_data* data) { struct uv_loop_data* addr = (struct uv_loop_data*)((uint64_t)data - (UV_EVENT_MAGIC_OFFSET << UV_EVENT_MAGIC_OFFSETBITS)); if (addr->post_task_func == NULL) { - UV_LOGE("post_task_func is NULL"); + UV_LOGE("post_task_func NULL"); return -1; } return 0; diff --git a/src/unix/linux.c b/src/unix/linux.c index 67a17c5..d361171 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -671,7 +671,7 @@ int uv__platform_loop_init(uv_loop_t* loop) { uv__iou_init(loop->backend_fd, &lfields->iou, 64, UV__IORING_SETUP_SQPOLL); uv__iou_init(loop->backend_fd, &lfields->ctl, 256, 0); - UV_LOGI("loop init: loop add is %{public}zu, backend_fd is %{public}d", (size_t)loop, loop->backend_fd); + UV_LOGI("init:%{public}zu, backend_fd:%{public}d", (size_t)loop, loop->backend_fd); return 0; } diff --git a/src/unix/loop.c b/src/unix/loop.c index 6c579de..2cb896a 100644 --- a/src/unix/loop.c +++ b/src/unix/loop.c @@ -33,7 +33,7 @@ int uv_loop_init(uv_loop_t* loop) { void* saved_data; int err; - UV_LOGI("loop init: loop addr is %{public}zu", (size_t)loop); + UV_LOGI("init:%{public}zu", (size_t)loop); saved_data = loop->data; memset(loop, 0, sizeof(*loop)); loop->data = saved_data; @@ -190,19 +190,13 @@ void uv__loop_close(uv_loop_t* loop) { #else uv__close(loop->backend_fd); #endif - UV_LOGI("close: loop addr is %{public}zu, loop->backend_fd is %{public}d", (size_t)loop, loop->backend_fd); + UV_LOGI("close:%{public}zu, backend_fd:%{public}d", (size_t)loop, loop->backend_fd); loop->backend_fd = -1; } uv_mutex_lock(&loop->wq_mutex); #ifndef USE_FFRT assert(uv__queue_empty(&loop->wq) && "thread pool work queue not empty!"); -#else - uv__loop_internal_fields_t* lfields_qos = uv__get_internal_fields(loop); - assert(uv__queue_empty(&(lfields_qos->wq_sub[uv_qos_background])) && "thread pool work queue qos_background not empty!"); - assert(uv__queue_empty(&(lfields_qos->wq_sub[uv_qos_utility])) && "thread pool work queue qos_utility not empty!"); - assert(uv__queue_empty(&(lfields_qos->wq_sub[uv_qos_default])) && "thread pool work queue qos_default not empty!"); - assert(uv__queue_empty(&(lfields_qos->wq_sub[uv_qos_user_initiated])) && "thread pool work queue qos_user_initiated not empty!"); #endif assert(!uv__has_active_reqs(loop)); uv_mutex_unlock(&loop->wq_mutex); diff --git a/src/unix/signal.c b/src/unix/signal.c index d69829b..90c8ce2 100644 --- a/src/unix/signal.c +++ b/src/unix/signal.c @@ -106,7 +106,7 @@ static void uv__signal_global_reinit(void) { if (uv__signal_unlock()) { #ifdef USE_OHOS_DFX - UV_LOGF("errno is %{public}d, uv__signal_lock_pipefd[1] is %{public}d", errno, uv__signal_lock_pipefd[1]); + UV_LOGF("errno:%{public}d, sig_lock_pfd[1]:%{public}d", errno, uv__signal_lock_pipefd[1]); return; #else abort(); @@ -157,7 +157,7 @@ static void uv__signal_block_and_lock(sigset_t* saved_sigmask) { if (uv__signal_lock()) { #ifdef USE_OHOS_DFX - UV_LOGF("errno is %{public}d, uv__signal_lock_pipefd[0] is %{public}d", errno, uv__signal_lock_pipefd[0]); + UV_LOGF("errno:%{public}d, sig_lock_pfd[0]:%{public}d", errno, uv__signal_lock_pipefd[0]); return; #else abort(); @@ -169,7 +169,7 @@ static void uv__signal_block_and_lock(sigset_t* saved_sigmask) { static void uv__signal_unlock_and_unblock(sigset_t* saved_sigmask) { if (uv__signal_unlock()) { #ifdef USE_OHOS_DFX - UV_LOGF("errno is %{public}d, uv__signal_lock_pipefd[1] is %{public}d", errno, uv__signal_lock_pipefd[1]); + UV_LOGF("errno:%{public}d, sig_lock_pfd[1]:%{public}d", errno, uv__signal_lock_pipefd[1]); return; #else abort(); @@ -482,7 +482,7 @@ static void uv__signal_event(uv_loop_t* loop, /* Other errors really should never happen. */ if (r == -1) { #ifdef USE_OHOS_DFX - UV_LOGF("errno is %{public}d, loop->signal_pipefd[0] is %{public}d", errno, loop->signal_pipefd[0]); + UV_LOGF("errno:%{public}d, sig_pfd[0]:%{public}d", errno, loop->signal_pipefd[0]); return; #else abort(); diff --git a/src/uv-common.c b/src/uv-common.c index 35581c9..8c30a06 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -21,6 +21,7 @@ #include "uv.h" #include "uv-common.h" +#include "uv_log.h" #include #include @@ -856,16 +857,23 @@ int uv_loop_close(uv_loop_t* loop) { void* saved_data; #endif - if (uv__has_active_reqs(loop)) + on_uv_loop_close(loop); + if (uv__has_active_reqs(loop)) { +#ifdef USE_OHOS_DFX + UV_LOGI("loop:%{public}zu, active reqs:%{public}u", (size_t)loop, loop->active_reqs.count); +#endif return UV_EBUSY; - + } uv__queue_foreach(q, &loop->handle_queue) { h = uv__queue_data(q, uv_handle_t, handle_queue); - if (!(h->flags & UV_HANDLE_INTERNAL)) + if (!(h->flags & UV_HANDLE_INTERNAL)) { +#ifdef USE_OHOS_DFX + UV_LOGI("loop:%{public}zu, active handle:%{public}zu", (size_t)loop, (size_t)h); +#endif return UV_EBUSY; + } } - on_uv_loop_close(loop); uv__loop_close(loop); #ifndef NDEBUG -- Gitee From ff359ae3bfda56826ccbfe80fbd4315aa66b21c1 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Mon, 19 Aug 2024 10:40:41 +0800 Subject: [PATCH 09/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84copyright?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- BUILD.gn | 2 +- src/threadpool.c | 1 - src/unix/log_unix.c | 27 +++++++++++---------------- src/unix/loop.c | 6 ------ src/unix/ohos/log_ohos.c | 27 +++++++++++---------------- src/unix/ohos/trace_ohos.c | 27 +++++++++++---------------- src/unix/trace_unix.c | 27 +++++++++++---------------- src/uv_log.h | 27 +++++++++++---------------- src/uv_trace.h | 27 +++++++++++---------------- src/win/log_win.c | 27 +++++++++++---------------- src/win/trace_win.c | 27 +++++++++++---------------- 11 files changed, 89 insertions(+), 136 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index a0dde3f..75a85eb 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2024 Huawei Device Co., Ltd. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to diff --git a/src/threadpool.c b/src/threadpool.c index 4d3fcc3..b66ad22 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -44,7 +44,6 @@ static uv_once_t once = UV_ONCE_INIT; static uv_cond_t cond; static uv_mutex_t mutex; static unsigned int idle_threads; -static unsigned int slow_io_work_running; static unsigned int nthreads; static uv_thread_t* threads; static uv_thread_t default_threads[4]; diff --git a/src/unix/log_unix.c b/src/unix/log_unix.c index 2105a68..056c87c 100644 --- a/src/unix/log_unix.c +++ b/src/unix/log_unix.c @@ -1,21 +1,16 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * http://www.apache.org/licenses/LICENSE-2.0 * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "uv_log.h" diff --git a/src/unix/loop.c b/src/unix/loop.c index 6c579de..0cc2bd1 100644 --- a/src/unix/loop.c +++ b/src/unix/loop.c @@ -197,12 +197,6 @@ void uv__loop_close(uv_loop_t* loop) { uv_mutex_lock(&loop->wq_mutex); #ifndef USE_FFRT assert(uv__queue_empty(&loop->wq) && "thread pool work queue not empty!"); -#else - uv__loop_internal_fields_t* lfields_qos = uv__get_internal_fields(loop); - assert(uv__queue_empty(&(lfields_qos->wq_sub[uv_qos_background])) && "thread pool work queue qos_background not empty!"); - assert(uv__queue_empty(&(lfields_qos->wq_sub[uv_qos_utility])) && "thread pool work queue qos_utility not empty!"); - assert(uv__queue_empty(&(lfields_qos->wq_sub[uv_qos_default])) && "thread pool work queue qos_default not empty!"); - assert(uv__queue_empty(&(lfields_qos->wq_sub[uv_qos_user_initiated])) && "thread pool work queue qos_user_initiated not empty!"); #endif assert(!uv__has_active_reqs(loop)); uv_mutex_unlock(&loop->wq_mutex); diff --git a/src/unix/ohos/log_ohos.c b/src/unix/ohos/log_ohos.c index 78779fa..f644ffc 100644 --- a/src/unix/ohos/log_ohos.c +++ b/src/unix/ohos/log_ohos.c @@ -1,21 +1,16 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * http://www.apache.org/licenses/LICENSE-2.0 * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "uv_log.h" diff --git a/src/unix/ohos/trace_ohos.c b/src/unix/ohos/trace_ohos.c index ba855ba..51512de 100644 --- a/src/unix/ohos/trace_ohos.c +++ b/src/unix/ohos/trace_ohos.c @@ -1,21 +1,16 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * http://www.apache.org/licenses/LICENSE-2.0 * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "uv_trace.h" diff --git a/src/unix/trace_unix.c b/src/unix/trace_unix.c index f84e38a..020f1a4 100644 --- a/src/unix/trace_unix.c +++ b/src/unix/trace_unix.c @@ -1,21 +1,16 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * http://www.apache.org/licenses/LICENSE-2.0 * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "uv_trace.h" diff --git a/src/uv_log.h b/src/uv_log.h index a75ebb8..5a34476 100644 --- a/src/uv_log.h +++ b/src/uv_log.h @@ -1,21 +1,16 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * http://www.apache.org/licenses/LICENSE-2.0 * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef UV_LOG_H diff --git a/src/uv_trace.h b/src/uv_trace.h index 619f741..6a4449c 100644 --- a/src/uv_trace.h +++ b/src/uv_trace.h @@ -1,21 +1,16 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * http://www.apache.org/licenses/LICENSE-2.0 * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef UV_TRACE_H diff --git a/src/win/log_win.c b/src/win/log_win.c index 2105a68..463cd93 100644 --- a/src/win/log_win.c +++ b/src/win/log_win.c @@ -1,21 +1,16 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * http://www.apache.org/licenses/LICENSE-2.0 * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "uv_log.h" diff --git a/src/win/trace_win.c b/src/win/trace_win.c index f84e38a..020f1a4 100644 --- a/src/win/trace_win.c +++ b/src/win/trace_win.c @@ -1,21 +1,16 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * http://www.apache.org/licenses/LICENSE-2.0 * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "uv_trace.h" -- Gitee From cbe99f34d813de689ad6b3ee6e82e369ec4a9b43 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Thu, 22 Aug 2024 21:22:06 +0800 Subject: [PATCH 10/33] =?UTF-8?q?=E5=A2=9E=E5=8A=A0watcher=E7=B4=A2?= =?UTF-8?q?=E5=BC=95fd=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- src/unix/linux.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/unix/linux.c b/src/unix/linux.c index 67a17c5..7f383c4 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -1510,8 +1510,13 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { continue; } +#ifndef USE_OHOS_DFX assert(fd >= 0); assert((unsigned) fd < loop->nwatchers); +#else + if (fd < 0 || (unsigned) fd >= loop->nwatchers) + continue; +#endif w = loop->watchers[fd]; -- Gitee From 3f0393149d55eb5ab5a5f5953229159619047b5c Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Mon, 26 Aug 2024 20:41:49 +0800 Subject: [PATCH 11/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9on=5Fuv=5Floop=5Fclose?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- src/uv-common.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/uv-common.c b/src/uv-common.c index 8c30a06..c766d09 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -857,7 +857,6 @@ int uv_loop_close(uv_loop_t* loop) { void* saved_data; #endif - on_uv_loop_close(loop); if (uv__has_active_reqs(loop)) { #ifdef USE_OHOS_DFX UV_LOGI("loop:%{public}zu, active reqs:%{public}u", (size_t)loop, loop->active_reqs.count); @@ -874,6 +873,7 @@ int uv_loop_close(uv_loop_t* loop) { } } + on_uv_loop_close(loop); uv__loop_close(loop); #ifndef NDEBUG @@ -897,6 +897,10 @@ void uv_loop_delete(uv_loop_t* loop) { err = uv_loop_close(loop); (void) err; /* Squelch compiler warnings. */ assert(err == 0); +#ifdef USE_OHOS_DFX + if (err != 0) + on_uv_loop_close(loop); +#endif if (loop != default_loop) uv__free(loop); } -- Gitee From 6e845267b81e1daf96de1fff863817f9823351e2 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Wed, 28 Aug 2024 09:09:05 +0800 Subject: [PATCH 12/33] =?UTF-8?q?=E5=A2=9E=E5=8A=A0uv=5F=5Fsubmit=5Fwork?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- src/threadpool.c | 3 +++ src/win/log_win.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/threadpool.c b/src/threadpool.c index 6b777d0..db6dac7 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -833,6 +833,9 @@ void uv__work_submit(uv_loop_t* loop, ffrt_task_attr_set_qos(&attr, ffrt_qos_background); break; default: +#ifdef USE_OHOS_DFX + UV_LOGI("Unknown work kind"); +#endif return; } diff --git a/src/win/log_win.c b/src/win/log_win.c index 463cd93..056c87c 100644 --- a/src/win/log_win.c +++ b/src/win/log_win.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. -- Gitee From 1b5221802e5728d4a6d148dee374ab7ef220f5e9 Mon Sep 17 00:00:00 2001 From: yongyuan Date: Sat, 31 Aug 2024 15:46:45 +0800 Subject: [PATCH 13/33] =?UTF-8?q?=E9=85=8D=E5=90=88=E8=A7=A3=E5=86=B3env?= =?UTF-8?q?=E9=80=80=E5=87=BA=E6=9C=BA=E5=88=B6=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yongyuan --- src/unix/async.c | 11 +++++++++++ src/unix/internal.h | 16 ++++++++++++++++ src/unix/linux.c | 3 ++- src/uv-common.h | 16 ++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/unix/async.c b/src/unix/async.c index 7f744c4..dbc66d6 100644 --- a/src/unix/async.c +++ b/src/unix/async.c @@ -39,6 +39,11 @@ #include #endif +#ifdef USE_FFRT +#include "ffrt.h" +#include "c/executor_task.h" +#endif + static void uv__async_send(uv_async_t* handle); static int uv__async_start(uv_loop_t* loop); @@ -249,6 +254,12 @@ void uv__async_stop(uv_loop_t* loop) { } uv__io_stop(loop, &loop->async_io_watcher, POLLIN); +#ifdef USE_FFRT + if (ffrt_get_cur_task() != NULL) { + uv__epoll_ctl(loop->backend_fd, EPOLL_CTL_DEL, loop->async_io_watcher.fd, NULL); + } +#endif + #if defined(__linux__) && defined(USE_OHOS_DFX) fdsan_close_with_tag(loop->async_io_watcher.fd, uv__get_addr_tag((void *)&loop->async_io_watcher)); #else diff --git a/src/unix/internal.h b/src/unix/internal.h index 80e596a..4a92125 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -35,6 +35,11 @@ #include #include #include + +#ifdef USE_FFRT +#include +#endif + #define UV_LOOP_MAGIC 0x100B100BU #define uv__msan_unpoison(p, n) \ do { \ @@ -262,6 +267,10 @@ int uv__fd_exists(uv_loop_t* loop, int fd); void uv__async_stop(uv_loop_t* loop); int uv__async_fork(uv_loop_t* loop); +#ifdef USE_FFRT +/* epoll */ +int uv__epoll_ctl(int epoll_fd, int op, int fd, struct epoll_event* event); +#endif /* loop */ void uv__run_idle(uv_loop_t* loop); @@ -472,4 +481,11 @@ uv__fs_copy_file_range(int fd_in, #define UV__CPU_AFFINITY_SUPPORTED 0 #endif +UV_UNUSED(static unsigned int self_increase(unsigned int* ptr)) { + return __sync_fetch_and_add(ptr, 1); +} + +UV_UNUSED(static unsigned int self_decrease(unsigned int* ptr)) { + return __sync_fetch_and_sub(ptr, 1); +} #endif /* UV_UNIX_INTERNAL_H_ */ diff --git a/src/unix/linux.c b/src/unix/linux.c index 5042ea6..c89f333 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -55,6 +55,7 @@ #include #include #include + #ifdef USE_FFRT #include "ffrt.h" #include "c/executor_task.h" @@ -73,7 +74,7 @@ int uv__epoll_ctl(int epoll_fd, int op, int fd, struct epoll_event* event) { #ifdef USE_FFRT if (ffrt_get_cur_task() != NULL) { ffrt_qos_t qos = ffrt_this_task_get_qos(); - return ffrt_epoll_ctl(qos, op, fd, event->events, NULL, NULL); + return ffrt_epoll_ctl(qos, op, fd, event == NULL ? 0 : event->events, NULL, NULL); } #endif return epoll_ctl(epoll_fd, op, fd ,event); diff --git a/src/uv-common.h b/src/uv-common.h index bcff87a..bc2e300 100644 --- a/src/uv-common.h +++ b/src/uv-common.h @@ -236,6 +236,21 @@ void uv__threadpool_cleanup(void); #define uv__has_active_reqs(loop) \ ((loop)->active_reqs.count > 0) +#if defined(USE_FFRT) && defined(USE_OHOS_DFX) +#define uv__req_register(loop, req) \ + do { \ + self_increase((unsigned int*)(&((loop)->active_reqs.count))); \ + } \ + while (0) + +#define uv__req_unregister(loop, req) \ + do { \ + if(!uv__has_active_reqs(loop)) \ + break; \ + self_decrease((unsigned int*)(&((loop)->active_reqs.count))); \ + } \ + while (0) +#else #define uv__req_register(loop, req) \ do { \ (loop)->active_reqs.count++; \ @@ -248,6 +263,7 @@ void uv__threadpool_cleanup(void); (loop)->active_reqs.count--; \ } \ while (0) +#endif #define uv__has_active_handles(loop) \ ((loop)->active_handles > 0) -- Gitee From a7fa5b06de6faa80dbe50d10fd3d1c0250660c7d Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Mon, 2 Sep 2024 15:48:55 +0800 Subject: [PATCH 14/33] =?UTF-8?q?=E6=95=B4=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E6=AD=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- .gitattributes | 1 - BUILD.gn | 16 +++++++++------- include/uv.h | 2 ++ src/heap-inl.h | 2 +- src/threadpool.c | 11 +++++------ src/timer.c | 1 - src/unix/core.c | 6 ++++-- 7 files changed, 21 insertions(+), 18 deletions(-) delete mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 89297cb..0000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -test/fixtures/lorem_ipsum.txt text eol=lf diff --git a/BUILD.gn b/BUILD.gn index 75a85eb..1aca736 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -246,13 +246,13 @@ if (defined(ohos_lite)) { if (is_mac || (defined(is_ios) && is_ios)) { sources += nonwin_srcs + [ "src/unix/bsd-ifaddrs.c", - "src/unix/kqueue.c", - "src/unix/random-getentropy.c", "src/unix/darwin-proctitle.c", "src/unix/darwin.c", "src/unix/fsevents.c", - "src/unix/os390-proctitle.c", + "src/unix/kqueue.c", "src/unix/log_unix.c", + "src/unix/os390-proctitle.c", + "src/unix/random-getentropy.c", "src/unix/trace_unix.c", ] } else if (is_mingw || is_win) { @@ -289,10 +289,10 @@ if (defined(ohos_lite)) { sources += nonwin_srcs + [ "src/unix/linux.c", "src/unix/procfs-exepath.c", + "src/unix/proctitle.c", "src/unix/random-getentropy.c", "src/unix/random-getrandom.c", "src/unix/random-sysctl-linux.c", - "src/unix/proctitle.c", ] if (libuv_use_ffrt) { external_deps += [ "ffrt:libffrt" ] @@ -307,9 +307,11 @@ if (defined(ohos_lite)) { "hitrace:hitrace_meter", ] } + if (is_ohos && enable_async_stack) { sources += [ "src/dfx/async_stack/libuv_async_stack.c" ] } + if (is_android) { sources += [ "src/win/log_win.c", @@ -319,20 +321,20 @@ if (defined(ohos_lite)) { } else if (is_linux) { sources += nonwin_srcs + [ "src/unix/linux.c", + "src/unix/log_unix.c", "src/unix/procfs-exepath.c", + "src/unix/proctitle.c", "src/unix/random-getrandom.c", "src/unix/random-sysctl-linux.c", - "src/unix/proctitle.c", - "src/unix/log_unix.c", "src/unix/trace_unix.c", ] } else { sources += nonwin_srcs + [ "src/unix/linux.c", "src/unix/procfs-exepath.c", + "src/unix/proctitle.c", "src/unix/random-getrandom.c", "src/unix/random-sysctl-linux.c", - "src/unix/proctitle.c", ] } subsystem_name = "thirdparty" diff --git a/include/uv.h b/include/uv.h index 418796d..945c34e 100644 --- a/include/uv.h +++ b/include/uv.h @@ -226,6 +226,7 @@ typedef enum { #define UV_EVENT_MAGIC_OFFSET 0x12345ULL #define UV_EVENT_MAGIC_OFFSETBITS 44 + /* Handle types. */ typedef struct uv_loop_s uv_loop_t; typedef struct uv_handle_s uv_handle_t; @@ -1953,6 +1954,7 @@ UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data); UV_EXTERN int uv_register_task_to_event(struct uv_loop_s* loop, uv_post_task func, void* handler); UV_EXTERN int uv_unregister_task_to_event(struct uv_loop_s* loop); UV_EXTERN int uv_check_data_valid(struct uv_loop_data* data); + /* String utilities needed internally for dealing with Windows. */ size_t uv_utf16_length_as_wtf8(const uint16_t* utf16, ssize_t utf16_len); diff --git a/src/heap-inl.h b/src/heap-inl.h index 939a523..1e2ed60 100644 --- a/src/heap-inl.h +++ b/src/heap-inl.h @@ -177,7 +177,7 @@ HEAP_EXPORT(void heap_remove(struct heap* heap, path >>= 1; k -= 1; } - + heap->nelts -= 1; /* Unlink the max node. */ diff --git a/src/threadpool.c b/src/threadpool.c index db6dac7..edd724f 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -35,6 +35,9 @@ #include "ffrt_inner.h" #endif #include +#ifdef ASYNC_STACKTRACE +#include "dfx/async_stack/libuv_async_stack.h" +#endif #define MAX_THREADPOOL_SIZE 1024 #define UV_TRACE_NAME "UV_TRACE" @@ -53,10 +56,6 @@ static struct uv__queue run_slow_work_message; static struct uv__queue slow_io_pending_wq; -#ifdef ASYNC_STACKTRACE -#include "dfx/async_stack/libuv_async_stack.h" -#endif - #ifdef UV_STATISTIC #define MAX_DUMP_QUEUE_SIZE 200 static uv_mutex_t dump_queue_mutex; @@ -634,7 +633,7 @@ static int uv__work_cancel(uv_loop_t* loop, uv_req_t* req, struct uv__work* w) { uv__loop_internal_fields_t* lfields = uv__get_internal_fields(w->loop); int qos = (ffrt_qos_t)(intptr_t)req->reserved[0]; - if (uv_check_data_valid((struct uv_loop_data*)(loop->data)) == 0) { + if (uv_check_data_valid((struct uv_loop_data*)(w->loop->data)) == 0) { int status = (w->work == uv__cancelled) ? UV_ECANCELED : 0; struct uv_loop_data* addr = (struct uv_loop_data*)((uint64_t)w->loop->data - (UV_EVENT_MAGIC_OFFSET << UV_EVENT_MAGIC_OFFSETBITS)); @@ -666,7 +665,7 @@ void uv__work_done(uv_async_t* handle) { return; } rdunlock_closed_uv_loop_rwlock(); - + uv_mutex_lock(&loop->wq_mutex); #ifndef USE_FFRT uv__queue_move(&loop->wq, &wq); diff --git a/src/timer.c b/src/timer.c index 0734f43..35548b4 100644 --- a/src/timer.c +++ b/src/timer.c @@ -97,7 +97,6 @@ int uv_timer_start(uv_timer_t* handle, (struct heap_node*) &handle->heap_node, timer_less_than); uv__handle_start(handle); - #ifdef __linux__ if (uv_check_data_valid((struct uv_loop_data*)handle->loop->data) == 0) { uv_async_send(&handle->loop->wq_async); diff --git a/src/unix/core.c b/src/unix/core.c index 359ceeb..ba7c8ce 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -1954,13 +1954,13 @@ int uv_register_task_to_event(struct uv_loop_s* loop, uv_post_task func, void* h #endif } + int uv_unregister_task_to_event(struct uv_loop_s* loop) { #if defined(__aarch64__) if (loop == NULL || loop->data == NULL || ((uint64_t)loop->data >> UV_EVENT_MAGIC_OFFSETBITS) != (uint64_t)(UV_EVENT_MAGIC_OFFSET)) return -1; - loop->data = (struct uv_loop_data*)((uint64_t)loop->data - (UV_EVENT_MAGIC_OFFSET << UV_EVENT_MAGIC_OFFSETBITS)); free(loop->data); @@ -1971,6 +1971,7 @@ int uv_unregister_task_to_event(struct uv_loop_s* loop) #endif } + int uv_check_data_valid(struct uv_loop_data* data) { #if defined(__aarch64__) if (data == NULL || ((uint64_t)data >> UV_EVENT_MAGIC_OFFSETBITS) != (uint64_t)(UV_EVENT_MAGIC_OFFSET)) { @@ -1986,4 +1987,5 @@ int uv_check_data_valid(struct uv_loop_data* data) { #else return -1; #endif -} \ No newline at end of file +} + -- Gitee From e634910f46b1a003faea81ae69845cb1b29fd12b Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Fri, 6 Sep 2024 18:56:41 +0800 Subject: [PATCH 15/33] =?UTF-8?q?=E5=A2=9E=E5=8A=A0uv=5F=5Fepoll=5Fctl=5Fp?= =?UTF-8?q?rep=E7=BB=B4=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- src/unix/linux.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/unix/linux.c b/src/unix/linux.c index c89f333..feccbb6 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -1245,6 +1245,7 @@ static void uv__epoll_ctl_prep(int epollfd, struct epoll_event* pe; uint32_t mask; uint32_t slot; + int ret = 0; if (ctl->ringfd == -1) { if (!uv__epoll_ctl(epollfd, op, fd, e)) @@ -1253,17 +1254,35 @@ static void uv__epoll_ctl_prep(int epollfd, if (op == EPOLL_CTL_DEL) return; /* Ignore errors, may be racing with another thread. */ - if (op != EPOLL_CTL_ADD) + if (op != EPOLL_CTL_ADD) { +#ifdef PRINT_ERRNO_ABORT + UV_ERRNO_ABORT("errno is %d, fd is %d, backend_fd is %d(%s:%s:%d)", + errno, fd, epollfd, __FILE__, __func__, __LINE__); +#else abort(); +#endif + } - if (errno != EEXIST) + if (errno != EEXIST) { +#ifdef PRINT_ERRNO_ABORT + UV_ERRNO_ABORT("errno is %d, fd is %d, backend_fd is %d(%s:%s:%d)", + errno, fd, epollfd, __FILE__, __func__, __LINE__); +#else abort(); +#endif + } /* File descriptor that's been watched before, update event mask. */ - if (!uv__epoll_ctl(epollfd, EPOLL_CTL_MOD, fd, e)) + ret = uv__epoll_ctl(epollfd, EPOLL_CTL_MOD, fd, e); + if (!ret) return; +#ifdef PRINT_ERRNO_ABORT + UV_ERRNO_ABORT("errno is %d, uv__epoll_ctl ret is %d, fd is %d, backend_fd is %d(%s:%s:%d)", + errno, ret, fd, epollfd, __FILE__, __func__, __LINE__); +#else abort(); +#endif } else { mask = ctl->sqmask; slot = (*ctl->sqtail)++ & mask; -- Gitee From f236a08d88759f3a38ddaa20be528cb83ba0cad1 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Thu, 12 Sep 2024 15:59:05 +0800 Subject: [PATCH 16/33] =?UTF-8?q?PAC=E4=BD=BF=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/BUILD.gn b/BUILD.gn index 1aca736..9d17a31 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -239,6 +239,7 @@ if (defined(ohos_lite)) { } ohos_source_set("libuv_source") { + branch_protector_ret = "pac_ret" configs = [ ":libuv_config" ] cflags = [ "-fvisibility=hidden" ] sources = common_source -- Gitee From 8a1c704c3198a49275e32bfa864e42b649bd0315 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Sat, 21 Sep 2024 14:31:36 +0800 Subject: [PATCH 17/33] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ldflags=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- BUILD.gn | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BUILD.gn b/BUILD.gn index 9d17a31..c8d5995 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -350,6 +350,9 @@ if (defined(ohos_lite)) { } ohos_shared_library("uv") { deps = [ ":libuv_source" ] + if (is_linux || is_ohos) { + ldflags = [ "-Wl,--exclude-libs=ALL" ] + } external_deps = [ "hilog:libhilog" ] public_configs = [ ":libuv_config" ] subsystem_name = "thirdparty" -- Gitee From 2998f712e80817220e00dd39f428ec5d4df3f7d9 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Tue, 24 Sep 2024 23:10:29 +0800 Subject: [PATCH 18/33] forbid io_uring Signed-off-by: liaoxingxing --- src/unix/linux.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/unix/linux.c b/src/unix/linux.c index feccbb6..3436fa2 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -481,6 +481,9 @@ int uv__io_uring_register(int fd, unsigned opcode, void* arg, unsigned nargs) { static int uv__use_io_uring(void) { +#if defined(USE_OHOS_DFX) + return 0; +#endif #if defined(__ANDROID_API__) return 0; /* Possibly available but blocked by seccomp. */ #elif defined(__arm__) && __SIZEOF_POINTER__ == 4 -- Gitee From 1b37fc333ee678225c88c08e0814c8191c028e30 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Thu, 26 Sep 2024 10:47:26 +0800 Subject: [PATCH 19/33] =?UTF-8?q?=E5=A2=9E=E5=8A=A0timer=E5=A0=86=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=A8=B3=E5=AE=9A=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- src/heap-inl.h | 17 +++++++++++++++-- src/unix/linux.c | 3 +++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/heap-inl.h b/src/heap-inl.h index 1e2ed60..a919042 100644 --- a/src/heap-inl.h +++ b/src/heap-inl.h @@ -17,6 +17,7 @@ #define UV_SRC_HEAP_H_ #include /* NULL */ +#include "uv_log.h" #if defined(__GNUC__) # define HEAP_EXPORT(declaration) __attribute__((unused)) static declaration @@ -137,6 +138,12 @@ HEAP_EXPORT(void heap_insert(struct heap* heap, /* Insert the new node. */ newnode->parent = *parent; +#ifdef USE_OHOS_DFX + if (child == NULL || newnode == NULL) { + UV_LOGF("Child is NULL, this may be due to multi-threaded calls."); + return; + } +#endif *child = newnode; heap->nelts += 1; @@ -178,11 +185,17 @@ HEAP_EXPORT(void heap_remove(struct heap* heap, k -= 1; } - heap->nelts -= 1; - +#ifdef USE_OHOS_DFX + if (child == NULL) { + UV_LOGF("Child is NULL, this may be due to multi-threaded calls."); + return; + } +#endif + /* Unlink the max node. */ child = *max; *max = NULL; + heap->nelts -= 1; if (child == node) { /* We're removing either the max or the last node in the tree. */ diff --git a/src/unix/linux.c b/src/unix/linux.c index feccbb6..3436fa2 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -481,6 +481,9 @@ int uv__io_uring_register(int fd, unsigned opcode, void* arg, unsigned nargs) { static int uv__use_io_uring(void) { +#if defined(USE_OHOS_DFX) + return 0; +#endif #if defined(__ANDROID_API__) return 0; /* Possibly available but blocked by seccomp. */ #elif defined(__arm__) && __SIZEOF_POINTER__ == 4 -- Gitee From fc449006c34e3fa81329a65437b95077ad63e47f Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Thu, 26 Sep 2024 11:46:37 +0800 Subject: [PATCH 20/33] =?UTF-8?q?=E5=A2=9E=E5=8A=A0timer=E5=A0=86=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=A8=B3=E5=AE=9A=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- src/heap-inl.h | 14 ++++---------- src/unix/linux.c | 3 --- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/heap-inl.h b/src/heap-inl.h index a919042..e3de2a7 100644 --- a/src/heap-inl.h +++ b/src/heap-inl.h @@ -138,12 +138,6 @@ HEAP_EXPORT(void heap_insert(struct heap* heap, /* Insert the new node. */ newnode->parent = *parent; -#ifdef USE_OHOS_DFX - if (child == NULL || newnode == NULL) { - UV_LOGF("Child is NULL, this may be due to multi-threaded calls."); - return; - } -#endif *child = newnode; heap->nelts += 1; @@ -185,16 +179,16 @@ HEAP_EXPORT(void heap_remove(struct heap* heap, k -= 1; } + /* Unlink the max node. */ + child = *max; + *max = NULL; + #ifdef USE_OHOS_DFX if (child == NULL) { UV_LOGF("Child is NULL, this may be due to multi-threaded calls."); return; } #endif - - /* Unlink the max node. */ - child = *max; - *max = NULL; heap->nelts -= 1; if (child == node) { diff --git a/src/unix/linux.c b/src/unix/linux.c index 3436fa2..feccbb6 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -481,9 +481,6 @@ int uv__io_uring_register(int fd, unsigned opcode, void* arg, unsigned nargs) { static int uv__use_io_uring(void) { -#if defined(USE_OHOS_DFX) - return 0; -#endif #if defined(__ANDROID_API__) return 0; /* Possibly available but blocked by seccomp. */ #elif defined(__arm__) && __SIZEOF_POINTER__ == 4 -- Gitee From 5093f53d3698a32e7176c4e916541aa951aab0c7 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Mon, 30 Sep 2024 09:51:22 +0800 Subject: [PATCH 21/33] threadpool modify Signed-off-by: liaoxingxing --- src/threadpool.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/threadpool.c b/src/threadpool.c index edd724f..923a637 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -678,6 +678,10 @@ void uv__work_done(uv_async_t* handle) { uv__queue_append(&lfields->wq_sub[i], &wq); } } + + if (loop->active_reqs > 1000) { + UV_LOGW("there are %{public}u tasks in loop thread", loop->active_reqs); + } #endif uv_mutex_unlock(&loop->wq_mutex); @@ -762,8 +766,8 @@ void uv__ffrt_work(ffrt_executor_task_t* data, ffrt_qos_t qos) #ifdef UV_STATISTIC uv__post_statistic_work(w, WORK_EXECUTING); #endif - uv_work_t* req = container_of(w, uv_work_t, work_req); #ifdef ASYNC_STACKTRACE + uv_work_t* req = container_of(w, uv_work_t, work_req); LibuvSetStackId((uint64_t)req->reserved[3]); #endif w->work(w); @@ -778,8 +782,8 @@ void uv__ffrt_work(ffrt_executor_task_t* data, ffrt_qos_t qos) || !lfields->wq_sub[qos].next || !lfields->wq_sub[qos].prev) { rdunlock_closed_uv_loop_rwlock(); - UV_LOGE("uv_loop(%{public}zu:%{public}#x) in task(%p:%p) is invalid", - (size_t)loop, loop->magic, req->work_cb, req->after_work_cb); + UV_LOGE("uv_loop(%{public}zu:%{public}#x), task is invalid", + (size_t)loop, loop->magic); return; } -- Gitee From 92bfbdd95c27338bc1455653ee0434f1b0e78cc6 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Tue, 8 Oct 2024 18:35:32 +0800 Subject: [PATCH 22/33] =?UTF-8?q?shared=20lib=E4=BD=BF=E7=94=A8=E5=AE=8F?= =?UTF-8?q?=E6=8E=A7=E5=88=B6hilog=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- BUILD.gn | 5 ++--- src/threadpool.c | 10 +++------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index c8d5995..d4564cd 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -350,10 +350,9 @@ if (defined(ohos_lite)) { } ohos_shared_library("uv") { deps = [ ":libuv_source" ] - if (is_linux || is_ohos) { - ldflags = [ "-Wl,--exclude-libs=ALL" ] + if (is_ohos) { + external_deps = [ "hilog:libhilog" ] } - external_deps = [ "hilog:libhilog" ] public_configs = [ ":libuv_config" ] subsystem_name = "thirdparty" innerapi_tags = [ "platformsdk" ] diff --git a/src/threadpool.c b/src/threadpool.c index 923a637..edd724f 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -678,10 +678,6 @@ void uv__work_done(uv_async_t* handle) { uv__queue_append(&lfields->wq_sub[i], &wq); } } - - if (loop->active_reqs > 1000) { - UV_LOGW("there are %{public}u tasks in loop thread", loop->active_reqs); - } #endif uv_mutex_unlock(&loop->wq_mutex); @@ -766,8 +762,8 @@ void uv__ffrt_work(ffrt_executor_task_t* data, ffrt_qos_t qos) #ifdef UV_STATISTIC uv__post_statistic_work(w, WORK_EXECUTING); #endif -#ifdef ASYNC_STACKTRACE uv_work_t* req = container_of(w, uv_work_t, work_req); +#ifdef ASYNC_STACKTRACE LibuvSetStackId((uint64_t)req->reserved[3]); #endif w->work(w); @@ -782,8 +778,8 @@ void uv__ffrt_work(ffrt_executor_task_t* data, ffrt_qos_t qos) || !lfields->wq_sub[qos].next || !lfields->wq_sub[qos].prev) { rdunlock_closed_uv_loop_rwlock(); - UV_LOGE("uv_loop(%{public}zu:%{public}#x), task is invalid", - (size_t)loop, loop->magic); + UV_LOGE("uv_loop(%{public}zu:%{public}#x) in task(%p:%p) is invalid", + (size_t)loop, loop->magic, req->work_cb, req->after_work_cb); return; } -- Gitee From 169decae331e2d978f41178f9d4ed37b8263ffeb Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Wed, 9 Oct 2024 21:01:33 +0800 Subject: [PATCH 23/33] =?UTF-8?q?=E5=9C=A8uv=5F=5Fffrt=5Fwork=E4=B8=AD?= =?UTF-8?q?=E7=A7=BB=E9=99=A4lfields=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- BUILD.gn | 3 --- src/threadpool.c | 18 +++++------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index c8d5995..9d17a31 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -350,9 +350,6 @@ if (defined(ohos_lite)) { } ohos_shared_library("uv") { deps = [ ":libuv_source" ] - if (is_linux || is_ohos) { - ldflags = [ "-Wl,--exclude-libs=ALL" ] - } external_deps = [ "hilog:libhilog" ] public_configs = [ ":libuv_config" ] subsystem_name = "thirdparty" diff --git a/src/threadpool.c b/src/threadpool.c index 923a637..07e0440 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -678,10 +678,6 @@ void uv__work_done(uv_async_t* handle) { uv__queue_append(&lfields->wq_sub[i], &wq); } } - - if (loop->active_reqs > 1000) { - UV_LOGW("there are %{public}u tasks in loop thread", loop->active_reqs); - } #endif uv_mutex_unlock(&loop->wq_mutex); @@ -766,24 +762,19 @@ void uv__ffrt_work(ffrt_executor_task_t* data, ffrt_qos_t qos) #ifdef UV_STATISTIC uv__post_statistic_work(w, WORK_EXECUTING); #endif -#ifdef ASYNC_STACKTRACE uv_work_t* req = container_of(w, uv_work_t, work_req); +#ifdef ASYNC_STACKTRACE LibuvSetStackId((uint64_t)req->reserved[3]); #endif w->work(w); #ifdef UV_STATISTIC uv__post_statistic_work(w, WORK_END); #endif - uv__loop_internal_fields_t* lfields = uv__get_internal_fields(loop); rdlock_closed_uv_loop_rwlock(); - if (loop->magic != UV_LOOP_MAGIC - || !lfields - || qos >= ARRAY_SIZE(lfields->wq_sub) - || !lfields->wq_sub[qos].next - || !lfields->wq_sub[qos].prev) { + if (loop->magic != UV_LOOP_MAGIC) { rdunlock_closed_uv_loop_rwlock(); - UV_LOGE("uv_loop(%{public}zu:%{public}#x), task is invalid", - (size_t)loop, loop->magic); + UV_LOGE("uv_loop(%{public}zu:%{public}#x) in task(%p:%p) is invalid", + (size_t)loop, loop->magic, req->work_cb, req->after_work_cb); return; } @@ -796,6 +787,7 @@ void uv__ffrt_work(ffrt_executor_task_t* data, ffrt_qos_t qos) (UV_EVENT_MAGIC_OFFSET << UV_EVENT_MAGIC_OFFSETBITS)); addr->post_task_func(addr->event_handler, uv__task_done_wrapper, (void*)w, status, qos); } else { + uv__loop_internal_fields_t* lfields = uv__get_internal_fields(loop); uv__queue_insert_tail(&(lfields->wq_sub[qos]), &w->wq); uv_async_send(&loop->wq_async); } -- Gitee From 176929f1e5b099ad358f2b50ff65d672459539c2 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Mon, 14 Oct 2024 15:54:04 +0800 Subject: [PATCH 24/33] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=93=E5=8D=B0activ?= =?UTF-8?q?e=20reqs=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing 增加打印active reqs数量 Signed-off-by: liaoxingxing --- src/threadpool.c | 31 ++++++++++++++++++++++++++++--- src/uv-common.c | 1 + 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/threadpool.c b/src/threadpool.c index 07e0440..6ba7737 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -42,6 +42,11 @@ #define MAX_THREADPOOL_SIZE 1024 #define UV_TRACE_NAME "UV_TRACE" +#ifdef USE_OHOS_DFX +#define MIN_REQS_THRESHOLD 50 +#define MAX_REQS_THRESHOLD 500 +#endif + static uv_rwlock_t g_closed_uv_loop_rwlock; static uv_once_t once = UV_ONCE_INIT; static uv_cond_t cond; @@ -582,9 +587,23 @@ void uv__work_submit(uv_loop_t* loop, #endif +static void uv__print_active_reqs(uv_loop_t* loop) { +#ifdef USE_OHOS_DFX + unsigned int count = loop->active_reqs.count; + if (count == MIN_REQS_THRESHOLD || count == MIN_REQS_THRESHOLD + 5 || + count == MAX_REQS_THRESHOLD || count == MAX_REQS_THRESHOLD + 5) { + UV_LOGW("active reqs:%{public}u", count); + } +#else + return; +#endif +} + + #ifdef USE_FFRT static void uv__task_done_wrapper(void* work, int status) { struct uv__work* w = (struct uv__work*)work; + uv__print_active_reqs(w->loop); w->done(w, status); } #endif @@ -745,6 +764,10 @@ static void uv__queue_done(struct uv__work* w, int err) { } req = container_of(w, uv_work_t, work_req); +#ifdef USE_OHOS_DFX + if (uv_check_data_valid((struct uv_loop_data*)(w->loop->data)) != 0) + uv__print_active_reqs(req->loop); +#endif uv__req_unregister(req->loop, req); if (req->after_work_cb == NULL) @@ -762,8 +785,8 @@ void uv__ffrt_work(ffrt_executor_task_t* data, ffrt_qos_t qos) #ifdef UV_STATISTIC uv__post_statistic_work(w, WORK_EXECUTING); #endif - uv_work_t* req = container_of(w, uv_work_t, work_req); #ifdef ASYNC_STACKTRACE + uv_work_t* req = container_of(w, uv_work_t, work_req); LibuvSetStackId((uint64_t)req->reserved[3]); #endif w->work(w); @@ -773,8 +796,8 @@ void uv__ffrt_work(ffrt_executor_task_t* data, ffrt_qos_t qos) rdlock_closed_uv_loop_rwlock(); if (loop->magic != UV_LOOP_MAGIC) { rdunlock_closed_uv_loop_rwlock(); - UV_LOGE("uv_loop(%{public}zu:%{public}#x) in task(%p:%p) is invalid", - (size_t)loop, loop->magic, req->work_cb, req->after_work_cb); + UV_LOGE("uv_loop(%{public}zu:%{public}#x), task is invalid", + (size_t)loop, loop->magic); return; } @@ -874,6 +897,7 @@ int uv_queue_work(uv_loop_t* loop, if (work_cb == NULL) return UV_EINVAL; + uv__print_active_reqs(loop); uv__req_init(loop, req, UV_WORK); req->loop = loop; req->work_cb = work_cb; @@ -926,6 +950,7 @@ int uv_queue_work_with_qos(uv_loop_t* loop, return UV_EINVAL; } + uv__print_active_reqs(loop); uv__req_init(loop, req, UV_WORK); req->loop = loop; req->work_cb = work_cb; diff --git a/src/uv-common.c b/src/uv-common.c index c766d09..13419f4 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -538,6 +538,7 @@ void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg) { struct uv__queue* q; uv_handle_t* h; + UV_LOGI("clean up handles in loop(%{public}zu)", (size_t)loop); uv__queue_move(&loop->handle_queue, &queue); while (!uv__queue_empty(&queue)) { q = uv__queue_head(&queue); -- Gitee From b3c7bf33443fdf550a58176ec0bb857bb9719673 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Tue, 29 Oct 2024 22:32:15 +0800 Subject: [PATCH 25/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=93=E5=8D=B0req?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- BUILD.gn | 4 ---- include/uv.h | 2 +- libuv.gni | 1 - src/threadpool.c | 27 ++++++++++++++------------- src/unix/async.c | 4 ++-- src/unix/linux.c | 6 +++--- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 6455e11..065945c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -184,10 +184,6 @@ if (defined(ohos_lite)) { defines += [ "ASYNC_STACKTRACE" ] } - if (enable_print_errno_abort && is_ohos) { - defines += [ "PRINT_ERRNO_ABORT" ] - } - if (enable_uv_statisic && is_ohos) { defines += [ "UV_STATISTIC" ] cflags += diff --git a/include/uv.h b/include/uv.h index 945c34e..e36e1ac 100644 --- a/include/uv.h +++ b/include/uv.h @@ -188,7 +188,7 @@ struct uv__queue { XX(GETNAMEINFO, getnameinfo) \ XX(RANDOM, random) \ -#ifdef PRINT_ERRNO_ABORT +#ifdef USE_OHOS_DFX #include "info/fatal_message.h" #define UV_ERRNO_ABORT(...) \ do { \ diff --git a/libuv.gni b/libuv.gni index 9fed6ba..75f8d75 100644 --- a/libuv.gni +++ b/libuv.gni @@ -15,6 +15,5 @@ declare_args() { libuv_use_ffrt = false enable_async_stack = true enable_uv_statisic = false - enable_print_errno_abort = true use_ohos_dfx = true } diff --git a/src/threadpool.c b/src/threadpool.c index 6ba7737..227df0d 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -43,8 +43,9 @@ #define UV_TRACE_NAME "UV_TRACE" #ifdef USE_OHOS_DFX -#define MIN_REQS_THRESHOLD 50 -#define MAX_REQS_THRESHOLD 500 +#define MIN_REQS_THRESHOLD 100 +#define MAX_REQS_THRESHOLD 300 +#define CURSOR 5 #endif static uv_rwlock_t g_closed_uv_loop_rwlock; @@ -587,12 +588,12 @@ void uv__work_submit(uv_loop_t* loop, #endif -static void uv__print_active_reqs(uv_loop_t* loop) { +static void uv__print_active_reqs(uv_loop_t* loop, const char* flag) { #ifdef USE_OHOS_DFX unsigned int count = loop->active_reqs.count; - if (count == MIN_REQS_THRESHOLD || count == MIN_REQS_THRESHOLD + 5 || - count == MAX_REQS_THRESHOLD || count == MAX_REQS_THRESHOLD + 5) { - UV_LOGW("active reqs:%{public}u", count); + if (count == MIN_REQS_THRESHOLD || count == MIN_REQS_THRESHOLD + CURSOR || + count == MAX_REQS_THRESHOLD || count == MAX_REQS_THRESHOLD + CURSOR) { + UV_LOGW("loop:%{public}zu, flag:%{public}s, active reqs:%{public}u", (size_t)loop, flag, count); } #else return; @@ -603,7 +604,7 @@ static void uv__print_active_reqs(uv_loop_t* loop) { #ifdef USE_FFRT static void uv__task_done_wrapper(void* work, int status) { struct uv__work* w = (struct uv__work*)work; - uv__print_active_reqs(w->loop); + uv__print_active_reqs(w->loop, "complete"); w->done(w, status); } #endif @@ -678,6 +679,10 @@ void uv__work_done(uv_async_t* handle) { int nevents; loop = container_of(handle, uv_loop_t, wq_async); +#ifdef USE_OHOS_DFX + if (uv_check_data_valid((struct uv_loop_data*)(loop->data)) != 0) + uv__print_active_reqs(loop, "complete"); +#endif rdlock_closed_uv_loop_rwlock(); if (!is_uv_loop_good_magic(loop)) { rdunlock_closed_uv_loop_rwlock(); @@ -764,10 +769,6 @@ static void uv__queue_done(struct uv__work* w, int err) { } req = container_of(w, uv_work_t, work_req); -#ifdef USE_OHOS_DFX - if (uv_check_data_valid((struct uv_loop_data*)(w->loop->data)) != 0) - uv__print_active_reqs(req->loop); -#endif uv__req_unregister(req->loop, req); if (req->after_work_cb == NULL) @@ -897,7 +898,7 @@ int uv_queue_work(uv_loop_t* loop, if (work_cb == NULL) return UV_EINVAL; - uv__print_active_reqs(loop); + uv__print_active_reqs(loop, "execute"); uv__req_init(loop, req, UV_WORK); req->loop = loop; req->work_cb = work_cb; @@ -950,7 +951,7 @@ int uv_queue_work_with_qos(uv_loop_t* loop, return UV_EINVAL; } - uv__print_active_reqs(loop); + uv__print_active_reqs(loop, "execute"); uv__req_init(loop, req, UV_WORK); req->loop = loop; req->work_cb = work_cb; diff --git a/src/unix/async.c b/src/unix/async.c index dbc66d6..65a029c 100644 --- a/src/unix/async.c +++ b/src/unix/async.c @@ -126,7 +126,7 @@ static void uv__async_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) { if (errno == EINTR) continue; -#ifdef PRINT_ERRNO_ABORT +#ifdef USE_OHOS_DFX UV_ERRNO_ABORT("errno is %d, loop addr is %zu, fd is %d (%s:%s:%d)", errno, (size_t)loop, w->fd, __FILE__, __func__, __LINE__); #else @@ -191,7 +191,7 @@ static void uv__async_send(uv_async_t* handle) { if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) return; -#ifdef PRINT_ERRNO_ABORT +#ifdef USE_OHOS_DFX UV_ERRNO_ABORT("errno is %d, loop addr is %zu, fd is %d (%s:%s:%d)", errno, (size_t)loop, fd, __FILE__, __func__, __LINE__); #else diff --git a/src/unix/linux.c b/src/unix/linux.c index 3436fa2..6517c95 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -1258,7 +1258,7 @@ static void uv__epoll_ctl_prep(int epollfd, return; /* Ignore errors, may be racing with another thread. */ if (op != EPOLL_CTL_ADD) { -#ifdef PRINT_ERRNO_ABORT +#ifdef USE_OHOS_DFX UV_ERRNO_ABORT("errno is %d, fd is %d, backend_fd is %d(%s:%s:%d)", errno, fd, epollfd, __FILE__, __func__, __LINE__); #else @@ -1267,7 +1267,7 @@ static void uv__epoll_ctl_prep(int epollfd, } if (errno != EEXIST) { -#ifdef PRINT_ERRNO_ABORT +#ifdef USE_OHOS_DFX UV_ERRNO_ABORT("errno is %d, fd is %d, backend_fd is %d(%s:%s:%d)", errno, fd, epollfd, __FILE__, __func__, __LINE__); #else @@ -1280,7 +1280,7 @@ static void uv__epoll_ctl_prep(int epollfd, if (!ret) return; -#ifdef PRINT_ERRNO_ABORT +#ifdef USE_OHOS_DFX UV_ERRNO_ABORT("errno is %d, uv__epoll_ctl ret is %d, fd is %d, backend_fd is %d(%s:%s:%d)", errno, ret, fd, epollfd, __FILE__, __func__, __LINE__); #else -- Gitee From aae6997a7219981148334a31c90ab5ca125f2c7b Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Sat, 2 Nov 2024 17:09:04 +0800 Subject: [PATCH 26/33] =?UTF-8?q?loop=E9=80=80=E5=87=BA=E6=97=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=A4=84=E7=90=86signal=5Fpipefd[0]=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- src/unix/signal.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/unix/signal.c b/src/unix/signal.c index 90c8ce2..3e5e303 100644 --- a/src/unix/signal.c +++ b/src/unix/signal.c @@ -21,7 +21,9 @@ #include "uv.h" #include "internal.h" #include "uv_log.h" - +#ifdef USE_FFRT +#include "ffrt_inner.h" +#endif #include #include #include @@ -341,6 +343,11 @@ void uv__signal_loop_cleanup(uv_loop_t* loop) { } if (loop->signal_pipefd[0] != -1) { +#ifdef USE_FFRT + if (ffrt_get_cur_task() != NULL) { + uv__epoll_ctl(loop->backend_fd, EPOLL_CTL_DEL, loop->signal_pipefd[0], NULL); + } +#endif uv__close(loop->signal_pipefd[0]); loop->signal_pipefd[0] = -1; } -- Gitee From e48115c9ddc4006da2bbd18757a21536154e7be3 Mon Sep 17 00:00:00 2001 From: cs1111 Date: Mon, 18 Nov 2024 15:59:39 +0800 Subject: [PATCH 27/33] fix:async stack in libuv Signed-off-by: cs1111 Change-Id: Ibfae56bc3ffba96e773a7cd36353e31629da7fee --- src/threadpool.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/threadpool.c b/src/threadpool.c index 227df0d..bffe852 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -412,10 +412,6 @@ static void worker(void* arg) { w = uv__queue_data(q, struct uv__work, wq); #ifdef UV_STATISTIC uv__post_statistic_work(w, WORK_EXECUTING); -#endif -#ifdef ASYNC_STACKTRACE - uv_work_t* req = container_of(w, uv_work_t, work_req); - LibuvSetStackId((uint64_t)req->reserved[3]); #endif w->work(w); #ifdef UV_STATISTIC @@ -722,10 +718,6 @@ void uv__work_done(uv_async_t* handle) { } dump_work->info = w->info; dump_work->work = uv__update_work_info; -#endif -#ifdef ASYNC_STACKTRACE - uv_work_t* req = container_of(w, uv_work_t, work_req); - LibuvSetStackId((uint64_t)req->reserved[3]); #endif w->done(w, err); nevents++; @@ -755,7 +747,9 @@ void uv__work_done(uv_async_t* handle) { static void uv__queue_work(struct uv__work* w) { uv_work_t* req = container_of(w, uv_work_t, work_req); - +#ifdef ASYNC_STACKTRACE + LibuvSetStackId((uint64_t)req->reserved[3]); +#endif req->work_cb(req); } @@ -769,6 +763,9 @@ static void uv__queue_done(struct uv__work* w, int err) { } req = container_of(w, uv_work_t, work_req); +#ifdef ASYNC_STACKTRACE + LibuvSetStackId((uint64_t)req->reserved[3]); +#endif uv__req_unregister(req->loop, req); if (req->after_work_cb == NULL) @@ -785,10 +782,6 @@ void uv__ffrt_work(ffrt_executor_task_t* data, ffrt_qos_t qos) uv_loop_t* loop = w->loop; #ifdef UV_STATISTIC uv__post_statistic_work(w, WORK_EXECUTING); -#endif -#ifdef ASYNC_STACKTRACE - uv_work_t* req = container_of(w, uv_work_t, work_req); - LibuvSetStackId((uint64_t)req->reserved[3]); #endif w->work(w); #ifdef UV_STATISTIC -- Gitee From 60479bd7f345c1c67363d6a05dda68fd84843f2b Mon Sep 17 00:00:00 2001 From: yongyuan Date: Fri, 29 Nov 2024 00:02:59 +0800 Subject: [PATCH 28/33] commit Signed-off-by: yongyuan --- src/unix/loop.c | 31 ++++++++++++++++++++++++++++++- src/unix/signal.c | 7 +++++++ src/uv-common.h | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/unix/loop.c b/src/unix/loop.c index 2cb896a..71c465d 100644 --- a/src/unix/loop.c +++ b/src/unix/loop.c @@ -28,6 +28,33 @@ #include #include +#ifdef USE_FFRT +#include +#include + +static void uv__get_process_name(char* processName, int bufferLength) { + int fd = open("/proc/self/cmdline", O_RDONLY); + if (fd != -1) { + ssize_t ret = syscall(SYS_read, fd, processName, bufferLength - 1); + if (ret != -1) { + processName[ret] = '\0'; + } + syscall(SYS_close, fd); + } +} + +static void uv__set_signal_flag(uv__loop_internal_fields_t* lfields) { + char processName[1024] = {0}; + uv__get_process_name(processName, sizeof(processName)); + char* c = strstr(processName, "com.atomicservice."); + if (c == NULL || c > processName) { + lfields->trigger = 0; + return; + } + lfields->trigger = 1; +} +#endif + int uv_loop_init(uv_loop_t* loop) { uv__loop_internal_fields_t* lfields; void* saved_data; @@ -42,7 +69,9 @@ int uv_loop_init(uv_loop_t* loop) { if (lfields == NULL) return UV_ENOMEM; loop->internal_fields = lfields; - +#ifdef USE_FFRT + uv__set_signal_flag(lfields); +#endif err = uv_mutex_init(&lfields->loop_metrics.lock); if (err) goto fail_metrics_mutex_init; diff --git a/src/unix/signal.c b/src/unix/signal.c index 3e5e303..cc15b26 100644 --- a/src/unix/signal.c +++ b/src/unix/signal.c @@ -507,7 +507,14 @@ static void uv__signal_event(uv_loop_t* loop, if (msg->signum == handle->signum) { assert(!(handle->flags & UV_HANDLE_CLOSING)); +#ifdef USE_FFRT + uv__loop_internal_fields_t* lfields = uv__get_internal_fields(handle->loop); + if (lfields->trigger != 1) { + handle->signal_cb(handle, handle->signum); + } +#else handle->signal_cb(handle, handle->signum); +#endif } handle->dispatched_signals++; diff --git a/src/uv-common.h b/src/uv-common.h index bc2e300..4a22af7 100644 --- a/src/uv-common.h +++ b/src/uv-common.h @@ -449,6 +449,7 @@ struct uv__loop_internal_fields_s { #endif /* __linux__ */ #ifdef USE_FFRT struct uv__queue wq_sub[4]; + unsigned int trigger; #endif }; -- Gitee From 681eafa8d85f136067c214d40c6d39ec937d6e5f Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Sat, 30 Nov 2024 15:01:38 +0800 Subject: [PATCH 29/33] atomicservice avoid uv_signal function Signed-off-by: liaoxingxing --- src/unix/loop.c | 30 ------------------------------ src/unix/signal.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/unix/loop.c b/src/unix/loop.c index 71c465d..295d572 100644 --- a/src/unix/loop.c +++ b/src/unix/loop.c @@ -28,33 +28,6 @@ #include #include -#ifdef USE_FFRT -#include -#include - -static void uv__get_process_name(char* processName, int bufferLength) { - int fd = open("/proc/self/cmdline", O_RDONLY); - if (fd != -1) { - ssize_t ret = syscall(SYS_read, fd, processName, bufferLength - 1); - if (ret != -1) { - processName[ret] = '\0'; - } - syscall(SYS_close, fd); - } -} - -static void uv__set_signal_flag(uv__loop_internal_fields_t* lfields) { - char processName[1024] = {0}; - uv__get_process_name(processName, sizeof(processName)); - char* c = strstr(processName, "com.atomicservice."); - if (c == NULL || c > processName) { - lfields->trigger = 0; - return; - } - lfields->trigger = 1; -} -#endif - int uv_loop_init(uv_loop_t* loop) { uv__loop_internal_fields_t* lfields; void* saved_data; @@ -69,9 +42,6 @@ int uv_loop_init(uv_loop_t* loop) { if (lfields == NULL) return UV_ENOMEM; loop->internal_fields = lfields; -#ifdef USE_FFRT - uv__set_signal_flag(lfields); -#endif err = uv_mutex_init(&lfields->loop_metrics.lock); if (err) goto fail_metrics_mutex_init; diff --git a/src/unix/signal.c b/src/unix/signal.c index cc15b26..ad3b57f 100644 --- a/src/unix/signal.c +++ b/src/unix/signal.c @@ -23,6 +23,8 @@ #include "uv_log.h" #ifdef USE_FFRT #include "ffrt_inner.h" +#include +#include #endif #include #include @@ -456,6 +458,36 @@ static int uv__signal_start(uv_signal_t* handle, } +#ifdef USE_FFRT +static void uv__get_process_name(char* processName, int bufferLength) { + int fd = open("/proc/self/cmdline", O_RDONLY); + if (fd != -1) { + ssize_t ret = syscall(SYS_read, fd, processName, bufferLength - 1); + if (ret != -1) { + processName[ret] = '\0'; + } + syscall(SYS_close, fd); + } +} + + +static void uv__set_signal_flag(uv__loop_internal_fields_t* lfields) { + static int trigger = -1; + if (trigger == -1) { + char processName[1024] = {0}; + uv__get_process_name(processName, sizeof(processName)); + char* c = strstr(processName, "com.atomicservice."); + if (c == NULL || c > processName) { + trigger = 0; + } else { + trigger = 1; + } + } + lfields->trigger = (unsigned int)trigger; +} +#endif + + static void uv__signal_event(uv_loop_t* loop, uv__io_t* w, unsigned int events) { @@ -467,7 +499,9 @@ static void uv__signal_event(uv_loop_t* loop, bytes = 0; end = 0; - +#ifdef USE_FFRT + uv__set_signal_flag(loop->internal_fields); +#endif do { r = read(loop->signal_pipefd[0], buf + bytes, sizeof(buf) - bytes); -- Gitee From 8c14957c60767d41396f9eea4912ee82ecdcde8c Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Tue, 3 Dec 2024 15:50:39 +0800 Subject: [PATCH 30/33] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=94=AF=E6=8C=81=E6=96=B0=E4=BC=98=E5=85=88?= =?UTF-8?q?=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- include/uv.h | 1 + src/threadpool.c | 5 +++-- src/unix/loop.c | 1 + src/uv-common.h | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/uv.h b/include/uv.h index e36e1ac..0d39684 100644 --- a/include/uv.h +++ b/include/uv.h @@ -1187,6 +1187,7 @@ typedef enum { uv_qos_utility = 1, uv_qos_default = 2, uv_qos_user_initiated = 3, + uv_qos_user_interactive = 4, } uv_qos_t; UV_EXTERN int uv_queue_work_with_qos(uv_loop_t* loop, diff --git a/src/threadpool.c b/src/threadpool.c index bffe852..ee86f7b 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -693,7 +693,7 @@ void uv__work_done(uv_async_t* handle) { uv__loop_internal_fields_t* lfields = uv__get_internal_fields(loop); int i; uv__queue_init(&wq); - for (i = 3; i >= 0; i--) { + for (i = 4; i >= 0; i--) { if (!uv__queue_empty(&lfields->wq_sub[i])) { uv__queue_append(&lfields->wq_sub[i], &wq); } @@ -940,7 +940,8 @@ int uv_queue_work_with_qos(uv_loop_t* loop, STATIC_ASSERT(uv_qos_utility == ffrt_qos_utility); STATIC_ASSERT(uv_qos_default == ffrt_qos_default); STATIC_ASSERT(uv_qos_user_initiated == ffrt_qos_user_initiated); - if (qos < ffrt_qos_background || qos > ffrt_qos_user_initiated) { + STATIC_ASSERT(uv_qos_user_interactive == ffrt_qos_deadline_request); + if (qos < ffrt_qos_background || qos > ffrt_qos_deadline_request) { return UV_EINVAL; } diff --git a/src/unix/loop.c b/src/unix/loop.c index 295d572..9832cd1 100644 --- a/src/unix/loop.c +++ b/src/unix/loop.c @@ -57,6 +57,7 @@ int uv_loop_init(uv_loop_t* loop) { uv__queue_init(&(lfields_qos->wq_sub[uv_qos_utility])); uv__queue_init(&(lfields_qos->wq_sub[uv_qos_default])); uv__queue_init(&(lfields_qos->wq_sub[uv_qos_user_initiated])); + uv__queue_init(&(lfields_qos->wq_sub[uv_qos_user_interactive])); #endif uv__queue_init(&loop->idle_handles); diff --git a/src/uv-common.h b/src/uv-common.h index 4a22af7..bfb0400 100644 --- a/src/uv-common.h +++ b/src/uv-common.h @@ -448,7 +448,7 @@ struct uv__loop_internal_fields_s { void* inv; /* used by uv__platform_invalidate_fd() */ #endif /* __linux__ */ #ifdef USE_FFRT - struct uv__queue wq_sub[4]; + struct uv__queue wq_sub[5]; unsigned int trigger; #endif }; -- Gitee From e09658c7bca6c76b09c1336c687856917ebdd800 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Mon, 23 Dec 2024 21:47:35 +0800 Subject: [PATCH 31/33] =?UTF-8?q?lfields=E7=A7=BB=E9=99=A4trigger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- src/unix/signal.c | 11 +++++------ src/uv-common.h | 1 - 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/unix/signal.c b/src/unix/signal.c index ad3b57f..00089a8 100644 --- a/src/unix/signal.c +++ b/src/unix/signal.c @@ -470,9 +470,9 @@ static void uv__get_process_name(char* processName, int bufferLength) { } } - -static void uv__set_signal_flag(uv__loop_internal_fields_t* lfields) { +static int uv__set_signal_flag() { static int trigger = -1; + if (trigger == -1) { char processName[1024] = {0}; uv__get_process_name(processName, sizeof(processName)); @@ -483,7 +483,7 @@ static void uv__set_signal_flag(uv__loop_internal_fields_t* lfields) { trigger = 1; } } - lfields->trigger = (unsigned int)trigger; + return trigger; } #endif @@ -500,7 +500,7 @@ static void uv__signal_event(uv_loop_t* loop, bytes = 0; end = 0; #ifdef USE_FFRT - uv__set_signal_flag(loop->internal_fields); + unsigned int trigger = uv__set_signal_flag(); #endif do { r = read(loop->signal_pipefd[0], buf + bytes, sizeof(buf) - bytes); @@ -542,8 +542,7 @@ static void uv__signal_event(uv_loop_t* loop, if (msg->signum == handle->signum) { assert(!(handle->flags & UV_HANDLE_CLOSING)); #ifdef USE_FFRT - uv__loop_internal_fields_t* lfields = uv__get_internal_fields(handle->loop); - if (lfields->trigger != 1) { + if (trigger != 1) { handle->signal_cb(handle, handle->signum); } #else diff --git a/src/uv-common.h b/src/uv-common.h index bfb0400..7ca246f 100644 --- a/src/uv-common.h +++ b/src/uv-common.h @@ -449,7 +449,6 @@ struct uv__loop_internal_fields_s { #endif /* __linux__ */ #ifdef USE_FFRT struct uv__queue wq_sub[5]; - unsigned int trigger; #endif }; -- Gitee From 3e21fd9069ef8f3cd335b9134bf428f13896dee5 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Tue, 24 Dec 2024 19:29:02 +0800 Subject: [PATCH 32/33] modify set to get Signed-off-by: liaoxingxing --- src/unix/signal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/unix/signal.c b/src/unix/signal.c index 00089a8..9b644c6 100644 --- a/src/unix/signal.c +++ b/src/unix/signal.c @@ -470,7 +470,7 @@ static void uv__get_process_name(char* processName, int bufferLength) { } } -static int uv__set_signal_flag() { +static int uv__get_signal_flag() { static int trigger = -1; if (trigger == -1) { @@ -500,7 +500,7 @@ static void uv__signal_event(uv_loop_t* loop, bytes = 0; end = 0; #ifdef USE_FFRT - unsigned int trigger = uv__set_signal_flag(); + unsigned int trigger = uv__get_signal_flag(); #endif do { r = read(loop->signal_pipefd[0], buf + bytes, sizeof(buf) - bytes); -- Gitee From b66418c7bf5aafaa7e8415809b870fa01fb9e52b Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Fri, 17 Jan 2025 17:24:25 +0800 Subject: [PATCH 33/33] add fatal log for fd don't belong to uv loop Signed-off-by: liaoxingxing --- src/unix/linux.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unix/linux.c b/src/unix/linux.c index 6517c95..dcf07d4 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -1549,6 +1549,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { * Ignore all errors because we may be racing with another thread * when the file descriptor is closed. */ + UV_LOGF("fd %{public}d don't belong to loop %{public}zu", fd, (size_t)loop); uv__epoll_ctl_prep(epollfd, ctl, &prep, EPOLL_CTL_DEL, fd, pe); continue; } -- Gitee