[pok-devel] [43] implement DELAYED_START |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/pok-devel Archives
]
Revision: 43
Author: jrosen
Date: 2012-10-05 18:34:19 +0200 (Fri, 05 Oct 2012)
Log Message:
-----------
implement DELAYED_START
Modified Paths:
--------------
trunk/kernel/arch/ppc/thread.c
trunk/kernel/arch/sparc/thread.c
trunk/kernel/arch/x86/thread.c
trunk/kernel/arch/x86/thread.h
trunk/kernel/core/partition.c
trunk/kernel/core/syscall.c
trunk/kernel/core/thread.c
trunk/kernel/include/arch.h
trunk/kernel/include/core/syscall.h
trunk/kernel/include/core/thread.h
trunk/libpok/arinc653/process.c
trunk/libpok/core/Makefile
trunk/libpok/include/core/syscall.h
trunk/libpok/include/core/thread.h
trunk/misc/release-files
Added Paths:
-----------
trunk/libpok/core/threaddelayedstart.c
Modified: trunk/kernel/arch/ppc/thread.c
===================================================================
--- trunk/kernel/arch/ppc/thread.c 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/kernel/arch/ppc/thread.c 2012-10-05 16:34:19 UTC (rev 43)
@@ -51,4 +51,24 @@
return (uint32_t)sp;
}
+uint32_t pok_context_reset(uint32_t stack_size,
+ uint32_t stack_addr)
+{
+ context_t* sp;
+ uint32_t id;
+ uint32_t entry;
+
+ sp = (context_t *) (stack_addr + stack_size - 4 - sizeof (context_t));
+
+ id = sp->r15;
+ entry = sp->r14;
+ memset (sp, 0, sizeof (context_t));
+
+ sp->r14 = entry;
+ sp->r15 = id;
+ sp->lr = (uint32_t) pok_arch_thread_start;
+ sp->sp = (uint32_t) &sp->back_chain;
+ return 0;
+}
+
#endif
Modified: trunk/kernel/arch/sparc/thread.c
===================================================================
--- trunk/kernel/arch/sparc/thread.c 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/kernel/arch/sparc/thread.c 2012-10-05 16:34:19 UTC (rev 43)
@@ -72,4 +72,23 @@
pok_arch_sp = new_sp;
}
+void pok_context_reset(uint32_t stack_size,
+ uint32_t stack_addr)
+{
+ (void)stack_size;
+ (void)stack_addr;
+ uint32_t id;
+ uint32_t entry;
+
+ char *ctx = (char *)(&_idlestack - 0x40);
+
+ id = *(uint32_t *)(ctx - PC_OFFSET);
+ entry = *(uint32_t *)(ctx - I1_OFFSET);
+
+ *(uint32_t *)(ctx - RESTORE_CNT_OFFSET) = 1;
+ *(uint32_t *)(ctx - PC_OFFSET) = entry;
+ *(uint32_t *)(ctx - NPC_OFFSET) = entry + 4;
+ *(uint32_t *)(ctx - I1_OFFSET) = id;
+}
+
#endif
Modified: trunk/kernel/arch/x86/thread.c
===================================================================
--- trunk/kernel/arch/x86/thread.c 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/kernel/arch/x86/thread.c 2012-10-05 16:34:19 UTC (rev 43)
@@ -73,4 +73,24 @@
"ret"
);
+void pok_context_reset(uint32_t stack_size,
+ uint32_t stack_addr)
+{
+ start_context_t* sp;
+ uint32_t id;
+ uint32_t entry;
+
+ sp = (start_context_t *) (stack_addr + stack_size - 4 - sizeof (start_context_t));
+
+ id = sp->id;
+ entry = sp->entry;
+ memset (sp, 0, sizeof (start_context_t));
+ sp->ctx.__esp = (uint32_t) (&sp->ctx.eip);
+ sp->ctx.eip = (uint32_t) pok_thread_start;
+ sp->ctx.cs = GDT_CORE_CODE_SEGMENT << 3;
+ sp->ctx.eflags = 1 << 9;
+ sp->entry = entry;
+ sp->id = id;
+}
+
#endif
Modified: trunk/kernel/arch/x86/thread.h
===================================================================
--- trunk/kernel/arch/x86/thread.h 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/kernel/arch/x86/thread.h 2012-10-05 16:34:19 UTC (rev 43)
@@ -52,6 +52,8 @@
void pok_context_switch(uint32_t* old_sp,
uint32_t new_sp);
+void pok_context_reset(uint32_t stack_size,
+ uint32_t stack_addr);
#endif /* !__POK_X86_THREAD_H__ */
Modified: trunk/kernel/core/partition.c
===================================================================
--- trunk/kernel/core/partition.c 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/kernel/core/partition.c 2012-10-05 16:34:19 UTC (rev 43)
@@ -37,6 +37,7 @@
#include <core/loader.h>
#include <core/partition.h>
#include <core/instrumentation.h>
+#include <core/time.h>
#include <libc.h>
@@ -273,6 +274,26 @@
pok_partitions[pid].mode = mode; /* Here, we change the mode */
+ pok_thread_t* thread;
+ unsigned int i;
+ for (i = 0; i < pok_partitions[pok_current_partition].nthreads; i++)
+ {
+ thread = &(pok_threads[POK_CURRENT_PARTITION.thread_index_low + i]);
+ if ((long long)thread->period == -1) {//-1 <==> ARINC INFINITE_TIME_VALUE
+ if(thread->state == POK_STATE_WAITING) { // delayed start, the delay is in the wakeup time
+ if(!thread->wakeup_time) {
+ thread->state = POK_STATE_RUNNABLE;
+ }
+ thread->wakeup_time += POK_GETTICK();
+ thread->end_time = thread->wakeup_time + thread->time_capacity;
+ }
+ } else {
+ if(thread->state == POK_STATE_WAITING) { // delayed start, the delay is in the wakeup time
+ thread->wakeup_time += POK_CONFIG_SCHEDULING_MAJOR_FRAME + POK_CURRENT_PARTITION.activation;
+ thread->end_time = thread->wakeup_time + thread->time_capacity;
+ }
+ }
+ }
pok_sched_stop_thread (pok_partitions[pid].thread_main);
/* We stop the thread that call this change. All the time,
* the thread that init this request is the init thread.
Modified: trunk/kernel/core/syscall.c
===================================================================
--- trunk/kernel/core/syscall.c 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/kernel/core/syscall.c 2012-10-05 16:34:19 UTC (rev 43)
@@ -125,6 +125,9 @@
return pok_thread_get_status (args->arg1, (pok_thread_attr_t*) (args->arg2 + infos->base_addr));
break;
+ case POK_SYSCALL_THREAD_DELAYED_START:
+ return pok_thread_delayed_start (args->arg1, args->arg2);
+ break;
case POK_SYSCALL_THREAD_SET_PRIORITY:
return pok_thread_set_priority (args->arg1, args->arg2);
break;
Modified: trunk/kernel/core/thread.c
===================================================================
--- trunk/kernel/core/thread.c 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/kernel/core/thread.c 2012-10-05 16:34:19 UTC (rev 43)
@@ -101,6 +101,7 @@
#endif
pok_threads[KERNEL_THREAD].priority = pok_sched_get_priority_min(0);
+ pok_threads[KERNEL_THREAD].base_priority = pok_sched_get_priority_min(0);
pok_threads[KERNEL_THREAD].state = POK_STATE_RUNNABLE;
pok_threads[KERNEL_THREAD].next_activation = 0;
@@ -111,7 +112,7 @@
pok_threads[IDLE_THREAD].remaining_time_capacity = 0;
pok_threads[IDLE_THREAD].wakeup_time = 0;
pok_threads[IDLE_THREAD].entry = pok_arch_idle;
- pok_threads[IDLE_THREAD].priority = pok_sched_get_priority_min(0);
+ pok_threads[IDLE_THREAD].base_priority = pok_sched_get_priority_min(0);
pok_threads[IDLE_THREAD].state = POK_STATE_RUNNABLE;
pok_threads[IDLE_THREAD].sp = pok_context_create
@@ -166,6 +167,7 @@
if ((attr->priority <= pok_sched_get_priority_max (pok_partitions[partition_id].sched)) && (attr->priority >= pok_sched_get_priority_min (pok_partitions[partition_id].sched)))
{
pok_threads[id].priority = attr->priority;
+ pok_threads[id].base_priority = attr->priority;
}
if (attr->period > 0)
@@ -300,6 +302,52 @@
}
#endif
+pok_ret_t pok_thread_delayed_start (const uint32_t id, const uint32_t ms)
+{
+ if (POK_CURRENT_PARTITION.thread_index_low > id || POK_CURRENT_PARTITION.thread_index_high < id)
+ return POK_ERRNO_THREADATTR;
+ pok_threads[id].priority = pok_threads[id].base_priority;
+ //reset stack
+ pok_context_reset(POK_USER_STACK_SIZE,pok_threads[id].init_stack_addr);
+ if ((long long)pok_threads[id].period == -1) //-1 <==> ARINC INFINITE_TIME_VALUE
+ {
+ if (pok_partitions[pok_threads[id].partition].mode == POK_PARTITION_MODE_NORMAL)
+ {
+ if (ms == 0)
+ {
+ pok_threads[id].state = POK_STATE_RUNNABLE;
+ pok_threads[id].end_time = POK_GETTICK() + pok_threads[id].time_capacity;
+ }
+ else
+ {
+ pok_threads[id].state = POK_STATE_WAITING;
+ pok_threads[id].wakeup_time = ms;
+ }
+ //the preemption is always enabled so
+ pok_sched();
+ }
+ else //the partition mode is cold or warm start
+ {
+ pok_threads[id].state = POK_STATE_WAITING;
+ pok_threads[id].wakeup_time = ms;
+ }
+ }
+ else
+ {
+ if (pok_partitions[pok_threads[id].partition].mode == POK_PARTITION_MODE_NORMAL)
+ { // set the first release point
+ pok_threads[id].next_activation = ms + POK_GETTICK();
+ pok_threads[id].end_time = pok_threads[id].deadline + pok_threads[id].next_activation;
+ }
+ else
+ {
+ pok_threads[id].state = POK_STATE_WAITING;
+ pok_threads[id].wakeup_time = ms;
+ }
+ }
+ return POK_ERRNO_OK;
+}
+
pok_ret_t pok_thread_get_status (const uint32_t id, pok_thread_attr_t *attr)
{
if (POK_CURRENT_PARTITION.thread_index_low > id || POK_CURRENT_PARTITION.thread_index_high < id)
Modified: trunk/kernel/include/arch.h
===================================================================
--- trunk/kernel/include/arch.h 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/kernel/include/arch.h 2012-10-05 16:34:19 UTC (rev 43)
@@ -59,6 +59,9 @@
void pok_context_switch (uint32_t* old_sp, uint32_t new_sp);
+void pok_context_reset(uint32_t stack_size,
+ uint32_t stack_addr);
+
pok_ret_t pok_create_space (uint8_t partition_id, uint32_t addr, uint32_t size);
uint32_t pok_space_base_vaddr (uint32_t addr);
Modified: trunk/kernel/include/core/syscall.h
===================================================================
--- trunk/kernel/include/core/syscall.h 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/kernel/include/core/syscall.h 2012-10-05 16:34:19 UTC (rev 43)
@@ -38,6 +38,9 @@
POK_SYSCALL_THREAD_SET_PRIORITY = 60,
POK_SYSCALL_THREAD_RESUME = 61,
POK_SYSCALL_THREAD_SUSPEND_TARGET = 62,
+ //POK_SYSCALL_THREAD_DEADLINE = 63,
+ //POK_SYSCALL_THREAD_STATE = 64,
+ POK_SYSCALL_THREAD_DELAYED_START = 65,
#ifdef POK_NEEDS_PORTS_SAMPLING
POK_SYSCALL_MIDDLEWARE_SAMPLING_ID = 101,
POK_SYSCALL_MIDDLEWARE_SAMPLING_READ = 102,
Modified: trunk/kernel/include/core/thread.h
===================================================================
--- trunk/kernel/include/core/thread.h 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/kernel/include/core/thread.h 2012-10-05 16:34:19 UTC (rev 43)
@@ -73,6 +73,7 @@
uint8_t partition;
uint32_t sp;
uint32_t init_stack_addr;
+ uint8_t base_priority;
/* stack pointer
* FIXME: this is platform-dependent code, we have to handle that ! */
} pok_thread_t;
@@ -99,6 +100,7 @@
void pok_thread_start (void (*entry)(), unsigned int id);
pok_ret_t pok_thread_suspend (void);
pok_ret_t pok_thread_restart (const uint32_t tid);
+pok_ret_t pok_thread_delayed_start (const uint32_t id, const uint32_t ms);
pok_ret_t pok_thread_get_status (const uint32_t id, pok_thread_attr_t *attr);
pok_ret_t pok_thread_set_priority (const uint32_t id, const uint32_t priority);
pok_ret_t pok_thread_resume (const uint32_t id);
Modified: trunk/libpok/arinc653/process.c
===================================================================
--- trunk/libpok/arinc653/process.c 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/libpok/arinc653/process.c 2012-10-05 16:34:19 UTC (rev 43)
@@ -112,6 +112,12 @@
strcpy(arinc_process_attribute[core_process_id].NAME, attributes->NAME);
*process_id = core_process_id;
*return_code = core_ret;
+ if(core_ret != POK_ERRNO_OK) {
+ return;
+ }
+ // ARINC specifies that threads shall be created in the DORMANT state
+ core_ret = pok_thread_suspend_target(core_process_id);
+ *return_code = core_ret;
}
void STOP_SELF ()
@@ -217,22 +223,7 @@
void START (PROCESS_ID_TYPE process_id,
RETURN_CODE_TYPE *return_code )
{
- pok_thread_attr_t attr;
- pok_ret_t core_ret;
-
- core_ret = pok_thread_status (process_id, &attr);
- if (core_ret != 0)
- {
- *return_code = INVALID_PARAM;
- return ;
- }
- if (attr.state != DORMANT)
- {
- *return_code = NO_ACTION;
- return ;
- }
- core_ret = pok_thread_restart(process_id);
- *return_code = core_ret;
+ DELAYED_START(process_id,0,return_code);
}
#ifndef POK_CONFIG_OPTIMIZE_FOR_GENERATED_CODE
@@ -242,16 +233,45 @@
(void) process_id;
*return_code = NOT_AVAILABLE;
}
+#endif
void DELAYED_START (PROCESS_ID_TYPE process_id,
SYSTEM_TIME_TYPE delay_time,
RETURN_CODE_TYPE *return_code )
{
- (void) process_id;
- (void) delay_time;
- *return_code = NOT_AVAILABLE;
+ pok_thread_attr_t attr;
+ pok_ret_t core_ret;
+
+ core_ret = pok_thread_status (process_id, &attr);
+ if (core_ret != POK_ERRNO_OK)
+ {
+ *return_code = INVALID_PARAM;
+ return;
+ }
+ if (attr.state != DORMANT)
+ {
+ *return_code = NO_ACTION;
+ return;
+ }
+ if (delay_time == INFINITE_TIME_VALUE)
+ {
+ *return_code = INVALID_PARAM;
+ return;
+ }
+ /*if ((int)attr.period != INFINITE_TIME_VALUE && delay_time >= attr.period)
+ {
+ *return_code = INVALID_PARAM;
+ return;
+ }*/
+ core_ret = pok_thread_delayed_start(process_id, delay_time);
+ if (core_ret == POK_ERRNO_OK) {
+ *return_code = NO_ERROR;
+ }else {
+ *return_code = INVALID_PARAM;
+ }
}
+#ifndef POK_CONFIG_OPTIMIZE_FOR_GENERATED_CODE
void LOCK_PREEMPTION (LOCK_LEVEL_TYPE *lock_level,
RETURN_CODE_TYPE *return_code )
{
Modified: trunk/libpok/core/Makefile
===================================================================
--- trunk/libpok/core/Makefile 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/libpok/core/Makefile 2012-10-05 16:34:19 UTC (rev 43)
@@ -36,6 +36,7 @@
threadperiod.o \
threadsleep.o \
threadstatus.o \
+ threaddelayedstart.o \
threadid.o \
threadpriority.o \
threadresume.o
Added: trunk/libpok/core/threaddelayedstart.c
===================================================================
--- trunk/libpok/core/threaddelayedstart.c (rev 0)
+++ trunk/libpok/core/threaddelayedstart.c 2012-10-05 16:34:19 UTC (rev 43)
@@ -0,0 +1,32 @@
+/*
+ * POK header
+ *
+ * The following file is a part of the POK project. Any modification should
+ * made according to the POK licence. You CANNOT use this file or a part of
+ * this file is this part of a file for your own project
+ *
+ * For more information on the POK licence, please see our LICENCE FILE
+ *
+ * Please follow the coding guidelines described in doc/CODING_GUIDELINES
+ *
+ * Copyright (c) 2007-2009 POK team
+ *
+ * Created by matias on Thu May 21 23:34:13 2009
+ */
+
+#include <core/dependencies.h>
+
+#ifdef POK_NEEDS_THREADS
+#include <arch.h>
+#include <types.h>
+#include <core/syscall.h>
+#include <core/thread.h>
+
+pok_ret_t pok_thread_delayed_start (const uint32_t thread_id, const pok_time_t ms)
+{
+ return pok_syscall2 (POK_SYSCALL_THREAD_DELAYED_START,
+ (uint32_t)thread_id,
+ (uint32_t)ms);
+}
+
+#endif
Modified: trunk/libpok/include/core/syscall.h
===================================================================
--- trunk/libpok/include/core/syscall.h 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/libpok/include/core/syscall.h 2012-10-05 16:34:19 UTC (rev 43)
@@ -38,6 +38,9 @@
POK_SYSCALL_THREAD_SET_PRIORITY = 60,
POK_SYSCALL_THREAD_RESUME = 61,
POK_SYSCALL_THREAD_SUSPEND_TARGET = 62,
+ POK_SYSCALL_THREAD_DEADLINE = 63,
+ POK_SYSCALL_THREAD_STATE = 64,
+ POK_SYSCALL_THREAD_DELAYED_START = 65,
#ifdef POK_NEEDS_PORTS_SAMPLING
POK_SYSCALL_MIDDLEWARE_SAMPLING_ID = 101,
POK_SYSCALL_MIDDLEWARE_SAMPLING_READ = 102,
Modified: trunk/libpok/include/core/thread.h
===================================================================
--- trunk/libpok/include/core/thread.h 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/libpok/include/core/thread.h 2012-10-05 16:34:19 UTC (rev 43)
@@ -58,6 +58,7 @@
pok_ret_t pok_thread_id (uint32_t* thread_id);
void pok_thread_init (void);
pok_ret_t pok_thread_status(const uint32_t thread_id, pok_thread_attr_t* attr);
+pok_ret_t pok_thread_delayed_start(const uint32_t thread_id, const pok_time_t ms);
pok_ret_t pok_thread_set_priority(const uint32_t thread_id, const uint32_t priority);
pok_ret_t pok_thread_resume(const uint32_t thread_id);
Modified: trunk/misc/release-files
===================================================================
--- trunk/misc/release-files 2012-10-04 12:35:12 UTC (rev 42)
+++ trunk/misc/release-files 2012-10-05 16:34:19 UTC (rev 43)
@@ -203,6 +203,7 @@
libpok/core/threadsleep.c
libpok/core/threadperiod.c
libpok/core/threadstatus.c
+libpok/core/threaddelayedstart.c
libpok/core/threadpriority.c
libpok/core/timecomputedeadline.c
libpok/core/timeget.c