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();
00089
00090 private:
00091 XrdSysError *XrdLog;
00092 XrdOucTrace *XrdTrace;
00093
00094 XrdSysMutex DispatchMutex;
00095 int idl_Workers;
00096
00097 int min_Workers;
00098 int max_Workers;
00099 int max_Workidl;
00100 int num_Workers;
00101 int stk_Workers;
00102 int num_JobsinQ;
00103 int num_Layoffs;
00104
00105 XrdJob *WorkFirst;
00106 XrdJob *WorkLast;
00107 XrdSysSemaphore WorkAvail;
00108 XrdSysMutex SchedMutex;
00109
00110 XrdJob *TimerQueue;
00111 XrdSysCondVar TimerRings;
00112 XrdSysMutex TimerMutex;
00113
00114 XrdSchedulerPID *firstPID;
00115 XrdSysMutex ReaperMutex;
00116
00117 void hireWorker(int dotrace=1);
00118 void Monitor();
00119 void traceExit(pid_t pid, int status);
00120 static const char *TraceID;
00121 };
00122 #endif