665
667
* If we return TIMER_RETRY, it's necessary to release the timer's lock
666
668
* and try again. (This happens when the timer is in the middle of firing.)
668
int posix_cpu_timer_set(struct k_itimer *timer, int flags,
669
struct itimerspec *new, struct itimerspec *old)
670
static int posix_cpu_timer_set(struct k_itimer *timer, int flags,
671
struct itimerspec *new, struct itimerspec *old)
671
673
struct task_struct *p = timer->it.cpu.task;
672
674
union cpu_time_count old_expires, new_expires, old_incr, val;
1484
int posix_cpu_nsleep(const clockid_t which_clock, int flags,
1485
struct timespec *rqtp, struct timespec __user *rmtp)
1486
static long posix_cpu_nsleep_restart(struct restart_block *restart_block);
1488
static int posix_cpu_nsleep(const clockid_t which_clock, int flags,
1489
struct timespec *rqtp, struct timespec __user *rmtp)
1487
1491
struct restart_block *restart_block =
1488
¤t_thread_info()->restart_block;
1492
¤t_thread_info()->restart_block;
1489
1493
struct itimerspec it;
1502
1506
if (error == -ERESTART_RESTARTBLOCK) {
1504
if (flags & TIMER_ABSTIME)
1508
if (flags & TIMER_ABSTIME)
1505
1509
return -ERESTARTNOHAND;
1507
* Report back to the user the time still remaining.
1509
if (rmtp != NULL && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
1511
* Report back to the user the time still remaining.
1513
if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
1510
1514
return -EFAULT;
1512
1516
restart_block->fn = posix_cpu_nsleep_restart;
1513
restart_block->arg0 = which_clock;
1514
restart_block->arg1 = (unsigned long) rmtp;
1515
restart_block->arg2 = rqtp->tv_sec;
1516
restart_block->arg3 = rqtp->tv_nsec;
1517
restart_block->nanosleep.index = which_clock;
1518
restart_block->nanosleep.rmtp = rmtp;
1519
restart_block->nanosleep.expires = timespec_to_ns(rqtp);
1521
long posix_cpu_nsleep_restart(struct restart_block *restart_block)
1524
static long posix_cpu_nsleep_restart(struct restart_block *restart_block)
1523
clockid_t which_clock = restart_block->arg0;
1524
struct timespec __user *rmtp;
1526
clockid_t which_clock = restart_block->nanosleep.index;
1525
1527
struct timespec t;
1526
1528
struct itimerspec it;
1529
rmtp = (struct timespec __user *) restart_block->arg1;
1530
t.tv_sec = restart_block->arg2;
1531
t.tv_nsec = restart_block->arg3;
1531
t = ns_to_timespec(restart_block->nanosleep.expires);
1533
restart_block->fn = do_no_restart_syscall;
1534
1533
error = do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t, &it);
1536
1535
if (error == -ERESTART_RESTARTBLOCK) {
1536
struct timespec __user *rmtp = restart_block->nanosleep.rmtp;
1538
* Report back to the user the time still remaining.
1540
if (rmtp != NULL && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
1538
* Report back to the user the time still remaining.
1540
if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
1541
1541
return -EFAULT;
1543
restart_block->fn = posix_cpu_nsleep_restart;
1544
restart_block->arg0 = which_clock;
1545
restart_block->arg1 = (unsigned long) rmtp;
1546
restart_block->arg2 = t.tv_sec;
1547
restart_block->arg3 = t.tv_nsec;
1543
restart_block->nanosleep.expires = timespec_to_ns(&t);
1554
1549
#define PROCESS_CLOCK MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED)
1555
1550
#define THREAD_CLOCK MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED)
1594
1589
timer->it_clock = THREAD_CLOCK;
1595
1590
return posix_cpu_timer_create(timer);
1597
static int thread_cpu_nsleep(const clockid_t which_clock, int flags,
1598
struct timespec *rqtp, struct timespec __user *rmtp)
1602
static long thread_cpu_nsleep_restart(struct restart_block *restart_block)
1593
struct k_clock clock_posix_cpu = {
1594
.clock_getres = posix_cpu_clock_getres,
1595
.clock_set = posix_cpu_clock_set,
1596
.clock_get = posix_cpu_clock_get,
1597
.timer_create = posix_cpu_timer_create,
1598
.nsleep = posix_cpu_nsleep,
1599
.nsleep_restart = posix_cpu_nsleep_restart,
1600
.timer_set = posix_cpu_timer_set,
1601
.timer_del = posix_cpu_timer_del,
1602
.timer_get = posix_cpu_timer_get,
1607
1605
static __init int init_posix_cpu_timers(void)
1609
1607
struct k_clock process = {
1610
.clock_getres = process_cpu_clock_getres,
1611
.clock_get = process_cpu_clock_get,
1612
.clock_set = do_posix_clock_nosettime,
1613
.timer_create = process_cpu_timer_create,
1614
.nsleep = process_cpu_nsleep,
1615
.nsleep_restart = process_cpu_nsleep_restart,
1608
.clock_getres = process_cpu_clock_getres,
1609
.clock_get = process_cpu_clock_get,
1610
.timer_create = process_cpu_timer_create,
1611
.nsleep = process_cpu_nsleep,
1612
.nsleep_restart = process_cpu_nsleep_restart,
1617
1614
struct k_clock thread = {
1618
.clock_getres = thread_cpu_clock_getres,
1619
.clock_get = thread_cpu_clock_get,
1620
.clock_set = do_posix_clock_nosettime,
1621
.timer_create = thread_cpu_timer_create,
1622
.nsleep = thread_cpu_nsleep,
1623
.nsleep_restart = thread_cpu_nsleep_restart,
1615
.clock_getres = thread_cpu_clock_getres,
1616
.clock_get = thread_cpu_clock_get,
1617
.timer_create = thread_cpu_timer_create,
1625
1619
struct timespec ts;
1627
register_posix_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
1628
register_posix_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
1621
posix_timers_register_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
1622
posix_timers_register_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
1630
1624
cputime_to_timespec(cputime_one_jiffy, &ts);
1631
1625
onecputick = ts.tv_nsec;