pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1380: Inside #if defined(RDTSC) && defined(USE_CLOCK_FOR_SLICES)
   * unsynchronized tsc's between cores, OS tsc resets, etc -    * individual intervals can be off by more than an order of    * magnitude in either direction without affecting the final time    * slice length appreciably.    *    * Note that the real interval lengths will always be longer.    * One reason is that we won't get calls exactly when they run    * out. Another is the often lousy clock(3) resolution. */       if (prev_tsc) { -  clock_t tsc_interval_time = clock_now - prev_clock; -  if (tsc_interval_time > 0) { +  if (clock_now > prev_clock) {    /* Estimate the next interval just by extrapolating the    * tsc/clock ratio of the last one. This adapts very    * quickly but is also very "jumpy". That shouldn't matter    * due to the approach with dividing the time slice into    * ~20 tsc intervals.    *    * Note: The main source of the jumpiness is probably that    * clock(3) has so lousy resolution on many platforms, i.e.    * it may step forward very large intervals very seldom    * (100 times/sec on linux/glibc 2.x). It also has the    * effect that the actual tsc intervals will be closer to    * 1/200 sec. */ -  +  clock_t tsc_interval_time = clock_now - prev_clock;    INT64 new_target_int =    (tsc_elapsed * (CLOCKS_PER_SEC / 400)) / tsc_interval_time;    if (new_target_int < target_int << 2)    target_int = new_target_int;    else {    /* The most likely cause for this is high variance in the    * interval lengths due to low clock(3) resolution. */   #ifdef PROFILE_CHECK_THREADS    fprintf (stderr, "[%d:%f] Capping large TSC interval increase "    "(from %"PRINTINT64"d to %"PRINTINT64"d)\n",
pike.git/src/threads.c:1429: Inside #if defined(RDTSC) && defined(USE_CLOCK_FOR_SLICES) and #if 0
   }   #endif   #endif    }    else {    /* clock(3) can have pretty low resolution and might not    * have advanced during the tsc interval. Just do another    * round on the old estimate, keeping prev_tsc and    * prev_clock fixed to get a longer interval for the next    * measurement. */ -  if (tsc_interval_time < 0) { +  if (clock_now < prev_clock) {    /* clock() wraps around fairly often as well. We still    * keep the old interval but update the baselines in this    * case. */    prev_tsc = tsc_now;    prev_clock = clock_now;    }    target_int += tsc_elapsed;   #ifdef PROFILE_CHECK_THREADS    no_clock_advs++;   #endif
pike.git/src/threads.c:1453: Inside #if defined(RDTSC) && defined(USE_CLOCK_FOR_SLICES) and #if defined(PROFILE_CHECK_THREADS)
  #ifdef PROFILE_CHECK_THREADS    fprintf (stderr, "[%d:%f] Warning: Encountered zero prev_tsc "    "(thread_start_clock: %"PRINTINT64"d, "    "clock_now: %"PRINTINT64"d)\n",    getpid(), get_real_time() * (1.0 / CPU_TIME_TICKS),    (INT64) thread_start_clock, (INT64) clock_now);   #endif    prev_tsc = tsc_now;    }    -  if (clock_now - thread_start_clock < 0) +  if (clock_now < thread_start_clock)    /* clock counter has wrapped since the start of the time    * slice. Let's reset and yield. */    thread_start_clock = 0;    else if (clock_now - thread_start_clock <    (clock_t) (CLOCKS_PER_SEC / 20))    return;    }      #ifdef PROFILE_CHECK_THREADS    {
pike.git/src/threads.c:1545:    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)    {    clock_t clock_now = clock(); -  if (clock_now - thread_start_clock < 0) +  if (clock_now < thread_start_clock)    /* clock counter has wrapped since the start of the time slice.    * Let's reset and yield. */    thread_start_clock = 0;    else if (clock_now - thread_start_clock < (clock_t) (CLOCKS_PER_SEC / 20))    return;    }   #else    static int div_;    if(div_++ & 255)    return;