|
xrootd
|
00001 #ifndef ___XRD_SCHED_H___ 00002 #define ___XRD_SCHED_H___ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d S c h e d u l e r . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC03-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 #include <unistd.h> 00014 #include <sys/types.h> 00015 00016 #include "XrdSys/XrdSysPthread.hh" 00017 #include "Xrd/XrdJob.hh" 00018 00019 class XrdOucTrace; 00020 class XrdSchedulerPID; 00021 class XrdSysError; 00022 00023 class XrdScheduler : public XrdJob 00024 { 00025 public: 00026 00027 int Active() {return num_Workers - idl_Workers + num_JobsinQ;} 00028 00029 void Cancel(XrdJob *jp); 00030 00031 inline int canStick() {return num_Workers < stk_Workers 00032 || (num_Workers-idl_Workers) < stk_Workers;} 00033 00034 void DoIt(); 00035 00036 pid_t Fork(const char *id); 00037 00038 void *Reaper(); 00039 00040 void Run(); 00041 00042 void Schedule(XrdJob *jp); 00043 void Schedule(int num, XrdJob *jfirst, XrdJob *jlast); 00044 void Schedule(XrdJob *jp, time_t atime); 00045 00046 void setParms(int minw, int maxw, int avlt, int maxi, int once=0); 00047 00048 void Start(); 00049 00050 int Stats(char *buff, int blen, int do_sync=0); 00051 00052 void TimeSched(); 00053 00054 // Statistical information 00055 // 00056 int num_TCreate; // Number of threads created 00057 int num_TDestroy;// Number of threads destroyed 00058 int num_Jobs; // Number of jobs scheduled 00059 int max_QLength; // Longest queue length we had 00060 int num_Limited; // Number of times max was reached 00061 00062 // Constructor and destructor 00063 // 00064 XrdScheduler(XrdSysError *eP, XrdOucTrace *tP, 00065 int minw=8, int maxw=2048, int maxi=780); 00066 00067 ~XrdScheduler(); 00068 00069 private: 00070 XrdSysError *XrdLog; 00071 XrdOucTrace *XrdTrace; 00072 00073 XrdSysMutex DispatchMutex; // Disp: Protects above area 00074 int idl_Workers; // Disp: Number of idle workers 00075 00076 int min_Workers; // Sched: Min threads we need to have 00077 int max_Workers; // Sched: Max threads we can start 00078 int max_Workidl; // Sched: Max idle time for threads above min_Workers 00079 int num_Workers; // Sched: Number of threads we have 00080 int stk_Workers; // Sched: Number of sticky workers we can have 00081 int num_JobsinQ; // Sched: Number of outstanding jobs in the queue 00082 int num_Layoffs; // Sched: Number of threads to terminate 00083 00084 XrdJob *WorkFirst; // Pending work 00085 XrdJob *WorkLast; 00086 XrdSysSemaphore WorkAvail; 00087 XrdSysMutex SchedMutex; // Protects private area 00088 00089 XrdJob *TimerQueue; // Pending work 00090 XrdSysCondVar TimerRings; 00091 XrdSysMutex TimerMutex; // Protects scheduler area 00092 00093 XrdSchedulerPID *firstPID; 00094 XrdSysMutex ReaperMutex; 00095 00096 void hireWorker(int dotrace=1); 00097 void Monitor(); 00098 void traceExit(pid_t pid, int status); 00099 static const char *TraceID; 00100 }; 00101 #endif
1.7.5