]> rtime.felk.cvut.cz Git - frescor/fosa.git/commitdiff
FOSA-PaRTiKle: some clean up
authorbrocalv <brocalv@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Mon, 25 Feb 2008 08:26:45 +0000 (08:26 +0000)
committerbrocalv <brocalv@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Mon, 25 Feb 2008 08:26:45 +0000 (08:26 +0000)
git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@1026 35b4ef3e-fd22-0410-ab77-dab3279adceb

src_partikle/Makefile
src_partikle/fosa_app_def_sched.c
src_partikle/fosa_clocks_and_timers.c
src_partikle/fosa_misc.c [new file with mode: 0644]
src_partikle/fosa_mutexes_and_condvars.c
src_partikle/fosa_threads_and_signals.c

index 09db518a3ea1c1f15f847c5edf42970beb8de09e..e157c9820f42808945fd870c4974a9e74df171d7 100644 (file)
@@ -1,11 +1,8 @@
-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 ;\
@@ -15,27 +12,12 @@ check_gcc = $(shell \
                 echo "$(2)";\
         fi)
 
-CFLAGS+=-I$(FOSA_INC)\
-       -DPARTIKLE\
-       -I$(PRTK_INC)\
-#      -DCONFIG_URGENCY\
 
 CFLAGS += $(call check_gcc, -fno-stack-protector,)
 
 LIBFOSA=libfosa_PARTIKLE.a
-CC=gcc
 
 all: $(LIBFOSA)
-
 $(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
index 0c2d83ffa761a7c7e9a6095a4eb7611f2716788e..057e65606dc2755144e2543cd489caf891c451b2 100644 (file)
 
 #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 <fosa_configuration_parameters.h>
 
 #define REACHS(str) printf ("%s: %s: %d: %s\n", __FILE__, __FUNCTION__, __LINE__, str)
 
@@ -99,8 +99,9 @@ void *fosa_scheduler_main (void * args)
        struct posix_appsched_event event;
        struct timespec current_time;
        posix_appsched_eventset_t accepted_events;
-       bool active;
+//     bool active;
        
+       printf ("SCHEDULER thread=0x%lx\n\n", (unsigned long) pthread_self ());
        
        // accept events which have a callback associated
        posix_appsched_fillset (&accepted_events);
@@ -165,29 +166,19 @@ void *fosa_scheduler_main (void * args)
                                        
 /*                                     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);
-#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);
-
-                                                                               
+// // #endif
+  
                                        // 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:
@@ -223,9 +214,7 @@ void *fosa_scheduler_main (void * args)
                                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);
-//                             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,
@@ -236,7 +225,6 @@ void *fosa_scheduler_main (void * args)
                                                 &actions,
                                                 &current_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
@@ -262,7 +250,10 @@ void *fosa_scheduler_main (void * args)
 
                        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, &current_time);
+                                               (fosa_scheduler_data, 
+                                                event.thread,(fosa_clock_id_t) event.event_info.info, 
+                                                &actions, 
+                                                &current_time);
                                break;
 
                        case POSIX_APPSCHED_ERROR:
@@ -273,9 +264,8 @@ void *fosa_scheduler_main (void * args)
                                         &actions);
                                break;
 
-               */
+*/
                } 
-//             printf ("ENd LOOP\n");
        }
 }
 
@@ -291,6 +281,10 @@ int fosa_ads_scheduler_create
        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;
@@ -335,7 +329,8 @@ int fosa_thread_attr_set_appscheduled
 {
        int err;
        
-       if (err = pthread_attr_setappscheduler (attr, fosa_scheduler_th))
+       err = pthread_attr_setappscheduler (attr, fosa_scheduler_th);
+       if (err)
                return err;
        
        if (appscheduled)
@@ -351,7 +346,8 @@ int fosa_thread_attr_get_appscheduled
 {
        int policy, err;
        
-       if (err = pthread_attr_getschedpolicy (attr, &policy))
+       err = pthread_attr_getschedpolicy (attr, &policy);
+       if (err)
                return err;
        
        *appscheduled = (policy == SCHED_APP);
@@ -390,11 +386,13 @@ int fosa_ads_set_appscheduled
        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) {
-               if (err = pthread_setappscheduler (thread, fosa_scheduler_th))
+               err = pthread_setappscheduler (thread, fosa_scheduler_th);
+               if (err)
                        return err;
        
                policy_new = SCHED_APP;
@@ -416,7 +414,8 @@ int fosa_ads_get_appscheduled
        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);
@@ -454,16 +453,25 @@ int fosa_adsactions_add_reject
        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;
+
 #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);
 #endif
-//         printf ("0x%x: Activate thread 0x%x\n", pthread_self (), thread);
        return posix_appsched_actions_addactivate (&(sched_actions -> actions), thread);
 }
 
@@ -471,7 +479,6 @@ int fosa_adsactions_add_suspend
                (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);
 }
@@ -505,7 +512,6 @@ int fosa_ads_set_handled_signal_set (fosa_signal_t set[], int size)
        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)
index dc536e4ab37e16763d343015e77f06512ba55aad..99f795c14626aec9305634e9daf5e3d7ede409ff 100644 (file)
@@ -125,9 +125,10 @@ int fosa_timer_arm
        
        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,
@@ -162,7 +163,7 @@ int fosa_timer_disarm(fosa_timer_id_t timerid, struct timespec
        // NULL timer -> disarm
        null_timer = (struct itimerspec) {
                .it_value = {0, 0},
-               .it_interval = 0,
+               .it_interval = {0, 0},
        };
        
        if (timer_settime (timerid, 0, &null_timer, &old))
diff --git a/src_partikle/fosa_misc.c b/src_partikle/fosa_misc.c
new file mode 100644 (file)
index 0000000..231a306
--- /dev/null
@@ -0,0 +1,11 @@
+#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;
+}
index 5c7d34cb67e13eefd2be870428a7597aaaf931f1..ce75869e3b6425e0bf0fc6f20e110223c2023231 100644 (file)
@@ -67,12 +67,14 @@ int fosa_mutex_init(fosa_mutex_t *mutex, int prioceiling)
        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);
-       if (err = pthread_mutexattr_setprioceiling (&attr, prioceiling))
+       err = pthread_mutexattr_setprioceiling (&attr, prioceiling);
+       if (err)
                return err;
        
        return pthread_mutex_init (mutex, &attr);
@@ -118,7 +120,8 @@ int fosa_cond_init(fosa_cond_t *cond)
        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);
index 38224e486753a895c5194fa54c97fd97ad95d3be..e95df0169aff712ccd94b291f36c7a9016844973 100644 (file)
@@ -171,16 +171,31 @@ int fosa_thread_get_specific_data(int key, fosa_thread_id_t tid,
  * 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()
 {
-       return sched_get_priority_min (SCHED_FIFO);
+       return prtk2fprio (sched_get_priority_min (SCHED_FIFO));
 }
 
 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)
@@ -190,7 +205,7 @@ 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;
        
-       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);
 }
@@ -202,7 +217,7 @@ int fosa_thread_attr_set_prio(fosa_thread_attr_t *attr, int prio)
        
        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 0;
 }
@@ -216,7 +231,7 @@ int fosa_thread_set_prio(fosa_thread_id_t tid, int prio)
                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);
 }
@@ -250,10 +265,7 @@ int fosa_set_accepted_signals(fosa_signal_t set[], int size)
        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 ++) {
-//             printf ("signal num=%d\n", set [i]);
                if (FOSA_SIGNAL_MIN > set [i] || set [i] > FOSA_SIGNAL_MAX)
                        return EINVAL;
        
@@ -261,7 +273,6 @@ int fosa_set_accepted_signals(fosa_signal_t set[], int size)
                sigaddset (&accept_set, set [i]);
        }
        
-//     printf ("Added to accept set\n");
        return pthread_sigmask (SIG_BLOCK, &accept_set, NULL);
 }
 
@@ -270,9 +281,9 @@ int fosa_signal_queue
     (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;
@@ -309,7 +320,7 @@ int fosa_signal_queue
                return errno;
        
        if (info)
-               *info = *((fosa_signal_info_t*) (&nfo.si_value));
+               *info = (fosa_signal_info_t) nfo.si_value.sival_ptr;
        
        if (signal_received)
                *signal_received = sig;