Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-02 10:13:36

0001 #ifndef ___XRD_SCHED_H___
0002 #define ___XRD_SCHED_H___
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                       X r d S c h e d u l e r . h h                        */
0006 /*                                                                            */
0007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0009 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0010 /*                                                                            */
0011 /* This file is part of the XRootD software suite.                            */
0012 /*                                                                            */
0013 /* XRootD is free software: you can redistribute it and/or modify it under    */
0014 /* the terms of the GNU Lesser General Public License as published by the     */
0015 /* Free Software Foundation, either version 3 of the License, or (at your     */
0016 /* option) any later version.                                                 */
0017 /*                                                                            */
0018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0021 /* License for more details.                                                  */
0022 /*                                                                            */
0023 /* You should have received a copy of the GNU Lesser General Public License   */
0024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0026 /*                                                                            */
0027 /* The copyright holder's institutional names and contributor's names may not */
0028 /* be used to endorse or promote products derived from this software without  */
0029 /* specific prior written permission of the institution or contributor.       */
0030 /******************************************************************************/
0031 
0032 #include <unistd.h>
0033 #include <sys/types.h>
0034 
0035 #include "XrdSys/XrdSysPthread.hh"
0036 #include "Xrd/XrdJob.hh"
0037 
0038 class XrdOucTrace;
0039 class XrdSchedulerPID;
0040 class XrdSysError;
0041 class XrdSysTrace;
0042 
0043 #define MAX_SCHED_PROCS 30000
0044 #define DFL_SCHED_PROCS  8192
0045 
0046 class XrdScheduler : public XrdJob
0047 {
0048 public:
0049 
0050 int           Active() {return num_Workers - idl_Workers + num_JobsinQ;}
0051 
0052 void          Cancel(XrdJob *jp);
0053 
0054 inline int    canStick() {return  num_Workers              < stk_Workers
0055                               || (num_Workers-idl_Workers) < stk_Workers;}
0056 
0057 void          DoIt();
0058 
0059 pid_t         Fork(const char *id);
0060 
0061 void         *Reaper();
0062 
0063 void          Run();
0064 
0065 void          Schedule(XrdJob *jp);
0066 void          Schedule(int num, XrdJob *jfirst, XrdJob *jlast);
0067 void          Schedule(XrdJob *jp, time_t atime);
0068 
0069 void          setParms(int minw, int maxw, int avlt, int maxi, int once=0);
0070 
0071 void          Start();
0072 
0073 int           Stats(char *buff, int blen, int do_sync=0);
0074 
0075 void          TimeSched();
0076 
0077 void          setNproc(const bool limlower);
0078 
0079 // Statistical information
0080 //
0081 int        num_TCreate; // Number of threads created
0082 int        num_TDestroy;// Number of threads destroyed
0083 int        num_Jobs;    // Number of jobs scheduled
0084 int        max_QLength; // Longest queue length we had
0085 int        num_Limited; // Number of times max was reached
0086 
0087 // This is the preferred constructor
0088 //
0089               XrdScheduler(XrdSysError *eP, XrdSysTrace *tP,
0090                            int minw=8, int maxw=8192, int maxi=780);
0091 
0092 // This constructor is only maintained for ABI compatibility and will be
0093 // removed in a future major release. While syntactically compatible the
0094 // sematics now are slightly different and tracing might not occur.
0095 //
0096               XrdScheduler(XrdSysError *eP, XrdOucTrace *tP,
0097                            int minw=8, int maxw=8192, int maxi=780);
0098 
0099 // This constructor is used for a stand-alone scheduler.
0100 //
0101               XrdScheduler(int minw=3, int maxw=128,  int maxi=12);
0102 
0103              ~XrdScheduler();
0104 
0105 private:
0106 XrdSysError *XrdLog;
0107 XrdSysTrace *XrdTrace;
0108 XrdOucTrace *XrdTraceOld;  // This is only used for ABI compatibility
0109 
0110 XrdSysMutex DispatchMutex; // Disp: Protects above area
0111 int        idl_Workers;    // Disp: Number of idle workers
0112 
0113 int        min_Workers;   // Sched: Min threads we need to have
0114 int        max_Workers;   // Sched: Max threads we can start
0115 int        max_Workidl;   // Sched: Max idle time for threads above min_Workers
0116 int        num_Workers;   // Sched: Number of threads we have
0117 int        stk_Workers;   // Sched: Number of sticky workers we can have
0118 int        num_JobsinQ;   // Sched: Number of outstanding jobs in the queue
0119 int        num_Layoffs;   // Sched: Number of threads to terminate
0120 
0121 XrdJob                *WorkFirst;  // Pending work
0122 XrdJob                *WorkLast;
0123 XrdSysSemaphore        WorkAvail;
0124 XrdSysMutex            SchedMutex; // Protects private area
0125 
0126 XrdJob                *TimerQueue; // Pending work
0127 XrdSysCondVar          TimerRings;
0128 XrdSysMutex            TimerMutex; // Protects scheduler area
0129 
0130 XrdSchedulerPID       *firstPID;
0131 XrdSysMutex            ReaperMutex;
0132 
0133 void Boot(XrdSysError *eP, XrdSysTrace *tP, int minw, int maxw, int maxi);
0134 void hireWorker(int dotrace=1);
0135 void Init(int minw, int maxw, int maxi);
0136 void Monitor();
0137 void traceExit(pid_t pid, int status);
0138 static const char *TraceID;
0139 };
0140 #endif