kernel: implement some more system calls

These are needed to demonstrate the Philosophers demo with threads
running in user mode.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-09-27 14:45:10 -07:00 committed by Andrew Boie
commit 76c04a21ee
3 changed files with 61 additions and 8 deletions

View file

@ -599,7 +599,7 @@ extern FUNC_NORETURN void k_thread_user_mode_enter(k_thread_entry_t entry,
*
* @return N/A
*/
extern void k_sleep(s32_t duration);
__syscall void k_sleep(s32_t duration);
/**
* @brief Cause the current thread to busy wait.
@ -640,7 +640,7 @@ extern void k_wakeup(k_tid_t thread);
*
* @return ID of current thread.
*/
extern k_tid_t k_current_get(void);
__syscall k_tid_t k_current_get(void);
/**
* @brief Cancel thread performing a delayed start.
@ -779,7 +779,7 @@ struct _static_thread_data {
*
* @return Priority of @a thread.
*/
extern int k_thread_priority_get(k_tid_t thread);
__syscall int k_thread_priority_get(k_tid_t thread);
/**
* @brief Set a thread's priority.
@ -1414,7 +1414,7 @@ static inline void k_disable_sys_clock_always_on(void)
*
* @return Current uptime.
*/
extern u32_t k_uptime_get_32(void);
__syscall u32_t k_uptime_get_32(void);
/**
* @brief Get elapsed time.

View file

@ -10,6 +10,7 @@
#include <ksched.h>
#include <wait_q.h>
#include <misc/util.h>
#include <syscall_handler.h>
/* the only struct _kernel instance */
struct _kernel _kernel = {0};
@ -257,11 +258,26 @@ int __must_switch_threads(void)
#endif
}
int k_thread_priority_get(k_tid_t thread)
int _impl_k_thread_priority_get(k_tid_t thread)
{
return thread->base.prio;
}
#ifdef CONFIG_USERSPACE
u32_t _handler_k_thread_priority_get(u32_t arg1, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, u32_t arg6,
void *ssf)
{
struct k_thread *thread;
_SYSCALL_ARG1;
thread = (struct k_thread *)arg1;
_SYSCALL_IS_OBJ(thread, K_OBJ_THREAD, 0, ssf);
return (u32_t)_impl_k_thread_priority_get(thread);
}
#endif
void k_thread_priority_set(k_tid_t tid, int prio)
{
/*
@ -322,7 +338,7 @@ void k_yield(void)
}
}
void k_sleep(s32_t duration)
void _impl_k_sleep(s32_t duration)
{
#ifdef CONFIG_MULTITHREADING
/* volatile to guarantee that irq_lock() is executed after ticks is
@ -352,6 +368,19 @@ void k_sleep(s32_t duration)
#endif
}
#ifdef CONFIG_USERSPACE
u32_t _handler_k_sleep(u32_t arg1, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, u32_t arg6, void *ssf)
{
_SYSCALL_ARG1;
_SYSCALL_VERIFY(arg1 != K_FOREVER, ssf);
_impl_k_sleep(arg1);
return 0;
}
#endif
void k_wakeup(k_tid_t thread)
{
int key = irq_lock();
@ -376,11 +405,21 @@ void k_wakeup(k_tid_t thread)
}
}
k_tid_t k_current_get(void)
k_tid_t _impl_k_current_get(void)
{
return _current;
}
#ifdef CONFIG_USERSPACE
u32_t _handler_k_current_get(u32_t arg1, u32_t arg2, u32_t arg3, u32_t arg4,
u32_t arg5, u32_t arg6, void *ssf)
{
_SYSCALL_ARG0;
return (u32_t)_impl_k_current_get();
}
#endif
#ifdef CONFIG_TIMESLICING
extern s32_t _time_slice_duration; /* Measured in ms */
extern s32_t _time_slice_elapsed; /* Measured in ms */

View file

@ -12,6 +12,7 @@
#include <linker/sections.h>
#include <wait_q.h>
#include <drivers/system_timer.h>
#include <syscall_handler.h>
#ifdef CONFIG_SYS_CLOCK_EXISTS
#ifdef _NON_OPTIMIZED_TICKS_PER_SEC
@ -68,7 +69,7 @@ u32_t _tick_get_32(void)
}
FUNC_ALIAS(_tick_get_32, sys_tick_get_32, u32_t);
u32_t k_uptime_get_32(void)
u32_t _impl_k_uptime_get_32(void)
{
#ifdef CONFIG_TICKLESS_KERNEL
__ASSERT(_sys_clock_always_on,
@ -77,6 +78,19 @@ u32_t k_uptime_get_32(void)
return __ticks_to_ms(_tick_get_32());
}
#ifdef CONFIG_USERSPACE
u32_t _handler_k_uptime_get_32(u32_t arg1, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, u32_t arg6, void *ssf)
{
_SYSCALL_ARG0;
#ifdef CONFIG_TICKLESS_KERNEL
_SYSCALL_VERIFY(_sys_clock_always_on, ssf);
#endif
return _impl_k_uptime_get_32();
}
#endif
/**
*
* @brief Return the current system tick count