00001 /* 00002 * BasicDelegate.hh 00003 * 00004 * Copyright (c) 2003 The University of Utah and the Flux Group. 00005 * All rights reserved. 00006 * 00007 * This file is licensed under the terms of the GNU Public License. 00008 * See the file "license.terms" for restrictions on redistribution 00009 * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 00010 */ 00011 00012 /** 00013 * @file BasicDelegate.hh 00014 * 00015 * Header file for a delegate that makes basic reports to a 00016 * Broker::RealTimeAdvocate. 00017 */ 00018 00019 #ifndef _basic_delegate_hh 00020 #define _basic_delegate_hh 00021 00022 #include <sys/types.h> 00023 #include <sys/time.h> 00024 #include <sys/resource.h> 00025 00026 #include <rk.h> 00027 #include <rk_stub.h> 00028 00029 #include <time_util.h> 00030 00031 #include <BrokerC.h> 00032 00033 #include "FakeDelegate.hh" 00034 00035 /** 00036 * A simple delegate that computes the number of deadlines missed and passes 00037 * the value to Broker::RealTimeAdvocate::ReportCPU. 00038 */ 00039 class BasicDelegate : public FakeDelegate 00040 { 00041 00042 public: 00043 00044 /** 00045 * Construct a BasicDelegate with the given values. This includes: 00046 * 00047 * @li Creating the process with rk_stub_mk_pid. 00048 * @li Initializing the bd_TaskDescription and bd_CPUSchedule parameter 00049 * lists. 00050 * @li and initializing internal state. 00051 * 00052 * @param name The name of the process. This will be passed on to 00053 * rk_stub_mk_pid. 00054 * @param period The period of the process in microseconds. 00055 * @param deadline The deadline of the process in microseconds and relative 00056 * to the start of the period. 00057 */ 00058 BasicDelegate(const char *name, 00059 unsigned long period, 00060 unsigned long deadline); 00061 00062 /** 00063 * Deconstruct a BasicDelegate. 00064 */ 00065 virtual ~BasicDelegate(); 00066 00067 /** 00068 * Premethod callback that just records the current time. 00069 * 00070 * @return RKSP_OK if the process is on schedule or RKSP_DROP if it is 00071 * running late and needs to drop data in order to catch up. 00072 */ 00073 virtual rk_stub_precall_retval_t precall(void); 00074 00075 /** 00076 * Postmethod callback that computes how many deadlines have been missed 00077 * and reports the results to bd_Advocate. 00078 */ 00079 virtual void postcall(void); 00080 00081 /** 00082 * TaskParameters constructed by the object that can be passed on to 00083 * Broker::TaskFactory::CreateTask. 00084 */ 00085 Broker::TaskParameters bd_TaskDescription; 00086 00087 /** 00088 * ScheduleParameters constructed by the object that can be passed on to 00089 * Broker::Task::BeginScheduling. 00090 */ 00091 Broker::ScheduleParameters bd_CPUSchedule; 00092 00093 /** 00094 * The process' advocate, this must be set by the code using the object. 00095 * The user must also call Broker::Task::BeginCPUScheduling and 00096 * Broker::Task::EndCPUScheduling. 00097 */ 00098 Broker::RealTimeTask_var bd_Advocate; 00099 00100 protected: 00101 00102 /** 00103 * The period of the process in microseconds. 00104 */ 00105 unsigned long bd_Period; 00106 00107 /** 00108 * The deadline of the process in microseconds and relative to the start of 00109 * the period. 00110 */ 00111 unsigned long bd_Deadline; 00112 00113 /** 00114 * The number of data segments to drop in order to get back on schedule. 00115 * This will be set by postcall() when it detects how many deadlines have 00116 * been missed. 00117 */ 00118 int bd_AdviseDrop; 00119 00120 /** 00121 * The simulated process ID. 00122 */ 00123 pid_t bd_PID; 00124 00125 /** 00126 * The "method" starting time as recorded by precall(). 00127 */ 00128 struct timespec bd_Start; 00129 00130 /** 00131 * The resource usage at the "method" starting time. 00132 */ 00133 struct rusage bd_RUStart; 00134 00135 }; 00136 00137 #endif