Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3334881ybc; Mon, 25 Nov 2019 12:45:18 -0800 (PST) X-Google-Smtp-Source: APXvYqyN2reqFzwEnwWxlVDEAxcv4el2x+e6EHtQV1Mz/GU3Yq2or+nuNikrP2IjygSicDMC2l/O X-Received: by 2002:aa7:c65a:: with SMTP id z26mr21055493edr.261.1574714718464; Mon, 25 Nov 2019 12:45:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574714718; cv=none; d=google.com; s=arc-20160816; b=HJX7ykx28Ib+tQ1Wj6YYmIIJCLUXuuHDZD2/Q2dVcs4L8Wsxl/BVLOQjsxrhyxZEie D62f+2dC+RmNGRSqu3+az/uujK5KqYjrTdA7zTrLU6fS8wott5m2Sn2fFVXUsKvkLqKc qrpRd/RXyqTse7GGcJBdKo0NfTaXpnygKHLIAhqcEf/aNS+xgjTI1AZoMGRTI7Jttia8 eCyB6N1vCBw5rZoMQPJTwSJLGiiq64fmCwKHDSZG4SqooKmJ6fPH26JKbAKRPsWCB91h m/h2ZGZ3UT9B5ym2lOgETroTNla2qadylhoBkakRG0ke2VkM5W58nasIUSlSOG8Nv2uE HUaw== 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=vkN17VKr1QonsL4KEkyHopuTh41vqxivJMdU6x1c6F8=; b=CViC4torXRi/c3FSZw9e7iHMIxWe8hole63fXEmQgHdz1M+2Dhz5F2wR3VhQeR5+or j5ZtvJOehAvO4Wk+MOuAdBJ3yRrgXqldDY5ZIHhFLjDZQkYMiGYOrWeRrsU1CZkGJ6rf pjpS/SKIHFipHu9hzJtqgPQmM5/XGlg1cH5V08b2JOk27P0nt5TXzY5zp1XEKsRJacV1 TBxKYgmn45delF10oOtLhvCRXP6QzToQawtgRgaeDALUSRG+aKKIgccFiswaaDTfHGmB MkyXmYTyamSp0sYzA+BAa1XdOTOuMXV9CalNROGPBLQXKS5ceYPbwt2VaEJ+2KmHIb0L z/AQ== 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 r17si5417679eje.139.2019.11.25.12.44.53; Mon, 25 Nov 2019 12:45:18 -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 S1726029AbfKYUnq (ORCPT + 99 others); Mon, 25 Nov 2019 15:43:46 -0500 Received: from mail-ot1-f68.google.com ([209.85.210.68]:33304 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725924AbfKYUnq (ORCPT ); Mon, 25 Nov 2019 15:43:46 -0500 Received: by mail-ot1-f68.google.com with SMTP id q23so8037064otn.0; Mon, 25 Nov 2019 12:43:45 -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=vkN17VKr1QonsL4KEkyHopuTh41vqxivJMdU6x1c6F8=; b=GxUPmvnOdIrCVOqOXI7sKzFlR8k8HZ0jF/9lZnTG+ut8Kk3KScfJdQXLtOph022tDn JXx1pxKm9XCQMS+vOnbVCWD4fuW42QE7oAmGRx+Ic2dnZiiGKxkbSYpiUySJKJX4f1JD 1AG6Iv/12Cs9nq1ZRVtanIV0xLaXJFnbCilTRWjeF1Oo50vQMqTboidjVMnopRlMBDrL oaBVnEX/Y+02VsMkvWoJxqC3VRlmPnV/RiP/xCyp7KLZYERERakk5UkeDUjuitg0Tc/j 0JzKAsP7RwNC3dxegaxfMOlowLdI6Jbi1h/YFg+Le/+oB3e76qDANCI3359av6i9eLkS UxTg== X-Gm-Message-State: APjAAAXEDZSsSTGurLYr2zb7LQF0Efs/FflDZZWcV81jO9ZNxs112WqO kzT+BF9HVCWHb5QmLlr03tsT//3l/T8Oyshx+k/qLqCX X-Received: by 2002:a9d:2073:: with SMTP id n106mr11207489ota.145.1574714625036; Mon, 25 Nov 2019 12:43:45 -0800 (PST) MIME-Version: 1.0 References: <1d7a1b3b-e9bf-1d80-609d-a9c0c932b15a@free.fr> <34e32662-c909-9eb3-e561-3274ad0bf3cc@free.fr> <20191125125530.GP25745@shell.armlinux.org.uk> <20191125133752.GS25745@shell.armlinux.org.uk> <21c242a9-3599-3288-79bf-a8889fad2a73@free.fr> In-Reply-To: <21c242a9-3599-3288-79bf-a8889fad2a73@free.fr> From: Geert Uytterhoeven Date: Mon, 25 Nov 2019 21:43:33 +0100 Message-ID: Subject: Re: [PATCH v1] clk: Add devm_clk_{prepare,enable,prepare_enable} To: Marc Gonzalez Cc: Russell King - ARM Linux admin , Stephen Boyd , Michael Turquette , linux-clk , Linux ARM , LKML 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 Hi Marc, On Mon, Nov 25, 2019 at 3:11 PM Marc Gonzalez wrote: > On 25/11/2019 14:37, Russell King - ARM Linux admin wrote: > > On Mon, Nov 25, 2019 at 02:10:21PM +0100, Marc Gonzalez wrote: > >> On 25/11/2019 13:55, Russell King - ARM Linux admin wrote: > >>> It's also worth reading https://lore.kernel.org/patchwork/patch/755667/ > >>> and considering whether you really are using the clk_prepare() and > >>> clk_enable() APIs correctly. Wanting these devm functions suggests > >>> you aren't... > >> > >> In that older thread, you wrote: > >> > >>> If you take the view that trying to keep clocks disabled is a good way > >>> to save power, then you'd have the clk_prepare() or maybe > >>> clk_prepare_enable() in your run-time PM resume handler, or maybe even > >>> deeper in the driver... the original design goal of the clk API was to > >>> allow power saving and clock control. > >>> > >>> With that in mind, getting and enabling the clock together in the > >>> probe function didn't make sense. > >>> > >>> I feel that aspect has been somewhat lost, and people now regard much > >>> of the clk API as a bit of a probe-time nuisance. > >> > >> In the few drivers I've written, I call clk_prepare_enable() at probe. > > > > Right, so the clocks are enabled as soon as the device is probed, > > in other words at boot time. It remains enabled for as long as the > > device is bound to its driver, whether or not the device is actually > > being used. Every switching edge causes heat to be generated. Every > > switching edge causes energy to be wasted. > > > > That's fine if you have an infinite energy supply. That hasn't been > > discovered yet. > > > > Given the prevalence of technology, don't you think we should be > > doing as much as we possibly can to reduce the energy consumption > > of the devices we use? It may be peanuts per device, but at scale > > it all adds up. > > OK, I'm starting to see the bigger picture. > > (To provide some rationale for the patch, I think devm is a huge > improvement for probe error-handling, and I did not understand > why every driver must do manual error-handling when dealing with > clocks in probe.) > > I did envision kernel modules being loaded on an as-needed basis, > somewhat side-stepping the energy-waste issue you point out. > But I realize that such a use-case may be uncommon. (Especially > due to module auto-loading.) > > A few months ago, I was discussing a similar issue with GKH: > Consider a device with a "START" register. Basically, if we write 0, > the device turns itself off; if we write 1, it runs as configured. > > I was trying to start the device only when at least one user had > it "open". So I used reference counting, and started the device > on 0->1 open transitions, and stopped the device on 1->0 close > transitions. GKH told me that was the wrong way to do it, and IIRC > suggested to start the device in probe. > > I probably misunderstood Greg's suggestion. Where is the right place > to start/stop a device (or gate its clocks)? In the device driver's Runtime PM callbacks? In the Power/Clock Domain Controller driver? See drivers/base/power/domain.c:genpd_{start,stop}_dev(), and how/when it's called. Embedded device driver writers typically care. Server device driver writes typically don't. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds