Re: [PATCH] posix-cpu-timers:clock_gettime(CLOCK_THREAD_CPUTIME_ID) goes backward

From: Ingo Molnar
Date: Thu Dec 25 2008 - 03:25:21 EST



* Hidetoshi Seto <seto.hidetoshi@xxxxxxxxxxxxxx> wrote:

> --- a/kernel/sched.c
> +++ b/kernel/sched.c
> @@ -4064,6 +4064,33 @@ DEFINE_PER_CPU(struct kernel_stat, kstat);
> EXPORT_PER_CPU_SYMBOL(kstat);
>
> /*
> + * Return total of runtime which already banked and which not yet
> + * @p in case that task is currently running.
> + */
> +unsigned long long task_total_exec(struct task_struct *p)
> +{
> + unsigned long flags;
> + struct rq *rq;
> + u64 ns = 0;
> +
> + rq = task_rq_lock(p, &flags);
> +
> + if (task_current(rq, p)) {
> + u64 delta_exec;
> +
> + update_rq_clock(rq);
> + delta_exec = rq->clock - p->se.exec_start;
> + if ((s64)delta_exec > 0)
> + ns = delta_exec;
> + }
> + ns += p->se.sum_exec_runtime;
> +
> + task_rq_unlock(rq, &flags);
> +
> + return ns;
> +}
> +

ok - the issue is real, but there's a few implementational details. Did
you know about task_delta_exec()? This new function duplicates that
function's behavior - and task_delta_exec() is already used by posix
task/cpu timers.

I find your new task_total_exec() interface better (it's easier to use),
could you have a look at eliminating task_delta_exec() users and migrating
them over to task_total_exec()?

Maybe even change the name of sum_exec_runtime over to __sum_exec_runtime,
to make sure nobody uses the 'raw' value - which is always stale up to one
tick's worth of execution. Accessing that raw value would only make sense
after the task has finished executing. (i.e. at cutime/cstime collection
time)

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/