IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 11, 2007, 10:56:27 AM (19 years ago)
Author:
eugene
Message:

adding intelligent timeouts to task and job threads; removing deprecated files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pantasks/CheckTasks.c

    r12332 r12404  
    11# include "pantasks.h"
    22
    3 int CheckTasks () {
     3float CheckTasks () {
    44
    55  Job *job;
    66  Task *task;
    77  int status;
     8  float time_running, next_timeout;
    89  // struct timeval now;
     10
     11  // actual maximum delay is controlled in job_threads.c
     12  next_timeout = 1.0;
    913
    1014  /** test all tasks: ready to test? ready to run? **/
    1115  while ((task = NextTask ()) != NULL) {
    1216
    13     if (!task[0].active) continue;
     17    /*** test for all reasons we should skip this task ***/
    1418
    15     /* ready to test? : check exec period */
    16     if (GetTaskTimer(task[0].last, FALSE) < task[0].exec_period) continue;
    17 
    18     /* need to check if the current time is within valid/invalid periods */
     19    /* task has been de-activated by the user */
     20    if (!task[0].active) {
     21      continue;
     22    }
     23    /* current time is not within valid/invalid periods */
    1924    if (!CheckTimeRanges (task[0].ranges, task[0].Nranges)) {
    20         gettimeofday (&task[0].last, (void *) NULL);
    21         continue;
     25      continue;
    2226    }
     27    /* all allowed tasks have been run in this period */
    2328    if (task[0].Nmax && (task[0].Njobs >= task[0].Nmax)) {
    24         gettimeofday (&task[0].last, (void *) NULL);
    25         continue;
     29      continue;
    2630    }
     31    /* too many outstanding jobs */
    2732    if (task[0].NpendingMax && (task[0].Npending >= task[0].NpendingMax)) {
    28         // fprintf (stderr, "npending: %d, max npending: %d\n", task[0].Npending, task[0].NpendingMax);
    29         gettimeofday (&task[0].last, (void *) NULL);
    30         continue;
     33      continue;
    3134    }
    3235
    33     // gettimeofday (&now, (void *) NULL);
    34     // fprintf (stderr, "t0: %d %6d  - \n", now.tv_sec, now.tv_usec);
     36    /* ready to test? : check time since last exec */
     37    time_running = GetTaskTimer(task[0].last, FALSE);
     38    if (time_running < task[0].exec_period) {
     39      // is we are to ready to run, set time to timeout, if shortest of all tasks
     40      next_timeout = MIN (next_timeout, task[0].exec_period - time_running);
     41      continue;
     42    }
     43
     44    /* ready to try running the task : reset the timer */
     45    next_timeout = 0.0;
     46    gettimeofday (&task[0].last, (void *) NULL);
     47    // XXX here is where I should add a fuzz factor (fraction of exec_period)
    3548
    3649    /* ready to run? : run task.exec macro */
     
    3851      status = exec_loop (task[0].exec);
    3952      if (!status) {
    40           gettimeofday (&task[0].last, (void *) NULL);
    41           continue;
     53        continue;
    4254      }
    4355    }
     
    4860    /* check if there are errors with this task */
    4961    if (!ValidateTask (task, TRUE)) {
    50         gettimeofday (&task[0].last, (void *) NULL);
    51         continue;
     62      continue;
    5263    }
    5364   
     
    6778    // task[0].last.tv_sec, task[0].last.tv_usec);
    6879
    69     /* reset timer on task (don't do this if Create/Submit fails) (why not??) */
    70     gettimeofday (&task[0].last, (void *) NULL);
     80    /* increment job counters */
    7181    task[0].Njobs ++;
    7282    task[0].Npending ++;
     
    7787    /* increment Nrun for inclusive ranges with Nmax */
    7888    BumpTimeRanges (task[0].ranges, task[0].Nranges);
    79 
    80     if (TestElapsedCheck()) return (TRUE);
    8189  }
    82   return (TRUE);
     90  return (next_timeout);
    8391}
Note: See TracChangeset for help on using the changeset viewer.