Commit e436d80085133858bf2613a630365e8a0459fd58
1 parent
969bb4e403
Exists in
master
and in
20 other branches
[PATCH] sched: implement cpu_clock(cpu) high-speed time source
Implement the cpu_clock(cpu) interface for kernel-internal use: high-speed (but slightly incorrect) per-cpu clock constructed from sched_clock(). This API, unused at the moment, will be used in the future by blktrace, by the softlockup-watchdog, by printk and by lockstat. Signed-off-by: Ingo Molnar <mingo@elte.hu>
Showing 2 changed files with 24 additions and 0 deletions Side-by-side Diff
include/linux/sched.h
... | ... | @@ -1348,6 +1348,13 @@ |
1348 | 1348 | #endif |
1349 | 1349 | |
1350 | 1350 | extern unsigned long long sched_clock(void); |
1351 | + | |
1352 | +/* | |
1353 | + * For kernel-internal use: high-speed (but slightly incorrect) per-cpu | |
1354 | + * clock constructed from sched_clock(): | |
1355 | + */ | |
1356 | +extern unsigned long long cpu_clock(int cpu); | |
1357 | + | |
1351 | 1358 | extern unsigned long long |
1352 | 1359 | task_sched_runtime(struct task_struct *task); |
1353 | 1360 |
kernel/sched.c
... | ... | @@ -379,6 +379,23 @@ |
379 | 379 | #define task_rq(p) cpu_rq(task_cpu(p)) |
380 | 380 | #define cpu_curr(cpu) (cpu_rq(cpu)->curr) |
381 | 381 | |
382 | +/* | |
383 | + * For kernel-internal use: high-speed (but slightly incorrect) per-cpu | |
384 | + * clock constructed from sched_clock(): | |
385 | + */ | |
386 | +unsigned long long cpu_clock(int cpu) | |
387 | +{ | |
388 | + struct rq *rq = cpu_rq(cpu); | |
389 | + unsigned long long now; | |
390 | + unsigned long flags; | |
391 | + | |
392 | + spin_lock_irqsave(&rq->lock, flags); | |
393 | + now = rq_clock(rq); | |
394 | + spin_unlock_irqrestore(&rq->lock, flags); | |
395 | + | |
396 | + return now; | |
397 | +} | |
398 | + | |
382 | 399 | #ifdef CONFIG_FAIR_GROUP_SCHED |
383 | 400 | /* Change a task's ->cfs_rq if it moves across CPUs */ |
384 | 401 | static inline void set_task_cfs_rq(struct task_struct *p) |