From patchwork Tue Oct 6 21:57:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 54566 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id 6A1A122FC5 for ; Tue, 6 Oct 2015 21:57:58 +0000 (UTC) Received: by lbcao8 with SMTP id ao8sf52821891lbc.1 for ; Tue, 06 Oct 2015 14:57:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=ITHwAVzmktYjiHvEPnJiw19PR4h5yBsR3hcCoO7uT4c=; b=d6wfkRURBjO5OAvsBT66/otR8ueph4h9yeOvs55eYcypFK//ru1t13nvUPPISF/ZGt gAGYYaG9dTn/3ch3YlNxI/izo0ZgoZqryi/rxSuVZZ5muKLs9+t78EM+hBnXuwMPPHy3 0ywgRco2tVseYAYgGZbfNbrV0hBCAcLRlCUPM37o7ZRFz7YJ6jzPhXRngaoNVcoxNiqm ky2dYI+GNze0gPvrNfiYGKByGnCKT9uzwiOTyhZzYG9m1RgQR1pvwiJ/g3AjcScTek3Q DU0HYvMoeTiURiGJWSqW/KtdlVN4dr8h74xbsiLnrK/XeTOxflCNFeF8vC/iaRrhi064 yiUQ== X-Gm-Message-State: ALoCoQm0NykbP7bBv2g00JA3yb+aQKYnVQEtDKgJTOFrnNkQNr0hw0RUYrizjoyT+Ag3XyPGCJJL X-Received: by 10.112.138.170 with SMTP id qr10mr7031784lbb.4.1444168677421; Tue, 06 Oct 2015 14:57:57 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.25.67 with SMTP id 64ls687610lfz.41.gmail; Tue, 06 Oct 2015 14:57:57 -0700 (PDT) X-Received: by 10.25.152.211 with SMTP id a202mr10466543lfe.66.1444168677288; Tue, 06 Oct 2015 14:57:57 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id k81si22600605lfi.90.2015.10.06.14.57.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Oct 2015 14:57:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by lacwq3 with SMTP id wq3so6592135lac.0 for ; Tue, 06 Oct 2015 14:57:57 -0700 (PDT) X-Received: by 10.25.20.80 with SMTP id k77mr10262216lfi.117.1444168677124; Tue, 06 Oct 2015 14:57:57 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2088191lbq; Tue, 6 Oct 2015 14:57:56 -0700 (PDT) X-Received: by 10.66.141.165 with SMTP id rp5mr49108510pab.127.1444168675956; Tue, 06 Oct 2015 14:57:55 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bk2si52085307pbc.78.2015.10.06.14.57.55; Tue, 06 Oct 2015 14:57:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752697AbbJFV5z (ORCPT + 12 others); Tue, 6 Oct 2015 17:57:55 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:36273 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752313AbbJFV5y (ORCPT ); Tue, 6 Oct 2015 17:57:54 -0400 Received: by pablk4 with SMTP id lk4so220830197pab.3 for ; Tue, 06 Oct 2015 14:57:54 -0700 (PDT) X-Received: by 10.68.216.193 with SMTP id os1mr49191970pbc.110.1444168674120; Tue, 06 Oct 2015 14:57:54 -0700 (PDT) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id c16sm35342076pbu.37.2015.10.06.14.57.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Oct 2015 14:57:53 -0700 (PDT) From: Lina Iyer To: linux-pm@vger.kernel.org Cc: grygorii.strashko@ti.com, ulf.hansson@linaro.org, khilman@linaro.org, daniel.lezcano@linaro.org, tglx@linutronix.de, geert+renesas@glider.be, lorenzo.pieralisi@arm.com, sboyd@codeaurora.org, Lina Iyer Subject: [RFC PATCH 2/2] PM / Domains: Atomic counters for domain usage count Date: Tue, 6 Oct 2015 15:57:36 -0600 Message-Id: <1444168656-6576-3-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1444168656-6576-1-git-send-email-lina.iyer@linaro.org> References: <1444168656-6576-1-git-send-email-lina.iyer@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lina.iyer@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Locking a domain to check if the domain can be powered on/off is an expensive operations and could hold up multiple devices executing runtime PM at the same time. In the case where there is atleast one active device, the domain would remain active. This can be easily checked by using an atomic counter to record domain usage. This restricts locking only to the last suspending or the first resuming device. Signed-off-by: Lina Iyer --- drivers/base/power/domain.c | 16 ++++++++++++++-- include/linux/pm_domain.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 3af1a63..80f8ea9 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -204,6 +204,7 @@ static bool genpd_sd_counter_dec(struct generic_pm_domain *genpd) if (!WARN_ON(atomic_read(&genpd->sd_count) == 0)) ret = !!atomic_dec_and_test(&genpd->sd_count); + atomic_dec(&genpd->usage_count); return ret; } @@ -211,6 +212,7 @@ static bool genpd_sd_counter_dec(struct generic_pm_domain *genpd) static void genpd_sd_counter_inc(struct generic_pm_domain *genpd) { atomic_inc(&genpd->sd_count); + atomic_inc(&genpd->usage_count); smp_mb__after_atomic(); } @@ -583,6 +585,9 @@ static int pm_genpd_runtime_suspend(struct device *dev) return ret; } + if (!atomic_dec_and_test(&genpd->usage_count)) + return 0; + /* * If power.irq_safe is set, this routine may be run with * IRQ disabled, so suspend only if the power domain is @@ -620,6 +625,9 @@ static int pm_genpd_runtime_resume(struct device *dev) if (IS_ERR(genpd)) return -EINVAL; + if (atomic_inc_return(&genpd->usage_count) > 1) + goto out; + /* * As we dont power off a non IRQ safe domain, which holds * an IRQ safe device, we dont need to restore power to it. @@ -1400,9 +1408,11 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, if (ret) genpd_free_dev_data(dev, gpd_data); - else + else { dev_pm_qos_add_notifier(dev, &gpd_data->nb); - + atomic_inc(&genpd->usage_count); + printk("Add device %d\n", atomic_read(&genpd->usage_count)); + } return ret; } @@ -1457,6 +1467,7 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd, genpd_unlock(genpd); + atomic_dec(&genpd->usage_count); genpd_free_dev_data(dev, gpd_data); return 0; @@ -1799,6 +1810,7 @@ void pm_genpd_init(struct generic_pm_domain *genpd, genpd->gov = gov; INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn); atomic_set(&genpd->sd_count, 0); + atomic_set(&genpd->usage_count, 0); genpd->status = is_off ? GPD_STATE_POWER_OFF : GPD_STATE_ACTIVE; genpd->device_count = 0; genpd->max_off_time_ns = -1; diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 613f7a5..7e52923 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -55,6 +55,7 @@ struct generic_pm_domain { struct work_struct power_off_work; const char *name; atomic_t sd_count; /* Number of subdomains with power "on" */ + atomic_t usage_count; /* Number of active users of domain "on" */ enum gpd_status status; /* Current state of the domain */ unsigned int device_count; /* Number of devices */ unsigned int suspended_count; /* System suspend device counter */