Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1144898lqb; Thu, 30 May 2024 01:16:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVVPx3ywq4Wpjj75EalF4sjnj/Sz7evzqrK2CFdMCbOCkIscqmKv/JTaXmV1Xv9y4Xj8FYZbk4NVRSCao5BfeVwGZtukWnW0L4b2OORTA== X-Google-Smtp-Source: AGHT+IHUHGsNHPkedjJpDmCyT/442rnOA7u8ipQW++Q5Rksl8cLjPlLqW34ON/CaSeufSUuzLq5R X-Received: by 2002:a05:6871:891:b0:250:171a:fc7b with SMTP id 586e51a60fabf-25060bf9c96mr1676475fac.28.1717056965816; Thu, 30 May 2024 01:16:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717056965; cv=pass; d=google.com; s=arc-20160816; b=NBA1ccmIZKtXFRDXHEzWFiXdZb5mIJ0W9PGR+PuRJIrg/n2/52c4DAuBSWNoOHSAka 6bYE3aWtsnotd+M77Di1WFdo63a8EY4P6z8pm9JMrzRVIDb4BnUHE7xAsQ4vNLoJPvfl oVuXLkRrt9RVn1f0ojtFoiHPdRNuQdxKaezSFi7MkBej56ubPMutEvyvp8RkLfvzYDB4 DUBhwnZt66e8n/G8G8UY0S/EPVVDr6QoH2tXBaaX3o0VUWm+gB5XJMLLHmzc7akB5UU+ KHEYZV/H7v6TMH5eF9EYtOKvyDQd8/qx0AvTCHzAO3/7OMoUyd/tyAaI9fL/culzzslB hA9Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=k20/mggq32MX0XT5cSqtsxqcJ+lwttdw4RIhMsw0RBg=; fh=ZcmmsOxRW9VwOKK5JEEbNytlBSoVwJqAi6tkhMAHMjM=; b=A5YJV5ETvQ8H8lW5MjQvIsD6bfBruPoAKmarn1LEq1uj6naMi2Hszu9jobsq8pXRfD wrwQe6b7VceLJApNL53kWpYMwodjAT5v+zWSaXMLxunLPKrvBF6rU6eZx06cWSjKWROb 0ij/3iTONI9bKPdMpUK5hZa0uBIfJYyijR5eWtHwA9eP4AEZbzfoV9+3DdQLgindPBVP yIpetVcefm0ldAMDng7KxkrI1REh7yf3D5tX8pkdY5pxTkojlKtrmXAnfPl+o2fCpdkG E1Usn5mSObED3xgh+WWcPruN6xi8waGIabD2iZsPEG/KjcvfvDTFwaDcjpgU28T9gr5N hYzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RgZ26U17; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-195049-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195049-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43fdb107d16si53660721cf.446.2024.05.30.01.16.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 01:16:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195049-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RgZ26U17; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-195049-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195049-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 879E91C22192 for ; Thu, 30 May 2024 08:16:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D08D14C5BE; Thu, 30 May 2024 08:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="RgZ26U17" Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D118217753 for ; Thu, 30 May 2024 08:15:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717056956; cv=none; b=ss5flSubWWGQo++JxDXxfjJQp+2yGBgr5/rJx8+7mzhR6gdH3YQd5N5qVrQbCHEDYad1mfQXfpdmt8/ZtNAaXD55BcozaFlLpnQUIOiy7bLGxVE4AoFbY9EK/oc6cO24pyUMsZZzLsPR87GobbcdVGSJjCX3tyKlbJ8aBu53Fxo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717056956; c=relaxed/simple; bh=R/6+LIm49u8oTIwIKRyzFjXZG4HUwTDHPLWkBzXDelo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=LQmgi0FsSSa7Lj5YF6pnqZCaeqoKTCGS9yHinTearROAaHw7wzmBc4E3ax520CfnXLMICOp3ZWc2k1lmEBe3hDE1Yvz7G0Fj9eyNgiM104sCbjOTmQoyFNt7xGlRWob9t0uBoMQ/nlofYnTIrlqdh8Myt2Qih0a1HeJdpILyxrQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=RgZ26U17; arc=none smtp.client-ip=209.85.128.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-62a0809c805so6688957b3.0 for ; Thu, 30 May 2024 01:15:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717056954; x=1717661754; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=k20/mggq32MX0XT5cSqtsxqcJ+lwttdw4RIhMsw0RBg=; b=RgZ26U17jWa2sN5I0bOLewkXd305iNTW/U0lwcOT/FbvLEFne0px3CE4ByU7jaO9rH vVM9Kzh1eBfG31xDr0dq2r7JKLcrUJNIEMgWmbrdU5FHuRNObUKDt8eDcpmnsjLNnJ3j Lm2dZ4rRLbz0fqig3Fakqdtc/P6XG7KFMjuyBSCCwsswEbNh5WGHCtz8Rsx29YQbaVGq cQ+eWaTZdPA3m4tsV+tMfkPSqnKLESGD0Siba9Gm7ZL/v9FcC9Yt443UjGY9I/fwKAGD 9kywt8P0JBlXiTxZTOIh1pW6kv5pMQMmgjFYnRZ5IA5jo5SnkkiezfZnvXeXFi/aZMo2 w+wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717056954; x=1717661754; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=k20/mggq32MX0XT5cSqtsxqcJ+lwttdw4RIhMsw0RBg=; b=WB2/j/OFYa+ClyJEDiJLyUNr7ACPeFllUp9Klzp7AVnsfhGjqm1ID8rS0cAMf0Je67 vw6cXkndqAHxi5U7+vpE0EVU7n0MtNbxlmTJF+MrsvqA1VaXzXPvE2i54R5RTYreLEfX 37K6cyDSfuj3jk+vLwhtG2Xh27xBQZdx5nrtSOrqVUgppPN9UDqh3rYtT8lglyPJ6rJH KPT/RKWgLZYdjssnDm2Cvk9co3WlTT5ewYEA+BnZOnQvxTpcRXTWSs9eN6seH4eh/bQI gA6No2eHoCsg4aKXdaUDLRooBsGzO7rZBn0MXfMlqIGX/Otz78LvTtYDI5d7TZlXEqRd xiYQ== X-Forwarded-Encrypted: i=1; AJvYcCU2p1U5kiU1Xfbu40belgUCCm+Ny0nmA+e7M1PMxQMsLyhpShxc4vHz/Atv2FQzVXedTH23mfcTIcnqkkmEfZlvwKfHh16tuSYxic4X X-Gm-Message-State: AOJu0YyH/eMffoR8fGdxJH7vaeVMb+EjpG+Md5hlhFIKkeQKEvSQqjhs JY7bVLq+SkV53MGi8u0R43bQWvnlesgPAH5jm3enDpE7RsK/ydf8kXumZD94tL2n05GNqDgsDul RbmPa0GSlhilYO+6LhHHPpyt0RKMlPYpaNWwXiw== X-Received: by 2002:a81:80c2:0:b0:61b:e871:9115 with SMTP id 00721157ae682-62c6bc3e020mr10625537b3.17.1717056953560; Thu, 30 May 2024 01:15:53 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240527142557.321610-1-ulf.hansson@linaro.org> <20240527142557.321610-2-ulf.hansson@linaro.org> <52dce8d3-acfa-4f2c-92d0-c25aa59d6526@quicinc.com> In-Reply-To: <52dce8d3-acfa-4f2c-92d0-c25aa59d6526@quicinc.com> From: Ulf Hansson Date: Thu, 30 May 2024 10:15:13 +0200 Message-ID: Subject: Re: [PATCH v2 1/7] pmdomain: core: Enable s2idle for CPU PM domains on PREEMPT_RT To: Nikunj Kela Cc: "Rafael J . Wysocki" , Sudeep Holla , linux-pm@vger.kernel.org, Lorenzo Pieralisi , Nikunj Kela , Prasad Sodagudi , Maulik Shah , Daniel Lezcano , Krzysztof Kozlowski , linux-rt-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Tue, 28 May 2024 at 21:56, Nikunj Kela wrote: > > > On 5/27/2024 7:25 AM, Ulf Hansson wrote: > > To allow a genpd provider for a CPU PM domain to enter a domain-idle-state > > during s2idle on a PREEMPT_RT based configuration, we can't use the regular > > spinlock, as they are turned into sleepable locks on PREEMPT_RT. > > > > To address this problem, let's convert into using the raw spinlock, but > > only for genpd providers that have the GENPD_FLAG_CPU_DOMAIN bit set. In > > this way, the lock can still be acquired/released in atomic context, which > > is needed in the idle-path for PREEMPT_RT. > > > > Do note that the genpd power-on/off notifiers may also be fired during > > s2idle, but these are already prepared for PREEMPT_RT as they are based on > > the raw notifiers. However, consumers of them may need to adopt accordingly > > to work properly on PREEMPT_RT. > > > > Signed-off-by: Ulf Hansson > > --- > > > > Changes in v2: > > - None. > > > > --- > > drivers/pmdomain/core.c | 47 ++++++++++++++++++++++++++++++++++++++- > > include/linux/pm_domain.h | 5 ++++- > > 2 files changed, 50 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c > > index 623d15b68707..072e6bdb6ee6 100644 > > --- a/drivers/pmdomain/core.c > > +++ b/drivers/pmdomain/core.c > > @@ -117,6 +117,48 @@ static const struct genpd_lock_ops genpd_spin_ops = { > > .unlock = genpd_unlock_spin, > > }; > > > > +static void genpd_lock_raw_spin(struct generic_pm_domain *genpd) > > + __acquires(&genpd->raw_slock) > > +{ > > + unsigned long flags; > > + > > + raw_spin_lock_irqsave(&genpd->raw_slock, flags); > > + genpd->raw_lock_flags = flags; > > +} > > + > > +static void genpd_lock_nested_raw_spin(struct generic_pm_domain *genpd, > > + int depth) > > + __acquires(&genpd->raw_slock) > > +{ > > + unsigned long flags; > > + > > + raw_spin_lock_irqsave_nested(&genpd->raw_slock, flags, depth); > > + genpd->raw_lock_flags = flags; > > +} > > + > > +static int genpd_lock_interruptible_raw_spin(struct generic_pm_domain *genpd) > > + __acquires(&genpd->raw_slock) > > +{ > > + unsigned long flags; > > + > > + raw_spin_lock_irqsave(&genpd->raw_slock, flags); > > + genpd->raw_lock_flags = flags; > > + return 0; > > +} > > + > > +static void genpd_unlock_raw_spin(struct generic_pm_domain *genpd) > > + __releases(&genpd->raw_slock) > > +{ > > + raw_spin_unlock_irqrestore(&genpd->raw_slock, genpd->raw_lock_flags); > > +} > > + > > +static const struct genpd_lock_ops genpd_raw_spin_ops = { > > + .lock = genpd_lock_raw_spin, > > + .lock_nested = genpd_lock_nested_raw_spin, > > + .lock_interruptible = genpd_lock_interruptible_raw_spin, > > + .unlock = genpd_unlock_raw_spin, > > +}; > > + > > #define genpd_lock(p) p->lock_ops->lock(p) > > #define genpd_lock_nested(p, d) p->lock_ops->lock_nested(p, d) > > #define genpd_lock_interruptible(p) p->lock_ops->lock_interruptible(p) > > @@ -2079,7 +2121,10 @@ static void genpd_free_data(struct generic_pm_domain *genpd) > > > > static void genpd_lock_init(struct generic_pm_domain *genpd) > > { > > - if (genpd->flags & GENPD_FLAG_IRQ_SAFE) { > > + if (genpd->flags & GENPD_FLAG_CPU_DOMAIN) { > > + raw_spin_lock_init(&genpd->raw_slock); > > + genpd->lock_ops = &genpd_raw_spin_ops; > > + } else if (genpd->flags & GENPD_FLAG_IRQ_SAFE) { > > Hi Ulf, though you are targeting only CPU domains for now, I wonder if > FLAG_IRQ_SAFE will be a better choice? The description of the flag says > it is safe for atomic context which won't be the case for PREEMPT_RT? You have a point! However, we also need to limit the use of raw spinlocks, from PREEMPT_RT point of view. In other words, just because a genpd provider is capable of executing its callbacks in atomic context, doesn't always mean that it should use raw spinlocks too. [...] Kind regards Uffe