Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3321547rwa; Tue, 23 Aug 2022 02:48:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR70UZGVzQp2mxf8ifRTnHpyXRKYz6VsBsNCPvS6TxGfQebSdamfbAJswfENGXbzP5mSMX26 X-Received: by 2002:a17:907:7fa1:b0:73d:8326:cd5 with SMTP id qk33-20020a1709077fa100b0073d83260cd5mr5530326ejc.522.1661248081652; Tue, 23 Aug 2022 02:48:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248081; cv=none; d=google.com; s=arc-20160816; b=VqcNrPHrpgVZgfCZwMeHsLM9oPjxELrF1bSINBMPZXxxx7xx6nYud1T9vOgkoda+LU vfsQrBvpAzzzWCLjMtH0dF3f4D4R8adUyAHszmAMXUzlut29cWM4tznDn55Ozo7oMC1z kvmmPraZrN16kH7QNBx9SHpjlNXiTYwAjerTy0CqigMlMeg10Ark3pXm63/MTGqWcvBb UrvJHfDGPY4q3y3u5JAwG6ObPtVd+FPAVS2PNDB3HXsnaidfTgMUcLvGD2p3yaEa4/RE xg6KgPTGDJRtmLf2NjuaXT2TgR4Fg8ldfIJUgGUOJlNI8vWE2vM2TQo5k+TCewV6vcPJ uFZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Yr8dEC9P4V6JRa9Qic5jOZSJzIcQX4xMMz/WII+LaPo=; b=UlvNJ2eD9UEnCB/11eMpVU/h4hhqdh4MHXq7tf/R9NHWiX0C+7c7P3jirSK+wjQDR5 VFx7UJwLrdiJZ434EU3/hYvTn698isEgXn8IPYSURbblXgt5yWIUamlPs7cC2ttTWPI+ gvhPtQN32S1u9pMeomEE9lkPJEcrHAaxXUzwwSeOTvSvHTRAwHEwnVHdSMuZ/s6mUQez XHZva5A6t3hxP79SqhuIU83UMp0wbRhlFIzCEwUHtIXoYo1HFVr/T6j3PykiOehBiz+t gWT60pAjXw7MGNp1OBrpz84FXV+Jpk8HdhYYlDL0z9za22H+C0RMrtvR2h5p6sqsYM5s TXyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FSlv5v1H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr9-20020a1709073f8900b0073da663ed6bsi536812ejc.218.2022.08.23.02.47.34; Tue, 23 Aug 2022 02:48:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FSlv5v1H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241810AbiHWIJ7 (ORCPT + 99 others); Tue, 23 Aug 2022 04:09:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240355AbiHWIIl (ORCPT ); Tue, 23 Aug 2022 04:08:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 492906CD12; Tue, 23 Aug 2022 01:05:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D7B1D61257; Tue, 23 Aug 2022 08:05:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0940C433C1; Tue, 23 Aug 2022 08:05:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661241933; bh=J/c8kppYkw5huAqLB5dP5Hv59OTcJ+Akjd0/dqhCAU0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FSlv5v1HzYJoiN330X2CtLsdJyjm7gPaFvGK9vXg8vSHKHY0LJEc/wtBpwRBIUU6Q FceAQu69fg0CLJRCmnv7j7w1iicN8vMrAoBYBDgLbatPfIl1wfRUVpp7MoPeEE+0zB Fz0QfVWKPdUsmScT2WTyaZR7ZjqoqIYt1n7qO8bo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Wilson , Fei Yang , Andi Shyti , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Tvrtko Ursulin , Mauro Carvalho Chehab , Rodrigo Vivi Subject: [PATCH 5.19 023/365] drm/i915/gt: Ignore TLB invalidations on idle engines Date: Tue, 23 Aug 2022 09:58:44 +0200 Message-Id: <20220823080119.189674334@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chris Wilson commit db100e28fdf026a1fc10657c5170bb1e65663805 upstream. Check if the device is powered down prior to any engine activity, as, on such cases, all the TLBs were already invalidated, so an explicit TLB invalidation is not needed, thus reducing the performance regression impact due to it. This becomes more significant with GuC, as it can only do so when the connection to the GuC is awake. Cc: stable@vger.kernel.org Fixes: 7938d61591d3 ("drm/i915: Flush TLBs before releasing backing store") Signed-off-by: Chris Wilson Cc: Fei Yang Reviewed-by: Andi Shyti Acked-by: Thomas Hellström Acked-by: Tvrtko Ursulin Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Andi Shyti Link: https://patchwork.freedesktop.org/patch/msgid/278a57a672edac75683f0818b292e95da583a5fe.1658924372.git.mchehab@kernel.org (cherry picked from commit 4bedceaed1ae1172cfe72d3ff752b3a1d32fe4d9) Signed-off-by: Rodrigo Vivi Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 10 ++++++---- drivers/gpu/drm/i915/gt/intel_gt.c | 17 ++++++++++------- drivers/gpu/drm/i915/gt/intel_gt_pm.h | 3 +++ 3 files changed, 19 insertions(+), 11 deletions(-) --- a/drivers/gpu/drm/i915/gem/i915_gem_pages.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_pages.c @@ -6,14 +6,15 @@ #include +#include "gt/intel_gt.h" +#include "gt/intel_gt_pm.h" + #include "i915_drv.h" #include "i915_gem_object.h" #include "i915_scatterlist.h" #include "i915_gem_lmem.h" #include "i915_gem_mman.h" -#include "gt/intel_gt.h" - void __i915_gem_object_set_pages(struct drm_i915_gem_object *obj, struct sg_table *pages, unsigned int sg_page_sizes) @@ -217,10 +218,11 @@ __i915_gem_object_unset_pages(struct drm if (test_and_clear_bit(I915_BO_WAS_BOUND_BIT, &obj->flags)) { struct drm_i915_private *i915 = to_i915(obj->base.dev); + struct intel_gt *gt = to_gt(i915); intel_wakeref_t wakeref; - with_intel_runtime_pm_if_active(&i915->runtime_pm, wakeref) - intel_gt_invalidate_tlbs(to_gt(i915)); + with_intel_gt_pm_if_awake(gt, wakeref) + intel_gt_invalidate_tlbs(gt); } return pages; --- a/drivers/gpu/drm/i915/gt/intel_gt.c +++ b/drivers/gpu/drm/i915/gt/intel_gt.c @@ -11,6 +11,7 @@ #include "i915_drv.h" #include "intel_context.h" +#include "intel_engine_pm.h" #include "intel_engine_regs.h" #include "intel_gt.h" #include "intel_gt_buffer_pool.h" @@ -1181,6 +1182,7 @@ void intel_gt_invalidate_tlbs(struct int struct drm_i915_private *i915 = gt->i915; struct intel_uncore *uncore = gt->uncore; struct intel_engine_cs *engine; + intel_engine_mask_t awake, tmp; enum intel_engine_id id; const i915_reg_t *regs; unsigned int num = 0; @@ -1204,26 +1206,31 @@ void intel_gt_invalidate_tlbs(struct int GEM_TRACE("\n"); - assert_rpm_wakelock_held(&i915->runtime_pm); - mutex_lock(>->tlb_invalidate_lock); intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL); spin_lock_irq(&uncore->lock); /* serialise invalidate with GT reset */ + awake = 0; for_each_engine(engine, gt, id) { struct reg_and_bit rb; + if (!intel_engine_pm_is_awake(engine)) + continue; + rb = get_reg_and_bit(engine, regs == gen8_regs, regs, num); if (!i915_mmio_reg_offset(rb.reg)) continue; intel_uncore_write_fw(uncore, rb.reg, rb.bit); + awake |= engine->mask; } spin_unlock_irq(&uncore->lock); - for_each_engine(engine, gt, id) { + for_each_engine_masked(engine, gt, awake, tmp) { + struct reg_and_bit rb; + /* * HW architecture suggest typical invalidation time at 40us, * with pessimistic cases up to 100us and a recommendation to @@ -1231,12 +1238,8 @@ void intel_gt_invalidate_tlbs(struct int */ const unsigned int timeout_us = 100; const unsigned int timeout_ms = 4; - struct reg_and_bit rb; rb = get_reg_and_bit(engine, regs == gen8_regs, regs, num); - if (!i915_mmio_reg_offset(rb.reg)) - continue; - if (__intel_wait_for_register_fw(uncore, rb.reg, rb.bit, 0, timeout_us, timeout_ms, --- a/drivers/gpu/drm/i915/gt/intel_gt_pm.h +++ b/drivers/gpu/drm/i915/gt/intel_gt_pm.h @@ -55,6 +55,9 @@ static inline void intel_gt_pm_might_put for (tmp = 1, intel_gt_pm_get(gt); tmp; \ intel_gt_pm_put(gt), tmp = 0) +#define with_intel_gt_pm_if_awake(gt, wf) \ + for (wf = intel_gt_pm_get_if_awake(gt); wf; intel_gt_pm_put_async(gt), wf = 0) + static inline int intel_gt_pm_wait_for_idle(struct intel_gt *gt) { return intel_wakeref_wait_for_idle(>->wakeref);