1850 lines · 49.4 KB · C
RawDownload
		 * 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\n", timeout);			dump_stack();			current->state = TASK_RUNNING;			goto out;		}	} 	expire = timeout + jiffies; 	setup_timer_on_stack(&timer, process_timeout, (unsigned long)current);	__mod_timer(&timer, expire, false, TIMER_NOT_PINNED);	schedule();	del_singleshot_timer_sync(&timer); 	/* Remove the timer from the object tracker */	destroy_timer_on_stack(&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_killable(signed long timeout){	__set_current_state(TASK_KILLABLE);	return schedule_timeout(timeout);}EXPORT_SYMBOL(schedule_timeout_killable); 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" */SYSCALL_DEFINE0(gettid){	return task_pid_vnr(current);} /** * do_sysinfo - fill in sysinfo struct * @info: pointer to buffer to fill */int do_sysinfo(struct sysinfo *info){	unsigned long mem_total, sav_total;	unsigned int mem_unit, bitcount;	struct timespec tp; 	memset(info, 0, sizeof(struct sysinfo)); 	ktime_get_ts(&tp);	monotonic_to_bootbased(&tp);	info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0); 	get_avenrun(info->loads, 0, SI_LOAD_SHIFT - FSHIFT); 	info->procs = nr_threads; 	si_meminfo(info);	si_swapinfo(info); 	/*	 * 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 = info->totalram + info->totalswap;	if (mem_total < info->totalram || mem_total < info->totalswap)		goto out;	bitcount = 0;	mem_unit = info->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	 * info->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...	 */ 	info->mem_unit = 1;	info->totalram <<= bitcount;	info->freeram <<= bitcount;	info->sharedram <<= bitcount;	info->bufferram <<= bitcount;	info->totalswap <<= bitcount;	info->freeswap <<= bitcount;	info->totalhigh <<= bitcount;	info->freehigh <<= bitcount; out:	return 0;} SYSCALL_DEFINE1(sysinfo, struct sysinfo __user *, info){	struct sysinfo val; 	do_sysinfo(&val); 	if (copy_to_user(info, &val, sizeof(struct sysinfo)))		return -EFAULT; 	return 0;} static int __cpuinit init_timers_cpu(int cpu){	int j;	struct tvec_base *base;	static char __cpuinitdata 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 | __GFP_ZERO,						cpu_to_node(cpu));			if (!base)				return -ENOMEM; 			/* Make sure that tvec_base is 2 byte aligned */			if (tbase_get_deferrable(base)) {				WARN_ON(1);				kfree(base);				return -ENOMEM;			}			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;	base->next_timer = base->timer_jiffies;	return 0;} #ifdef CONFIG_HOTPLUG_CPUstatic void migrate_timer_list(struct tvec_base *new_base, struct list_head *head){	struct timer_list *timer; 	while (!list_empty(head)) {		timer = list_first_entry(head, struct timer_list, entry);		detach_timer(timer, 0);		timer_set_base(timer, new_base);		if (time_before(timer->expires, new_base->next_timer) &&		    !tbase_get_deferrable(timer->base))			new_base->next_timer = timer->expires;		internal_add_timer(new_base, timer);	}} static void __cpuinit migrate_timers(int cpu){	struct tvec_base *old_base;	struct tvec_base *new_base;	int i; 	BUG_ON(cpu_online(cpu));	old_base = per_cpu(tvec_bases, cpu);	new_base = get_cpu_var(tvec_bases);	/*	 * The caller is globally serialized and nobody else	 * takes two locks at once, deadlock is not possible.	 */	spin_lock_irq(&new_base->lock);	spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); 	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_irq(&new_base->lock);	put_cpu_var(tvec_bases);}#endif /* CONFIG_HOTPLUG_CPU */ static int __cpuinit timer_cpu_notify(struct notifier_block *self,				unsigned long action, void *hcpu){	long cpu = (long)hcpu;	int err; 	switch(action) {	case CPU_UP_PREPARE:	case CPU_UP_PREPARE_FROZEN:		err = init_timers_cpu(cpu);		if (err < 0)			return notifier_from_errno(err);		break;#ifdef CONFIG_HOTPLUG_CPU	case CPU_DEAD:	case CPU_DEAD_FROZEN:		migrate_timers(cpu);		break;#endif	default:		break;	}	return NOTIFY_OK;} static struct notifier_block __cpuinitdata timers_nb = {	.notifier_call	= timer_cpu_notify,};  void __init init_timers(void){	int err = timer_cpu_notify(&timers_nb, (unsigned long)CPU_UP_PREPARE,				(void *)(long)smp_processor_id()); 	init_timer_stats(); 	BUG_ON(err != NOTIFY_OK);	register_cpu_notifier(&timers_nb);	open_softirq(TIMER_SOFTIRQ, run_timer_softirq);} /** * msleep - sleep safely even with waitqueue interruptions * @msecs: Time in milliseconds to sleep for */void msleep(unsigned int msecs){	unsigned long timeout = msecs_to_jiffies(msecs) + 1; 	while (timeout)		timeout = schedule_timeout_uninterruptible(timeout);} EXPORT_SYMBOL(msleep); /** * msleep_interruptible - sleep waiting for signals * @msecs: Time in milliseconds to sleep for */unsigned long msleep_interruptible(unsigned int msecs){	unsigned long timeout = msecs_to_jiffies(msecs) + 1; 	while (timeout && !signal_pending(current))		timeout = schedule_timeout_interruptible(timeout);	return jiffies_to_msecs(timeout);} EXPORT_SYMBOL(msleep_interruptible); static int __sched do_usleep_range(unsigned long min, unsigned long max){	ktime_t kmin;	unsigned long delta; 	kmin = ktime_set(0, min * NSEC_PER_USEC);	delta = (max - min) * NSEC_PER_USEC;	return schedule_hrtimeout_range(&kmin, delta, HRTIMER_MODE_REL);} /** * usleep_range - Drop in replacement for udelay where wakeup is flexible * @min: Minimum time in usecs to sleep * @max: Maximum time in usecs to sleep */void usleep_range(unsigned long min, unsigned long max){	__set_current_state(TASK_UNINTERRUPTIBLE);	do_usleep_range(min, max);}EXPORT_SYMBOL(usleep_range);

Lines 1501–1850 of 1850. Previous lines