clientlib.c

Go to the documentation of this file.
00001 /*!
00002  * \file   cpu_reserve/lib/src/clientlib.c
00003  * \brief  Client bindings for the CPU reservation server
00004  *
00005  * \date   09/06/2004
00006  * \author Jork Loeser <jork.loeser@inf.tu-dresden.de>
00007  *
00008  */
00009 /* (c) 2004 Technische Universitaet Dresden
00010  * This file is part of DROPS, which is distributed under the terms of the
00011  * GNU General Public License 2. Please see the COPYING file for details.
00012  */
00013 #include <l4/env/errno.h>
00014 #include <l4/cpu_reserve/sched.h>
00015 #include <l4/sys/types.h>
00016 #include <l4/sys/syscalls.h>
00017 #include <l4/sys/rt_sched.h>
00018 #include <l4/names/libnames.h>
00019 #include <stdlib.h>
00020 #include "cpu_reserve-client.h"
00021 
00022 static l4_threadid_t server_id = L4_INVALID_ID;
00023 
00024 typedef void* (*malloc_t)(unsigned long);
00025 
00026 #define my_default_environment \
00027   { { _corba: { major: CORBA_NO_EXCEPTION, repos_id: 0} }, \
00028       { param: 0}, L4_IPC_NEVER_INITIALIZER, \
00029       { fp: { 1, 1, L4_WHOLE_ADDRESS_SPACE, 0, 0 } }, \
00030       (malloc_t)malloc, free }
00031 
00032 static void l4cpu_reserve_set_preempter(l4_threadid_t thread,
00033                                         l4_threadid_t preempter){
00034     l4_threadid_t pager;
00035     l4_umword_t dummy;
00036 
00037     pager = L4_INVALID_ID;
00038     l4_thread_ex_regs_flags(thread, -1, -1, &preempter, &pager,
00039                             &dummy, &dummy, &dummy,
00040                             L4_THREAD_EX_REGS_NO_CANCEL);
00041 }
00042 
00043 static int server_init(void){
00044     if(!l4_is_invalid_id(server_id)) return 0;
00045 
00046     return names_waitfor_name(l4cpu_reserve_name,
00047                               &server_id, 5000)?0:-L4_EIPC;
00048 }
00049 
00050 int l4cpu_reserve_add(l4_threadid_t thread,
00051                       const char*name,
00052                       int prio,
00053                       int period,
00054                       int *wcet,
00055                       int deadline,
00056                       int *id){
00057     int err;
00058     DICE_DECLARE_ENV(env);
00059 
00060     if((err = server_init())!=0) return err;
00061 
00062     return l4cpu_reserve_add_call(&server_id,
00063                                   &thread,
00064                                   name,
00065                                   prio,
00066                                   period,
00067                                   wcet,
00068                                   deadline,
00069                                   id,
00070                                   &env);
00071 }
00072 
00073 int l4cpu_reserve_delayed_preempt(l4_threadid_t thread,
00074                                   int id,
00075                                   int prio,
00076                                   int *delay){
00077     int err;
00078     DICE_DECLARE_ENV(env);
00079 
00080     if((err = server_init())!=0) return err;
00081 
00082     return l4cpu_reserve_delayed_preempt_call(&server_id,
00083                                               &thread,
00084                                               id,
00085                                               prio,
00086                                               delay,
00087                                               &env);
00088 }
00089 
00090 int l4cpu_reserve_change(l4_threadid_t thread,
00091                          int id,
00092                          int new_prio,
00093                          int *new_wcet,
00094                          int new_deadline){
00095     int err;
00096     DICE_DECLARE_ENV(env);
00097 
00098     if((err = server_init())!=0) return err;
00099 
00100     return l4cpu_reserve_change_call(&server_id,
00101                                      &thread,
00102                                      id,
00103                                      new_prio,
00104                                      new_wcet,
00105                                      new_deadline,
00106                                      &env);
00107 }
00108 
00109 int l4cpu_reserve_delete_thread(l4_threadid_t thread){
00110     int err;
00111     DICE_DECLARE_ENV(env);
00112 
00113     if((err = server_init())!=0) return err;
00114 
00115     /* Remove a preempter, as this could be the watcher, wich
00116      * we want to remove */
00117     l4cpu_reserve_set_preempter(thread, L4_INVALID_ID);
00118 
00119     return l4cpu_reserve_delete_thread_call(&server_id,
00120                                             &thread,
00121                                             &env);
00122 }
00123 
00124 int l4cpu_reserve_delete_task(l4_threadid_t task){
00125     int err;
00126     DICE_DECLARE_ENV(env);
00127 
00128     if((err = server_init())!=0) return err;
00129 
00130     return l4cpu_reserve_delete_task_call(&server_id,
00131                                           &task,
00132                                           &env);
00133 }
00134 
00135 int l4cpu_reserve_begin_strictly_periodic(l4_threadid_t thread,
00136                                           l4_kernel_clock_t clock){
00137     int err;
00138     DICE_DECLARE_ENV(env);
00139 
00140     if((err = server_init())!=0) return err;
00141 
00142     return l4cpu_reserve_begin_strictly_periodic_call(&server_id,
00143                                                       &thread,
00144                                                       clock,
00145                                                       &env);
00146 }
00147 
00148 int l4cpu_reserve_begin_strictly_periodic_self(l4_threadid_t thread){
00149     int err;
00150     DICE_DECLARE_ENV(env);
00151     l4_threadid_t s;
00152 
00153     if((err = server_init())!=0) return err;
00154 
00155     if(l4_is_invalid_id(thread)) thread = l4_myself();
00156     s = l4_next_period_id(server_id);
00157     return l4cpu_reserve_begin_strictly_periodic_call(&s, &thread, 0, &env);
00158 }
00159 
00160 int l4cpu_reserve_begin_strictly_periodic_self_deprecated(
00161     l4_threadid_t thread, l4_kernel_clock_t clock){
00162     int err;
00163     DICE_DECLARE_ENV(env);
00164     l4_threadid_t s;
00165 
00166     if((err = server_init())!=0) return err;
00167 
00168     if(l4_is_invalid_id(thread)) thread = l4_myself();
00169     s = l4_next_period_id(server_id);
00170     return l4cpu_reserve_begin_strictly_periodic_call(&s,
00171                                                       &thread,
00172                                                       clock,
00173                                                       &env);
00174 }
00175 
00176 int l4cpu_reserve_begin_minimal_periodic(l4_threadid_t thread,
00177                                          l4_kernel_clock_t clock){
00178     int err;
00179     DICE_DECLARE_ENV(env);
00180 
00181     if((err = server_init())!=0) return err;
00182 
00183     return l4cpu_reserve_begin_minimal_periodic_call(&server_id,
00184                                                      &thread,
00185                                                      clock,
00186                                                      &env);
00187 }
00188 
00189 int l4cpu_reserve_begin_minimal_periodic_self(l4_threadid_t thread){
00190     int err;
00191     DICE_DECLARE_ENV(env);
00192     l4_threadid_t s;
00193 
00194     if((err = server_init())!=0) return err;
00195 
00196     if(l4_is_invalid_id(thread)) thread = l4_myself();
00197     s = l4_next_period_id(server_id);
00198     return l4cpu_reserve_begin_minimal_periodic_call(&s, &thread, 0, &env);
00199 }
00200 
00201 int l4cpu_reserve_begin_minimal_periodic_self_deprecated(
00202     l4_threadid_t thread, l4_kernel_clock_t clock){
00203     int err;
00204     DICE_DECLARE_ENV(env);
00205     l4_threadid_t s;
00206 
00207     if((err = server_init())!=0) return err;
00208 
00209     if(l4_is_invalid_id(thread)) thread = l4_myself();
00210     s = l4_next_period_id(server_id);
00211     return l4cpu_reserve_begin_minimal_periodic_call(&s,
00212                                                      &thread,
00213                                                      clock,
00214                                                      &env);
00215 }
00216 
00217 int l4cpu_reserve_end_periodic(l4_threadid_t thread){
00218     int err;
00219     DICE_DECLARE_ENV(env);
00220 
00221     if((err = server_init())!=0) return err;
00222 
00223     return l4cpu_reserve_end_periodic_call(&server_id,
00224                                            &thread,
00225                                            &env);
00226 }
00227 
00228 int l4cpu_reserve_watch(l4_threadid_t thread,
00229                         unsigned **addr){
00230     int err;
00231     DICE_DECLARE_ENV(env);
00232     l4dm_dataspace_t ds;
00233     l4_threadid_t preempter;
00234 
00235     if((err = server_init())!=0) return err;
00236 
00237     if((err = l4cpu_reserve_watch_call(&server_id,
00238                                        &thread,
00239                                        &ds,
00240                                        &preempter,
00241                                        &env))!=0) return err;
00242 
00243     l4cpu_reserve_set_preempter(thread, preempter);
00244 
00245     if(addr!=0){
00246         if((err = l4rm_attach(&ds, L4_PAGESIZE, 0, L4DM_RW, (void**)addr))!=0){
00247             /* the server is watching the thread although we cannot see it */
00248             return err;
00249         }
00250     }
00251     return 0;
00252 }
00253 
00254 
00255 int l4cpu_reserve_scheds_count(void){
00256     int err;
00257     DICE_DECLARE_ENV(env);
00258 
00259     if((err = server_init())!=0) return err;
00260 
00261     return l4cpu_reserve_scheds_count_call(&server_id, &env);
00262 }
00263 
00264 int l4cpu_reserve_scheds_get(int idx,
00265                              char **name,
00266                              l4_threadid_t *thread,
00267                              l4_threadid_t *creator,
00268                              int *id,
00269                              int *prio,
00270                              int *period,
00271                              int *wcet,
00272                              int *deadline){
00273     int err;
00274     DICE_DECLARE_ENV(env);
00275 
00276     if((err = server_init())!=0) return err;
00277 
00278     return l4cpu_reserve_scheds_get_call(&server_id,
00279                                          idx,
00280                                          name,
00281                                          thread,
00282                                          creator,
00283                                          id,
00284                                          prio,
00285                                          period,
00286                                          wcet,
00287                                          deadline,
00288                                          &env);
00289 }
00290 
00291 int l4cpu_reserve_time_demand(l4_threadid_t thread,
00292                               int id){
00293     int err;
00294     DICE_DECLARE_ENV(env);
00295 
00296     if((err = server_init())!=0) return err;
00297 
00298     return l4cpu_reserve_time_demand_call(&server_id,
00299                                           &thread, id,
00300                                           &env);
00301 }
00302 

CPU reservation server Reference Manual, written by Jork Loeser  © 2004