From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754372AbaHNSgp (ORCPT ); Thu, 14 Aug 2014 14:36:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24603 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752879AbaHNSgo (ORCPT ); Thu, 14 Aug 2014 14:36:44 -0400 Date: Thu, 14 Aug 2014 20:34:13 +0200 From: Oleg Nesterov To: Rik van Riel Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Hidetoshi Seto , Frank Mayhar , Frederic Weisbecker , Andrew Morton , Sanjay Rao , Larry Woodman Subject: Re: [PATCH RFC] time,signal: protect resource use statistics with seqlock Message-ID: <20140814183413.GA6959@redhat.com> References: <20140812191218.GA15210@redhat.com> <53EA94DD.5040900@redhat.com> <20140813172230.GA6296@redhat.com> <20140813133526.1eb5526f@cuia.bos.redhat.com> <20140813180807.GA8098@redhat.com> <53EBADB1.2020403@redhat.com> <20140813184511.GA9663@redhat.com> <20140813170324.544aaf2d@cuia.bos.redhat.com> <20140814132239.GA24465@redhat.com> <20140814174849.GA5091@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140814174849.GA5091@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/14, Oleg Nesterov wrote: > > But just for record, the "lockless" version doesn't look that bad to me, > > void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times) > { > struct signal_struct *sig = tsk->signal; > bool lockless, is_dead; > struct task_struct *t; > unsigned long flags; > u64 exec; > > lockless = true; > is_dead = !lock_task_sighand(p, &flags); > retry: > times->utime = sig->utime; > times->stime = sig->stime; > times->sum_exec_runtime = exec = sig->sum_sched_runtime; > if (is_dead) > return; > > if (lockless) > unlock_task_sighand(p, &flags); > > rcu_read_lock(); > for_each_thread(tsk, t) { > cputime_t utime, stime; > task_cputime(t, &utime, &stime); > times->utime += utime; > times->stime += stime; > times->sum_exec_runtime += task_sched_runtime(t); > } > rcu_read_unlock(); > > if (lockless) { > lockless = false; > is_dead = !lock_task_sighand(p, &flags); > if (is_dead || exec != sig->sum_sched_runtime) > goto retry; > } > unlock_task_sighand(p, &flags); > } > > The obvious problem is that we should shift lock_task_sighand() from the > callers to thread_group_cputime() first, or add thread_group_cputime_lockless() > and change the current users one by one. OTOH, it is simple to convert do_sys_times() and posix_cpu_clock_get_task() to use the lockless version, and avoid the new stats_lock and other changes it needs. > And of course, stats_lock is more generic. Yes, this is true in any case. So I simply do not know. Oleg.