return ~(clk >> 3);
}
+/*
+ * Alternate field names for struct task_cputime when used on cache
+ * expirations. Will go away soon.
+ */
+#define virt_exp utime
+#define prof_exp stime
+#define sched_exp sum_exec_runtime
+
#ifdef CONFIG_POSIX_TIMERS
/**
* posix_cputimers - Container for posix CPU timer related data
+ * @cputime_expires: Earliest-expiration cache
* @cpu_timers: List heads to queue posix CPU timers
*
* Used in task_struct and signal_struct
*/
struct posix_cputimers {
+ struct task_cputime cputime_expires;
struct list_head cpu_timers[CPUCLOCK_MAX];
};
static inline void posix_cputimers_init(struct posix_cputimers *pct)
{
+ memset(&pct->cputime_expires, 0, sizeof(pct->cputime_expires));
INIT_LIST_HEAD(&pct->cpu_timers[0]);
INIT_LIST_HEAD(&pct->cpu_timers[1]);
INIT_LIST_HEAD(&pct->cpu_timers[2]);
}
+void posix_cputimers_group_init(struct posix_cputimers *pct, u64 cpu_limit);
+
+static inline void posix_cputimers_rt_watchdog(struct posix_cputimers *pct,
+ u64 runtime)
+{
+ pct->cputime_expires.sched_exp = runtime;
+}
+
/* Init task static initializer */
#define INIT_CPU_TIMERLISTS(c) { \
LIST_HEAD_INIT(c.cpu_timers[0]), \
#else
struct posix_cputimers { };
#define INIT_CPU_TIMERS(s)
+static inline void posix_cputimers_init(struct posix_cputimers *pct) { }
+static inline void posix_cputimers_group_init(struct posix_cputimers *pct,
+ u64 cpu_limit) { }
#endif
#define REQUEUE_PENDING 1
unsigned long cpu_limit;
cpu_limit = READ_ONCE(sig->rlim[RLIMIT_CPU].rlim_cur);
- if (cpu_limit != RLIM_INFINITY) {
- sig->cputime_expires.prof_exp = cpu_limit * NSEC_PER_SEC;
+ posix_cputimers_group_init(pct, cpu_limit);
+ if (cpu_limit != RLIM_INFINITY)
sig->cputimer.running = true;
- }
-
- posix_cputimers_init(pct);
}
#else
static inline void posix_cpu_timers_init_group(struct signal_struct *sig) { }
#endif
}
-#ifdef CONFIG_POSIX_TIMERS
-/*
- * Initialize POSIX timer handling for a single task.
- */
-static void posix_cpu_timers_init(struct task_struct *tsk)
-{
- tsk->cputime_expires.prof_exp = 0;
- tsk->cputime_expires.virt_exp = 0;
- tsk->cputime_expires.sched_exp = 0;
-
- posix_cputimers_init(&tsk->posix_cputimers);
-}
-#else
-static inline void posix_cpu_timers_init(struct task_struct *tsk) { }
-#endif
-
static inline void init_task_pid_links(struct task_struct *task)
{
enum pid_type type;
task_io_accounting_init(&p->ioac);
acct_clear_integrals(p);
- posix_cpu_timers_init(p);
+ posix_cputimers_init(&p->posix_cputimers);
p->io_context = NULL;
audit_set_context(p, NULL);
static void posix_cpu_timer_rearm(struct k_itimer *timer);
+void posix_cputimers_group_init(struct posix_cputimers *pct, u64 cpu_limit)
+{
+ posix_cputimers_init(pct);
+ if (cpu_limit != RLIM_INFINITY)
+ pct->cputime_expires.prof_exp = cpu_limit * NSEC_PER_SEC;
+}
+
/*
* Called after updating RLIMIT_CPU to run cpu timer and update
- * tsk->signal->cputime_expires expiration cache if necessary. Needs
- * siglock protection since other code may update expiration cache as
- * well.
+ * tsk->signal->posix_cputimers.cputime_expires expiration cache if
+ * necessary. Needs siglock protection since other code may update
+ * expiration cache as well.
*/
void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new)
{
if (CPUCLOCK_PERTHREAD(timer->it_clock)) {
head = p->posix_cputimers.cpu_timers;
- cputime_expires = &p->cputime_expires;
+ cputime_expires = &p->posix_cputimers.cputime_expires;
} else {
head = p->signal->posix_cputimers.cpu_timers;
- cputime_expires = &p->signal->cputime_expires;
+ cputime_expires = &p->signal->posix_cputimers.cputime_expires;
}
head += CPUCLOCK_WHICH(timer->it_clock);
struct list_head *firing)
{
struct list_head *timers = tsk->posix_cputimers.cpu_timers;
- struct task_cputime *tsk_expires = &tsk->cputime_expires;
+ struct task_cputime *tsk_expires = &tsk->posix_cputimers.cputime_expires;
u64 expires, stime, utime;
unsigned long soft;
* If cputime_expires is zero, then there are no active
* per thread CPU timers.
*/
- if (task_cputime_zero(&tsk->cputime_expires))
+ if (task_cputime_zero(tsk_expires))
return;
task_cputime(tsk, &utime, &stime);
prof_expires = x;
}
- sig->cputime_expires.prof_exp = prof_expires;
- sig->cputime_expires.virt_exp = virt_expires;
- sig->cputime_expires.sched_exp = sched_expires;
- if (task_cputime_zero(&sig->cputime_expires))
+ sig->posix_cputimers.cputime_expires.prof_exp = prof_expires;
+ sig->posix_cputimers.cputime_expires.virt_exp = virt_expires;
+ sig->posix_cputimers.cputime_expires.sched_exp = sched_expires;
+ if (task_cputime_zero(&sig->posix_cputimers.cputime_expires))
stop_process_timers(sig);
sig->cputimer.checking_timer = false;
{
struct signal_struct *sig;
- if (!task_cputime_zero(&tsk->cputime_expires)) {
+ if (!task_cputime_zero(&tsk->posix_cputimers.cputime_expires)) {
struct task_cputime task_sample;
task_cputime(tsk, &task_sample.utime, &task_sample.stime);
task_sample.sum_exec_runtime = tsk->se.sum_exec_runtime;
- if (task_cputime_expired(&task_sample, &tsk->cputime_expires))
+ if (task_cputime_expired(&task_sample,
+ &tsk->posix_cputimers.cputime_expires))
return 1;
}
sample_cputime_atomic(&group_sample, &sig->cputimer.cputime_atomic);
- if (task_cputime_expired(&group_sample, &sig->cputime_expires))
+ if (task_cputime_expired(&group_sample,
+ &sig->posix_cputimers.cputime_expires))
return 1;
}
*/
switch (clock_idx) {
case CPUCLOCK_PROF:
- if (expires_gt(tsk->signal->cputime_expires.prof_exp, *newval))
- tsk->signal->cputime_expires.prof_exp = *newval;
+ if (expires_gt(tsk->signal->posix_cputimers.cputime_expires.prof_exp, *newval))
+ tsk->signal->posix_cputimers.cputime_expires.prof_exp = *newval;
break;
case CPUCLOCK_VIRT:
- if (expires_gt(tsk->signal->cputime_expires.virt_exp, *newval))
- tsk->signal->cputime_expires.virt_exp = *newval;
+ if (expires_gt(tsk->signal->posix_cputimers.cputime_expires.virt_exp, *newval))
+ tsk->signal->posix_cputimers.cputime_expires.virt_exp = *newval;
break;
}