1581 lines · 41.3 KB · C
RawDownload
		pid = parent->tgid;#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT){		struct task_struct *old = parent; 		/*		 * Make sure we read the pid before re-reading the		 * parent pointer:		 */		smp_rmb();		parent = me->group_leader->real_parent;		if (old != parent)			continue;}#endif		break;	}	return pid;} asmlinkage long sys_getuid(void){	/* Only we change this so SMP safe */	return current->uid;} asmlinkage long sys_geteuid(void){	/* Only we change this so SMP safe */	return current->euid;} asmlinkage long sys_getgid(void){	/* Only we change this so SMP safe */	return current->gid;} asmlinkage long sys_getegid(void){	/* Only we change this so SMP safe */	return  current->egid;} #endif static void process_timeout(unsigned long __data){	wake_up_process((task_t *)__data);} /** * schedule_timeout - sleep until timeout * @timeout: timeout value in jiffies * * Make the current task sleep until @timeout jiffies have * elapsed. The routine will return immediately unless * the current task state has been set (see set_current_state()). * * You can set the task state as follows - * * %TASK_UNINTERRUPTIBLE - at least @timeout jiffies are guaranteed to * pass before the routine returns. The routine will return 0 * * %TASK_INTERRUPTIBLE - the routine may return early if a signal is * delivered to the current task. In this case the remaining time * in jiffies will be returned, or 0 if the timer expired in time * * The current task state is guaranteed to be TASK_RUNNING when this * routine returns. * * Specifying a @timeout value of %MAX_SCHEDULE_TIMEOUT will schedule * the CPU away without a bound on the timeout. In this case the return * value will be %MAX_SCHEDULE_TIMEOUT. * * In all cases the return value is guaranteed to be non-negative. */fastcall signed long __sched schedule_timeout(signed long timeout){	struct timer_list timer;	unsigned long expire; 	switch (timeout)	{	case MAX_SCHEDULE_TIMEOUT:		/*		 * These two special cases are useful to be comfortable		 * in the caller. Nothing more. We could take		 * MAX_SCHEDULE_TIMEOUT from one of the negative value		 * but I' d like to return a valid offset (>=0) to allow		 * the caller to do everything it want with the retval.		 */		schedule();		goto out;	default:		/*		 * Another bit of PARANOID. Note that the retval will be		 * 0 since no piece of kernel is supposed to do a check		 * for a negative retval of schedule_timeout() (since it		 * should never happens anyway). You just have the printk()		 * that will tell you if something is gone wrong and where.		 */		if (timeout < 0)		{			printk(KERN_ERR "schedule_timeout: wrong timeout "				"value %lx from %p\n", timeout,				__builtin_return_address(0));			current->state = TASK_RUNNING;			goto out;		}	} 	expire = timeout + jiffies; 	setup_timer(&timer, process_timeout, (unsigned long)current);	__mod_timer(&timer, expire);	schedule();	del_singleshot_timer_sync(&timer); 	timeout = expire - jiffies;  out:	return timeout < 0 ? 0 : timeout;}EXPORT_SYMBOL(schedule_timeout); /* * We can use __set_current_state() here because schedule_timeout() calls * schedule() unconditionally. */signed long __sched schedule_timeout_interruptible(signed long timeout){	__set_current_state(TASK_INTERRUPTIBLE);	return schedule_timeout(timeout);}EXPORT_SYMBOL(schedule_timeout_interruptible); signed long __sched schedule_timeout_uninterruptible(signed long timeout){	__set_current_state(TASK_UNINTERRUPTIBLE);	return schedule_timeout(timeout);}EXPORT_SYMBOL(schedule_timeout_uninterruptible); /* Thread ID - the internal kernel "pid" */asmlinkage long sys_gettid(void){	return current->pid;} /* * sys_sysinfo - fill in sysinfo struct */ asmlinkage long sys_sysinfo(struct sysinfo __user *info){	struct sysinfo val;	unsigned long mem_total, sav_total;	unsigned int mem_unit, bitcount;	unsigned long seq; 	memset((char *)&val, 0, sizeof(struct sysinfo)); 	do {		struct timespec tp;		seq = read_seqbegin(&xtime_lock); 		/*		 * This is annoying.  The below is the same thing		 * posix_get_clock_monotonic() does, but it wants to		 * take the lock which we want to cover the loads stuff		 * too.		 */ 		getnstimeofday(&tp);		tp.tv_sec += wall_to_monotonic.tv_sec;		tp.tv_nsec += wall_to_monotonic.tv_nsec;		if (tp.tv_nsec - NSEC_PER_SEC >= 0) {			tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;			tp.tv_sec++;		}		val.uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0); 		val.loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);		val.loads[1] = avenrun[1] << (SI_LOAD_SHIFT - FSHIFT);		val.loads[2] = avenrun[2] << (SI_LOAD_SHIFT - FSHIFT); 		val.procs = nr_threads;	} while (read_seqretry(&xtime_lock, seq)); 	si_meminfo(&val);	si_swapinfo(&val); 	/*	 * If the sum of all the available memory (i.e. ram + swap)	 * is less than can be stored in a 32 bit unsigned long then	 * we can be binary compatible with 2.2.x kernels.  If not,	 * well, in that case 2.2.x was broken anyways...	 *	 *  -Erik Andersen <andersee@debian.org>	 */ 	mem_total = val.totalram + val.totalswap;	if (mem_total < val.totalram || mem_total < val.totalswap)		goto out;	bitcount = 0;	mem_unit = val.mem_unit;	while (mem_unit > 1) {		bitcount++;		mem_unit >>= 1;		sav_total = mem_total;		mem_total <<= 1;		if (mem_total < sav_total)			goto out;	} 	/*	 * If mem_total did not overflow, multiply all memory values by	 * val.mem_unit and set it to 1.  This leaves things compatible	 * with 2.2.x, and also retains compatibility with earlier 2.4.x	 * kernels...	 */ 	val.mem_unit = 1;	val.totalram <<= bitcount;	val.freeram <<= bitcount;	val.sharedram <<= bitcount;	val.bufferram <<= bitcount;	val.totalswap <<= bitcount;	val.freeswap <<= bitcount;	val.totalhigh <<= bitcount;	val.freehigh <<= bitcount;  out:	if (copy_to_user(info, &val, sizeof(struct sysinfo)))		return -EFAULT; 	return 0;} static int __devinit init_timers_cpu(int cpu){	int j;	tvec_base_t *base;	static char __devinitdata tvec_base_done[NR_CPUS]; 	if (!tvec_base_done[cpu]) {		static char boot_done; 		if (boot_done) {			/*			 * The APs use this path later in boot			 */			base = kmalloc_node(sizeof(*base), GFP_KERNEL,						cpu_to_node(cpu));			if (!base)				return -ENOMEM;			memset(base, 0, sizeof(*base));			per_cpu(tvec_bases, cpu) = base;		} else {			/*			 * This is for the boot CPU - we use compile-time			 * static initialisation because per-cpu memory isn't			 * ready yet and because the memory allocators are not			 * initialised either.			 */			boot_done = 1;			base = &boot_tvec_bases;		}		tvec_base_done[cpu] = 1;	} else {		base = per_cpu(tvec_bases, cpu);	} 	spin_lock_init(&base->lock);	for (j = 0; j < TVN_SIZE; j++) {		INIT_LIST_HEAD(base->tv5.vec + j);		INIT_LIST_HEAD(base->tv4.vec + j);		INIT_LIST_HEAD(base->tv3.vec + j);		INIT_LIST_HEAD(base->tv2.vec + j);	}	for (j = 0; j < TVR_SIZE; j++)		INIT_LIST_HEAD(base->tv1.vec + j); 	base->timer_jiffies = jiffies;	return 0;} #ifdef CONFIG_HOTPLUG_CPUstatic void migrate_timer_list(tvec_base_t *new_base, struct list_head *head){	struct timer_list *timer; 	while (!list_empty(head)) {		timer = list_entry(head->next, struct timer_list, entry);		detach_timer(timer, 0);		timer->base = new_base;		internal_add_timer(new_base, timer);	}} static void __devinit migrate_timers(int cpu){	tvec_base_t *old_base;	tvec_base_t *new_base;	int i; 	BUG_ON(cpu_online(cpu));	old_base = per_cpu(tvec_bases, cpu);	new_base = get_cpu_var(tvec_bases); 	local_irq_disable();	spin_lock(&new_base->lock);	spin_lock(&old_base->lock); 	BUG_ON(old_base->running_timer); 	for (i = 0; i < TVR_SIZE; i++)		migrate_timer_list(new_base, old_base->tv1.vec + i);	for (i = 0; i < TVN_SIZE; i++) {		migrate_timer_list(new_base, old_base->tv2.vec + i);		migrate_timer_list(new_base, old_base->tv3.vec + i);		migrate_timer_list(new_base, old_base->tv4.vec + i);		migrate_timer_list(new_base, old_base->tv5.vec + i);	} 	spin_unlock(&old_base->lock);	spin_unlock(&new_base->lock);	local_irq_enable();	put_cpu_var(tvec_bases);}#endif /* CONFIG_HOTPLUG_CPU */ static int timer_cpu_notify(struct notifier_block *self,				unsigned long action, void *hcpu){	long cpu = (long)hcpu;	switch(action) {	case CPU_UP_PREPARE:		if (init_timers_cpu(cpu) < 0)			return NOTIFY_BAD;		break;#ifdef CONFIG_HOTPLUG_CPU	case CPU_DEAD:		migrate_timers(cpu);		break;#endif	default:		break;	}	return NOTIFY_OK;} static struct notifier_block timers_nb = {	.notifier_call	= timer_cpu_notify,};  void __init init_timers(void){	timer_cpu_notify(&timers_nb, (unsigned long)CPU_UP_PREPARE,				(void *)(long)smp_processor_id());	register_cpu_notifier(&timers_nb);	open_softirq(TIMER_SOFTIRQ, run_timer_softirq, NULL);} #ifdef CONFIG_TIME_INTERPOLATION struct time_interpolator *time_interpolator __read_mostly;static struct time_interpolator *time_interpolator_list __read_mostly;static DEFINE_SPINLOCK(time_interpolator_lock); static inline u64 time_interpolator_get_cycles(unsigned int src){	unsigned long (*x)(void); 	switch (src)	{		case TIME_SOURCE_FUNCTION:			x = time_interpolator->addr;			return x(); 		case TIME_SOURCE_MMIO64	:			return readq_relaxed((void __iomem *)time_interpolator->addr); 		case TIME_SOURCE_MMIO32	:			return readl_relaxed((void __iomem *)time_interpolator->addr); 		default: return get_cycles();	}} static inline u64 time_interpolator_get_counter(int writelock){	unsigned int src = time_interpolator->source; 	if (time_interpolator->jitter)	{		u64 lcycle;		u64 now; 		do {			lcycle = time_interpolator->last_cycle;			now = time_interpolator_get_cycles(src);			if (lcycle && time_after(lcycle, now))				return lcycle; 			/* When holding the xtime write lock, there's no need			 * to add the overhead of the cmpxchg.  Readers are			 * force to retry until the write lock is released.			 */			if (writelock) {				time_interpolator->last_cycle = now;				return now;			}			/* Keep track of the last timer value returned. The use of cmpxchg here			 * will cause contention in an SMP environment.			 */		} while (unlikely(cmpxchg(&time_interpolator->last_cycle, lcycle, now) != lcycle));		return now;	}	else		return time_interpolator_get_cycles(src);} void time_interpolator_reset(void){	time_interpolator->offset = 0;	time_interpolator->last_counter = time_interpolator_get_counter(1);} #define GET_TI_NSECS(count,i) (((((count) - i->last_counter) & (i)->mask) * (i)->nsec_per_cyc) >> (i)->shift) unsigned long time_interpolator_get_offset(void){	/* If we do not have a time interpolator set up then just return zero */	if (!time_interpolator)		return 0; 	return time_interpolator->offset +		GET_TI_NSECS(time_interpolator_get_counter(0), time_interpolator);} #define INTERPOLATOR_ADJUST 65536#define INTERPOLATOR_MAX_SKIP 10*INTERPOLATOR_ADJUST static void time_interpolator_update(long delta_nsec){	u64 counter;	unsigned long offset; 	/* If there is no time interpolator set up then do nothing */	if (!time_interpolator)		return; 	/*	 * The interpolator compensates for late ticks by accumulating the late	 * time in time_interpolator->offset. A tick earlier than expected will	 * lead to a reset of the offset and a corresponding jump of the clock	 * forward. Again this only works if the interpolator clock is running	 * slightly slower than the regular clock and the tuning logic insures	 * that.	 */ 	counter = time_interpolator_get_counter(1);	offset = time_interpolator->offset +			GET_TI_NSECS(counter, time_interpolator); 	if (delta_nsec < 0 || (unsigned long) delta_nsec < offset)		time_interpolator->offset = offset - delta_nsec;	else {		time_interpolator->skips++;		time_interpolator->ns_skipped += delta_nsec - offset;		time_interpolator->offset = 0;	}	time_interpolator->last_counter = counter; 	/* Tuning logic for time interpolator invoked every minute or so.	 * Decrease interpolator clock speed if no skips occurred and an offset is carried.	 * Increase interpolator clock speed if we skip too much time.	 */	if (jiffies % INTERPOLATOR_ADJUST == 0)	{		if (time_interpolator->skips == 0 && time_interpolator->offset > tick_nsec)			time_interpolator->nsec_per_cyc--;		if (time_interpolator->ns_skipped > INTERPOLATOR_MAX_SKIP && time_interpolator->offset == 0)			time_interpolator->nsec_per_cyc++;		time_interpolator->skips = 0;		time_interpolator->ns_skipped = 0;	}} static inline intis_better_time_interpolator(struct time_interpolator *new){	if (!time_interpolator)		return 1;	return new->frequency > 2*time_interpolator->frequency ||	    (unsigned long)new->drift < (unsigned long)time_interpolator->drift;} 

Lines 1001–1500 of 1581. Previous lines