pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1101: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    if(h>=THREAD_TABLE_SIZE)    Pike_fatal("thread_table_hash failed miserably!\n");    if(thread_state_for_id(s->id))    {    if(thread_state_for_id(s->id) == s)    Pike_fatal("Registring thread twice!\n");    else    Pike_fatal("Forgot to unregister thread!\n");    } - /* fprintf(stderr, "thread_table_insert: %"PRINTSIZET"x\n", (size_t) s->id); */ +    #endif    mt_lock( & thread_table_lock );    num_pike_threads++;    if((s->hashlink = thread_table_chains[h]) != NULL)    s->hashlink->backlink = &s->hashlink;    thread_table_chains[h] = s;    s->backlink = &thread_table_chains[h];    mt_unlock( & thread_table_lock );   }      PMOD_EXPORT void thread_table_delete(struct thread_state *s)   { - /* fprintf(stderr, "thread_table_delete: %"PRINTSIZET"x\n", (size_t) s->id); */ +     mt_lock( & thread_table_lock );    num_pike_threads--;    if(s->hashlink != NULL)    s->hashlink->backlink = s->backlink;    *(s->backlink) = s->hashlink;    mt_unlock( & thread_table_lock );   }      PMOD_EXPORT struct thread_state *thread_state_for_id(THREAD_T tid)   {    unsigned INT32 h = thread_table_hash(&tid);    struct thread_state *s = NULL; - #if 0 -  if(num_threads>1) -  fprintf (stderr, "thread_state_for_id: %"PRINTSIZET"x\n", (size_t) tid); - #endif +    #ifdef PIKE_DEBUG    if(h>=THREAD_TABLE_SIZE)    Pike_fatal("thread_table_hash failed miserably!\n");   #endif    mt_lock( & thread_table_lock );    if(thread_table_chains[h] == NULL)    {    /* NULL result */    }    else if(th_equal((s=thread_table_chains[h])->id, tid))
pike.git/src/threads.c:1165:    s->hashlink->backlink = s->backlink;    *(s->backlink) = s->hashlink;    /* And relink at the head of the chain */    if((s->hashlink = thread_table_chains[h]) != NULL)    s->hashlink->backlink = &s->hashlink;    thread_table_chains[h] = s;    s->backlink = &thread_table_chains[h];    }    }    mt_unlock( & thread_table_lock ); - #if 0 -  if(num_threads>1 && s) -  fprintf (stderr, "thread_state_for_id return value: %"PRINTSIZET"x\n", -  (size_t) s->id); - #endif +     return s;    /* NOTEZ BIEN: Return value only guaranteed to remain valid as long    as you have the interpreter lock, unless tid == th_self() */   }      struct thread_state *gdb_thread_state_for_id(THREAD_T tid)   /* Should only be used from a debugger session. */   {    unsigned INT32 h = thread_table_hash(&tid);    struct thread_state *s;
pike.git/src/threads.c:1365:   PMOD_EXPORT int count_pike_threads(void)   {    return num_pike_threads;   }      static void check_threads(struct callback *UNUSED(cb), void *UNUSED(arg), void *UNUSED(arg2))   {   #ifdef PROFILE_CHECK_THREADS    static unsigned long calls = 0, yields = 0;    static unsigned long clock_checks = 0, no_clock_advs = 0; - #if 0 -  static unsigned long slice_int_n = 0; /* Slice interval length. */ -  static double slice_int_mean = 0.0, slice_int_m2 = 0.0; -  static unsigned long tsc_int_n = 0; /* Actual tsc interval length. */ -  static double tsc_int_mean = 0.0, tsc_int_m2 = 0.0; -  static unsigned long tsc_tgt_n = 0; /* Target tsc interval length. */ -  static double tsc_tgt_mean = 0.0, tsc_tgt_m2 = 0.0; - #endif +     static unsigned long tps = 0, tps_int_n = 0; /* TSC intervals per slice. */    static double tps_int_mean = 0.0, tps_int_m2 = 0.0;    calls++;   #endif   #ifdef PIKE_DEBUG    check_threads_calls++;   #endif      #if defined (USE_CLOCK_FOR_SLICES) && defined (PIKE_DEBUG)    if (last_clocked_thread != th_self())
pike.git/src/threads.c:1425: Inside #if defined(RDTSC) && defined(USE_CLOCK_FOR_SLICES)
   tsc_now, prev_tsc, target_int);   #endif    target_int = TSC_START_INTERVAL;    prev_tsc = 0;    }    else    return;    }      #ifdef PROFILE_CHECK_THREADS - #if 0 -  if (prev_tsc) { -  double delta = tsc_elapsed - tsc_int_mean; -  tsc_int_n++; -  tsc_int_mean += delta / tsc_int_n; -  tsc_int_m2 += delta * (tsc_elapsed - tsc_int_mean); -  } - #endif +     clock_checks++;    tps++;   #endif       {    clock_t clock_now = clock();       /* Aim tsc intervals at 1/20th of a thread time slice interval,    * i.e. at 1/400 sec. That means the time is checked with    * clock(3) approx 20 times per slice. That still cuts the vast
pike.git/src/threads.c:1488: Inside #if defined(RDTSC) && defined(USE_CLOCK_FOR_SLICES) and #if defined(PROFILE_CHECK_THREADS)
   fprintf (stderr, "[%d:%f] Capping large TSC interval increase "    "(from %"PRINTINT64"d to %"PRINTINT64"d)\n",    getpid(), get_real_time() * (1.0 / CPU_TIME_TICKS),    target_int, new_target_int);   #endif    /* The + 1 is paranoia just in case it has become zero somehow. */    target_int = (target_int << 2) + 1;    }    prev_tsc = tsc_now;    prev_clock = clock_now; - #if 0 - #ifdef PROFILE_CHECK_THREADS -  { -  double delta = target_int - tsc_tgt_mean; -  tsc_tgt_n++; -  tsc_tgt_mean += delta / tsc_tgt_n; -  tsc_tgt_m2 += delta * (target_int - tsc_tgt_mean); +     } - #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 (clock_now < prev_clock) {    /* clock() wraps around fairly often as well. We still    * keep the old interval but update the baselines in this    * case. */
pike.git/src/threads.c:1646:    check_threads_yields++;   #endif      #ifdef PROFILE_CHECK_THREADS    {    static long last_time;    struct timeval now;       yields++;    - #if 0 - #ifdef USE_CLOCK_FOR_SLICES -  if (thread_start_clock) { -  double slice_time = -  (double) (clock() - thread_start_clock) / CLOCKS_PER_SEC; -  double delta = slice_time - slice_int_mean; -  slice_int_n++; -  slice_int_mean += delta / slice_int_n; -  slice_int_m2 += delta * (slice_time - slice_int_mean); -  } - #endif - #endif -  +     ACCURATE_GETTIMEOFDAY (&now);    if (now.tv_sec > last_time) {    fprintf (stderr, "[%d:%f] check_threads: %lu calls, "    "%lu clocks, %lu no advs, %lu yields" - #if 0 -  ", slice %.3f:%.1e, tsc int %.2e:%.1e, tsc tgt %.2e:%.1e" - #endif +     ", tps %g:%.1e\n",    getpid(), get_real_time() * (1.0 / CPU_TIME_TICKS),    calls, clock_checks, no_clock_advs, yields, - #if 0 -  slice_int_mean, -  slice_int_n > 1 ? sqrt (slice_int_m2 / (slice_int_n - 1)) : 0.0, -  tsc_int_mean, -  tsc_int_n > 1 ? sqrt (tsc_int_m2 / (tsc_int_n - 1)) : 0.0, -  tsc_tgt_mean, -  tsc_tgt_n > 1 ? sqrt (tsc_tgt_m2 / (tsc_tgt_n - 1)) : 0.0, - #endif +     tps_int_mean,    tps_int_n > 1 ? sqrt (tps_int_m2 / (tps_int_n - 1)) : 0.0);    last_time = (unsigned long) now.tv_sec;    calls = yields = clock_checks = no_clock_advs = 0;    }    }   #endif       {   #ifdef PIKE_DEBUG