Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp980737lqj; Mon, 3 Jun 2024 06:59:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVuIB6TQNGJta1ExTLJj1pC0v0cSHAlUpAOAA/Drlb3HxR2/5ETjmrKmJK5MNNvkmI6E0hUCNXVQp4jS4u9pL6ZAj7eRGEFClPXzZ62cA== X-Google-Smtp-Source: AGHT+IHyWATSh0gbOPRPCvNBpIH/Uo6A6OnJ01u3dTeptCgrtiJJng/z53ZmS5/ddfi063G+VRmg X-Received: by 2002:a05:6a20:9744:b0:1b2:5399:6445 with SMTP id adf61e73a8af0-1b26f2cc148mr8533923637.42.1717423171454; Mon, 03 Jun 2024 06:59:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717423171; cv=pass; d=google.com; s=arc-20160816; b=Q/BTbX5NJ18qZjOPrKewtOly33EO9NmzDSBk8DCLYzIe9Aw9SH+N2/gGBC3NzDCmfk /MdA9Mo32+nCIQ3UUO7K+NlLMBwwgQvyZ8fSbLloe7xa38M6bPXWOj5JjEcndoGbLMh5 U7rZwnQKecwFXPmihDQR50L/YMgaagv6i2u2fm2pvlbH2bPtJItqg5oIdipm2E2aWGtk RjEvqaof9RR+mgoVrZx/011GH/vJgFHLX2AATKVBSWKJYe+EDENgvBAMifzNMxzeN5lz n61twGmqZq1KePjXB+xUnJ20JKXYMMV5lVDSuFwKE+DC/CeSo95cXYAun5kSrG6O0btD OPJg== 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=o2BkymhQ/db2q0Xr2SvTMdgw34Lx4ntfmiWk5iS8ce4=; fh=My7TuJvWvaz7c+Dp5RpjFml5hYwoY2ama2mN/au4aNw=; b=WfVuXo440+4iNDCWd9P4Xfgxkyxh8KSL9n/uZnyiL6zZM7BA5zdDjeaMW8avyiK3C4 PjU+anpviCIriZTrnYqr1TSoMxBT0yY01N24hmaPb+DegnYsJBbr391qjW6+4+g+ZypC 6tsJIAgwy5/HDSJJe5Wdb7fu4ZGU+inOsho9e6zxW+1L35L1WuHei98rkW3KXkbSGdFr +xDAfOmf2F3ed1RMHKSVPfndTwQKSELVSODs42tFmo1a7EC0Y83HJapGs3Abr22+zzBq rDPhK5g7GpC0tA+aq2+6QK+RSzCVMOGruDJAdW7fuF6k/0Gv22HGSL+R5too19q/M7+7 /8bA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lYDdyh9D; 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-199258-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199258-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f6324191b7si65701165ad.608.2024.06.03.06.59.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 06:59:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199258-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lYDdyh9D; 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-199258-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199258-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 6941628A972 for ; Mon, 3 Jun 2024 13:59:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7BEC12DDBA; Mon, 3 Jun 2024 13:59:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="lYDdyh9D" Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.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 E60201E892 for ; Mon, 3 Jun 2024 13:59:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717423166; cv=none; b=odzTcpLs/7XKEyWv1/6aI5WUd/PUx4nTnFW1iOhiM2dgnPbjKrAb//frilY98Km2goZmLuHTYSCubQBOPQ3u/e1+83s+4q0NzxhjRGRcq97dg1eGiSiP/Qw0ivdEGmRvkZ3Lhn1jrh43iLvnkljCkjJjVAwlTyibGFjQhwrPW70= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717423166; c=relaxed/simple; bh=cp0EWn+6r/LDs36eodL94/fGja5GAeIBzCYRxpW1QoQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=hXv6JPvcOp0ytPkCQ2aHPQXcpFr+jABIGzyWBWLcMz7BWP7RmqmqUcS2W5exoWXwuTaTmTYbNKTsXdzavFUQIJi81im8oBJAF4EH8gJON+AvgJr30tNvgFpy3iZGKkJvueyX+d+il9lXDWT55ReIwx0N287kz9UVZ8xoskHpMT4= 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=lYDdyh9D; arc=none smtp.client-ip=209.85.219.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-yb1-f180.google.com with SMTP id 3f1490d57ef6-df7722171bcso4304038276.3 for ; Mon, 03 Jun 2024 06:59:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717423164; x=1718027964; 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=o2BkymhQ/db2q0Xr2SvTMdgw34Lx4ntfmiWk5iS8ce4=; b=lYDdyh9DSxC8f0IuGLcT7CDeWTvZcmaYqLJrGECfN4NcTa8cQnzervbRRG+b4DDgK3 2RUASGHSsZZamZV1/zQD6R0lpRpvSIE0s20ZFXE+vTNth+1Zh7Wsd89Gc/m42s5yplWz XJ0wo0s5cM0X5ZKj5QtpTN+o8HlcJ/aEOsZ37e7W+KyBQsUgA0ERXjUl/zDNfhaaProM EuRNEFIPZ+LDBlIEOkwL6N0S1qzbyvdoMGfE8xGqZztuzMmLzK78T0TsxCvHa5tUmXqX sTe0XC7LvAAaKvW63yWK3iwZjZ46A9MQ11KHgo0TM46ULrkCtwshujEp8rZfyL8YvsWp aTfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717423164; x=1718027964; 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=o2BkymhQ/db2q0Xr2SvTMdgw34Lx4ntfmiWk5iS8ce4=; b=LqwuB+7YeCX1B5D4f3QnLFoweEcpyRjkta4CeuTyPRNH/gihhIDQAq+7poSOcXRuPC qOcFxJ3r09bdqIE5rxvgXfHV+n//meFVZfwy2bh6RENuLd9Cd2SfmlFGyHvwSICYPRNB nPvGjAAdxPr9XU2o7Pqxfn1Gc0H3j4CHQEhybpVwJjc7HQgt4rfAHVvnrO3ELL7fbWpp j/82EEqV2wVuQpybVRdOneFo36UXK1/93hY5IjP01YL8PRcWSZfqoY3vQHS5yIPcapFp EGTjZ7Q1HXAWh6YZMlVfytufqBTWKZTlQXJrXzKqcCthGdnC5ViqIHBKmoXKB/tVbLEp nMYQ== X-Forwarded-Encrypted: i=1; AJvYcCXMurpmIsc8szsC4T8fWo2+ft4N1V3SWo48dYo7/4z0VCEOmXaDQuE1HRlE86PmD0dF6a9QaidrFKN2pCHI3aSfwd8PGMk7bIr2XTHF X-Gm-Message-State: AOJu0Yx8eF2CNMthjMQ6fyaVYcaXrReTBJkJGidRpOaVBO+Q86sB+nbF Va4JULgreP45SjX2/E/5cEINpUhpyeojytchgZxFj5GoOo/BR4C9YuIL7pqR/2i+Wft/2HTNbBP Ic/kMam8iOGLPWivtU8HyZWSwn4KorytxypLyOw== X-Received: by 2002:a05:6902:260c:b0:de6:dcd:20ae with SMTP id 3f1490d57ef6-dfa73c229e7mr10000393276.27.1717423163818; Mon, 03 Jun 2024 06:59:23 -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> <24570028-42cf-43b1-95f2-b6f48233bef9@quicinc.com> In-Reply-To: <24570028-42cf-43b1-95f2-b6f48233bef9@quicinc.com> From: Ulf Hansson Date: Mon, 3 Jun 2024 15:58:47 +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 Thu, 30 May 2024 at 16:23, Nikunj Kela wrote: > > > On 5/30/2024 1:15 AM, Ulf Hansson wrote: > > 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. > > Got it! Thanks. Maybe in future, if there is a need, a new GENPD FLAG > for RT, something like GENPD_FLAG_IRQ_SAFE_RT, can be added to address this. Yes, I agree, something along those lines would make sense. BTW, did you manage to get some time to test the series on your end? Kind regards Uffe