git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@1026
35b4ef3e-fd22-0410-ab77-
dab3279adceb
-FOSA_MODULES=fosa_clocks_and_timers fosa_threads_and_signals fosa_app_def_sched fosa_mutexes_and_condvars fosa_misc
-FOSA_OBJS = $(addsuffix .o,$(FOSA_MODULES))
-
-FOSA_INC=../include
-
-PRTK=$(HOME)/FRESCOR/FRSHv2/partikle/trunk
-PRTK_INC=$(PRTK)/user/ulibc/include
+include ../config.mk
+include ../rules.mk
+FOSA_MODULES=fosa_clocks_and_timers fosa_threads_and_signals fosa_app_def_sched fosa_mutexes_and_condvars fosa_misc fosa_long_jump
+FOSA_OBJS=$(addsuffix .o,$(FOSA_MODULES))
check_gcc = $(shell \
if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1 ;\
check_gcc = $(shell \
if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1 ;\
-CFLAGS+=-I$(FOSA_INC)\
- -DPARTIKLE\
- -I$(PRTK_INC)\
-# -DCONFIG_URGENCY\
CFLAGS += $(call check_gcc, -fno-stack-protector,)
LIBFOSA=libfosa_PARTIKLE.a
CFLAGS += $(call check_gcc, -fno-stack-protector,)
LIBFOSA=libfosa_PARTIKLE.a
$(LIBFOSA): $(FOSA_OBJS)
$(AR) -r $(LIBFOSA) $(FOSA_OBJS)
cp $(LIBFOSA) ../lib
$(LIBFOSA): $(FOSA_OBJS)
$(AR) -r $(LIBFOSA) $(FOSA_OBJS)
cp $(LIBFOSA) ../lib
-
-test_fosa.prtk: test_fosa.c $(LIBFOSA)
- $(CC) -c test_fosa.c $(CFLAGS)
- ldkernel -o test_fosa.prtk test_fosa.o $(LIBFOSA)
-
-# test_fosa.o: test_fosa.c
-
-clean:
- $(RM) -f *.o *~ *.a *.prtk
#include <fosa_configuration_parameters.h>
#include <fosa_app_def_sched.h>
#include <fosa_configuration_parameters.h>
#include <fosa_app_def_sched.h>
+#include <fosa_threads_and_signals.h>
#include <sched.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sched.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
-// #include <fosa_configuration_parameters.h>
#define REACHS(str) printf ("%s: %s: %d: %s\n", __FILE__, __FUNCTION__, __LINE__, str)
#define REACHS(str) printf ("%s: %s: %d: %s\n", __FILE__, __FUNCTION__, __LINE__, str)
struct posix_appsched_event event;
struct timespec current_time;
posix_appsched_eventset_t accepted_events;
struct posix_appsched_event event;
struct timespec current_time;
posix_appsched_eventset_t accepted_events;
+ printf ("SCHEDULER thread=0x%lx\n\n", (unsigned long) pthread_self ());
// accept events which have a callback associated
posix_appsched_fillset (&accepted_events);
// accept events which have a callback associated
posix_appsched_fillset (&accepted_events);
/* active = actions.activated;
int suspend = actions.suspended; */
/* active = actions.activated;
int suspend = actions.suspended; */
-#ifdef CONFIG_URGENCY
- #error "Urgency not supported. Disable this feature in the Makefile"
-#else
+// #ifndef CONFIG_URGENCY
clear_actions (&actions);
// printf ("NEW: activate (%d), suspend (%d)\n", actions.activated, actions.suspended);
clear_actions (&actions);
// printf ("NEW: activate (%d), suspend (%d)\n", actions.activated, actions.suspended);
-#endif
-
- posix_appsched_actions_addaccept (&actions.actions, event.thread);
-
-// printf ("activated\n");
-// if (active)
-// fosa_adsactions_add_activate (&actions, event.thread, 0);
-// if (suspend)
-// fosa_adsactions_add_suspend (&actions, event.thread);
-
-
// alloc memory for reply info of 'fosa_ads_invoke_with_data ()'
struct reply_info *reply_mem = malloc (sizeof (struct reply_info));
if (!reply_mem) {
// alloc memory for reply info of 'fosa_ads_invoke_with_data ()'
struct reply_info *reply_mem = malloc (sizeof (struct reply_info));
if (!reply_mem) {
- printf ("BUG: not enougth dynamic memory\n");
- exit (-20);
+ posix_appsched_actions_addreject (&actions.actions, event.thread);
+ } else {
+ posix_appsched_actions_addaccept (&actions.actions, event.thread);
+ pthread_setspecific_for (fosa_reply_key, event.thread, reply_mem);
- pthread_setspecific_for (fosa_reply_key, event.thread, reply_mem);
}
break;
case POSIX_APPSCHED_TERMINATE:
}
break;
case POSIX_APPSCHED_TERMINATE:
struct reply_info *fosa_reply;
// Get reply memory pointer
struct reply_info *fosa_reply;
// Get reply memory pointer
-// printf ("CALL_WITH_DATA: caller 0x%x\n", event.thread);
pthread_getspecific_from (fosa_reply_key, event.thread, (void **) &fosa_reply);
pthread_getspecific_from (fosa_reply_key, event.thread, (void **) &fosa_reply);
-// printf ("reply_size (0x%x)=%d\n", fosa_reply -> size_ptr, (fosa_reply -> size_ptr)? *(fosa_reply -> size_ptr):-1);
fosa_scheduler_ops.explicit_call_with_data
(fosa_scheduler_data,
event.thread,
fosa_scheduler_ops.explicit_call_with_data
(fosa_scheduler_data,
event.thread,
&actions,
¤t_time);
&actions,
¤t_time);
-// printf ("CALL_WITH_DATA: activate (%d), suspend (%d)\n", actions.activated, actions.suspended);
// activate the thread unless suspended or already activated
if (!actions.suspended && !actions.activated) {
posix_appsched_actions_addactivate
// activate the thread unless suspended or already activated
if (!actions.suspended && !actions.activated) {
posix_appsched_actions_addactivate
case POSIX_APPSCHED_THREAD_NOTIFICATION:
fosa_scheduler_ops.notification_for_thread
case POSIX_APPSCHED_THREAD_NOTIFICATION:
fosa_scheduler_ops.notification_for_thread
- (fosa_scheduler_data, event.thread,(fosa_clock_id_t) event.event_info.info, &actions, ¤t_time);
+ (fosa_scheduler_data,
+ event.thread,(fosa_clock_id_t) event.event_info.info,
+ &actions,
+ ¤t_time);
break;
case POSIX_APPSCHED_ERROR:
break;
case POSIX_APPSCHED_ERROR:
-// printf ("ENd LOOP\n");
pthread_attr_t attr;
struct sched_param sp;
pthread_attr_t attr;
struct sched_param sp;
+
+ printf ("\nMAIN thread=0x%lx\n\n", (unsigned long)pthread_self ());
+
+
if (!scheduler_ops)
return EINVAL;
fosa_scheduler_ops = *scheduler_ops;
if (!scheduler_ops)
return EINVAL;
fosa_scheduler_ops = *scheduler_ops;
- if (err = pthread_attr_setappscheduler (attr, fosa_scheduler_th))
+ err = pthread_attr_setappscheduler (attr, fosa_scheduler_th);
+ if (err)
return err;
if (appscheduled)
return err;
if (appscheduled)
- if (err = pthread_attr_getschedpolicy (attr, &policy))
+ err = pthread_attr_getschedpolicy (attr, &policy);
+ if (err)
return err;
*appscheduled = (policy == SCHED_APP);
return err;
*appscheduled = (policy == SCHED_APP);
struct sched_param sp;
int policy_old, policy_new, err;
struct sched_param sp;
int policy_old, policy_new, err;
- if (err = pthread_getschedparam (thread, &policy_old, &sp))
+ err = pthread_getschedparam (thread, &policy_old, &sp);
+ if (err)
return err;
if (appscheduled) {
return err;
if (appscheduled) {
- if (err = pthread_setappscheduler (thread, fosa_scheduler_th))
+ err = pthread_setappscheduler (thread, fosa_scheduler_th);
+ if (err)
return err;
policy_new = SCHED_APP;
return err;
policy_new = SCHED_APP;
struct sched_param sp;
int policy, err;
struct sched_param sp;
int policy, err;
- if (err = pthread_getschedparam (thread, &policy, &sp))
+ err = pthread_getschedparam (thread, &policy, &sp);
+ if (err)
return err;
*appscheduled = (policy == SCHED_APP);
return err;
*appscheduled = (policy == SCHED_APP);
return posix_appsched_actions_addreject (&(sched_actions -> actions), thread);
}
return posix_appsched_actions_addreject (&(sched_actions -> actions), thread);
}
+extern inline int fosa2prtk (int prio, int urg);
int fosa_adsactions_add_activate
(fosa_ads_actions_t *sched_actions,
fosa_thread_id_t thread,
fosa_ads_urgency_t urgency)
{
sched_actions -> activated = true;
int fosa_adsactions_add_activate
(fosa_ads_actions_t *sched_actions,
fosa_thread_id_t thread,
fosa_ads_urgency_t urgency)
{
sched_actions -> activated = true;
#ifdef CONFIG_URGENCY
#error "Urgency not supported. Disable this feature in the Makefile"
#ifdef CONFIG_URGENCY
#error "Urgency not supported. Disable this feature in the Makefile"
+ int fosaprio, policy;
+ struct sched_param sp;
+
+ pthread_getschedparam (thread, &policy, &sp);
+ fosa_thread_get_prio (thread, &fosaprio);
+ sp.sched_priority = fosa2prtk (fosaprio, urgency);
+ printf ("policy=%d, prio=%d, urg=%d, new_prio=%d\n", policy);
+ pthread_setschedparam (thread, policy, &sp);
-// printf ("0x%x: Activate thread 0x%x\n", pthread_self (), thread);
return posix_appsched_actions_addactivate (&(sched_actions -> actions), thread);
}
return posix_appsched_actions_addactivate (&(sched_actions -> actions), thread);
}
(fosa_ads_actions_t *sched_actions,
fosa_thread_id_t thread)
{
(fosa_ads_actions_t *sched_actions,
fosa_thread_id_t thread)
{
-// printf ("0x%x: Suspend thread 0x%x\n", pthread_self (), thread);
sched_actions -> suspended = true;
return posix_appsched_actions_addsuspend (&(sched_actions -> actions), thread);
}
sched_actions -> suspended = true;
return posix_appsched_actions_addsuspend (&(sched_actions -> actions), thread);
}
if (!pthread_equal (pthread_self (), fosa_scheduler_th))
return EPOLICY;
if (!pthread_equal (pthread_self (), fosa_scheduler_th))
return EPOLICY;
- printf ("\n\nHANDLED\n");
sigemptyset (&fosa_handled_signals);
for (i = 0; i < size; i++) {
if (FOSA_SIGNAL_MIN > set [i] || set [i] > FOSA_SIGNAL_MAX)
sigemptyset (&fosa_handled_signals);
for (i = 0; i < size; i++) {
if (FOSA_SIGNAL_MIN > set [i] || set [i] > FOSA_SIGNAL_MAX)
clock_gettime (CLOCK_REALTIME, &now);
clock_gettime (CLOCK_REALTIME, &now);
-// printf ("(0x%x): Arm timer (%d). abstime=%d, value={%ld,%ld}, now={%ld, %ld}\n",\
-// pthread_self (), timerid, abstime, value -> tv_sec, value -> tv_nsec, now.tv_sec, now.tv_nsec);
-
+/*
+ printf ("(0x%x): Arm timer (%d). abstime=%d, value={%ld,%ld}, now={%ld, %ld}\n",\
+ pthread_self (), timerid, abstime, value -> tv_sec, value -> tv_nsec, now.tv_sec, now.tv_nsec);
+*/
struct itimerspec tvalue =
{
.it_value = (struct timespec) *value,
struct itimerspec tvalue =
{
.it_value = (struct timespec) *value,
// NULL timer -> disarm
null_timer = (struct itimerspec) {
.it_value = {0, 0},
// NULL timer -> disarm
null_timer = (struct itimerspec) {
.it_value = {0, 0},
};
if (timer_settime (timerid, 0, &null_timer, &old))
};
if (timer_settime (timerid, 0, &null_timer, &old))
--- /dev/null
+#include <time.h>
+
+
+unsigned int sleep(unsigned int seconds)
+{
+ struct timespec remain, t = {seconds, 0};
+ if (nanosleep (&t, &remain))
+ return remain.tv_sec;
+ else
+ return 0;
+}
pthread_mutexattr_t attr;
int err;
pthread_mutexattr_t attr;
int err;
- if (err = pthread_mutexattr_init (&attr))
+ err = pthread_mutexattr_init (&attr);
+ if (err)
return err;
pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_ERRORCHECK);
pthread_mutexattr_setprotocol (&attr, PTHREAD_PRIO_PROTECT);
return err;
pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_ERRORCHECK);
pthread_mutexattr_setprotocol (&attr, PTHREAD_PRIO_PROTECT);
- if (err = pthread_mutexattr_setprioceiling (&attr, prioceiling))
+ err = pthread_mutexattr_setprioceiling (&attr, prioceiling);
+ if (err)
return err;
return pthread_mutex_init (mutex, &attr);
return err;
return pthread_mutex_init (mutex, &attr);
pthread_condattr_t attr;
int err;
pthread_condattr_t attr;
int err;
- if (err = pthread_condattr_init (&attr))
+ err = pthread_condattr_init (&attr);
+ if (err)
return err;
return pthread_cond_init (cond, NULL);
return err;
return pthread_cond_init (cond, NULL);
* Thread scheduling
**********************/
// PaRTiKle uses decreasing values for increasing priority (0 -> maxprio)
* Thread scheduling
**********************/
// PaRTiKle uses decreasing values for increasing priority (0 -> maxprio)
-// TODO: planificació jerà rquica
+
+inline int fosa2prtk (int prio, int urg)
+{
+ return ((prio & 0x3f) << 4) + (urg & 0xf);
+}
+
+static inline int prtk2fprio (int prio)
+{
+ return (prio >> 4) & 0x3f;
+}
+
+static inline int prtk2furg (int prio)
+{
+ return prio & 0xf;
+}
+
int fosa_get_priority_max()
{
int fosa_get_priority_max()
{
- return sched_get_priority_min (SCHED_FIFO);
+ return prtk2fprio (sched_get_priority_min (SCHED_FIFO));
}
int fosa_get_priority_min()
{
}
int fosa_get_priority_min()
{
- return sched_get_priority_max (SCHED_FIFO);
+ return prtk2fprio (sched_get_priority_max (SCHED_FIFO));
}
int fosa_thread_attr_set_prio(fosa_thread_attr_t *attr, int prio)
}
int fosa_thread_attr_set_prio(fosa_thread_attr_t *attr, int prio)
if (prio > fosa_get_priority_max () || prio < fosa_get_priority_min ())
return EINVAL;
if (prio > fosa_get_priority_max () || prio < fosa_get_priority_min ())
return EINVAL;
- sp.sched_priority = sched_get_priority_min (SCHED_FIFO) - prio;
+ sp.sched_priority = sched_get_priority_min (SCHED_FIFO) - fosa2prtk (prio, 0);
return pthread_attr_setschedparam (attr, &sp);
}
return pthread_attr_setschedparam (attr, &sp);
}
pthread_attr_getschedparam (attr, &sp);
pthread_attr_getschedparam (attr, &sp);
- *prio = sched_get_priority_min (SCHED_FIFO) - sp.sched_priority;
+ *prio = prtk2fprio (sched_get_priority_min (SCHED_FIFO) - sp.sched_priority);
return EINVAL;
pthread_getschedparam (tid, &policy, &sp);
return EINVAL;
pthread_getschedparam (tid, &policy, &sp);
- sp.sched_priority = sched_get_priority_min (SCHED_FIFO) - prio;
+ sp.sched_priority = sched_get_priority_min (SCHED_FIFO) - fosa2prtk (prio, 0);
return pthread_setschedparam (tid, policy, &sp);
}
return pthread_setschedparam (tid, policy, &sp);
}
act.sa_flags = SA_SIGINFO;
act.sa_handler = SIG_DFL;
act.sa_flags = SA_SIGINFO;
act.sa_handler = SIG_DFL;
-// printf ("Handled\n");
-// printf ("Fosa signal range [%d,%d]\n", FOSA_SIGNAL_MIN, FOSA_SIGNAL_MAX);
for (i = 0; i < size; i ++) {
for (i = 0; i < size; i ++) {
-// printf ("signal num=%d\n", set [i]);
if (FOSA_SIGNAL_MIN > set [i] || set [i] > FOSA_SIGNAL_MAX)
return EINVAL;
if (FOSA_SIGNAL_MIN > set [i] || set [i] > FOSA_SIGNAL_MAX)
return EINVAL;
sigaddset (&accept_set, set [i]);
}
sigaddset (&accept_set, set [i]);
}
-// printf ("Added to accept set\n");
return pthread_sigmask (SIG_BLOCK, &accept_set, NULL);
}
return pthread_sigmask (SIG_BLOCK, &accept_set, NULL);
}
(fosa_signal_t signal, fosa_signal_info_t info,
fosa_thread_id_t receiver)
{
(fosa_signal_t signal, fosa_signal_info_t info,
fosa_thread_id_t receiver)
{
- union sigval *nfo = (union sigval *) &info;
+ union sigval nfo = (union sigval) info.sival_ptr;
- if (sigqueue (1, signal, *nfo))
+ if (sigqueue (1, signal, nfo))
return errno;
else
return 0;
return errno;
else
return 0;
- *info = *((fosa_signal_info_t*) (&nfo.si_value));
+ *info = (fosa_signal_info_t) nfo.si_value.sival_ptr;
if (signal_received)
*signal_received = sig;
if (signal_received)
*signal_received = sig;