Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp7407pxj; Thu, 13 May 2021 19:10:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrtOKi1ne8NBw8IPhCa8LqKLYg2LJW2fLPi/kH+O/mcs+3bBbLYOILkAw+HfibQXupwtFP X-Received: by 2002:a17:906:36da:: with SMTP id b26mr46802514ejc.8.1620958217179; Thu, 13 May 2021 19:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620958217; cv=none; d=google.com; s=arc-20160816; b=ub1cvILzrNR67yH37JNpvX90+73N6buMGvUbACei3vjjA+Hte39vCVxow/HNMsSz9X i7zB+8e7m+foODOUxECKw/sXY+mtmmoTVUegIrV1E6UAr5mf3OW0HlT/4pjSc9urGnbA W7xtsXeOMzqgvfSKeGkyaPGjDY7K0zFAYGBd+4pMn/fNAD7tD0OEocj0xnOHLa4PAAG0 1OhhKmxigr4Hxg8LezebkujTvd9SubtThyjlwkrImPvcdGEiiqlcXhzfU81UGGwgmWAx 9wcjvqVgOSiaNCIVydQNYLkmcapM9YL1336KJnpHwElTmK8h9GYra4HNNxAjytsaW8Ec rBeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=PzU6Nec0u/bWUzoVTQzGjPD1233RhMkO44ZIA/naB5E=; b=townNn246xu0cvczpqqO2ToX1Og3oo4zR3hSMXJecn+pJBkl936O+8ZIIb790l8Kdm F58GD5CTMhZklNp7joPsAF9IdL9XFr3j+VMwNyE1lyeBn5+HwAK1p7ejG0/gR++N4vh7 1NN2LV731mXw1ABA890CLl40d1Ywy1ccWQgM6LjbPU13TUhd8yBn+uhqBoVPoxhbuGSp VMk6yvqMswtQePd7XwXVYYWJ0C8lX/s3SLdc0E3RBOF9unpzJGoGPoUrQXuoq6p8cGQA HW/FT1HN7JhF2OtD7fJ5Zq+84t7gvtLuSug/YjwmVuG822lgtJ5oB9HrmVzXd+6uJ2Ym QR8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EaDx7N7c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ne40si4213958ejc.551.2021.05.13.19.09.54; Thu, 13 May 2021 19:10:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EaDx7N7c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231145AbhEMXMl (ORCPT + 99 others); Thu, 13 May 2021 19:12:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:52504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229544AbhEMXMl (ORCPT ); Thu, 13 May 2021 19:12:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3063061263; Thu, 13 May 2021 23:11:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620947490; bh=shkz49Q/KRzo+03G48Nq9Ll4xVIQp0LbIA9DLkkqVz0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EaDx7N7ckbHe7vOGU5txF/GKUOLGjdJGdk68flGReecUuSrns+XvpRAz5fipqZRZo P7niJImBhH0NBV6t1xNyozlOXo2Ql05JuhgZMWtemWTZBIeZ+vHpPRVX7WSMOOxyI7 fnJCDAPgwcU0J+js83sOnlLWScbcr+19caIkbsdVBFB2y/zAPRJr9JapsxSPrVL2On pJOQl0kvIG7d70vE8HTW0r4aY7eH1NzZUfkc7/crgo7Mb+2yf3jU11MyfhSqMV93dJ KJRCh+47NUfmlRj2Eeqc9J14QD8nTNdAD5x2qWmYnnSgFdbiGNze5pi+3WapOdVSEf FdbNpiqvnPMyA== Date: Fri, 14 May 2021 01:11:27 +0200 From: Frederic Weisbecker To: "Paul E. McKenney" Cc: Peter Zijlstra , kernel test robot , Ingo Molnar , LKML , lkp@lists.01.org, lkp@intel.com, ying.huang@intel.com, feng.tang@intel.com, zhengjun.xing@intel.com Subject: Re: [entry] 47b8ff194c: will-it-scale.per_process_ops -3.0% regression Message-ID: <20210513231127.GA165500@lothringen> References: <20210428071653.GC13086@xsang-OptiPlex-9020> <20210513174636.GB975577@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210513174636.GB975577@paulmck-ThinkPad-P17-Gen-1> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 13, 2021 at 10:46:36AM -0700, Paul E. McKenney wrote: > On Thu, May 13, 2021 at 10:19:21AM +0200, Peter Zijlstra wrote: > > On Wed, Apr 28, 2021 at 03:16:53PM +0800, kernel test robot wrote: > > > > > > > > > Greeting, > > > > > > FYI, we noticed a -3.0% regression of will-it-scale.per_process_ops due to commit: > > > > > > > > > commit: 47b8ff194c1fd73d58dc339b597d466fe48c8958 ("entry: Explicitly flush pending rcuog wakeup before last rescheduling point") > > > > So the RCU bits are in rcu_user_enter(), which is called from > > __context_tracking_enter() aka user_enter(), which is under > > context_tracking_enabled(). > > > > But the new code in entry is not; we now unconditionally call > > rcu_nocb_flush_deferred_wakeup(). Did that want to be under > > context_tracking_enabled() as well? > > > > Frederic, Paul? > > My argument in favor of the change below is that if there is no context > tracking, then scheduling-clock interrupts will happen on all non-idle > CPUs. The next scheduling-clock interrupt will check this deferred-wakeup > state, and if set, cause rcu_core() to be invoked (for example, within the > RCU_SOFTIRQ handler). And rcu_core() invokes do_nocb_deferred_wakeup(), > which takes care of this. > > For idle CPUs, do_idle() invokes rcu_nocb_flush_deferred_wakeup(). > > Frederic, any cases that I am missing? That sounds good, but two things: 1) Even if context tracking is not running, we still need to handle deferred wakeups on idle. But all user/guest/idle currently use the same function. 2) Context tracking may be running even when full nohz is not. But here only full nohz is concerned. So the change should rather be as follows (completely untested!). I rather put the static key check in tick.h in order not to involve deep dependencies inside rcupdate.h (especially rcupdate.h -> tick.h -> sched.h) diff --git a/include/linux/entry-kvm.h b/include/linux/entry-kvm.h index 8b2b1d68b954..136b8d97d8c0 100644 --- a/include/linux/entry-kvm.h +++ b/include/linux/entry-kvm.h @@ -3,6 +3,7 @@ #define __LINUX_ENTRYKVM_H #include +#include /* Transfer to guest mode work */ #ifdef CONFIG_KVM_XFER_TO_GUEST_WORK @@ -57,7 +58,7 @@ int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu); static inline void xfer_to_guest_mode_prepare(void) { lockdep_assert_irqs_disabled(); - rcu_nocb_flush_deferred_wakeup(); + tick_nohz_user_enter_prepare(); } /** diff --git a/include/linux/tick.h b/include/linux/tick.h index 0bb80a7f05b9..bfd571f18cfd 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -11,6 +11,7 @@ #include #include #include +#include #ifdef CONFIG_GENERIC_CLOCKEVENTS extern void __init tick_init(void); @@ -304,4 +305,10 @@ static inline void tick_nohz_task_switch(void) __tick_nohz_task_switch(); } +static inline void tick_nohz_user_enter_prepare(void) +{ + if (tick_nohz_full_cpu(smp_processor_id())) + rcu_nocb_flush_deferred_wakeup(); +} + #endif diff --git a/kernel/entry/common.c b/kernel/entry/common.c index a0b3b04fb596..bf16395b9e13 100644 --- a/kernel/entry/common.c +++ b/kernel/entry/common.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "common.h" @@ -186,7 +187,7 @@ static unsigned long exit_to_user_mode_loop(struct pt_regs *regs, local_irq_disable_exit_to_user(); /* Check if any of the above work has queued a deferred wakeup */ - rcu_nocb_flush_deferred_wakeup(); + tick_nohz_user_enter_prepare(); ti_work = READ_ONCE(current_thread_info()->flags); } @@ -202,7 +203,7 @@ static void exit_to_user_mode_prepare(struct pt_regs *regs) lockdep_assert_irqs_disabled(); /* Flush pending rcuog wakeup before the last need_resched() check */ - rcu_nocb_flush_deferred_wakeup(); + tick_nohz_user_enter_prepare(); if (unlikely(ti_work & EXIT_TO_USER_MODE_WORK)) ti_work = exit_to_user_mode_loop(regs, ti_work);