From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753744AbbCFAGY (ORCPT ); Thu, 5 Mar 2015 19:06:24 -0500 Received: from g9t5008.houston.hp.com ([15.240.92.66]:44577 "EHLO g9t5008.houston.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752552AbbCFAGX (ORCPT ); Thu, 5 Mar 2015 19:06:23 -0500 Message-ID: <1425600379.2475.76.camel@j-VirtualBox> Subject: Re: [PATCH v2] sched, timer: Use atomics for thread_group_cputimer to improve scalability From: Jason Low To: Frederic Weisbecker Cc: Peter Zijlstra , Ingo Molnar , Linus Torvalds , "Paul E. McKenney" , Andrew Morton , Oleg Nesterov , Mike Galbraith , Rik van Riel , Steven Rostedt , Scott Norton , Aswin Chandramouleeswaran , linux-kernel@vger.kernel.org, jason.low2@hp.com Date: Thu, 05 Mar 2015 16:06:19 -0800 In-Reply-To: <20150305153506.GD5074@lerouge> References: <1425321731.5304.14.camel@j-VirtualBox> <20150305153506.GD5074@lerouge> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit Mime-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2015-03-05 at 16:35 +0100, Frederic Weisbecker wrote: > On Mon, Mar 02, 2015 at 10:42:11AM -0800, Jason Low wrote: > > +/* Sample thread_group_cputimer values in "cputimer", copy results to "times" */ > > +static inline void sample_group_cputimer(struct task_cputime *times, > > + struct thread_group_cputimer *cputimer) > > +{ > > + times->utime = atomic64_read(&cputimer->utime); > > + times->stime = atomic64_read(&cputimer->stime); > > + times->sum_exec_runtime = atomic64_read(&cputimer->sum_exec_runtime); > > So, in the case we are calling that right after setting cputimer->running, I guess we are fine > because we just updated cputimer with the freshest values. > > But if we are reading this a while after, say several ticks further, there is a chance that > we read stale values since we don't lock anymore. > > I don't know if it matters or not, I guess it depends how stale it can be and how much precision > we expect from posix cpu timers. It probably doesn't matter. > > But just in case, atomic64_read_return(&cputimer->utime, 0) would make sure we get the freshest > value because it performs a full barrier, at the cost of more overhead of course. (Assuming that is atomic64_add_return :)) Yeah, there aren't any guarantees that we read the freshest value, but since the lock isn't used to serialize subsequent accesses of times->utime, ect..., the values can potentially become stale by the time they get used anyway, even when we have the locking. So I'm not sure if atomic64_add_return(&time, 0) for the reads would really provide much of a benefit when we factor in the extra overhead.