00001
#ifndef SCHEDULER_H
00002
#define SCHEDULER_H
00003
00004
#include <nmstl_util.h>
00005
#include "Registry.h"
00006
#include <queue>
00007
#include <string>
00008
00009 BOREALIS_NAMESPACE_BEGIN;
00010
00011
class AuroraNode;
00012
class QBox;
00013
00014 class SchedStats
00015 {
00016
public:
00017
00018 map<string, deque<double> >
_selectivities;
00019 map<string, deque<double> >
_box_costs;
00020 map<string, deque<double> >
_avg_queue_increment;
00021
00022 int cpu_load;
00023 };
00024
00025 class SchedulerStats
00026 {
00027
public:
00028 map<string, double >
_total_cost;
00029 map<string, int >
_execution_count;
00030
00031 map<string, int>
_total_input;
00032 map<string, int>
_total_output;
00033
00034 map<string, deque<double> >
_selectivities;
00035 map<string, deque<double> >
_avg_queue_increment;
00036
00037 map<string, double >
_box_costs,
_shadow_box_costs;
00038 map<string, int >
_box_executions,
_shadow_box_executions;
00039
00040 map<string, double >
_queue_sizes,
_shadow_queue_sizes;
00041 map<string, int>
_queue_entries,
_shadow_queue_entries;
00042
00043 map<string, int>
_last_enq_tuples,
_curr_enq_tuples;
00044 };
00045
00046
00051 class SchedulerTask {
00052
public:
00054 virtual ~SchedulerTask() {}
00055
00057
virtual void run() = 0;
00058 };
00059
00074 class Scheduler {
00075
friend class AuroraNode;
00076
00077
public:
00078 typedef Registry<Scheduler> Registry;
00079
00081 class BoxData {
00082
public:
00083 virtual ~BoxData() {}
00084 };
00085
00086
virtual ~Scheduler();
00087
00090 AuroraNode&
node() {
return *_node; }
00091
00094
virtual void start() = 0;
00095
00099
virtual void shutdown() = 0;
00100
00109
virtual void scheduleExclusiveTask(ptr<SchedulerTask>) = 0;
00110
00116 virtual void topologyChanged() { ASSERT(_dynamic_support); }
00117
00120 bool hasDynamicSupport() {
return _dynamic_support; }
00121
00127 virtual void drain() { ASSERT(_drain_support); }
00128
00130 bool hasDrain() {
return _drain_support; }
00131
00132
static unsigned long ticks();
00133
00134
00135
00136
00137 static double secondsPerTick() {
return (1<<21) / 3.9e9; }
00138
00139
00140
00141 static unsigned long ticksPerSecond() {
return 1335; }
00142
00143
00144 SchedulerStats _sched_stats;
00145
00146
00147
virtual void invalidateBoxes( vector<string> boxNames );
00148
00149
virtual void updateListeners( vector<string> boxNames,
bool add );
00150
00151
virtual void chokeSubNetwork ( vector<string> boxNames );
00152
00153
virtual void suspendSubNetwork ( vector<string> boxNames );
00154
00155
virtual void resumeSubNetwork( vector<string> boxNames );
00156
00157
virtual void drainSubNetwork( vector<string> boxNames );
00158
00159 virtual void removeFromSchedule(
QBox* box) { }
00160
00161
virtual string
to_string();
00162
00163
00164
virtual void init_sched_stats(
int windowSize,
int historySize );
00165
00166
protected:
00167 unsigned int _init_time;
00168
00169
void setBoxData(
QBox& box, ptr<BoxData> data);
00170
BoxData *
getBoxData(
const QBox& box)
const;
00171
00178
Scheduler(
bool dynamic_support =
false,
bool drain_support =
false);
00179
00180
private:
00181
AuroraNode *_node;
00182
00183
bool _dynamic_support;
00184
bool _drain_support;
00185 };
00186
00187 inline unsigned long Scheduler::ticks()
00188 {
00189
unsigned int low, high;
00190
asm volatile (
"rdtsc" :
"=a" (low),
"=d" (high));
00191
00192
return (high<<11) + (low>>21);
00193 }
00194
00195 #define AURORA_DECLARE_SCHEDULER(ClassName) AURORA_DECLARE_REG_CLASS(Scheduler, ClassName)
00196 #define AURORA_DEFINE_SCHEDULER(ClassName) \
00197
AURORA_DEFINE_REG_CLASS(Scheduler, ClassName)
00198
00199 BOREALIS_NAMESPACE_END;
00200
00201
00202
#include "QBox.h"
00203
00204
#endif