arch: deprecate _current

`_current` is now functionally equals to `arch_curr_thread()`, remove
its usage in-tree and deprecate it instead of removing it outright,
as it has been with us since forever.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
This commit is contained in:
Yong Cong Sin 2024-11-19 13:57:54 +08:00 committed by Anas Nashif
commit b1def7145f
107 changed files with 490 additions and 479 deletions

View file

@ -135,7 +135,7 @@ static void isr_handler(const void *data)
break;
}
if (_current->base.prio < 0) {
if (arch_current_thread()->base.prio < 0) {
isr_info.value = K_COOP_THREAD;
break;
}
@ -643,9 +643,9 @@ ZTEST(context, test_ctx_thread)
TC_PRINT("Testing k_is_in_isr() from a preemptible thread\n");
zassert_false(k_is_in_isr(), "Should not be in ISR context");
zassert_false(_current->base.prio < 0,
zassert_false(arch_current_thread()->base.prio < 0,
"Current thread should have preemptible priority: %d",
_current->base.prio);
arch_current_thread()->base.prio);
}
@ -683,7 +683,7 @@ static void _test_kernel_thread(k_tid_t _thread_id)
zassert_false(k_is_in_isr(), "k_is_in_isr() when called from a thread is true");
zassert_false((_current->base.prio >= 0),
zassert_false((arch_current_thread()->base.prio >= 0),
"thread is not a cooperative thread");
}

View file

@ -314,7 +314,7 @@ ZTEST(fatal_exception, test_fatal)
* priority -1. To run the test smoothly make both main and ztest
* threads run at same priority level.
*/
k_thread_priority_set(_current, K_PRIO_PREEMPT(MAIN_PRIORITY));
k_thread_priority_set(arch_current_thread(), K_PRIO_PREEMPT(MAIN_PRIORITY));
#ifndef CONFIG_ARCH_POSIX
TC_PRINT("test alt thread 1: generic CPU exception\n");

View file

@ -86,7 +86,7 @@ int main(void)
* panic and not an oops). Set the thread non-essential as a
* workaround.
*/
z_thread_essential_clear(_current);
z_thread_essential_clear(arch_current_thread());
test_message_capture();
return 0;

View file

@ -116,7 +116,7 @@ void thread3_entry(void *p1, void *p2, void *p3)
/* 9.1 - T3 should be executing on the same CPU that T1 was. */
cpu_t3 = _current->base.cpu;
cpu_t3 = arch_current_thread()->base.cpu;
zassert_true(cpu_t3 == cpu_t1, "T3 not executing on T1's original CPU");
@ -136,7 +136,7 @@ void thread4_entry(void *p1, void *p2, void *p3)
* It is expected to execute on the same CPU that T2 did.
*/
cpu_t4 = _current->base.cpu;
cpu_t4 = arch_current_thread()->base.cpu;
zassert_true(cpu_t4 == cpu_t2, "T4 on unexpected CPU");
@ -165,7 +165,7 @@ void thread2_entry(void *p1, void *p2, void *p3)
arch_irq_unlock(key);
}
cpu_t2 = _current->base.cpu;
cpu_t2 = arch_current_thread()->base.cpu;
zassert_false(cpu_t2 == cpu_t1, "T2 and T1 unexpectedly on the same CPU");
@ -205,7 +205,7 @@ ZTEST(ipi_cascade, test_ipi_cascade)
/* 3. T3 and T4 are blocked. Pin T3 to this CPU */
cpu_t1 = _current->base.cpu;
cpu_t1 = arch_current_thread()->base.cpu;
status = k_thread_cpu_pin(&thread3, cpu_t1);
zassert_true(status == 0, "Failed to pin T3 to %d : %d\n", cpu_t1, status);
@ -249,7 +249,7 @@ ZTEST(ipi_cascade, test_ipi_cascade)
zassert_false(timer_expired, "Test terminated by timer");
zassert_true(cpu_t1 != _current->base.cpu,
zassert_true(cpu_t1 != arch_current_thread()->base.cpu,
"Main thread (T1) did not change CPUs\n");
show_executing_threads("Final");

View file

@ -125,7 +125,7 @@ ZTEST(mem_protect, test_permission_inheritance)
struct k_heap *z_impl_ret_resource_pool_ptr(void)
{
return _current->resource_pool;
return arch_current_thread()->resource_pool;
}
static inline struct k_heap *z_vrfy_ret_resource_pool_ptr(void)

View file

@ -132,7 +132,7 @@ ZTEST(object_validation, test_generic_object)
ZTEST(object_validation, test_kobj_assign_perms_on_alloc_obj)
{
static struct k_sem *test_dyn_sem;
struct k_thread *thread = _current;
struct k_thread *thread = arch_current_thread();
uintptr_t start_addr, end_addr;
size_t size_heap = K_HEAP_MEM_POOL_SIZE;
@ -173,7 +173,7 @@ ZTEST(object_validation, test_no_ref_dyn_kobj_release_mem)
zassert_not_null(test_dyn_mutex,
"Can not allocate dynamic kernel object");
struct k_thread *thread = _current;
struct k_thread *thread = arch_current_thread();
/* revoke access from the current thread */
k_object_access_revoke(test_dyn_mutex, thread);

View file

@ -312,7 +312,7 @@ ZTEST_USER(userspace, test_read_kernram)
set_fault(K_ERR_CPU_EXCEPTION);
p = _current->init_data;
p = arch_current_thread()->init_data;
printk("%p\n", p);
zassert_unreachable("Read from kernel RAM did not fault");
}
@ -327,7 +327,7 @@ ZTEST_USER(userspace, test_write_kernram)
/* Try to write to kernel RAM. */
set_fault(K_ERR_CPU_EXCEPTION);
_current->init_data = NULL;
arch_current_thread()->init_data = NULL;
zassert_unreachable("Write to kernel RAM did not fault");
}
@ -1038,11 +1038,11 @@ ZTEST(userspace, test_tls_leakage)
* supervisor mode to be leaked
*/
memset(_current->userspace_local_data, 0xff,
memset(arch_current_thread()->userspace_local_data, 0xff,
sizeof(struct _thread_userspace_local_data));
k_thread_user_mode_enter(tls_leakage_user_part,
_current->userspace_local_data, NULL, NULL);
arch_current_thread()->userspace_local_data, NULL, NULL);
#else
ztest_test_skip();
#endif

View file

@ -318,8 +318,9 @@ ZTEST(smp, test_coop_switch_in_abort)
unsigned int num_threads = arch_num_cpus();
unsigned int i;
zassert_true(_current->base.prio < 0, "test case relies on ztest thread be cooperative");
zassert_true(_current->base.prio > SPAWN_AB_PRIO,
zassert_true(arch_current_thread()->base.prio < 0,
"test case relies on ztest thread be cooperative");
zassert_true(arch_current_thread()->base.prio > SPAWN_AB_PRIO,
"spawn test need to have higher priority than ztest thread");
/* Spawn N number of cooperative threads, where N = number of CPUs */
@ -869,15 +870,15 @@ static void t2_mutex_lock(void *p1, void *p2, void *p3)
ARG_UNUSED(p2);
ARG_UNUSED(p3);
zassert_equal(_current->base.global_lock_count, 0,
zassert_equal(arch_current_thread()->base.global_lock_count, 0,
"thread global lock cnt %d is incorrect",
_current->base.global_lock_count);
arch_current_thread()->base.global_lock_count);
k_mutex_lock((struct k_mutex *)p1, K_FOREVER);
zassert_equal(_current->base.global_lock_count, 0,
zassert_equal(arch_current_thread()->base.global_lock_count, 0,
"thread global lock cnt %d is incorrect",
_current->base.global_lock_count);
arch_current_thread()->base.global_lock_count);
k_mutex_unlock((struct k_mutex *)p1);
@ -885,9 +886,9 @@ static void t2_mutex_lock(void *p1, void *p2, void *p3)
* context switch but global_lock_cnt has not been decrease
* because no irq_lock() was called.
*/
zassert_equal(_current->base.global_lock_count, 0,
zassert_equal(arch_current_thread()->base.global_lock_count, 0,
"thread global lock cnt %d is incorrect",
_current->base.global_lock_count);
arch_current_thread()->base.global_lock_count);
}
/**

View file

@ -232,7 +232,7 @@ static void umode_entry(void *thread_id, void *p2, void *p3)
ARG_UNUSED(p2);
ARG_UNUSED(p3);
if (!z_is_thread_essential(_current) &&
if (!z_is_thread_essential(arch_current_thread()) &&
(k_current_get() == (k_tid_t)thread_id)) {
ztest_test_pass();
} else {
@ -249,9 +249,9 @@ static void umode_entry(void *thread_id, void *p2, void *p3)
*/
static void enter_user_mode_entry(void *p1, void *p2, void *p3)
{
z_thread_essential_set(_current);
z_thread_essential_set(arch_current_thread());
zassert_true(z_is_thread_essential(_current), "Thread isn't set"
zassert_true(z_is_thread_essential(arch_current_thread()), "Thread isn't set"
" as essential\n");
k_thread_user_mode_enter(umode_entry,

View file

@ -27,16 +27,16 @@ static void thread_entry(void *p1, void *p2, void *p3)
ARG_UNUSED(p2);
ARG_UNUSED(p3);
z_thread_essential_set(_current);
z_thread_essential_set(arch_current_thread());
if (z_is_thread_essential(_current)) {
if (z_is_thread_essential(arch_current_thread())) {
k_busy_wait(100);
} else {
zassert_unreachable("The thread is not set as essential");
}
z_thread_essential_clear(_current);
zassert_false(z_is_thread_essential(_current),
z_thread_essential_clear(arch_current_thread());
zassert_false(z_is_thread_essential(arch_current_thread()),
"Essential flag of the thread is not cleared");
k_sem_give(&sync_sem);
@ -68,7 +68,7 @@ void k_sys_fatal_error_handler(unsigned int reason,
fatal_error_signaled = true;
z_thread_essential_clear(_current);
z_thread_essential_clear(arch_current_thread());
}
static void abort_thread_entry(void *p1, void *p2, void *p3)
@ -77,9 +77,9 @@ static void abort_thread_entry(void *p1, void *p2, void *p3)
ARG_UNUSED(p2);
ARG_UNUSED(p3);
z_thread_essential_set(_current);
z_thread_essential_set(arch_current_thread());
if (z_is_thread_essential(_current)) {
if (z_is_thread_essential(arch_current_thread())) {
k_busy_wait(100);
} else {
zassert_unreachable("The thread is not set as essential");

View file

@ -72,7 +72,7 @@ ZTEST(usage_api, test_all_stats_usage)
k_thread_runtime_stats_t stats4;
k_thread_runtime_stats_t stats5;
priority = k_thread_priority_get(_current);
priority = k_thread_priority_get(arch_current_thread());
tid = k_thread_create(&helper_thread, helper_stack,
K_THREAD_STACK_SIZEOF(helper_stack),
helper1, NULL, NULL, NULL,
@ -196,7 +196,7 @@ ZTEST(usage_api, test_thread_stats_enable_disable)
k_thread_runtime_stats_t helper_stats3;
int priority;
priority = k_thread_priority_get(_current);
priority = k_thread_priority_get(arch_current_thread());
tid = k_thread_create(&helper_thread, helper_stack,
K_THREAD_STACK_SIZEOF(helper_stack),
helper1, NULL, NULL, NULL,
@ -209,7 +209,7 @@ ZTEST(usage_api, test_thread_stats_enable_disable)
k_sleep(K_TICKS(5));
k_thread_runtime_stats_get(_current, &stats1);
k_thread_runtime_stats_get(arch_current_thread(), &stats1);
k_thread_runtime_stats_get(tid, &helper_stats1);
k_thread_runtime_stats_disable(tid);
@ -225,7 +225,7 @@ ZTEST(usage_api, test_thread_stats_enable_disable)
k_sleep(K_TICKS(2));
k_thread_runtime_stats_enable(tid);
k_thread_runtime_stats_get(_current, &stats2);
k_thread_runtime_stats_get(arch_current_thread(), &stats2);
k_thread_runtime_stats_get(tid, &helper_stats2);
/* Sleep for two ticks to let the helper thread execute again. */
@ -280,12 +280,12 @@ ZTEST(usage_api, test_sys_stats_enable_disable)
k_sys_runtime_stats_disable();
k_thread_runtime_stats_get(_current, &thread_stats1);
k_thread_runtime_stats_get(arch_current_thread(), &thread_stats1);
k_thread_runtime_stats_all_get(&sys_stats1);
busy_loop(2);
k_thread_runtime_stats_get(_current, &thread_stats2);
k_thread_runtime_stats_get(arch_current_thread(), &thread_stats2);
k_thread_runtime_stats_all_get(&sys_stats2);
/*
@ -297,7 +297,7 @@ ZTEST(usage_api, test_sys_stats_enable_disable)
busy_loop(2);
k_thread_runtime_stats_get(_current, &thread_stats3);
k_thread_runtime_stats_get(arch_current_thread(), &thread_stats3);
k_thread_runtime_stats_all_get(&sys_stats3);
/*
@ -398,7 +398,7 @@ ZTEST(usage_api, test_thread_stats_usage)
k_thread_runtime_stats_t stats2;
k_thread_runtime_stats_t stats3;
priority = k_thread_priority_get(_current);
priority = k_thread_priority_get(arch_current_thread());
/*
* Verify that k_thread_runtime_stats_get() returns the expected
@ -408,7 +408,7 @@ ZTEST(usage_api, test_thread_stats_usage)
status = k_thread_runtime_stats_get(NULL, &stats1);
zassert_true(status == -EINVAL);
status = k_thread_runtime_stats_get(_current, NULL);
status = k_thread_runtime_stats_get(arch_current_thread(), NULL);
zassert_true(status == -EINVAL);
/* Align to the next tick */
@ -422,7 +422,7 @@ ZTEST(usage_api, test_thread_stats_usage)
helper1, NULL, NULL, NULL,
priority + 2, 0, K_TICKS(1));
main_thread = _current;
main_thread = arch_current_thread();
k_timer_init(&timer, resume_main, NULL);
k_timer_start(&timer, K_TICKS(1), K_TICKS(10));
@ -440,7 +440,7 @@ ZTEST(usage_api, test_thread_stats_usage)
* the helper threads runtime stats.
*/
k_thread_suspend(_current);
k_thread_suspend(arch_current_thread());
/*
* T = 1.
@ -449,14 +449,14 @@ ZTEST(usage_api, test_thread_stats_usage)
*/
k_thread_runtime_stats_get(tid, &stats1);
k_thread_suspend(_current);
k_thread_suspend(arch_current_thread());
/*
* T = 11.
* Timer woke the main thread. Suspend main thread again.
*/
k_thread_suspend(_current);
k_thread_suspend(arch_current_thread());
/*
* T = 21.
@ -465,7 +465,7 @@ ZTEST(usage_api, test_thread_stats_usage)
*/
k_thread_runtime_stats_get(tid, &stats2);
k_thread_suspend(_current);
k_thread_suspend(arch_current_thread());
/*
* T = 31.