ia64/linux-2.6.18-xen.hg

annotate kernel/posix-cpu-timers.c @ 0:831230e53067

Import 2.6.18 from kernel.org tarball.
author Ian Campbell <ian.campbell@xensource.com>
date Wed Apr 11 14:15:44 2007 +0100 (2007-04-11)
parents
children 3e8752eb6d9c
rev   line source
ian@0 1 /*
ian@0 2 * Implement CPU time clocks for the POSIX clock interface.
ian@0 3 */
ian@0 4
ian@0 5 #include <linux/sched.h>
ian@0 6 #include <linux/posix-timers.h>
ian@0 7 #include <asm/uaccess.h>
ian@0 8 #include <linux/errno.h>
ian@0 9
ian@0 10 static int check_clock(const clockid_t which_clock)
ian@0 11 {
ian@0 12 int error = 0;
ian@0 13 struct task_struct *p;
ian@0 14 const pid_t pid = CPUCLOCK_PID(which_clock);
ian@0 15
ian@0 16 if (CPUCLOCK_WHICH(which_clock) >= CPUCLOCK_MAX)
ian@0 17 return -EINVAL;
ian@0 18
ian@0 19 if (pid == 0)
ian@0 20 return 0;
ian@0 21
ian@0 22 read_lock(&tasklist_lock);
ian@0 23 p = find_task_by_pid(pid);
ian@0 24 if (!p || (CPUCLOCK_PERTHREAD(which_clock) ?
ian@0 25 p->tgid != current->tgid : p->tgid != pid)) {
ian@0 26 error = -EINVAL;
ian@0 27 }
ian@0 28 read_unlock(&tasklist_lock);
ian@0 29
ian@0 30 return error;
ian@0 31 }
ian@0 32
ian@0 33 static inline union cpu_time_count
ian@0 34 timespec_to_sample(const clockid_t which_clock, const struct timespec *tp)
ian@0 35 {
ian@0 36 union cpu_time_count ret;
ian@0 37 ret.sched = 0; /* high half always zero when .cpu used */
ian@0 38 if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED) {
ian@0 39 ret.sched = (unsigned long long)tp->tv_sec * NSEC_PER_SEC + tp->tv_nsec;
ian@0 40 } else {
ian@0 41 ret.cpu = timespec_to_cputime(tp);
ian@0 42 }
ian@0 43 return ret;
ian@0 44 }
ian@0 45
ian@0 46 static void sample_to_timespec(const clockid_t which_clock,
ian@0 47 union cpu_time_count cpu,
ian@0 48 struct timespec *tp)
ian@0 49 {
ian@0 50 if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED) {
ian@0 51 tp->tv_sec = div_long_long_rem(cpu.sched,
ian@0 52 NSEC_PER_SEC, &tp->tv_nsec);
ian@0 53 } else {
ian@0 54 cputime_to_timespec(cpu.cpu, tp);
ian@0 55 }
ian@0 56 }
ian@0 57
ian@0 58 static inline int cpu_time_before(const clockid_t which_clock,
ian@0 59 union cpu_time_count now,
ian@0 60 union cpu_time_count then)
ian@0 61 {
ian@0 62 if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED) {
ian@0 63 return now.sched < then.sched;
ian@0 64 } else {
ian@0 65 return cputime_lt(now.cpu, then.cpu);
ian@0 66 }
ian@0 67 }
ian@0 68 static inline void cpu_time_add(const clockid_t which_clock,
ian@0 69 union cpu_time_count *acc,
ian@0 70 union cpu_time_count val)
ian@0 71 {
ian@0 72 if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED) {
ian@0 73 acc->sched += val.sched;
ian@0 74 } else {
ian@0 75 acc->cpu = cputime_add(acc->cpu, val.cpu);
ian@0 76 }
ian@0 77 }
ian@0 78 static inline union cpu_time_count cpu_time_sub(const clockid_t which_clock,
ian@0 79 union cpu_time_count a,
ian@0 80 union cpu_time_count b)
ian@0 81 {
ian@0 82 if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED) {
ian@0 83 a.sched -= b.sched;
ian@0 84 } else {
ian@0 85 a.cpu = cputime_sub(a.cpu, b.cpu);
ian@0 86 }
ian@0 87 return a;
ian@0 88 }
ian@0 89
ian@0 90 /*
ian@0 91 * Update expiry time from increment, and increase overrun count,
ian@0 92 * given the current clock sample.
ian@0 93 */
ian@0 94 static void bump_cpu_timer(struct k_itimer *timer,
ian@0 95 union cpu_time_count now)
ian@0 96 {
ian@0 97 int i;
ian@0 98
ian@0 99 if (timer->it.cpu.incr.sched == 0)
ian@0 100 return;
ian@0 101
ian@0 102 if (CPUCLOCK_WHICH(timer->it_clock) == CPUCLOCK_SCHED) {
ian@0 103 unsigned long long delta, incr;
ian@0 104
ian@0 105 if (now.sched < timer->it.cpu.expires.sched)
ian@0 106 return;
ian@0 107 incr = timer->it.cpu.incr.sched;
ian@0 108 delta = now.sched + incr - timer->it.cpu.expires.sched;
ian@0 109 /* Don't use (incr*2 < delta), incr*2 might overflow. */
ian@0 110 for (i = 0; incr < delta - incr; i++)
ian@0 111 incr = incr << 1;
ian@0 112 for (; i >= 0; incr >>= 1, i--) {
ian@0 113 if (delta < incr)
ian@0 114 continue;
ian@0 115 timer->it.cpu.expires.sched += incr;
ian@0 116 timer->it_overrun += 1 << i;
ian@0 117 delta -= incr;
ian@0 118 }
ian@0 119 } else {
ian@0 120 cputime_t delta, incr;
ian@0 121
ian@0 122 if (cputime_lt(now.cpu, timer->it.cpu.expires.cpu))
ian@0 123 return;
ian@0 124 incr = timer->it.cpu.incr.cpu;
ian@0 125 delta = cputime_sub(cputime_add(now.cpu, incr),
ian@0 126 timer->it.cpu.expires.cpu);
ian@0 127 /* Don't use (incr*2 < delta), incr*2 might overflow. */
ian@0 128 for (i = 0; cputime_lt(incr, cputime_sub(delta, incr)); i++)
ian@0 129 incr = cputime_add(incr, incr);
ian@0 130 for (; i >= 0; incr = cputime_halve(incr), i--) {
ian@0 131 if (cputime_lt(delta, incr))
ian@0 132 continue;
ian@0 133 timer->it.cpu.expires.cpu =
ian@0 134 cputime_add(timer->it.cpu.expires.cpu, incr);
ian@0 135 timer->it_overrun += 1 << i;
ian@0 136 delta = cputime_sub(delta, incr);
ian@0 137 }
ian@0 138 }
ian@0 139 }
ian@0 140
ian@0 141 static inline cputime_t prof_ticks(struct task_struct *p)
ian@0 142 {
ian@0 143 return cputime_add(p->utime, p->stime);
ian@0 144 }
ian@0 145 static inline cputime_t virt_ticks(struct task_struct *p)
ian@0 146 {
ian@0 147 return p->utime;
ian@0 148 }
ian@0 149 static inline unsigned long long sched_ns(struct task_struct *p)
ian@0 150 {
ian@0 151 return (p == current) ? current_sched_time(p) : p->sched_time;
ian@0 152 }
ian@0 153
ian@0 154 int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
ian@0 155 {
ian@0 156 int error = check_clock(which_clock);
ian@0 157 if (!error) {
ian@0 158 tp->tv_sec = 0;
ian@0 159 tp->tv_nsec = ((NSEC_PER_SEC + HZ - 1) / HZ);
ian@0 160 if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED) {
ian@0 161 /*
ian@0 162 * If sched_clock is using a cycle counter, we
ian@0 163 * don't have any idea of its true resolution
ian@0 164 * exported, but it is much more than 1s/HZ.
ian@0 165 */
ian@0 166 tp->tv_nsec = 1;
ian@0 167 }
ian@0 168 }
ian@0 169 return error;
ian@0 170 }
ian@0 171
ian@0 172 int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
ian@0 173 {
ian@0 174 /*
ian@0 175 * You can never reset a CPU clock, but we check for other errors
ian@0 176 * in the call before failing with EPERM.
ian@0 177 */
ian@0 178 int error = check_clock(which_clock);
ian@0 179 if (error == 0) {
ian@0 180 error = -EPERM;
ian@0 181 }
ian@0 182 return error;
ian@0 183 }
ian@0 184
ian@0 185
ian@0 186 /*
ian@0 187 * Sample a per-thread clock for the given task.
ian@0 188 */
ian@0 189 static int cpu_clock_sample(const clockid_t which_clock, struct task_struct *p,
ian@0 190 union cpu_time_count *cpu)
ian@0 191 {
ian@0 192 switch (CPUCLOCK_WHICH(which_clock)) {
ian@0 193 default:
ian@0 194 return -EINVAL;
ian@0 195 case CPUCLOCK_PROF:
ian@0 196 cpu->cpu = prof_ticks(p);
ian@0 197 break;
ian@0 198 case CPUCLOCK_VIRT:
ian@0 199 cpu->cpu = virt_ticks(p);
ian@0 200 break;
ian@0 201 case CPUCLOCK_SCHED:
ian@0 202 cpu->sched = sched_ns(p);
ian@0 203 break;
ian@0 204 }
ian@0 205 return 0;
ian@0 206 }
ian@0 207
ian@0 208 /*
ian@0 209 * Sample a process (thread group) clock for the given group_leader task.
ian@0 210 * Must be called with tasklist_lock held for reading.
ian@0 211 * Must be called with tasklist_lock held for reading, and p->sighand->siglock.
ian@0 212 */
ian@0 213 static int cpu_clock_sample_group_locked(unsigned int clock_idx,
ian@0 214 struct task_struct *p,
ian@0 215 union cpu_time_count *cpu)
ian@0 216 {
ian@0 217 struct task_struct *t = p;
ian@0 218 switch (clock_idx) {
ian@0 219 default:
ian@0 220 return -EINVAL;
ian@0 221 case CPUCLOCK_PROF:
ian@0 222 cpu->cpu = cputime_add(p->signal->utime, p->signal->stime);
ian@0 223 do {
ian@0 224 cpu->cpu = cputime_add(cpu->cpu, prof_ticks(t));
ian@0 225 t = next_thread(t);
ian@0 226 } while (t != p);
ian@0 227 break;
ian@0 228 case CPUCLOCK_VIRT:
ian@0 229 cpu->cpu = p->signal->utime;
ian@0 230 do {
ian@0 231 cpu->cpu = cputime_add(cpu->cpu, virt_ticks(t));
ian@0 232 t = next_thread(t);
ian@0 233 } while (t != p);
ian@0 234 break;
ian@0 235 case CPUCLOCK_SCHED:
ian@0 236 cpu->sched = p->signal->sched_time;
ian@0 237 /* Add in each other live thread. */
ian@0 238 while ((t = next_thread(t)) != p) {
ian@0 239 cpu->sched += t->sched_time;
ian@0 240 }
ian@0 241 cpu->sched += sched_ns(p);
ian@0 242 break;
ian@0 243 }
ian@0 244 return 0;
ian@0 245 }
ian@0 246
ian@0 247 /*
ian@0 248 * Sample a process (thread group) clock for the given group_leader task.
ian@0 249 * Must be called with tasklist_lock held for reading.
ian@0 250 */
ian@0 251 static int cpu_clock_sample_group(const clockid_t which_clock,
ian@0 252 struct task_struct *p,
ian@0 253 union cpu_time_count *cpu)
ian@0 254 {
ian@0 255 int ret;
ian@0 256 unsigned long flags;
ian@0 257 spin_lock_irqsave(&p->sighand->siglock, flags);
ian@0 258 ret = cpu_clock_sample_group_locked(CPUCLOCK_WHICH(which_clock), p,
ian@0 259 cpu);
ian@0 260 spin_unlock_irqrestore(&p->sighand->siglock, flags);
ian@0 261 return ret;
ian@0 262 }
ian@0 263
ian@0 264
ian@0 265 int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
ian@0 266 {
ian@0 267 const pid_t pid = CPUCLOCK_PID(which_clock);
ian@0 268 int error = -EINVAL;
ian@0 269 union cpu_time_count rtn;
ian@0 270
ian@0 271 if (pid == 0) {
ian@0 272 /*
ian@0 273 * Special case constant value for our own clocks.
ian@0 274 * We don't have to do any lookup to find ourselves.
ian@0 275 */
ian@0 276 if (CPUCLOCK_PERTHREAD(which_clock)) {
ian@0 277 /*
ian@0 278 * Sampling just ourselves we can do with no locking.
ian@0 279 */
ian@0 280 error = cpu_clock_sample(which_clock,
ian@0 281 current, &rtn);
ian@0 282 } else {
ian@0 283 read_lock(&tasklist_lock);
ian@0 284 error = cpu_clock_sample_group(which_clock,
ian@0 285 current, &rtn);
ian@0 286 read_unlock(&tasklist_lock);
ian@0 287 }
ian@0 288 } else {
ian@0 289 /*
ian@0 290 * Find the given PID, and validate that the caller
ian@0 291 * should be able to see it.
ian@0 292 */
ian@0 293 struct task_struct *p;
ian@0 294 read_lock(&tasklist_lock);
ian@0 295 p = find_task_by_pid(pid);
ian@0 296 if (p) {
ian@0 297 if (CPUCLOCK_PERTHREAD(which_clock)) {
ian@0 298 if (p->tgid == current->tgid) {
ian@0 299 error = cpu_clock_sample(which_clock,
ian@0 300 p, &rtn);
ian@0 301 }
ian@0 302 } else if (p->tgid == pid && p->signal) {
ian@0 303 error = cpu_clock_sample_group(which_clock,
ian@0 304 p, &rtn);
ian@0 305 }
ian@0 306 }
ian@0 307 read_unlock(&tasklist_lock);
ian@0 308 }
ian@0 309
ian@0 310 if (error)
ian@0 311 return error;
ian@0 312 sample_to_timespec(which_clock, rtn, tp);
ian@0 313 return 0;
ian@0 314 }
ian@0 315
ian@0 316
ian@0 317 /*
ian@0 318 * Validate the clockid_t for a new CPU-clock timer, and initialize the timer.
ian@0 319 * This is called from sys_timer_create with the new timer already locked.
ian@0 320 */
ian@0 321 int posix_cpu_timer_create(struct k_itimer *new_timer)
ian@0 322 {
ian@0 323 int ret = 0;
ian@0 324 const pid_t pid = CPUCLOCK_PID(new_timer->it_clock);
ian@0 325 struct task_struct *p;
ian@0 326
ian@0 327 if (CPUCLOCK_WHICH(new_timer->it_clock) >= CPUCLOCK_MAX)
ian@0 328 return -EINVAL;
ian@0 329
ian@0 330 INIT_LIST_HEAD(&new_timer->it.cpu.entry);
ian@0 331 new_timer->it.cpu.incr.sched = 0;
ian@0 332 new_timer->it.cpu.expires.sched = 0;
ian@0 333
ian@0 334 read_lock(&tasklist_lock);
ian@0 335 if (CPUCLOCK_PERTHREAD(new_timer->it_clock)) {
ian@0 336 if (pid == 0) {
ian@0 337 p = current;
ian@0 338 } else {
ian@0 339 p = find_task_by_pid(pid);
ian@0 340 if (p && p->tgid != current->tgid)
ian@0 341 p = NULL;
ian@0 342 }
ian@0 343 } else {
ian@0 344 if (pid == 0) {
ian@0 345 p = current->group_leader;
ian@0 346 } else {
ian@0 347 p = find_task_by_pid(pid);
ian@0 348 if (p && p->tgid != pid)
ian@0 349 p = NULL;
ian@0 350 }
ian@0 351 }
ian@0 352 new_timer->it.cpu.task = p;
ian@0 353 if (p) {
ian@0 354 get_task_struct(p);
ian@0 355 } else {
ian@0 356 ret = -EINVAL;
ian@0 357 }
ian@0 358 read_unlock(&tasklist_lock);
ian@0 359
ian@0 360 return ret;
ian@0 361 }
ian@0 362
ian@0 363 /*
ian@0 364 * Clean up a CPU-clock timer that is about to be destroyed.
ian@0 365 * This is called from timer deletion with the timer already locked.
ian@0 366 * If we return TIMER_RETRY, it's necessary to release the timer's lock
ian@0 367 * and try again. (This happens when the timer is in the middle of firing.)
ian@0 368 */
ian@0 369 int posix_cpu_timer_del(struct k_itimer *timer)
ian@0 370 {
ian@0 371 struct task_struct *p = timer->it.cpu.task;
ian@0 372 int ret = 0;
ian@0 373
ian@0 374 if (likely(p != NULL)) {
ian@0 375 read_lock(&tasklist_lock);
ian@0 376 if (unlikely(p->signal == NULL)) {
ian@0 377 /*
ian@0 378 * We raced with the reaping of the task.
ian@0 379 * The deletion should have cleared us off the list.
ian@0 380 */
ian@0 381 BUG_ON(!list_empty(&timer->it.cpu.entry));
ian@0 382 } else {
ian@0 383 spin_lock(&p->sighand->siglock);
ian@0 384 if (timer->it.cpu.firing)
ian@0 385 ret = TIMER_RETRY;
ian@0 386 else
ian@0 387 list_del(&timer->it.cpu.entry);
ian@0 388 spin_unlock(&p->sighand->siglock);
ian@0 389 }
ian@0 390 read_unlock(&tasklist_lock);
ian@0 391
ian@0 392 if (!ret)
ian@0 393 put_task_struct(p);
ian@0 394 }
ian@0 395
ian@0 396 return ret;
ian@0 397 }
ian@0 398
ian@0 399 /*
ian@0 400 * Clean out CPU timers still ticking when a thread exited. The task
ian@0 401 * pointer is cleared, and the expiry time is replaced with the residual
ian@0 402 * time for later timer_gettime calls to return.
ian@0 403 * This must be called with the siglock held.
ian@0 404 */
ian@0 405 static void cleanup_timers(struct list_head *head,
ian@0 406 cputime_t utime, cputime_t stime,
ian@0 407 unsigned long long sched_time)
ian@0 408 {
ian@0 409 struct cpu_timer_list *timer, *next;
ian@0 410 cputime_t ptime = cputime_add(utime, stime);
ian@0 411
ian@0 412 list_for_each_entry_safe(timer, next, head, entry) {
ian@0 413 list_del_init(&timer->entry);
ian@0 414 if (cputime_lt(timer->expires.cpu, ptime)) {
ian@0 415 timer->expires.cpu = cputime_zero;
ian@0 416 } else {
ian@0 417 timer->expires.cpu = cputime_sub(timer->expires.cpu,
ian@0 418 ptime);
ian@0 419 }
ian@0 420 }
ian@0 421
ian@0 422 ++head;
ian@0 423 list_for_each_entry_safe(timer, next, head, entry) {
ian@0 424 list_del_init(&timer->entry);
ian@0 425 if (cputime_lt(timer->expires.cpu, utime)) {
ian@0 426 timer->expires.cpu = cputime_zero;
ian@0 427 } else {
ian@0 428 timer->expires.cpu = cputime_sub(timer->expires.cpu,
ian@0 429 utime);
ian@0 430 }
ian@0 431 }
ian@0 432
ian@0 433 ++head;
ian@0 434 list_for_each_entry_safe(timer, next, head, entry) {
ian@0 435 list_del_init(&timer->entry);
ian@0 436 if (timer->expires.sched < sched_time) {
ian@0 437 timer->expires.sched = 0;
ian@0 438 } else {
ian@0 439 timer->expires.sched -= sched_time;
ian@0 440 }
ian@0 441 }
ian@0 442 }
ian@0 443
ian@0 444 /*
ian@0 445 * These are both called with the siglock held, when the current thread
ian@0 446 * is being reaped. When the final (leader) thread in the group is reaped,
ian@0 447 * posix_cpu_timers_exit_group will be called after posix_cpu_timers_exit.
ian@0 448 */
ian@0 449 void posix_cpu_timers_exit(struct task_struct *tsk)
ian@0 450 {
ian@0 451 cleanup_timers(tsk->cpu_timers,
ian@0 452 tsk->utime, tsk->stime, tsk->sched_time);
ian@0 453
ian@0 454 }
ian@0 455 void posix_cpu_timers_exit_group(struct task_struct *tsk)
ian@0 456 {
ian@0 457 cleanup_timers(tsk->signal->cpu_timers,
ian@0 458 cputime_add(tsk->utime, tsk->signal->utime),
ian@0 459 cputime_add(tsk->stime, tsk->signal->stime),
ian@0 460 tsk->sched_time + tsk->signal->sched_time);
ian@0 461 }
ian@0 462
ian@0 463
ian@0 464 /*
ian@0 465 * Set the expiry times of all the threads in the process so one of them
ian@0 466 * will go off before the process cumulative expiry total is reached.
ian@0 467 */
ian@0 468 static void process_timer_rebalance(struct task_struct *p,
ian@0 469 unsigned int clock_idx,
ian@0 470 union cpu_time_count expires,
ian@0 471 union cpu_time_count val)
ian@0 472 {
ian@0 473 cputime_t ticks, left;
ian@0 474 unsigned long long ns, nsleft;
ian@0 475 struct task_struct *t = p;
ian@0 476 unsigned int nthreads = atomic_read(&p->signal->live);
ian@0 477
ian@0 478 if (!nthreads)
ian@0 479 return;
ian@0 480
ian@0 481 switch (clock_idx) {
ian@0 482 default:
ian@0 483 BUG();
ian@0 484 break;
ian@0 485 case CPUCLOCK_PROF:
ian@0 486 left = cputime_div(cputime_sub(expires.cpu, val.cpu),
ian@0 487 nthreads);
ian@0 488 do {
ian@0 489 if (likely(!(t->flags & PF_EXITING))) {
ian@0 490 ticks = cputime_add(prof_ticks(t), left);
ian@0 491 if (cputime_eq(t->it_prof_expires,
ian@0 492 cputime_zero) ||
ian@0 493 cputime_gt(t->it_prof_expires, ticks)) {
ian@0 494 t->it_prof_expires = ticks;
ian@0 495 }
ian@0 496 }
ian@0 497 t = next_thread(t);
ian@0 498 } while (t != p);
ian@0 499 break;
ian@0 500 case CPUCLOCK_VIRT:
ian@0 501 left = cputime_div(cputime_sub(expires.cpu, val.cpu),
ian@0 502 nthreads);
ian@0 503 do {
ian@0 504 if (likely(!(t->flags & PF_EXITING))) {
ian@0 505 ticks = cputime_add(virt_ticks(t), left);
ian@0 506 if (cputime_eq(t->it_virt_expires,
ian@0 507 cputime_zero) ||
ian@0 508 cputime_gt(t->it_virt_expires, ticks)) {
ian@0 509 t->it_virt_expires = ticks;
ian@0 510 }
ian@0 511 }
ian@0 512 t = next_thread(t);
ian@0 513 } while (t != p);
ian@0 514 break;
ian@0 515 case CPUCLOCK_SCHED:
ian@0 516 nsleft = expires.sched - val.sched;
ian@0 517 do_div(nsleft, nthreads);
ian@0 518 do {
ian@0 519 if (likely(!(t->flags & PF_EXITING))) {
ian@0 520 ns = t->sched_time + nsleft;
ian@0 521 if (t->it_sched_expires == 0 ||
ian@0 522 t->it_sched_expires > ns) {
ian@0 523 t->it_sched_expires = ns;
ian@0 524 }
ian@0 525 }
ian@0 526 t = next_thread(t);
ian@0 527 } while (t != p);
ian@0 528 break;
ian@0 529 }
ian@0 530 }
ian@0 531
ian@0 532 static void clear_dead_task(struct k_itimer *timer, union cpu_time_count now)
ian@0 533 {
ian@0 534 /*
ian@0 535 * That's all for this thread or process.
ian@0 536 * We leave our residual in expires to be reported.
ian@0 537 */
ian@0 538 put_task_struct(timer->it.cpu.task);
ian@0 539 timer->it.cpu.task = NULL;
ian@0 540 timer->it.cpu.expires = cpu_time_sub(timer->it_clock,
ian@0 541 timer->it.cpu.expires,
ian@0 542 now);
ian@0 543 }
ian@0 544
ian@0 545 /*
ian@0 546 * Insert the timer on the appropriate list before any timers that
ian@0 547 * expire later. This must be called with the tasklist_lock held
ian@0 548 * for reading, and interrupts disabled.
ian@0 549 */
ian@0 550 static void arm_timer(struct k_itimer *timer, union cpu_time_count now)
ian@0 551 {
ian@0 552 struct task_struct *p = timer->it.cpu.task;
ian@0 553 struct list_head *head, *listpos;
ian@0 554 struct cpu_timer_list *const nt = &timer->it.cpu;
ian@0 555 struct cpu_timer_list *next;
ian@0 556 unsigned long i;
ian@0 557
ian@0 558 head = (CPUCLOCK_PERTHREAD(timer->it_clock) ?
ian@0 559 p->cpu_timers : p->signal->cpu_timers);
ian@0 560 head += CPUCLOCK_WHICH(timer->it_clock);
ian@0 561
ian@0 562 BUG_ON(!irqs_disabled());
ian@0 563 spin_lock(&p->sighand->siglock);
ian@0 564
ian@0 565 listpos = head;
ian@0 566 if (CPUCLOCK_WHICH(timer->it_clock) == CPUCLOCK_SCHED) {
ian@0 567 list_for_each_entry(next, head, entry) {
ian@0 568 if (next->expires.sched > nt->expires.sched)
ian@0 569 break;
ian@0 570 listpos = &next->entry;
ian@0 571 }
ian@0 572 } else {
ian@0 573 list_for_each_entry(next, head, entry) {
ian@0 574 if (cputime_gt(next->expires.cpu, nt->expires.cpu))
ian@0 575 break;
ian@0 576 listpos = &next->entry;
ian@0 577 }
ian@0 578 }
ian@0 579 list_add(&nt->entry, listpos);
ian@0 580
ian@0 581 if (listpos == head) {
ian@0 582 /*
ian@0 583 * We are the new earliest-expiring timer.
ian@0 584 * If we are a thread timer, there can always
ian@0 585 * be a process timer telling us to stop earlier.
ian@0 586 */
ian@0 587
ian@0 588 if (CPUCLOCK_PERTHREAD(timer->it_clock)) {
ian@0 589 switch (CPUCLOCK_WHICH(timer->it_clock)) {
ian@0 590 default:
ian@0 591 BUG();
ian@0 592 case CPUCLOCK_PROF:
ian@0 593 if (cputime_eq(p->it_prof_expires,
ian@0 594 cputime_zero) ||
ian@0 595 cputime_gt(p->it_prof_expires,
ian@0 596 nt->expires.cpu))
ian@0 597 p->it_prof_expires = nt->expires.cpu;
ian@0 598 break;
ian@0 599 case CPUCLOCK_VIRT:
ian@0 600 if (cputime_eq(p->it_virt_expires,
ian@0 601 cputime_zero) ||
ian@0 602 cputime_gt(p->it_virt_expires,
ian@0 603 nt->expires.cpu))
ian@0 604 p->it_virt_expires = nt->expires.cpu;
ian@0 605 break;
ian@0 606 case CPUCLOCK_SCHED:
ian@0 607 if (p->it_sched_expires == 0 ||
ian@0 608 p->it_sched_expires > nt->expires.sched)
ian@0 609 p->it_sched_expires = nt->expires.sched;
ian@0 610 break;
ian@0 611 }
ian@0 612 } else {
ian@0 613 /*
ian@0 614 * For a process timer, we must balance
ian@0 615 * all the live threads' expirations.
ian@0 616 */
ian@0 617 switch (CPUCLOCK_WHICH(timer->it_clock)) {
ian@0 618 default:
ian@0 619 BUG();
ian@0 620 case CPUCLOCK_VIRT:
ian@0 621 if (!cputime_eq(p->signal->it_virt_expires,
ian@0 622 cputime_zero) &&
ian@0 623 cputime_lt(p->signal->it_virt_expires,
ian@0 624 timer->it.cpu.expires.cpu))
ian@0 625 break;
ian@0 626 goto rebalance;
ian@0 627 case CPUCLOCK_PROF:
ian@0 628 if (!cputime_eq(p->signal->it_prof_expires,
ian@0 629 cputime_zero) &&
ian@0 630 cputime_lt(p->signal->it_prof_expires,
ian@0 631 timer->it.cpu.expires.cpu))
ian@0 632 break;
ian@0 633 i = p->signal->rlim[RLIMIT_CPU].rlim_cur;
ian@0 634 if (i != RLIM_INFINITY &&
ian@0 635 i <= cputime_to_secs(timer->it.cpu.expires.cpu))
ian@0 636 break;
ian@0 637 goto rebalance;
ian@0 638 case CPUCLOCK_SCHED:
ian@0 639 rebalance:
ian@0 640 process_timer_rebalance(
ian@0 641 timer->it.cpu.task,
ian@0 642 CPUCLOCK_WHICH(timer->it_clock),
ian@0 643 timer->it.cpu.expires, now);
ian@0 644 break;
ian@0 645 }
ian@0 646 }
ian@0 647 }
ian@0 648
ian@0 649 spin_unlock(&p->sighand->siglock);
ian@0 650 }
ian@0 651
ian@0 652 /*
ian@0 653 * The timer is locked, fire it and arrange for its reload.
ian@0 654 */
ian@0 655 static void cpu_timer_fire(struct k_itimer *timer)
ian@0 656 {
ian@0 657 if (unlikely(timer->sigq == NULL)) {
ian@0 658 /*
ian@0 659 * This a special case for clock_nanosleep,
ian@0 660 * not a normal timer from sys_timer_create.
ian@0 661 */
ian@0 662 wake_up_process(timer->it_process);
ian@0 663 timer->it.cpu.expires.sched = 0;
ian@0 664 } else if (timer->it.cpu.incr.sched == 0) {
ian@0 665 /*
ian@0 666 * One-shot timer. Clear it as soon as it's fired.
ian@0 667 */
ian@0 668 posix_timer_event(timer, 0);
ian@0 669 timer->it.cpu.expires.sched = 0;
ian@0 670 } else if (posix_timer_event(timer, ++timer->it_requeue_pending)) {
ian@0 671 /*
ian@0 672 * The signal did not get queued because the signal
ian@0 673 * was ignored, so we won't get any callback to
ian@0 674 * reload the timer. But we need to keep it
ian@0 675 * ticking in case the signal is deliverable next time.
ian@0 676 */
ian@0 677 posix_cpu_timer_schedule(timer);
ian@0 678 }
ian@0 679 }
ian@0 680
ian@0 681 /*
ian@0 682 * Guts of sys_timer_settime for CPU timers.
ian@0 683 * This is called with the timer locked and interrupts disabled.
ian@0 684 * If we return TIMER_RETRY, it's necessary to release the timer's lock
ian@0 685 * and try again. (This happens when the timer is in the middle of firing.)
ian@0 686 */
ian@0 687 int posix_cpu_timer_set(struct k_itimer *timer, int flags,
ian@0 688 struct itimerspec *new, struct itimerspec *old)
ian@0 689 {
ian@0 690 struct task_struct *p = timer->it.cpu.task;
ian@0 691 union cpu_time_count old_expires, new_expires, val;
ian@0 692 int ret;
ian@0 693
ian@0 694 if (unlikely(p == NULL)) {
ian@0 695 /*
ian@0 696 * Timer refers to a dead task's clock.
ian@0 697 */
ian@0 698 return -ESRCH;
ian@0 699 }
ian@0 700
ian@0 701 new_expires = timespec_to_sample(timer->it_clock, &new->it_value);
ian@0 702
ian@0 703 read_lock(&tasklist_lock);
ian@0 704 /*
ian@0 705 * We need the tasklist_lock to protect against reaping that
ian@0 706 * clears p->signal. If p has just been reaped, we can no
ian@0 707 * longer get any information about it at all.
ian@0 708 */
ian@0 709 if (unlikely(p->signal == NULL)) {
ian@0 710 read_unlock(&tasklist_lock);
ian@0 711 put_task_struct(p);
ian@0 712 timer->it.cpu.task = NULL;
ian@0 713 return -ESRCH;
ian@0 714 }
ian@0 715
ian@0 716 /*
ian@0 717 * Disarm any old timer after extracting its expiry time.
ian@0 718 */
ian@0 719 BUG_ON(!irqs_disabled());
ian@0 720
ian@0 721 ret = 0;
ian@0 722 spin_lock(&p->sighand->siglock);
ian@0 723 old_expires = timer->it.cpu.expires;
ian@0 724 if (unlikely(timer->it.cpu.firing)) {
ian@0 725 timer->it.cpu.firing = -1;
ian@0 726 ret = TIMER_RETRY;
ian@0 727 } else
ian@0 728 list_del_init(&timer->it.cpu.entry);
ian@0 729 spin_unlock(&p->sighand->siglock);
ian@0 730
ian@0 731 /*
ian@0 732 * We need to sample the current value to convert the new
ian@0 733 * value from to relative and absolute, and to convert the
ian@0 734 * old value from absolute to relative. To set a process
ian@0 735 * timer, we need a sample to balance the thread expiry
ian@0 736 * times (in arm_timer). With an absolute time, we must
ian@0 737 * check if it's already passed. In short, we need a sample.
ian@0 738 */
ian@0 739 if (CPUCLOCK_PERTHREAD(timer->it_clock)) {
ian@0 740 cpu_clock_sample(timer->it_clock, p, &val);
ian@0 741 } else {
ian@0 742 cpu_clock_sample_group(timer->it_clock, p, &val);
ian@0 743 }
ian@0 744
ian@0 745 if (old) {
ian@0 746 if (old_expires.sched == 0) {
ian@0 747 old->it_value.tv_sec = 0;
ian@0 748 old->it_value.tv_nsec = 0;
ian@0 749 } else {
ian@0 750 /*
ian@0 751 * Update the timer in case it has
ian@0 752 * overrun already. If it has,
ian@0 753 * we'll report it as having overrun
ian@0 754 * and with the next reloaded timer
ian@0 755 * already ticking, though we are
ian@0 756 * swallowing that pending
ian@0 757 * notification here to install the
ian@0 758 * new setting.
ian@0 759 */
ian@0 760 bump_cpu_timer(timer, val);
ian@0 761 if (cpu_time_before(timer->it_clock, val,
ian@0 762 timer->it.cpu.expires)) {
ian@0 763 old_expires = cpu_time_sub(
ian@0 764 timer->it_clock,
ian@0 765 timer->it.cpu.expires, val);
ian@0 766 sample_to_timespec(timer->it_clock,
ian@0 767 old_expires,
ian@0 768 &old->it_value);
ian@0 769 } else {
ian@0 770 old->it_value.tv_nsec = 1;
ian@0 771 old->it_value.tv_sec = 0;
ian@0 772 }
ian@0 773 }
ian@0 774 }
ian@0 775
ian@0 776 if (unlikely(ret)) {
ian@0 777 /*
ian@0 778 * We are colliding with the timer actually firing.
ian@0 779 * Punt after filling in the timer's old value, and
ian@0 780 * disable this firing since we are already reporting
ian@0 781 * it as an overrun (thanks to bump_cpu_timer above).
ian@0 782 */
ian@0 783 read_unlock(&tasklist_lock);
ian@0 784 goto out;
ian@0 785 }
ian@0 786
ian@0 787 if (new_expires.sched != 0 && !(flags & TIMER_ABSTIME)) {
ian@0 788 cpu_time_add(timer->it_clock, &new_expires, val);
ian@0 789 }
ian@0 790
ian@0 791 /*
ian@0 792 * Install the new expiry time (or zero).
ian@0 793 * For a timer with no notification action, we don't actually
ian@0 794 * arm the timer (we'll just fake it for timer_gettime).
ian@0 795 */
ian@0 796 timer->it.cpu.expires = new_expires;
ian@0 797 if (new_expires.sched != 0 &&
ian@0 798 (timer->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE &&
ian@0 799 cpu_time_before(timer->it_clock, val, new_expires)) {
ian@0 800 arm_timer(timer, val);
ian@0 801 }
ian@0 802
ian@0 803 read_unlock(&tasklist_lock);
ian@0 804
ian@0 805 /*
ian@0 806 * Install the new reload setting, and
ian@0 807 * set up the signal and overrun bookkeeping.
ian@0 808 */
ian@0 809 timer->it.cpu.incr = timespec_to_sample(timer->it_clock,
ian@0 810 &new->it_interval);
ian@0 811
ian@0 812 /*
ian@0 813 * This acts as a modification timestamp for the timer,
ian@0 814 * so any automatic reload attempt will punt on seeing
ian@0 815 * that we have reset the timer manually.
ian@0 816 */
ian@0 817 timer->it_requeue_pending = (timer->it_requeue_pending + 2) &
ian@0 818 ~REQUEUE_PENDING;
ian@0 819 timer->it_overrun_last = 0;
ian@0 820 timer->it_overrun = -1;
ian@0 821
ian@0 822 if (new_expires.sched != 0 &&
ian@0 823 (timer->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE &&
ian@0 824 !cpu_time_before(timer->it_clock, val, new_expires)) {
ian@0 825 /*
ian@0 826 * The designated time already passed, so we notify
ian@0 827 * immediately, even if the thread never runs to
ian@0 828 * accumulate more time on this clock.
ian@0 829 */
ian@0 830 cpu_timer_fire(timer);
ian@0 831 }
ian@0 832
ian@0 833 ret = 0;
ian@0 834 out:
ian@0 835 if (old) {
ian@0 836 sample_to_timespec(timer->it_clock,
ian@0 837 timer->it.cpu.incr, &old->it_interval);
ian@0 838 }
ian@0 839 return ret;
ian@0 840 }
ian@0 841
ian@0 842 void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp)
ian@0 843 {
ian@0 844 union cpu_time_count now;
ian@0 845 struct task_struct *p = timer->it.cpu.task;
ian@0 846 int clear_dead;
ian@0 847
ian@0 848 /*
ian@0 849 * Easy part: convert the reload time.
ian@0 850 */
ian@0 851 sample_to_timespec(timer->it_clock,
ian@0 852 timer->it.cpu.incr, &itp->it_interval);
ian@0 853
ian@0 854 if (timer->it.cpu.expires.sched == 0) { /* Timer not armed at all. */
ian@0 855 itp->it_value.tv_sec = itp->it_value.tv_nsec = 0;
ian@0 856 return;
ian@0 857 }
ian@0 858
ian@0 859 if (unlikely(p == NULL)) {
ian@0 860 /*
ian@0 861 * This task already died and the timer will never fire.
ian@0 862 * In this case, expires is actually the dead value.
ian@0 863 */
ian@0 864 dead:
ian@0 865 sample_to_timespec(timer->it_clock, timer->it.cpu.expires,
ian@0 866 &itp->it_value);
ian@0 867 return;
ian@0 868 }
ian@0 869
ian@0 870 /*
ian@0 871 * Sample the clock to take the difference with the expiry time.
ian@0 872 */
ian@0 873 if (CPUCLOCK_PERTHREAD(timer->it_clock)) {
ian@0 874 cpu_clock_sample(timer->it_clock, p, &now);
ian@0 875 clear_dead = p->exit_state;
ian@0 876 } else {
ian@0 877 read_lock(&tasklist_lock);
ian@0 878 if (unlikely(p->signal == NULL)) {
ian@0 879 /*
ian@0 880 * The process has been reaped.
ian@0 881 * We can't even collect a sample any more.
ian@0 882 * Call the timer disarmed, nothing else to do.
ian@0 883 */
ian@0 884 put_task_struct(p);
ian@0 885 timer->it.cpu.task = NULL;
ian@0 886 timer->it.cpu.expires.sched = 0;
ian@0 887 read_unlock(&tasklist_lock);
ian@0 888 goto dead;
ian@0 889 } else {
ian@0 890 cpu_clock_sample_group(timer->it_clock, p, &now);
ian@0 891 clear_dead = (unlikely(p->exit_state) &&
ian@0 892 thread_group_empty(p));
ian@0 893 }
ian@0 894 read_unlock(&tasklist_lock);
ian@0 895 }
ian@0 896
ian@0 897 if ((timer->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE) {
ian@0 898 if (timer->it.cpu.incr.sched == 0 &&
ian@0 899 cpu_time_before(timer->it_clock,
ian@0 900 timer->it.cpu.expires, now)) {
ian@0 901 /*
ian@0 902 * Do-nothing timer expired and has no reload,
ian@0 903 * so it's as if it was never set.
ian@0 904 */
ian@0 905 timer->it.cpu.expires.sched = 0;
ian@0 906 itp->it_value.tv_sec = itp->it_value.tv_nsec = 0;
ian@0 907 return;
ian@0 908 }
ian@0 909 /*
ian@0 910 * Account for any expirations and reloads that should
ian@0 911 * have happened.
ian@0 912 */
ian@0 913 bump_cpu_timer(timer, now);
ian@0 914 }
ian@0 915
ian@0 916 if (unlikely(clear_dead)) {
ian@0 917 /*
ian@0 918 * We've noticed that the thread is dead, but
ian@0 919 * not yet reaped. Take this opportunity to
ian@0 920 * drop our task ref.
ian@0 921 */
ian@0 922 clear_dead_task(timer, now);
ian@0 923 goto dead;
ian@0 924 }
ian@0 925
ian@0 926 if (cpu_time_before(timer->it_clock, now, timer->it.cpu.expires)) {
ian@0 927 sample_to_timespec(timer->it_clock,
ian@0 928 cpu_time_sub(timer->it_clock,
ian@0 929 timer->it.cpu.expires, now),
ian@0 930 &itp->it_value);
ian@0 931 } else {
ian@0 932 /*
ian@0 933 * The timer should have expired already, but the firing
ian@0 934 * hasn't taken place yet. Say it's just about to expire.
ian@0 935 */
ian@0 936 itp->it_value.tv_nsec = 1;
ian@0 937 itp->it_value.tv_sec = 0;
ian@0 938 }
ian@0 939 }
ian@0 940
ian@0 941 /*
ian@0 942 * Check for any per-thread CPU timers that have fired and move them off
ian@0 943 * the tsk->cpu_timers[N] list onto the firing list. Here we update the
ian@0 944 * tsk->it_*_expires values to reflect the remaining thread CPU timers.
ian@0 945 */
ian@0 946 static void check_thread_timers(struct task_struct *tsk,
ian@0 947 struct list_head *firing)
ian@0 948 {
ian@0 949 int maxfire;
ian@0 950 struct list_head *timers = tsk->cpu_timers;
ian@0 951
ian@0 952 maxfire = 20;
ian@0 953 tsk->it_prof_expires = cputime_zero;
ian@0 954 while (!list_empty(timers)) {
ian@0 955 struct cpu_timer_list *t = list_entry(timers->next,
ian@0 956 struct cpu_timer_list,
ian@0 957 entry);
ian@0 958 if (!--maxfire || cputime_lt(prof_ticks(tsk), t->expires.cpu)) {
ian@0 959 tsk->it_prof_expires = t->expires.cpu;
ian@0 960 break;
ian@0 961 }
ian@0 962 t->firing = 1;
ian@0 963 list_move_tail(&t->entry, firing);
ian@0 964 }
ian@0 965
ian@0 966 ++timers;
ian@0 967 maxfire = 20;
ian@0 968 tsk->it_virt_expires = cputime_zero;
ian@0 969 while (!list_empty(timers)) {
ian@0 970 struct cpu_timer_list *t = list_entry(timers->next,
ian@0 971 struct cpu_timer_list,
ian@0 972 entry);
ian@0 973 if (!--maxfire || cputime_lt(virt_ticks(tsk), t->expires.cpu)) {
ian@0 974 tsk->it_virt_expires = t->expires.cpu;
ian@0 975 break;
ian@0 976 }
ian@0 977 t->firing = 1;
ian@0 978 list_move_tail(&t->entry, firing);
ian@0 979 }
ian@0 980
ian@0 981 ++timers;
ian@0 982 maxfire = 20;
ian@0 983 tsk->it_sched_expires = 0;
ian@0 984 while (!list_empty(timers)) {
ian@0 985 struct cpu_timer_list *t = list_entry(timers->next,
ian@0 986 struct cpu_timer_list,
ian@0 987 entry);
ian@0 988 if (!--maxfire || tsk->sched_time < t->expires.sched) {
ian@0 989 tsk->it_sched_expires = t->expires.sched;
ian@0 990 break;
ian@0 991 }
ian@0 992 t->firing = 1;
ian@0 993 list_move_tail(&t->entry, firing);
ian@0 994 }
ian@0 995 }
ian@0 996
ian@0 997 /*
ian@0 998 * Check for any per-thread CPU timers that have fired and move them
ian@0 999 * off the tsk->*_timers list onto the firing list. Per-thread timers
ian@0 1000 * have already been taken off.
ian@0 1001 */
ian@0 1002 static void check_process_timers(struct task_struct *tsk,
ian@0 1003 struct list_head *firing)
ian@0 1004 {
ian@0 1005 int maxfire;
ian@0 1006 struct signal_struct *const sig = tsk->signal;
ian@0 1007 cputime_t utime, stime, ptime, virt_expires, prof_expires;
ian@0 1008 unsigned long long sched_time, sched_expires;
ian@0 1009 struct task_struct *t;
ian@0 1010 struct list_head *timers = sig->cpu_timers;
ian@0 1011
ian@0 1012 /*
ian@0 1013 * Don't sample the current process CPU clocks if there are no timers.
ian@0 1014 */
ian@0 1015 if (list_empty(&timers[CPUCLOCK_PROF]) &&
ian@0 1016 cputime_eq(sig->it_prof_expires, cputime_zero) &&
ian@0 1017 sig->rlim[RLIMIT_CPU].rlim_cur == RLIM_INFINITY &&
ian@0 1018 list_empty(&timers[CPUCLOCK_VIRT]) &&
ian@0 1019 cputime_eq(sig->it_virt_expires, cputime_zero) &&
ian@0 1020 list_empty(&timers[CPUCLOCK_SCHED]))
ian@0 1021 return;
ian@0 1022
ian@0 1023 /*
ian@0 1024 * Collect the current process totals.
ian@0 1025 */
ian@0 1026 utime = sig->utime;
ian@0 1027 stime = sig->stime;
ian@0 1028 sched_time = sig->sched_time;
ian@0 1029 t = tsk;
ian@0 1030 do {
ian@0 1031 utime = cputime_add(utime, t->utime);
ian@0 1032 stime = cputime_add(stime, t->stime);
ian@0 1033 sched_time += t->sched_time;
ian@0 1034 t = next_thread(t);
ian@0 1035 } while (t != tsk);
ian@0 1036 ptime = cputime_add(utime, stime);
ian@0 1037
ian@0 1038 maxfire = 20;
ian@0 1039 prof_expires = cputime_zero;
ian@0 1040 while (!list_empty(timers)) {
ian@0 1041 struct cpu_timer_list *t = list_entry(timers->next,
ian@0 1042 struct cpu_timer_list,
ian@0 1043 entry);
ian@0 1044 if (!--maxfire || cputime_lt(ptime, t->expires.cpu)) {
ian@0 1045 prof_expires = t->expires.cpu;
ian@0 1046 break;
ian@0 1047 }
ian@0 1048 t->firing = 1;
ian@0 1049 list_move_tail(&t->entry, firing);
ian@0 1050 }
ian@0 1051
ian@0 1052 ++timers;
ian@0 1053 maxfire = 20;
ian@0 1054 virt_expires = cputime_zero;
ian@0 1055 while (!list_empty(timers)) {
ian@0 1056 struct cpu_timer_list *t = list_entry(timers->next,
ian@0 1057 struct cpu_timer_list,
ian@0 1058 entry);
ian@0 1059 if (!--maxfire || cputime_lt(utime, t->expires.cpu)) {
ian@0 1060 virt_expires = t->expires.cpu;
ian@0 1061 break;
ian@0 1062 }
ian@0 1063 t->firing = 1;
ian@0 1064 list_move_tail(&t->entry, firing);
ian@0 1065 }
ian@0 1066
ian@0 1067 ++timers;
ian@0 1068 maxfire = 20;
ian@0 1069 sched_expires = 0;
ian@0 1070 while (!list_empty(timers)) {
ian@0 1071 struct cpu_timer_list *t = list_entry(timers->next,
ian@0 1072 struct cpu_timer_list,
ian@0 1073 entry);
ian@0 1074 if (!--maxfire || sched_time < t->expires.sched) {
ian@0 1075 sched_expires = t->expires.sched;
ian@0 1076 break;
ian@0 1077 }
ian@0 1078 t->firing = 1;
ian@0 1079 list_move_tail(&t->entry, firing);
ian@0 1080 }
ian@0 1081
ian@0 1082 /*
ian@0 1083 * Check for the special case process timers.
ian@0 1084 */
ian@0 1085 if (!cputime_eq(sig->it_prof_expires, cputime_zero)) {
ian@0 1086 if (cputime_ge(ptime, sig->it_prof_expires)) {
ian@0 1087 /* ITIMER_PROF fires and reloads. */
ian@0 1088 sig->it_prof_expires = sig->it_prof_incr;
ian@0 1089 if (!cputime_eq(sig->it_prof_expires, cputime_zero)) {
ian@0 1090 sig->it_prof_expires = cputime_add(
ian@0 1091 sig->it_prof_expires, ptime);
ian@0 1092 }
ian@0 1093 __group_send_sig_info(SIGPROF, SEND_SIG_PRIV, tsk);
ian@0 1094 }
ian@0 1095 if (!cputime_eq(sig->it_prof_expires, cputime_zero) &&
ian@0 1096 (cputime_eq(prof_expires, cputime_zero) ||
ian@0 1097 cputime_lt(sig->it_prof_expires, prof_expires))) {
ian@0 1098 prof_expires = sig->it_prof_expires;
ian@0 1099 }
ian@0 1100 }
ian@0 1101 if (!cputime_eq(sig->it_virt_expires, cputime_zero)) {
ian@0 1102 if (cputime_ge(utime, sig->it_virt_expires)) {
ian@0 1103 /* ITIMER_VIRTUAL fires and reloads. */
ian@0 1104 sig->it_virt_expires = sig->it_virt_incr;
ian@0 1105 if (!cputime_eq(sig->it_virt_expires, cputime_zero)) {
ian@0 1106 sig->it_virt_expires = cputime_add(
ian@0 1107 sig->it_virt_expires, utime);
ian@0 1108 }
ian@0 1109 __group_send_sig_info(SIGVTALRM, SEND_SIG_PRIV, tsk);
ian@0 1110 }
ian@0 1111 if (!cputime_eq(sig->it_virt_expires, cputime_zero) &&
ian@0 1112 (cputime_eq(virt_expires, cputime_zero) ||
ian@0 1113 cputime_lt(sig->it_virt_expires, virt_expires))) {
ian@0 1114 virt_expires = sig->it_virt_expires;
ian@0 1115 }
ian@0 1116 }
ian@0 1117 if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) {
ian@0 1118 unsigned long psecs = cputime_to_secs(ptime);
ian@0 1119 cputime_t x;
ian@0 1120 if (psecs >= sig->rlim[RLIMIT_CPU].rlim_max) {
ian@0 1121 /*
ian@0 1122 * At the hard limit, we just die.
ian@0 1123 * No need to calculate anything else now.
ian@0 1124 */
ian@0 1125 __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk);
ian@0 1126 return;
ian@0 1127 }
ian@0 1128 if (psecs >= sig->rlim[RLIMIT_CPU].rlim_cur) {
ian@0 1129 /*
ian@0 1130 * At the soft limit, send a SIGXCPU every second.
ian@0 1131 */
ian@0 1132 __group_send_sig_info(SIGXCPU, SEND_SIG_PRIV, tsk);
ian@0 1133 if (sig->rlim[RLIMIT_CPU].rlim_cur
ian@0 1134 < sig->rlim[RLIMIT_CPU].rlim_max) {
ian@0 1135 sig->rlim[RLIMIT_CPU].rlim_cur++;
ian@0 1136 }
ian@0 1137 }
ian@0 1138 x = secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur);
ian@0 1139 if (cputime_eq(prof_expires, cputime_zero) ||
ian@0 1140 cputime_lt(x, prof_expires)) {
ian@0 1141 prof_expires = x;
ian@0 1142 }
ian@0 1143 }
ian@0 1144
ian@0 1145 if (!cputime_eq(prof_expires, cputime_zero) ||
ian@0 1146 !cputime_eq(virt_expires, cputime_zero) ||
ian@0 1147 sched_expires != 0) {
ian@0 1148 /*
ian@0 1149 * Rebalance the threads' expiry times for the remaining
ian@0 1150 * process CPU timers.
ian@0 1151 */
ian@0 1152
ian@0 1153 cputime_t prof_left, virt_left, ticks;
ian@0 1154 unsigned long long sched_left, sched;
ian@0 1155 const unsigned int nthreads = atomic_read(&sig->live);
ian@0 1156
ian@0 1157 if (!nthreads)
ian@0 1158 return;
ian@0 1159
ian@0 1160 prof_left = cputime_sub(prof_expires, utime);
ian@0 1161 prof_left = cputime_sub(prof_left, stime);
ian@0 1162 prof_left = cputime_div(prof_left, nthreads);
ian@0 1163 virt_left = cputime_sub(virt_expires, utime);
ian@0 1164 virt_left = cputime_div(virt_left, nthreads);
ian@0 1165 if (sched_expires) {
ian@0 1166 sched_left = sched_expires - sched_time;
ian@0 1167 do_div(sched_left, nthreads);
ian@0 1168 } else {
ian@0 1169 sched_left = 0;
ian@0 1170 }
ian@0 1171 t = tsk;
ian@0 1172 do {
ian@0 1173 if (unlikely(t->flags & PF_EXITING))
ian@0 1174 continue;
ian@0 1175
ian@0 1176 ticks = cputime_add(cputime_add(t->utime, t->stime),
ian@0 1177 prof_left);
ian@0 1178 if (!cputime_eq(prof_expires, cputime_zero) &&
ian@0 1179 (cputime_eq(t->it_prof_expires, cputime_zero) ||
ian@0 1180 cputime_gt(t->it_prof_expires, ticks))) {
ian@0 1181 t->it_prof_expires = ticks;
ian@0 1182 }
ian@0 1183
ian@0 1184 ticks = cputime_add(t->utime, virt_left);
ian@0 1185 if (!cputime_eq(virt_expires, cputime_zero) &&
ian@0 1186 (cputime_eq(t->it_virt_expires, cputime_zero) ||
ian@0 1187 cputime_gt(t->it_virt_expires, ticks))) {
ian@0 1188 t->it_virt_expires = ticks;
ian@0 1189 }
ian@0 1190
ian@0 1191 sched = t->sched_time + sched_left;
ian@0 1192 if (sched_expires && (t->it_sched_expires == 0 ||
ian@0 1193 t->it_sched_expires > sched)) {
ian@0 1194 t->it_sched_expires = sched;
ian@0 1195 }
ian@0 1196 } while ((t = next_thread(t)) != tsk);
ian@0 1197 }
ian@0 1198 }
ian@0 1199
ian@0 1200 /*
ian@0 1201 * This is called from the signal code (via do_schedule_next_timer)
ian@0 1202 * when the last timer signal was delivered and we have to reload the timer.
ian@0 1203 */
ian@0 1204 void posix_cpu_timer_schedule(struct k_itimer *timer)
ian@0 1205 {
ian@0 1206 struct task_struct *p = timer->it.cpu.task;
ian@0 1207 union cpu_time_count now;
ian@0 1208
ian@0 1209 if (unlikely(p == NULL))
ian@0 1210 /*
ian@0 1211 * The task was cleaned up already, no future firings.
ian@0 1212 */
ian@0 1213 goto out;
ian@0 1214
ian@0 1215 /*
ian@0 1216 * Fetch the current sample and update the timer's expiry time.
ian@0 1217 */
ian@0 1218 if (CPUCLOCK_PERTHREAD(timer->it_clock)) {
ian@0 1219 cpu_clock_sample(timer->it_clock, p, &now);
ian@0 1220 bump_cpu_timer(timer, now);
ian@0 1221 if (unlikely(p->exit_state)) {
ian@0 1222 clear_dead_task(timer, now);
ian@0 1223 goto out;
ian@0 1224 }
ian@0 1225 read_lock(&tasklist_lock); /* arm_timer needs it. */
ian@0 1226 } else {
ian@0 1227 read_lock(&tasklist_lock);
ian@0 1228 if (unlikely(p->signal == NULL)) {
ian@0 1229 /*
ian@0 1230 * The process has been reaped.
ian@0 1231 * We can't even collect a sample any more.
ian@0 1232 */
ian@0 1233 put_task_struct(p);
ian@0 1234 timer->it.cpu.task = p = NULL;
ian@0 1235 timer->it.cpu.expires.sched = 0;
ian@0 1236 goto out_unlock;
ian@0 1237 } else if (unlikely(p->exit_state) && thread_group_empty(p)) {
ian@0 1238 /*
ian@0 1239 * We've noticed that the thread is dead, but
ian@0 1240 * not yet reaped. Take this opportunity to
ian@0 1241 * drop our task ref.
ian@0 1242 */
ian@0 1243 clear_dead_task(timer, now);
ian@0 1244 goto out_unlock;
ian@0 1245 }
ian@0 1246 cpu_clock_sample_group(timer->it_clock, p, &now);
ian@0 1247 bump_cpu_timer(timer, now);
ian@0 1248 /* Leave the tasklist_lock locked for the call below. */
ian@0 1249 }
ian@0 1250
ian@0 1251 /*
ian@0 1252 * Now re-arm for the new expiry time.
ian@0 1253 */
ian@0 1254 arm_timer(timer, now);
ian@0 1255
ian@0 1256 out_unlock:
ian@0 1257 read_unlock(&tasklist_lock);
ian@0 1258
ian@0 1259 out:
ian@0 1260 timer->it_overrun_last = timer->it_overrun;
ian@0 1261 timer->it_overrun = -1;
ian@0 1262 ++timer->it_requeue_pending;
ian@0 1263 }
ian@0 1264
ian@0 1265 /*
ian@0 1266 * This is called from the timer interrupt handler. The irq handler has
ian@0 1267 * already updated our counts. We need to check if any timers fire now.
ian@0 1268 * Interrupts are disabled.
ian@0 1269 */
ian@0 1270 void run_posix_cpu_timers(struct task_struct *tsk)
ian@0 1271 {
ian@0 1272 LIST_HEAD(firing);
ian@0 1273 struct k_itimer *timer, *next;
ian@0 1274
ian@0 1275 BUG_ON(!irqs_disabled());
ian@0 1276
ian@0 1277 #define UNEXPIRED(clock) \
ian@0 1278 (cputime_eq(tsk->it_##clock##_expires, cputime_zero) || \
ian@0 1279 cputime_lt(clock##_ticks(tsk), tsk->it_##clock##_expires))
ian@0 1280
ian@0 1281 if (UNEXPIRED(prof) && UNEXPIRED(virt) &&
ian@0 1282 (tsk->it_sched_expires == 0 ||
ian@0 1283 tsk->sched_time < tsk->it_sched_expires))
ian@0 1284 return;
ian@0 1285
ian@0 1286 #undef UNEXPIRED
ian@0 1287
ian@0 1288 /*
ian@0 1289 * Double-check with locks held.
ian@0 1290 */
ian@0 1291 read_lock(&tasklist_lock);
ian@0 1292 if (likely(tsk->signal != NULL)) {
ian@0 1293 spin_lock(&tsk->sighand->siglock);
ian@0 1294
ian@0 1295 /*
ian@0 1296 * Here we take off tsk->cpu_timers[N] and tsk->signal->cpu_timers[N]
ian@0 1297 * all the timers that are firing, and put them on the firing list.
ian@0 1298 */
ian@0 1299 check_thread_timers(tsk, &firing);
ian@0 1300 check_process_timers(tsk, &firing);
ian@0 1301
ian@0 1302 /*
ian@0 1303 * We must release these locks before taking any timer's lock.
ian@0 1304 * There is a potential race with timer deletion here, as the
ian@0 1305 * siglock now protects our private firing list. We have set
ian@0 1306 * the firing flag in each timer, so that a deletion attempt
ian@0 1307 * that gets the timer lock before we do will give it up and
ian@0 1308 * spin until we've taken care of that timer below.
ian@0 1309 */
ian@0 1310 spin_unlock(&tsk->sighand->siglock);
ian@0 1311 }
ian@0 1312 read_unlock(&tasklist_lock);
ian@0 1313
ian@0 1314 /*
ian@0 1315 * Now that all the timers on our list have the firing flag,
ian@0 1316 * noone will touch their list entries but us. We'll take
ian@0 1317 * each timer's lock before clearing its firing flag, so no
ian@0 1318 * timer call will interfere.
ian@0 1319 */
ian@0 1320 list_for_each_entry_safe(timer, next, &firing, it.cpu.entry) {
ian@0 1321 int firing;
ian@0 1322 spin_lock(&timer->it_lock);
ian@0 1323 list_del_init(&timer->it.cpu.entry);
ian@0 1324 firing = timer->it.cpu.firing;
ian@0 1325 timer->it.cpu.firing = 0;
ian@0 1326 /*
ian@0 1327 * The firing flag is -1 if we collided with a reset
ian@0 1328 * of the timer, which already reported this
ian@0 1329 * almost-firing as an overrun. So don't generate an event.
ian@0 1330 */
ian@0 1331 if (likely(firing >= 0)) {
ian@0 1332 cpu_timer_fire(timer);
ian@0 1333 }
ian@0 1334 spin_unlock(&timer->it_lock);
ian@0 1335 }
ian@0 1336 }
ian@0 1337
ian@0 1338 /*
ian@0 1339 * Set one of the process-wide special case CPU timers.
ian@0 1340 * The tasklist_lock and tsk->sighand->siglock must be held by the caller.
ian@0 1341 * The oldval argument is null for the RLIMIT_CPU timer, where *newval is
ian@0 1342 * absolute; non-null for ITIMER_*, where *newval is relative and we update
ian@0 1343 * it to be absolute, *oldval is absolute and we update it to be relative.
ian@0 1344 */
ian@0 1345 void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
ian@0 1346 cputime_t *newval, cputime_t *oldval)
ian@0 1347 {
ian@0 1348 union cpu_time_count now;
ian@0 1349 struct list_head *head;
ian@0 1350
ian@0 1351 BUG_ON(clock_idx == CPUCLOCK_SCHED);
ian@0 1352 cpu_clock_sample_group_locked(clock_idx, tsk, &now);
ian@0 1353
ian@0 1354 if (oldval) {
ian@0 1355 if (!cputime_eq(*oldval, cputime_zero)) {
ian@0 1356 if (cputime_le(*oldval, now.cpu)) {
ian@0 1357 /* Just about to fire. */
ian@0 1358 *oldval = jiffies_to_cputime(1);
ian@0 1359 } else {
ian@0 1360 *oldval = cputime_sub(*oldval, now.cpu);
ian@0 1361 }
ian@0 1362 }
ian@0 1363
ian@0 1364 if (cputime_eq(*newval, cputime_zero))
ian@0 1365 return;
ian@0 1366 *newval = cputime_add(*newval, now.cpu);
ian@0 1367
ian@0 1368 /*
ian@0 1369 * If the RLIMIT_CPU timer will expire before the
ian@0 1370 * ITIMER_PROF timer, we have nothing else to do.
ian@0 1371 */
ian@0 1372 if (tsk->signal->rlim[RLIMIT_CPU].rlim_cur
ian@0 1373 < cputime_to_secs(*newval))
ian@0 1374 return;
ian@0 1375 }
ian@0 1376
ian@0 1377 /*
ian@0 1378 * Check whether there are any process timers already set to fire
ian@0 1379 * before this one. If so, we don't have anything more to do.
ian@0 1380 */
ian@0 1381 head = &tsk->signal->cpu_timers[clock_idx];
ian@0 1382 if (list_empty(head) ||
ian@0 1383 cputime_ge(list_entry(head->next,
ian@0 1384 struct cpu_timer_list, entry)->expires.cpu,
ian@0 1385 *newval)) {
ian@0 1386 /*
ian@0 1387 * Rejigger each thread's expiry time so that one will
ian@0 1388 * notice before we hit the process-cumulative expiry time.
ian@0 1389 */
ian@0 1390 union cpu_time_count expires = { .sched = 0 };
ian@0 1391 expires.cpu = *newval;
ian@0 1392 process_timer_rebalance(tsk, clock_idx, expires, now);
ian@0 1393 }
ian@0 1394 }
ian@0 1395
ian@0 1396 static long posix_cpu_clock_nanosleep_restart(struct restart_block *);
ian@0 1397
ian@0 1398 int posix_cpu_nsleep(const clockid_t which_clock, int flags,
ian@0 1399 struct timespec *rqtp, struct timespec __user *rmtp)
ian@0 1400 {
ian@0 1401 struct restart_block *restart_block =
ian@0 1402 &current_thread_info()->restart_block;
ian@0 1403 struct k_itimer timer;
ian@0 1404 int error;
ian@0 1405
ian@0 1406 /*
ian@0 1407 * Diagnose required errors first.
ian@0 1408 */
ian@0 1409 if (CPUCLOCK_PERTHREAD(which_clock) &&
ian@0 1410 (CPUCLOCK_PID(which_clock) == 0 ||
ian@0 1411 CPUCLOCK_PID(which_clock) == current->pid))
ian@0 1412 return -EINVAL;
ian@0 1413
ian@0 1414 /*
ian@0 1415 * Set up a temporary timer and then wait for it to go off.
ian@0 1416 */
ian@0 1417 memset(&timer, 0, sizeof timer);
ian@0 1418 spin_lock_init(&timer.it_lock);
ian@0 1419 timer.it_clock = which_clock;
ian@0 1420 timer.it_overrun = -1;
ian@0 1421 error = posix_cpu_timer_create(&timer);
ian@0 1422 timer.it_process = current;
ian@0 1423 if (!error) {
ian@0 1424 static struct itimerspec zero_it;
ian@0 1425 struct itimerspec it = { .it_value = *rqtp,
ian@0 1426 .it_interval = {} };
ian@0 1427
ian@0 1428 spin_lock_irq(&timer.it_lock);
ian@0 1429 error = posix_cpu_timer_set(&timer, flags, &it, NULL);
ian@0 1430 if (error) {
ian@0 1431 spin_unlock_irq(&timer.it_lock);
ian@0 1432 return error;
ian@0 1433 }
ian@0 1434
ian@0 1435 while (!signal_pending(current)) {
ian@0 1436 if (timer.it.cpu.expires.sched == 0) {
ian@0 1437 /*
ian@0 1438 * Our timer fired and was reset.
ian@0 1439 */
ian@0 1440 spin_unlock_irq(&timer.it_lock);
ian@0 1441 return 0;
ian@0 1442 }
ian@0 1443
ian@0 1444 /*
ian@0 1445 * Block until cpu_timer_fire (or a signal) wakes us.
ian@0 1446 */
ian@0 1447 __set_current_state(TASK_INTERRUPTIBLE);
ian@0 1448 spin_unlock_irq(&timer.it_lock);
ian@0 1449 schedule();
ian@0 1450 spin_lock_irq(&timer.it_lock);
ian@0 1451 }
ian@0 1452
ian@0 1453 /*
ian@0 1454 * We were interrupted by a signal.
ian@0 1455 */
ian@0 1456 sample_to_timespec(which_clock, timer.it.cpu.expires, rqtp);
ian@0 1457 posix_cpu_timer_set(&timer, 0, &zero_it, &it);
ian@0 1458 spin_unlock_irq(&timer.it_lock);
ian@0 1459
ian@0 1460 if ((it.it_value.tv_sec | it.it_value.tv_nsec) == 0) {
ian@0 1461 /*
ian@0 1462 * It actually did fire already.
ian@0 1463 */
ian@0 1464 return 0;
ian@0 1465 }
ian@0 1466
ian@0 1467 /*
ian@0 1468 * Report back to the user the time still remaining.
ian@0 1469 */
ian@0 1470 if (rmtp != NULL && !(flags & TIMER_ABSTIME) &&
ian@0 1471 copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
ian@0 1472 return -EFAULT;
ian@0 1473
ian@0 1474 restart_block->fn = posix_cpu_clock_nanosleep_restart;
ian@0 1475 /* Caller already set restart_block->arg1 */
ian@0 1476 restart_block->arg0 = which_clock;
ian@0 1477 restart_block->arg1 = (unsigned long) rmtp;
ian@0 1478 restart_block->arg2 = rqtp->tv_sec;
ian@0 1479 restart_block->arg3 = rqtp->tv_nsec;
ian@0 1480
ian@0 1481 error = -ERESTART_RESTARTBLOCK;
ian@0 1482 }
ian@0 1483
ian@0 1484 return error;
ian@0 1485 }
ian@0 1486
ian@0 1487 static long
ian@0 1488 posix_cpu_clock_nanosleep_restart(struct restart_block *restart_block)
ian@0 1489 {
ian@0 1490 clockid_t which_clock = restart_block->arg0;
ian@0 1491 struct timespec __user *rmtp;
ian@0 1492 struct timespec t;
ian@0 1493
ian@0 1494 rmtp = (struct timespec __user *) restart_block->arg1;
ian@0 1495 t.tv_sec = restart_block->arg2;
ian@0 1496 t.tv_nsec = restart_block->arg3;
ian@0 1497
ian@0 1498 restart_block->fn = do_no_restart_syscall;
ian@0 1499 return posix_cpu_nsleep(which_clock, TIMER_ABSTIME, &t, rmtp);
ian@0 1500 }
ian@0 1501
ian@0 1502
ian@0 1503 #define PROCESS_CLOCK MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED)
ian@0 1504 #define THREAD_CLOCK MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED)
ian@0 1505
ian@0 1506 static int process_cpu_clock_getres(const clockid_t which_clock,
ian@0 1507 struct timespec *tp)
ian@0 1508 {
ian@0 1509 return posix_cpu_clock_getres(PROCESS_CLOCK, tp);
ian@0 1510 }
ian@0 1511 static int process_cpu_clock_get(const clockid_t which_clock,
ian@0 1512 struct timespec *tp)
ian@0 1513 {
ian@0 1514 return posix_cpu_clock_get(PROCESS_CLOCK, tp);
ian@0 1515 }
ian@0 1516 static int process_cpu_timer_create(struct k_itimer *timer)
ian@0 1517 {
ian@0 1518 timer->it_clock = PROCESS_CLOCK;
ian@0 1519 return posix_cpu_timer_create(timer);
ian@0 1520 }
ian@0 1521 static int process_cpu_nsleep(const clockid_t which_clock, int flags,
ian@0 1522 struct timespec *rqtp,
ian@0 1523 struct timespec __user *rmtp)
ian@0 1524 {
ian@0 1525 return posix_cpu_nsleep(PROCESS_CLOCK, flags, rqtp, rmtp);
ian@0 1526 }
ian@0 1527 static int thread_cpu_clock_getres(const clockid_t which_clock,
ian@0 1528 struct timespec *tp)
ian@0 1529 {
ian@0 1530 return posix_cpu_clock_getres(THREAD_CLOCK, tp);
ian@0 1531 }
ian@0 1532 static int thread_cpu_clock_get(const clockid_t which_clock,
ian@0 1533 struct timespec *tp)
ian@0 1534 {
ian@0 1535 return posix_cpu_clock_get(THREAD_CLOCK, tp);
ian@0 1536 }
ian@0 1537 static int thread_cpu_timer_create(struct k_itimer *timer)
ian@0 1538 {
ian@0 1539 timer->it_clock = THREAD_CLOCK;
ian@0 1540 return posix_cpu_timer_create(timer);
ian@0 1541 }
ian@0 1542 static int thread_cpu_nsleep(const clockid_t which_clock, int flags,
ian@0 1543 struct timespec *rqtp, struct timespec __user *rmtp)
ian@0 1544 {
ian@0 1545 return -EINVAL;
ian@0 1546 }
ian@0 1547
ian@0 1548 static __init int init_posix_cpu_timers(void)
ian@0 1549 {
ian@0 1550 struct k_clock process = {
ian@0 1551 .clock_getres = process_cpu_clock_getres,
ian@0 1552 .clock_get = process_cpu_clock_get,
ian@0 1553 .clock_set = do_posix_clock_nosettime,
ian@0 1554 .timer_create = process_cpu_timer_create,
ian@0 1555 .nsleep = process_cpu_nsleep,
ian@0 1556 };
ian@0 1557 struct k_clock thread = {
ian@0 1558 .clock_getres = thread_cpu_clock_getres,
ian@0 1559 .clock_get = thread_cpu_clock_get,
ian@0 1560 .clock_set = do_posix_clock_nosettime,
ian@0 1561 .timer_create = thread_cpu_timer_create,
ian@0 1562 .nsleep = thread_cpu_nsleep,
ian@0 1563 };
ian@0 1564
ian@0 1565 register_posix_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
ian@0 1566 register_posix_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
ian@0 1567
ian@0 1568 return 0;
ian@0 1569 }
ian@0 1570 __initcall(init_posix_cpu_timers);