XRootD
XrdScheduler Class Reference

#include <XrdScheduler.hh>

+ Inheritance diagram for XrdScheduler:
+ Collaboration diagram for XrdScheduler:

Public Member Functions

 XrdScheduler (int minw=3, int maxw=128, int maxi=12)
 
 XrdScheduler (XrdSysError *eP, XrdOucTrace *tP, int minw=8, int maxw=8192, int maxi=780)
 
 XrdScheduler (XrdSysError *eP, XrdSysTrace *tP, int minw=8, int maxw=8192, int maxi=780)
 
 ~XrdScheduler ()
 
int Active ()
 
void Cancel (XrdJob *jp)
 
int canStick ()
 
void DoIt ()
 
pid_t Fork (const char *id)
 
void * Reaper ()
 
void Run ()
 
void Schedule (int num, XrdJob *jfirst, XrdJob *jlast)
 
void Schedule (XrdJob *jp)
 
void Schedule (XrdJob *jp, time_t atime)
 
void setNproc (const bool limlower)
 
void setParms (int minw, int maxw, int avlt, int maxi, int once=0)
 
void Start ()
 
int Stats (char *buff, int blen, int do_sync=0)
 
void TimeSched ()
 
- Public Member Functions inherited from XrdJob
 XrdJob (const char *desc="")
 
virtual ~XrdJob ()
 

Public Attributes

int max_QLength
 
int num_Jobs
 
int num_Limited
 
int num_TCreate
 
int num_TDestroy
 
- Public Attributes inherited from XrdJob
const char * Comment
 
XrdJob * NextJob
 

Detailed Description

Definition at line 46 of file XrdScheduler.hh.

Constructor & Destructor Documentation

◆ XrdScheduler() [1/3]

XrdScheduler::XrdScheduler ( XrdSysError *  eP,
XrdSysTrace *  tP,
int  minw = 8,
int  maxw = 8192,
int  maxi = 780 
)

Definition at line 97 of file XrdScheduler.cc.

99  : XrdJob("underused thread monitor"),
100  XrdTraceOld(0), WorkAvail(0, "sched work"),
101  TimerRings(TimerMutex)
102 {
103  Boot(eP, tP, minw, maxw, maxi);
104 }
XrdJob(const char *desc="")
Definition: XrdJob.hh:51

◆ XrdScheduler() [2/3]

XrdScheduler::XrdScheduler ( XrdSysError *  eP,
XrdOucTrace *  tP,
int  minw = 8,
int  maxw = 8192,
int  maxi = 780 
)

Definition at line 109 of file XrdScheduler.cc.

111  : XrdJob("underused thread monitor"),
112  XrdTraceOld(tP), WorkAvail(0, "sched work"),
113  TimerRings(TimerMutex)
114 {
115 
116 // Invoke the main initialization function with a new style trace object
117 //
118  Boot(eP, new XrdSysTrace("Xrd", eP->logger()), minw, maxw, maxi);
119 }
XrdSysLogger * logger(XrdSysLogger *lp=0)
Definition: XrdSysError.hh:141

References XrdSysError::logger().

+ Here is the call graph for this function:

◆ XrdScheduler() [3/3]

XrdScheduler::XrdScheduler ( int  minw = 3,
int  maxw = 128,
int  maxi = 12 
)

Definition at line 125 of file XrdScheduler.cc.

126  : XrdJob("underused thread monitor"),
127  XrdTraceOld(0), WorkAvail(0, "sched work"),
128  TimerRings(TimerMutex)
129 {
131  int eFD;
132 
133 // Get a file descriptor mirroring standard error
134 //
135 #if ( defined(__linux__) || defined(__GNU__) ) && defined(F_DUPFD_CLOEXEC)
136  eFD = fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 0);
137 #else
138  eFD = dup(STDERR_FILENO);
139  fcntl(eFD, F_SETFD, FD_CLOEXEC);
140 #endif
141 
142 // Now we need to get a logger object. We make this a real dumb one.
143 //
144  Logger = new XrdSysLogger(eFD, 0);
145  XrdLog = new XrdSysError(Logger);
146 
147 // Now get a trace object
148 //
149  XrdTrace = new XrdSysTrace("Xrd", Logger);
150  if (getenv("XRDDEBUG") != 0) XrdTrace->What = TRACE_SCHED;
151 
152 // Set remaining values. We do no use maximum possible threads here.
153 //
154  Init(minw, maxw, maxi);
155 }
#define TRACE_SCHED
Definition: XrdTrace.hh:42
XrdSysLogger Logger
Definition: XrdGlobals.cc:47

References XrdGlobal::Logger, TRACE_SCHED, and XrdSysTrace::What.

◆ ~XrdScheduler()

XrdScheduler::~XrdScheduler ( )

Definition at line 180 of file XrdScheduler.cc.

181 {
182 }

Member Function Documentation

◆ Active()

int XrdScheduler::Active ( )
inline

Definition at line 50 of file XrdScheduler.hh.

50 {return num_Workers - idl_Workers + num_JobsinQ;}

Referenced by XrdStats::Report().

+ Here is the caller graph for this function:

◆ Cancel()

void XrdScheduler::Cancel ( XrdJob *  jp)

Definition at line 188 of file XrdScheduler.cc.

189 {
190  XrdJob *p, *pp = 0;
191 
192 // Lock the queue
193 //
194  TimerMutex.Lock();
195 
196 // Find the matching job, if any
197 //
198  p = TimerQueue;
199  while(p && p != jp) {pp = p; p = p->NextJob;}
200 
201 // Delete the job element
202 //
203  if (p)
204  {if (pp) pp->NextJob = p->NextJob;
205  else TimerQueue = p->NextJob;
206  TRACE(SCHED, "time event " <<jp->Comment <<" cancelled");
207  }
208 
209 // All done
210 //
211  TimerMutex.UnLock();
212 }
#define TRACE(act, x)
Definition: XrdTrace.hh:63
Definition: XrdJob.hh:43
XrdJob * NextJob
Definition: XrdJob.hh:46
const char * Comment
Definition: XrdJob.hh:47

References XrdJob::Comment, XrdSysMutex::Lock(), XrdJob::NextJob, TRACE, and XrdSysMutex::UnLock().

Referenced by XrdXrootdJob::~XrdXrootdJob(), XrdXrootdTransit::Recycle(), Schedule(), and setParms().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ canStick()

int XrdScheduler::canStick ( )
inline

Definition at line 54 of file XrdScheduler.hh.

54  {return num_Workers < stk_Workers
55  || (num_Workers-idl_Workers) < stk_Workers;}

Referenced by XrdLinkXeq::DoIt().

+ Here is the caller graph for this function:

◆ DoIt()

void XrdScheduler::DoIt ( )
virtual

Implements XrdJob.

Definition at line 218 of file XrdScheduler.cc.

219 {
220  int num_kill, num_idle;
221 
222 // Now check if there are too many idle threads (kill them if there are)
223 //
224  if (!num_JobsinQ)
225  {DispatchMutex.Lock(); num_idle = idl_Workers; DispatchMutex.UnLock();
226  num_kill = num_idle - min_Workers;
227  TRACE(SCHED, num_Workers <<" threads; " <<num_idle <<" idle");
228  if (num_kill > 0)
229  {if (num_kill > 1) num_kill = num_kill/2;
230  SchedMutex.Lock();
231  num_Layoffs = num_kill;
232  while(num_kill--) WorkAvail.Post();
233  SchedMutex.UnLock();
234  }
235  }
236 
237 // Check if we should reschedule ourselves
238 //
239  if (max_Workidl > 0) Schedule((XrdJob *)this, max_Workidl+time(0));
240 }
void Schedule(XrdJob *jp)

References XrdSysMutex::Lock(), XrdSysSemaphore::Post(), Schedule(), TRACE, and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ Fork()

pid_t XrdScheduler::Fork ( const char *  id)

Definition at line 248 of file XrdScheduler.cc.

249 {
250  static int retc, ReaperStarted = 0;
251  pthread_t tid;
252  pid_t pid;
253 
254 // Fork
255 //
256  if ((pid = fork()) < 0)
257  {XrdLog->Emsg("Scheduler",errno,"fork to handle",id);
258  return pid;
259  }
260  if (!pid) return pid;
261 
262 // Obtain the status of the reaper thread.
263 //
264  ReaperMutex.Lock();
265  firstPID = new XrdSchedulerPID(pid, firstPID);
266  retc = ReaperStarted;
267  ReaperStarted = 1;
268  ReaperMutex.UnLock();
269 
270 // Start the reaper thread if it has not started.
271 //
272  if (!retc)
273  if ((retc = XrdSysThread::Run(&tid, XrdStartReaper, (void *)this,
274  0, "Process reaper")))
275  {XrdLog->Emsg("Scheduler", retc, "create reaper thread");
276  ReaperStarted = 0;
277  }
278 
279  return pid;
280 }
void * XrdStartReaper(void *carg)
Definition: XrdScheduler.cc:75
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)

References XrdSysError::Emsg(), XrdSysMutex::Lock(), XrdSysThread::Run(), XrdSysMutex::UnLock(), and XrdStartReaper().

+ Here is the call graph for this function:

◆ Reaper()

void * XrdScheduler::Reaper ( )

Definition at line 286 of file XrdScheduler.cc.

287 {
288  int status;
289  pid_t pid;
290  XrdSchedulerPID *tp, *ptp, *xtp;
291 #if defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_5)
292  struct timespec ts = { 1, 0 };
293 #else
294  sigset_t Sset;
295  int signum;
296 
297 // Set up for signal handling. Note: main() must block this signal at start)
298 //
299  sigemptyset(&Sset);
300  sigaddset(&Sset, SIGCHLD);
301 #endif
302 
303 // Wait for all outstanding children
304 //
305  do {ReaperMutex.Lock();
306  tp = firstPID; ptp = 0;
307  while(tp)
308  {do {pid = waitpid(tp->pid, &status, WNOHANG);}
309  while (pid < 0 && errno == EINTR);
310  if (pid > 0)
311  {if (TRACING(TRACE_SCHED)) traceExit(pid, status);
312  xtp = tp; tp = tp->next;
313  if (ptp) ptp->next = tp;
314  else firstPID = tp;
315  delete xtp;
316  } else {ptp = tp; tp = tp->next;}
317  }
318  ReaperMutex.UnLock();
319 #if defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_5)
320  // Mac OS X sigwait() is broken on <= 10.4.
321  } while (nanosleep(&ts, 0) <= 0);
322 #else
323  } while(sigwait(&Sset, &signum) >= 0);
324 #endif
325  return (void *)0;
326 }
static std::string ts()
timestamp output for logging messages
Definition: XrdCephOss.cc:53
#define TRACING(x)
Definition: XrdTrace.hh:70
XrdSchedulerPID * next
Definition: XrdScheduler.cc:63

References XrdSysMutex::Lock(), XrdSchedulerPID::next, XrdSchedulerPID::pid, TRACE_SCHED, TRACING, ts(), and XrdSysMutex::UnLock().

Referenced by XrdStartReaper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Run()

void XrdScheduler::Run ( )

Definition at line 332 of file XrdScheduler.cc.

333 {
334  int waiting;
335  XrdJob *jp;
336 
337 // Wait for work then do it (an endless task for a worker thread)
338 //
339  do {do {DispatchMutex.Lock(); idl_Workers++;DispatchMutex.UnLock();
340  WorkAvail.Wait();
341  DispatchMutex.Lock();waiting = --idl_Workers;DispatchMutex.UnLock();
342  SchedMutex.Lock();
343  if ((jp = WorkFirst))
344  {if (!(WorkFirst = jp->NextJob)) WorkLast = 0;
345  if (num_JobsinQ) num_JobsinQ--;
346  else XrdLog->Emsg("Scheduler","Job queue count underflow!");
347  } else {
348  num_JobsinQ = 0;
349  if (num_Layoffs > 0)
350  {num_Layoffs--;
351  if (waiting)
352  {num_TDestroy++; num_Workers--;
353  TRACE(SCHED, "terminating thread; workers=" <<num_Workers);
354  SchedMutex.UnLock();
355  return;
356  }
357  }
358  }
359  SchedMutex.UnLock();
360  } while(!jp);
361 
362  // Check if we should hire a new worker (we always want 1 idle thread)
363  // before running this job.
364  //
365  if (!waiting) hireWorker();
366  if (TRACING(TRACE_SCHED) && *(jp->Comment) != '.')
367  {TRACE(SCHED, "running " <<jp->Comment <<" inq=" <<num_JobsinQ);}
368  jp->DoIt();
369  } while(1);
370 }
virtual void DoIt()=0

References XrdJob::Comment, XrdJob::DoIt(), XrdSysError::Emsg(), XrdSysMutex::Lock(), XrdJob::NextJob, num_TDestroy, TRACE, TRACE_SCHED, TRACING, XrdSysMutex::UnLock(), XrdSysSemaphore::Wait(), and XrdLog.

Referenced by XrdStartWorking().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Schedule() [1/3]

void XrdScheduler::Schedule ( int  num,
XrdJob *  jfirst,
XrdJob *  jlast 
)

Definition at line 407 of file XrdScheduler.cc.

408 {
409 
410 // Lock down our data area
411 //
412  SchedMutex.Lock();
413 
414 // Place the request list on the queue
415 //
416  jlast->NextJob = 0;
417  if (WorkFirst)
418  {WorkLast->NextJob = jfirst;
419  WorkLast = jlast;
420  } else {
421  WorkFirst = jfirst;
422  WorkLast = jlast;
423  }
424 
425 // Calculate statistics
426 //
427  num_Jobs += numjobs;
428  num_JobsinQ += numjobs;
429  if (num_JobsinQ > max_QLength) max_QLength = num_JobsinQ;
430 
431 // Indicate number of jobs to work on
432 //
433  while(numjobs--) WorkAvail.Post();
434 
435 // Unlock the data area and return
436 //
437  SchedMutex.UnLock();
438 }

References XrdSysMutex::Lock(), max_QLength, XrdJob::NextJob, num_Jobs, XrdSysSemaphore::Post(), and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ Schedule() [2/3]

void XrdScheduler::Schedule ( XrdJob *  jp)

Definition at line 376 of file XrdScheduler.cc.

377 {
378 // Lock down our data area
379 //
380  SchedMutex.Lock();
381 
382 // Place the request on the queue and broadcast it
383 //
384  jp->NextJob = 0;
385  if (WorkFirst)
386  {WorkLast->NextJob = jp;
387  WorkLast = jp;
388  } else {
389  WorkFirst = jp;
390  WorkLast = jp;
391  }
392  WorkAvail.Post();
393 
394 // Calculate statistics
395 //
396  num_Jobs++;
397  num_JobsinQ++;
398  if (num_JobsinQ > max_QLength) max_QLength = num_JobsinQ;
399 
400 // Unlock the data area and return
401 //
402  SchedMutex.UnLock();
403 }

References XrdSysMutex::Lock(), max_QLength, XrdJob::NextJob, num_Jobs, XrdSysSemaphore::Post(), and XrdSysMutex::UnLock().

Referenced by XrdCmsDelNode::XrdCmsDelNode(), XrdCmsDrop::XrdCmsDrop(), XrdStatsJob::XrdStatsJob(), XrdXrootdJob::XrdXrootdJob(), XrdXrootdPrepare::XrdXrootdPrepare(), XrdSsiFileReq::Activate(), XrdSsiEvent::AddEvent(), XrdXrootdAioTask::Completed(), XrdCmsConfig::Configure2(), XrdSsiFileReq::DeferredFinalize(), XrdPfc::IO::Detach(), XrdPollE::Disable(), XrdPollPoll::Disable(), XrdCmsNode::do_SelPrep(), XrdObjectQ< T >::DoIt(), DoIt(), XrdStatsJob::DoIt(), XrdCmsBlackList::DoIt(), XrdCms::PingClock::DoIt(), XrdCmsJob::DoIt(), XrdCmsPrepare::DoIt(), XrdXrootdJob::DoIt(), XrdXrootdMonFile::DoIt(), XrdXrootdMonitor_Ident::DoIt(), XrdXrootdMonitor_Tick::DoIt(), XrdXrootdPrepare::DoIt(), XrdNetRefresh::DoIt(), XrdXrootdCallBack::Done(), XrdPosixFileRH::HandleResponse(), XrdXrootdMonFile::Init(), XrdXrootdMonitor::Init(), XrdCmsBlackList::Init(), mainAccept(), mainAdmin(), XrdPfc::ResourceMonitor::perform_purge_check(), XrdPfc::Cache::Prepare(), XrdCmsPrepare::Reset(), XrdSsiUtils::RetErr(), XrdPosixFileRH::Sched(), XrdOfsPrepGPIReal::PrepGRun::Sched(), XrdSsiTaskReal::SchedError(), XrdOssCsiFileAio::SchedReadJob(), XrdOssCsiFileAio::SchedReadJob2(), XrdXrootdJob::Schedule(), XrdXrootdAioFob::Schedule(), XrdOssCsiFileAio::SchedWriteJob(), XrdOssCsiFileAio::SchedWriteJob2(), XrdObjectQ< T >::Set(), setParms(), XrdLinkCtl::Setup(), Start(), XrdNetRefresh::Start(), XrdPollE::Start(), XrdPollPoll::Start(), XrdSendQ::Terminate(), XrdCmsCache::TickTock(), TimeSched(), and XrdSsiSessReal::UnHold().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Schedule() [3/3]

void XrdScheduler::Schedule ( XrdJob *  jp,
time_t  atime 
)

Definition at line 442 of file XrdScheduler.cc.

443 {
444  XrdJob *pp = 0, *p;
445 
446 // Cancel this event, if scheduled
447 //
448  Cancel(jp);
449 
450 // Lock the queue
451 //
452  if (TRACING(TRACE_SCHED) && *(jp->Comment) != '.')
453  {TRACE(SCHED, "scheduling " <<jp->Comment <<" in " <<atime-time(0) <<" seconds");}
454  jp->SchedTime = atime;
455  TimerMutex.Lock();
456 
457 // Find the insertion point for the work element
458 //
459  p = TimerQueue;
460  while(p && p->SchedTime <= atime) {pp = p; p = p->NextJob;}
461 
462 // Insert the job element
463 //
464  jp->NextJob = p;
465  if (pp) pp->NextJob = jp;
466  else {TimerQueue = jp; TimerRings.Signal();}
467 
468 // All done
469 //
470  TimerMutex.UnLock();
471 }
void Cancel(XrdJob *jp)

References Cancel(), XrdJob::Comment, XrdSysMutex::Lock(), XrdJob::NextJob, XrdSysCondVar2::Signal(), TRACE, TRACE_SCHED, TRACING, and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ setNproc()

void XrdScheduler::setNproc ( const bool  limlower)

Definition at line 477 of file XrdScheduler.cc.

478 {
479  // If supported change the NPROC resource limit and set max_Workers.
480  // Caller can select leaving or increasing the limit, or potentially
481  // setting a more restrictive limit than the current one.
482 
483  // If this method is called the setParms method should be called after, so
484  // that a caller supplied value of max_Workers can override the value here.
485 
486  // We attempt to set the limit to our maximum supported threads in the
487  // XrdScheduler (with a margin for pid_max).
488 
489 // Reset the soft limit applied to our process concerning the system wide
490 // number threads for our uid (Linux only).
491 //
492 #if ( defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__)) ) && defined(RLIMIT_NPROC)
493 
494  struct rlimit rlim;
495 
496 // First determine the absolute maximum we can have
497 //
498  rlim_t theMax = MAX_SCHED_PROCS;
499  int pdFD, rdsz;
500  if ((pdFD = open("/proc/sys/kernel/pid_max", O_RDONLY)) >= 0)
501  {char pmBuff[32];
502  if ((rdsz = read(pdFD, pmBuff, sizeof(pmBuff))) > 0)
503  {rdsz = atoi(pmBuff);
504  if (rdsz < 16384) theMax = 16384; // This is unlikely
505  else if (rdsz < MAX_SCHED_PROCS)
506  theMax = static_cast<rlim_t>(rdsz-2000);
507  }
508  close(pdFD);
509  }
510 
511 // We allow disabling the NPROC setting entirely.
512 //
513  const bool setnp = (getenv("XRDLEAVENPROC") == 0);
514 
515 // Get the resource thread limit and set to maximum. In Linux this may be -1
516 // to indicate useless infnity, so we have to come up with a number, sigh.
517 //
518  if (setnp && !getrlimit(RLIMIT_NPROC, &rlim))
519  {if (rlim.rlim_max == RLIM_INFINITY || rlim.rlim_max > theMax)
520  {if (limlower || (rlim.rlim_cur != RLIM_INFINITY && rlim.rlim_cur < theMax))
521  {rlim.rlim_cur = theMax;
522  setrlimit(RLIMIT_NPROC, &rlim);
523  }
524  } else {
525  if (rlim.rlim_cur != rlim.rlim_max)
526  {rlim.rlim_cur = rlim.rlim_max;
527  setrlimit(RLIMIT_NPROC, &rlim);
528  }
529  }
530  }
531 
532 // Readjust our internal maximum to be the actual maximum
533 //
534  if (!getrlimit(RLIMIT_NPROC, &rlim))
535  {if (rlim.rlim_cur == RLIM_INFINITY || rlim.rlim_cur > theMax)
536  max_Workers = static_cast<int>(theMax);
537  else max_Workers = static_cast<int>(rlim.rlim_cur);
538  }
539 
540 // The above may allow way too many threads. We make sure that the default
541 // maximum threads is adhered to.
542 //
543  if (max_Workers > DFL_SCHED_PROCS) max_Workers = DFL_SCHED_PROCS;
544 #endif
545 }
ssize_t read(int fildes, void *buf, size_t nbyte)
#define close(a)
Definition: XrdPosix.hh:48
#define open
Definition: XrdPosix.hh:76
#define DFL_SCHED_PROCS
Definition: XrdScheduler.hh:44
#define MAX_SCHED_PROCS
Definition: XrdScheduler.hh:43

References close, DFL_SCHED_PROCS, MAX_SCHED_PROCS, open, and read().

Referenced by XrdConfig::XrdConfig().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setParms()

void XrdScheduler::setParms ( int  minw,
int  maxw,
int  avlt,
int  maxi,
int  once = 0 
)

Definition at line 551 of file XrdScheduler.cc.

552 {
553  static int isSet = 0;
554 
555 // Lock the data area and check for 1-time set
556 //
557  SchedMutex.Lock();
558  if (once && isSet) {SchedMutex.UnLock(); return;}
559  isSet = 1;
560 
561 // get a consistent view of all the values
562 //
563  if (maxw <= 0) maxw = max_Workers;
564  if (minw < 0) minw = min_Workers;
565  if (minw > maxw) minw = maxw;
566  if (avlw < 0) avlw = maxw/4*3;
567  else if (avlw > maxw) avlw = maxw;
568 
569 // Set the values
570 //
571  min_Workers = minw;
572  max_Workers = maxw;
573  stk_Workers = maxw - avlw;
574  if (maxi >=0) max_Workidl = maxi;
575 
576 // Unlock the data area
577 //
578  SchedMutex.UnLock();
579 
580 // If we have an idle interval, schedule the idle check
581 //
582  if (maxi > 0)
583  {Cancel((XrdJob *)this);
584  Schedule((XrdJob *)this, (time_t)maxi+time(0));
585  }
586 
587 // Debug the info
588 //
589  TRACE(SCHED,"Set min_Workers=" <<min_Workers <<" max_Workers=" <<max_Workers);
590  TRACE(SCHED,"Set stk_Workers=" <<stk_Workers <<" max_Workidl=" <<max_Workidl);
591 }

References Cancel(), XrdSysMutex::Lock(), Schedule(), TRACE, and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ Start()

void XrdScheduler::Start ( )

Definition at line 597 of file XrdScheduler.cc.

598 {
599  int retc, numw;
600  pthread_t tid;
601 
602 // Provide ABI compatibility for XrdOucTrace which is deprecated!
603 //
604  if (getenv("XRDDEBUG") != 0) XrdTrace->What = TRACE_SCHED;
605  else if (XrdTraceOld) XrdTrace->What |= XrdTraceOld->What;
606 
607 // Start a time based scheduler
608 //
609  if ((retc = XrdSysThread::Run(&tid, XrdStartTSched, (void *)this,
610  XRDSYSTHREAD_BIND, "Time scheduler")))
611  XrdLog->Emsg("Scheduler", retc, "create time scheduler thread");
612 
613 // If we an idle interval, schedule the idle check
614 //
615  if (max_Workidl > 0) Schedule((XrdJob *)this, (time_t)max_Workidl+time(0));
616 
617 // Start 1/3 of the minimum number of threads
618 //
619  if (!(numw = min_Workers/3)) numw = 2;
620  while(numw--) hireWorker(0);
621 
622 // Unlock the data area
623 //
624  TRACE(SCHED, "Starting with " <<num_Workers <<" workers" );
625 }
void * XrdStartTSched(void *carg)
Definition: XrdScheduler.cc:81
#define XRDSYSTHREAD_BIND

References XrdSysError::Emsg(), XrdSysThread::Run(), Schedule(), TRACE, TRACE_SCHED, XrdOucTrace::What, XrdSysTrace::What, XrdLog, XrdStartTSched(), XRDSYSTHREAD_BIND, and XrdGlobal::XrdTrace.

Referenced by XrdOssCsi::Init(), and XrdOucGetCache().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Stats()

int XrdScheduler::Stats ( char *  buff,
int  blen,
int  do_sync = 0 
)

Definition at line 631 of file XrdScheduler.cc.

632 {
633  int cnt_Jobs, cnt_JobsinQ, xam_QLength, cnt_Workers, cnt_idl;
634  int cnt_TCreate, cnt_TDestroy, cnt_Limited;
635  static const char statfmt[] = "<stats id=\"sched\"><jobs>%d</jobs>"
636  "<inq>%d</inq><maxinq>%d</maxinq>"
637  "<threads>%d</threads><idle>%d</idle>"
638  "<tcr>%d</tcr><tde>%d</tde>"
639  "<tlimr>%d</tlimr></stats>";
640 
641 // If only length wanted, do so
642 //
643  if (!buff) return sizeof(statfmt) + 16*8;
644 
645 // Get values protected by the Dispatch lock (avoid lock if no sync needed)
646 //
647  if (do_sync) DispatchMutex.Lock();
648  cnt_idl = idl_Workers;
649  if (do_sync) DispatchMutex.UnLock();
650 
651 // Get values protected by the Scheduler lock (avoid lock if no sync needed)
652 //
653  if (do_sync) SchedMutex.Lock();
654  cnt_Workers = num_Workers;
655  cnt_Jobs = num_Jobs;
656  cnt_JobsinQ = num_JobsinQ;
657  xam_QLength = max_QLength;
658  cnt_TCreate = num_TCreate;
659  cnt_TDestroy= num_TDestroy;
660  cnt_Limited = num_Limited;
661  if (do_sync) SchedMutex.UnLock();
662 
663 // Format the stats and return them
664 //
665  return snprintf(buff, blen, statfmt, cnt_Jobs, cnt_JobsinQ, xam_QLength,
666  cnt_Workers, cnt_idl, cnt_TCreate, cnt_TDestroy,
667  cnt_Limited);
668 }

References XrdSysMutex::Lock(), max_QLength, num_Jobs, num_Limited, num_TCreate, num_TDestroy, and XrdSysMutex::UnLock().

Referenced by XrdConfig::XrdConfig().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TimeSched()

void XrdScheduler::TimeSched ( )

Definition at line 674 of file XrdScheduler.cc.

675 {
676  XrdJob *jp;
677  int wtime;
678 
679 // Continuous loop until we find some work here
680 //
681  do {TimerMutex.Lock();
682  if (TimerQueue) wtime = TimerQueue->SchedTime-time(0);
683  else wtime = 60*60;
684  if (wtime > 0)
685  {TimerRings.Wait(wtime);
686  TimerMutex.UnLock();
687  } else {
688  jp = TimerQueue;
689  TimerQueue = jp->NextJob;
690  Schedule(jp);
691  TimerMutex.UnLock();
692  }
693  } while(1);
694 }

References XrdSysMutex::Lock(), XrdJob::NextJob, Schedule(), XrdSysMutex::UnLock(), and XrdSysCondVar2::Wait().

Referenced by XrdStartTSched().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ max_QLength

int XrdScheduler::max_QLength

Definition at line 84 of file XrdScheduler.hh.

Referenced by Schedule(), and Stats().

◆ num_Jobs

int XrdScheduler::num_Jobs

Definition at line 83 of file XrdScheduler.hh.

Referenced by Schedule(), and Stats().

◆ num_Limited

int XrdScheduler::num_Limited

Definition at line 85 of file XrdScheduler.hh.

Referenced by Stats().

◆ num_TCreate

int XrdScheduler::num_TCreate

Definition at line 81 of file XrdScheduler.hh.

Referenced by Stats().

◆ num_TDestroy

int XrdScheduler::num_TDestroy

Definition at line 82 of file XrdScheduler.hh.

Referenced by Run(), and Stats().


The documentation for this class was generated from the following files: