Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp95755pxa; Wed, 26 Aug 2020 18:22:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMnvlu0D/JgBqUM2OW3/m+fJXhtqDQOUSsONza48GCziAuxe9xaCgoiRZitjRJu9wTLeMn X-Received: by 2002:a17:906:7197:: with SMTP id h23mr8465304ejk.20.1598491364012; Wed, 26 Aug 2020 18:22:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598491364; cv=none; d=google.com; s=arc-20160816; b=x3YFq+Z7ruVvhVWfsMIqIf9YcqfjBMvTLGgwFxILqY1K5eBi0lC0uytU49FeCd4xya 8Nyr+nxw78k40I9kqi1+8NqTDTB1cCTDvxvbtTBYx76kuX706LpWietnzstDGEa4h9W3 y/Q1X7AW3QBcxohezSxCN0GgFa2fTUjOMZkNe3aOBpRxWBuolBDUlJ7g5IkSkzq9x0Ae T7EYawiKMODQNeXCgI+mH206+wPhV2fW1o37HJxF135Ue/RnjMaSH3KnmasjoaWGd56F Ghh0+utMWVkP0EUbhnzV+GREzCKVsSxonqaE0hYq2twHKSA//wstkYn2EPsRI8UU5zHp jy6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=3iBsmvYXjS76V9LCK+z2HaGa73AfxRjgBvqaEc9ru4U=; b=JWZl02P9RNx/89dTeZ8X3iowvUnho7gIBZCzJj3R7UopJ2McDqWdZ60+PdqlIUEVQt /StOlNkUsS+n7SjloNXf6j3qoJKs0OIwKhFSLP2l1DNixS2o/sHNF/MWWaiMfBEWE6bY ND0zjBlVqrlS+vIFSHop8qO3pYhBeZ5QsTiaa7ac20oMycI75bDI884lP6mmDVUxGDzX rLpqakVJyFcmL9gchzhaW5a7YHWwlCEleNsU4j+QUkML40IlOJicp2/wAh1VWEvdP8G1 Mzi9KB/bV3B5CI0ZwA/pMJWefvlQNhCSsR9xZfvTm40iEEpiGnCOhx+vPJvYQyJFB1gH EJbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=nAPU2Dd5; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q12si280421eju.680.2020.08.26.18.22.20; Wed, 26 Aug 2020 18:22:43 -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=@joelfernandes.org header.s=google header.b=nAPU2Dd5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726790AbgH0BSa (ORCPT + 99 others); Wed, 26 Aug 2020 21:18:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726779AbgH0BS2 (ORCPT ); Wed, 26 Aug 2020 21:18:28 -0400 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4A9CC06179F for ; Wed, 26 Aug 2020 18:18:28 -0700 (PDT) Received: by mail-qt1-x843.google.com with SMTP id n18so3479695qtw.0 for ; Wed, 26 Aug 2020 18:18:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=3iBsmvYXjS76V9LCK+z2HaGa73AfxRjgBvqaEc9ru4U=; b=nAPU2Dd5ugwB//giUmF6/JiMEfIFheeg9ufhJZd/MLsppIIPnWIlrDhayxHh5sW9S4 jTZy5PxmkMPv5ElaZTiSbeyFn+BzqQjGoyJUf7DL6YA5LDDirvilpVAA2JASY9AW8UTz vVqtSnNTWu/w9PFpvENUg1cIFO/i5olq99fkk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3iBsmvYXjS76V9LCK+z2HaGa73AfxRjgBvqaEc9ru4U=; b=o45rFyXeyITWZAWXoFp3lFea7h8BzDsWm0VYqJua0o8oR0UZe3dcowkQ1z96LTTMPK hnKiUWiejVHih/0rKJCwazgR3nvaKdmJjmyCpoPb1N4pQ9pz71T4AgNPZAe0K8VmJ4ae 3y9jPSeoWrewq8KTnAi5llmpbBI6Ha6NhrOTLiTmLcj6FJynf2PhoO7ZPP5KbYBJjZ7b FHSILvDGl4XbogmnA1I09IdZCxWp1VL794ZpFf5SY+TNoRklM9BQ7XBcgaUzK1URt1MQ pzaf32sUejP+BX0j7tCHnTmvse2KLtMe5mBGeyP29jWyYWX5I2Ifd9YjkcC11q1Uifux rqCg== X-Gm-Message-State: AOAM532Z+Wpubu008Pp2QYrYoYMj4Qs1YkNo/gy9GjtczG3V0IBBpSAf xLrjqHrOE6xNxrkTTrB+iK1MGw== X-Received: by 2002:ac8:e89:: with SMTP id v9mr16971905qti.100.1598491107913; Wed, 26 Aug 2020 18:18:27 -0700 (PDT) Received: from localhost ([2620:15c:6:12:cad3:ffff:feb3:bd59]) by smtp.gmail.com with ESMTPSA id f14sm632376qkl.52.2020.08.26.18.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Aug 2020 18:18:27 -0700 (PDT) Date: Wed, 26 Aug 2020 21:18:26 -0400 From: Joel Fernandes To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, mingo@kernel.org, will@kernel.org, npiggin@gmail.com, elver@google.com, jgross@suse.com, paulmck@kernel.org, rostedt@goodmis.org, rjw@rjwysocki.net, svens@linux.ibm.com, tglx@linutronix.de Subject: Re: [PATCH v2 03/11] sched,idle,rcu: Push rcu_idle deeper into the idle path Message-ID: <20200827011826.GA1942571@google.com> References: <20200821084738.508092956@infradead.org> <20200821085348.310943801@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200821085348.310943801@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 21, 2020 at 10:47:41AM +0200, Peter Zijlstra wrote: > Lots of things take locks, due to a wee bug, rcu_lockdep didn't notice > that the locking tracepoints were using RCU. > > Push rcu_idle_{enter,exit}() as deep as possible into the idle paths, > this also resolves a lot of _rcuidle()/RCU_NONIDLE() usage. > > Specifically, sched_clock_idle_wakeup_event() will use ktime which > will use seqlocks which will tickle lockdep, and > stop_critical_timings() uses lock. I was wondering if those tracepoints should just use _rcuidle variant of the trace call. But that's a terrible idea considering that would add unwanted overhead I think. Reviewed-by: Joel Fernandes (Google) thanks, - Joel > > Signed-off-by: Peter Zijlstra (Intel) > Reviewed-by: Steven Rostedt (VMware) > Tested-by: Marco Elver > --- > drivers/cpuidle/cpuidle.c | 12 ++++++++---- > kernel/sched/idle.c | 22 ++++++++-------------- > 2 files changed, 16 insertions(+), 18 deletions(-) > > --- a/drivers/cpuidle/cpuidle.c > +++ b/drivers/cpuidle/cpuidle.c > @@ -145,13 +145,14 @@ static void enter_s2idle_proper(struct c > * executing it contains RCU usage regarded as invalid in the idle > * context, so tell RCU about that. > */ > - RCU_NONIDLE(tick_freeze()); > + tick_freeze(); > /* > * The state used here cannot be a "coupled" one, because the "coupled" > * cpuidle mechanism enables interrupts and doing that with timekeeping > * suspended is generally unsafe. > */ > stop_critical_timings(); > + rcu_idle_enter(); > drv->states[index].enter_s2idle(dev, drv, index); > if (WARN_ON_ONCE(!irqs_disabled())) > local_irq_disable(); > @@ -160,7 +161,8 @@ static void enter_s2idle_proper(struct c > * first CPU executing it calls functions containing RCU read-side > * critical sections, so tell RCU about that. > */ > - RCU_NONIDLE(tick_unfreeze()); > + rcu_idle_exit(); > + tick_unfreeze(); > start_critical_timings(); > > time_end = ns_to_ktime(local_clock()); > @@ -229,16 +231,18 @@ int cpuidle_enter_state(struct cpuidle_d > /* Take note of the planned idle state. */ > sched_idle_set_state(target_state); > > - trace_cpu_idle_rcuidle(index, dev->cpu); > + trace_cpu_idle(index, dev->cpu); > time_start = ns_to_ktime(local_clock()); > > stop_critical_timings(); > + rcu_idle_enter(); > entered_state = target_state->enter(dev, drv, index); > + rcu_idle_exit(); > start_critical_timings(); > > sched_clock_idle_wakeup_event(); > time_end = ns_to_ktime(local_clock()); > - trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu); > + trace_cpu_idle(PWR_EVENT_EXIT, dev->cpu); > > /* The cpu is no longer idle or about to enter idle. */ > sched_idle_set_state(NULL); > --- a/kernel/sched/idle.c > +++ b/kernel/sched/idle.c > @@ -54,17 +54,18 @@ __setup("hlt", cpu_idle_nopoll_setup); > > static noinline int __cpuidle cpu_idle_poll(void) > { > + trace_cpu_idle(0, smp_processor_id()); > + stop_critical_timings(); > rcu_idle_enter(); > - trace_cpu_idle_rcuidle(0, smp_processor_id()); > local_irq_enable(); > - stop_critical_timings(); > > while (!tif_need_resched() && > - (cpu_idle_force_poll || tick_check_broadcast_expired())) > + (cpu_idle_force_poll || tick_check_broadcast_expired())) > cpu_relax(); > - start_critical_timings(); > - trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, smp_processor_id()); > + > rcu_idle_exit(); > + start_critical_timings(); > + trace_cpu_idle(PWR_EVENT_EXIT, smp_processor_id()); > > return 1; > } > @@ -91,7 +92,9 @@ void __cpuidle default_idle_call(void) > local_irq_enable(); > } else { > stop_critical_timings(); > + rcu_idle_enter(); > arch_cpu_idle(); > + rcu_idle_exit(); > start_critical_timings(); > } > } > @@ -158,7 +161,6 @@ static void cpuidle_idle_call(void) > > if (cpuidle_not_available(drv, dev)) { > tick_nohz_idle_stop_tick(); > - rcu_idle_enter(); > > default_idle_call(); > goto exit_idle; > @@ -178,21 +180,17 @@ static void cpuidle_idle_call(void) > u64 max_latency_ns; > > if (idle_should_enter_s2idle()) { > - rcu_idle_enter(); > > entered_state = call_cpuidle_s2idle(drv, dev); > if (entered_state > 0) > goto exit_idle; > > - rcu_idle_exit(); > - > max_latency_ns = U64_MAX; > } else { > max_latency_ns = dev->forced_idle_latency_limit_ns; > } > > tick_nohz_idle_stop_tick(); > - rcu_idle_enter(); > > next_state = cpuidle_find_deepest_state(drv, dev, max_latency_ns); > call_cpuidle(drv, dev, next_state); > @@ -209,8 +207,6 @@ static void cpuidle_idle_call(void) > else > tick_nohz_idle_retain_tick(); > > - rcu_idle_enter(); > - > entered_state = call_cpuidle(drv, dev, next_state); > /* > * Give the governor an opportunity to reflect on the outcome > @@ -226,8 +222,6 @@ static void cpuidle_idle_call(void) > */ > if (WARN_ON_ONCE(irqs_disabled())) > local_irq_enable(); > - > - rcu_idle_exit(); > } > > /* > >