From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F180BC7EE31 for ; Tue, 28 Feb 2023 10:42:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D207310E03C; Tue, 28 Feb 2023 10:42:09 +0000 (UTC) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4CA9410E688 for ; Tue, 28 Feb 2023 10:42:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677580928; x=1709116928; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qOlU9oAqGU2lXLDcj4Db4j4MqpbFsRajed6eGGDb4h4=; b=Ik5eEnfMYMTW7vftL+CjCzcYF8ngEFpQbHNuEHw1B4IEOVZK1XSg43WN OEr8BqY9UCDaWTq9uPmbweCR+VKhkpPfKesMYVnaDqwcY+uvTTqyEywDI Nn/OqWSQWku6/ZWTPtIr4H7lH1PJXMXF8bJMt9uMzIN+zKHT0xyFUtgkT DP2s6HuuxuZ3m/OY6bkWYv9d/8/Usjn+dy/RpFFwSpdGCkCbEMeI3s35L ZLUJwUfsVt9fV1cCXHs8FUctTNvpjkk6XM2zEhj3psAEHv5w1iSqvX2Xa +/1XCojErQVQDI/t4N1cPAF9hqhFCbxtDM7D4q6xFCXnjehxb9wziqFwx Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="398884717" X-IronPort-AV: E=Sophos;i="5.98,221,1673942400"; d="scan'208";a="398884717" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 02:42:07 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="738108973" X-IronPort-AV: E=Sophos;i="5.98,221,1673942400"; d="scan'208";a="738108973" Received: from mistoan-mobl.ger.corp.intel.com (HELO mwauld-desk1.intel.com) ([10.252.9.93]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 02:42:07 -0800 From: Matthew Auld To: intel-xe@lists.freedesktop.org Date: Tue, 28 Feb 2023 10:41:32 +0000 Message-Id: <20230228104137.80965-10-matthew.auld@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230228104137.80965-1-matthew.auld@intel.com> References: <20230228104137.80965-1-matthew.auld@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Intel-xe] [PATCH v2 09/14] drm/xe/buddy: add compatible and intersects hooks X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lucas De Marchi Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" Copy this from i915. We need .compatible for lmem -> lmem transfers, so they don't just get nooped by ttm, if need to move something from mappable to non-mappble or vice versa. The .intersects is needed for eviction, to determine if a victim resource is worth eviction. e.g if we need mappable space there is no point in evicting a resource that has zero mappable pages. Signed-off-by: Matthew Auld Cc: Lucas De Marchi --- drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 62 ++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c index f703e962f499..8dd33ac65499 100644 --- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c @@ -230,9 +230,71 @@ static void xe_ttm_vram_mgr_debug(struct ttm_resource_manager *man, drm_printf(printer, "man size:%llu\n", man->size); } +static bool xe_ttm_vram_mgr_intersects(struct ttm_resource_manager *man, + struct ttm_resource *res, + const struct ttm_place *place, + size_t size) +{ + struct xe_ttm_vram_mgr *mgr = to_xe_ttm_vram_mgr(man); + struct xe_ttm_vram_mgr_resource *vres = + to_xe_ttm_vram_mgr_resource(res); + struct drm_buddy *mm = &mgr->mm; + struct drm_buddy_block *block; + + if (!place->fpfn && !place->lpfn) + return true; + + if (!place->fpfn && place->lpfn == mgr->visible_size >> PAGE_SHIFT) + return vres->used_visible_size > 0; + + list_for_each_entry(block, &vres->blocks, link) { + unsigned long fpfn = + drm_buddy_block_offset(block) >> PAGE_SHIFT; + unsigned long lpfn = fpfn + + (drm_buddy_block_size(mm, block) >> PAGE_SHIFT); + + if (place->fpfn < lpfn && place->lpfn > fpfn) + return true; + } + + return false; +} + +static bool xe_ttm_vram_mgr_compatible(struct ttm_resource_manager *man, + struct ttm_resource *res, + const struct ttm_place *place, + size_t size) +{ + struct xe_ttm_vram_mgr *mgr = to_xe_ttm_vram_mgr(man); + struct xe_ttm_vram_mgr_resource *vres = + to_xe_ttm_vram_mgr_resource(res); + struct drm_buddy *mm = &mgr->mm; + struct drm_buddy_block *block; + + if (!place->fpfn && !place->lpfn) + return true; + + if (!place->fpfn && place->lpfn == mgr->visible_size >> PAGE_SHIFT) + return vres->used_visible_size == size; + + list_for_each_entry(block, &vres->blocks, link) { + unsigned long fpfn = + drm_buddy_block_offset(block) >> PAGE_SHIFT; + unsigned long lpfn = fpfn + + (drm_buddy_block_size(mm, block) >> PAGE_SHIFT); + + if (fpfn < place->fpfn || lpfn > place->lpfn) + return false; + } + + return true; +} + static const struct ttm_resource_manager_func xe_ttm_vram_mgr_func = { .alloc = xe_ttm_vram_mgr_new, .free = xe_ttm_vram_mgr_del, + .intersects = xe_ttm_vram_mgr_intersects, + .compatible = xe_ttm_vram_mgr_compatible, .debug = xe_ttm_vram_mgr_debug }; -- 2.39.2