Commit 2092c1d4 authored by Thomas Gleixner's avatar Thomas Gleixner

posix-cpu-timers: Simplify sample functions

All callers hand in a valdiated clock id. Remove the return value which was
unchecked in most places anyway.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarFrederic Weisbecker <frederic@kernel.org>
Link: https://lkml.kernel.org/r/20190821192920.430475832@linutronix.de
parent 5405d005
...@@ -180,14 +180,12 @@ posix_cpu_clock_set(const clockid_t clock, const struct timespec64 *tp) ...@@ -180,14 +180,12 @@ posix_cpu_clock_set(const clockid_t clock, const struct timespec64 *tp)
} }
/* /*
* Sample a per-thread clock for the given task. * Sample a per-thread clock for the given task. clkid is validated.
*/ */
static int cpu_clock_sample(const clockid_t which_clock, static void cpu_clock_sample(const clockid_t clkid, struct task_struct *p,
struct task_struct *p, u64 *sample) u64 *sample)
{ {
switch (CPUCLOCK_WHICH(which_clock)) { switch (clkid) {
default:
return -EINVAL;
case CPUCLOCK_PROF: case CPUCLOCK_PROF:
*sample = prof_ticks(p); *sample = prof_ticks(p);
break; break;
...@@ -197,8 +195,9 @@ static int cpu_clock_sample(const clockid_t which_clock, ...@@ -197,8 +195,9 @@ static int cpu_clock_sample(const clockid_t which_clock,
case CPUCLOCK_SCHED: case CPUCLOCK_SCHED:
*sample = task_sched_runtime(p); *sample = task_sched_runtime(p);
break; break;
default:
WARN_ON_ONCE(1);
} }
return 0;
} }
/* /*
...@@ -297,11 +296,11 @@ thread_group_start_cputime(struct task_struct *tsk, struct task_cputime *times) ...@@ -297,11 +296,11 @@ thread_group_start_cputime(struct task_struct *tsk, struct task_cputime *times)
* Sample a process (thread group) clock for the given task clkid. If the * Sample a process (thread group) clock for the given task clkid. If the
* group's cputime accounting is already enabled, read the atomic * group's cputime accounting is already enabled, read the atomic
* store. Otherwise a full update is required. Task's sighand lock must be * store. Otherwise a full update is required. Task's sighand lock must be
* held to protect the task traversal on a full update. * held to protect the task traversal on a full update. clkid is already
* validated.
*/ */
static int cpu_clock_sample_group(const clockid_t which_clock, static void cpu_clock_sample_group(const clockid_t clkid, struct task_struct *p,
struct task_struct *p, u64 *sample, bool start)
u64 *sample, bool start)
{ {
struct thread_group_cputimer *cputimer = &p->signal->cputimer; struct thread_group_cputimer *cputimer = &p->signal->cputimer;
struct task_cputime cputime; struct task_cputime cputime;
...@@ -315,9 +314,7 @@ static int cpu_clock_sample_group(const clockid_t which_clock, ...@@ -315,9 +314,7 @@ static int cpu_clock_sample_group(const clockid_t which_clock,
sample_cputime_atomic(&cputime, &cputimer->cputime_atomic); sample_cputime_atomic(&cputime, &cputimer->cputime_atomic);
} }
switch (CPUCLOCK_WHICH(which_clock)) { switch (clkid) {
default:
return -EINVAL;
case CPUCLOCK_PROF: case CPUCLOCK_PROF:
*sample = cputime.utime + cputime.stime; *sample = cputime.utime + cputime.stime;
break; break;
...@@ -327,8 +324,9 @@ static int cpu_clock_sample_group(const clockid_t which_clock, ...@@ -327,8 +324,9 @@ static int cpu_clock_sample_group(const clockid_t which_clock,
case CPUCLOCK_SCHED: case CPUCLOCK_SCHED:
*sample = cputime.sum_exec_runtime; *sample = cputime.sum_exec_runtime;
break; break;
default:
WARN_ON_ONCE(1);
} }
return 0;
} }
static int posix_cpu_clock_get(const clockid_t clock, struct timespec64 *tp) static int posix_cpu_clock_get(const clockid_t clock, struct timespec64 *tp)
......
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