From patchwork Tue Apr 10 10:34:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10332793 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 2F11D6028A for ; Tue, 10 Apr 2018 10:34:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DA3B26212 for ; Tue, 10 Apr 2018 10:34:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 123B928CF3; Tue, 10 Apr 2018 10:34:54 +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 5B51B28B36 for ; Tue, 10 Apr 2018 10:34:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C44306E32F; Tue, 10 Apr 2018 10:34:52 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3DA246E32F for ; Tue, 10 Apr 2018 10:34:51 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id f125so22366847wme.4 for ; Tue, 10 Apr 2018 03:34:50 -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=cgFubS3DED6ymry/VCP5ttGVZC6trCMpu+Hfkxc2PUM=; b=jLpEmL3YYvgiokeD4DqHJ9r3C9OFgzRbgmULUrYo2KqHlrURijGiuQfaijuSpe6Z9S 5JU+qXgZ4KVW8ANQ7klIRzKw649a29aaZPu7z12u7sT/6a/4Zc95X2cFjkZ9adQEeBcX j4y4vypZhWuQp6Lgmosc00/8Z/H/uFJJJbKgHkj4DeWg+yN44ZAhGTypB6s2X8pe3lbs +f4dJmGEMYYJaVmLAxTqWhF/wU/qgkynbNu8K+4+a58tT08WUyo3+N7sTc+QiLF+qP5I DkeQjGSNlJtc8DJh29X2xlqPU850vvqLOXxGimAJH9UpJK1V0G4pZCpfvSX0au+u/u7L z66Q== 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=cgFubS3DED6ymry/VCP5ttGVZC6trCMpu+Hfkxc2PUM=; b=XkiMoxqWhR+nh9VZuu7X+xRx2VXCQ06R53xxuLgscqeUbo4Li/m2Fc7tskWyqNIaJg cuL7RVNm5wOrhmI9bqThTP8MZMWA2lf3RwyTTd6nJ5c6uXjzbAg49kCzmSk0y63/K1Pf nUMQEmuYksw1k50/C0RnxQfuvVb1iwS0CzPECvf8b6R9SSAfLba1V++0lR1ZatmzRRZ7 gKMbvLl91lPj0a6I04CCFCmMtWFs5o9/U70gL2X1Hvd5FYwdEJvmi1Mj6wscLWsfAUhj vdTu2Fyx6KM2GRhggqqu020jiRBV6z8WWhpUWhRoW6EZQUcuqOfwRmnfv6cAZaA6Hjwj YUUA== X-Gm-Message-State: ALQs6tCFVKvn2493TRcxjhdbLfxcyMW0Zjwy7HxzUyVypIYjWYIpMTsf U6eWal6jORG4XGGo0AYgMSv2vO7q X-Google-Smtp-Source: AIpwx49ghGBIJJHCyVW/TdGndhX8ZjE6h0SiQLFGeDeiekNTduVwbsYjNrA6czMY5kC6/XvUBDH0ew== X-Received: by 10.28.144.146 with SMTP id s140mr1149338wmd.74.1523356489518; Tue, 10 Apr 2018 03:34:49 -0700 (PDT) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id y51sm1702933wrc.38.2018.04.10.03.34.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Apr 2018 03:34:49 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Tue, 10 Apr 2018 11:34:40 +0100 Message-Id: <20180410103440.24048-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180410092328.20645-1-tvrtko.ursulin@linux.intel.com> References: <20180410092328.20645-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH v2] 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. v2: * Re-arrange the code a bit to avoid second unlock and return branch. (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 | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c index bd7e695fc663..247a050f816e 100644 --- a/drivers/gpu/drm/i915/i915_pmu.c +++ b/drivers/gpu/drm/i915/i915_pmu.c @@ -473,20 +473,35 @@ 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; - - val = kdev->power.suspended_jiffies - - i915->pmu.suspended_jiffies_last; - val += jiffies - kdev->power.accounting_timestamp; + /* + * 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 = jiffies_to_nsecs(val); + val += i915->pmu.sample[__I915_SAMPLE_RC6].cur; + 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); - - val = jiffies_to_nsecs(val); - val += i915->pmu.sample[__I915_SAMPLE_RC6].cur; - i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = val; - spin_unlock_irqrestore(&i915->pmu.lock, flags); }