Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3060371pxb; Tue, 19 Jan 2021 12:41:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzArGqHkMWiTAR1H+lXTBsm4fJVZ30lrRCkscze5KNtRzmvQLWnEx7qWHg8O7lgi+BhLQcl X-Received: by 2002:a50:d552:: with SMTP id f18mr4783455edj.168.1611088878811; Tue, 19 Jan 2021 12:41:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611088878; cv=none; d=google.com; s=arc-20160816; b=T5tVx1ZH9cYcXdYkp4Zstce5Inzy2NolfhBih9KzVHuTNDS3z56dUvyqSdlLnsRI69 seLyzB+kbXumwHgWKUtKuDb6vHiyn1cKjgxr/6PbPPsyGSCEisN77uiTxfFB7aoUEXQG mnigILxrEO96P6cTot256sOAj96SbHlolNoskEt/yaQzu3gnBbUgURZIG4HfnP5VyZze tU/ZyUQcUCg+8rlIpNdY96QNtMerXDLMIH48u0243fjRey5shCcsBCcJWZwsOl+eOCsm AgT88oiWFzjKXq3HvZbEy0lGFXhTvmh1JBq65GkNtbgSU0+hG9Urstg64mPi0XNNz5m5 Jrlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=D6KlUQTbL5/2CJrk6DGIi6MNkCUnrcgjf32j2D+4yxc=; b=Z7c44IkfhgtjRLmYmHtxgy6LnodrcAYMx+LURUYgvUIizj2IrnZujNfdVRtkuOQ0YH ydQBukGbpsjUz2+oC9myt4hmYnqyXIi4uFKW9P2lxQiuMybB3oPmeGmuIYhe4bJ3xxu+ mjGVoYJSTf/pIE4JNaq3UIJtrTOpRW2lRhZCLrLzcTGm0IGjaeyCYpn5b4qwHOm8Z13a if4teMBjvYxP9Gi++/Yn5xrie/pKiNGk2HDIK8UdbDdH9KdW8kw1xCWcs1q/AxUY4J+J w95vo0XY5+xP9l9pMTBdSN46VmztvkYryjiwOJQySyA0hwYCejb5LRiN1S5p4AjnQGB6 ISwQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id sa7si9065965ejb.706.2021.01.19.12.40.55; Tue, 19 Jan 2021 12:41:18 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730665AbhASUkT (ORCPT + 99 others); Tue, 19 Jan 2021 15:40:19 -0500 Received: from mail-ot1-f43.google.com ([209.85.210.43]:40479 "EHLO mail-ot1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390848AbhASUjP (ORCPT ); Tue, 19 Jan 2021 15:39:15 -0500 Received: by mail-ot1-f43.google.com with SMTP id i20so13344736otl.7; Tue, 19 Jan 2021 12:38:59 -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=D6KlUQTbL5/2CJrk6DGIi6MNkCUnrcgjf32j2D+4yxc=; b=oJz2WGABUuMtAbox6dr0tywwxmS8DEE/x2jK8D5LU5lfsm2fb37mbpmIuDLLo/stcE A3GIhhMaxjiPk+4WuQ72oRkblQpJ5XQXvKcAZADwa3YJDDaOrXjpcl3pxoLxxl+ItJmf 8xUCW0ZK3v4YvRbJpaSpEuSrkMKEhapjRpjTF0Ceitu4kAeS7hTGjz21dcDYJt4wzeq7 /fphW6fsth7GJD70A1tp7bdpwBk2VroRligjGabH5VHNcTWVHwAuFbtbnE20qchFZd1R +96rtCc9HvBUpIW8u7vfwG+7YZkORvwtMO4eVcmG1GsSmSCYV1wiu6VsvUqarFxbOEL6 gAHA== X-Gm-Message-State: AOAM532r/Z15TAe20DAHp2ilSEajBo82WZXuB3lPSrEJpDHv1ugkqOCn S1TozgD3v4o9mj6R+Q99b8ps6FPvQSpCDbPqKpo= X-Received: by 2002:a05:6830:1f5a:: with SMTP id u26mr4738858oth.250.1611088713849; Tue, 19 Jan 2021 12:38:33 -0800 (PST) MIME-Version: 1.0 References: <17nqrn25-rp5s-4652-o5o1-72p2oprqpq90@onlyvoer.pbz> <7him7sydd6.fsf@baylibre.com> In-Reply-To: <7him7sydd6.fsf@baylibre.com> From: Geert Uytterhoeven Date: Tue, 19 Jan 2021 21:38:22 +0100 Message-ID: Subject: Re: [PATCH] PM / clk: make PM clock layer compatible with clocks that must sleep To: Kevin Hilman , Nicolas Pitre Cc: "Rafael J. Wysocki" , Greg Kroah-Hartman , Michael Turquette , Stephen Boyd , Russell King , Linux PM list , linux-clk , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kevin, Nicolas, On Tue, Jan 19, 2021 at 7:45 PM Kevin Hilman wrote: > [ + Geert.. renesas SoCs are the primary user of PM clk ] Thanks! > Nicolas Pitre writes: > > The clock API splits its interface into sleepable ant atomic contexts: > > > > - clk_prepare/clk_unprepare for stuff that might sleep > > > > - clk_enable_clk_disable for anything that may be done in atomic context > > > > The code handling runtime PM for clocks only calls clk_disable() on > > suspend requests, and clk_enable on resume requests. This means that > > runtime PM with clock providers that only have the prepare/unprepare > > methods implemented is basically useless. > > > > Many clock implementations can't accommodate atomic contexts. This is > > often the case when communication with the clock happens through another > > subsystem like I2C or SCMI. > > > > Let's make the clock PM code useful with such clocks by safely invoking > > clk_prepare/clk_unprepare upon resume/suspend requests. Of course, when > > such clocks are registered with the PM layer then pm_runtime_irq_safe() > > can't be used, and neither pm_runtime_suspend() nor pm_runtime_resume() > > may be invoked in atomic context. > > > > For clocks that do implement the enable and disable methods then > > everything just works as before. > > > > Signed-off-by: Nicolas Pitre Thanks for your patch! > > --- a/drivers/base/power/clock_ops.c > > +++ b/drivers/base/power/clock_ops.c > > +/** > > + * pm_clk_op_lock - ensure exclusive access for performing clock operations. > > + * @psd: pm_subsys_data instance corresponding to the PM clock entry list > > + * and clk_op_might_sleep count being used. > > + * @flags: stored irq flags. > > + * @fn: string for the caller function's name. > > + * > > + * This is used by pm_clk_suspend() and pm_clk_resume() to guard > > + * against concurrent modifications to the clock entry list and the > > + * clock_op_might_sleep count. If clock_op_might_sleep is != 0 then > > + * only the mutex can be locked and those functions can only be used in > > + * non atomic context. If clock_op_might_sleep == 0 then these functions > > + * may be used in any context and only the spinlock can be locked. > > + * Returns -EINVAL if called in atomic context when clock ops might sleep. > > + */ > > +static int pm_clk_op_lock(struct pm_subsys_data *psd, unsigned long *flags, > > + const char *fn) > > +{ > > + bool atomic_context = in_atomic() || irqs_disabled(); Is this safe? Cfr. https://lore.kernel.org/dri-devel/20200914204209.256266093@linutronix.de/ 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