Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp38802imm; Mon, 4 Jun 2018 12:36:04 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIg0lE0+XZ7tnPbr2bz/9hS/emYE/LsKV1N29H37z7pBimMEczI7nb2h9AT2baCQZDA86AH X-Received: by 2002:a17:902:2bc5:: with SMTP id l63-v6mr22618268plb.299.1528140964924; Mon, 04 Jun 2018 12:36:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528140964; cv=none; d=google.com; s=arc-20160816; b=iZhcOCozKECg7nAdgCkc6m0VThr6ljZgRNFKrzdEKVEr8fmo4I9GZO7dfOSuVEdGth B9w/yKj1SmvEJUNsA8NvgwThJiEGlC0WVITR2k6s/EIP05/4XeoxVsBxUL4cxZrB04zy N+PyHVxXYYGEQjzOW+YsB0lM1tvcayFUZpIbbG1yqNna360+AD3+Q+yKoQwUjwV2P+wB ouz2LbNRZd2/h9VZa4C3NbBvTg1Iwa6s5Tz+Rkr1r4ZZthlT/58kllo6dmoOatD01Vx/ WeMmu3e/zJfKTKmj0ynf92IQClBGe4ot5vIuy+PFYqkJpVam2/VJY9anRXQdXUMSQR4w VJ3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=p9kYGe3KlFmDU/9nRiQnu8blucGneakuqfapo86qHV8=; b=thoILqRmfnakqIP9PdLFf0hf4C0ZA+6qu9b6RpmG383P8dPxTE2acxmqTDIXLDoZE4 MJZFDD65pKjecWBSz4xK0F9/fVrUKKOjzU3xy0Lw83uFo9YFC4ujzb1zxGoKQ+an1zlV t9MrjkHFF4h4PYwwgDFm6O1mT/fjzg3Jasj9QVaxSLXVWN8VwkysQQt2aFnO6c1t6W5T g9QtUONC1TpviJY+5nu6DZY3uXBzUsg0nmoQR1YJSYnEgy6ZsZSpVagrGoedAijOUWzC gdfTqqe3raA3vvet3HYTBZCOv2981ZdP7FwbWD4Kb3pyjHyb34G0SVHmQJ1VBirIaw/a hnhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w16-v6si47286241plq.141.2018.06.04.12.35.50; Mon, 04 Jun 2018 12:36:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751119AbeFDTfP (ORCPT + 99 others); Mon, 4 Jun 2018 15:35:15 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37022 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750868AbeFDTfO (ORCPT ); Mon, 4 Jun 2018 15:35:14 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1959401EF05; Mon, 4 Jun 2018 19:35:13 +0000 (UTC) Received: from malachite.bss.redhat.com (dhcp-10-20-1-11.bss.redhat.com [10.20.1.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5178C2026DEF; Mon, 4 Jun 2018 19:35:13 +0000 (UTC) From: Lyude Paul To: amd-gfx@lists.freedesktop.org Cc: Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , "David (ChunMing) Zhou" , David Airlie , Harry Wentland , Andrey Grodzovsky , Tony Cheng , "Leo (Sunpeng) Li" , Shirish S , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/amdgpu: Grab/put runtime PM references in atomic_commit_tail() Date: Mon, 4 Jun 2018 15:35:03 -0400 Message-Id: <20180604193509.29153-1-lyude@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 04 Jun 2018 19:35:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 04 Jun 2018 19:35:13 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lyude@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org So, unfortunately I recently made the discovery that in the upstream kernel, the only reason that amdgpu is not currently suffering from issues with runtime PM putting the GPU into suspend while it's driving displays is due to the fact that on most prime systems, we have sound devices associated with the GPU that hold their own runtime PM ref for the GPU. What this means however, is that in the event that there isn't any kind of sound device active (which can easily be reproduced by building a kernel with sound drivers disabled), the GPU will fall asleep even when there's displays active. This appears to be in part due to the fact that amdgpu has not actually ever relied on it's rpm_idle() function to be the only thing keeping it running, and normally grabs it's own power references whenever there are displays active (as can be seen with the original pre-DC codepath in amdgpu_display_crtc_set_config() in amdgpu_display.c). This means it's very likely that this bug was introduced during the switch over the DC. So to fix this, we start grabbing runtime PM references every time we enable a previously disabled CRTC in atomic_commit_tail(). This appears to be the correct solution, as it matches up with what i915 does in i915/intel_runtime_pm.c. The one sideaffect of this is that we ignore the variable that the pre-DC code used to use for tracking when it needed runtime PM refs, adev->have_disp_power_ref. This is mainly because there's no way for a driver to tell whether or not all of it's CRTCs are enabled or disabled when we've begun committing an atomic state, as there may be CRTC commits happening in parallel that aren't contained within the atomic state being committed. So, it's safer to just get/put a reference for each CRTC being enabled or disabled in the new atomic state. Signed-off-by: Lyude Paul --- As a note, I'm not entirely happy with this fix and I wouldn't be surprised if I missed something while looking through amdgpu. So, please don't hesistate to suggest a better fix :). drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index 1dd1142246c2..361b81ef6997 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -4211,6 +4212,8 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state) if (dm_old_crtc_state->stream) remove_stream(adev, acrtc, dm_old_crtc_state->stream); + pm_runtime_get_noresume(dev->dev); + acrtc->enabled = true; acrtc->hw_mode = new_crtc_state->mode; crtc->hwmode = new_crtc_state->mode; @@ -4396,6 +4399,16 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state) drm_atomic_helper_wait_for_flip_done(dev, state); drm_atomic_helper_cleanup_planes(dev, state); + + /* Finally, drop a runtime PM reference for each newly disabled CRTC, + * so we can put the GPU into runtime suspend if we're not driving any + * displays anymore + */ + pm_runtime_mark_last_busy(dev->dev); + for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { + if (old_crtc_state->active && !new_crtc_state->active) + pm_runtime_put_autosuspend(dev->dev); + } } -- 2.17.1