From 2e9badffcec60213ec4843b7df3296e5dbb9818a Mon Sep 17 00:00:00 2001 From: SupervisedThinking Date: Wed, 19 Oct 2022 12:23:07 +0200 Subject: [PATCH 1/2] tbb: update to 2021.7.0 --- packages/devel/tbb/package.mk | 4 +- ...-if-pthread_create-fails-with-EAGAIN.patch | 142 +++++++++++++++--- 2 files changed, 123 insertions(+), 23 deletions(-) diff --git a/packages/devel/tbb/package.mk b/packages/devel/tbb/package.mk index 98deba01bf..791b57fe32 100644 --- a/packages/devel/tbb/package.mk +++ b/packages/devel/tbb/package.mk @@ -2,8 +2,8 @@ # Copyright (C) 2022-present Team LibreELEC (https://libreelec.tv) PKG_NAME="tbb" -PKG_VERSION="2021.6.0" -PKG_SHA256="4897dd106d573e9dacda8509ca5af1a0e008755bf9c383ef6777ac490223031f" +PKG_VERSION="2021.7.0" +PKG_SHA256="2cae2a80cda7d45dc7c072e4295c675fff5ad8316691f26f40539f7e7e54c0cc" PKG_LICENSE="Apache-2.0" PKG_SITE="https://github.com/oneapi-src/oneTBB" PKG_URL="https://github.com/oneapi-src/oneTBB/archive/refs/tags/v${PKG_VERSION}.tar.gz" diff --git a/packages/devel/tbb/patches/tbb-999.01-PR824-retry-if-pthread_create-fails-with-EAGAIN.patch b/packages/devel/tbb/patches/tbb-999.01-PR824-retry-if-pthread_create-fails-with-EAGAIN.patch index 7188839905..72d557a566 100644 --- a/packages/devel/tbb/patches/tbb-999.01-PR824-retry-if-pthread_create-fails-with-EAGAIN.patch +++ b/packages/devel/tbb/patches/tbb-999.01-PR824-retry-if-pthread_create-fails-with-EAGAIN.patch @@ -1,4 +1,4 @@ -From f12c93efd04991bc982a27e2fa6142538c33ca82 Mon Sep 17 00:00:00 2001 +From 3a8bc6478654afcbd219f45e7ea01353c2d57eb6 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 7 May 2022 19:55:24 +0800 Subject: [PATCH] Retry if pthread_create fails with EAGAIN @@ -20,11 +20,14 @@ systems support it. Signed-off-by: Rui Ueyama --- - src/tbb/rml_thread_monitor.h | 19 ++++++++++++++++++- - 1 file changed, 18 insertions(+), 1 deletion(-) + src/tbb/rml_thread_monitor.h | 30 +++++++++++++++- + test/CMakeLists.txt | 3 ++ + test/tbb/test_pthread_create.cpp | 59 ++++++++++++++++++++++++++++++++ + 3 files changed, 91 insertions(+), 1 deletion(-) + create mode 100644 test/tbb/test_pthread_create.cpp diff --git a/src/tbb/rml_thread_monitor.h b/src/tbb/rml_thread_monitor.h -index 13b556380..5b844b232 100644 +index 13b556380..dc046ba00 100644 --- a/src/tbb/rml_thread_monitor.h +++ b/src/tbb/rml_thread_monitor.h @@ -31,6 +31,7 @@ @@ -35,29 +38,126 @@ index 13b556380..5b844b232 100644 #else #error Unsupported platform #endif -@@ -191,8 +192,24 @@ inline thread_monitor::handle_type thread_monitor::launch( void* (*thread_routin +@@ -183,6 +184,32 @@ inline void thread_monitor::check( int error_code, const char* routine ) { + } + } + ++// pthread_create(2) can spuriously fail on Linux. This is a function ++// to wrap pthread_create(2) to retry if it fails with EAGAIN. ++inline void do_pthread_create(pthread_t *handle, pthread_attr_t *s, void* (*thread_routine)(void*), void* arg) { ++#ifdef __linux__ ++ int tries = 0; ++ const int max_num_tries = 20; ++ ++ for (;;) { ++ int error_code = pthread_create(handle, s, thread_routine, arg); ++ if (!error_code) ++ break; ++ if (error_code != EAGAIN || tries++ > max_num_tries) { ++ handle_perror(error_code, "pthread_create has failed"); ++ break; ++ } ++ ++ // Retry after tries * 1 millisecond. ++ struct timespec ts = {0, tries * 1000 * 1000}; ++ nanosleep(&ts, NULL); ++ } ++#else ++ if (int error_code = pthread_create(handle, s, thread_routine, arg)) ++ handle_perror(error_code, "pthread_create has failed"); ++#endif ++} ++ + inline thread_monitor::handle_type thread_monitor::launch( void* (*thread_routine)(void*), void* arg, std::size_t stack_size ) { + // FIXME - consider more graceful recovery than just exiting if a thread cannot be launched. + // Note that there are some tricky situations to deal with, such that the thread is already +@@ -191,8 +218,9 @@ inline thread_monitor::handle_type thread_monitor::launch( void* (*thread_routin check(pthread_attr_init( &s ), "pthread_attr_init has failed"); if( stack_size>0 ) check(pthread_attr_setstacksize( &s, stack_size ), "pthread_attr_setstack_size has failed" ); + pthread_t handle; - check( pthread_create( &handle, &s, thread_routine, arg ), "pthread_create has failed" ); -+ int tries = 0; -+ for (;;) { -+ int error_code = pthread_create(&handle, &s, thread_routine, arg); -+ if (!error_code) -+ break; -+ if (error_code != EAGAIN || tries++ > 20) { -+ handle_perror(error_code, "pthread_create has failed"); -+ break; -+ } -+ -+ // pthreaed_create can spuriously fail on many Unix-like systems. -+ // Retry after tries * 1 millisecond. -+ struct timespec ts = {0, tries * 1000 * 1000}; -+ nanosleep(&ts, NULL); -+ } -+ ++ do_pthread_create(&handle, &s, thread_routine, arg); check( pthread_attr_destroy( &s ), "pthread_attr_destroy has failed" ); return handle; } +diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt +index f15679e83..92802b015 100644 +--- a/test/CMakeLists.txt ++++ b/test/CMakeLists.txt +@@ -373,6 +373,9 @@ if (TARGET TBB::tbb) + if (APPLE OR ANDROID_PLATFORM) + target_link_libraries(test_dynamic_link PRIVATE -rdynamic) # for the test_dynamic_link + endif() ++ if (UNIX AND NOT APPLE) ++ tbb_add_test(SUBDIR tbb NAME test_pthread_create DEPENDENCIES TBB::tbb) ++ endif() + tbb_add_test(SUBDIR tbb NAME test_collaborative_call_once DEPENDENCIES TBB::tbb) + tbb_add_test(SUBDIR tbb NAME test_concurrent_lru_cache DEPENDENCIES TBB::tbb) + tbb_add_test(SUBDIR tbb NAME test_concurrent_unordered_map DEPENDENCIES TBB::tbb) +diff --git a/test/tbb/test_pthread_create.cpp b/test/tbb/test_pthread_create.cpp +new file mode 100644 +index 000000000..4cb1f4ea5 +--- /dev/null ++++ b/test/tbb/test_pthread_create.cpp +@@ -0,0 +1,59 @@ ++/* ++ Copyright (c) 2005-2022 Intel Corporation ++ ++ 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 ++ ++ http://www.apache.org/licenses/LICENSE-2.0 ++ ++ 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 "common/test.h" ++#include "common/utils.h" ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++//! Test that thread pool creation won't be affected with a spurious failure of pthread_create(). ++//! \brief \ref error_guessing ++TEST_CASE("pthread_create is not affected by fork") { ++ std::atomic_bool done; ++ ++ std::thread thr([&]() { ++ while (!done) { ++ pid_t pid = fork(); ++ CHECK(pid != -1); ++ ++ if (pid == 0) { ++ // child ++ _exit(0); ++ } else { ++ int wstatus; ++ do { ++ pid_t pid2 = waitpid(pid, &wstatus, 0); ++ CHECK(pid2 != -1); ++ } while (!WIFEXITED(wstatus) && !WIFSIGNALED(wstatus)); ++ } ++ } ++ }); ++ ++ for (int i = 0; i < 50; i++) { ++ tbb::task_scheduler_handle handle{tbb::attach{}}; ++ tbb::parallel_for(0, 10000, [](int) {}); ++ tbb::finalize(handle); ++ } ++ ++ done = true; ++ thr.join(); ++} From 90ebb32ebc992ecafa823ac4679e424687628a3a Mon Sep 17 00:00:00 2001 From: SupervisedThinking Date: Wed, 19 Oct 2022 12:23:34 +0200 Subject: [PATCH 2/2] mold: update to 1.6.0 - drop upstreamed patch --- packages/devel/mold/package.mk | 4 ++-- ...llow-custom-mold-binary-install-path.patch | 24 ------------------- 2 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 packages/devel/mold/patches/mold-999.01-PR740-allow-custom-mold-binary-install-path.patch diff --git a/packages/devel/mold/package.mk b/packages/devel/mold/package.mk index 25b283088b..0802cea170 100644 --- a/packages/devel/mold/package.mk +++ b/packages/devel/mold/package.mk @@ -2,8 +2,8 @@ # Copyright (C) 2022-present Team LibreELEC (https://libreelec.tv) PKG_NAME="mold" -PKG_VERSION="1.5.1" -PKG_SHA256="ec94aa74758f1bc199a732af95c6304ec98292b87f2f4548ce8436a7c5b054a1" +PKG_VERSION="1.6.0" +PKG_SHA256="59cd3ea1a2a5fb50d0d97faddd8bff4c7e71054a576c00a87b17f56ecbd88729" PKG_LICENSE="AGPL-3.0-or-later" PKG_SITE="https://github.com/rui314/mold" PKG_URL="https://github.com/rui314/mold/archive/refs/tags/v${PKG_VERSION}.tar.gz" diff --git a/packages/devel/mold/patches/mold-999.01-PR740-allow-custom-mold-binary-install-path.patch b/packages/devel/mold/patches/mold-999.01-PR740-allow-custom-mold-binary-install-path.patch deleted file mode 100644 index 0ecca3b06e..0000000000 --- a/packages/devel/mold/patches/mold-999.01-PR740-allow-custom-mold-binary-install-path.patch +++ /dev/null @@ -1,24 +0,0 @@ -From f7f2ef6182d058f7c58401d9278aa3136cb996f5 Mon Sep 17 00:00:00 2001 -From: SupervisedThinking -Date: Thu, 29 Sep 2022 11:49:57 +0200 -Subject: [PATCH] CMakeLists: allow custom mold binary install path - -- https://cmake.org/cmake/help/latest/command/install.html -- ${CMAKE_INSTALL_BINDIR} defaults to bin if not set ---- - CMakeLists.txt | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 7136cf2b..4542f915 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -287,7 +287,7 @@ if(BUILD_TESTING) - endif() - - if(NOT CMAKE_SKIP_INSTALL_RULES) -- install(TARGETS mold RUNTIME DESTINATION bin) -+ install(TARGETS mold RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR}) - install(FILES docs/mold.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1/) - install(CODE "