pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1243:      PMOD_EXPORT int count_pike_threads(void)   {    return num_pike_threads;   }      /* #define PROFILE_CHECK_THREADS */      #if defined(HAVE_RDTSC) && defined(USE_CLOCK_FOR_SLICES)   static int use_tsc_for_slices; + #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=1000*1000; +  static INT64 tsc_mincycles = TSC_START_INTERVAL;   #endif      #ifdef PROFILE_CHECK_THREADS    static unsigned long calls = 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",
pike.git/src/threads.c:1283:   } while (0)       if (use_tsc_for_slices) {    static INT64 target;    INT64 now;    clock_t elapsed;       GETCYCLES(now);       if ((target-now)>0) { -  if ((target-now)>tsc_mincycles) -  use_tsc_for_slices = 0; /* The counter jumped back too far; TSC unusable */ +  if ((target-now)>tsc_mincycles) { +  /* The counter jumped back in time (since target == +  * previous_now + tsc_mincycles), so reset and continue. In the +  * worst case this keeps happening all the time, and then the +  * only effect is that we always fall back to clock(3). */ + #ifdef 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;    }       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);