Branch: Tag:

2008-11-18

2008-11-18 19:10:30 by Martin Stjernholm <mast@lysator.liu.se>

Don't use a divisor in check_threads in combination with the
time-based skipping of yields; instead assume check_threads is called
with a "lagom" interval. Added some simple profiling code.

Rev: src/threads.c:1.267

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: threads.c,v 1.266 2008/09/09 16:53:13 mast Exp $ + || $Id: threads.c,v 1.267 2008/11/18 19:10:30 mast Exp $   */      #include "global.h"
778:    return num_pike_threads;   }    + /* #define PROFILE_CHECK_THREADS */ +    static void check_threads(struct callback *cb, void *arg, void * arg2)   { -  + #ifdef PROFILE_CHECK_THREADS +  static unsigned long calls = 0; +  calls++; + #endif +    #ifndef HAVE_NO_YIELD    /* If we have no yield we can't cut calls here since it's possible    * that a thread switch will take place only occasionally in the    * window below. */ -  static int div_; -  if(div_++ & 255) -  return; +    #ifdef HAVE_GETHRTIME    {    static hrtime_t last_ = 0;
818:   #elif defined (USE_CLOCK_FOR_SLICES)    if (clock() - thread_start_clock < (clock_t) (CLOCKS_PER_SEC / 20))    return; + #else +  static int div_; +  if(div_++ & 255) +  return;   #endif   #endif    -  + #ifdef PROFILE_CHECK_THREADS +  { +  static long last_time; +  struct timeval now; +  gettimeofday (&now, NULL); +  if (now.tv_sec > last_time) { +  fprintf (stderr, "check_threads calls in %ld sec(s): %lu\n", +  (long) (now.tv_sec - last_time), calls); +  last_time = (unsigned long) now.tv_sec; +  calls = 0; +  } +  } + #endif +     DEBUG_CHECK_THREAD();       THREADS_ALLOW();