From patchwork Tue Apr 10 11:27:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10332843 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A19376028A for ; Tue, 10 Apr 2018 11:27:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91DA128DA8 for ; Tue, 10 Apr 2018 11:27:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 862B328DAC; Tue, 10 Apr 2018 11:27:18 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 05B8F28DA8 for ; Tue, 10 Apr 2018 11:27:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3ECE06E3C5; Tue, 10 Apr 2018 11:27:17 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8065A6E3C5 for ; Tue, 10 Apr 2018 11:27:15 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id w2so21339277wmw.1 for ; Tue, 10 Apr 2018 04:27:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TeCrAn7z+R2gons/REzTJWL1eWQOXOw9Eql2hGIca+s=; b=0XAiyzBrN5RVx3FjZmwvZtM0eOUuVf6qZnjiWf3EhkxnCZfRZ3qDcu7VsdXJZsJ3gU CYZerS8bTaWuRkgD8Y2DwANoUWd5wld5riKwNbgv9gyl9yl3p4+RozS6b4qPf+kKXc+2 jfzQJbbe50Lm13trhi1zCoHjiEkIIMgOwQ10+9lg1STQZH4xMX3sCQ8GLK9141+xconT Cck/ky8qlUGu02aNyMfE0aTAtpMmhXQCzH+y8U7EDhc/jWrGYQB9T63iLZezd633M/rN AN53/1ndCVQKIfXInxYby2D5qwefRYq003RC21v55h737+HK8ltbjFODdP2JeSQwn63D FqkA== 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=TeCrAn7z+R2gons/REzTJWL1eWQOXOw9Eql2hGIca+s=; b=oySmMiTA3fpKDte6HtepTEznAP2zkbKB27vfU4O1S9szp9gFqxfasf+wekrXGoZnq8 CQmbOtjbwln8iE8ktmcxzsIRjm4jf8TlhpRCLAqZhd2yggDa7489drOxgcakb6IlOrfC tOC2/iACKyxhGJIEy7kzAikovKjkA9q/QCTDv4aFNOyfP7SuOjeVJaRa8U7PLnl9zbwc exvNR6BATJgnGEyivvAeHFZNGpmGRETxyyHvyVCDJ9cFifTuk5Yl2i4uV/1rIwn+Jjox dqewvyD3VaGpeKSACl84lUHjQ6HLpNCSBk6Mlg1U0lyZ9uoLXVWtx791E3x2PU15qgCf //2A== X-Gm-Message-State: ALQs6tAQ29tYd8bunHoFrliMVG6tP116ZRQe6bgrCvQ3arHBZEUO+o9I JpZD3KrWTxcGST5IgpDZND6rhmqk X-Google-Smtp-Source: AIpwx49PUt8ko5XqruFEmYofg9vLwqDkCmN1pxgAW+rG8QDXd4GTtf6hNSdLOy8Fo6q2qZ536q7Irw== X-Received: by 10.28.245.16 with SMTP id t16mr1386143wmh.63.1523359633482; Tue, 10 Apr 2018 04:27:13 -0700 (PDT) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id k28sm4055646wrk.96.2018.04.10.04.27.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Apr 2018 04:27:12 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Tue, 10 Apr 2018 12:27:04 +0100 Message-Id: <20180410112704.24462-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <152335754222.3167.5335527274394190331@mail.alporthouse.com> References: <152335754222.3167.5335527274394190331@mail.alporthouse.com> Subject: [Intel-gfx] [PATCH v3] drm/i915/pmu: Inspect runtime PM state more carefully while estimating RC6 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin While thinking about sporadic failures of perf_pmu/rc6-runtime-pm* tests on some CI machines I have concluded that: a) the PMU readout of RC6 can race against runtime PM transitions, and b) there are other reasons than being runtime suspended which can cause intel_runtime_pm_get_if_in_use to fail. Therefore when estimating RC6 the code needs to assert we are indeed in suspended state, and if not, the best we can do is return the last known RC6 value. Without this check we can calculate the estimated value based on un- initialized or inappropriate internal state, which can result in over- estimation, or in any case incorrect value being returned. v2: * Re-arrange the code a bit to avoid second unlock and return branch. (Chris Wilson) v3: * Insert some strategic blank lines and improve commit msg. (Chris Wilson) Signed-off-by: Tvrtko Ursulin Fixes: 1fe699e30113 ("drm/i915/pmu: Fix sleep under atomic in RC6 readout") Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=105010 Cc: Tvrtko Ursulin Cc: Chris Wilson Cc: Imre Deak Reviewed-by: Chris Wilson --- drivers/gpu/drm/i915/i915_pmu.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c index bd7e695fc663..9135d0ada128 100644 --- a/drivers/gpu/drm/i915/i915_pmu.c +++ b/drivers/gpu/drm/i915/i915_pmu.c @@ -473,20 +473,37 @@ static u64 get_rc6(struct drm_i915_private *i915) spin_lock_irqsave(&i915->pmu.lock, flags); spin_lock(&kdev->power.lock); - if (!i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur) - i915->pmu.suspended_jiffies_last = - kdev->power.suspended_jiffies; + /* + * After the above branch intel_runtime_pm_get_if_in_use failed + * to get the runtime PM reference we cannot assume we are in + * runtime suspend since we can either: a) race with coming out + * of it before we took the power.lock, or b) there are other + * states than suspended which can bring us here. + * + * We need to double-check that we are indeed currently runtime + * suspended and if not we cannot do better than report the last + * known RC6 value. + */ + if (kdev->power.runtime_status == RPM_SUSPENDED) { + if (!i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur) + i915->pmu.suspended_jiffies_last = + kdev->power.suspended_jiffies; - val = kdev->power.suspended_jiffies - - i915->pmu.suspended_jiffies_last; - val += jiffies - kdev->power.accounting_timestamp; + val = kdev->power.suspended_jiffies - + i915->pmu.suspended_jiffies_last; + val += jiffies - kdev->power.accounting_timestamp; - spin_unlock(&kdev->power.lock); + val = jiffies_to_nsecs(val); + val += i915->pmu.sample[__I915_SAMPLE_RC6].cur; - val = jiffies_to_nsecs(val); - val += i915->pmu.sample[__I915_SAMPLE_RC6].cur; - i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = val; + i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = val; + } else if (i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur) { + val = i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur; + } else { + val = i915->pmu.sample[__I915_SAMPLE_RC6].cur; + } + spin_unlock(&kdev->power.lock); spin_unlock_irqrestore(&i915->pmu.lock, flags); }