lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130618142744.GG17619@somewhere.redhat.com>
Date:	Tue, 18 Jun 2013 16:27:45 +0200
From:	Frederic Weisbecker <fweisbec@...il.com>
To:	kosaki.motohiro@...il.com
Cc:	linux-kernel@...r.kernel.org,
	Olivier Langlois <olivier@...llion01.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	Ingo Molnar <mingo@...nel.org>,
	Peter Zijlstra <peterz@...radead.org>,
	KOSAKI Motohiro <kosaki.motohiro@...fujitsu.com>
Subject: Re: [PATCH 6/8] sched: task_sched_runtime introduce micro
 optimization

On Sun, May 26, 2013 at 05:35:47PM -0400, kosaki.motohiro@...il.com wrote:
> From: KOSAKI Motohiro <kosaki.motohiro@...fujitsu.com>
> 
> rq lock in task_sched_runtime() is necessary for two reasons. 1)
> accessing se.sum_exec_runtime is not atomic on 32bit and 2)
> do_task_delta_exec() require it.
> 
> So, 64bit can avoid holding rq lock when add_delta is false and
> delta_exec is 0.
> 
> Cc: Olivier Langlois <olivier@...llion01.com>
> Cc: Thomas Gleixner <tglx@...utronix.de>
> Cc: Frederic Weisbecker <fweisbec@...il.com>
> Cc: Ingo Molnar <mingo@...nel.org>
> Suggested-by: Paul Turner <pjt@...gle.com>
> Acked-by: Peter Zijlstra <peterz@...radead.org>
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@...fujitsu.com>
> ---
>  kernel/sched/core.c |   15 +++++++++++++++
>  1 files changed, 15 insertions(+), 0 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 96512e9..0f859cc 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -2692,6 +2692,21 @@ unsigned long long task_sched_runtime(struct task_struct *p, bool add_delta)
>  	struct rq *rq;
>  	u64 ns = 0;
>  
> +#ifdef CONFIG_64BIT
> +	/*
> +	 * 64-bit doesn't need locks to atomically read a 64bit value. So we
> +	 * have two optimization chances, 1) when caller doesn't need
> +	 * delta_exec and 2) when the task's delta_exec is 0. The former is
> +	 * obvious. The latter is complicated. reading ->on_cpu is racy, but
> +	 * this is ok. If we race with it leaving cpu, we'll take a lock. So
> +	 * we're correct. If we race with it entering cpu, unaccounted time
> +	 * is 0. This is indistinguishable from the read occurring a few
> +	 * cycles earlier.
> +	 */
> +	if (!add_delta || !p->on_cpu)
> +		return p->se.sum_exec_runtime;

I'm not sure this is correct from an smp ordering POV. p->on_cpu may appear
to be 0 whereas the task is actually running for a while and p->se.sum_exec_runtime
can then be past the actual value on the remote CPU.

> +#endif
> +
>  	rq = task_rq_lock(p, &flags);
>  	ns = p->se.sum_exec_runtime;
>  	if (add_delta)
> -- 
> 1.7.1
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ