Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp829023ybx; Wed, 6 Nov 2019 09:02:17 -0800 (PST) X-Google-Smtp-Source: APXvYqyAOXpOUuXb5/wtRLgBa/ccw6xegTOx61HJctajLxTGuWz/j6g0GUedxceFnw7WMksMTDgK X-Received: by 2002:a17:906:2e5a:: with SMTP id r26mr16503291eji.283.1573059736945; Wed, 06 Nov 2019 09:02:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573059736; cv=none; d=google.com; s=arc-20160816; b=Ie1lm7DgwZziEAOsG5tnNqpIUz+i6AHAYATKAcbWLkMkqu+jW0aG5CECU7DBtAZui1 1hwIRjnDyXbqH/eHT9HCBkc320I+cQ3qjwH+sGVpIAkB260FHu8SJxBYwI0B73eC2bj0 45rrcy2QPddn4ND73kr2Z+vKxkDBYhh11YIwc/hpraA/NtN4xu8lzb1btHKFRk5ySkHe W+UIGhecbTjAQLM2a1UTrMaXBfos2aOT5DZvLYCv2If+dW+7t8o7OTKCwH0QL406n0W5 p056j0O5QMH73nQgCm0rKLmlzX2R3nFsDu5iIkMGg5Bh+TqSJD/MKj/xWqQHzWbtGo3R QQZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:dkim-signature; bh=TuUoy8AF5+MQM14Gz0S6Jwy4jFwogd2IsB/lmQVPWOU=; b=LstuIMXLlnAz0giUvnlJlQxErQTrmqoLg+pFnqnn03PV+Qx0pM5kZj0d/2hXZaeT0R v0zORvG7HJ+uD/OYT+qkZZLW665KEs7cHQ4N3z9+TfneN41oXWjBU2R2iabCRCv94y1/ qeH7sdo/FenlsyT+dc4TdMC2SSycQySnozrB0BDAyqkiee7vTL4ybHF/HWuBH0k5P9jN Ce7wLKVpTTJyCG4aVD4kisbFEc9jd0FUWFIQkdcsHVMGO8HlQ2/ewQEj56G+UYt4w1Mb PMHtXyFKHuxgjmOjJs/o6TUN2l1YEh0XQst9Tgp2tOcb6UTbSY0HMJZveeBqCZ7aEy4O G1GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AfrgdJhV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11si16189342ejw.201.2019.11.06.09.01.49; Wed, 06 Nov 2019 09:02:16 -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; dkim=pass header.i=@linaro.org header.s=google header.b=AfrgdJhV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732268AbfKFRAx (ORCPT + 99 others); Wed, 6 Nov 2019 12:00:53 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:38609 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732176AbfKFRAx (ORCPT ); Wed, 6 Nov 2019 12:00:53 -0500 Received: by mail-qk1-f193.google.com with SMTP id e2so25236917qkn.5 for ; Wed, 06 Nov 2019 09:00:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=TuUoy8AF5+MQM14Gz0S6Jwy4jFwogd2IsB/lmQVPWOU=; b=AfrgdJhVutnHKlbfu7HBPtnX6DELZ9cgqccdljj5em2WkeXm7A+cS4SocjHeEBGrey V5js7w0f6AKzhPOP8qngyoMT+q5ClnmhglpUJwzdcerB3rZVe5CIrup1wJYqXSNJp+aV K0fVk91f4XrVESCNS8JK7pmXSNRAePxBF6/BEkNOu5fAGE6adJaZ6u6DhWmSM+pciczh O4rHYR7nb518D25cuU+DdtAZOzyJhWOHjPZNN4jmXQv4zOD2pz6FZoAB3gg2lKadTRZC EPgO75NJk3QkDC5V4/hb8nxR+Kolt+kxnIu/TsXeHFrqzokUcvuo56nRZoX4aL6VpJA7 VZGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=TuUoy8AF5+MQM14Gz0S6Jwy4jFwogd2IsB/lmQVPWOU=; b=Nvb3KXuJYqFPdfbC5E9by+Xa572j/7/pRHJO/2DeTEv3xDC/5e9VdmzKNvryiikRor w/1noBvEHRbVtkf6BTNRxA7Tyt7Mr9S+u70Medwh8P5h6WG25K0gOn1sA1ozl0BYOVhI KfoJAwjds7Uwn+o/YjgXLj6WUWKdbBOENKlV5OKze07Pd43UUa8riBY6XuWCDW5LHfUR FXM0sBla7S17ZOX6sCmAX/4OJfTJgJgllkLGs2LUJQmQz/L6gb1o/DJt2sPq4JZeQXDg fz3SUNZk09hXmdduH3xOH8dWHnRYDsx9oi8EEg02aD2bmx3ARjKWvAarA4cyoYgdFivb gWKQ== X-Gm-Message-State: APjAAAUB9c8gkikS8vkbM0wtQ4mdD7n/jR7xqeDuKJavp2QbqAPyfp85 HQRQfPpE89iZvMkgsik3lbRF/w== X-Received: by 2002:a37:9f48:: with SMTP id i69mr2912658qke.273.1573059650812; Wed, 06 Nov 2019 09:00:50 -0800 (PST) Received: from [192.168.1.169] (pool-71-255-246-27.washdc.fios.verizon.net. [71.255.246.27]) by smtp.gmail.com with ESMTPSA id s123sm11680430qke.31.2019.11.06.09.00.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Nov 2019 09:00:50 -0800 (PST) Subject: Re: [Patch v5 2/6] sched/fair: Add infrastructure to store and update instantaneous thermal pressure To: Vincent Guittot References: <1572979786-20361-1-git-send-email-thara.gopinath@linaro.org> <1572979786-20361-3-git-send-email-thara.gopinath@linaro.org> Cc: Ingo Molnar , Peter Zijlstra , Ionela Voinescu , Zhang Rui , Eduardo Valentin , Quentin Perret , linux-kernel , Amit Kachhap , Javi Merino , Daniel Lezcano From: Thara Gopinath Message-ID: <5DC2FC41.8030308@linaro.org> Date: Wed, 6 Nov 2019 12:00:49 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Vincent, Thanks for the review On 11/06/2019 03:27 AM, Vincent Guittot wrote: > Hi Thara, > > > On Tue, 5 Nov 2019 at 19:49, Thara Gopinath wrote: >> >> Add interface APIs to initialize, update/average, track, accumulate >> and decay thermal pressure per cpu basis. A per cpu variable >> thermal_pressure 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.This API passes on the instantaneous >> thermal pressure 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 maximum capacity. >> Considering, trigger_thermal_pressure_average reads thermal_pressure and >> update_thermal_pressure writes into thermal_pressure, 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 thermal_pressure value >> used to calculate average thermal pressure for a cpu can be >> stale for upto 1 tick period. >> >> Signed-off-by: Thara Gopinath >> --- >> >> v3->v4: >> - Dropped per cpu max_capacity_info struct and instead added a per >> delta_capacity variable to store the delta between maximum >> capacity and capped capacity. The delta is now calculated when >> thermal pressure is updated and not every tick. >> - Dropped populate_max_capacity_info api as only per cpu delta >> capacity is stored. >> - Renamed update_periodic_maxcap to >> trigger_thermal_pressure_average and update_maxcap_capacity to >> update_thermal_pressure. >> v4->v5: >> - As per Peter's review comments folded thermal.c into fair.c. >> - As per Ionela's review comments revamped update_thermal_pressure >> to take maximum available capacity as input instead of maximum >> capped frequency ration. >> >> --- >> include/linux/sched.h | 9 +++++++++ >> kernel/sched/fair.c | 37 +++++++++++++++++++++++++++++++++++++ >> 2 files changed, 46 insertions(+) >> >> diff --git a/include/linux/sched.h b/include/linux/sched.h >> index 263cf08..3c31084 100644 >> --- a/include/linux/sched.h >> +++ b/include/linux/sched.h >> @@ -1993,6 +1993,15 @@ static inline void rseq_syscall(struct pt_regs *regs) >> >> #endif >> >> +#ifdef CONFIG_SMP >> +void update_thermal_pressure(int cpu, unsigned long capped_capacity); >> +#else >> +static inline void >> +update_thermal_pressure(int cpu, unsigned long capped_capacity) >> +{ >> +} >> +#endif >> + >> const struct sched_avg *sched_trace_cfs_rq_avg(struct cfs_rq *cfs_rq); >> char *sched_trace_cfs_rq_path(struct cfs_rq *cfs_rq, char *str, int len); >> int sched_trace_cfs_rq_cpu(struct cfs_rq *cfs_rq); >> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >> index 682a754..2e907cc 100644 >> --- a/kernel/sched/fair.c >> +++ b/kernel/sched/fair.c >> @@ -86,6 +86,12 @@ static unsigned int normalized_sysctl_sched_wakeup_granularity = 1000000UL; >> >> const_debug unsigned int sysctl_sched_migration_cost = 500000UL; >> >> +/* >> + * Per-cpu instantaneous delta between maximum capacity >> + * and maximum available capacity due to thermal events. >> + */ >> +static DEFINE_PER_CPU(unsigned long, thermal_pressure); >> + >> #ifdef CONFIG_SMP >> /* >> * For asym packing, by default the lower numbered CPU has higher priority. >> @@ -10401,6 +10407,37 @@ static unsigned int get_rr_interval_fair(struct rq *rq, struct task_struct *task >> return rr_interval; >> } >> >> +#ifdef CONFIG_SMP >> +/** >> + * update_thermal_pressure: Update thermal pressure >> + * @cpu: the cpu for which thermal pressure is to be updated for >> + * @capped_capacity: maximum capacity of the cpu after the capping >> + * due to thermal event. >> + * >> + * Delta between the arch_scale_cpu_capacity and capped max capacity is >> + * stored in per cpu thermal_pressure variable. >> + */ >> +void update_thermal_pressure(int cpu, unsigned long capped_capacity) >> +{ >> + unsigned long delta; >> + >> + delta = arch_scale_cpu_capacity(cpu) - capped_capacity; >> + per_cpu(thermal_pressure, cpu) = delta; > > use WRITE_ONCE Will do. > >> +} >> +#endif >> + >> +/** >> + * trigger_thermal_pressure_average: Trigger the thermal pressure accumulate >> + * and average algorithm >> + */ >> +static void trigger_thermal_pressure_average(struct rq *rq) >> +{ >> +#ifdef CONFIG_SMP >> + update_thermal_load_avg(rq_clock_task(rq), rq, >> + per_cpu(thermal_pressure, cpu_of(rq))); >> +#endif >> +} >> + >> /* >> * All the scheduling class methods: >> */ >> -- >> 2.1.4 >> -- Warm Regards Thara