Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp364434imu; Fri, 25 Jan 2019 03:47:05 -0800 (PST) X-Google-Smtp-Source: ALg8bN7L5AkufBnyOs7OdSkTJPNQ3OmR5o7lB5TRAMpYBSoGEFhEs46VOBUF2KPcYKVf6Sc3jaqv X-Received: by 2002:a63:960a:: with SMTP id c10mr9603930pge.106.1548416825045; Fri, 25 Jan 2019 03:47:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548416825; cv=none; d=google.com; s=arc-20160816; b=naOgYORklEmgPCu4kFUeFAofy8y5M3FWcfSXhy8uu56M6Oowl4dF1Lj213PuMKwy8g uM7GdnyvJ44Vz0TJlIcDlPpW8VrEutQ6dfSzKH7FbDs6cduIJ64bNCNhp0s3Qlu4EcK0 d8xIWJw9OUyKXR+S+41bN+bVp8YrjIsE4P3trRr2Sa00SlRWSW0/0d7Hi/ffHJCM28zZ L4V/gGoeQ7tNPKuAyYv7tSPcQoDVB6CnhfpOrGDJv6bAD9TS62NF8WsOeORpQCD7L7v7 dcqzfiU7dnFu/I2iJi+Ma9n3/GPPeWk0RfHe7qqs5YghpvCx41MVNW7X2fS4nt6VKmu8 bkvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=t4Cp6HDwBhrK740eAcs5gva9lGThOBIN7jzLKKpLtX4=; b=e4n54jlM1sns1KcRE/iR10y17l4X+I6noqaBzS5dfTIucst2wCTXk28wDmtkcq5Ap0 HrZLvzImj65HUTGLB0pPlf0nZ6I8SYYkCaj4SEgVFJqvOGmbNcrauA41Vs7kKgDQfVta QYZ2P8/Omly2YyyCiSU2SRMSxnY1ixqpXbfo6+yflw7ygbZRXwH/hIAaKY1i2RT6KPRs 2NoRwB4rxtbt3i0Eo3j9AA+hZDUQxVg53R8OhYjYi4XrtfeKuYlGnJyqA8rgPnide7Ex vcTQGBp281GJfW8NNeqfJApWzMcUOHt9al0EiVe1BkYkGrzggICBT8LBSBmzQ04C+FHX OZ1w== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s73si854521pfs.54.2019.01.25.03.46.49; Fri, 25 Jan 2019 03:47:05 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727959AbfAYLpa (ORCPT + 99 others); Fri, 25 Jan 2019 06:45:30 -0500 Received: from mail-ot1-f68.google.com ([209.85.210.68]:36804 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726100AbfAYLpa (ORCPT ); Fri, 25 Jan 2019 06:45:30 -0500 Received: by mail-ot1-f68.google.com with SMTP id k98so8260851otk.3; Fri, 25 Jan 2019 03:45:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=t4Cp6HDwBhrK740eAcs5gva9lGThOBIN7jzLKKpLtX4=; b=k5SS5bI7kz8UAjQtYQVzXWPWUfS7fvtmEa5082FTWzTsn2CKWdV5nrvAOwxFrYEWmZ 4n2wjC9E2geIv8BMofrWw1ZqCIHphkm3BCYmH4ruycRjXmYX0OIX3WB9Hc3GT3Cauz1j r2aY78HwtLENzxHbzot4ZWaNeGSe2yy+8NhC4oQZAUU2I/Cc58889ki+IOFBqzqi7b0H q3qUnNI1qjPYAmpKNY6McCZkyyq3+4no9iCJvDYS6nWawCe/tCFt4cwJ0G5Hi1QMgp4P ofxPvgzZYPBmyG3E/70UOJhFmRezjcx1ArFOvv8rH2joTWhYANgVeNHF8KGS2KTQzTcz 3EWw== X-Gm-Message-State: AJcUukcDtaSt5oHVfTUK8Fw4kF1G05niMwtKto8xjt1XW2w7iiDM05U5 NipfydfHhqsHU/2L7mbm/xvk+a9Dbvp2f0MvnQA= X-Received: by 2002:a9d:5e8c:: with SMTP id f12mr7897682otl.343.1548416729065; Fri, 25 Jan 2019 03:45:29 -0800 (PST) MIME-Version: 1.0 References: <73e091e2d56d9fa6eb94feaed9fc2be30bf6da20.1548398851.git.amit.kucheria@linaro.org> <20190125103152.7svjfmowgigznipm@vireshk-i7> In-Reply-To: <20190125103152.7svjfmowgigznipm@vireshk-i7> From: "Rafael J. Wysocki" Date: Fri, 25 Jan 2019 12:45:17 +0100 Message-ID: Subject: Re: [PATCHv3 2/9] cpufreq: Auto-register the driver as a thermal cooling device if asked To: Viresh Kumar Cc: Amit Kucheria , Linux Kernel Mailing List , linux-arm-msm , Eduardo Valentin , Stephen Boyd , Doug Anderson , Matthias Kaehlcke , "Rafael J. Wysocki" , "open list:CPU FREQUENCY SCALING FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 25, 2019 at 11:32 AM Viresh Kumar wrote: > > On 25-01-19, 12:32, Amit Kucheria wrote: > > All cpufreq drivers do similar things to register as a cooling device. > > Provide a cpufreq driver flag so drivers can just ask the cpufreq core > > to register the cooling device on their behalf. This allows us to get > > rid of duplicated code in the drivers. > > > > In order to allow this, we add a struct thermal_cooling_device pointer > > to struct cpufreq_policy so that drivers don't need to store it in a > > private data structure. > > > > Suggested-by: Stephen Boyd > > Suggested-by: Viresh Kumar > > Signed-off-by: Amit Kucheria > > Reviewed-by: Matthias Kaehlcke > > Tested-by: Matthias Kaehlcke > > --- > > drivers/cpufreq/cpufreq.c | 6 ++++++ > > include/linux/cpufreq.h | 21 +++++++++++++++++++++ > > 2 files changed, 27 insertions(+) > > > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > > index e35a886e00bc..cf1be057caf4 100644 > > --- a/drivers/cpufreq/cpufreq.c > > +++ b/drivers/cpufreq/cpufreq.c > > @@ -1318,6 +1318,9 @@ static int cpufreq_online(unsigned int cpu) > > if (cpufreq_driver->ready) > > cpufreq_driver->ready(policy); > > > > + if (cpufreq_driver->flags & CPUFREQ_AUTO_REGISTER_COOLING_DEV) > > + register_cooling_device(policy); > > + > > pr_debug("initialization complete\n"); > > > > return 0; > > @@ -1405,6 +1408,9 @@ static int cpufreq_offline(unsigned int cpu) > > goto unlock; > > } > > > > + if (cpufreq_driver->flags & CPUFREQ_AUTO_REGISTER_COOLING_DEV) > > + unregister_cooling_device(policy); > > + > > if (cpufreq_driver->stop_cpu) > > cpufreq_driver->stop_cpu(policy); > > > > diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h > > index bd7fbd6a4478..c7eb59b8ce94 100644 > > --- a/include/linux/cpufreq.h > > +++ b/include/linux/cpufreq.h > > @@ -13,6 +13,7 @@ > > > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -151,6 +152,9 @@ struct cpufreq_policy { > > > > /* For cpufreq driver's internal use */ > > void *driver_data; > > + > > + /* Pointer to the cooling device if used for thermal mitigation */ > > + struct thermal_cooling_device *cdev; > > }; > > > > /* Only for ACPI */ > > @@ -386,6 +390,12 @@ struct cpufreq_driver { > > */ > > #define CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING BIT(6) > > > > +/* > > + * Set by drivers that want the core to automatically register the cpufreq > > + * driver as a thermal cooling device. > > + */ > > +#define CPUFREQ_AUTO_REGISTER_COOLING_DEV BIT(7) > > + > > int cpufreq_register_driver(struct cpufreq_driver *driver_data); > > int cpufreq_unregister_driver(struct cpufreq_driver *driver_data); > > > > @@ -415,6 +425,17 @@ cpufreq_verify_within_cpu_limits(struct cpufreq_policy *policy) > > policy->cpuinfo.max_freq); > > } > > > > +static inline void register_cooling_device(struct cpufreq_policy *policy) > > +{ > > + policy->cdev = of_cpufreq_cooling_register(policy); > > +} > > + > > +static inline void unregister_cooling_device(struct cpufreq_policy *policy) > > +{ > > + cpufreq_cooling_unregister(policy->cdev); > > + policy->cdev = NULL; > > +} > > I thought that we discussed over chat that you wouldn't add any > wrapper routines. How do you see these getting used ? I will suggest > that this should be open coded in the core itself. Agreed.