pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:335: Inside #if defined(POSIX_THREADS)
   pthread_attr_setstacksize(&small_pattr, 4096*sizeof(char *));   #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_GETHRTIME) && \ -  !(defined(HAVE_MACH_TASK_INFO_H) && defined(TASK_THREAD_TIMES_INFO)) && \ -  defined(HAVE_CLOCK) && \ -  !defined(HAVE_NO_YIELD) + #if defined(HAVE_CLOCK) && \ +  !defined(HAVE_NO_YIELD) && \ +  (defined (HAVE_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;      PMOD_EXPORT int num_threads = 1;
pike.git/src/threads.c:1257: Inside #if defined(PROFILE_CHECK_THREADS)
  #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. */    -  /* Could consider using get_cpu_time here to get more accurate -  * measurements on more platforms. But otoh we don't really need -  * very high accuracy - the fallback to clock(3) should be good -  * enough in most cases. So let's avoid as much overhead as -  * possible. */ + #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)    /* 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, mincycles=1000*1000;    INT64 now;    clock_t elapsed;    -  if (use_tsc_for_slices) { +     if (!target) {    GETCYCLES(target);    }       GETCYCLES(now);       if ((target-now)>0) {    if ((target-now)>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);    return;    }    if (elapsed > (clock_t) (CLOCKS_PER_SEC/18)) {    mincycles -= mincycles>>2;    if (elapsed > (clock_t) (CLOCKS_PER_SEC/10))    mincycles >>= 2;    }    target = now + mincycles; -  +  goto do_yield;    } - #elif defined(HAVE_GETHRTIME) + #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;    last_ = now;    }   #elif defined(HAVE_MACH_TASK_INFO_H) && defined(TASK_THREAD_TIMES_INFO)    {    static struct timeval last_check = { 0, 0 };
pike.git/src/threads.c:1378:    sys.tv_usec = info.system_time.microseconds;    timeradd (&user, &sys, &now);    timersub(&now, &last_check, &diff);    if (diff.tv_usec < 50000 && diff.tv_sec == 0)    return;    last_check = now;   #endif    }    }   #elif defined (USE_CLOCK_FOR_SLICES) - #ifdef 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 (clock() - thread_start_clock < (clock_t) (CLOCKS_PER_SEC / 20))    return;   #else    static int div_;    if(div_++ & 255)    return;   #endif   #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);    last_time = (unsigned long) now.tv_sec;    calls = 0;