From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932202Ab3AISfO (ORCPT ); Wed, 9 Jan 2013 13:35:14 -0500 Received: from mail-qa0-f50.google.com ([209.85.216.50]:39677 "EHLO mail-qa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758023Ab3AISfM (ORCPT ); Wed, 9 Jan 2013 13:35:12 -0500 Date: Wed, 9 Jan 2013 19:35:06 +0100 From: Frederic Weisbecker To: Steven Rostedt Cc: LKML , Alessio Igor Bogani , Andrew Morton , Chris Metcalf , Christoph Lameter , Geoff Levand , Gilad Ben Yossef , Hakan Akkan , Ingo Molnar , Li Zhong , Namhyung Kim , "Paul E. McKenney" , Paul Gortmaker , Peter Zijlstra , Thomas Gleixner Subject: Re: [PATCH 06/33] cputime: Safely read cputime of full dynticks CPUs Message-ID: <20130109183454.GB8293@somewhere.redhat.com> References: <1357610913-1080-1-git-send-email-fweisbec@gmail.com> <1357610913-1080-7-git-send-email-fweisbec@gmail.com> <1357743251.5190.57.camel@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1357743251.5190.57.camel@gandalf.local.home> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 09, 2013 at 09:54:11AM -0500, Steven Rostedt wrote: > On Tue, 2013-01-08 at 03:08 +0100, Frederic Weisbecker wrote: > > > diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c > > index 07912dd..bf4f72d 100644 > > --- a/kernel/sched/cputime.c > > +++ b/kernel/sched/cputime.c > > @@ -484,7 +484,7 @@ void vtime_task_switch(struct task_struct *prev) > > * vtime_account(). > > */ > > #ifndef __ARCH_HAS_VTIME_ACCOUNT > > -void vtime_account(struct task_struct *tsk) > > +void vtime_account_irq_enter(struct task_struct *tsk) > > { > > if (!in_interrupt()) { > > /* > > @@ -505,7 +505,7 @@ void vtime_account(struct task_struct *tsk) > > } > > vtime_account_system(tsk); > > } > > -EXPORT_SYMBOL_GPL(vtime_account); > > +EXPORT_SYMBOL_GPL(vtime_account_irq_enter); > > #endif /* __ARCH_HAS_VTIME_ACCOUNT */ > > #endif /* CONFIG_VIRT_CPU_ACCOUNTING */ > > > > @@ -616,41 +616,67 @@ void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime > > #endif /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ > > > > #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN > > -static DEFINE_PER_CPU(long, last_jiffies) = INITIAL_JIFFIES; > > - > > -static cputime_t get_vtime_delta(void) > > +static cputime_t get_vtime_delta(struct task_struct *tsk) > > { > > long delta; > > > > - delta = jiffies - __this_cpu_read(last_jiffies); > > - __this_cpu_add(last_jiffies, delta); > > + delta = jiffies - tsk->prev_jiffies; > > + tsk->prev_jiffies += delta; > > > > return jiffies_to_cputime(delta); > > } > > > > -void vtime_account_system(struct task_struct *tsk) > > +static void __vtime_account_system(struct task_struct *tsk) > > { > > - cputime_t delta_cpu = get_vtime_delta(); > > + cputime_t delta_cpu = get_vtime_delta(tsk); > > > > account_system_time(tsk, irq_count(), delta_cpu, cputime_to_scaled(delta_cpu)); > > } > > > > +void vtime_account_system(struct task_struct *tsk) > > +{ > > + write_seqlock(&tsk->vtime_seqlock); > > + __vtime_account_system(tsk); > > __vtime_account_system() calls account_system_time() > account_system_time() calls __account_system_time() > __account_system_time() calls acct_update_integrals() > (when CONFIG_TASK_XACCT is set) > acct_update_integrals() calls task_cputime() > task_cputime() grabs t->vtime_seqlock for read > > DEADLOCK > > ironically the subject says *Safely* read cputime ;-) Well at least it crashes safely. Safely as in "deterministic".