kernel/sched: Eliminate PRESTART thread state

Traditionally threads have been initialized with a PRESTART flag set,
which gets cleared when the thread runs for the first time via either
its timeout or the k_thread_start() API.

But if you think about it, this is no different, semantically, than
SUSPENDED: the thread is prevented from running until the flag is
cleared.

So unify the two.  Start threads in the SUSPENDED state, point
everyone looking at the PRESTART bit to the SUSPENDED flag, and make
k_thread_start() be a synonym for k_thread_resume().

There is some mild code size savings from the eliminated duplication,
but the real win here is that we make space in the thread flags byte,
which had run out.

Signed-off-by: Andy Ross <andyross@google.com>
This commit is contained in:
Andy Ross 2024-11-25 07:06:58 -08:00 committed by Anas Nashif
commit 7cdf40541b
13 changed files with 29 additions and 86 deletions

View file

@ -78,11 +78,7 @@ int tm_thread_create(int thread_id, int priority, void (*entry_function)(void *,
*/
int tm_thread_resume(int thread_id)
{
if (test_thread[thread_id].base.thread_state & _THREAD_PRESTART) {
k_thread_start(&test_thread[thread_id]);
} else {
k_thread_resume(&test_thread[thread_id]);
}
k_thread_resume(&test_thread[thread_id]);
return TM_SUCCESS;
}

View file

@ -213,7 +213,7 @@ ZTEST(threads_lifecycle_1cpu, test_k_thread_foreach_unlocked_null_cb)
* @brief Test k_thread_state_str API with null callback
*
* @details It's impossible to sched a thread step by step manually to
* experience each state from _THREAD_PRESTART to _THREAD_DEAD. To cover each
* experience each state from initialization to _THREAD_DEAD. To cover each
* line of function k_thread_state_str(), set thread_state of tdata1 and check
* the string this function returns
*
@ -245,10 +245,6 @@ ZTEST(threads_lifecycle_1cpu, test_k_thread_state_str)
str = k_thread_state_str(tid, state_str, sizeof(state_str));
zassert_str_equal(str, "pending");
tid->base.thread_state = _THREAD_PRESTART;
str = k_thread_state_str(tid, state_str, sizeof(state_str));
zassert_str_equal(str, "prestart");
tid->base.thread_state = _THREAD_DEAD;
str = k_thread_state_str(tid, state_str, sizeof(state_str));
zassert_str_equal(str, "dead");