list_for_each_entry(nte, base->tv1.vec + j, entry) { expires = nte->expires; if (j < (base->timer_jiffies & TVR_MASK)) list = base->tv2.vec + (INDEX(0)); goto found; } j = (j + 1) & TVR_MASK; } while (j != (base->timer_jiffies & TVR_MASK)); /* Check tv2-tv5. */ varray[0] = &base->tv2; varray[1] = &base->tv3; varray[2] = &base->tv4; varray[3] = &base->tv5; for (i = 0; i < 4; i++) { j = INDEX(i); do { if (list_empty(varray[i]->vec + j)) { j = (j + 1) & TVN_MASK; continue; } list_for_each_entry(nte, varray[i]->vec + j, entry) if (time_before(nte->expires, expires)) expires = nte->expires; if (j < (INDEX(i)) && i < 3) list = varray[i + 1]->vec + (INDEX(i + 1)); goto found; } while (j != (INDEX(i))); }found: if (list) { /* * The search wrapped. We need to look at the next list * from next tv element that would cascade into tv element * where we found the timer element. */ list_for_each_entry(nte, list, entry) { if (time_before(nte->expires, expires)) expires = nte->expires; } } spin_unlock(&base->lock); /* * It can happen that other CPUs service timer IRQs and increment * jiffies, but we have not yet got a local timer tick to process * the timer wheels. In that case, the expiry time can be before * jiffies, but since the high-resolution timer here is relative to * jiffies, the default expression when high-resolution timers are * not active, * * time_before(MAX_JIFFY_OFFSET + jiffies, expires) * * would falsely evaluate to true. If that is the case, just * return jiffies so that we can immediately fire the local timer */ if (time_before(expires, jiffies)) return jiffies; if (time_before(hr_expires, expires)) return hr_expires; return expires;}#endif /******************************************************************/ /* * Timekeeping variables */unsigned long tick_usec = TICK_USEC; /* USER_HZ period (usec) */unsigned long tick_nsec = TICK_NSEC; /* ACTHZ period (nsec) */ /* * The current time * wall_to_monotonic is what we need to add to xtime (or xtime corrected * for sub jiffie times) to get to monotonic time. Monotonic is pegged * at zero at system boot time, so wall_to_monotonic will be negative, * however, we will ALWAYS keep the tv_nsec part positive so we can use * the usual normalization. */struct timespec xtime __attribute__ ((aligned (16)));struct timespec wall_to_monotonic __attribute__ ((aligned (16))); EXPORT_SYMBOL(xtime); /* Don't completely fail for HZ > 500. */int tickadj = 500/HZ ? : 1; /* microsecs */ /* * phase-lock loop variables *//* TIME_ERROR prevents overwriting the CMOS clock */int time_state = TIME_OK; /* clock synchronization status */int time_status = STA_UNSYNC; /* clock status bits */long time_offset; /* time adjustment (us) */long time_constant = 2; /* pll time constant */long time_tolerance = MAXFREQ; /* frequency tolerance (ppm) */long time_precision = 1; /* clock precision (us) */long time_maxerror = NTP_PHASE_LIMIT; /* maximum error (us) */long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */static long time_phase; /* phase offset (scaled us) */long time_freq = (((NSEC_PER_SEC + HZ/2) % HZ - HZ/2) << SHIFT_USEC) / NSEC_PER_USEC; /* frequency offset (scaled ppm)*/static long time_adj; /* tick adjust (scaled 1 / HZ) */long time_reftime; /* time at last adjustment (s) */long time_adjust;long time_next_adjust; /* * this routine handles the overflow of the microsecond field * * The tricky bits of code to handle the accurate clock support * were provided by Dave Mills (Mills@UDEL.EDU) of NTP fame. * They were originally developed for SUN and DEC kernels. * All the kudos should go to Dave for this stuff. * */static void second_overflow(void){ long ltemp; /* Bump the maxerror field */ time_maxerror += time_tolerance >> SHIFT_USEC; if (time_maxerror > NTP_PHASE_LIMIT) { time_maxerror = NTP_PHASE_LIMIT; time_status |= STA_UNSYNC; } /* * Leap second processing. If in leap-insert state at the end of the * day, the system clock is set back one second; if in leap-delete * state, the system clock is set ahead one second. The microtime() * routine or external clock driver will insure that reported time is * always monotonic. The ugly divides should be replaced. */ switch (time_state) { case TIME_OK: if (time_status & STA_INS) time_state = TIME_INS; else if (time_status & STA_DEL) time_state = TIME_DEL; break; case TIME_INS: if (xtime.tv_sec % 86400 == 0) { xtime.tv_sec--; wall_to_monotonic.tv_sec++; /* * The timer interpolator will make time change * gradually instead of an immediate jump by one second */ time_interpolator_update(-NSEC_PER_SEC); time_state = TIME_OOP; clock_was_set(); printk(KERN_NOTICE "Clock: inserting leap second " "23:59:60 UTC\n"); } break; case TIME_DEL: if ((xtime.tv_sec + 1) % 86400 == 0) { xtime.tv_sec++; wall_to_monotonic.tv_sec--; /* * Use of time interpolator for a gradual change of * time */ time_interpolator_update(NSEC_PER_SEC); time_state = TIME_WAIT; clock_was_set(); printk(KERN_NOTICE "Clock: deleting leap second " "23:59:59 UTC\n"); } break; case TIME_OOP: time_state = TIME_WAIT; break; case TIME_WAIT: if (!(time_status & (STA_INS | STA_DEL))) time_state = TIME_OK; } /* * Compute the phase adjustment for the next second. In PLL mode, the * offset is reduced by a fixed factor times the time constant. In FLL * mode the offset is used directly. In either mode, the maximum phase * adjustment for each second is clamped so as to spread the adjustment * over not more than the number of seconds between updates. */ ltemp = time_offset; if (!(time_status & STA_FLL)) ltemp = shift_right(ltemp, SHIFT_KG + time_constant); ltemp = min(ltemp, (MAXPHASE / MINSEC) << SHIFT_UPDATE); ltemp = max(ltemp, -(MAXPHASE / MINSEC) << SHIFT_UPDATE); time_offset -= ltemp; time_adj = ltemp << (SHIFT_SCALE - SHIFT_HZ - SHIFT_UPDATE); /* * Compute the frequency estimate and additional phase adjustment due * to frequency error for the next second. */ ltemp = time_freq; time_adj += shift_right(ltemp,(SHIFT_USEC + SHIFT_HZ - SHIFT_SCALE)); #if HZ == 100 /* * Compensate for (HZ==100) != (1 << SHIFT_HZ). Add 25% and 3.125% to * get 128.125; => only 0.125% error (p. 14) */ time_adj += shift_right(time_adj, 2) + shift_right(time_adj, 5);#endif#if HZ == 250 /* * Compensate for (HZ==250) != (1 << SHIFT_HZ). Add 1.5625% and * 0.78125% to get 255.85938; => only 0.05% error (p. 14) */ time_adj += shift_right(time_adj, 6) + shift_right(time_adj, 7);#endif#if HZ == 1000 /* * Compensate for (HZ==1000) != (1 << SHIFT_HZ). Add 1.5625% and * 0.78125% to get 1023.4375; => only 0.05% error (p. 14) */ time_adj += shift_right(time_adj, 6) + shift_right(time_adj, 7);#endif} /* * Returns how many microseconds we need to add to xtime this tick * in doing an adjustment requested with adjtime. */static long adjtime_adjustment(void){ long time_adjust_step; time_adjust_step = time_adjust; if (time_adjust_step) { /* * We are doing an adjtime thing. Prepare time_adjust_step to * be within bounds. Note that a positive time_adjust means we * want the clock to run faster. * * Limit the amount of the step to be in the range * -tickadj .. +tickadj */ time_adjust_step = min(time_adjust_step, (long)tickadj); time_adjust_step = max(time_adjust_step, (long)-tickadj); } return time_adjust_step;} /* in the NTP reference this is called "hardclock()" */static void update_wall_time_one_tick(void){ long time_adjust_step, delta_nsec; time_adjust_step = adjtime_adjustment(); if (time_adjust_step) /* Reduce by this step the amount of time left */ time_adjust -= time_adjust_step; delta_nsec = tick_nsec + time_adjust_step * 1000; /* * Advance the phase, once it gets to one microsecond, then * advance the tick more. */ time_phase += time_adj; if ((time_phase >= FINENSEC) || (time_phase <= -FINENSEC)) { long ltemp = shift_right(time_phase, (SHIFT_SCALE - 10)); time_phase -= ltemp << (SHIFT_SCALE - 10); delta_nsec += ltemp; } xtime.tv_nsec += delta_nsec; time_interpolator_update(delta_nsec); /* Changes by adjtime() do not take effect till next tick. */ if (time_next_adjust != 0) { time_adjust = time_next_adjust; time_next_adjust = 0; }} /* * Return how long ticks are at the moment, that is, how much time * update_wall_time_one_tick will add to xtime next time we call it * (assuming no calls to do_adjtimex in the meantime). * The return value is in fixed-point nanoseconds with SHIFT_SCALE-10 * bits to the right of the binary point. * This function has no side-effects. */u64 current_tick_length(void){ long delta_nsec; delta_nsec = tick_nsec + adjtime_adjustment() * 1000; return ((u64) delta_nsec << (SHIFT_SCALE - 10)) + time_adj;} /* * Using a loop looks inefficient, but "ticks" is * usually just one (we shouldn't be losing ticks, * we're doing this this way mainly for interrupt * latency reasons, not because we think we'll * have lots of lost timer ticks */static void update_wall_time(unsigned long ticks){ do { ticks--; update_wall_time_one_tick(); if (xtime.tv_nsec >= 1000000000) { xtime.tv_nsec -= 1000000000; xtime.tv_sec++; second_overflow(); } } while (ticks);} /* * Called from the timer interrupt handler to charge one tick to the current * process. user_tick is 1 if the tick is user time, 0 for system. */void update_process_times(int user_tick){ struct task_struct *p = current; int cpu = smp_processor_id(); /* Note: this timer irq context must be accounted for as well. */ if (user_tick) account_user_time(p, jiffies_to_cputime(1)); else account_system_time(p, HARDIRQ_OFFSET, jiffies_to_cputime(1)); run_local_timers(); if (rcu_pending(cpu)) rcu_check_callbacks(cpu, user_tick); scheduler_tick(); run_posix_cpu_timers(p);} /* * Nr of active tasks - counted in fixed-point numbers */static unsigned long count_active_tasks(void){ return nr_active() * FIXED_1;} /* * Hmm.. Changed this, as the GNU make sources (load.c) seems to * imply that avenrun[] is the standard name for this kind of thing. * Nothing else seems to be standardized: the fractional size etc * all seem to differ on different machines. * * Requires xtime_lock to access. */unsigned long avenrun[3]; EXPORT_SYMBOL(avenrun); /* * calc_load - given tick count, update the avenrun load estimates. * This is called while holding a write_lock on xtime_lock. */static inline void calc_load(unsigned long ticks){ unsigned long active_tasks; /* fixed-point */ static int count = LOAD_FREQ; count -= ticks; if (count < 0) { count += LOAD_FREQ; active_tasks = count_active_tasks(); CALC_LOAD(avenrun[0], EXP_1, active_tasks); CALC_LOAD(avenrun[1], EXP_5, active_tasks); CALC_LOAD(avenrun[2], EXP_15, active_tasks); }} /* jiffies at the most recent update of wall time */unsigned long wall_jiffies = INITIAL_JIFFIES; /* * This read-write spinlock protects us from races in SMP while * playing with xtime and avenrun. */#ifndef ARCH_HAVE_XTIME_LOCKseqlock_t xtime_lock __cacheline_aligned_in_smp = SEQLOCK_UNLOCKED; EXPORT_SYMBOL(xtime_lock);#endif /* * This function runs timers and the timer-tq in bottom half context. */static void run_timer_softirq(struct softirq_action *h){ tvec_base_t *base = __get_cpu_var(tvec_bases); hrtimer_run_queues(); if (time_after_eq(jiffies, base->timer_jiffies)) __run_timers(base);} /* * Called by the local, per-CPU timer interrupt on SMP. */void run_local_timers(void){ raise_softirq(TIMER_SOFTIRQ); softlockup_tick();} /* * Called by the timer interrupt. xtime_lock must already be taken * by the timer IRQ! */static inline void update_times(void){ unsigned long ticks; ticks = jiffies - wall_jiffies; if (ticks) { wall_jiffies += ticks; update_wall_time(ticks); } calc_load(ticks);} /* * The 64-bit jiffies value is not atomic - you MUST NOT read it * without sampling the sequence number in xtime_lock. * jiffies is defined in the linker script... */ void do_timer(struct pt_regs *regs){ jiffies_64++; /* prevent loading jiffies before storing new jiffies_64 value. */ barrier(); update_times();} #ifdef __ARCH_WANT_SYS_ALARM /* * For backwards compatibility? This can be done in libc so Alpha * and all newer ports shouldn't need it. */asmlinkage unsigned long sys_alarm(unsigned int seconds){ return alarm_setitimer(seconds);} #endif #ifndef __alpha__ /* * The Alpha uses getxpid, getxuid, and getxgid instead. Maybe this * should be moved into arch/i386 instead? */ /** * sys_getpid - return the thread group id of the current process * * Note, despite the name, this returns the tgid not the pid. The tgid and * the pid are identical unless CLONE_THREAD was specified on clone() in * which case the tgid is the same in all threads of the same group. * * This is SMP safe as current->tgid does not change. */asmlinkage long sys_getpid(void){ return current->tgid;} /* * Accessing ->group_leader->real_parent is not SMP-safe, it could * change from under us. However, rather than getting any lock * we can use an optimistic algorithm: get the parent * pid, and go back and check that the parent is still * the same. If it has changed (which is extremely unlikely * indeed), we just try again.. * * NOTE! This depends on the fact that even if we _do_ * get an old value of "parent", we can happily dereference * the pointer (it was and remains a dereferencable kernel pointer * no matter what): we just can't necessarily trust the result * until we know that the parent pointer is valid. * * NOTE2: ->group_leader never changes from under us. */asmlinkage long sys_getppid(void){ int pid; struct task_struct *me = current; struct task_struct *parent; parent = me->group_leader->real_parent; for (;;) {Lines 501–1000 of 1581. Previous lines Load more
list_for_each_entry(nte, base->tv1.vec + j, entry) { expires = nte->expires; if (j < (base->timer_jiffies & TVR_MASK)) list = base->tv2.vec + (INDEX(0)); goto found; } j = (j + 1) & TVR_MASK; } while (j != (base->timer_jiffies & TVR_MASK)); /* Check tv2-tv5. */ varray[0] = &base->tv2; varray[1] = &base->tv3; varray[2] = &base->tv4; varray[3] = &base->tv5; for (i = 0; i < 4; i++) { j = INDEX(i); do { if (list_empty(varray[i]->vec + j)) { j = (j + 1) & TVN_MASK; continue; } list_for_each_entry(nte, varray[i]->vec + j, entry) if (time_before(nte->expires, expires)) expires = nte->expires; if (j < (INDEX(i)) && i < 3) list = varray[i + 1]->vec + (INDEX(i + 1)); goto found; } while (j != (INDEX(i))); } found: if (list) { /* * The search wrapped. We need to look at the next list * from next tv element that would cascade into tv element * where we found the timer element. */ list_for_each_entry(nte, list, entry) { if (time_before(nte->expires, expires)) expires = nte->expires; } } spin_unlock(&base->lock); /* * It can happen that other CPUs service timer IRQs and increment * jiffies, but we have not yet got a local timer tick to process * the timer wheels. In that case, the expiry time can be before * jiffies, but since the high-resolution timer here is relative to * jiffies, the default expression when high-resolution timers are * not active, * * time_before(MAX_JIFFY_OFFSET + jiffies, expires) * * would falsely evaluate to true. If that is the case, just * return jiffies so that we can immediately fire the local timer */ if (time_before(expires, jiffies)) return jiffies; if (time_before(hr_expires, expires)) return hr_expires; return expires; } #endif /******************************************************************/ /* * Timekeeping variables */ unsigned long tick_usec = TICK_USEC; /* USER_HZ period (usec) */ unsigned long tick_nsec = TICK_NSEC; /* ACTHZ period (nsec) */ /* * The current time * wall_to_monotonic is what we need to add to xtime (or xtime corrected * for sub jiffie times) to get to monotonic time. Monotonic is pegged * at zero at system boot time, so wall_to_monotonic will be negative, * however, we will ALWAYS keep the tv_nsec part positive so we can use * the usual normalization. */ struct timespec xtime __attribute__ ((aligned (16))); struct timespec wall_to_monotonic __attribute__ ((aligned (16))); EXPORT_SYMBOL(xtime); /* Don't completely fail for HZ > 500. */ int tickadj = 500/HZ ? : 1; /* microsecs */ /* * phase-lock loop variables */ /* TIME_ERROR prevents overwriting the CMOS clock */ int time_state = TIME_OK; /* clock synchronization status */ int time_status = STA_UNSYNC; /* clock status bits */ long time_offset; /* time adjustment (us) */ long time_constant = 2; /* pll time constant */ long time_tolerance = MAXFREQ; /* frequency tolerance (ppm) */ long time_precision = 1; /* clock precision (us) */ long time_maxerror = NTP_PHASE_LIMIT; /* maximum error (us) */ long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */ static long time_phase; /* phase offset (scaled us) */ long time_freq = (((NSEC_PER_SEC + HZ/2) % HZ - HZ/2) << SHIFT_USEC) / NSEC_PER_USEC; /* frequency offset (scaled ppm)*/ static long time_adj; /* tick adjust (scaled 1 / HZ) */ long time_reftime; /* time at last adjustment (s) */ long time_adjust; long time_next_adjust; /* * this routine handles the overflow of the microsecond field * * The tricky bits of code to handle the accurate clock support * were provided by Dave Mills (Mills@UDEL.EDU) of NTP fame. * They were originally developed for SUN and DEC kernels. * All the kudos should go to Dave for this stuff. * */ static void second_overflow(void) { long ltemp; /* Bump the maxerror field */ time_maxerror += time_tolerance >> SHIFT_USEC; if (time_maxerror > NTP_PHASE_LIMIT) { time_maxerror = NTP_PHASE_LIMIT; time_status |= STA_UNSYNC; } /* * Leap second processing. If in leap-insert state at the end of the * day, the system clock is set back one second; if in leap-delete * state, the system clock is set ahead one second. The microtime() * routine or external clock driver will insure that reported time is * always monotonic. The ugly divides should be replaced. */ switch (time_state) { case TIME_OK: if (time_status & STA_INS) time_state = TIME_INS; else if (time_status & STA_DEL) time_state = TIME_DEL; break; case TIME_INS: if (xtime.tv_sec % 86400 == 0) { xtime.tv_sec--; wall_to_monotonic.tv_sec++; /* * The timer interpolator will make time change * gradually instead of an immediate jump by one second */ time_interpolator_update(-NSEC_PER_SEC); time_state = TIME_OOP; clock_was_set(); printk(KERN_NOTICE "Clock: inserting leap second " "23:59:60 UTC\n"); } break; case TIME_DEL: if ((xtime.tv_sec + 1) % 86400 == 0) { xtime.tv_sec++; wall_to_monotonic.tv_sec--; /* * Use of time interpolator for a gradual change of * time */ time_interpolator_update(NSEC_PER_SEC); time_state = TIME_WAIT; clock_was_set(); printk(KERN_NOTICE "Clock: deleting leap second " "23:59:59 UTC\n"); } break; case TIME_OOP: time_state = TIME_WAIT; break; case TIME_WAIT: if (!(time_status & (STA_INS | STA_DEL))) time_state = TIME_OK; } /* * Compute the phase adjustment for the next second. In PLL mode, the * offset is reduced by a fixed factor times the time constant. In FLL * mode the offset is used directly. In either mode, the maximum phase * adjustment for each second is clamped so as to spread the adjustment * over not more than the number of seconds between updates. */ ltemp = time_offset; if (!(time_status & STA_FLL)) ltemp = shift_right(ltemp, SHIFT_KG + time_constant); ltemp = min(ltemp, (MAXPHASE / MINSEC) << SHIFT_UPDATE); ltemp = max(ltemp, -(MAXPHASE / MINSEC) << SHIFT_UPDATE); time_offset -= ltemp; time_adj = ltemp << (SHIFT_SCALE - SHIFT_HZ - SHIFT_UPDATE); /* * Compute the frequency estimate and additional phase adjustment due * to frequency error for the next second. */ ltemp = time_freq; time_adj += shift_right(ltemp,(SHIFT_USEC + SHIFT_HZ - SHIFT_SCALE)); #if HZ == 100 /* * Compensate for (HZ==100) != (1 << SHIFT_HZ). Add 25% and 3.125% to * get 128.125; => only 0.125% error (p. 14) */ time_adj += shift_right(time_adj, 2) + shift_right(time_adj, 5); #endif #if HZ == 250 /* * Compensate for (HZ==250) != (1 << SHIFT_HZ). Add 1.5625% and * 0.78125% to get 255.85938; => only 0.05% error (p. 14) */ time_adj += shift_right(time_adj, 6) + shift_right(time_adj, 7); #endif #if HZ == 1000 /* * Compensate for (HZ==1000) != (1 << SHIFT_HZ). Add 1.5625% and * 0.78125% to get 1023.4375; => only 0.05% error (p. 14) */ time_adj += shift_right(time_adj, 6) + shift_right(time_adj, 7); #endif } /* * Returns how many microseconds we need to add to xtime this tick * in doing an adjustment requested with adjtime. */ static long adjtime_adjustment(void) { long time_adjust_step; time_adjust_step = time_adjust; if (time_adjust_step) { /* * We are doing an adjtime thing. Prepare time_adjust_step to * be within bounds. Note that a positive time_adjust means we * want the clock to run faster. * * Limit the amount of the step to be in the range * -tickadj .. +tickadj */ time_adjust_step = min(time_adjust_step, (long)tickadj); time_adjust_step = max(time_adjust_step, (long)-tickadj); } return time_adjust_step; } /* in the NTP reference this is called "hardclock()" */ static void update_wall_time_one_tick(void) { long time_adjust_step, delta_nsec; time_adjust_step = adjtime_adjustment(); if (time_adjust_step) /* Reduce by this step the amount of time left */ time_adjust -= time_adjust_step; delta_nsec = tick_nsec + time_adjust_step * 1000; /* * Advance the phase, once it gets to one microsecond, then * advance the tick more. */ time_phase += time_adj; if ((time_phase >= FINENSEC) || (time_phase <= -FINENSEC)) { long ltemp = shift_right(time_phase, (SHIFT_SCALE - 10)); time_phase -= ltemp << (SHIFT_SCALE - 10); delta_nsec += ltemp; } xtime.tv_nsec += delta_nsec; time_interpolator_update(delta_nsec); /* Changes by adjtime() do not take effect till next tick. */ if (time_next_adjust != 0) { time_adjust = time_next_adjust; time_next_adjust = 0; } } /* * Return how long ticks are at the moment, that is, how much time * update_wall_time_one_tick will add to xtime next time we call it * (assuming no calls to do_adjtimex in the meantime). * The return value is in fixed-point nanoseconds with SHIFT_SCALE-10 * bits to the right of the binary point. * This function has no side-effects. */ u64 current_tick_length(void) { long delta_nsec; delta_nsec = tick_nsec + adjtime_adjustment() * 1000; return ((u64) delta_nsec << (SHIFT_SCALE - 10)) + time_adj; } /* * Using a loop looks inefficient, but "ticks" is * usually just one (we shouldn't be losing ticks, * we're doing this this way mainly for interrupt * latency reasons, not because we think we'll * have lots of lost timer ticks */ static void update_wall_time(unsigned long ticks) { do { ticks--; update_wall_time_one_tick(); if (xtime.tv_nsec >= 1000000000) { xtime.tv_nsec -= 1000000000; xtime.tv_sec++; second_overflow(); } } while (ticks); } /* * Called from the timer interrupt handler to charge one tick to the current * process. user_tick is 1 if the tick is user time, 0 for system. */ void update_process_times(int user_tick) { struct task_struct *p = current; int cpu = smp_processor_id(); /* Note: this timer irq context must be accounted for as well. */ if (user_tick) account_user_time(p, jiffies_to_cputime(1)); else account_system_time(p, HARDIRQ_OFFSET, jiffies_to_cputime(1)); run_local_timers(); if (rcu_pending(cpu)) rcu_check_callbacks(cpu, user_tick); scheduler_tick(); run_posix_cpu_timers(p); } /* * Nr of active tasks - counted in fixed-point numbers */ static unsigned long count_active_tasks(void) { return nr_active() * FIXED_1; } /* * Hmm.. Changed this, as the GNU make sources (load.c) seems to * imply that avenrun[] is the standard name for this kind of thing. * Nothing else seems to be standardized: the fractional size etc * all seem to differ on different machines. * * Requires xtime_lock to access. */ unsigned long avenrun[3]; EXPORT_SYMBOL(avenrun); /* * calc_load - given tick count, update the avenrun load estimates. * This is called while holding a write_lock on xtime_lock. */ static inline void calc_load(unsigned long ticks) { unsigned long active_tasks; /* fixed-point */ static int count = LOAD_FREQ; count -= ticks; if (count < 0) { count += LOAD_FREQ; active_tasks = count_active_tasks(); CALC_LOAD(avenrun[0], EXP_1, active_tasks); CALC_LOAD(avenrun[1], EXP_5, active_tasks); CALC_LOAD(avenrun[2], EXP_15, active_tasks); } } /* jiffies at the most recent update of wall time */ unsigned long wall_jiffies = INITIAL_JIFFIES; /* * This read-write spinlock protects us from races in SMP while * playing with xtime and avenrun. */ #ifndef ARCH_HAVE_XTIME_LOCK seqlock_t xtime_lock __cacheline_aligned_in_smp = SEQLOCK_UNLOCKED; EXPORT_SYMBOL(xtime_lock); #endif /* * This function runs timers and the timer-tq in bottom half context. */ static void run_timer_softirq(struct softirq_action *h) { tvec_base_t *base = __get_cpu_var(tvec_bases); hrtimer_run_queues(); if (time_after_eq(jiffies, base->timer_jiffies)) __run_timers(base); } /* * Called by the local, per-CPU timer interrupt on SMP. */ void run_local_timers(void) { raise_softirq(TIMER_SOFTIRQ); softlockup_tick(); } /* * Called by the timer interrupt. xtime_lock must already be taken * by the timer IRQ! */ static inline void update_times(void) { unsigned long ticks; ticks = jiffies - wall_jiffies; if (ticks) { wall_jiffies += ticks; update_wall_time(ticks); } calc_load(ticks); } /* * The 64-bit jiffies value is not atomic - you MUST NOT read it * without sampling the sequence number in xtime_lock. * jiffies is defined in the linker script... */ void do_timer(struct pt_regs *regs) { jiffies_64++; /* prevent loading jiffies before storing new jiffies_64 value. */ barrier(); update_times(); } #ifdef __ARCH_WANT_SYS_ALARM /* * For backwards compatibility? This can be done in libc so Alpha * and all newer ports shouldn't need it. */ asmlinkage unsigned long sys_alarm(unsigned int seconds) { return alarm_setitimer(seconds); } #endif #ifndef __alpha__ /* * The Alpha uses getxpid, getxuid, and getxgid instead. Maybe this * should be moved into arch/i386 instead? */ /** * sys_getpid - return the thread group id of the current process * * Note, despite the name, this returns the tgid not the pid. The tgid and * the pid are identical unless CLONE_THREAD was specified on clone() in * which case the tgid is the same in all threads of the same group. * * This is SMP safe as current->tgid does not change. */ asmlinkage long sys_getpid(void) { return current->tgid; } /* * Accessing ->group_leader->real_parent is not SMP-safe, it could * change from under us. However, rather than getting any lock * we can use an optimistic algorithm: get the parent * pid, and go back and check that the parent is still * the same. If it has changed (which is extremely unlikely * indeed), we just try again.. * * NOTE! This depends on the fact that even if we _do_ * get an old value of "parent", we can happily dereference * the pointer (it was and remains a dereferencable kernel pointer * no matter what): we just can't necessarily trust the result * until we know that the parent pointer is valid. * * NOTE2: ->group_leader never changes from under us. */ asmlinkage long sys_getppid(void) { int pid; struct task_struct *me = current; struct task_struct *parent; parent = me->group_leader->real_parent; for (;;) {