k_current_get(): make it a "const" function
This function always returns the same value for a given thread. Add the const attribute to it so the compiler won't call it over and over needlessly each time _current is referenced, making for far more efficient code. The __attribute_const__ symbol is used to mimic the Linux equivalent. We want to make it clear that this is distinct from the const keyword. Fix the test_x86_cpu_scrubs_regs where the compiler wasn't told that a bunch of registers are being clobbered as highlighted by this change. Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
parent
a0905efa80
commit
0dc7b9ee46
4 changed files with 22 additions and 15 deletions
|
@ -180,6 +180,7 @@ cpp_id_attributes = [
|
|||
"__used",
|
||||
"__unused",
|
||||
"__weak",
|
||||
"__attribute_const__",
|
||||
"__DEPRECATED_MACRO",
|
||||
"FUNC_NORETURN",
|
||||
"__subsystem",
|
||||
|
|
|
@ -528,7 +528,7 @@ __syscall void k_wakeup(k_tid_t thread);
|
|||
* @return ID of current thread.
|
||||
*
|
||||
*/
|
||||
__syscall k_tid_t k_current_get(void);
|
||||
__syscall k_tid_t k_current_get(void) __attribute_const__;
|
||||
|
||||
/**
|
||||
* @brief Abort a thread.
|
||||
|
|
|
@ -190,6 +190,9 @@ do { \
|
|||
#ifndef __deprecated
|
||||
#define __deprecated __attribute__((deprecated))
|
||||
#endif
|
||||
#ifndef __attribute_const__
|
||||
#define __attribute_const__ __attribute__((__const__))
|
||||
#endif
|
||||
#define ARG_UNUSED(x) (void)(x)
|
||||
|
||||
#define likely(x) __builtin_expect((bool)!!(x), true)
|
||||
|
|
|
@ -27,23 +27,26 @@ void z_impl_test_cpu_write_reg(void)
|
|||
#if CONFIG_X86
|
||||
#ifndef CONFIG_X86_64
|
||||
__asm__ volatile (
|
||||
"movl $0xDEADBEEF, %eax;\n\t"
|
||||
"movl $0xDEADBEEF, %ebx;\n\t"
|
||||
"movl $0xDEADBEEF, %ecx;\n\t"
|
||||
"movl $0xDEADBEEF, %edx;\n\t"
|
||||
"movl $0xDEADBEEF, %edi;\n\t"
|
||||
"movl $0xDEADBEEF, %%eax;\n\t"
|
||||
"movl $0xDEADBEEF, %%ebx;\n\t"
|
||||
"movl $0xDEADBEEF, %%ecx;\n\t"
|
||||
"movl $0xDEADBEEF, %%edx;\n\t"
|
||||
"movl $0xDEADBEEF, %%edi;\n\t"
|
||||
: : : "eax", "ebx", "ecx", "edx", "edi"
|
||||
);
|
||||
#else
|
||||
__asm__ volatile (
|
||||
"movq $0xDEADBEEF, %rax;\n\t"
|
||||
"movq $0xDEADBEEF, %rcx;\n\t"
|
||||
"movq $0xDEADBEEF, %rdx;\n\t"
|
||||
"movq $0xDEADBEEF, %rsi;\n\t"
|
||||
"movq $0xDEADBEEF, %rdi;\n\t"
|
||||
"movq $0xDEADBEEF, %r8;\n\t"
|
||||
"movq $0xDEADBEEF, %r9;\n\t"
|
||||
"movq $0xDEADBEEF, %r10;\n\t"
|
||||
"movq $0xDEADBEEF, %r11;\n\t"
|
||||
"movq $0xDEADBEEF, %%rax;\n\t"
|
||||
"movq $0xDEADBEEF, %%rcx;\n\t"
|
||||
"movq $0xDEADBEEF, %%rdx;\n\t"
|
||||
"movq $0xDEADBEEF, %%rsi;\n\t"
|
||||
"movq $0xDEADBEEF, %%rdi;\n\t"
|
||||
"movq $0xDEADBEEF, %%r8;\n\t"
|
||||
"movq $0xDEADBEEF, %%r9;\n\t"
|
||||
"movq $0xDEADBEEF, %%r10;\n\t"
|
||||
"movq $0xDEADBEEF, %%r11;\n\t"
|
||||
: : : "rax", "rcx", "rdx", "rsi", "rdi",
|
||||
"r8", "r9", "r10", "r11"
|
||||
);
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue