From patchwork Thu Apr 25 09:04:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 10916327 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B20F51575 for ; Thu, 25 Apr 2019 09:05:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D84728068 for ; Thu, 25 Apr 2019 09:05:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8ABED2881A; Thu, 25 Apr 2019 09:05:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2B25F28068 for ; Thu, 25 Apr 2019 09:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=N6lk8ficWdhBnXkoH0gSVO36fRA/7ctHdCAAPIaaX8E=; b=ZqRlC9vhROepNHsUGRchkPIJD1 PrfquntG/0rjG/q858GGEnS3GQIscgwEVMKp7kXHfnz0iRTPKEd5cq+RDcOfu6jwiFNVrjcSmA5gB JzOaTJcvswYjNGRaptorL6kpQZfTHTqEZweulstSw0RKaY0eA2ioiWXWMQ39d7g2w4SG879CL0ios IlHIIKop23/1D1YCrT/oMoXrpf98xZ0QQFRi9aJwzLyDpp3vkXHsPG0/PhQxjTGVGjiNKieHeXdbL hhIWWYlVn+V4OGXbn39Lfi9Gf/sf0SSMQbCHrhsZb4G/vT3tO5JaulJT6+qX7+VT15dlVVos2KJE6 +xFyrDSw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJaJa-0001mP-A2; Thu, 25 Apr 2019 09:05:10 +0000 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJaJ1-0000DO-5N for linux-arm-kernel@lists.infradead.org; Thu, 25 Apr 2019 09:04:36 +0000 Received: by mail-lj1-x241.google.com with SMTP id l6so4700779ljb.3 for ; Thu, 25 Apr 2019 02:04:35 -0700 (PDT) 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; bh=ljpH5vhDYU6UY/Q2jNUSgYZIZdDGjQoptAffM3+XQlk=; b=BAmUdz0A6ucFtMa3FlMjlvWEkgHz+I/RgilH744my9IIg2l5Ut2yeVd499EqUNrr6R uV/4d0GC3qYyx6hCiI49R6RLU0kg/2hLato1gnweW5VdtAIm8JM2e0zrpFNRcFPidZnd h3/qVFeDrsxuCRCGoaPPavPlZpDY7b7UMRlMdiXQXYk9Zrw73S1i5lRTrrtbIRHkdGwb ewlfzjEnDEjEXq7oGTSkAonepLVdiQ/Hizm1tR0DDbGj44fhARuiSq0PIR7rFyEgI7JK klfi2i29i5xjhTfk+vEM6yAgeYBd690fWdvNX9Ybvab1BGCzhknbbmqCaB1iggqbLqWV FjvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ljpH5vhDYU6UY/Q2jNUSgYZIZdDGjQoptAffM3+XQlk=; b=b0yM9c06zE7Mcwz6TZPxAsCuTiJkHC5Njm7Z6D5fgWbkYGqoNpcSCDClUaU44UJi24 mnSn9+30DomsuoLv0ISuWdRzSmxA0NqXIWH/3ZgAYC9ghYePOKGqRhvAYSiLyXXCKY4J TIT48oeMFxJRN0eOLIQsalolhJstgBj/PzpemEpywf7gJIsV+1OOwcnfVLDrtHxVk2RY 4rK2l4ekWqPdkDKr1vZdKeu4AwSYMqWyB4zc2B7jo+CSG4sBmLflppbk8n4dVkASUvJ+ CdtLlSjO4IOnTr6eLGXHxpSnXLL7Dzz7JmhPo+GGqYovrp4Wf7xsIaOpkF19L5VVFw9S lMbw== X-Gm-Message-State: APjAAAWfnD0Jw3i5lVS8cQ0QTQFPK11uIx45JvF6eE7oJ+egB4INGpct okEte7Jle34gkuOdYsRICUAFDg== X-Google-Smtp-Source: APXvYqwUgctYNY2PsII4FPHfAlMMLwytUkPcselJGfHLwIChpuih8ndC76NbC/2TMSVHxD4zsiSlAg== X-Received: by 2002:a2e:9a0f:: with SMTP id o15mr10280206lji.130.1556183073597; Thu, 25 Apr 2019 02:04:33 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id v26sm4517353lja.60.2019.04.25.02.04.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Apr 2019 02:04:32 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Subject: [PATCH 3/4] PM / Domains: Search for the CPU device outside the genpd lock Date: Thu, 25 Apr 2019 11:04:12 +0200 Message-Id: <20190425090413.10700-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190425090413.10700-1-ulf.hansson@linaro.org> References: <20190425090413.10700-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190425_020435_236795_8E030AC5 X-CRM114-Status: GOOD ( 16.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Rajendra Nayak , Kevin Hilman , Stephen Boyd , Viresh Kumar , Daniel Lezcano , linux-kernel@vger.kernel.org, Lina Iyer , Tony Lindgren , Niklas Cassel , "Raju P . L . S . S . S . N" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP While attaching/detaching a device to a PM domain (genpd) that has the GENPD_FLAG_CPU_DOMAIN set, genpd iterates the cpu_possible_mask to check whether the device corresponds to a CPU. This iteration is done while holding the genpd's lock, which is unnecessary. Let's avoid the locking, by restructuring the corresponding code a bit. Signed-off-by: Ulf Hansson Acked-by: Viresh Kumar --- drivers/base/power/domain.c | 52 +++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 93298b7db408..da1c99178943 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1450,8 +1450,8 @@ static void genpd_free_dev_data(struct device *dev, dev_pm_put_subsys_data(dev); } -static void __genpd_update_cpumask(struct generic_pm_domain *genpd, - int cpu, bool set, unsigned int depth) +static void genpd_update_cpumask(struct generic_pm_domain *genpd, + int cpu, bool set, unsigned int depth) { struct gpd_link *link; @@ -1462,7 +1462,7 @@ static void __genpd_update_cpumask(struct generic_pm_domain *genpd, struct generic_pm_domain *master = link->master; genpd_lock_nested(master, depth + 1); - __genpd_update_cpumask(master, cpu, set, depth + 1); + genpd_update_cpumask(master, cpu, set, depth + 1); genpd_unlock(master); } @@ -1472,38 +1472,37 @@ static void __genpd_update_cpumask(struct generic_pm_domain *genpd, cpumask_clear_cpu(cpu, genpd->cpus); } -static void genpd_update_cpumask(struct generic_pm_domain *genpd, - struct device *dev, bool set) +static void genpd_set_cpumask(struct generic_pm_domain *genpd, int cpu) +{ + if (cpu >= 0) + genpd_update_cpumask(genpd, cpu, true, 0); +} + +static void genpd_clear_cpumask(struct generic_pm_domain *genpd, int cpu) +{ + if (cpu >= 0) + genpd_update_cpumask(genpd, cpu, false, 0); +} + +static int genpd_get_cpu(struct generic_pm_domain *genpd, struct device *dev) { int cpu; if (!genpd_is_cpu_domain(genpd)) - return; + return -1; for_each_possible_cpu(cpu) { - if (get_cpu_device(cpu) == dev) { - __genpd_update_cpumask(genpd, cpu, set, 0); - return; - } + if (get_cpu_device(cpu) == dev) + return cpu; } -} -static void genpd_set_cpumask(struct generic_pm_domain *genpd, - struct device *dev) -{ - genpd_update_cpumask(genpd, dev, true); -} - -static void genpd_clear_cpumask(struct generic_pm_domain *genpd, - struct device *dev) -{ - genpd_update_cpumask(genpd, dev, false); + return -1; } static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev) { struct generic_pm_domain_data *gpd_data; - int ret; + int ret, cpu; dev_dbg(dev, "%s()\n", __func__); @@ -1514,13 +1513,15 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev) if (IS_ERR(gpd_data)) return PTR_ERR(gpd_data); + cpu = genpd_get_cpu(genpd, dev); + ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0; if (ret) goto out; genpd_lock(genpd); - genpd_set_cpumask(genpd, dev); + genpd_set_cpumask(genpd, cpu); dev_pm_domain_set(dev, &genpd->domain); genpd->device_count++; @@ -1560,13 +1561,14 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, { struct generic_pm_domain_data *gpd_data; struct pm_domain_data *pdd; - int ret = 0; + int cpu, ret = 0; dev_dbg(dev, "%s()\n", __func__); pdd = dev->power.subsys_data->domain_data; gpd_data = to_gpd_data(pdd); dev_pm_qos_remove_notifier(dev, &gpd_data->nb); + cpu = genpd_get_cpu(genpd, dev); genpd_lock(genpd); @@ -1578,7 +1580,7 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, genpd->device_count--; genpd->max_off_time_changed = true; - genpd_clear_cpumask(genpd, dev); + genpd_clear_cpumask(genpd, cpu); dev_pm_domain_set(dev, NULL); list_del_init(&pdd->list_node);