Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

StrictPolicyImpl.hh

Go to the documentation of this file.
00001 /*
00002  * StrictPolicyImpl.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 StrictPolicyImpl.hh
00014  *
00015  * Header file for the StrictPolicyImpl class.
00016  */
00017 
00018 #ifndef _strict_policy_impl_hh
00019 #define _strict_policy_impl_hh
00020 
00021 #include "BrokerC.h"
00022 #include "BrokerS.h"
00023 
00024 #include "StrictPolicyS.h"
00025 
00026 #include "RealTimeSchedule.hh"
00027 
00028 #include "listNode.h"
00029 
00030 /**
00031  * An implementation of the StrictPolicy interface.
00032  */
00033 class StrictPolicyImpl : public virtual POA_BrokerPolicies::StrictPolicy
00034 {
00035     
00036 public:
00037 
00038     /**
00039      * Construct a StrictPolicyImpl object with the given values.
00040      *
00041      * @param name The name of this object as registered with the
00042      *             NamingService.
00043      */
00044     StrictPolicyImpl(const char *name);
00045 
00046     /**
00047      * Deconstruct the policy.
00048      */
00049     virtual ~StrictPolicyImpl();
00050 
00051     /** @copydoc Broker::Policy::Name */
00052     virtual char *Name(void)
00053         throw (CORBA::SystemException);
00054     
00055     /** @copydoc Broker::Policy::AddTask */
00056     virtual void AddTask(Broker::Task_ptr new_task,
00057                          const Broker::ScheduleParameters &sp)
00058         throw (CORBA::SystemException);
00059     /** @copydoc Broker::Policy::RemoveTask */
00060     virtual void RemoveTask(Broker::Task_ptr added_task)
00061         throw (CORBA::SystemException);
00062     
00063     /** @copydoc Broker::Policy::GetTaskList */
00064     virtual Broker::TaskList *GetTaskList(void)
00065         throw (CORBA::SystemException);
00066 
00067     /** @copydoc Broker::Policy::Activate */
00068     virtual void Activate(const Broker::TaskList &tasks)
00069         throw (CORBA::SystemException);
00070     /** @copydoc Broker::Policy::Deactivate */
00071     virtual void Deactivate(void)
00072         throw (CORBA::SystemException);
00073     
00074     /** @copydoc Broker::Policy::ChangeTaskCPU */
00075     virtual void ChangeTaskCPU(Broker::RealTimeTask_ptr task,
00076                                CORBA::ULong ct,
00077                                CORBA::ULong status,
00078                                CORBA::ULong advice)
00079         throw (CORBA::SystemException, Broker::InvalidState);
00080 
00081     /** @copydoc BrokerPolicies::StrictPolicy::GetMaxCPUAllocation */
00082     virtual CORBA::Float GetMaxCPUAllocation(void)
00083         throw (CORBA::SystemException);
00084     /** @copydoc BrokerPolicies::StrictPolicy::SetMaxCPUAllocation */
00085     virtual void SetMaxCPUAllocation(CORBA::Float amount)
00086         throw (CORBA::SystemException);
00087 
00088     /** @copydoc BrokerPolicies::StrictPolicy::SetTaskPriority */
00089     virtual void SetTaskPriority(Broker::Task_ptr task, CORBA::Short priority)
00090         throw (CORBA::SystemException);
00091 
00092     /** @copydoc BrokerPolicies::StrictPolicy::GetTaskPriority */
00093     virtual CORBA::Short GetTaskPriority(Broker::Task_ptr task)
00094         throw (CORBA::SystemException);
00095 
00096     /**
00097      * Maximum percentage of CPU to allocate to tasks.
00098      */
00099     const static float DEFAULT_MAX_USED_CPU = 0.75;
00100 
00101     /**
00102      * Minimum percentage of CPU to allocate to a single task.
00103      */
00104     const static float DEFAULT_MIN_TASK_CPU = 0.02;
00105 
00106 private:
00107 
00108     enum {
00109         TPB_STARVED,
00110     };
00111 
00112     /*
00113      * Flags for the TaskPriority structure.
00114      *
00115      * TPF_STARVED - The task is starved for resources.  This flag is used to
00116      * determine whether or not GiveCPU() will give CPU to a task or just
00117      * return it to the free CPU pool.
00118      */
00119     enum {
00120         TPF_STARVED = (1L << TPB_STARVED),
00121     };
00122 
00123     /**
00124      * List node used to track tasks that this policy is managing.
00125      */
00126     struct TaskPriority {
00127         struct lnNode tp_Link;
00128         unsigned int tp_Flags;
00129         struct TaskPriority *tp_SubLink;
00130         RealTimeSchedule tp_Schedule;
00131         CORBA::ULong tp_SubTime;
00132         CORBA::ULong tp_ComputeTime;
00133         Broker::RealTimeTask_var tp_Task;
00134     };
00135 
00136     /**
00137      * Repair the task list by removing any dead/unreachable objects.
00138      */
00139     void RepairTaskList(void);
00140 
00141     /**
00142      * Find the TaskPriority node that corresponds to the given task.
00143      *
00144      * @param task The Broker::RealTimeTask object to look up.
00145      * @return The TaskPriority list node that has the given task object.
00146      * @exception Broker::Internal If no TaskPriority node exists for the given
00147      *            task.
00148      */
00149     struct TaskPriority *FindTaskPriority(Broker::RealTimeTask_ptr task);
00150 
00151     /**
00152      * Construct a list, ordered from lowest to highest priority, of the tasks
00153      * whose schedule intersects with the given one.
00154      *
00155      * @param rts The schedule to match.
00156      * @param ignore The TaskPriority node to ignore when building the list or
00157      *               NULL if no nodes should be ignored.
00158      * @return The list of nodes, linked by tp_SubLink, that match the given
00159      *         schedule.
00160      */
00161     struct TaskPriority *SubList(const RealTimeSchedule &rts,
00162                                  struct TaskPriority *ignore);
00163 
00164     /**
00165      * Take CPU time from other tasks to give to another.
00166      *
00167      * @param sub_list The list of tasks to take CPU time from, typically built
00168      *                 with the SubList() method.
00169      * @param amount The amount of CPU time to take away.
00170      * @param for_tp The node that will be given the CPU time.
00171      * @return The actual amount of CPU time that can be given to the task.
00172      */
00173     CORBA::ULong TakeCPU(struct TaskPriority *sub_list,
00174                          CORBA::ULong amount,
00175                          struct TaskPriority *for_tp);
00176 
00177     /**
00178      * Give CPU time back to the other tasks.
00179      *
00180      * @param sub_list The list of tasks to give CPU time to, typically  built
00181      *                 with the SubList() method.
00182      * @param amount The amount of CPU time to give out.
00183      * @param for_tp The donating task.
00184      * @return XXX ...
00185      */
00186     CORBA::ULong GiveCPU(struct TaskPriority *sub_list,
00187                          CORBA::ULong amount,
00188                          struct TaskPriority *for_tp);
00189 
00190     /** The name of this object as registered with the NamingService. */
00191     CORBA::String_var sp_Name;
00192 
00193     /** The maximum percentage of CPU time that we are allowed to allocate. */
00194     float sp_MaxUsedCPU;
00195 
00196     /** The minimum percentage of CPU time that a task must have. */
00197     float sp_MinTaskCPU;
00198 
00199     /** A list of TaskPriority objects */
00200     struct lnList sp_List;
00201     
00202     /** The largest deadline of the tasks managed by this policy. */
00203     CORBA::ULong sp_MaxDeadline;
00204 
00205     /** Fake task object used to represent CPU time that is not reserved. */
00206     struct TaskPriority sp_FauxTask;
00207 
00208 };
00209 
00210 #endif

Generated on Mon Dec 1 16:29:07 2003 for CPU Broker by doxygen 1.3.4