From: brocalv Date: Mon, 12 May 2008 13:59:00 +0000 (+0000) Subject: FOSA-PaRTiKle: adaptation to the FOSA time abstraction X-Git-Url: https://rtime.felk.cvut.cz/gitweb/frescor/fosa.git/commitdiff_plain/4b6e6542d68f0052b9249169e530dd2bc4ae0baf?ds=sidebyside FOSA-PaRTiKle: adaptation to the FOSA time abstraction git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@1163 35b4ef3e-fd22-0410-ab77-dab3279adceb --- diff --git a/src_partikle/Makefile b/src_partikle/Makefile index e157c98..3297cd9 100644 --- a/src_partikle/Makefile +++ b/src_partikle/Makefile @@ -1,7 +1,7 @@ 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_MODULES=fosa_clocks_and_timers fosa_threads_and_signals fosa_app_def_sched fosa_mutexes_and_condvars fosa_misc fosa_long_jump fosa_time FOSA_OBJS=$(addsuffix .o,$(FOSA_MODULES)) check_gcc = $(shell \ diff --git a/src_partikle/fosa_app_def_sched.c b/src_partikle/fosa_app_def_sched.c index c47296e..99c3dc5 100644 --- a/src_partikle/fosa_app_def_sched.c +++ b/src_partikle/fosa_app_def_sched.c @@ -60,6 +60,8 @@ #include #include #include +#include + #include #include #include @@ -472,21 +474,21 @@ int fosa_adsactions_add_suspend return posix_appsched_actions_addsuspend (&(sched_actions -> actions), thread); } -int fosa_adsactions_add_timeout +int fosa_adsactions_add_timeout (fosa_ads_actions_t *sched_actions, fosa_clock_id_t clock_id, - const struct timespec *at_time) + const fosa_abs_time_t *at_time) { - sched_actions -> timeout = *at_time; + sched_actions -> timeout = fosa_abs_time_to_timespec (*at_time); sched_actions -> timeout_ptr = &(sched_actions -> timeout); return 0; } -int fosa_adsactions_add_thread_notification +int fosa_adsactions_add_thread_notification (fosa_ads_actions_t *sched_actions, fosa_thread_id_t thread, fosa_clock_id_t clock_id, - const struct timespec *at_time) + const fosa_abs_time_t *at_time) { printf ("BUG: fosa_adsactions_add_thread_notification: Not implemented\n"); exit (-21); diff --git a/src_partikle/fosa_clocks_and_timers.c b/src_partikle/fosa_clocks_and_timers.c index f028462..a5e051c 100644 --- a/src_partikle/fosa_clocks_and_timers.c +++ b/src_partikle/fosa_clocks_and_timers.c @@ -58,14 +58,19 @@ //================================================ #include +#include +#include /************************* * Timing: Clocks *************************/ -int fosa_clock_get_time(fosa_clock_id_t clockid, struct timespec *current_time) -{ - if (clock_gettime (clockid, current_time)) - return FOSA_EINVAL; +int fosa_clock_get_time(fosa_clock_id_t clockid, fosa_abs_time_t *current_time) +{ + int err; + struct timespec now; + + err = clock_gettime (clockid, &now); + *current_time = fosa_timespec_to_abs_time(now); return 0; } @@ -119,42 +124,47 @@ int fosa_timer_delete(fosa_timer_id_t timerid) } -int fosa_timer_arm - (fosa_timer_id_t timerid, bool abstime, - const struct timespec *value) +int fosa_rel_timer_arm (fosa_timer_id_t timerid, const fosa_rel_time_t *value) { - struct timespec now; + struct itimerspec tvalue; - clock_gettime (CLOCK_REALTIME, &now); + tvalue.it_value = fosa_rel_time_to_timespec(*value); + tvalue.it_interval = (struct timespec) {0,0}; - struct itimerspec tvalue = - { - .it_value = (struct timespec) *value, - .it_interval = {0,0}, - }; + if (timer_settime (timerid, 0, &tvalue, NULL)) + return FOSA_EINVAL; + + return 0; +} + +int fosa_abs_timer_arm (fosa_timer_id_t timerid, const fosa_abs_time_t *value) +{ + struct itimerspec tvalue; - if (timer_settime (timerid, abstime, &tvalue, NULL)) - return EINVAL; + tvalue.it_value = fosa_abs_time_to_timespec(*value); + tvalue.it_interval = (struct timespec) {0,0}; + + if (timer_settime (timerid, TIMER_ABSTIME, &tvalue, NULL)) + return FOSA_EINVAL; return 0; } int fosa_timer_get_remaining_time - (fosa_timer_id_t timerid, struct timespec *remaining_time) + (fosa_timer_id_t timerid, fosa_rel_time_t *remaining_time) { struct itimerspec value; if (timer_gettime (timerid, &value)) - return EINVAL; + return FOSA_EINVAL; - *remaining_time = value.it_value; + *remaining_time = fosa_timespec_to_rel_time (value.it_value); return 0; } -int fosa_timer_disarm(fosa_timer_id_t timerid, struct timespec - *remaining_time) +int fosa_timer_disarm (fosa_timer_id_t timerid, fosa_rel_time_t *remaining_time) { struct itimerspec null_timer, old; @@ -165,10 +175,10 @@ int fosa_timer_disarm(fosa_timer_id_t timerid, struct timespec }; if (timer_settime (timerid, 0, &null_timer, &old)) - return EINVAL; + return FOSA_EINVAL; if (remaining_time) - *remaining_time = old.it_value; + *remaining_time = fosa_timespec_to_rel_time (old.it_value); return 0; } diff --git a/src_partikle/fosa_mutexes_and_condvars.c b/src_partikle/fosa_mutexes_and_condvars.c index ce75869..4b14c78 100644 --- a/src_partikle/fosa_mutexes_and_condvars.c +++ b/src_partikle/fosa_mutexes_and_condvars.c @@ -58,6 +58,7 @@ //================================================ #include +#include /******************************************************* * Mutexes with priority ceiling @@ -147,19 +148,18 @@ int fosa_cond_wait(fosa_cond_t *cond, fosa_mutex_t *mutex) return pthread_cond_wait (cond, mutex); } -int fosa_cond_timedwait - (fosa_cond_t *cond, - fosa_mutex_t *mutex, - const struct timespec *abstime) +int fosa_cond_timedwait (fosa_cond_t *cond, fosa_mutex_t *mutex, + const fosa_abs_time_t *abstime) { int err; + struct timespec tout = fosa_abs_time_to_timespec (*abstime); - err = pthread_cond_timedwait (cond, mutex, abstime); + err = pthread_cond_timedwait (cond, mutex, &tout); if (err == ETIMEDOUT) - return ETIMEDOUT; + return FOSA_ETIMEDOUT; if (err) - return EINVAL; + return FOSA_EINVAL; return 0; } diff --git a/src_partikle/fosa_threads_and_signals.c b/src_partikle/fosa_threads_and_signals.c index e95df01..d48561b 100644 --- a/src_partikle/fosa_threads_and_signals.c +++ b/src_partikle/fosa_threads_and_signals.c @@ -59,6 +59,7 @@ #include #include +#include #include #include @@ -298,12 +299,13 @@ int fosa_signal_queue } int fosa_signal_timedwait - (fosa_signal_t set[], int size, fosa_signal_t *signal_received, - fosa_signal_info_t *info, const struct timespec *timeout) + (fosa_signal_t set[], int size, fosa_signal_t *signal_received, + fosa_signal_info_t *info, const fosa_rel_time_t *timeout) { int i, sig; sigset_t wset; siginfo_t nfo; + struct timespec tout = fosa_rel_time_to_timespec (*timeout); if (size < 0) return EINVAL; @@ -315,7 +317,7 @@ int fosa_signal_queue sigaddset (&wset, set [i]); } - sig = sigtimedwait (&wset, &nfo, timeout); + sig = sigtimedwait (&wset, &nfo, &tout); if (sig == -1) return errno; diff --git a/src_partikle/fosa_time.c b/src_partikle/fosa_time.c new file mode 100644 index 0000000..d63f84e --- /dev/null +++ b/src_partikle/fosa_time.c @@ -0,0 +1,93 @@ +//---------------------------------------------------------------------- +// Copyright (C) 2006 - 2007 by the FRESCOR consortium: +// +// Universidad de Cantabria, SPAIN +// University of York, UK +// Scuola Superiore Sant'Anna, ITALY +// Kaiserslautern University, GERMANY +// Univ. Politecnica Valencia, SPAIN +// Czech Technical University in Prague, CZECH REPUBLIC +// ENEA SWEDEN +// Thales Communication S.A. FRANCE +// Visual Tools S.A. SPAIN +// Rapita Systems Ltd UK +// Evidence ITALY +// +// See http://www.frescor.org +// +// The FRESCOR project (FP6/2005/IST/5-034026) is funded +// in part by the European Union Sixth Framework Programme +// The European Union is not liable of any use that may be +// made of this code. +// +// +// based on previous work (FSF) done in the FIRST project +// +// Copyright (C) 2005 Mälardalen University, SWEDEN +// Scuola Superiore S.Anna, ITALY +// Universidad de Cantabria, SPAIN +// University of York, UK +// +// This file is part of FOSA (Frsh Operating System Abstraction) +// +// FOSA is free software; you can redistribute it and/or modify it +// under terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) any +// later version. FOSA is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. You should have received a +// copy of the GNU General Public License along with FOSA; see file +// COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, +// Cambridge, MA 02139, USA. +// +// As a special exception, including FOSA header files in a file, +// instantiating FOSA generics or templates, or linking other files +// with FOSA objects to produce an executable application, does not +// by itself cause the resulting executable application to be covered +// by the GNU General Public License. This exception does not +// however invalidate any other reasons why the executable file might be +// covered by the GNU Public License. +// ----------------------------------------------------------------------- +// fosa_time.c +//============================================== +// ******** ****** ******** ********** +// **///// /** ** **////// /** /** +// ** /** ** /** /** /** +// ******* /** ** /********* /********** +// **//// /** ** ////////** /**//////** +// ** /** ** /** /** /** +// ** /** ** ******** /** /** +// // /******/ //////// // // +// +// FOSA(Frescor Operating System Adaptation layer) +//================================================ + +#include "fosa.h" + +/** + * fosa_eat() + * + * Eat some time using system clock facilities + **/ +void fosa_eat(const fosa_rel_time_t *cpu_time) +{ + fosa_clock_id_t clock_id; + fosa_abs_time_t current_time, time_to_go; + + // NOTE: there should be a constant for the cpu_clock_id of the caller + // to avoid calling 'fosa_thread_get_cputime_clock' + fosa_thread_get_cputime_clock(fosa_thread_self(), &clock_id); + fosa_clock_get_time(clock_id, ¤t_time); + + time_to_go = fosa_abs_time_incr(current_time, *cpu_time); + + /* We also spread smaller_timespec */ + while ( fosa_abs_time_smaller_or_equal(current_time, time_to_go) ) + { + fosa_clock_get_time(clock_id, ¤t_time); + } +} + + +