Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4781619ybf; Wed, 4 Mar 2020 10:31:38 -0800 (PST) X-Google-Smtp-Source: ADFU+vvXNovOMluLejDMUTNHOrscxI6ITQojhk7IDw8Ha5wMCHvmC9zPwpsbKNUjXWfQvcP/wVDO X-Received: by 2002:aca:a98a:: with SMTP id s132mr2599047oie.141.1583346698359; Wed, 04 Mar 2020 10:31:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583346698; cv=none; d=google.com; s=arc-20160816; b=duA98Db7BUfhgNJHHpuUTIXbSuqq230BMHkjQi1WgOGA+LeiCFXXmCEzN2751syFWq nkYmWXoVeolsR3bQ5dWeBo7MOlaPp1LCufmeEui03L+PvgfUuCPZLPCIoQnh/vMGH6Hk 6nTEbb+ehrq2xv7AG1pgD5KDZx1QJ8DUrgfs5oHNrK9oHBdDNyXQxwiDj9pCmewLc69d 2S25SgcC3m2T1tzcKXzIFjl2PF1BvFwkAVQ5MrkfAy72s4Re6nXkp66mwh5TzcVl8BA3 q6x1pywH5sLnJWaDdgHo0K7FCUljfY31nlWSr1vqxg7HWPR7RbzjN7KvDikjaeBx+Hhs qN+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references; bh=cNssy2h4OBR98teMsNYAof41kwww9CWU/dtbzC+DD20=; b=YMDdcAuw/v08Lh7ub1wRUz2j43pTzxXTKn7r2Xlxd4u/VUvpQNOm/trxcU3gUEu0PZ Kc+2EYASGKB4NQosCqoFputQ62AJzDCDKv2m5KSNdVH5Q0/mwSvxqsvMYeaiwcF7JJyD etnosydC6L5i9BgxkLfCrB0S4qcGNqksyUn8IgtPcb0QEcIkLMMtnrKM0ftI2eB/ofdD TD3i8lvTKNrVLGy3LreSknrRcOBK67JYLVOZ3gNWnoiEP9K8Gocu3YnpO9TMhzduYCPj ICg9+TdM3zN8Wtezn+aIF8YjGf0WIb5DdFrXNvaGZecDkYmVgHdPNDLaJ/42qu+EHel+ zuJQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w25si1324539otm.223.2020.03.04.10.31.26; Wed, 04 Mar 2020 10:31:38 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730021AbgCDSbU (ORCPT + 99 others); Wed, 4 Mar 2020 13:31:20 -0500 Received: from foss.arm.com ([217.140.110.172]:38340 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729600AbgCDSbU (ORCPT ); Wed, 4 Mar 2020 13:31:20 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5BE5031B; Wed, 4 Mar 2020 10:31:19 -0800 (PST) Received: from e113632-lin (e113632-lin.cambridge.arm.com [10.1.194.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0B45A3F6C4; Wed, 4 Mar 2020 10:31:17 -0800 (PST) References: <20200304114844.17700-1-daniel.lezcano@linaro.org> User-agent: mu4e 0.9.17; emacs 26.3 From: Valentin Schneider To: Daniel Lezcano Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , "open list\:SCHEDULER" Subject: Re: [PATCH] sched: fair: Use the earliest break even In-reply-to: Date: Wed, 04 Mar 2020 18:31:10 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 04 2020, Daniel Lezcano wrote: >> With that said, that comment actually raises a valid point: picking >> recently idled CPUs might give us warmer cache. So by using the break >> even stat, we can end up picking CPUs with colder caches (have been >> idling for longer) than the current logic would. I suppose more testing >> will tell us where we stand. > > Actually I'm not sure this comment still applies. If the CPU is powered > down, the cache is flushed or we can be picking up CPU with their cache > totally trashed by interrupt processing. > >>> +++ b/kernel/sched/sched.h >>> @@ -1015,6 +1015,7 @@ struct rq { >>> #ifdef CONFIG_CPU_IDLE >>> /* Must be inspected within a rcu lock section */ >>> struct cpuidle_state *idle_state; >>> + s64 break_even; >> >> Why signed? This should be purely positive, right? > > It should be, but s64 complies with the functions ktime_to_ns signature. > > static inline s64 ktime_to_ns(const ktime_t kt) > Would there be harm then in simply storing: ktime_get_ns() + idle_state->exit_latency_ns (which is u64)? >>> #endif >>> }; >>> >>> @@ -1850,6 +1851,16 @@ static inline struct cpuidle_state *idle_get_state(struct rq *rq) >>> >>> return rq->idle_state; >>> } >>> + >>> +static inline void idle_set_break_even(struct rq *rq, s64 break_even) >>> +{ >>> + rq->break_even = break_even; >>> +} >>> + >>> +static inline s64 idle_get_break_even(struct rq *rq) >>> +{ >>> + return rq->break_even; >>> +} >> >> I'm not super familiar with the callsites for setting idle states, >> what's the locking situation there? Do we have any rq lock? > > It is safe, we are under rcu, this section was discussed several years > ago when introducing the idle_set_state(): > > https://lkml.org/lkml/2014/9/19/332 > Thanks for the link! So while we (should) have the relevant barriers, there can still be concurrent writing (from the CPU entering/leaving idle) and reading (from the CPU gathering stats). rcu_dereference() gives you READ_ONCE(), and the rcu_assign_pointer() should give you an smp_store_release(). What I'm thinking here is, if we have reasons not to use the RCU primitives, we should at least slap some READ/WRITE_ONCE() to the accesses. Also, can RCU even do anything about scalar values like the break even you're storing? >> In find_idlest_group_cpu() we're in a read-side RCU section, so the >> idle_state is protected (speaking of which, why isn't idle_get_state() >> using rcu_dereference()?), but that's doesn't cover the break even. >> >> IIUC at the very least we may want to give them the READ/WRITE_ONCE() >> treatment. >>