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: 162833 Delivered-To: patches@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp1671745jan; Thu, 25 Apr 2019 02:04:34 -0700 (PDT) X-Received: by 2002:a2e:7e0f:: with SMTP id z15mr20311182ljc.122.1556183074020; Thu, 25 Apr 2019 02:04:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556183074; cv=none; d=google.com; s=arc-20160816; b=di8eL0aC39OtFPoag1Co0lV7Pk2aoge6kIQA90eKA7zGk2ARsquobdBWuHjIaoaiKN WVzXVOdBaX554fHJ/sX9Lk/WuzvX9cUl66gojfIB3e6Et81dRNnZRMh0izmqx6llVtnI F8ZvaBlau3chq6AwaflGJCKileliqgMtyMEpRHojUJQWmiupYDJ6z2DAp3PxupSwZfg+ T+Ge8i4woa+WYLs4nI6vuJsWsO6I6ZOnF19u+P+KTioAj7a0behx0glp76nWxHe1T1pJ bv+c1is4D2fM+P3MiQDDaXEdgQmSF6ADglx9rxP46Mx7AQzG2smaIaCmAnRQPqFhaoWJ 8EMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ljpH5vhDYU6UY/Q2jNUSgYZIZdDGjQoptAffM3+XQlk=; b=QuMovMx2TkNWzh+7SpYIpshnaN7hW8RQ4Y1Ar0bJ/hPen8n+WiVYZJsmRyZcXwZNQz dD5acOVibOPZNSTPl/SXOzl0pG+L5iGmebizSl8r3z7f0/qnEWy6tY+gUKDWxM1Kc1lc cnHZ2wDwfDAv4A1+DQ47s1IdteScGjqA18b6ZG9tDjf8aHR/y+Uka5NFAmuqW9tjxo2e C+hHyP8AdLyveoD1/2hM+qGLIjzl4xBSXzzEmNa76xzsRMnfBpvpFBjts7ljQQxihcAU gk/aH6pPMgo6KtJO9nP9gKgv0C7JaTIHzD/e/AexbeS+/THKWEsrsWZry+Efo4bllrXB CllA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BAmUdz0A; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id u25sor11050992ljj.11.2019.04.25.02.04.33 for (Google Transport Security); Thu, 25 Apr 2019 02:04:34 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BAmUdz0A; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=gZK+0tcOsfDuae59WPqYq6DLcDblMjyDkf+MkbM2IBLfiDchbhcZnSNn1raGkJ0hra KbDx29guRR21qE+s+qVvB5VmVLcTt6yhj72Zp6Osuv7h1kG3tkSQfywNNcGrZ33EX2vX uIrR4GUxm4zRDjyIAwWBQ6ltzRCH/qcx1etno7Yo9PM/LukBrzlf3q6D1ePZOk16cBvx 3iRduUVo3ZLe9rBY4hnWV0XGlftixGjCGv8RP20rUrdA9AntzF+Z8my4ZRKU1tv21JQb 7akV+ZD2e1w8/ONQVgtabUdKxRQxwLk4dhpnjzlEUUXeZdLw10o1ytijJACfBsO/foFV SbFA== X-Gm-Message-State: APjAAAVaDQALEV23yzGpuKrs0U3U0EoOjRwz/ewCnRvM7FSJCLVt5cu1 GI0q8dx3n7zRhvnRRYiaMYWZP3Xm 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) Return-Path: 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 Cc: Ulf Hansson , Daniel Lezcano , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Rajendra Nayak , Viresh Kumar , Niklas Cassel , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.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> 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 --- drivers/base/power/domain.c | 52 +++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 25 deletions(-) -- 2.17.1 Acked-by: Viresh Kumar 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);