Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4795135pxj; Tue, 22 Jun 2021 08:12:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6YS9vOr6P2iTHFnER9Z2auJh7ixNs8GdFSXiIt23oP5s95sFNmf/p10nnko2gxCdYIMJl X-Received: by 2002:aa7:d8d4:: with SMTP id k20mr5627154eds.143.1624374727158; Tue, 22 Jun 2021 08:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624374727; cv=none; d=google.com; s=arc-20160816; b=M7lvqZyUl68btTfxNUhRf7MCLUqOG6p+t78lht1/yDHhTjZYBXUWz7vUB6z71NHqi/ MBK3kt/fgHEL8jJhD15+yzVYzw7pSG+xTEyLW32zv/6hEVJEwb0jWGNI7S5VLFiBzjv/ LuIBd9JnsVgmC57oLW2LrBzMBFFCdRDpnEal+VURy87fkzV71jY0Lz4tVDpyWbLh/jnp eFEScK/Uu7z3/RmI/N5lzDv9Of836KH4O9h3h5Hb9jVH3PnYZNl0k4on3RXmAaQWeSaF ca/sDXHznJWnKM/v6zsDcSrrs1d2lrXIZzM9OGNkmpIizHOHSbjVw5cFob7TGly3iigu gkPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=mL8Sk+kRHc6IW/ZbDnVRlXEEPyyQTbYJQirQKKSTpXY=; b=x8JAYHT0QW0HYjiYTeb6SK6JM5VwDbAa4j5+H3kqdqHz+tfIudm5sUdqx3nF8QT0sd n8+ggKcWOfK/Xz0Y+OUnSLxZMaiVvtlKkkWTS3xHD7zPZGAQnoA07D1e3oJxquf2tdJg n5fRnCGmab8O2Qclxwgn5nCLC6fD361X7QP5gbuEZixhiYaLSbDW0DF3WMnoZwY9hNHb TcFIG87K6Bqy8ODVHK7TP1hytHplSfnQYDWVuJxf2WFPU8gM1iRH2qFJ1Tjb1PGONb8g g/zNdpK9C5E2rCvaaKiAvGTWU388pytn8BK8iXZdej4BJO0e16ffq1VwTlH6cJgpQKKA QnPw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j29si13995823ejj.60.2021.06.22.08.11.41; Tue, 22 Jun 2021 08:12:07 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232089AbhFVPMn (ORCPT + 99 others); Tue, 22 Jun 2021 11:12:43 -0400 Received: from foss.arm.com ([217.140.110.172]:50804 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232000AbhFVPM0 (ORCPT ); Tue, 22 Jun 2021 11:12:26 -0400 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 938B7ED1; Tue, 22 Jun 2021 08:10:10 -0700 (PDT) Received: from [10.57.7.129] (unknown [10.57.7.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 81E093F718; Tue, 22 Jun 2021 08:10:08 -0700 (PDT) Subject: Re: [RFC PATCH 3/4] cpufreq: Add Active Stats calls tracking frequency changes To: "Rafael J. Wysocki" Cc: Linux Kernel Mailing List , Daniel Lezcano , Linux PM , Amit Kucheria , "Zhang, Rui" , Dietmar Eggemann , Chris Redpath , Beata.Michalska@arm.com, Viresh Kumar , "Rafael J. Wysocki" , Amit Kachhap References: <20210622075925.16189-1-lukasz.luba@arm.com> <20210622075925.16189-4-lukasz.luba@arm.com> <4e5476a6-fa9f-a9ef-ff26-8fa1b4bb90c0@arm.com> <851205af-39d6-3864-bd28-ae84528946c4@arm.com> From: Lukasz Luba Message-ID: <52bcc920-907e-b816-000e-85cce0b61e80@arm.com> Date: Tue, 22 Jun 2021 16:10:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/22/21 3:59 PM, Rafael J. Wysocki wrote: > On Tue, Jun 22, 2021 at 4:51 PM Rafael J. Wysocki wrote: >> >> On Tue, Jun 22, 2021 at 4:09 PM Lukasz Luba wrote: >>> >>> >>> >>> On 6/22/21 2:51 PM, Rafael J. Wysocki wrote: >>>> On Tue, Jun 22, 2021 at 3:42 PM Lukasz Luba wrote: >>>>> >>>>> >>>>> >>>>> On 6/22/21 1:28 PM, Rafael J. Wysocki wrote: >>>>>> On Tue, Jun 22, 2021 at 9:59 AM Lukasz Luba wrote: >>>>>>> >>>>>>> The Active Stats framework tracks and accounts the activity of the CPU >>>>>>> for each performance level. It accounts the real residency, when the CPU >>>>>>> was not idle, at a given performance level. This patch adds needed calls >>>>>>> which provide the CPU frequency transition events to the Active Stats >>>>>>> framework. >>>>>>> >>>>>>> Signed-off-by: Lukasz Luba >>>>>>> --- >>>>>>> drivers/cpufreq/cpufreq.c | 5 +++++ >>>>>>> 1 file changed, 5 insertions(+) >>>>>>> >>>>>>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c >>>>>>> index 802abc925b2a..d79cb9310572 100644 >>>>>>> --- a/drivers/cpufreq/cpufreq.c >>>>>>> +++ b/drivers/cpufreq/cpufreq.c >>>>>>> @@ -14,6 +14,7 @@ >>>>>>> >>>>>>> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt >>>>>>> >>>>>>> +#include >>>>>>> #include >>>>>>> #include >>>>>>> #include >>>>>>> @@ -387,6 +388,8 @@ static void cpufreq_notify_transition(struct cpufreq_policy *policy, >>>>>>> >>>>>>> cpufreq_stats_record_transition(policy, freqs->new); >>>>>>> policy->cur = freqs->new; >>>>>>> + >>>>>>> + active_stats_cpu_freq_change(policy->cpu, freqs->new); >>>>>>> } >>>>>>> } >>>>>>> >>>>>>> @@ -2085,6 +2088,8 @@ unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, >>>>>>> policy->cpuinfo.max_freq); >>>>>>> cpufreq_stats_record_transition(policy, freq); >>>>>>> >>>>>>> + active_stats_cpu_freq_fast_change(policy->cpu, freq); >>>>>>> + >>>>>> >>>>>> This is quite a bit of overhead and so why is it needed in addition to >>>>>> the code below? >>>>> >>>>> The code below is tracing, which is good for post-processing. We use in >>>>> our tool LISA, when we analyze the EAS decision, based on captured >>>>> trace data. >>>>> >>>>> This new code is present at run time, so subsystems like our thermal >>>>> governor IPA can use it and get better estimation about CPU used power >>>>> for any arbitrary period, e.g. 50ms, 100ms, 300ms, ... >>>> >>>> So can it be made not run when the IPA is not using it? >>> >>> I can make a Kconfig for IPA to select this ACTIVE_STATS. >>> Also, I can add description that this framework is mostly needed >>> for IPA, so don't enable it if you don't use IPA (default is 'n' >>> so it shouldn't harm others). >>> >>> This Active Stats shouldn't be stopped when thermal zone is switching >>> between governors at run time, e.g. IPA -> step_wise -> IPA >>> because when IPA is set next time, it might not have correct CPU >>> stats (what is the current frequency and for how long it has been >>> actively used). >> >> But after a while it will collect enough useful data I suppose? >> >>> Beside, switching governors at run time is not a good idea >>> (apart from stress testing them ;) ). >>> >>>> >>>>>> >>>>>> And pretty much the same goes for the idle loop change. There is >>>>>> quite a bit of instrumentation in that code already and it avoids >>>>>> adding new locking for a reason. Why is it a good idea to add more >>>>>> locking to that code? >>>>> >>>>> This active_stats_cpu_freq_fast_change() doesn't use the locking, it >>>>> relies on schedutil lock in [1]. >>>> >>>> Ah, OK. >>>> >>>> But it still adds overhead AFAICS. >>> >>> Agree, it's an extra code. For platforms which use IPA it's a >>> justifiable cost, weighted by better estimation thanks to this calls. >>> For other platforms, this framework will be set to default 'n' option. >> >> A general problem with build-time configuration is for distros that >> want to ship one kernel binary to run on multiple hardware platforms. >> They need to enable those options anyway and then get the full cost on >> the platforms that don't need it, but want to use the common binary >> kernel. >> >> Again, please consider making this new code run only when it is needed >> even if configured in and if it runs, make it as low-overhead as >> possible. > > Also, why don't you add these hooks to the drivers that are generally > worked with by the IPA? In Arm world (especially 32-bit world) there is 'a lot' custom idle and cpufreq drivers. It's probably even not feasible to do. We also has this CPU_IDLE_MULTIPLE_DRIVERS mechanism. It's a pain, especially when not having all possible platfroms. > > That you won't need to worry about the possible impact on everybody else. > I'll try to make it as low-overhead as possible and turn off if there is no client subsystem (like IPA) currently using it. That might be feasible. Thank you Rafael for valuable comments.