Changeset 160 for trunk/src/gmake/job.c


Ignore:
Timestamp:
Sep 8, 2004, 5:15:50 AM (21 years ago)
Author:
bird
Message:

merged with beta1.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmake/job.c

    r58 r160  
    230230
    231231int unixy_shell = 1;
     232
     233/* Number of jobs started in the current second.  */
     234
     235unsigned long job_counter = 0;
    232236
    233237
     
    370374
    371375
    372 /*
    373    found apostrophe at (p-1)
    374 
    375    inc p until after closing apostrophe.  */
     376/* found apostrophe at (p-1)
     377   inc p until after closing apostrophe.
     378 */
    376379
    377380static char *
    378 handle_apos (char *p)
     381vms_handle_apos (char *p)
    379382{
    380383  int alast;
    381   int inside;
    382384
    383385#define SEPCHARS ",/()= "
    384386
    385   inside = 0;
     387  alast = 0;
    386388
    387389  while (*p != 0)
     
    389391      if (*p == '"')
    390392        {
    391           if (inside)
    392             {
    393               while ((alast > 0)
    394                     && (*p == '"'))
    395                 {
    396                   p++;
    397                   alast--;
    398                 }
    399               if (alast == 0)
    400                 inside = 0;
    401               else
    402                 {
    403                   fprintf (stderr, _("Syntax error, still inside '\"'\n"));
    404                   exit (3);
    405                 }
     393          if (alast)
     394            {
     395              alast = 0;
     396              p++;
    406397            }
    407398          else
     
    410401              if (strchr (SEPCHARS, *p))
    411402                break;
    412               inside = 1;
    413403              alast = 1;
    414               while (*p == '"')
    415                 {
    416                   alast++;
    417                   p++;
    418                 }
    419404            }
    420405        }
     
    442427
    443428RETSIGTYPE
    444 child_handler (int sig)
     429child_handler (int sig UNUSED)
    445430{
    446431  ++dead_children;
     
    453438
    454439#ifdef __EMX__
    455   signal(SIGCHLD, SIG_DFL); /* The signal handler must called only once! ????*/
    456 #endif
    457 
     440  /* The signal handler must called only once! */
     441  signal (SIGCHLD, SIG_DFL);
     442#endif
     443
     444  /* This causes problems if the SIGCHLD interrupts a printf().
    458445  DB (DB_JOBS, (_("Got a SIGCHLD; %u unreaped children.\n"), dead_children));
     446  */
    459447}
    460448
     
    605593              coredump = WCOREDUMP (status);
    606594
    607 #if 0 /*def __EMX__*/
    608               /* the SIGCHLD handler must not be used on OS/2 because, unlike
    609                  on UNIX systems, it had to call wait() itself.  Therefore
    610                  job_rfd has to be closed here.  */
    611               if (job_rfd >= 0)
    612                 {
    613                   close (job_rfd);
    614                   job_rfd = -1;
    615                 }
    616 #endif
    617 
     595              /* If we have started jobs in this second, remove one.  */
     596              if (job_counter)
     597                --job_counter;
    618598            }
    619599          else
     
    13781358#endif  /* __MSDOS__ or Amiga or WINDOWS32 */
    13791359
     1360  /* Bump the number of jobs started in this second.  */
     1361  ++job_counter;
     1362
    13801363  /* We are the parent side.  Set the state to
    13811364     say the commands are running and return.  */
     
    16671650        saved_errno = errno;
    16681651#ifdef __EMX__
    1669         signal(SIGCHLD, SIG_DFL); /* The child handler must be turned off here. */
     1652        /* The child handler must be turned off here.  */
     1653        signal (SIGCHLD, SIG_DFL);
    16701654#endif
    16711655        set_child_handler_action_flags (SA_RESTART);
     
    17251709}
    17261710
     1711/* Determine if the load average on the system is too high to start a new job.
     1712   The real system load average is only recomputed once a second.  However, a
     1713   very parallel make can easily start tens or even hundreds of jobs in a
     1714   second, which brings the system to its knees for a while until that first
     1715   batch of jobs clears out.
     1716
     1717   To avoid this we use a weighted algorithm to try to account for jobs which
     1718   have been started since the last second, and guess what the load average
     1719   would be now if it were computed.
     1720
     1721   This algorithm was provided by Thomas Riedl <thomas.riedl@siemens.com>,
     1722   who writes:
     1723
     1724!      calculate something load-oid and add to the observed sys.load,
     1725!      so that latter can catch up:
     1726!      - every job started increases jobctr;
     1727!      - every dying job decreases a positive jobctr;
     1728!      - the jobctr value gets zeroed every change of seconds,
     1729!        after its value*weight_b is stored into the 'backlog' value last_sec
     1730!      - weight_a times the sum of jobctr and last_sec gets
     1731!        added to the observed sys.load.
     1732!
     1733!      The two weights have been tried out on 24 and 48 proc. Sun Solaris-9
     1734!      machines, using a several-thousand-jobs-mix of cpp, cc, cxx and smallish
     1735!      sub-shelled commands (rm, echo, sed...) for tests.
     1736!      lowering the 'direct influence' factor weight_a (e.g. to 0.1)
     1737!      resulted in significant excession of the load limit, raising it
     1738!      (e.g. to 0.5) took bad to small, fast-executing jobs and didn't
     1739!      reach the limit in most test cases.
     1740!
     1741!      lowering the 'history influence' weight_b (e.g. to 0.1) resulted in
     1742!      exceeding the limit for longer-running stuff (compile jobs in
     1743!      the .5 to 1.5 sec. range),raising it (e.g. to 0.5) overrepresented
     1744!      small jobs' effects.
     1745
     1746 */
     1747
     1748#define LOAD_WEIGHT_A           0.25
     1749#define LOAD_WEIGHT_B           0.25
     1750
    17271751static int
    17281752load_too_high (void)
     
    17311755  return 1;
    17321756#else
    1733   double load;
     1757  static double last_sec;
     1758  static time_t last_now;
     1759  double load, guess;
     1760  time_t now;
    17341761
    17351762  if (max_load_average < 0)
    17361763    return 0;
    17371764
     1765  /* Find the real system load average.  */
    17381766  make_access ();
    17391767  if (getloadavg (&load, 1) != 1)
     
    17551783  user_access ();
    17561784
    1757   DB (DB_JOBS, ("Current system load = %f (max requested = %f)\n",
    1758                 load, max_load_average));
    1759   return load >= max_load_average;
     1785  /* If we're in a new second zero the counter and correct the backlog
     1786     value.  Only keep the backlog for one extra second; after that it's 0.  */
     1787  now = time (NULL);
     1788  if (last_now < now)
     1789    {
     1790      if (last_now == now - 1)
     1791        last_sec = LOAD_WEIGHT_B * job_counter;
     1792      else
     1793        last_sec = 0.0;
     1794
     1795      job_counter = 0;
     1796      last_now = now;
     1797    }
     1798
     1799  /* Try to guess what the load would be right now.  */
     1800  guess = load + (LOAD_WEIGHT_A * (job_counter + last_sec));
     1801
     1802  DB (DB_JOBS, ("Estimated system load = %f (actual = %f) (max requested = %f)\n",
     1803                guess, load, max_load_average));
     1804
     1805  return guess >= max_load_average;
    17601806#endif
    17611807}
     
    21932239                 comma or space and before slash. */
    21942240            case '"':
    2195               q = handle_apos (q + 1);
     2241              q = vms_handle_apos (q);
    21962242              sep = q;
    21972243              break;
     
    28682914  char** sh_cmds;
    28692915#else  /* must be UNIX-ish */
    2870   static char sh_chars[] = "#;\"*?[]&|<>(){}$`^~";
    2871   static char *sh_cmds[] = { "cd", "eval", "exec", "exit", "login",
    2872                              "logout", "set", "umask", "wait", "while", "for",
    2873                              "case", "if", ":", ".", "break", "continue",
    2874                              "export", "read", "readonly", "shift", "times",
    2875                              "trap", "switch", 0 };
    2876 #endif /* __MSDOS__ */
     2916  static char sh_chars[] = "#;\"*?[]&|<>(){}$`^~!";
     2917  static char *sh_cmds[] = { ".", ":", "break", "case", "cd", "continue",
     2918                             "eval", "exec", "exit", "export", "for", "if",
     2919                             "login", "logout", "read", "readonly", "set",
     2920                             "shift", "switch", "test", "times", "trap",
     2921                             "umask", "wait", "while", 0 };
     2922#endif
    28772923  register int i;
    28782924  register char *p;
Note: See TracChangeset for help on using the changeset viewer.