From 3ddef29a76ea8141d718b61c7248a579da4edfdb Mon Sep 17 00:00:00 2001 From: yan-mingzhen Date: Sat, 3 Aug 2024 16:01:16 +0800 Subject: [PATCH 01/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] =?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/16] =?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/16] =?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/16] =?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/16] =?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/16] =?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/16] =?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/16] =?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 df413d1664c1ac9b91e9a9a7f65d1faf455eb645 Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Thu, 12 Sep 2024 15:59:05 +0800 Subject: [PATCH 16/16] =?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