Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2100873lqb; Mon, 27 May 2024 07:56:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXg7wzehuRzVLq10FMSFCp/VqDO+SnTnuGxieP+7mJF3LoU8MGyJ1QvaRTTxtHgPpVAIt1PIHZBhyqrLYzDV/yAUFHkv1udpg9/nINgnA== X-Google-Smtp-Source: AGHT+IF0f1pVkL9B8m+ZDdXSTA2UrKXaaQtLfAChI3YcV1GCvTTRYRUYTeRtLzmKvAobFGPpqVto X-Received: by 2002:a05:6214:2c13:b0:6ab:996d:425b with SMTP id 6a1803df08f44-6ab9cfbeb68mr207498466d6.4.1716821769093; Mon, 27 May 2024 07:56:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716821769; cv=pass; d=google.com; s=arc-20160816; b=SSNOFTu4wW2h5GQtgYEKsuvDfzeCdrxKx0Qxhj+UoLMnrruR/vRfprReGPII1AxciX c9E2Rnzw2RKxs/llPHLTGAWX1sW9Smw8sbOEWkdeKJU7ifCmz0mVpVs7m5h3rVNG7nPJ mn1iRFQJWpchQYmLRJp4n6ADfzjMqZBHEPQupEadJfcYZkpfPuWCaqV95Du6YM74Tx1w syz+ZrYcGCq9vgA1i/Qx7djKlekTf76GXMaxsylWhcnlEvvrHFLwE/Cndn690LP2z1OQ 4PgmkQ30IhsjOaRnb7oLMv/cjzIZMSnA8EbeNDOVxufSW96wUOGQGp/f+3o8IkwYIUsX MgQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PZoaMc6WifhZ+fBwKL5gwIEFdMUp0oaX6j5v8OfXh20=; fh=wMko0FyI9+mKWffgjTlFeC8A6Ys2BmVcEzFEore6Oko=; b=HYKMbIEcAN7N4lk26JnvCslEpV1Jw1cO2KstukdByzTL5910c0bZEiyMxn5pB2Xj+6 9eMDe4nXEMAkZhDQrhUxcwkhVUmtaIip8dwO+6jCMfgZ/6tFOchMTye6+gSRe240e7Cx QLrLjkYXsuW9fghzvbrYUWngTOL+g0B+t5ezybuVmmLQ8mY2hhwqmnGdcaPl79MD9BTu JfRFtFmeelgn354muKr4ns9SpoEXF+JA8d2GKBaZlJei1/8uuHcrtRTvy/cbYmIWcO18 gH/4AOwNNgg6iBotcCHLuwyBVzHYtI1A1pf6rKOgbotmAPo68ZgQRHTeFRamru6UprCY deBA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MB+Qa57g; 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-190957-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190957-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 6a1803df08f44-6ad7920cc9csi37298506d6.378.2024.05.27.07.56.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:56:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190957-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=MB+Qa57g; 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-190957-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190957-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 BF1981C2147F for ; Mon, 27 May 2024 14:56:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D932D16191A; Mon, 27 May 2024 14:26:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="MB+Qa57g" Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 EF30B161906 for ; Mon, 27 May 2024 14:26:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819973; cv=none; b=AnisvRN8GtihYT2M/51uP5LkoIyIJt82Q8qhb8R905NmZceXlb2+ciY/JoKlpAy3vIAcbUgKFy9WESLSHC+Xvz5gzUFwPu1zFAgNbQszI9zWB2BrdjrnAy4rGNFp8ERKutCb8oYYiWyzc0XrJa7bjZB9rBAqVK/C/xADpddxkis= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819973; c=relaxed/simple; bh=XKLaI74qjA22QeAsWI8Ln1246wnUj1/8uIXA+l/FzQk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L9YYqtN4+LEEozRYb/vfK7VY6SuD6pgEb2BGdotlMUzfAkiO2aEdxcL6Fyw1K+8+GHDu7TiGtoIBy4OqWTIX3zligWlqDf8yyW7fqshfp7xmtQzHKttJR1J7oa6Q7MQ/7uP39FdfkshYp8AP8sjdzXNYYmKQD7ybvJcgJNO2Pkk= 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=MB+Qa57g; arc=none smtp.client-ip=209.85.167.48 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-lf1-f48.google.com with SMTP id 2adb3069b0e04-51fcb7dc722so5088075e87.1 for ; Mon, 27 May 2024 07:26:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716819970; x=1717424770; darn=vger.kernel.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=PZoaMc6WifhZ+fBwKL5gwIEFdMUp0oaX6j5v8OfXh20=; b=MB+Qa57g/N7vGhiTnBqeOdPr2vrn3NUueqPQQ1Cj2S9JeTDVEVYKown+p3pkV1/rnz 2fdKR7s0KH8PLV6H7cqPf/nbWkIBZM4RAAEb8ujyrliHHUxgFs36RiT7aCnqeKIfGoIL V1HY731aMyAVRbVhkXsr/6dXHuWynzkwFmUTXL+ug3jsUqPampMfQfxYLbzDVxJdrpbb gTUTLo0o4x9Ne+RxMEeEKxbTsC2Wod91QWafaMdpzINvF1BpSlgNzNaV215B2i+dzhJK lDoLTcmsZ2YF57TJAyaamMFaD8Uc0NUU9vq+bPBqAruMedGXVwU22A3ZxhvfPC5OciKB Nw9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716819970; x=1717424770; 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=PZoaMc6WifhZ+fBwKL5gwIEFdMUp0oaX6j5v8OfXh20=; b=jkfUOsZ0FCbyDgaul6sqXOhXiLC4vRiq3dCyFZx/P38o2dgzJru1FHqUlvkcOIQxms UfpPUm4q1B5h9E+DgRzFWpe1JZneOsdmc9PQhiQAb5L+9R5VD5shr37WmuSJ1NvX367t nJ/2UPOCB9GBhpY3IZH/y49DWblNVn7H1ipuPBJSLkxvOrwNmPEYuUKn/mjS5XXLYe9T D+rt+FMp60jcv4W0pXRGYLr3PhCEjVvkayWsynXGvT5uFCNQzcL1XgSONa5Ja6JybH9t +uYwXesPstUV+DqT8K7xMAJR/DnuWQPhZvovSv42bp/BGvzKqUC6dcj8fUezb7hv6dea tRZw== X-Forwarded-Encrypted: i=1; AJvYcCU9a9uZ0QtUvaR15SksLJ7t0cfVNYZErYaFNiqXUK+USu3JjHkgdrZoMe6SICSfMItkQMTl2k3tTb5bpzVoo1V1U4NEMbmOtkq4CSPQ X-Gm-Message-State: AOJu0Yy1QG3h9S1LtZ3ypXjpzcRAIwhB/UDZn2Wfy5tiIsOCUNyoFJo8 GPWoV63+S8VvesJ/mz5hqe24OnTGa6LqFU1VYDJ1Z14Mj/Z6MKCc5AF/4u1r9v8= X-Received: by 2002:a19:5e10:0:b0:51f:c38b:149c with SMTP id 2adb3069b0e04-527ef3ff4d1mr4004099e87.10.1716819970021; Mon, 27 May 2024 07:26:10 -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 2adb3069b0e04-529711fa7f3sm562002e87.258.2024.05.27.07.26.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:26:09 -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 v2 1/7] pmdomain: core: Enable s2idle for CPU PM domains on PREEMPT_RT Date: Mon, 27 May 2024 16:25:51 +0200 Message-Id: <20240527142557.321610-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240527142557.321610-1-ulf.hansson@linaro.org> References: <20240527142557.321610-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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) { 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 f24546a3d3db..0d7fc47de3bc 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) -- 2.34.1