[ Pobierz całość w formacie PDF ]
.tv_sec = 0;t.tv_nsec = 0;return -ENOSYS;memcpy_tofs(interval, &t, sizeof(struct timespec));return 0;}static unsigned long timespectojiffies(struct timespec *value){unsigned long sec = (unsigned) value->tv_sec;long nsec = value->tv_nsec;if (sec > (LONG_MAX / HZ))return LONG_MAX;nsec += 1000000000L / HZ - 1;nsec /= 1000000000L / HZ;return HZ * sec + nsec;}static void jiffiestotimespec(unsigned long jiffies, struct timespec *value){value->tv_nsec = (jiffies % HZ) * (1000000000L / HZ);value->tv_sec = jiffies / HZ;return;}asmlinkage int sys_nanosleep(struct timespec *rqtp, struct timespec *rmtp){int error;struct timespec t;unsigned long expire;error = verify_area(VERIFY_READ, rqtp, sizeof(struct timespec));if (error)return error;memcpy_fromfs(&t, rqtp, sizeof(struct timespec));if (rmtp) {error = verify_area(VERIFY_WRITE, rmtp,sizeof(struct timespec));if (error)return error;}if (t.tv_nsec >= 1000000000L || t.tv_nsec < 0 || t.tv_sec < 0)return -EINVAL;if (t.tv_sec == 0 && t.tv_nsec <= 2000000L &¤t->policy != SCHED_OTHER) {/** Short delay requests up to 2 ms will be handled with* high precision by a busy wait for all real-time processes.*/udelay((t.tv_nsec + 999) / 1000);return 0;}expire = timespectojiffies(&t) + (t.tv_sec || t.tv_nsec) + jiffies;current->timeout = expire;current->state = TASK_INTERRUPTIBLE;schedule();if (expire > jiffies) {if (rmtp) {jiffiestotimespec(expire - jiffies -(expire > jiffies + 1), &t);memcpy_tofs(rmtp, &t, sizeof(struct timespec));}return -EINTR;}return 0;}static void show_task(int nr,struct task_struct * p){unsigned long free;static const char * stat_nam[] = { "R", "S", "D", "Z", "T", "W" };printk("%-8s %3d ", p->comm, (p == current) ? -nr : nr);if (((unsigned) p->state) < sizeof(stat_nam)/sizeof(char *))printk(stat_nam[p->state]);elseprintk(" ");#if ((~0UL) == 0xffffffff)if (p == current)printk(" current ");elseprintk(" %08lX ", thread_saved_pc(&p->tss));#elseif (p == current)printk(" current task ");elseprintk(" %016lx ", thread_saved_pc(&p->tss));#endiffor (free = 1; free < PAGE_SIZE/sizeof(long) ; free++) {if (((unsigned long *)p->kernel_stack_page)[free])break;}printk("%5lu %5d %6d ", free*sizeof(long), p->pid, p->p_pptr->pid);if (p->p_cptr)printk("%5d ", p->p_cptr->pid);elseprintk(" ");if (p->p_ysptr)printk("%7d", p->p_ysptr->pid);elseprintk(" ");if (p->p_osptr)printk(" %5d\n", p->p_osptr->pid);elseprintk("\n");}void show_state(void){int i;#if ((~0UL) == 0xffffffff)printk("\n"" free sibling\n");printk(" task PC stack pid father child younger older\n");#elseprintk("\n"" free sibling\n");printk(" task PC stack pid father child younger older\n");#endiffor (i=0 ; i<NR_TASKS ; i++)if (task[i])show_task(i,task[i]);}void sched_init(void){/** We have to do a little magic to get the first* process right in SMP mode.*/int cpu=smp_processor_id();#ifndef __SMP__current_set[cpu]=&init_task;#elseinit_task.processor=cpu;for(cpu = 0; cpu < NR_CPUS; cpu++)current_set[cpu] = &init_task;#endifinit_bh(TIMER_BH, timer_bh);init_bh(TQUEUE_BH, tqueue_bh);init_bh(IMMEDIATE_BH, immediate_bh);}
[ Pobierz całość w formacie PDF ]