From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934316AbcIEOUV (ORCPT ); Mon, 5 Sep 2016 10:20:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51112 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932266AbcIEOUT (ORCPT ); Mon, 5 Sep 2016 10:20:19 -0400 Date: Mon, 5 Sep 2016 16:16:57 +0200 From: Stanislaw Gruszka To: linux-kernel@vger.kernel.org Cc: Giovanni Gherdovich , Linus Torvalds , Mel Gorman , Mike Galbraith , Paolo Bonzini , Peter Zijlstra , Rik van Riel , Thomas Gleixner , Wanpeng Li , Ingo Molnar Subject: Re: [PATCH v2 1/2] sched/cputime: Use only pi_lock to protect sum_exec_runtime read Message-ID: <20160905141657.GA22190@redhat.com> References: <1473066782-19372-1-git-send-email-sgruszka@redhat.com> <1473066782-19372-2-git-send-email-sgruszka@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1473066782-19372-2-git-send-email-sgruszka@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 05 Sep 2016 14:20:18 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 05, 2016 at 11:13:01AM +0200, Stanislaw Gruszka wrote: > Currently we protect 64bit sum_exec_runtime read on 32bit cpus using > task_rq_lock() which internally takes t->pi_lock and rq->lock. Taking > rq->lock is not needed in this case. I looked more at kernel/sched/ code and now I'm not sure about this. I assumed that update_curr() is called with rq->curr->pi_lock, but looks like it can be called with some other task->pi_lock not necessary the rq->curr, hence looks that we need rq->lock to assure protection Stanislaw > Signed-off-by: Stanislaw Gruszka > --- > kernel/sched/cputime.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c > index b93c72d..5535774 100644 > --- a/kernel/sched/cputime.c > +++ b/kernel/sched/cputime.c > @@ -315,12 +315,11 @@ static inline u64 read_sum_exec_runtime(struct task_struct *t) > static u64 read_sum_exec_runtime(struct task_struct *t) > { > u64 ns; > - struct rq_flags rf; > - struct rq *rq; > + unsigned long flags; > > - rq = task_rq_lock(t, &rf); > + raw_spin_lock_irqsave(&t->pi_lock, flags); > ns = t->se.sum_exec_runtime; > - task_rq_unlock(rq, t, &rf); > + raw_spin_unlock_irqrestore(&t->pi_lock, flags); > > return ns; > } > -- > 1.8.3.1 >