From 29260f3ff51eeda673ed1189f05c130bc9bdbf59 Mon Sep 17 00:00:00 2001 From: chencheng Date: Tue, 7 May 2024 15:42:22 +0800 Subject: [PATCH 1/3] lib/tntimer: Fix semaphore operation cause tntimer endless loop Signed-off-by: chencheng --- lib/tntimer/tntimer.c | 6 +++--- lib/uksched/include/uk/wait.h | 6 ++++-- lib/uksched/thread.c | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/tntimer/tntimer.c b/lib/tntimer/tntimer.c index 3b2450a2..5a01204e 100644 --- a/lib/tntimer/tntimer.c +++ b/lib/tntimer/tntimer.c @@ -96,7 +96,7 @@ void tn_timer_delete(struct timer *t) { UK_ASSERT(t); - uk_list_del(&t->list); + uk_list_del_init(&t->list); if (timoutListsOverflowed && uk_list_empty(&timer_list_head)) tn_timer_list_switch(); } @@ -173,7 +173,7 @@ void tn_timer_announce(void) t = uk_list_first_entry( &timer_list_head, struct timer, list); - uk_list_del(&t->list); + uk_list_del_init(&t->list); t->timeout_func(t->parameter); if (t->flag & TN_TIMER_FLAG_PERIODIC) tn_timer_start(t); @@ -188,7 +188,7 @@ void tn_timer_announce(void) t = uk_list_first_entry( &timer_list_head, struct timer, list); if (t->timeout_tick <= cur) { - uk_list_del(&t->list); + uk_list_del_init(&t->list); t->timeout_func(t->parameter); if (t->flag & TN_TIMER_FLAG_PERIODIC) tn_timer_start(t); diff --git a/lib/uksched/include/uk/wait.h b/lib/uksched/include/uk/wait.h index 0d5b4eb3..94f566a3 100644 --- a/lib/uksched/include/uk/wait.h +++ b/lib/uksched/include/uk/wait.h @@ -113,8 +113,9 @@ do { \ break; \ } \ uk_waitq_add(wq, &__wait); \ - TN_THREAD_TIMER_START(__current, ns_to_ticks( \ - deadline - ukplat_monotonic_clock())); \ + if (deadline != 0) \ + TN_THREAD_TIMER_START(__current, ns_to_ticks( \ + deadline - ukplat_monotonic_clock())); \ uk_thread_set_blocked(__current); \ uk_sched_thread_blocked(__current); \ ukplat_spin_unlock_irqrestore(&((wq)->sl), \ @@ -203,6 +204,7 @@ void uk_waitq_wake_up(struct uk_waitq *wq) _waitq_foreach_safe(curr, &(wq->wait_list), thread_list, tmp) { uk_thread_wake(curr->thread); + tn_timer_delete(&curr->thread->timer); } ukplat_spin_unlock_irqrestore(&(wq->sl), flags); diff --git a/lib/uksched/thread.c b/lib/uksched/thread.c index a3064b8a..c7b20087 100644 --- a/lib/uksched/thread.c +++ b/lib/uksched/thread.c @@ -246,6 +246,7 @@ static void _uk_thread_struct_init(struct uk_thread *t, t->priv = priv; t->dtor = dtor; t->exec_time = 0; + UK_INIT_LIST_HEAD(&t->timer.list); #ifdef CONFIG_LIBUKSCHED_THREAD_PRIORITY t->prio = prio; -- Gitee From b26d0e0bd332b8219c4e4e7a528002592957bda7 Mon Sep 17 00:00:00 2001 From: chencheng Date: Tue, 7 May 2024 17:24:57 +0800 Subject: [PATCH 2/3] lib/tntimer: Fix rwlock operation may cause tntimer endless loop Signed-off-by: chencheng --- lib/uksched/include/uk/wait.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/uksched/include/uk/wait.h b/lib/uksched/include/uk/wait.h index 94f566a3..d4f850be 100644 --- a/lib/uksched/include/uk/wait.h +++ b/lib/uksched/include/uk/wait.h @@ -149,8 +149,9 @@ do { \ __current = uk_thread_current(); \ ukplat_spin_lock_irqsave(&((wq)->sl), flags); \ uk_waitq_add(wq, &__wait); \ - TN_THREAD_TIMER_START(__current, ns_to_ticks( \ - deadline - ukplat_monotonic_clock())); \ + if (deadline != 0) \ + TN_THREAD_TIMER_START(__current, ns_to_ticks( \ + deadline - ukplat_monotonic_clock())); \ uk_thread_set_blocked(__current); \ uk_sched_thread_blocked(__current); \ ukplat_spin_unlock_irqrestore(&((wq)->sl), flags); \ @@ -219,8 +220,10 @@ void uk_waitq_wake_up_one(struct uk_waitq *wq) ukplat_spin_lock_irqsave(&(wq->sl), flags); head = _waitq_best(wq); - if (head) + if (head) { uk_thread_wake(head->thread); + tn_timer_delete(&head->thread->timer); + } ukplat_spin_unlock_irqrestore(&(wq->sl), flags); if (head) uk_sched_reschedule(); -- Gitee From 0a1140020953a8e79eeb6cc769fc4a4e478568a0 Mon Sep 17 00:00:00 2001 From: chencheng Date: Tue, 7 May 2024 18:23:18 +0800 Subject: [PATCH 3/3] lib/tntimer: Fix rwlock operation may cause tntimer endless loop Signed-off-by: chencheng --- lib/uksched/include/uk/wait.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/uksched/include/uk/wait.h b/lib/uksched/include/uk/wait.h index d4f850be..ce1039a6 100644 --- a/lib/uksched/include/uk/wait.h +++ b/lib/uksched/include/uk/wait.h @@ -114,8 +114,11 @@ do { \ } \ uk_waitq_add(wq, &__wait); \ if (deadline != 0) \ - TN_THREAD_TIMER_START(__current, ns_to_ticks( \ - deadline - ukplat_monotonic_clock())); \ + TN_THREAD_TIMER_START( \ + __current, \ + ns_to_ticks( \ + deadline \ + - ukplat_monotonic_clock())); \ uk_thread_set_blocked(__current); \ uk_sched_thread_blocked(__current); \ ukplat_spin_unlock_irqrestore(&((wq)->sl), \ -- Gitee