From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>, Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
John Stultz <john.stultz@linaro.org>,
Frederic Weisbecker <frederic@kernel.org>,
Anna-Maria Behnsen <anna-maria@linutronix.de>,
Christoph Hellwig <hch@lst.de>
Subject: [patch V2 29/38] posix-cpu-timers: Switch thread group sampling to array
Date: Wed, 21 Aug 2019 21:09:16 +0200 [thread overview]
Message-ID: <20190821192921.988426956@linutronix.de> (raw)
In-Reply-To: 20190821190847.665673890@linutronix.de
That allows more simplifications in various places.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
V2: Adopt to the per clock base struct
---
include/linux/sched/cputime.h | 2
kernel/time/itimer.c | 11 +---
kernel/time/posix-cpu-timers.c | 104 +++++++++++++++++------------------------
3 files changed, 49 insertions(+), 68 deletions(-)
--- a/include/linux/sched/cputime.h
+++ b/include/linux/sched/cputime.h
@@ -61,7 +61,7 @@ extern void cputime_adjust(struct task_c
* Thread group CPU time accounting.
*/
void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times);
-void thread_group_sample_cputime(struct task_struct *tsk, struct task_cputime *times);
+void thread_group_sample_cputime(struct task_struct *tsk, u64 *samples);
/*
* The following are functions that support scheduler-internal time accounting.
--- a/kernel/time/itimer.c
+++ b/kernel/time/itimer.c
@@ -55,15 +55,10 @@ static void get_cpu_itimer(struct task_s
val = it->expires;
interval = it->incr;
if (val) {
- struct task_cputime cputime;
- u64 t;
+ u64 t, samples[CPUCLOCK_MAX];
- thread_group_sample_cputime(tsk, &cputime);
- if (clock_id == CPUCLOCK_PROF)
- t = cputime.utime + cputime.stime;
- else
- /* CPUCLOCK_VIRT */
- t = cputime.utime;
+ thread_group_sample_cputime(tsk, samples);
+ t = samples[clock_id];
if (val < t)
/* about to fire */
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -225,22 +225,14 @@ static inline void __update_gt_cputime(a
}
}
-static void update_gt_cputime(struct task_cputime_atomic *cputime_atomic, struct task_cputime *sum)
+static void update_gt_cputime(struct task_cputime_atomic *cputime_atomic,
+ struct task_cputime *sum)
{
__update_gt_cputime(&cputime_atomic->utime, sum->utime);
__update_gt_cputime(&cputime_atomic->stime, sum->stime);
__update_gt_cputime(&cputime_atomic->sum_exec_runtime, sum->sum_exec_runtime);
}
-/* Sample task_cputime_atomic values in "atomic_timers", store results in "times". */
-static inline void sample_cputime_atomic(struct task_cputime *times,
- struct task_cputime_atomic *atomic_times)
-{
- times->utime = atomic64_read(&atomic_times->utime);
- times->stime = atomic64_read(&atomic_times->stime);
- times->sum_exec_runtime = atomic64_read(&atomic_times->sum_exec_runtime);
-}
-
/**
* thread_group_sample_cputime - Sample cputime for a given task
* @tsk: Task for which cputime needs to be started
@@ -252,20 +244,19 @@ static inline void sample_cputime_atomic
*
* Updates @times with an uptodate sample of the thread group cputimes.
*/
-void thread_group_sample_cputime(struct task_struct *tsk,
- struct task_cputime *times)
+void thread_group_sample_cputime(struct task_struct *tsk, u64 *samples)
{
struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
WARN_ON_ONCE(!cputimer->running);
- sample_cputime_atomic(times, &cputimer->cputime_atomic);
+ proc_sample_cputime_atomic(&cputimer->cputime_atomic, samples);
}
/**
* thread_group_start_cputime - Start cputime and return a sample
* @tsk: Task for which cputime needs to be started
- * @iimes: Storage for time samples
+ * @samples: Storage for time samples
*
* The thread group cputime accouting is avoided when there are no posix
* CPU timers armed. Before starting a timer it's required to check whether
@@ -274,14 +265,14 @@ void thread_group_sample_cputime(struct
*
* Updates @times with an uptodate sample of the thread group cputimes.
*/
-static void
-thread_group_start_cputime(struct task_struct *tsk, struct task_cputime *times)
+static void thread_group_start_cputime(struct task_struct *tsk, u64 *samples)
{
struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
- struct task_cputime sum;
/* Check if cputimer isn't running. This is accessed without locking. */
if (!READ_ONCE(cputimer->running)) {
+ struct task_cputime sum;
+
/*
* The POSIX timer interface allows for absolute time expiry
* values through the TIMER_ABSTIME flag, therefore we have
@@ -299,7 +290,15 @@ thread_group_start_cputime(struct task_s
*/
WRITE_ONCE(cputimer->running, true);
}
- sample_cputime_atomic(times, &cputimer->cputime_atomic);
+ proc_sample_cputime_atomic(&cputimer->cputime_atomic, samples);
+}
+
+static void __thread_group_cputime(struct task_struct *tsk, u64 *samples)
+{
+ struct task_cputime ct;
+
+ thread_group_cputime(tsk, &ct);
+ store_samples(samples, ct.stime, ct.utime, ct.sum_exec_runtime);
}
/*
@@ -313,28 +312,18 @@ static u64 cpu_clock_sample_group(const
bool start)
{
struct thread_group_cputimer *cputimer = &p->signal->cputimer;
- struct task_cputime cputime;
+ u64 samples[CPUCLOCK_MAX];
if (!READ_ONCE(cputimer->running)) {
if (start)
- thread_group_start_cputime(p, &cputime);
+ thread_group_start_cputime(p, samples);
else
- thread_group_cputime(p, &cputime);
+ __thread_group_cputime(p, samples);
} else {
- sample_cputime_atomic(&cputime, &cputimer->cputime_atomic);
+ proc_sample_cputime_atomic(&cputimer->cputime_atomic, samples);
}
- switch (clkid) {
- case CPUCLOCK_PROF:
- return cputime.utime + cputime.stime;
- case CPUCLOCK_VIRT:
- return cputime.utime;
- case CPUCLOCK_SCHED:
- return cputime.sum_exec_runtime;
- default:
- WARN_ON_ONCE(1);
- }
- return 0;
+ return samples[clkid];
}
static int posix_cpu_clock_get(const clockid_t clock, struct timespec64 *tp)
@@ -889,9 +878,7 @@ static void check_process_timers(struct
{
struct signal_struct *const sig = tsk->signal;
struct posix_cputimer_base *base = sig->posix_cputimers.bases;
- u64 utime, ptime, virt_expires, prof_expires;
- u64 sum_sched_runtime, sched_expires;
- struct task_cputime cputime;
+ u64 virt_exp, prof_exp, sched_exp, samples[CPUCLOCK_MAX];
unsigned long soft;
/*
@@ -911,30 +898,29 @@ static void check_process_timers(struct
* Collect the current process totals. Group accounting is active
* so the sample can be taken directly.
*/
- sample_cputime_atomic(&cputime, &sig->cputimer.cputime_atomic);
- utime = cputime.utime;
- ptime = utime + cputime.stime;
- sum_sched_runtime = cputime.sum_exec_runtime;
-
- prof_expires = check_timers_list(&base[CPUCLOCK_PROF].cpu_timers,
- firing, ptime);
- virt_expires = check_timers_list(&base[CPUCLOCK_VIRT].cpu_timers,
- firing, utime);
- sched_expires = check_timers_list(&base[CLPCLOCK_SCHED].cpu_timers,
- firing, sum_sched_runtime);
+ proc_sample_cputime_atomic(&sig->cputimer.cputime_atomic, samples);
+
+ prof_exp = check_timers_list(&base[CPUCLOCK_PROF].cpu_timers,
+ firing, samples[CPUCLOCK_PROF]);
+ virt_exp = check_timers_list(&base[CPUCLOCK_VIRT].cpu_timers,
+ firing, samples[CPUCLOCK_VIRT]);
+ sched_exp = check_timers_list(&base[CPUCLOCK_SCHED].cpu_timers,
+ firing, samples[CPUCLOCK_SCHED]);
/*
* Check for the special case process timers.
*/
- check_cpu_itimer(tsk, &sig->it[CPUCLOCK_PROF], &prof_expires, ptime,
- SIGPROF);
- check_cpu_itimer(tsk, &sig->it[CPUCLOCK_VIRT], &virt_expires, utime,
- SIGVTALRM);
+ check_cpu_itimer(tsk, &sig->it[CPUCLOCK_PROF], &prof_exp,
+ samples[CPUCLOCK_PROF], SIGPROF);
+ check_cpu_itimer(tsk, &sig->it[CPUCLOCK_VIRT], &virt_exp,
+ samples[CPUCLOCK_PROF], SIGVTALRM);
+
soft = task_rlimit(tsk, RLIMIT_CPU);
if (soft != RLIM_INFINITY) {
- unsigned long psecs = div_u64(ptime, NSEC_PER_SEC);
+ u64 softns, ptime = samples[CPUCLOCK_PROF];
unsigned long hard = task_rlimit_max(tsk, RLIMIT_CPU);
- u64 x;
+ unsigned long psecs = div_u64(ptime, NSEC_PER_SEC);
+
if (psecs >= hard) {
/*
* At the hard limit, we just die.
@@ -961,14 +947,14 @@ static void check_process_timers(struct
sig->rlim[RLIMIT_CPU].rlim_cur = soft;
}
}
- x = soft * NSEC_PER_SEC;
- if (!prof_expires || x < prof_expires)
- prof_expires = x;
+ softns = soft * NSEC_PER_SEC;
+ if (!prof_exp || softns < prof_exp)
+ prof_exp = softns;
}
- base[CPUCLOCK_PROF].nextevt = prof_expires;
- base[CPUCLOCK_VIRT].nextevt = virt_expires;
- base[CPUCLOCK_SCHED].nextevt = sched_expires;
+ base[CPUCLOCK_PROF].nextevt = prof_exp;
+ base[CPUCLOCK_VIRT].nextevt = virt_exp;
+ base[CPUCLOCK_SCHED].nextevt = sched_exp;
if (expiry_cache_is_zero(&sig->posix_cputimers))
stop_process_timers(sig);
next prev parent reply other threads:[~2019-08-21 19:31 UTC|newest]
Thread overview: 137+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-21 19:08 [patch V2 00/38] posix-cpu-timers: Cleanup and consolidation Thomas Gleixner
2019-08-21 19:08 ` [patch V2 01/38] posix-cpu-timers: Provide task validation functions Thomas Gleixner
2019-08-21 22:33 ` Frederic Weisbecker
2019-08-21 23:03 ` Frederic Weisbecker
2019-08-23 15:33 ` Thomas Gleixner
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:08 ` [patch V2 02/38] posix-cpu-timers: Use common permission check in posix_cpu_clock_get() Thomas Gleixner
2019-08-21 23:40 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-29 11:00 ` kbuild test robot
2019-08-29 11:21 ` Thomas Gleixner
2019-08-30 1:08 ` [kbuild-all] " Philip Li
2019-08-29 11:23 ` kbuild test robot
2019-08-21 19:08 ` [patch V2 03/38] posix-cpu-timers: Use common permission check in posix_cpu_timer_create() Thomas Gleixner
2019-08-21 23:49 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:08 ` [patch V2 04/38] posix-cpu-timers: Provide quick sample function for itimer Thomas Gleixner
2019-08-22 12:13 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:08 ` [patch V2 05/38] itimers: Use quick sample function Thomas Gleixner
2019-08-22 12:15 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-29 23:47 ` kbuild test robot
2019-08-30 6:01 ` Thomas Gleixner
2019-08-21 19:08 ` [patch V2 06/38] posix-cpu-timers: Sample directly in timer check Thomas Gleixner
2019-08-22 12:30 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:08 ` [patch V2 07/38] posix-cpu-timers: Rename thread_group_cputimer() and make it static Thomas Gleixner
2019-08-22 12:41 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:08 ` [patch V2 08/38] posix-cpu-timers: Consolidate thread group sample code Thomas Gleixner
2019-08-22 13:49 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:08 ` [patch V2 09/38] posix-cpu-timers: Use clock ID in posix_cpu_timer_set() Thomas Gleixner
2019-08-22 13:58 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:08 ` [patch V2 10/38] posix-cpu-timers: Use clock ID in posix_cpu_timer_get() Thomas Gleixner
2019-08-22 14:07 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:08 ` [patch V2 11/38] posix-cpu-timers: Use clock ID in posix_cpu_timer_rearm() Thomas Gleixner
2019-08-22 14:12 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:08 ` [patch V2 12/38] posix-cpu-timers: Remove pointless return value check Thomas Gleixner
2019-08-22 14:15 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 13/38] posix-cpu-timers: Simplify sample functions Thomas Gleixner
2019-08-22 14:20 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 14/38] posix-cpu-timers: Get rid of pointer indirection Thomas Gleixner
2019-08-22 14:41 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 15/38] posix-cpu-timers: Sample task times once in expiry check Thomas Gleixner
2019-08-22 15:00 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 16/38] posix-cpu-timers: Move prof/virt_ticks into caller Thomas Gleixner
2019-08-22 15:05 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 17/38] posix-cpu-timers: Create a container struct Thomas Gleixner
2019-08-22 15:32 ` Frederic Weisbecker
2019-08-23 15:34 ` Thomas Gleixner
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 19/38] posix-cpu-timers: Move expiry cache into struct posix_cputimers Thomas Gleixner
2019-08-22 16:29 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 20/38] posix-cpu-timers: Provide array based access to expiry cache Thomas Gleixner
2019-08-23 17:33 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 21/38] posix-cpu-timers: Simplify timer queueing Thomas Gleixner
2019-08-23 17:51 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 22/38] posix-cpu-timers: Simplify set_process_cpu_timer() Thomas Gleixner
2019-08-23 18:00 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 23/38] posix-cpu-timers: Switch check_*_timers() to array cache Thomas Gleixner
2019-08-23 18:13 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 24/38] posix-cpu-timers: Remove the odd field rename defines Thomas Gleixner
2019-08-23 18:36 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 25/38] posix-cpu-timers: Provide array based sample functions Thomas Gleixner
2019-08-23 22:08 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 26/38] posix-cpu-timers: Make expiry checks array based Thomas Gleixner
2019-08-23 22:44 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 27/38] posix-cpu-timers: Remove cputime_expires Thomas Gleixner
2019-08-23 22:50 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 28/38] posix-cpu-timers: Restructure expiry array Thomas Gleixner
2019-08-26 16:32 ` Frederic Weisbecker
2019-08-26 18:16 ` Thomas Gleixner
2019-08-26 18:22 ` [patch V3 " Thomas Gleixner
2019-08-26 19:45 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-26 21:06 ` [patch V2 28/38] " Frederic Weisbecker
2019-08-26 21:46 ` Thomas Gleixner
2019-08-21 19:09 ` Thomas Gleixner [this message]
2019-08-26 21:12 ` [patch V2 29/38] posix-cpu-timers: Switch thread group sampling to array Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 30/38] posix-cpu-timers: Respect INFINITY for hard RTTIME limit Thomas Gleixner
2019-08-26 21:19 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 31/38] rlimit: Rewrite non-sensical RLIMIT_CPU comment Thomas Gleixner
2019-08-26 21:41 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 32/38] posix-cpu-timers: Get rid of zero checks Thomas Gleixner
2019-08-26 21:57 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 33/38] posix-cpu-timers: Consolidate timer expiry further Thomas Gleixner
2019-08-26 22:29 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 34/38] posix-cpu-timers: Get rid of 64bit divisions Thomas Gleixner
2019-08-26 22:51 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 35/38] posix-cpu-timers: Remove pointless comparisons Thomas Gleixner
2019-08-26 22:59 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 36/38] posix-cpu-timers: Deduplicate rlimit handling Thomas Gleixner
2019-08-26 23:13 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 37/38] posix-cpu-timers: Move state tracking to struct posix_cputimers Thomas Gleixner
2019-08-26 23:28 ` Frederic Weisbecker
2019-08-26 23:33 ` Thomas Gleixner
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-21 19:09 ` [patch V2 38/38] posix-cpu-timers: Utilize timerqueue for storage Thomas Gleixner
2019-08-27 0:48 ` Frederic Weisbecker
2019-08-27 6:08 ` Thomas Gleixner
2019-08-27 13:17 ` Frederic Weisbecker
2019-08-27 13:46 ` Thomas Gleixner
2019-08-27 19:31 ` [patch V3 " Thomas Gleixner
2019-08-27 22:23 ` Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2019-08-22 0:54 ` [patch V2 00/38] posix-cpu-timers: Cleanup and consolidation Christoph Hellwig
2019-08-22 1:02 ` Frederic Weisbecker
2019-08-22 1:02 ` Christoph Hellwig
[not found] ` <20190821192920.909530418@linutronix.de>
2019-08-22 16:06 ` [patch V2 18/38] sched: Move struct task_cputime to types.h Frederic Weisbecker
2019-08-28 10:16 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190821192921.988426956@linutronix.de \
--to=tglx@linutronix.de \
--cc=anna-maria@linutronix.de \
--cc=frederic@kernel.org \
--cc=hch@lst.de \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).