From patchwork Tue Apr 10 09:23:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10332719 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 4F7AB6053B for ; Tue, 10 Apr 2018 09:23:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FCFC28C16 for ; Tue, 10 Apr 2018 09:23:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33CCA28CF6; Tue, 10 Apr 2018 09:23:42 +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 B3BEC28C16 for ; Tue, 10 Apr 2018 09:23:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 100566E3AA; Tue, 10 Apr 2018 09:23:41 +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 BB0806E3AA for ; Tue, 10 Apr 2018 09:23:39 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id x82so21947634wmg.1 for ; Tue, 10 Apr 2018 02:23:39 -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; bh=y+1aIEVJQDMNnNJB4vqwvLZ95/I99g6wUNHIpBA2et8=; b=G8Qob1B6wrg6vbmOvP7YrQ1tixLEM1rG7HNnFDio+qa+D54/uMHL+Uk/TE4Am+Jfzu iY4KWIySN1BVn1wrwr9ItN1HLHl60cHpiJe4T3qpURYi4JyBMy4P5tc7S5IddbeLik+c dMtLIRFhcMQcAqtqCCv4tl8rb2TnIGpkzXrbkNHZjdORjcC91MZJKMTCm/DU7u0O94Fz HsIvzQxSfiwgOBfFI99/W5Btr7/KQTK+QxtgiZDA6+X2OgkR4ZL0pK30O3Jc2zrtg9aO 6lBSQ0mBptTa7wCHVLEYLeiTAee+pSntLqeJm2jeIB4DhBlISJgDlee14trkxWYh9zqo bjzQ== 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; bh=y+1aIEVJQDMNnNJB4vqwvLZ95/I99g6wUNHIpBA2et8=; b=JenoKfXkepZ8bYnIgJpCFwCrTgHKNF7+R8VEMHLaoq1VTJtVOL09ulmhtBZxIG4TYi lUy217LsbOkLSAfCK7PAtUSWNSnYuDF55lkxibi2wwRB3PwBW9RoV6zGf3EAPEN8lpl6 FpQ0NljTdpGfCtaByMbq3ch9crDrYuTPJTjo8GhfovWmzK5uF+KWjQcQ60EvrLQZvyQ2 W98HOik2/OtniCI54irT5RCilhBeHfkaECqv13R3EhE1SLIyzRip/S2ywtxkLr+XXOQd zfIRL4luFi4iUMaoJuWSbK+JlIAlj9lkOXhqZByoHuEexXl4NyLDRV9WFWuRg9oqMX5b N03g== X-Gm-Message-State: ALQs6tCVObtKr5WJzg2ByihawSH/EChzZ7YDDPrPkPbK5if//4LdtP6+ 1QzT7qvQQjM32lZk5PXL2kAlkpN2 X-Google-Smtp-Source: AIpwx4/4KeV4q7425pahF7QJPQH9M+4B1ErIGw1bOEgrv3abXTOawU5r9WrOjdv0WVnhi1iPmykygA== X-Received: by 10.28.69.86 with SMTP id s83mr967944wma.156.1523352218083; Tue, 10 Apr 2018 02:23:38 -0700 (PDT) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id e27sm4096884wre.86.2018.04.10.02.23.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Apr 2018 02:23:37 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Tue, 10 Apr 2018 10:23:28 +0100 Message-Id: <20180410092328.20645-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 Subject: [Intel-gfx] [PATCH] 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. 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 --- I was able to trigger state != RPM_SUSPENDED on the shards, but not yet the actual estimation overaccounting. As such this fix is based partially on speculation that it will fix the sporadic perf_pmu/rc6* failures. Nevertheless I think it is correct to add this check regardless. --- drivers/gpu/drm/i915/i915_pmu.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c index bd7e695fc663..e92a9571db77 100644 --- a/drivers/gpu/drm/i915/i915_pmu.c +++ b/drivers/gpu/drm/i915/i915_pmu.c @@ -473,6 +473,30 @@ static u64 get_rc6(struct drm_i915_private *i915) spin_lock_irqsave(&i915->pmu.lock, flags); spin_lock(&kdev->power.lock); + /* + * 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) { + spin_unlock(&kdev->power.lock); + + 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_irqrestore(&i915->pmu.lock, flags); + + return val; + } + if (!i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur) i915->pmu.suspended_jiffies_last = kdev->power.suspended_jiffies;