Commit 9556ad6a authored by Thomas Gleixner's avatar Thomas Gleixner

Merge branch 'fortglx/4.11/time' of...

Merge branch 'fortglx/4.11/time' of https://git.linaro.org/people/john.stultz/linux into timers/core

 - Remove unused functions
 - Document udelay inaccuracy
 - Remove posix timer data from task struct when posix timers are off
parents 4c45c516 b18b6a9c
...@@ -2179,7 +2179,7 @@ static const struct file_operations proc_map_files_operations = { ...@@ -2179,7 +2179,7 @@ static const struct file_operations proc_map_files_operations = {
.llseek = generic_file_llseek, .llseek = generic_file_llseek,
}; };
#ifdef CONFIG_CHECKPOINT_RESTORE #if defined(CONFIG_CHECKPOINT_RESTORE) && defined(CONFIG_POSIX_TIMERS)
struct timers_private { struct timers_private {
struct pid *pid; struct pid *pid;
struct task_struct *task; struct task_struct *task;
...@@ -2936,7 +2936,7 @@ static const struct pid_entry tgid_base_stuff[] = { ...@@ -2936,7 +2936,7 @@ static const struct pid_entry tgid_base_stuff[] = {
REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations), REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
REG("setgroups", S_IRUGO|S_IWUSR, proc_setgroups_operations), REG("setgroups", S_IRUGO|S_IWUSR, proc_setgroups_operations),
#endif #endif
#ifdef CONFIG_CHECKPOINT_RESTORE #if defined(CONFIG_CHECKPOINT_RESTORE) && defined(CONFIG_POSIX_TIMERS)
REG("timers", S_IRUGO, proc_timers_operations), REG("timers", S_IRUGO, proc_timers_operations),
#endif #endif
REG("timerslack_ns", S_IRUGO|S_IWUGO, proc_pid_set_timerslack_ns_operations), REG("timerslack_ns", S_IRUGO|S_IWUGO, proc_pid_set_timerslack_ns_operations),
......
...@@ -5,6 +5,17 @@ ...@@ -5,6 +5,17 @@
* Copyright (C) 1993 Linus Torvalds * Copyright (C) 1993 Linus Torvalds
* *
* Delay routines, using a pre-computed "loops_per_jiffy" value. * Delay routines, using a pre-computed "loops_per_jiffy" value.
*
* Please note that ndelay(), udelay() and mdelay() may return early for
* several reasons:
* 1. computed loops_per_jiffy too low (due to the time taken to
* execute the timer interrupt.)
* 2. cache behaviour affecting the time it takes to execute the
* loop function.
* 3. CPU clock rate changes.
*
* Please see this thread:
* http://lists.openwall.net/linux-kernel/2011/01/09/56
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
......
...@@ -42,6 +42,27 @@ extern struct fs_struct init_fs; ...@@ -42,6 +42,27 @@ extern struct fs_struct init_fs;
#define INIT_PREV_CPUTIME(x) #define INIT_PREV_CPUTIME(x)
#endif #endif
#ifdef CONFIG_POSIX_TIMERS
#define INIT_POSIX_TIMERS(s) \
.posix_timers = LIST_HEAD_INIT(s.posix_timers),
#define INIT_CPU_TIMERS(s) \
.cpu_timers = { \
LIST_HEAD_INIT(s.cpu_timers[0]), \
LIST_HEAD_INIT(s.cpu_timers[1]), \
LIST_HEAD_INIT(s.cpu_timers[2]), \
},
#define INIT_CPUTIMER(s) \
.cputimer = { \
.cputime_atomic = INIT_CPUTIME_ATOMIC, \
.running = false, \
.checking_timer = false, \
},
#else
#define INIT_POSIX_TIMERS(s)
#define INIT_CPU_TIMERS(s)
#define INIT_CPUTIMER(s)
#endif
#define INIT_SIGNALS(sig) { \ #define INIT_SIGNALS(sig) { \
.nr_threads = 1, \ .nr_threads = 1, \
.thread_head = LIST_HEAD_INIT(init_task.thread_node), \ .thread_head = LIST_HEAD_INIT(init_task.thread_node), \
...@@ -49,14 +70,10 @@ extern struct fs_struct init_fs; ...@@ -49,14 +70,10 @@ extern struct fs_struct init_fs;
.shared_pending = { \ .shared_pending = { \
.list = LIST_HEAD_INIT(sig.shared_pending.list), \ .list = LIST_HEAD_INIT(sig.shared_pending.list), \
.signal = {{0}}}, \ .signal = {{0}}}, \
.posix_timers = LIST_HEAD_INIT(sig.posix_timers), \ INIT_POSIX_TIMERS(sig) \
.cpu_timers = INIT_CPU_TIMERS(sig.cpu_timers), \ INIT_CPU_TIMERS(sig) \
.rlim = INIT_RLIMITS, \ .rlim = INIT_RLIMITS, \
.cputimer = { \ INIT_CPUTIMER(sig) \
.cputime_atomic = INIT_CPUTIME_ATOMIC, \
.running = false, \
.checking_timer = false, \
}, \
INIT_PREV_CPUTIME(sig) \ INIT_PREV_CPUTIME(sig) \
.cred_guard_mutex = \ .cred_guard_mutex = \
__MUTEX_INITIALIZER(sig.cred_guard_mutex), \ __MUTEX_INITIALIZER(sig.cred_guard_mutex), \
...@@ -247,7 +264,7 @@ extern struct task_group root_task_group; ...@@ -247,7 +264,7 @@ extern struct task_group root_task_group;
.blocked = {{0}}, \ .blocked = {{0}}, \
.alloc_lock = __SPIN_LOCK_UNLOCKED(tsk.alloc_lock), \ .alloc_lock = __SPIN_LOCK_UNLOCKED(tsk.alloc_lock), \
.journal_info = NULL, \ .journal_info = NULL, \
.cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ INIT_CPU_TIMERS(tsk) \
.pi_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock), \ .pi_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock), \
.timer_slack_ns = 50000, /* 50 usec default slack */ \ .timer_slack_ns = 50000, /* 50 usec default slack */ \
.pids = { \ .pids = { \
...@@ -274,13 +291,6 @@ extern struct task_group root_task_group; ...@@ -274,13 +291,6 @@ extern struct task_group root_task_group;
} }
#define INIT_CPU_TIMERS(cpu_timers) \
{ \
LIST_HEAD_INIT(cpu_timers[0]), \
LIST_HEAD_INIT(cpu_timers[1]), \
LIST_HEAD_INIT(cpu_timers[2]), \
}
/* Attach to the init_task data structure for proper alignment */ /* Attach to the init_task data structure for proper alignment */
#define __init_task_data __attribute__((__section__(".data..init_task"))) #define __init_task_data __attribute__((__section__(".data..init_task")))
......
...@@ -734,13 +734,14 @@ struct signal_struct { ...@@ -734,13 +734,14 @@ struct signal_struct {
unsigned int is_child_subreaper:1; unsigned int is_child_subreaper:1;
unsigned int has_child_subreaper:1; unsigned int has_child_subreaper:1;
#ifdef CONFIG_POSIX_TIMERS
/* POSIX.1b Interval Timers */ /* POSIX.1b Interval Timers */
int posix_timer_id; int posix_timer_id;
struct list_head posix_timers; struct list_head posix_timers;
/* ITIMER_REAL timer for the process */ /* ITIMER_REAL timer for the process */
struct hrtimer real_timer; struct hrtimer real_timer;
struct pid *leader_pid;
ktime_t it_real_incr; ktime_t it_real_incr;
/* /*
...@@ -759,12 +760,16 @@ struct signal_struct { ...@@ -759,12 +760,16 @@ struct signal_struct {
/* Earliest-expiration cache. */ /* Earliest-expiration cache. */
struct task_cputime cputime_expires; struct task_cputime cputime_expires;
struct list_head cpu_timers[3];
#endif
struct pid *leader_pid;
#ifdef CONFIG_NO_HZ_FULL #ifdef CONFIG_NO_HZ_FULL
atomic_t tick_dep_mask; atomic_t tick_dep_mask;
#endif #endif
struct list_head cpu_timers[3];
struct pid *tty_old_pgrp; struct pid *tty_old_pgrp;
/* boolean value for session group leader */ /* boolean value for session group leader */
...@@ -1691,8 +1696,10 @@ struct task_struct { ...@@ -1691,8 +1696,10 @@ struct task_struct {
/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */ /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
unsigned long min_flt, maj_flt; unsigned long min_flt, maj_flt;
#ifdef CONFIG_POSIX_TIMERS
struct task_cputime cputime_expires; struct task_cputime cputime_expires;
struct list_head cpu_timers[3]; struct list_head cpu_timers[3];
#endif
/* process credentials */ /* process credentials */
const struct cred __rcu *ptracer_cred; /* Tracer's credentials at attach */ const struct cred __rcu *ptracer_cred; /* Tracer's credentials at attach */
......
...@@ -1304,6 +1304,7 @@ void __cleanup_sighand(struct sighand_struct *sighand) ...@@ -1304,6 +1304,7 @@ void __cleanup_sighand(struct sighand_struct *sighand)
} }
} }
#ifdef CONFIG_POSIX_TIMERS
/* /*
* Initialize POSIX timer handling for a thread group. * Initialize POSIX timer handling for a thread group.
*/ */
...@@ -1322,6 +1323,9 @@ static void posix_cpu_timers_init_group(struct signal_struct *sig) ...@@ -1322,6 +1323,9 @@ static void posix_cpu_timers_init_group(struct signal_struct *sig)
INIT_LIST_HEAD(&sig->cpu_timers[1]); INIT_LIST_HEAD(&sig->cpu_timers[1]);
INIT_LIST_HEAD(&sig->cpu_timers[2]); INIT_LIST_HEAD(&sig->cpu_timers[2]);
} }
#else
static inline void posix_cpu_timers_init_group(struct signal_struct *sig) { }
#endif
static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
{ {
...@@ -1346,11 +1350,11 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) ...@@ -1346,11 +1350,11 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
init_waitqueue_head(&sig->wait_chldexit); init_waitqueue_head(&sig->wait_chldexit);
sig->curr_target = tsk; sig->curr_target = tsk;
init_sigpending(&sig->shared_pending); init_sigpending(&sig->shared_pending);
INIT_LIST_HEAD(&sig->posix_timers);
seqlock_init(&sig->stats_lock); seqlock_init(&sig->stats_lock);
prev_cputime_init(&sig->prev_cputime); prev_cputime_init(&sig->prev_cputime);
#ifdef CONFIG_POSIX_TIMERS #ifdef CONFIG_POSIX_TIMERS
INIT_LIST_HEAD(&sig->posix_timers);
hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
sig->real_timer.function = it_real_fn; sig->real_timer.function = it_real_fn;
#endif #endif
...@@ -1425,6 +1429,7 @@ static void rt_mutex_init_task(struct task_struct *p) ...@@ -1425,6 +1429,7 @@ static void rt_mutex_init_task(struct task_struct *p)
#endif #endif
} }
#ifdef CONFIG_POSIX_TIMERS
/* /*
* Initialize POSIX timer handling for a single task. * Initialize POSIX timer handling for a single task.
*/ */
...@@ -1437,6 +1442,9 @@ static void posix_cpu_timers_init(struct task_struct *tsk) ...@@ -1437,6 +1442,9 @@ static void posix_cpu_timers_init(struct task_struct *tsk)
INIT_LIST_HEAD(&tsk->cpu_timers[1]); INIT_LIST_HEAD(&tsk->cpu_timers[1]);
INIT_LIST_HEAD(&tsk->cpu_timers[2]); INIT_LIST_HEAD(&tsk->cpu_timers[2]);
} }
#else
static inline void posix_cpu_timers_init(struct task_struct *tsk) { }
#endif
static inline void static inline void
init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid) init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
......
...@@ -2246,6 +2246,7 @@ prio_changed_rt(struct rq *rq, struct task_struct *p, int oldprio) ...@@ -2246,6 +2246,7 @@ prio_changed_rt(struct rq *rq, struct task_struct *p, int oldprio)
} }
} }
#ifdef CONFIG_POSIX_TIMERS
static void watchdog(struct rq *rq, struct task_struct *p) static void watchdog(struct rq *rq, struct task_struct *p)
{ {
unsigned long soft, hard; unsigned long soft, hard;
...@@ -2267,6 +2268,9 @@ static void watchdog(struct rq *rq, struct task_struct *p) ...@@ -2267,6 +2268,9 @@ static void watchdog(struct rq *rq, struct task_struct *p)
p->cputime_expires.sched_exp = p->se.sum_exec_runtime; p->cputime_expires.sched_exp = p->se.sum_exec_runtime;
} }
} }
#else
static inline void watchdog(struct rq *rq, struct task_struct *p) { }
#endif
static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued) static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued)
{ {
......
...@@ -172,18 +172,19 @@ sched_info_switch(struct rq *rq, ...@@ -172,18 +172,19 @@ sched_info_switch(struct rq *rq,
*/ */
/** /**
* cputimer_running - return true if cputimer is running * get_running_cputimer - return &tsk->signal->cputimer if cputimer is running
* *
* @tsk: Pointer to target task. * @tsk: Pointer to target task.
*/ */
static inline bool cputimer_running(struct task_struct *tsk) #ifdef CONFIG_POSIX_TIMERS
static inline
struct thread_group_cputimer *get_running_cputimer(struct task_struct *tsk)
{ {
struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
/* Check if cputimer isn't running. This is accessed without locking. */ /* Check if cputimer isn't running. This is accessed without locking. */
if (!READ_ONCE(cputimer->running)) if (!READ_ONCE(cputimer->running))
return false; return NULL;
/* /*
* After we flush the task's sum_exec_runtime to sig->sum_sched_runtime * After we flush the task's sum_exec_runtime to sig->sum_sched_runtime
...@@ -200,10 +201,17 @@ static inline bool cputimer_running(struct task_struct *tsk) ...@@ -200,10 +201,17 @@ static inline bool cputimer_running(struct task_struct *tsk)
* clock delta is behind the expiring timer value. * clock delta is behind the expiring timer value.
*/ */
if (unlikely(!tsk->sighand)) if (unlikely(!tsk->sighand))
return false; return NULL;
return true; return cputimer;
}
#else
static inline
struct thread_group_cputimer *get_running_cputimer(struct task_struct *tsk)
{
return NULL;
} }
#endif
/** /**
* account_group_user_time - Maintain utime for a thread group. * account_group_user_time - Maintain utime for a thread group.
...@@ -218,9 +226,9 @@ static inline bool cputimer_running(struct task_struct *tsk) ...@@ -218,9 +226,9 @@ static inline bool cputimer_running(struct task_struct *tsk)
static inline void account_group_user_time(struct task_struct *tsk, static inline void account_group_user_time(struct task_struct *tsk,
cputime_t cputime) cputime_t cputime)
{ {
struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; struct thread_group_cputimer *cputimer = get_running_cputimer(tsk);
if (!cputimer_running(tsk)) if (!cputimer)
return; return;
atomic64_add(cputime, &cputimer->cputime_atomic.utime); atomic64_add(cputime, &cputimer->cputime_atomic.utime);
...@@ -239,9 +247,9 @@ static inline void account_group_user_time(struct task_struct *tsk, ...@@ -239,9 +247,9 @@ static inline void account_group_user_time(struct task_struct *tsk,
static inline void account_group_system_time(struct task_struct *tsk, static inline void account_group_system_time(struct task_struct *tsk,
cputime_t cputime) cputime_t cputime)
{ {
struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; struct thread_group_cputimer *cputimer = get_running_cputimer(tsk);
if (!cputimer_running(tsk)) if (!cputimer)
return; return;
atomic64_add(cputime, &cputimer->cputime_atomic.stime); atomic64_add(cputime, &cputimer->cputime_atomic.stime);
...@@ -260,9 +268,9 @@ static inline void account_group_system_time(struct task_struct *tsk, ...@@ -260,9 +268,9 @@ static inline void account_group_system_time(struct task_struct *tsk,
static inline void account_group_exec_runtime(struct task_struct *tsk, static inline void account_group_exec_runtime(struct task_struct *tsk,
unsigned long long ns) unsigned long long ns)
{ {
struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; struct thread_group_cputimer *cputimer = get_running_cputimer(tsk);
if (!cputimer_running(tsk)) if (!cputimer)
return; return;
atomic64_add(ns, &cputimer->cputime_atomic.sum_exec_runtime); atomic64_add(ns, &cputimer->cputime_atomic.sum_exec_runtime);
......
...@@ -1275,27 +1275,8 @@ int timekeeping_inject_offset(struct timespec *ts) ...@@ -1275,27 +1275,8 @@ int timekeeping_inject_offset(struct timespec *ts)
} }
EXPORT_SYMBOL(timekeeping_inject_offset); EXPORT_SYMBOL(timekeeping_inject_offset);
/**
* timekeeping_get_tai_offset - Returns current TAI offset from UTC
*
*/
s32 timekeeping_get_tai_offset(void)
{
struct timekeeper *tk = &tk_core.timekeeper;
unsigned int seq;
s32 ret;
do {
seq = read_seqcount_begin(&tk_core.seq);
ret = tk->tai_offset;
} while (read_seqcount_retry(&tk_core.seq, seq));
return ret;
}
/** /**
* __timekeeping_set_tai_offset - Lock free worker function * __timekeeping_set_tai_offset - Sets the TAI offset from UTC and monotonic
* *
*/ */
static void __timekeeping_set_tai_offset(struct timekeeper *tk, s32 tai_offset) static void __timekeeping_set_tai_offset(struct timekeeper *tk, s32 tai_offset)
...@@ -1304,24 +1285,6 @@ static void __timekeeping_set_tai_offset(struct timekeeper *tk, s32 tai_offset) ...@@ -1304,24 +1285,6 @@ static void __timekeeping_set_tai_offset(struct timekeeper *tk, s32 tai_offset)
tk->offs_tai = ktime_add(tk->offs_real, ktime_set(tai_offset, 0)); tk->offs_tai = ktime_add(tk->offs_real, ktime_set(tai_offset, 0));
} }
/**
* timekeeping_set_tai_offset - Sets the current TAI offset from UTC
*
*/
void timekeeping_set_tai_offset(s32 tai_offset)
{
struct timekeeper *tk = &tk_core.timekeeper;
unsigned long flags;
raw_spin_lock_irqsave(&timekeeper_lock, flags);
write_seqcount_begin(&tk_core.seq);
__timekeeping_set_tai_offset(tk, tai_offset);
timekeeping_update(tk, TK_MIRROR | TK_CLOCK_WAS_SET);
write_seqcount_end(&tk_core.seq);
raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
clock_was_set();
}
/** /**
* change_clocksource - Swaps clocksources if a new one is available * change_clocksource - Swaps clocksources if a new one is available
* *
......
...@@ -11,8 +11,6 @@ extern ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ...@@ -11,8 +11,6 @@ extern ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq,
extern int timekeeping_valid_for_hres(void); extern int timekeeping_valid_for_hres(void);
extern u64 timekeeping_max_deferment(void); extern u64 timekeeping_max_deferment(void);
extern int timekeeping_inject_offset(struct timespec *ts); extern int timekeeping_inject_offset(struct timespec *ts);
extern s32 timekeeping_get_tai_offset(void);
extern void timekeeping_set_tai_offset(s32 tai_offset);
extern int timekeeping_suspend(void); extern int timekeeping_suspend(void);
extern void timekeeping_resume(void); extern void timekeeping_resume(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment