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

MaxDecayTaskAdvocate.cc

Go to the documentation of this file.
00001 /*
00002  * MaxDecayTaskAdvocate.cc
00003  *
00004  * Copyright (c) 2003, 2004 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 MaxDecayTaskAdvocate.cc
00014  *
00015  * Implementation of the MaxDecayTaskAdvocate class.
00016  */
00017 
00018 #include "config.h"
00019 
00020 #include <iostream>
00021 
00022 #include <instrumentation.h>
00023 
00024 #include "MaxDecayTaskAdvocate.hh"
00025 
00026 using namespace std;
00027 
00028 #ifndef max
00029 #define max(x, y) (((x) > (y)) ? (x) : (y))
00030 #endif
00031 
00032 /**
00033  * The default number of periods to wait before dropping the reservation to the
00034  * currently observed minimum.
00035  */
00036 #define DECAY_AFTER 5
00037 
00038 MaxDecayTaskAdvocate::MaxDecayTaskAdvocate(void)
00039 {
00040     this->md_LastAdvice = 0;
00041     this->md_Decay = DECAY_AFTER;
00042     this->md_DecayAfter = DECAY_AFTER;
00043 }
00044 
00045 MaxDecayTaskAdvocate::~MaxDecayTaskAdvocate(void)
00046 {
00047 }
00048 
00049 void MaxDecayTaskAdvocate::SetDelegateAttribute(const char *name,
00050                                                 const CORBA::Any &value)
00051     throw (CORBA::SystemException)
00052 {
00053     if( (strcasecmp(name, "decay_after") == 0) ||
00054         (strcasecmp(name, "decay-after") == 0) ||
00055         (strcasecmp(name, "decay after") == 0) )
00056     {
00057         const char *str;
00058         
00059         if( value >>= this->md_DecayAfter )
00060         {
00061         }
00062         else if( (value >>= str) &&
00063                  (sscanf(str, "%d", &this->md_DecayAfter) == 1) )
00064         {
00065         }
00066         else
00067         {
00068             throw CORBA::BAD_PARAM();
00069         }
00070     }
00071     else
00072     {
00073         this->RealTimeTaskDelegateImpl::SetDelegateAttribute(name, value);
00074     }
00075 }
00076 
00077 CORBA::Any_ptr MaxDecayTaskAdvocate::GetDelegateAttribute(const char *name)
00078     throw (CORBA::SystemException)
00079 {
00080     CORBA::Any_var retval;
00081     
00082     if( name == NULL )
00083     {
00084         throw CORBA::BAD_PARAM();
00085     }
00086     else if( (strcasecmp(name, "decay_after") == 0) ||
00087              (strcasecmp(name, "decay-after") == 0) ||
00088              (strcasecmp(name, "decay after") == 0) )
00089     {
00090         retval = new CORBA::Any();
00091         (*retval) <<= this->md_DecayAfter;
00092     }
00093     else if( (strcasecmp(name, "last_advice") == 0) ||
00094              (strcasecmp(name, "last-advice") == 0) ||
00095              (strcasecmp(name, "last advice") == 0) )
00096     {
00097         retval = new CORBA::Any();
00098         (*retval) <<= this->md_LastAdvice;
00099     }
00100     else
00101     {
00102         retval = this->RealTimeTaskDelegateImpl::GetDelegateAttribute(name);
00103     }
00104     return( retval._retn() );
00105 }
00106 
00107 Broker::CPUReserve MaxDecayTaskAdvocate::PassCPU(Broker::RealTimeTask_ptr rtt,
00108                                                  const Broker::CPUReserve &status,
00109                                                  const Broker::CPUReserve &advice,
00110                                                  const Broker::KeyedReportParameters &krp)
00111     throw (CORBA::SystemException)
00112 {
00113     Broker::CPUReserve new_advice = advice;
00114     
00115     if( CORBA::is_nil(this->dm_RemoteObject.in()) )
00116     {
00117         throw CORBA::BAD_INV_ORDER();
00118     }
00119 
00120     if( new_advice.Compute >= this->md_LastAdvice )
00121     {
00122         /* The incoming advice is larger than even our last, start over. */
00123         this->md_Decay = this->md_DecayAfter;
00124         this->md_SubMax = 0;
00125         new_advice.Compute += (CORBA::ULong)(0.01 * new_advice.Compute);
00126     }
00127     else if( this->md_Decay >= 0 )
00128     {
00129         /* The incoming advice is smaller than our last: update the max and */
00130         this->md_SubMax = max(this->md_SubMax, new_advice.Compute);
00131         this->md_Decay -= 1;
00132         /* ... see if it is time to decay. */
00133         if( this->md_Decay == 0 )
00134         {
00135             new_advice.Compute = (CORBA::ULong)
00136                 (this->md_SubMax + (0.01 * this->md_SubMax));
00137             this->md_SubMax = 0;
00138             this->md_Decay = this->md_DecayAfter;
00139         }
00140         else
00141         {
00142             new_advice.Compute = this->md_LastAdvice;
00143         }
00144     }
00145     this->md_LastAdvice = new_advice.Compute;
00146     return this->RealTimeTaskDelegateImpl::PassCPU(rtt,
00147                                                    status,
00148                                                    new_advice,
00149                                                    krp);
00150 }

Generated on Fri Oct 22 07:50:24 2004 for CPU Broker by  doxygen 1.3.9.1