Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3817451ybg; Mon, 28 Oct 2019 20:14:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkVDUE31e25rCeI530FY5UZE6FSEJAfOSEfbo8dVczdbSZ9L/h+Yt4ICArFjtOf0sWQ2+3 X-Received: by 2002:a17:906:6d84:: with SMTP id h4mr1101133ejt.262.1572318853582; Mon, 28 Oct 2019 20:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572318853; cv=none; d=google.com; s=arc-20160816; b=xKIomIGfELbduCEil/+0CF98zjU1v+RFZdb9Cbjuao3JRkCkJ22m7jQhBxHQrlX4R4 4kjQFz/Ye2yzcMvBh66Or90eLoRXewbpWhxODRAopGfK3WWVIIzNo+Ty9sTwn4RHhmZD tVygvMCccKto2zWpq8OXpcwvhxxy4P1HgQZsMtWVFJrx2q3ylrSepHh7LexBiFU5V2sV RttFrGh8+QRTNfWrNDYOa8hHiAlFHu8/NU2q2nBxHv08TAnZN6TH1FvYPNGPnDkfus/X lPBWnl4eVfL6hyjQWTL5R4qQ/aRbcXFFbCjhQnfuR9HRLrscsMf9xp0OBjsmw3DbjyWa ZOLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=LYQJBoLlXMijB61UyPZNPGjwfcxayF05c36JKITFNco=; b=tGwa7j6xTzB/V24asYOt3gav07173NNVZg2dZYYtKMwg+yD6siw7T7GL6WdMgGOet2 XbDdsUgKbvzoUlUeEpyopi9E69T8T2ElRLdSfmBgpiDpoaV8K1X9EIw/vxJXS0SKEajS Jzpq4SFx1Eu1dzTQ7I33NudDvbpj41w8+zjwwLT0+xrS1VYPoArSELIQDHmzbV7vvobK cULZKgIIS8xM1XjdCGbRQbVAoXfcm21kvz87lV0I6GfW0K9vLHqhE2H05nsU6KMDCaVI Q1+wsemGdE64m0K/OhQbXw740QlZOB9kMJ8ImEek0OqlHf/FzFSiGlfui8g1SASX0IHZ u+ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=H476hzYT; 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 c30si9262364ede.125.2019.10.28.20.13.49; Mon, 28 Oct 2019 20:14:13 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=H476hzYT; 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 S1729009AbfJ1PVr (ORCPT + 99 others); Mon, 28 Oct 2019 11:21:47 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:46312 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727615AbfJ1PVr (ORCPT ); Mon, 28 Oct 2019 11:21:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=LYQJBoLlXMijB61UyPZNPGjwfcxayF05c36JKITFNco=; b=H476hzYTFEKh98cq8PNtPeKoR Ojuzom3FRoQ1ViHJD70YdoENeuLnlImHSvX3aHS12eCSmh5GZzVIWcIe0MGqPcV8xIAVw1sFifich x4mt23MPw1TxnjTGt32WIIdAc73cjcVHnJVJUDBodBDR6LqWiNIeSZsxoVgO7xRTcVCQwsohi+uYK iUjl2VuGOA3O0E4v/HZDWgpdXYcxh6qunLM4HdZO/nbN11WwDCCao1bKuZq0FFgRB8vWmH5atuzvS NKfpk9bQsDd9CUUjO1PkgxVTpx/oEToBUmT/kbv0FbUqKEe5bB10VSKGEaELZLAfYqDc3PA+Of3ur YpYFaPsqA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iP6pu-000472-5C; Mon, 28 Oct 2019 15:21:38 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id DED44300E4D; Mon, 28 Oct 2019 16:20:34 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 2F4E12B4468C8; Mon, 28 Oct 2019 16:21:35 +0100 (CET) Date: Mon, 28 Oct 2019 16:21:35 +0100 From: Peter Zijlstra To: Thara Gopinath Cc: mingo@redhat.com, ionela.voinescu@arm.com, vincent.guittot@linaro.org, rui.zhang@intel.com, edubezval@gmail.com, qperret@google.com, linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, javi.merino@kernel.org, daniel.lezcano@linaro.org Subject: Re: [Patch v4 2/6] sched: Add infrastructure to store and update instantaneous thermal pressure Message-ID: <20191028152135.GC4097@hirez.programming.kicks-ass.net> References: <1571776465-29763-1-git-send-email-thara.gopinath@linaro.org> <1571776465-29763-3-git-send-email-thara.gopinath@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1571776465-29763-3-git-send-email-thara.gopinath@linaro.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 22, 2019 at 04:34:21PM -0400, Thara Gopinath wrote: > Add thermal.c and thermal.h files that provides interface > APIs to initialize, update/average, track, accumulate and decay > thermal pressure per cpu basis. A per cpu variable delta_capacity is > introduced to keep track of instantaneous per cpu thermal pressure. > Thermal pressure is the delta between maximum capacity and capped > capacity due to a thermal event. > API trigger_thermal_pressure_average is called for periodic accumulate > and decay of the thermal pressure. It is to to be called from a > periodic tick function. This API passes on the instantaneous delta > capacity of a cpu to update_thermal_load_avg to do the necessary > accumulate, decay and average. > API update_thermal_pressure is for the system to update the thermal > pressure by providing a capped frequency ratio. > Considering, trigger_thermal_pressure_average reads delta_capacity and > update_thermal_pressure writes into delta_capacity, one can argue for > some sort of locking mechanism to avoid a stale value. > But considering trigger_thermal_pressure_average can be called from a > system critical path like scheduler tick function, a locking mechanism > is not ideal. This means that it is possible the delta_capacity value > used to calculate average thermal pressure for a cpu can be > stale for upto 1 tick period. Please use a blank line at the end of a paragraph. > Signed-off-by: Thara Gopinath > --- > include/linux/sched.h | 8 ++++++++ > kernel/sched/Makefile | 2 +- > kernel/sched/thermal.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ > kernel/sched/thermal.h | 13 +++++++++++++ > 4 files changed, 67 insertions(+), 1 deletion(-) > create mode 100644 kernel/sched/thermal.c > create mode 100644 kernel/sched/thermal.h These are some tiny files, do these functions really need their own little files? > diff --git a/kernel/sched/thermal.c b/kernel/sched/thermal.c > new file mode 100644 > index 0000000..0c84960 > --- /dev/null > +++ b/kernel/sched/thermal.c > @@ -0,0 +1,45 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Scheduler Thermal Interactions > + * > + * Copyright (C) 2018 Linaro, Inc., Thara Gopinath > + */ > + > +#include > +#include "sched.h" > +#include "pelt.h" > +#include "thermal.h" > + > +static DEFINE_PER_CPU(unsigned long, delta_capacity); > + > +/** > + * update_thermal_pressure: Update thermal pressure > + * @cpu: the cpu for which thermal pressure is to be updated for > + * @capped_freq_ratio: capped max frequency << SCHED_CAPACITY_SHIFT / max freq > + * > + * capped_freq_ratio is normalized into capped capacity and the delta between > + * the arch_scale_cpu_capacity and capped capacity is stored in per cpu > + * delta_capacity. > + */ > +void update_thermal_pressure(int cpu, u64 capped_freq_ratio) > +{ > + unsigned long __capacity, delta; > + > + /* Normalize the capped freq ratio */ > + __capacity = (capped_freq_ratio * arch_scale_cpu_capacity(cpu)) >> > + SCHED_CAPACITY_SHIFT; > + delta = arch_scale_cpu_capacity(cpu) - __capacity; > + pr_debug("updating cpu%d thermal pressure to %lu\n", cpu, delta); Surely we can do without the pr_debug() here? > + per_cpu(delta_capacity, cpu) = delta; > +}