pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1248:   }      /* #define PROFILE_CHECK_THREADS */      #if defined(HAVE_RDTSC) && defined(USE_CLOCK_FOR_SLICES)   static int use_tsc_for_slices;   #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; + #endif +    #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. */   
pike.git/src/threads.c:1278: Inside #if undefined(HAVE_NO_YIELD) and #if defined(HAVE_RDTSC) && defined(USE_CLOCK_FOR_SLICES)
   number of cycles passed comes close to what it was the last    time when we decided to yield. */      #define GETCYCLES(v) do { \    unsigned __l, __h; \    __asm__ __volatile__ ("rdtsc" : "=a" (__l), "=d" (__h)); \    (v)= __l | (((INT64)__h)<<32); \   } while (0)       if (use_tsc_for_slices) { -  static INT64 target, mincycles=1000*1000; +  static INT64 target;    INT64 now;    clock_t elapsed;       if (!target) {    GETCYCLES(target);    }       GETCYCLES(now);       if ((target-now)>0) { -  if ((target-now)>mincycles) +  if ((target-now)>tsc_mincycles)    use_tsc_for_slices = 0; /* The counter jumped back too far; TSC unusable */    else    return;    }       elapsed = clock() - thread_start_clock;       if (elapsed < (clock_t) (CLOCKS_PER_SEC/30)) { -  mincycles |= 0xffff; -  if ((now-target)<=(mincycles<<4)) -  mincycles += (mincycles>>1); -  target = now + (mincycles>>1); +  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)) { -  mincycles -= mincycles>>2; +  tsc_mincycles -= tsc_mincycles>>2;    if (elapsed > (clock_t) (CLOCKS_PER_SEC/10)) -  mincycles >>= 2; +  tsc_mincycles >>= 2;    } -  target = now + mincycles; +  target = now + tsc_mincycles;    goto do_yield;    }   #endif /* HAVE_RDTSC && USE_CLOCK_FOR_SLICES */      #ifdef HAVE_GETHRTIME    {    static hrtime_t last_ = 0;    hrtime_t now = gethrtime();    if( now-last_ < 50000000 ) /* 0.05s slice */    return;
pike.git/src/threads.c:1397:   #endif       do_yield:;      #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); +  fprintf (stderr, "check_threads calls in %ld sec(s): %lu " +  "(tsc mincycles: %"PRINTINT64"d)\n", +  (long) (now.tv_sec - last_time), calls, + #if defined(HAVE_RDTSC) && defined(USE_CLOCK_FOR_SLICES) +  use_tsc_for_slices ? tsc_mincycles : -1 + #else +  -2 + #endif +  );    last_time = (unsigned long) now.tv_sec;    calls = 0;    }    }   #endif       pike_thread_yield();   }      PMOD_EXPORT void pike_thread_yield(void)