00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00060 #include <new>
00061 #include "generics.h"
00062 #include "BandwidthThrottle.h"
00063 #include "Constant.h"
00064 #include "Platform.h"
00065 #include "Print.h"
00066
00067
00068 static Gcra gcra;
00069
00070
00071
00072
00073
00074 ticks_t BandwidthThrottle::increment(
00075 uint32_t pbps,
00076 uint32_t
00077 ) {
00078 ticks_t hz = gcra.frequency();
00079 ticks_t increment = (0 < pbps) ? (hz + pbps - 1) / pbps : intmaxof(ticks_t);
00080 return increment;
00081 }
00082
00083
00084
00085
00086
00087 ticks_t BandwidthThrottle::limit(
00088 uint32_t ,
00089 uint32_t jt
00090 ) {
00091 ticks_t hz = gcra.frequency();
00092 ticks_t limit = (hz * jt) / Constant::ns_per_s;
00093 return limit;
00094 }
00095
00096
00097
00098
00099
00100 ticks_t BandwidthThrottle::increment(
00101 uint32_t ,
00102 uint32_t ,
00103 uint32_t sbps,
00104 uint32_t
00105 ) {
00106 ticks_t hz = gcra.frequency();
00107 ticks_t increment = (0 < sbps) ? (hz + sbps - 1) / sbps : intmaxof(ticks_t);
00108 return increment;
00109 }
00110
00111
00112
00113
00114
00115 ticks_t BandwidthThrottle::limit(
00116 uint32_t pbps,
00117 uint32_t jt,
00118 uint32_t sbps,
00119 uint32_t mbs
00120 ) {
00121 ticks_t limit = BandwidthThrottle::limit(pbps, jt);
00122 ticks_t pincrement = BandwidthThrottle::increment(pbps, jt);
00123 ticks_t sincrement = BandwidthThrottle::increment(pbps, jt, sbps, mbs);
00124 if ((1 < mbs) && (0 < pincrement) && (pincrement < sincrement)) {
00125 limit += (mbs - 1) * (sincrement - pincrement);
00126 }
00127 return limit;
00128 }
00129
00130
00131
00132
00133
00134 BandwidthThrottle::BandwidthThrottle() :
00135 CompoundThrottle(),
00136 peak(),
00137 sustained()
00138 {
00139 }
00140
00141
00142
00143
00144
00145 BandwidthThrottle::BandwidthThrottle(
00146 uint32_t pbps,
00147 uint32_t jt
00148 ) :
00149 CompoundThrottle(peak),
00150 peak(
00151 this->increment(pbps, jt),
00152 this->limit(pbps, jt)
00153 )
00154 {
00155 }
00156
00157
00158
00159
00160
00161 BandwidthThrottle::BandwidthThrottle(
00162 uint32_t pbps,
00163 uint32_t jt,
00164 uint32_t sbps,
00165 uint32_t mbs
00166 ) :
00167 CompoundThrottle(peak, sustained),
00168 peak(
00169 this->increment(pbps, jt),
00170 this->limit(pbps, jt)
00171 ),
00172 sustained(
00173 this->increment(pbps, jt, sbps, mbs),
00174 this->limit(pbps, jt, sbps, mbs)
00175 )
00176 {
00177 }
00178
00179
00180
00181
00182
00183
00184 BandwidthThrottle::~BandwidthThrottle() {
00185 }
00186
00187
00188
00189
00190
00191 bool BandwidthThrottle::initialize() {
00192 bool rc = false;
00193 try {
00194 this->BandwidthThrottle::~BandwidthThrottle();
00195 new(this) BandwidthThrottle;
00196 rc = true;
00197 } catch (...) {
00198 rc = false;
00199 }
00200 return rc;
00201 }
00202
00203
00204
00205
00206
00207 bool BandwidthThrottle::initialize(
00208 uint32_t pbps,
00209 uint32_t jt
00210 ) {
00211 bool rc = false;
00212 try {
00213 this->BandwidthThrottle::~BandwidthThrottle();
00214 new(this) BandwidthThrottle(pbps, jt);
00215 rc = true;
00216 } catch (...) {
00217 rc = false;
00218 }
00219 return rc;
00220 }
00221
00222
00223
00224
00225
00226 bool BandwidthThrottle::initialize(
00227 uint32_t pbps,
00228 uint32_t jt,
00229 uint32_t sbps,
00230 uint32_t mbs
00231 ) {
00232 bool rc = false;
00233 try {
00234 this->BandwidthThrottle::~BandwidthThrottle();
00235 new(this) BandwidthThrottle(pbps, jt, sbps, mbs);
00236 rc = true;
00237 } catch (...) {
00238 rc = false;
00239 }
00240 return rc;
00241 }
00242
00243
00244
00245
00246 void BandwidthThrottle::show(int level, Output* display, int indent) const {
00247 Platform& pl = Platform::instance();
00248 Print printf(display);
00249 const char* sp = printf.output().indentation(indent);
00250 char component[sizeof(__FILE__)];
00251 printf("%s%s(%p)[%lu]:\n",
00252 sp, pl.component(__FILE__, component, sizeof(component)),
00253 this, sizeof(*this));
00254 this->CompoundThrottle::show(level, display, indent + 1);
00255 printf("%s peak:\n", sp);
00256 this->peak.show(level, display, indent + 2);
00257 printf("%s sustained:\n", sp);
00258 this->sustained.show(level, display, indent + 2);
00259 }