00001 #ifndef ___XRD_SCHED_H___
00002 #define ___XRD_SCHED_H___
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 #include <unistd.h>
00033 #include <sys/types.h>
00034
00035 #include "XrdSys/XrdSysPthread.hh"
00036 #include "Xrd/XrdJob.hh"
00037
00038 class XrdOucTrace;
00039 class XrdSchedulerPID;
00040 class XrdSysError;
00041
00042 #define MAX_SCHED_PROCS 30000
00043
00044 class XrdScheduler : public XrdJob
00045 {
00046 public:
00047
00048 int Active() {return num_Workers - idl_Workers + num_JobsinQ;}
00049
00050 void Cancel(XrdJob *jp);
00051
00052 inline int canStick() {return num_Workers < stk_Workers
00053 || (num_Workers-idl_Workers) < stk_Workers;}
00054
00055 void DoIt();
00056
00057 pid_t Fork(const char *id);
00058
00059 void *Reaper();
00060
00061 void Run();
00062
00063 void Schedule(XrdJob *jp);
00064 void Schedule(int num, XrdJob *jfirst, XrdJob *jlast);
00065 void Schedule(XrdJob *jp, time_t atime);
00066
00067 void setParms(int minw, int maxw, int avlt, int maxi, int once=0);
00068
00069 void Start();
00070
00071 int Stats(char *buff, int blen, int do_sync=0);
00072
00073 void TimeSched();
00074
00075
00076
00077 int num_TCreate;
00078 int num_TDestroy;
00079 int num_Jobs;
00080 int max_QLength;
00081 int num_Limited;
00082
00083
00084
00085 XrdScheduler(XrdSysError *eP, XrdOucTrace *tP,
00086 int minw=8, int maxw=8192, int maxi=780);
00087
00088 XrdScheduler(int minw=3, int maxw=128, int maxi=12);
00089
00090 ~XrdScheduler();
00091
00092 private:
00093 XrdSysError *XrdLog;
00094 XrdOucTrace *XrdTrace;
00095
00096 XrdSysMutex DispatchMutex;
00097 int idl_Workers;
00098
00099 int min_Workers;
00100 int max_Workers;
00101 int max_Workidl;
00102 int num_Workers;
00103 int stk_Workers;
00104 int num_JobsinQ;
00105 int num_Layoffs;
00106
00107 XrdJob *WorkFirst;
00108 XrdJob *WorkLast;
00109 XrdSysSemaphore WorkAvail;
00110 XrdSysMutex SchedMutex;
00111
00112 XrdJob *TimerQueue;
00113 XrdSysCondVar TimerRings;
00114 XrdSysMutex TimerMutex;
00115
00116 XrdSchedulerPID *firstPID;
00117 XrdSysMutex ReaperMutex;
00118
00119 void hireWorker(int dotrace=1);
00120 void Init(int minw, int maxw, int maxi);
00121 void Monitor();
00122 void traceExit(pid_t pid, int status);
00123 static const char *TraceID;
00124 };
00125 #endif