pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:571: Inside #if defined(USE_CLOCK_FOR_SLICES)
  #endif   #ifdef USE_CLOCK_FOR_SLICES    /* Initialize thread_start_clock to zero instead of clock() since we    * don't know for how long the thread already has run. */    thread_start_clock = 0;    last_clocked_thread = ts->id;   #ifdef RDTSC    prev_tsc = 0;   #endif   #ifdef PROFILE_CHECK_THREADS -  fprintf (stderr, "[%d:%f] pike_init_thread_state: tsc reset\n", +  WERR("[%d:%f] pike_init_thread_state: tsc reset\n",    getpid(), get_real_time() * (1.0 / CPU_TIME_TICKS));   #endif   #endif   }      PMOD_EXPORT void pike_swap_out_thread (struct thread_state *ts    COMMA_DLOC_DECL)   {    USE_DLOC_ARGS();    THREADS_FPRINTF (2, "Swap out %sthread %p @ %s:%d\n",
pike.git/src/threads.c:1311:    f_aggregate(Pike_sp - oldsp);   }      #ifdef PIKE_DEBUG   PMOD_EXPORT void debug_list_all_threads(void)   {    INT32 x;    struct thread_state *s;    THREAD_T self = th_self();    -  fprintf(stderr,"--Listing all threads--\n"); -  fprintf (stderr, "Current thread: %"PRINTSIZET"x\n", (size_t) self); -  fprintf(stderr,"Current interpreter thread state: %p%s\n", +  WERR("--Listing all threads--\n"); +  WERR("Current thread: %"PRINTSIZET"x\n", (size_t) self); +  WERR("Current interpreter thread state: %p%s\n",    Pike_interpreter.thread_state,    Pike_interpreter.thread_state == (struct thread_state *) (ptrdiff_t) -1 ?    " (swapped)" : ""); -  fprintf(stderr,"Current thread state according to thread_state_for_id(): %p\n", +  WERR("Current thread state according to thread_state_for_id(): %p\n",    thread_state_for_id (self)); -  fprintf(stderr,"Current thread obj: %p\n", +  WERR("Current thread obj: %p\n",    (Pike_interpreter.thread_state &&    Pike_interpreter.thread_state != (struct thread_state *) (ptrdiff_t) -1) ?    Pike_interpreter.thread_state->thread_obj : NULL); -  fprintf(stderr,"Current thread hash: %d\n",thread_table_hash(&self)); -  fprintf(stderr,"Current stack pointer: %p\n",&self); +  WERR("Current thread hash: %d\n",thread_table_hash(&self)); +  WERR("Current stack pointer: %p\n",&self);    for(x=0; x<THREAD_TABLE_SIZE; x++)    {    for(s=thread_table_chains[x]; s; s=s->hashlink) {    struct object *o = THREADSTATE2OBJ(s); -  fprintf(stderr,"ThTab[%d]: state=%p, obj=%p, " +  WERR("ThTab[%d]: state=%p, obj=%p, "    "swapped=%d, sp=%p (%+"PRINTPTRDIFFT"d), fp=%p, stackbase=%p, "    "id=%"PRINTSIZET"x\n",    x, s, o, s->swapped,    s->state.stack_pointer,    s->state.stack_pointer - s->state.evaluator_stack,    s->state.frame_pointer,    s->state.stack_top,    (size_t) s->id);    }    } -  fprintf(stderr,"-----------------------\n"); +  WERR("-----------------------\n");   }   #endif      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))   {
pike.git/src/threads.c:1392: Inside #if defined(RDTSC) && defined(USE_CLOCK_FOR_SLICES)
   RDTSC(tsc_now);    tsc_elapsed = tsc_now - prev_tsc;       if (tsc_elapsed < target_int) {    if (tsc_elapsed < 0) {    /* The counter jumped back in time, 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, "[%d:%f] TSC backward jump detected " +  WERR("[%d:%f] TSC backward jump detected "    "(now: %"PRINTINT64"d, prev: %"PRINTINT64"d, "    "target_int: %"PRINTINT64"d) - resetting\n",    getpid(), get_real_time() * (1.0 / CPU_TIME_TICKS),    tsc_now, prev_tsc, target_int);   #endif    target_int = TSC_START_INTERVAL;    prev_tsc = 0;    }    else    return;
pike.git/src/threads.c:1451: Inside #if defined(RDTSC) && defined(USE_CLOCK_FOR_SLICES)
   * 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 " +  WERR("[%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;    }
pike.git/src/threads.c:1483: Inside #if defined(RDTSC) && defined(USE_CLOCK_FOR_SLICES)
   prev_clock = clock_now;    }    target_int += tsc_elapsed;   #ifdef PROFILE_CHECK_THREADS    no_clock_advs++;   #endif    }    }    else {   #ifdef PROFILE_CHECK_THREADS -  fprintf (stderr, "[%d:%f] Warning: Encountered zero prev_tsc " +  WERR("[%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)    /* clock counter has wrapped since the start of the time
pike.git/src/threads.c:1611: Inside #if defined(PROFILE_CHECK_THREADS)
     #ifdef PROFILE_CHECK_THREADS    {    static long last_time;    struct timeval now;       yields++;       ACCURATE_GETTIMEOFDAY (&now);    if (now.tv_sec > last_time) { -  fprintf (stderr, "[%d:%f] check_threads: %lu calls, " +  WERR("[%d:%f] check_threads: %lu calls, "    "%lu clocks, %lu no advs, %lu yields"    ", tps %g:%.1e\n",    getpid(), get_real_time() * (1.0 / CPU_TIME_TICKS),    calls, clock_checks, no_clock_advs, yields,    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;    }    }
pike.git/src/threads.c:1700: Inside #if defined(HAVE_BROKEN_LINUX_THREAD_EUID)
   /* Work-around for Linux's pthreads not propagating the    * effective uid & gid.    */    if (!geteuid()) {   #if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)    /* The sete?id calls will clear the dumpable state that we might    * have set with system.dumpable. */    int current = prctl(PR_GET_DUMPABLE);   #ifdef PIKE_DEBUG    if (current == -1) -  fprintf (stderr, "%s:%d: Unexpected error from prctl(2). errno=%d\n", +  WERR("%s:%d: Unexpected error from prctl(2). errno=%d\n",    __FILE__, __LINE__, errno);   #endif   #endif   #ifdef HAVE_BROKEN_LINUX_THREAD_EUID    if( setegid(arg.egid) != 0 || seteuid(arg.euid) != 0 )    { -  fprintf (stderr, "%s:%d: Unexpected error from setegid(2). errno=%d\n", +  WERR("%s:%d: Unexpected error from setegid(2). errno=%d\n",    __FILE__, __LINE__, errno);    }   #endif   #if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)    if (current != -1 && prctl(PR_SET_DUMPABLE, current) == -1) {    DWERR("%s:%d: Unexpected error from prctl(2). errno=%d\n",    __FILE__, __LINE__, errno);    }   #endif    }
pike.git/src/threads.c:3141: Inside #if defined(HAVE_BROKEN_LINUX_THREAD_EUID)
   */    if (!geteuid()) {   #if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)    /* The sete?id calls will clear the dumpable state that we might    * have set with system.dumpable. */    int current = prctl(PR_GET_DUMPABLE);   #endif   #ifdef HAVE_BROKEN_LINUX_THREAD_EUID    if( setegid(arg.egid) != 0 || seteuid(arg.euid) != 0 )    { -  fprintf (stderr, "%s:%d: Unexpected error from setegid(2). errno=%d\n", +  WERR("%s:%d: Unexpected error from setegid(2). errno=%d\n",    __FILE__, __LINE__, errno);    }   #endif   #if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)    if (prctl(PR_SET_DUMPABLE, current) == -1)    Pike_fatal ("Didn't expect prctl to go wrong. errno=%d\n", errno);   #endif    }   #endif /* HAVE_BROKEN_LINUX_THREAD_EUID */       do    { - /* if(farmers == me) Pike_fatal("Ouch!\n"); */ - /* fprintf(stderr, "farm_begin %p\n",me ); */ +     me->harvest( me->field ); - /* fprintf(stderr, "farm_end %p\n", me); */ +        me->harvest = 0;    mt_lock( &rosie );    if( ++_num_idle_farmers > 16 )    {    --_num_idle_farmers;    --_num_farmers;    mt_unlock( &rosie );    free( me );    return 0;    }    me->neighbour = farmers;    farmers = me; - /* fprintf(stderr, "farm_wait %p\n", me); */ +     while(!me->harvest) co_wait( &me->harvest_moon, &rosie );    --_num_idle_farmers;    mt_unlock( &rosie ); - /* fprintf(stderr, "farm_endwait %p\n", me); */ +     } while(1);    UNREACHABLE(return 0);   }      int th_num_idle_farmers(void)   {    return _num_idle_farmers;   }      
pike.git/src/threads.c:3467: Inside #if defined(DO_PIKE_CLEANUP)
   mt_unlock (&thread_table_lock);       while (num_pending_interrupts && time (NULL) < timeout) {    THREADS_ALLOW();    sysleep(1.0);    THREADS_DISALLOW();    }      #if 0    if (num_kills) { -  fprintf (stderr, "Killed %d thread(s) in exit cleanup", +  WERR("Killed %d thread(s) in exit cleanup",    num_kills - num_pending_interrupts);    if (num_pending_interrupts) -  fprintf (stderr, ", %d more haven't responded", num_pending_interrupts); +  WERR(", %d more haven't responded", num_pending_interrupts);    fputs (".\n", stderr);    }   #endif   }   #endif      void th_cleanup(void)   {    th_running = 0;