Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1046926pxm; Wed, 23 Feb 2022 16:46:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJxlyNKYMGxEH+hdUWbInwvWpQ7uw5zRHs76HUDTMohtA6JvWbWjSjvVZkvkTd23EYdeeirN X-Received: by 2002:a17:902:850b:b0:14d:9b77:958a with SMTP id bj11-20020a170902850b00b0014d9b77958amr366106plb.123.1645663610007; Wed, 23 Feb 2022 16:46:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645663610; cv=none; d=google.com; s=arc-20160816; b=lrqygkgoQNosdjb/9NWkXieJVH+OWGHyX+d2IQB/l6K/ZYZTWodw1O4QRVZ0Nd5vay zNv2ENa43QHt6urXVRiOliyuDmKfOFaHTJBK39hjvANvryHwy9932un8a5Xl7X5hM/sN h+4r/IYHGJz7MAi/yV9ZG2ZYuoKnp2zSewswSRQj73qW00ssX2+1ZzSmBYZDDYsbOSCH 7lsURVoH9rylluS9yaMyKeTO4QhEMyTDQeN4argmZ1ljgsqWRellM5YpjW4CO/TfJCnN 8mp+IR3ad2tRaNK9AtIqomCoxFvbfkRJsDxWV+haUjVhHIX1FVI2x5p3QX2JIRiInLzd v6+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9zjHo6BnE+LkvSb3drhMyymhfgiGeZ2qxQyNQtjreqM=; b=F2hdfaOSoj01+uaH4h8PJsWoHThkzw9TJGzgMToSF/lD3I0mGoLzAQkHOLWO2dlZmo wP4K1UeJAt0un0VQbTcpiU3yFB0L44XRiI97141RJS7H3NkWNqnI7Qm5xO6Zm1N3vkFq HCuB4/vCCTU/8yffhRASD0x9AzaaobxqDbg4HZyitebTH2M9AL/4REOOfGNajd+Icd0i PziiEkfnrUSH2R/vCvgdjirBIEtSOP9T1ZcWgMnutcBmeoC+E+Tm/IBaRIVVL2Z0iT7N gV6SFOk87BNfvZtRUD8VPYFP230CVfvkaSCtkSQMUylE52TSz3NNfSlTjPtTS4TMCMix wFgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CNsXNq6G; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x16si969422pjn.133.2022.02.23.16.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 16:46:49 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CNsXNq6G; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 541A590CDD; Wed, 23 Feb 2022 16:42:38 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240680AbiBWM5n (ORCPT + 99 others); Wed, 23 Feb 2022 07:57:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240670AbiBWM5m (ORCPT ); Wed, 23 Feb 2022 07:57:42 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E755F9FFE for ; Wed, 23 Feb 2022 04:57:13 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id d17so15273951pfl.0 for ; Wed, 23 Feb 2022 04:57:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9zjHo6BnE+LkvSb3drhMyymhfgiGeZ2qxQyNQtjreqM=; b=CNsXNq6GX/7wV0tQQjbzBvUkFpuR3GUyUnpFx34jzgdd5Fca/MULlkHlNnop9BE1H7 UzYtJoh0fjmwrJ7nPJWqTsMnuA09heFJZcOadyMiQnz0YGRZ/cBWaupEglqNi+YebIfG bOd1OHuu0t0wZKKTgcbhFCjlTiEy7o0wednqgj1ST/w7M17cUKSSQXfRpvdVVuqub/Sb ulNUDwC7lxJ4ocr5GGvujco3nau+SVz1RFQkaiugxQQbQchtOTC8nzH541e/vEwwKtGS vxVgnoH3bg3IHWaZTegO5vsd79ctl9MSUb4ZNp5ritfSZ0gc+b4dzihzzT3qXH53GrdP zrzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9zjHo6BnE+LkvSb3drhMyymhfgiGeZ2qxQyNQtjreqM=; b=LhjNUzBzxNsx1kfu+LMoYfu+oUGfqRQ6It9XtxcrWp9TLEM608c4gAhWBy6XRsT7qw Wi+LmFVAzZFz5MPUtQsAhNDEBvFUm8knE2vNQWMFqIPEZ1FqIAg7RXRFIUD1SYDl8b5L qaKE9wGOZksQIvcNUZqPRzv6sqOEduIl5aV7+h4bjFm7GX29HrvAVfS0vYIBl+vK+Vt6 UnX37gw57zImr8wBrvFB5zbKgV0jY1lloXrncxUIrRWeHyf0DzbJSiMsrB3oeDmJ0ZqK rNjiZdgcTWAqmPZL8F1mbo344jbCA9e8jgwx6ARMTs3WVsXxqXFq8kWzlq369NfFzE1y I9UA== X-Gm-Message-State: AOAM533MYWQD+Y4iCZkEnKiYKiJVRaZiWFWgpCCX4HJWQ6MB3803xEjf coo/HO8QoNftD/KaDh72CBvB+A== X-Received: by 2002:a63:531d:0:b0:365:5f0c:7cbb with SMTP id h29-20020a63531d000000b003655f0c7cbbmr23503993pgb.150.1645621033463; Wed, 23 Feb 2022 04:57:13 -0800 (PST) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id z23sm22136243pfj.87.2022.02.23.04.57.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 04:57:12 -0800 (PST) From: Shawn Guo To: Marc Zyngier , "Rafael J . Wysocki" Cc: Valentin Schneider , Sebastian Andrzej Siewior , Thomas Gleixner , Maulik Shah , Bjorn Andersson , Sudeep Holla , Ulf Hansson , Daniel Lezcano , Rob Herring , devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Shawn Guo Subject: [PATCH v6 1/3] PM: cpu: Add CPU_LAST_PM_ENTER and CPU_FIRST_PM_EXIT support Date: Wed, 23 Feb 2022 20:55:34 +0800 Message-Id: <20220223125536.230224-2-shawn.guo@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220223125536.230224-1-shawn.guo@linaro.org> References: <20220223125536.230224-1-shawn.guo@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It becomes a common situation on some platforms that certain hardware setup needs to be done on the last standing cpu, and rpmh-rsc[1] is such an existing example. As figuring out the last standing cpu is really something generic, it adds CPU_LAST_PM_ENTER (and CPU_FIRST_PM_EXIT) event support to cpu_pm helper, so that individual driver can be notified when the last standing cpu is about to enter low power state. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/soc/qcom/rpmh-rsc.c?id=v5.16#n773 Signed-off-by: Shawn Guo --- include/linux/cpu_pm.h | 15 +++++++++++++++ kernel/cpu_pm.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/include/linux/cpu_pm.h b/include/linux/cpu_pm.h index 552b8f9ea05e..153344307b7c 100644 --- a/include/linux/cpu_pm.h +++ b/include/linux/cpu_pm.h @@ -55,6 +55,21 @@ enum cpu_pm_event { /* A cpu power domain is exiting a low power state */ CPU_CLUSTER_PM_EXIT, + + /* + * A cpu is entering a low power state after all other cpus + * in the system have entered the lower power state. + */ + CPU_LAST_PM_ENTER, + + /* The last cpu failed to enter a low power state */ + CPU_LAST_PM_ENTER_FAILED, + + /* + * A cpu is exiting a low power state before any other cpus + * in the system exits the low power state. + */ + CPU_FIRST_PM_EXIT, }; #ifdef CONFIG_CPU_PM diff --git a/kernel/cpu_pm.c b/kernel/cpu_pm.c index 246efc74e3f3..7c104446e1e9 100644 --- a/kernel/cpu_pm.c +++ b/kernel/cpu_pm.c @@ -26,6 +26,8 @@ static struct { .lock = __RAW_SPIN_LOCK_UNLOCKED(cpu_pm_notifier.lock), }; +static atomic_t cpus_in_pm; + static int cpu_pm_notify(enum cpu_pm_event event) { int ret; @@ -116,7 +118,20 @@ EXPORT_SYMBOL_GPL(cpu_pm_unregister_notifier); */ int cpu_pm_enter(void) { - return cpu_pm_notify_robust(CPU_PM_ENTER, CPU_PM_ENTER_FAILED); + int ret; + + ret = cpu_pm_notify_robust(CPU_PM_ENTER, CPU_PM_ENTER_FAILED); + if (ret) + return ret; + + if (atomic_inc_return(&cpus_in_pm) == num_online_cpus()) { + ret = cpu_pm_notify_robust(CPU_LAST_PM_ENTER, + CPU_LAST_PM_ENTER_FAILED); + if (ret) + return ret; + } + + return 0; } EXPORT_SYMBOL_GPL(cpu_pm_enter); @@ -134,7 +149,21 @@ EXPORT_SYMBOL_GPL(cpu_pm_enter); */ int cpu_pm_exit(void) { - return cpu_pm_notify(CPU_PM_EXIT); + int ret; + + ret = cpu_pm_notify(CPU_PM_EXIT); + if (ret) + return ret; + + if (atomic_read(&cpus_in_pm) == num_online_cpus()) { + ret = cpu_pm_notify(CPU_FIRST_PM_EXIT); + if (ret) + return ret; + } + + atomic_dec(&cpus_in_pm); + + return 0; } EXPORT_SYMBOL_GPL(cpu_pm_exit); -- 2.25.1