monitor.c

Go to the documentation of this file.
00001 /*!
00002  * \file   cpu_reserve/server/src/monitor.c
00003  * \brief  
00004  *
00005  * \date   11/12/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 <stdio.h>
00014 #include <l4/env/errno.h>
00015 #include <l4/util/macros.h>
00016 #include "monitor.h"
00017 #include "sched.h"
00018 
00019 int enable_rt_mon;
00020 
00021 static inline int thread_equal(l4_threadid_t a, l4_threadid_t b){
00022     return a.id.lthread == b.id.lthread &&
00023         a.id.task == b.id.task;
00024 }
00025 
00026 /*!\brief Start the histogramm of dl overflow of a thread
00027  *
00028  * \pre scheds-lock should be hold outside
00029  */
00030 int monitor_start(const sched_t *sched, const l4_threadid_t *thread){
00031     int i;
00032 
00033     /* find the entry with ID 1, as this determines the maxval and
00034      * the name of the histogram */
00035     lock_scheds();
00036     for(i=0;i<sched_cur_threads;i++){
00037         if(thread_equal(scheds[i]->thread, *thread) &&
00038            scheds[i]->id == 1 && !is_dp(scheds[i])){
00039             /* we found the thread. Create the histogramm */
00040 
00041            char name[RT_MON_NAME_LENGTH];
00042            snprintf(name, sizeof(name), "DL: %s", scheds[i]->name);
00043             scheds[i]->dl_hist = rt_mon_hist_create(0, scheds[i]->wcet,
00044                                                     300,
00045                                                     name, "us", "occ.",
00046                                                     RT_MON_THREAD_TIME);
00047             unlock_scheds();
00048             return 0;
00049         }
00050     }
00051     unlock_scheds();
00052     return -L4_ENOTFOUND;
00053 }
00054 
00055 
00056 /*!\brief Monitor the consumed time of a thread using the rt_mon lib
00057  *
00058  * \param thread        the thread itself
00059  * \param time          consumed time of the thread so far
00060  */
00061 void monitor_thread_dl(l4_threadid_t *thread, l4_cpu_time_t time){
00062     int i;
00063 
00064     //LOG("Period end, thread=" l4util_idfmt, l4util_idstr(*thread));
00065     /* find the thread */
00066     lock_scheds();
00067     for(i=0;i<sched_cur_threads;i++){
00068         if(thread_equal(scheds[i]->thread, *thread) &&
00069            scheds[i]->id == 1 && !is_dp(scheds[i]) && 
00070            scheds[i]->dl_hist){
00071             /* we found the thread. Update its histogramm */
00072             if(scheds[i]->dl_old){
00073                 rt_mon_hist_insert_data(scheds[i]->dl_hist,
00074                                         time-scheds[i]->dl_old,1);
00075             }
00076             scheds[i]->dl_old = time;
00077             goto e_back;
00078         }
00079     }
00080   e_back:
00081     unlock_scheds();
00082 }
00083 
00084 

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