From patchwork Mon Apr 29 14:05:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 13647034 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CC9B6C04FFE for ; Mon, 29 Apr 2024 14:06:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GO3zvncvbwVu0UxND26khw2SGO0/U0tJjuaxTWKIOBc=; b=yU45PRWhmh1Y0B bktDdzCgG9zUxn3JbAPW6CLD3e7f3ebcjdeuFZfSnLMpnWJVsOZkPh7QJtUlqDu3qj0B/KGEZMAxv g/LoMp7Q9P+4ChhqsUx/DEzbhCKyC2Lkf8noAr1WlA47ckFVccgJUnTYWFDbBRR3XJ69B531uXylA 5BK8LJ23jf6R1Ic4vS6W47h4PQOzFTWSVJJ353FkDxxHWc9uihWZmgEvDiMaDVGGXMvEoWt503Ibd ST/Yn7QBTWpQdCQ8BmQlBJ8OAHrvl3CrrgLGyt8HmqOP8oNjMg6lArnVZBvsrSGpk8W8DQRJgDYoh ihKx2TqWdxs7GOobPtlg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1Rdw-000000033OS-1rKs; Mon, 29 Apr 2024 14:06:08 +0000 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1Rdj-000000033KU-1oGb for linux-arm-kernel@lists.infradead.org; Mon, 29 Apr 2024 14:05:56 +0000 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-518a56cdbcfso7074152e87.2 for ; Mon, 29 Apr 2024 07:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714399552; x=1715004352; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v7PwnHMKHYTfq+/GlcRBAJxV8k/M8+pq8KDTTyHcZEg=; b=f3yBkS/PJYqV3UB6Qk58UznFmd44LrBd6+ey6TDknTFpqXavP1Fu7OcDfVXS4Lgdmw YP0KwqCW8pkGzaviW4xvS9VVivyYWGA6EjuubPKkGFSOnaycIzcLXpEdiDkLsCys6jPB pBtSw7TuHzdxzLq5aRKaWmzK869+A6JVl+T0D+1KDCIEj1bY/JHXobFhY2bIsj+XCnWK q02qz3+sF0QmW76XMYDrszGaYLj04K5y3NfB64rHf25JULyjegallGC9i2MFMVuZ7u4B de5e4IUOaQvBwSuHxVBgtjopVDRbAb7uDJ4lZVQVnQzXBpd95JoJzQJYZPaPiC1kXlMn xqeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714399552; x=1715004352; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v7PwnHMKHYTfq+/GlcRBAJxV8k/M8+pq8KDTTyHcZEg=; b=gLJUFSqy0LT8FgOSiDPy+LLHCL+rFjB31TGBlKbLM6q9CApTjfZshZEjOHqxSzx4zT QLj9PNT7lWxt1ECE37jREnBIc99TQwfUWnFDZ8RaZgcKcbqglxQ7ZFy/KHCx1Fm+BoRD MiBmnZZDNPE8po6cTgeV55jlpS8Y9NTcsOfRUB0lkL+jQUkwiURy/JpI+YlTuFAMhmBH UwEyjeTPoR1ocEWB816EVCjVHV8uBB2Ncm5OwkEboaYnrJEGIR43QLOVFjUQwxx8Fgpo SPUv706jfrZfxpCJXTwlQwQQ06cY32gtsFsCVAcx//seG9ezv5UCZFmcPg4sjsWRuZL5 xiHg== X-Forwarded-Encrypted: i=1; AJvYcCXgPdswsibhV1tLN1osM1Iqpn7evKtB3fMqdqG6PmJCNdLk1VfQzPlOI8F3mMbqwfKZRWTRbZSAKm4wTRv5y8ASUgGjf/PAiRgrDvrSLpOgag/sPPQ= X-Gm-Message-State: AOJu0YxTzJ2NPXmpiSLETlqh95C9xYD8G8OxHZNlpSXzxqF0JFpjinMw rXmWu0Q3+WHNL9imqOqcOl0htS2vk79lfzHJX1izZ0aK5DqMOAs1IsMSj7rC5Ew= X-Google-Smtp-Source: AGHT+IFR8cvupOz4nvn65URl6ZTQLfP1foLQ6aQMTVOSVqjXElBksfqqnj9dzeKq2OEC3TicFEDdMA== X-Received: by 2002:a05:651c:211b:b0:2d8:d972:67e3 with SMTP id a27-20020a05651c211b00b002d8d97267e3mr10312447ljq.5.1714399552449; Mon, 29 Apr 2024 07:05:52 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id l5-20020a2e9085000000b002d7095bf808sm3636733ljg.128.2024.04.29.07.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 07:05:52 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , linux-pm@vger.kernel.org Cc: Lorenzo Pieralisi , Nikunj Kela , Prasad Sodagudi , Maulik Shah , Daniel Lezcano , Krzysztof Kozlowski , Ulf Hansson , linux-rt-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/6] pmdomain: core: Enable s2idle for CPU PM domains on PREEMPT_RT Date: Mon, 29 Apr 2024 16:05:26 +0200 Message-Id: <20240429140531.210576-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240429140531.210576-1-ulf.hansson@linaro.org> References: <20240429140531.210576-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240429_070555_494661_6ED1ACCC X-CRM114-Status: GOOD ( 17.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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 342779464c0d..abd3c069df8b 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) @@ -2069,7 +2111,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) { spin_lock_init(&genpd->slock); genpd->lock_ops = &genpd_spin_ops; } else { diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 772d3280d35f..670392ecd076 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -194,8 +194,11 @@ struct generic_pm_domain { spinlock_t slock; unsigned long lock_flags; }; + struct { + raw_spinlock_t raw_slock; + unsigned long raw_lock_flags; + }; }; - }; static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)