pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:337: Inside #if defined(POSIX_THREADS)
  #endif    pthread_attr_setdetachstate(&small_pattr, PTHREAD_CREATE_DETACHED);   #endif   }      static void cleanup_thread_state (struct thread_state *th);      #ifndef CONFIGURE_TEST      #if defined(HAVE_CLOCK) && \ -  (defined (HAVE_RDTSC) || \ +  (defined (RDTSC) || \    (!defined(HAVE_GETHRTIME) && \    !(defined(HAVE_MACH_TASK_INFO_H) && defined(TASK_THREAD_TIMES_INFO))))   static clock_t thread_start_clock = 0;   static THREAD_T last_clocked_thread = 0;   #define USE_CLOCK_FOR_SLICES   #endif      #define THIS_THREAD ((struct thread_state *)CURRENT_STORAGE)      static struct callback *threads_evaluator_callback=0;
pike.git/src/threads.c:1242:   }   #endif      PMOD_EXPORT int count_pike_threads(void)   {    return num_pike_threads;   }      /* #define PROFILE_CHECK_THREADS */    - #if defined(HAVE_RDTSC) && defined(USE_CLOCK_FOR_SLICES) + #if defined(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) + #if defined(RDTSC) && defined(USE_CLOCK_FOR_SLICES)    static INT64 tsc_mincycles = TSC_START_INTERVAL;   #endif      #ifdef PROFILE_CHECK_THREADS    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) + #if defined(RDTSC) && defined(USE_CLOCK_FOR_SLICES)    /* We can get here as often as 30+ thousand times per second;    let's try to avoid doing as many clock(3)/times(2) syscalls    by using the TSC. We'll skip any further checks until the    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;    INT64 now;    clock_t elapsed;    -  GETCYCLES(now); +  RDTSC(now);       if ((target-now)>0) {    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) - "
pike.git/src/threads.c:1335:    return;    }    if (elapsed > (clock_t) (CLOCKS_PER_SEC/18)) {    tsc_mincycles -= tsc_mincycles>>2;    if (elapsed > (clock_t) (CLOCKS_PER_SEC/10))    tsc_mincycles >>= 2;    }    target = now + tsc_mincycles;    goto do_yield;    } - #endif /* HAVE_RDTSC && USE_CLOCK_FOR_SLICES */ + #endif /* 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;    last_ = now;    }   #elif defined(HAVE_MACH_TASK_INFO_H) && defined(TASK_THREAD_TIMES_INFO)
pike.git/src/threads.c:1437: Inside #if defined(PROFILE_CHECK_THREADS)
  #endif       gettimeofday (&now, NULL);    if (now.tv_sec > last_time) {    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) + #if defined(RDTSC) && defined(USE_CLOCK_FOR_SLICES)    (INT64) (use_tsc_for_slices ? tsc_mincycles : -1),   #else    (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 = clock_checks = 0;    }   
pike.git/src/threads.c:2987:    mt_init( & interpreter_lock);    mt_init( & interpreter_lock_wanted);    low_mt_lock_interpreter();    mt_init( & thread_table_lock);    mt_init( & interleave_lock);    mt_init( & rosie);    co_init( & live_threads_change);    co_init( & threads_disabled_change);    thread_table_init();    - #if defined(HAVE_RDTSC) && defined(USE_CLOCK_FOR_SLICES) + #if defined(RDTSC) && defined(USE_CLOCK_FOR_SLICES)    {    INT32 cpuid[4];    x86_get_cpuid (1, cpuid);    /* fprintf (stderr, "cpuid 1: %x\n", cpuid[2]); */    use_tsc_for_slices = cpuid[2] & 0x10; /* TSC exists */    if (use_tsc_for_slices) {    x86_get_cpuid (0x80000007, cpuid);    /* fprintf (stderr, "cpuid 0x80000007: %x\n", cpuid[2]); */    use_tsc_for_slices = cpuid[2] & 0x100; /* TSC is invariant */    }