pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:33:   #include "module_support.h"   #include "pike_types.h"   #include "operators.h"   #include "bignum.h"   #include "signal_handler.h"   #include "backend.h"   #include "pike_rusage.h"   #include "pike_cpulib.h"      #include <errno.h> + #include <math.h>      #ifdef HAVE_SYS_PRCTL_H   #include <sys/prctl.h>   #endif /* HAVE_SYS_PRCTL_H */      #ifdef HAVE_SYS_TIME_H   #include <sys/time.h>   #endif   #ifdef HAVE_TIME_H   #include <time.h>
pike.git/src/threads.c:1253:   #define TSC_START_INTERVAL (1000 * 1000)   #endif      static void check_threads(struct callback *cb, void *arg, void * arg2)   {   #if defined(HAVE_RDTSC) && defined(USE_CLOCK_FOR_SLICES)    static INT64 tsc_mincycles = TSC_START_INTERVAL;   #endif      #ifdef PROFILE_CHECK_THREADS -  static unsigned long calls = 0; +  static INT64 prev_now; +  static unsigned long calls = 0, clock_checks = 0; +  static unsigned long slice_int_n = 0; +  static double slice_int_mean = 0.0, slice_int_m2 = 0.0; +  static unsigned long tsc_int_n = 0; +  static double tsc_int_mean = 0.0, tsc_int_m2 = 0.0;    calls++;   #endif      #if defined (USE_CLOCK_FOR_SLICES) && defined (PIKE_DEBUG)    if (last_clocked_thread != th_self())    Pike_fatal ("Stale thread %08lx in last_clocked_thread (self is %08lx)\n",    (unsigned long) last_clocked_thread, (unsigned long) th_self());   #endif      #if defined(HAVE_RDTSC) && defined(USE_CLOCK_FOR_SLICES)
pike.git/src/threads.c:1300: Inside #if defined(PROFILE_CHECK_THREADS)
   fprintf (stderr, "TSC jump detected (now: %"PRINTINT64"d, "    "target: %"PRINTINT64"d, tsc_mincycles: %"PRINTINT64"d) - "    "resetting\n", now, target, tsc_mincycles);   #endif    tsc_mincycles = TSC_START_INTERVAL;    }    else    return;    }    + #ifdef PROFILE_CHECK_THREADS +  if (prev_now) { +  INT64 tsc_interval = now - prev_now; +  double delta = tsc_interval - tsc_int_mean; +  tsc_int_n++; +  tsc_int_mean += delta / tsc_int_n; +  tsc_int_m2 += delta * (tsc_interval - tsc_int_mean); +  } +  prev_now = now; +  clock_checks++; + #endif +     elapsed = clock() - thread_start_clock;       if (elapsed < (clock_t) (CLOCKS_PER_SEC/30)) {    tsc_mincycles |= 0xffff;    if ((now-target)<=(tsc_mincycles<<4))    tsc_mincycles += (tsc_mincycles>>1);    target = now + (tsc_mincycles>>1);    return;    }    if (elapsed > (clock_t) (CLOCKS_PER_SEC/18)) {
pike.git/src/threads.c:1399:    if(div_++ & 255)    return;   #endif       do_yield:;      #ifdef PROFILE_CHECK_THREADS    {    static long last_time;    struct timeval now; +  + #ifdef USE_CLOCK_FOR_SLICES +  if (thread_start_clock) { +  double slice_time = +  (double) (clock() - thread_start_clock) / CLOCKS_PER_SEC; +  double delta = slice_time - slice_int_mean; +  slice_int_n++; +  slice_int_mean += delta / slice_int_n; +  slice_int_m2 += delta * (slice_time - slice_int_mean); +  } + #endif +     gettimeofday (&now, NULL);    if (now.tv_sec > last_time) { -  fprintf (stderr, "check_threads calls in %ld sec(s): %lu " -  "(tsc mincycles: %"PRINTINT64"d)\n", -  (long) (now.tv_sec - last_time), calls, +  fprintf (stderr, "check_threads: %lu calls, %lu clocks, " +  "slice [avg %.3f, d %.1e], " +  "tsc [mincyc %"PRINTINT64"d, avg %.2e, d %.1e]\n", +  calls, clock_checks, +  slice_int_mean, +  slice_int_n > 1 ? sqrt (slice_int_m2 / (slice_int_n - 1)) : 0.0,   #if defined(HAVE_RDTSC) && defined(USE_CLOCK_FOR_SLICES) -  use_tsc_for_slices ? tsc_mincycles : -1 +  (INT64) (use_tsc_for_slices ? tsc_mincycles : -1),   #else -  -2 +  (INT64) -2,   #endif -  ); +  tsc_int_mean, +  tsc_int_n > 1 ? sqrt (tsc_int_m2 / (tsc_int_n - 1)) : 0.0);    last_time = (unsigned long) now.tv_sec; -  calls = 0; +  calls = clock_checks = 0;    } -  +  +  /* Cannot use this with the first tsc reading after the yield. */ +  prev_now = 0;    }   #endif       pike_thread_yield();   }      PMOD_EXPORT void pike_thread_yield(void)   {    DEBUG_CHECK_THREAD();