Commit 3a245c0f authored by Thomas Gleixner's avatar Thomas Gleixner
Browse files

posix-cpu-timers: Move expiry cache into struct posix_cputimers



The expiry cache belongs into the posix_cputimers container where the other
cpu timers information is.

Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarFrederic Weisbecker <frederic@kernel.org>
Link: https://lkml.kernel.org/r/20190821192921.014444012@linutronix.de
parent 9eacb5c7
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -62,24 +62,43 @@ static inline int clockid_to_fd(const clockid_t clk)
	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]),				\
@@ -94,6 +113,9 @@ static inline void posix_cputimers_init(struct posix_cputimers *pct)
#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
+0 −8
Original line number Diff line number Diff line
@@ -246,11 +246,6 @@ struct prev_cputime {
#endif
};

/* Alternate field names when used on cache expirations: */
#define virt_exp			utime
#define prof_exp			stime
#define sched_exp			sum_exec_runtime

enum vtime_state {
	/* Task is sleeping or running in a CPU with VTIME inactive: */
	VTIME_INACTIVE = 0,
@@ -862,9 +857,6 @@ struct task_struct {
	unsigned long			min_flt;
	unsigned long			maj_flt;

#ifdef CONFIG_POSIX_TIMERS
	struct task_cputime		cputime_expires;
#endif
	/* Empty if CONFIG_POSIX_CPUTIMERS=n */
	struct posix_cputimers		posix_cputimers;

+0 −3
Original line number Diff line number Diff line
@@ -149,9 +149,6 @@ struct signal_struct {
	 */
	struct thread_group_cputimer cputimer;

	/* Earliest-expiration cache. */
	struct task_cputime cputime_expires;

#endif
	/* Empty if CONFIG_POSIX_TIMERS=n */
	struct posix_cputimers posix_cputimers;
+3 −22
Original line number Diff line number Diff line
@@ -1527,13 +1527,10 @@ static void posix_cpu_timers_init_group(struct signal_struct *sig)
	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
@@ -1638,22 +1635,6 @@ static void rt_mutex_init_task(struct task_struct *p)
#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;
@@ -1932,7 +1913,7 @@ static __latent_entropy struct task_struct *copy_process(
	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);
+4 −2
Original line number Diff line number Diff line
@@ -2305,8 +2305,10 @@ static void watchdog(struct rq *rq, struct task_struct *p)
		}

		next = DIV_ROUND_UP(min(soft, hard), USEC_PER_SEC/HZ);
		if (p->rt.timeout > next)
			p->cputime_expires.sched_exp = p->se.sum_exec_runtime;
		if (p->rt.timeout > next) {
			posix_cputimers_rt_watchdog(&p->posix_cputimers,
						    p->se.sum_exec_runtime);
		}
	}
}
#else
Loading