aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Forissier <jerome@forissier.org>2020-07-09 19:46:09 +0200
committerJérôme Forissier <jerome@forissier.org>2020-07-14 23:48:08 +0200
commitf86aa9e1925ef129e92324b3d5e1d4c7f0a03e87 (patch)
tree76c0f9e765a7295bb289c3c167d49ecb947e66c6
parent334316feab7445d4cb040ee11dbbf53d61ad2320 (diff)
core: make thread ID a short int
Changes thread_get_id() and thread_get_id_may_fail() to return 'short int' instead of 'int'. That is, 16 bits instead of 32 on all supported architectures which is more than enough since the largest thread ID value is (CFG_NUM_THREADS - 1). Note, struct wait_queue_elem::handle is already a short int. trace_ext_get_thread_id() is not changed (still returns an int) because it is part of the TA API and modifying it would needlessly introduce incompatibilities. Signed-off-by: Jerome Forissier <jerome@forissier.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
-rw-r--r--core/arch/arm/include/kernel/thread.h6
-rw-r--r--core/arch/arm/kernel/mutex_lockdep.c6
-rw-r--r--core/arch/arm/kernel/thread.c10
-rw-r--r--core/arch/arm/kernel/thread_a64.S2
-rw-r--r--core/include/kernel/tee_ta_manager.h2
-rw-r--r--core/kernel/tee_ta_manager.c2
-rw-r--r--lib/libutils/ext/ftrace/ftrace.c2
7 files changed, 16 insertions, 14 deletions
diff --git a/core/arch/arm/include/kernel/thread.h b/core/arch/arm/include/kernel/thread.h
index 98abe26a..c0443e5c 100644
--- a/core/arch/arm/include/kernel/thread.h
+++ b/core/arch/arm/include/kernel/thread.h
@@ -42,7 +42,7 @@ struct thread_core_local {
uint64_t x[4];
#endif
vaddr_t tmp_stack_va_end;
- int curr_thread;
+ short int curr_thread;
uint32_t flags;
vaddr_t abt_stack_va_end;
#ifdef CFG_TEE_CORE_DEBUG
@@ -299,12 +299,12 @@ void thread_clr_boot_thread(void);
/*
* Returns current thread id.
*/
-int thread_get_id(void);
+short int thread_get_id(void);
/*
* Returns current thread id, return -1 on failure.
*/
-int thread_get_id_may_fail(void);
+short int thread_get_id_may_fail(void);
/* Returns Thread Specific Data (TSD) pointer. */
struct thread_specific_data *thread_get_tsd(void);
diff --git a/core/arch/arm/kernel/mutex_lockdep.c b/core/arch/arm/kernel/mutex_lockdep.c
index 144e7b8e..2095c862 100644
--- a/core/arch/arm/kernel/mutex_lockdep.c
+++ b/core/arch/arm/kernel/mutex_lockdep.c
@@ -36,7 +36,7 @@ void mutex_lockdep_init(void)
void mutex_lock_check(struct mutex *m)
{
- int thread = thread_get_id();
+ short int thread = thread_get_id();
uint32_t exceptions = 0;
exceptions = cpu_spin_lock_xsave(&graph_lock);
@@ -46,7 +46,7 @@ void mutex_lock_check(struct mutex *m)
void mutex_trylock_check(struct mutex *m)
{
- int thread = thread_get_id();
+ short int thread = thread_get_id();
uint32_t exceptions = 0;
exceptions = cpu_spin_lock_xsave(&graph_lock);
@@ -56,7 +56,7 @@ void mutex_trylock_check(struct mutex *m)
void mutex_unlock_check(struct mutex *m)
{
- int thread = thread_get_id();
+ short int thread = thread_get_id();
uint32_t exceptions = 0;
exceptions = cpu_spin_lock_xsave(&graph_lock);
diff --git a/core/arch/arm/kernel/thread.c b/core/arch/arm/kernel/thread.c
index 3d876aec..21a00ba3 100644
--- a/core/arch/arm/kernel/thread.c
+++ b/core/arch/arm/kernel/thread.c
@@ -834,23 +834,25 @@ bool thread_init_stack(uint32_t thread_id, vaddr_t sp)
return true;
}
-int thread_get_id_may_fail(void)
+short int thread_get_id_may_fail(void)
{
/*
* thread_get_core_local() requires foreign interrupts to be disabled
*/
uint32_t exceptions = thread_mask_exceptions(THREAD_EXCP_FOREIGN_INTR);
struct thread_core_local *l = thread_get_core_local();
- int ct = l->curr_thread;
+ short int ct = l->curr_thread;
thread_unmask_exceptions(exceptions);
return ct;
}
-int thread_get_id(void)
+short int thread_get_id(void)
{
- int ct = thread_get_id_may_fail();
+ short int ct = thread_get_id_may_fail();
+ /* Thread ID has to fit in a short int */
+ COMPILE_TIME_ASSERT(CFG_NUM_THREADS <= SHRT_MAX);
assert(ct >= 0 && ct < CFG_NUM_THREADS);
return ct;
}
diff --git a/core/arch/arm/kernel/thread_a64.S b/core/arch/arm/kernel/thread_a64.S
index d0df9bf8..74512089 100644
--- a/core/arch/arm/kernel/thread_a64.S
+++ b/core/arch/arm/kernel/thread_a64.S
@@ -16,7 +16,7 @@
#include "thread_private.h"
.macro get_thread_ctx core_local, res, tmp0, tmp1
- ldr w\tmp0, [\core_local, \
+ ldrh w\tmp0, [\core_local, \
#THREAD_CORE_LOCAL_CURR_THREAD]
ldr x\res, =threads
mov x\tmp1, #THREAD_CTX_SIZE
diff --git a/core/include/kernel/tee_ta_manager.h b/core/include/kernel/tee_ta_manager.h
index f8eb7c0f..eb87501b 100644
--- a/core/include/kernel/tee_ta_manager.h
+++ b/core/include/kernel/tee_ta_manager.h
@@ -105,7 +105,7 @@ struct tee_ta_session {
uint32_t ref_count; /* reference counter */
struct condvar refc_cv; /* CV used to wait for ref_count to be 0 */
struct condvar lock_cv; /* CV used to wait for lock */
- int lock_thread; /* Id of thread holding the lock */
+ short int lock_thread; /* Id of thread holding the lock */
bool unlink; /* True if session is to be unlinked */
#if defined(CFG_TA_GPROF_SUPPORT)
struct sample_buf *sbuf; /* Profiling data (PC sampling) */
diff --git a/core/kernel/tee_ta_manager.c b/core/kernel/tee_ta_manager.c
index 82bf2707..deb6754b 100644
--- a/core/kernel/tee_ta_manager.c
+++ b/core/kernel/tee_ta_manager.c
@@ -39,7 +39,7 @@ struct tee_ta_ctx_head tee_ctxes = TAILQ_HEAD_INITIALIZER(tee_ctxes);
#ifndef CFG_CONCURRENT_SINGLE_INSTANCE_TA
static struct condvar tee_ta_cv = CONDVAR_INITIALIZER;
-static int tee_ta_single_instance_thread = THREAD_ID_INVALID;
+static short int tee_ta_single_instance_thread = THREAD_ID_INVALID;
static size_t tee_ta_single_instance_count;
#endif
diff --git a/lib/libutils/ext/ftrace/ftrace.c b/lib/libutils/ext/ftrace/ftrace.c
index bf3d968e..dff56d13 100644
--- a/lib/libutils/ext/ftrace/ftrace.c
+++ b/lib/libutils/ext/ftrace/ftrace.c
@@ -32,7 +32,7 @@ static const char hex_str[] = "0123456789abcdef";
static __noprof struct ftrace_buf *get_fbuf(void)
{
#if defined(__KERNEL__)
- int ct = thread_get_id_may_fail();
+ short int ct = thread_get_id_may_fail();
struct tee_ta_session *s = NULL;
struct thread_specific_data *tsd = NULL;