From: falcovorbis <fal...@us...> - 2024-10-08 08:08:47
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 9e86e5a61343d1745f07e23fd3dad69393950138 (commit) via 2ea7584169179ef8a2d5d1971d8be1007ff93a50 (commit) via 93a780da0b042e4e9a535d3990f74ab416da376c (commit) from dab8d5dbaed1e6820e6eb037fed87c6263351ed6 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 9e86e5a61343d1745f07e23fd3dad69393950138 Merge: 2ea75841 93a780da Author: Donald Haase <qu...@ya...> Date: Tue Oct 8 04:07:35 2024 -0400 Merge pull request #783 from pcercuei/prio-boosting thread: Add priority boosting system commit 2ea7584169179ef8a2d5d1971d8be1007ff93a50 Author: Falco Girgis <gyr...@gm...> Date: Tue Oct 8 02:49:40 2024 -0500 Fixed pvrtex warnings with Clang18 host compiler (#791) * Fixed pvrtex warnings with Clang18 host compiler - A couple of warnings are manifesting in the pvrtex codebase when bulding with a recent verison of Clang. - ATOMIC_INIT() was deprecated in later versions of C, which Clang defaults to now * forcing project to be built uniformly using GNU17 C standard for everyone * got rid of ATOMIC_INIT() usage - Clang correctly diagnosed a set but unused variable in pvrtex... commit 93a780da0b042e4e9a535d3990f74ab416da376c Author: Paul Cercueil <pa...@cr...> Date: Wed Oct 2 16:31:11 2024 +0200 thread: Add priority boosting system Introduce a new 'real_prio' field into the thread structure, which contains the static priority set during the thread creation or with thd_set_prio(). The 'prio' field now represents the dynamic priority. When a low-priority thread A holds a lock, and a high-priority thread B requests it, the dynamic priority of A will be temporarily raised to the dynamic priority of B, until A releases the lock, in which case it falls back to its static priority. The point of this setup is to avoid starvation, where a low-priority thread holds a resource that is needed by a high-priority thread, and won't release it because it rarely gets preempted. This is not yet perfect, as we can imagine a setup where a low-priority thread A holds two locks, each one requested by different high-priority tasts B and C; A would get boosted to B's dynamic priority, and when releasing the lock, reset to its original low priority, causing thread C to starve. Signed-off-by: Paul Cercueil <pa...@cr...> ----------------------------------------------------------------------- Summary of changes: doc/CHANGELOG.md | 1 + include/kos/thread.h | 5 ++++- kernel/thread/mutex.c | 12 ++++++++++++ kernel/thread/thread.c | 2 ++ utils/pvrtex/Makefile | 2 +- utils/pvrtex/mem.c | 2 +- utils/pvrtex/pvr_texture_encoder.c | 6 ++---- 7 files changed, 23 insertions(+), 7 deletions(-) diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index fad4dd20..83a7aed1 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -7,6 +7,7 @@ Platform-specific changes are prefixed with the platform name, otherwise the cha - Added . & .. directories to filesystems that lack it [AB] - Replaced previous implementation of realpath() to remove license from AUTHORS [AB] - Enabled hybrid PVR DR/DMA vertex submission in driver + sped up pvr_prim() [FG] +- Add thread priority boosting system [Paul Cercueil = PC] ## KallistiOS version 2.1.0 - Cleaned up generated stubs files on a make clean [Lawrence Sebald == LS] diff --git a/include/kos/thread.h b/include/kos/thread.h index e5c80a3a..f78d5b81 100644 --- a/include/kos/thread.h +++ b/include/kos/thread.h @@ -182,9 +182,12 @@ typedef __attribute__((aligned(32))) struct kthread { /** \brief Kernel thread id. */ tid_t tid; - /** \brief Static priority: 0..PRIO_MAX (higher means lower priority). */ + /** \brief Dynamic priority */ prio_t prio; + /** \brief Static priority: 0..PRIO_MAX (higher means lower priority). */ + prio_t real_prio; + /** \brief Thread flags. */ kthread_flags_t flags; diff --git a/kernel/thread/mutex.c b/kernel/thread/mutex.c index 38abc2ed..afcd680c 100644 --- a/kernel/thread/mutex.c +++ b/kernel/thread/mutex.c @@ -133,6 +133,15 @@ int mutex_lock_timed(mutex_t *m, int timeout) { deadline = timer_ms_gettime64() + timeout; for(;;) { + if (m->holder->prio >= thd_current->prio) { + m->holder->prio = thd_current->prio; + + /* Thread list is sorted by priority, update the position + * of the thread holding the lock */ + thd_remove_from_runnable(m->holder); + thd_add_to_runnable(m->holder, 0); + } + rv = genwait_wait(m, timeout ? "mutex_lock_timed" : "mutex_lock", timeout, NULL); if(rv < 0) { @@ -253,6 +262,9 @@ static int mutex_unlock_common(mutex_t *m, kthread_t *thd) { return -1; } + if (thd != (kthread_t *)0xffffffff) + thd->prio = thd->real_prio; + /* If we need to wake up a thread, do so. */ if(wakeup) genwait_wake_one(m); diff --git a/kernel/thread/thread.c b/kernel/thread/thread.c index 69c1e8b7..9297d0a1 100644 --- a/kernel/thread/thread.c +++ b/kernel/thread/thread.c @@ -516,6 +516,7 @@ kthread_t *thd_create_ex(const kthread_attr_t *restrict attr, /* Set Thread Pointer */ nt->context.gbr = (uint32_t)nt->tcbhead; nt->tid = tid; + nt->real_prio = real_attr.prio; nt->prio = real_attr.prio; nt->state = STATE_READY; @@ -627,6 +628,7 @@ int thd_set_prio(kthread_t *thd, prio_t prio) { /* Set the new priority */ thd->prio = prio; + thd->real_prio = prio; return 0; } diff --git a/utils/pvrtex/Makefile b/utils/pvrtex/Makefile index f68f5576..87586755 100644 --- a/utils/pvrtex/Makefile +++ b/utils/pvrtex/Makefile @@ -16,7 +16,7 @@ else CXXFLAGS += -O3 endif -CFLAGS := $(CXXFLAGS) -Wno-pointer-sign +CFLAGS := $(CXXFLAGS) -Wno-pointer-sign -std=gnu17 define textSegment2Header mkdir -p info diff --git a/utils/pvrtex/mem.c b/utils/pvrtex/mem.c index 84f3796d..a8357cfe 100644 --- a/utils/pvrtex/mem.c +++ b/utils/pvrtex/mem.c @@ -67,7 +67,7 @@ void free(void *ptr); * dynamic libraries and remove -Wl,-Bsymbolic from the linker flags. * Note that this will cost performance. */ -static atomic_size_t max_alloc_size = ATOMIC_VAR_INIT(INT_MAX); +static atomic_size_t max_alloc_size = INT_MAX; void av_max_alloc(size_t max){ atomic_store_explicit(&max_alloc_size, max, memory_order_relaxed); diff --git a/utils/pvrtex/pvr_texture_encoder.c b/utils/pvrtex/pvr_texture_encoder.c index d101eeb7..c3656068 100644 --- a/utils/pvrtex/pvr_texture_encoder.c +++ b/utils/pvrtex/pvr_texture_encoder.c @@ -837,7 +837,7 @@ void pteAutoSelectPixelFormat(PvrTexEncoder *pte) { assert(pte); assert(pte->src_img_cnt); - unsigned clearpix = 0, halfpix = 0, opaquepix = 0; + unsigned clearpix = 0, halfpix = 0; for(int j = 0; j < pte->src_img_cnt; j++) { pteImage *img = pte->src_imgs + j; @@ -846,9 +846,7 @@ void pteAutoSelectPixelFormat(PvrTexEncoder *pte) { int a = img->pixels[i].a; if (a == 0) clearpix++; - else if (a == 0xff) - opaquepix++; - else + else if (a != 0xff) halfpix++; } } hooks/post-receive -- A pseudo Operating System for the Dreamcast. |