Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1691554imm; Fri, 11 May 2018 22:07:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrKcHj9VmWtFpL+sv9Dk/xRYMvKy7z4x3bUEN2pg5ed28vCISWoiv6eNghxyG5Z1JRx5kyr X-Received: by 2002:a62:415d:: with SMTP id o90-v6mr1730580pfa.140.1526101646880; Fri, 11 May 2018 22:07:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526101646; cv=none; d=google.com; s=arc-20160816; b=YIjhB1OVMOjDrYgIPwRkLD5LukExKikiZIsnAXoEY/GNxwu4SbvfzKWACvRfIs1bB0 y26tiSwDchl2OsYYcogvuIWSue/8IjjAImWjcgYp9GYG8wedfOrBT5JKHqiBVNWOYnLu caa3i9UnAgUQN512HA435FD7iRVs83B149uW5ZRUSUJBSciDj6x7VlQbyf1mSeCEv1TW V2uiX9UUNGEJof/xLt1UL6CnkucTA00pIjZfbYytVjVgft5f6lDj1vqmoN6AkdLVfcib 0PYPe+osdxhBG4IDirWzmmKKa5LfmzspOH3KCQZpf+2z2MlE7YDgo2pP6p11QBs2vs/6 UmKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:reply-to:subject:cc:to:from:date :arc-authentication-results; bh=j1o3ROaSKLzxm00H26WxLBNx8z2hCgkY4c0pn8Jz/KA=; b=ZFokq2AWt+unsBILwgv4O49kFSy226MH7wIa+OHP7Fs1yW3vGg/7PanbdPwwZ/sRk3 a86x4OYBLXAeds9SVZY57NOelZhSYVM72h47+soePfw9d3in/LW0wtZkriEYXrFJXiKE rPGpGZG00kY2mos7FB/3hbE/6WvBlexIgEN3csbfNt+JsJXRxk6+lDsAh9HNqI9UxdLB de5cAKhM0H3mPukQysUY8uCiD/Nwd783JLXUPM96KqaWhP1UYboF1lGUSibEa8GvhOjS GdCuA/4Fy/Nq39wYwVitAr2lJrEqlSdatebV8Iye6JruBf9SawK2SnZDX7FM6ec6Imlv HAHg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b35-v6si4677224plh.36.2018.05.11.22.07.11; Fri, 11 May 2018 22:07:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750805AbeELFHB (ORCPT + 99 others); Sat, 12 May 2018 01:07:01 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43186 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750722AbeELFHA (ORCPT ); Sat, 12 May 2018 01:07:00 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4C558bl022015 for ; Sat, 12 May 2018 01:06:59 -0400 Received: from e16.ny.us.ibm.com (e16.ny.us.ibm.com [129.33.205.206]) by mx0b-001b2d01.pphosted.com with ESMTP id 2hwh42ybs8-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 12 May 2018 01:06:59 -0400 Received: from localhost by e16.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 12 May 2018 01:06:58 -0400 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e16.ny.us.ibm.com (146.89.104.203) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 12 May 2018 01:06:56 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4C56tmZ48824524; Sat, 12 May 2018 05:06:55 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 19963B2064; Sat, 12 May 2018 02:08:54 -0400 (EDT) Received: from paulmck-ThinkPad-W541 (unknown [9.85.188.179]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP id BC014B204D; Sat, 12 May 2018 02:08:53 -0400 (EDT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id A48E216C2ADD; Fri, 11 May 2018 22:08:24 -0700 (PDT) Date: Fri, 11 May 2018 22:08:24 -0700 From: "Paul E. McKenney" To: Joel Fernandes Cc: Byungchul Park , jiangshanlai@gmail.com, josh@joshtriplett.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, linux-kernel@vger.kernel.org, kernel-team@lge.com, peterz@infradead.org Subject: Re: [PATCH] rcu: Report a quiescent state when it's exactly in the state Reply-To: paulmck@linux.vnet.ibm.com References: <1526027434-21237-1-git-send-email-byungchul.park@lge.com> <3af4cec0-4019-e3ac-77f9-8631252fb6da@lge.com> <20180511161746.GX26088@linux.vnet.ibm.com> <20180511224138.GA89902@joelaf.mtv.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180511224138.GA89902@joelaf.mtv.corp.google.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 18051205-0024-0000-0000-00000357C46C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009010; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000260; SDB=6.01031055; UDB=6.00526987; IPR=6.00810186; MB=3.00021064; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-12 05:06:58 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18051205-0025-0000-0000-000047FB9BC0 Message-Id: <20180512050824.GF26088@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-11_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805120045 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 11, 2018 at 03:41:38PM -0700, Joel Fernandes wrote: > On Fri, May 11, 2018 at 09:17:46AM -0700, Paul E. McKenney wrote: > > On Fri, May 11, 2018 at 09:57:54PM +0900, Byungchul Park wrote: > > > Hello folks, > > > > > > I think I wrote the title in a misleading way. > > > > > > Please change the title to something else such as, > > > "rcu: Report a quiescent state when it's in the state" or, > > > "rcu: Add points reporting quiescent states where proper" or so on. > > > > > > On 2018-05-11 오후 5:30, Byungchul Park wrote: > > > >We expect a quiescent state of TASKS_RCU when cond_resched_tasks_rcu_qs() > > > >is called, no matter whether it actually be scheduled or not. However, > > > >it currently doesn't report the quiescent state when the task enters > > > >into __schedule() as it's called with preempt = true. So make it report > > > >the quiescent state unconditionally when cond_resched_tasks_rcu_qs() is > > > >called. > > > > > > > >And in TINY_RCU, even though the quiescent state of rcu_bh also should > > > >be reported when the tick interrupt comes from user, it doesn't. So make > > > >it reported. > > > > > > > >Lastly in TREE_RCU, rcu_note_voluntary_context_switch() should be > > > >reported when the tick interrupt comes from not only user but also idle, > > > >as an extended quiescent state. > > > > > > > >Signed-off-by: Byungchul Park > > > >--- > > > > include/linux/rcupdate.h | 4 ++-- > > > > kernel/rcu/tiny.c | 6 +++--- > > > > kernel/rcu/tree.c | 4 ++-- > > > > 3 files changed, 7 insertions(+), 7 deletions(-) > > > > > > > >diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h > > > >index ee8cf5fc..7432261 100644 > > > >--- a/include/linux/rcupdate.h > > > >+++ b/include/linux/rcupdate.h > > > >@@ -195,8 +195,8 @@ static inline void exit_tasks_rcu_finish(void) { } > > > > */ > > > > #define cond_resched_tasks_rcu_qs() \ > > > > do { \ > > > >- if (!cond_resched()) \ > > > >- rcu_note_voluntary_context_switch_lite(current); \ > > > >+ rcu_note_voluntary_context_switch_lite(current); \ > > > >+ cond_resched(); \ > > > > Ah, good point. > > > > Peter, I have to ask... Why is "cond_resched()" considered a preemption > > while "schedule()" is not? > > Infact something interesting I inferred from the __schedule loop related to > your question: > > switch_count can either be set to prev->invcsw or prev->nvcsw. If we can > assume that switch_count reflects whether the context switch is involuntary > or voluntary, > > task-running-state preempt switch_count > 0 (running) 1 involuntary > 0 0 involuntary > 1 0 voluntary > 1 1 involuntary > > According to the above table, both the task's running state and the preempt > parameter to __schedule should be used together to determine if the switch is > a voluntary one or not. > > So this code in rcu_note_context_switch should really be: > if (!preempt && !(current->state & TASK_RUNNING)) > rcu_note_voluntary_context_switch_lite(current); > > According to the above table, cond_resched always classifies as an > involuntary switch which makes sense to me. Even though cond_resched is > explicitly called, its still sort of involuntary in the sense its not called > into the scheduler for sleeping, but rather for seeing if something else can > run instead (a preemption point). Infact none of the task deactivation in the > __schedule loop will run if cond_resched is used. > > I agree that if schedule was called directly but with TASK_RUNNING=1, then > that could probably be classified an involuntary switch too... > > Also since we're deciding to call rcu_note_voluntary_context_switch_lite > unconditionally, then IMO this comment on that macro: > > /* > * Note a voluntary context switch for RCU-tasks benefit. This is a > * macro rather than an inline function to avoid #include hell. > */ > #ifdef CONFIG_TASKS_RCU > #define rcu_note_voluntary_context_switch_lite(t) > > Should be changed to: > > /* > * Note a attempt to perform a voluntary context switch for RCU-tasks > * benefit. This is called even in situations where a context switch > * didn't really happen even though it was requested. This is a > * macro rather than an inline function to avoid #include hell. > */ > #ifdef CONFIG_TASKS_RCU > #define rcu_note_voluntary_context_switch_lite(t) > > Right? > > Correct me if I'm wrong about anything, thanks, The starting point for me is that Tasks RCU is a special-purpose mechanism for freeing trampolines in PREEMPT=y kernels. The approach is to arrange for the trampoline to be inaccessible to future execution, wait for a tasks-RCU grace period, then free the trampoline. So a tasks-RCU grace period must wait until all tasks have spent at least some time outside of a trampoline. My understanding is that trampolines cannot contain preemption points, such as cond_resched() and cond_resched_tasks_rcu_qs(), so we want to count them as quiescent states regardless of whether or not any associated context switch is counted as involuntary. What situations lead to the second line of your table above? The sched_yield() system call, but trampolines don't do system calls, either, as far as I know. So it looks to me like that test can leave out the TASK_RUNNING check. Or am I missing something subtle? Thanx, Paul