]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
posix-cpu-timers: Move expiry cache into struct posix_cputimers
authorThomas Gleixner <tglx@linutronix.de>
Wed, 21 Aug 2019 19:09:06 +0000 (21:09 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 28 Aug 2019 09:50:35 +0000 (11:50 +0200)
The expiry cache belongs into the posix_cputimers container where the other
cpu timers information is.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Link: https://lkml.kernel.org/r/20190821192921.014444012@linutronix.de
include/linux/posix-timers.h
include/linux/sched.h
include/linux/sched/signal.h
kernel/fork.c
kernel/sched/rt.c
kernel/time/posix-cpu-timers.c

index cdef89750b2cde7a65ba9a79bf98e8ddef890f58..a3731ba15bce49f2f0e31514afbdcd00f0f0db74 100644 (file)
@@ -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
index 37c39df9b18684b3385691e3395b9f3e985850a3..8cc8e323093f7e79f22401fb187db42e6a3fbd78 100644 (file)
@@ -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;
 
index 88fbb3f1c3758530347583938afd0d6d440a4251..729bd892ee45a11df3ec460ee8ba731e7d6ca47b 100644 (file)
@@ -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;
index b6a135e4275b41f6ac7fc27568b95094fd38314e..52bfe7c20ff61d538e2661073428b72cf4d38bd6 100644 (file)
@@ -1527,12 +1527,9 @@ 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) { }
@@ -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);
index da3e85e61013996fd4787a45ed7ca41fd1257ff0..d6678f773c966fe28bd4de1ba166fc091e21e3aa 100644 (file)
@@ -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
index 849e2045fb6e4945e98cab0dad0045bfa3340a20..3e29d169243757898a966d4a4b2b39995148e65e 100644 (file)
 
 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)
 {
@@ -447,10 +454,10 @@ static void arm_timer(struct k_itimer *timer)
 
        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);
 
@@ -774,7 +781,7 @@ static void check_thread_timers(struct task_struct *tsk,
                                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;
 
@@ -785,7 +792,7 @@ static void check_thread_timers(struct task_struct *tsk,
         * 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);
@@ -954,10 +961,10 @@ static void check_process_timers(struct task_struct *tsk,
                        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;
@@ -1058,12 +1065,13 @@ static inline int fastpath_timer_check(struct task_struct *tsk)
 {
        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;
        }
 
@@ -1088,7 +1096,8 @@ static inline int fastpath_timer_check(struct task_struct *tsk)
 
                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;
        }
 
@@ -1204,12 +1213,12 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
         */
        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;
        }