Page Reclamation Support for Xe3p Platforms
Subsystems (2)
v4 cover Page Reclamation Support for Xe3p Platforms
This series introduces a hardware-assisted page reclamation support on Xe3p
platforms, integrating with the KMD's existing TLB invalidation workflow and adding the ability to perform selective Private Physical Cache (PPC) flushing rather than always forcing the default full PPC flush.
Currently as of Xe2, Xe TLB invalidations trigger a full Private Physical Cache flush to guarantee non-coherent memory correctness. New HW (Xe3p and beyond) supports a page reclamation feature, which we selectively enable on platforms with a flag in device info.
The driver can provide a “Page Reclaim List” (PRL), tracking the physical pages used that correspond to an unmap/unbind operation and let hardware perform selective cache line eviction. If reclamation succeeds, we skip the full PPC flush entirely otherwise we fall back to our current process of full PPC flush with the TLB invalidation.
Thanks,
Brian
v2:
- General refactor to remove additional variables from tlb fences (flush_cache and PRL ptr). (Matthew B)
- Removed lock from xe_tlb_inval_reset_timeout and moved into xe_tlb_inval_done_handler. (Matthew B)
- Removed page reclaim variables out of tlb fences (Matthew B)
- Add FW check for page reclaim support. (Shuicheng, Matthew B)
- Moved PRL max entries overflow handling out from generate_reclaim_entry to caller. (Shuicheng)
- Fix one off error with NULL terminated PRL.
- Add xe_page_reclaim_list_init for clarity. (Matthew B)
- Invalidate PRL on early abort page walks.
- Allocate PRL bo size to num_entries. (Matthew B)
- Move PRL bo allocation to tlb_inval run_job. (Matthew B)
- Modify debugfs to expose file only if page reclaim supported by default instead of previous behavior to return an ENODEV and thus no need to move xe_match_desc from configfs (Michal)
- Compacted warning checking, update commit message, spelling, moved variables, etc. (Shuicheng, Matthew B, Michal)
- Remove unused function. (Shuicheng)
- Fix various missing kernel doc input.
v3:
- Removed MEDIA_IS_ON due to racy condition. (Matthew A)
- Move l3 policy access to xe_pat. (Matthew A)
- Add vm_dbg prints for PRL generation and invalidation. (Matthew B)
- Add comments for PRL tile handling and flush behavior with medai. (Matthew B)
- Modify reclaim_entry to QW and adjust bitfields accordingly. (Matthew B)
- Add missing shift of PTE for page address in reclaim entry. (Matthew B)
- Fix NULL pointer dereference check.
- s/ifence/fence for kernel doc.
- Squashed dependent patch.
- Update erroneous comments
v4:
- s/GEN_MASK/GEN_MASK_ULL, s/BIT/BIT_ULL for xe_guc_reclaim_entry (CI)
- Revised comments to current changes (Tejas)
- Moved PAT macros back to original place.
Brian Nguyen (8):
drm/xe/xe_tlb_inval: Modify fence interface to support PPC flush drm/xe/guc: Add page reclamation interface to GuC
drm/xe: Create page reclaim list on unbind
drm/xe: Suballocate BO for page reclaim
drm/xe: Prep page reclaim in tlb inval job
drm/xe: Append page reclamation action to tlb inval drm/xe: Optimize flushing of L2$ by skipping unnecessary page reclaim drm/xe: Add debugfs support for page reclamation
Matthew Brost (1):
drm/xe: Do not forward invalid TLB invalidation seqnos to upper layers
Oak Zeng (1):
drm/xe: Add page reclamation info to device info
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/abi/guc_actions_abi.h | 2 + drivers/gpu/drm/xe/regs/xe_gtt_defs.h | 1 + drivers/gpu/drm/xe/xe_debugfs.c | 41 +++++++ drivers/gpu/drm/xe/xe_device_types.h | 9 ++ drivers/gpu/drm/xe/xe_guc.c | 4 + drivers/gpu/drm/xe/xe_guc_ct.c | 17 +++ drivers/gpu/drm/xe/xe_guc_fwif.h | 1 + drivers/gpu/drm/xe/xe_guc_tlb_inval.c | 37 ++++-- drivers/gpu/drm/xe/xe_page_reclaim.c | 133 ++++++++++++++++++++++ drivers/gpu/drm/xe/xe_page_reclaim.h | 81 ++++++++++++++ drivers/gpu/drm/xe/xe_pat.c | 8 ++ drivers/gpu/drm/xe/xe_pat.h | 10 ++ drivers/gpu/drm/xe/xe_pci.c | 1 + drivers/gpu/drm/xe/xe_pci_types.h | 1 + drivers/gpu/drm/xe/xe_pt.c | 137 ++++++++++++++++++++++- drivers/gpu/drm/xe/xe_pt_types.h | 5 + drivers/gpu/drm/xe/xe_tile.c | 5 + drivers/gpu/drm/xe/xe_tlb_inval.c | 27 ++++- drivers/gpu/drm/xe/xe_tlb_inval.h | 2 +- drivers/gpu/drm/xe/xe_tlb_inval_job.c | 37 +++++- drivers/gpu/drm/xe/xe_tlb_inval_job.h | 4 + drivers/gpu/drm/xe/xe_tlb_inval_types.h | 5 +- drivers/gpu/drm/xe/xe_vm.c | 4 +- 24 files changed, 557 insertions(+), 16 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_page_reclaim.c create mode 100644 drivers/gpu/drm/xe/xe_page_reclaim.h
Signature · 1 line
2.52.0
PATCH v4 1/10 drm/xe: Do not forward invalid TLB invalidation seqnos to upper layers
From: Matthew Brost <[email protected]>
Certain TLB invalidation operations send multiple H2G messages per seqno with only the final H2G containing the valid seqno - the others carry an invalid seqno. The G2H handler drops these invalid seqno to aovid prematurely signaling a TLB invalidation fence.
With TLB_INVALIDATION_SEQNO_INVALID used to indicate in progress multi-step TLB invalidations, reset tdr to ensure that timeout won't prematurely trigger when G2H actions are still ongoing.
v2: Remove lock from xe_tlb_inval_reset_timeout. (Matthew B)
v3: Squash with dependent patch from Matthew Brost' series.
--- drivers/gpu/drm/xe/xe_tlb_inval.c | 20 ++++++++++++++++++++ drivers/gpu/drm/xe/xe_tlb_inval_types.h | 1 + 2 files changed, 21 insertions(+)
drivers/gpu/drm/xe/xe_tlb_inval.c +20 -0
@@ -199,6 +199,20 @@ void xe_tlb_inval_reset(struct xe_tlb_inval *tlb_inval)mutex_unlock (&tlb_inval->seqno_lock); } +/** +* xe_tlb_inval_reset_timeout() - Reset TLB inval fence timeout +* @tlb_inval: TLB invalidation client +* +* Reset the TLB invalidation timeout timer. +*/ +static void xe_tlb_inval_reset_timeout (struct xe_tlb_inval *tlb_inval) +{ +lockdep_assert_held (&tlb_inval->pending_lock); + +mod_delayed_work (system_wq, &tlb_inval->fence_tdr, + tlb_inval->ops->timeout_delay (tlb_inval)); +} +static bool xe_tlb_inval_seqno_past (struct xe_tlb_inval *tlb_inval,int seqno) {int seqno_recv =READ_ONCE (tlb_inval->seqno_recv);
@@ -360,6 +374,12 @@ void xe_tlb_inval_done_handler(struct xe_tlb_inval *tlb_inval, int seqno)* process_g2h_msg(). */ spin_lock_irqsave (&tlb_inval->pending_lock, flags); +if (seqno ==TLB_INVALIDATION_SEQNO_INVALID ) { +xe_tlb_inval_reset_timeout (tlb_inval); +spin_unlock_irqrestore (&tlb_inval->pending_lock, flags); +return ; + } +if (xe_tlb_inval_seqno_past (tlb_inval, seqno)) {spin_unlock_irqrestore (&tlb_inval->pending_lock, flags);return ;
drivers/gpu/drm/xe/xe_tlb_inval_types.h +1 -0
@@ -80,6 +80,7 @@ struct xe_tlb_inval {const struct xe_tlb_inval_ops *ops;/** @tlb_inval.seqno: TLB invalidation seqno, protected by CT lock */ #define TLB_INVALIDATION_SEQNO_MAX 0x100000 +#define TLB_INVALIDATION_SEQNO_INVALID TLB_INVALIDATION_SEQNO_MAXint seqno;/** @tlb_invalidation.seqno_lock: protects @tlb_invalidation.seqno */ struct mutex seqno_lock;
Signature · 1 line
2.52.0
PATCH v4 2/10 drm/xe/xe_tlb_inval: Modify fence interface to support PPC flush
In reply to Brian NguyenAllow tlb_invalidation to control when driver wants to flush the Private Physical Cache (PPC) as a process of the tlb invalidation process.
Default behavior is still to always flush the PPC but driver now has the option to disable it.
v2:
- Revise commit/kernel doc descriptions. (Shuicheng)
- Remove unused function. (Shuicheng)
- Remove bool flush_cache parameter from fence, and various function inputs. (Matthew B)
--- drivers/gpu/drm/xe/xe_guc_tlb_inval.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_guc_tlb_inval.c +6 -3
@@ -34,9 +34,12 @@ static int send_tlb_inval(struct xe_guc *guc, const u32 *action, int len) G2H_LEN_DW_TLB_INVALIDATE, 1); } -#define MAKE_INVAL_OP (type) ((type << XE_GUC_TLB_INVAL_TYPE_SHIFT) | \ +#define MAKE_INVAL_OP_FLUSH (type, flush_cache) ((type << XE_GUC_TLB_INVAL_TYPE_SHIFT) | \ XE_GUC_TLB_INVAL_MODE_HEAVY << XE_GUC_TLB_INVAL_MODE_SHIFT | \ - XE_GUC_TLB_INVAL_FLUSH_CACHE) + (flush_cache ? \ + XE_GUC_TLB_INVAL_FLUSH_CACHE : 0)) + +#define MAKE_INVAL_OP (type) MAKE_INVAL_OP_FLUSH(type, true)static int send_tlb_inval_all (struct xe_tlb_inval *tlb_inval,u32 seqno) {
@@ -152,7 +155,7 @@ static int send_tlb_inval_ppgtt(struct xe_tlb_inval *tlb_inval, u32 seqno, ilog2(SZ_2M) + 1)));xe_gt_assert (gt,IS_ALIGNED (start, length)); - action[len++] =MAKE_INVAL_OP (XE_GUC_TLB_INVAL_PAGE_SELECTIVE ); + action[len++] =MAKE_INVAL_OP_FLUSH (XE_GUC_TLB_INVAL_PAGE_SELECTIVE , true); action[len++] = asid; action[len++] =lower_32_bits (start); action[len++] =upper_32_bits (start);
Signature · 1 line
2.52.0
PATCH v4 3/10 drm/xe: Add page reclamation info to device info
In reply to Brian NguyenFrom: Oak Zeng <[email protected]>
Starting from Xe3p, HW adds a feature assisting range based page reclamation. Introduce a bit in device info to indicate whether device has such capability.
--- drivers/gpu/drm/xe/xe_device_types.h | 2 ++ drivers/gpu/drm/xe/xe_pci.c | 1 + drivers/gpu/drm/xe/xe_pci_types.h | 1 + 3 files changed, 4 insertions(+)
drivers/gpu/drm/xe/xe_device_types.h +2 -0
@@ -315,6 +315,8 @@ struct xe_device { u8 has_mem_copy_instr:1;/** @info.has_mert: Device has standalone MERT */ u8 has_mert:1; +/** @info.has_page_reclaim_hw_assist: Device supports page reclamation feature */ + u8 has_page_reclaim_hw_assist:1;/** @info.has_pxp: Device has PXP support */ u8 has_pxp:1;/** @info.has_range_tlb_inval: Has range based TLB invalidations */
drivers/gpu/drm/xe/xe_pci.c +1 -0
@@ -681,6 +681,7 @@ static int xe_info_init_early(struct xe_device *xe, xe->info.has_late_bind = desc->has_late_bind; xe->info.has_llc = desc->has_llc; xe->info.has_mert = desc->has_mert; + xe->info.has_page_reclaim_hw_assist = desc->has_page_reclaim_hw_assist; xe->info.has_pxp = desc->has_pxp; xe->info.has_sriov =xe_configfs_primary_gt_allowed (to_pci_dev (xe->drm.dev)) && desc->has_sriov;
drivers/gpu/drm/xe/xe_pci_types.h +1 -0
@@ -49,6 +49,7 @@ struct xe_device_desc { u8 has_mbx_power_limits:1; u8 has_mem_copy_instr:1; u8 has_mert:1; + u8 has_page_reclaim_hw_assist:1; u8 has_pxp:1; u8 has_sriov:1; u8 needs_scratch:1;
Signature · 1 line
2.52.0
PATCH v4 4/10 drm/xe/guc: Add page reclamation interface to GuC
In reply to Brian NguyenAdd page reclamation related changes to GuC interface, handlers, and senders to support page reclamation.
Currently TLB invalidations will perform an entire PPC flush in order to prevent stale memory access for noncoherent system memory. Page reclamation is an extension of the typical TLB invalidation workflow, allowing disabling of full PPC flush and enable selective PPC flushing. Selective flushing will be decided by a list of pages whom's address is passed to GuC at time of action.
Page reclamation interfaces require at least GuC FW ver 70.31.0.
v2:
- Moved send_page_reclaim to first patch usage.
- Add comments explaining shared done handler. (Matthew B)
- Add FW version fallback to disable page reclaim on older versions. (Matthew B, Shuicheng)
--- drivers/gpu/drm/xe/abi/guc_actions_abi.h | 2 ++ drivers/gpu/drm/xe/xe_guc.c | 4 ++++ drivers/gpu/drm/xe/xe_guc_ct.c | 17 +++++++++++++++++ drivers/gpu/drm/xe/xe_guc_fwif.h | 1 + 4 files changed, 24 insertions(+)
drivers/gpu/drm/xe/abi/guc_actions_abi.h +2 -0
@@ -151,6 +151,8 @@ enum xe_guc_action {XE_GUC_ACTION_TLB_INVALIDATION =0x7000 ,XE_GUC_ACTION_TLB_INVALIDATION_DONE =0x7001 ,XE_GUC_ACTION_TLB_INVALIDATION_ALL =0x7002 , +XE_GUC_ACTION_PAGE_RECLAMATION =0x7003 , +XE_GUC_ACTION_PAGE_RECLAMATION_DONE =0x7004 ,XE_GUC_ACTION_STATE_CAPTURE_NOTIFICATION =0x8002 ,XE_GUC_ACTION_NOTIFY_FLUSH_LOG_BUFFER_TO_FILE =0x8003 , XE_GUC_ACTION_NOTIFY_CRASH_DUMP_POSTED = 0x8004,
drivers/gpu/drm/xe/xe_guc.c +4 -0
@@ -767,6 +767,10 @@ int xe_guc_init(struct xe_guc *guc)if (!xe_uc_fw_is_enabled (&guc->fw))return 0 ; +/* Disable page reclaim if GuC FW does not support */ +if (GUC_FIRMWARE_VER (guc) <MAKE_GUC_VER (70 ,31 ,0 )) + xe->info.has_page_reclaim_hw_assist = false; +if (IS_SRIOV_VF (xe)) { ret =xe_guc_ct_init (&guc->ct);if (ret)
drivers/gpu/drm/xe/xe_guc_ct.c +17 -0
@@ -1405,6 +1405,7 @@ static int parse_g2h_event(struct xe_guc_ct *ct, u32 *msg, u32 len)case XE_GUC_ACTION_DEREGISTER_CONTEXT_DONE :case XE_GUC_ACTION_SCHED_ENGINE_MODE_DONE :case XE_GUC_ACTION_TLB_INVALIDATION_DONE : +case XE_GUC_ACTION_PAGE_RECLAMATION_DONE :g2h_release_space (ct, len); }
@@ -1591,6 +1592,15 @@ static int process_g2h_msg(struct xe_guc_ct *ct, u32 *msg, u32 len) ret =xe_guc_pagefault_handler (guc, payload, adj_len);break ;case XE_GUC_ACTION_TLB_INVALIDATION_DONE : +case XE_GUC_ACTION_PAGE_RECLAMATION_DONE : +/* +* Page reclamation is an extension of TLB invalidation. Both +* operations share the same seqno and fence. When either +* action completes, we need to signal the corresponding +* fence. Since the handling logic (lookup fence by seqno, +* fence signalling) is identical, we use the same handler +* for both G2H events. +*/ ret =xe_guc_tlb_inval_done_handler (guc, payload, adj_len);break ;case XE_GUC_ACTION_GUC2PF_RELAY_FROM_VF :
@@ -1756,6 +1766,7 @@ static int g2h_read(struct xe_guc_ct *ct, u32 *msg, bool fast_path)switch (action) {case XE_GUC_ACTION_REPORT_PAGE_FAULT_REQ_DESC :case XE_GUC_ACTION_TLB_INVALIDATION_DONE : +case XE_GUC_ACTION_PAGE_RECLAMATION_DONE :break ;/* Process these in fast-path */ default :return 0 ;
@@ -1792,6 +1803,12 @@ static void g2h_fast_path(struct xe_guc_ct *ct, u32 *msg, u32 len) ret =xe_guc_pagefault_handler (guc, payload, adj_len);break ;case XE_GUC_ACTION_TLB_INVALIDATION_DONE : +case XE_GUC_ACTION_PAGE_RECLAMATION_DONE : +/* +* Seqno and fence handling of page reclamation and TLB +* invalidation is identical, so we can use the same handler +* for both actions. +*/ __g2h_release_space (ct, len); ret =xe_guc_tlb_inval_done_handler (guc, payload, adj_len);break ;
drivers/gpu/drm/xe/xe_guc_fwif.h +1 -0
@@ -16,6 +16,7 @@#define G2H_LEN_DW_DEREGISTER_CONTEXT 3#define G2H_LEN_DW_TLB_INVALIDATE 3#define G2H_LEN_DW_G2G_NOTIFY_MIN 3 +#define G2H_LEN_DW_PAGE_RECLAMATION 3#define GUC_ID_MAX 65535#define GUC_ID_UNKNOWN 0xffffffff
Signature · 1 line
2.52.0
PATCH v4 5/10 drm/xe: Create page reclaim list on unbind
In reply to Brian NguyenPage reclaim list (PRL) is preparation work for the page reclaim feature. The PRL is firstly owned by pt_update_ops and all other page reclaim operations will point back to this PRL. PRL generates its entries during the unbind page walker, updating the PRL.
This PRL is restricted to a 4K page, so 512 page entries at most.
v2:
- Removed unused function. (Shuicheng)
- Compacted warning checking, update commit message, spelling, etc. (Shuicheng, Matthew B)
- Fix kernel docs
- Moved PRL max entries overflow handling out from generate_reclaim_entry to caller (Shuicheng)
- Add xe_page_reclaim_list_init for clarity. (Matthew B)
- Modify xe_guc_page_reclaim_entry to use macros
for greater flexbility. (Matthew B)
- Add fallback for PTE outside of page reclaim supported 4K, 64K, 2M pages (Matthew B)
- Invalidate PRL for early abort page walk.
- Removed page reclaim related variables from tlb fence (Matthew Brost)
- Remove error handling in *alloc_entries failure. (Matthew B)
v3:
- Fix NULL pointer dereference check.
- Modify reclaim_entry to QW and bitfields accordingly. (Matthew B)
- Add vm_dbg prints for PRL generation and invalidation. (Matthew B)
v4:
- s/GENMASK/GENMASK_ULL && s/BIT/BIT_ULL (CI)
--- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/regs/xe_gtt_defs.h | 1 + drivers/gpu/drm/xe/xe_page_reclaim.c | 62 +++++++++++++ drivers/gpu/drm/xe/xe_page_reclaim.h | 72 +++++++++++++++ drivers/gpu/drm/xe/xe_pt.c | 123 +++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_pt_types.h | 5 ++ 6 files changed, 263 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/xe/xe_page_reclaim.c create mode 100644 drivers/gpu/drm/xe/xe_page_reclaim.h
drivers/gpu/drm/xe/Makefile +1 -0
@@ -95,6 +95,7 @@ xe-y += xe_bb.o \ xe_oa.o \ xe_observation.o \ xe_pagefault.o \ + xe_page_reclaim.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \
drivers/gpu/drm/xe/regs/xe_gtt_defs.h +1 -0
@@ -9,6 +9,7 @@#define XELPG_GGTT_PTE_PAT0 BIT_ULL(52)#define XELPG_GGTT_PTE_PAT1 BIT_ULL(53) +#define XE_PTE_ADDR_MASK GENMASK_ULL(51, 12)#define GGTT_PTE_VFID GENMASK_ULL(11, 2)#define GUC_GGTT_TOP 0xFEE00000
drivers/gpu/drm/xe/xe_page_reclaim.c new file +62 -0
62 lines not on this page · raw message
drivers/gpu/drm/xe/xe_page_reclaim.h new file +72 -0
72 lines not on this page · raw message
drivers/gpu/drm/xe/xe_pt.c +122 -1
199 lines not on this page · raw message
drivers/gpu/drm/xe/xe_pt_types.h +5 -0
@@ -8,6 +8,7 @@#include <linux/types.h> +#include "xe_page_reclaim.h" #include "xe_pt_walk.h" struct xe_bo ;
@@ -79,6 +80,8 @@ struct xe_vm_pgtable_update_op {struct xe_vm_pgtable_update entries[XE_VM_MAX_LEVEL *2 +1 ];/** @vma: VMA for operation, operation not valid if NULL */ struct xe_vma *vma; +/** @prl: Backing pointer to page reclaim list of pt_update_ops */ +struct xe_page_reclaim_list *prl;/** @num_entries: number of entries for this update operation */ u32 num_entries;/** @bind: is a bind */
@@ -95,6 +98,8 @@ struct xe_vm_pgtable_update_ops {struct llist_head deferred;/** @q: exec queue for PT operations */ struct xe_exec_queue *q; +/** @prl: embedded page reclaim list */ +struct xe_page_reclaim_list prl;/** @start: start address of ops */ u64 start;/** @last: last address of ops */
Signature · 1 line
2.52.0
PATCH v4 6/10 drm/xe: Suballocate BO for page reclaim
In reply to Brian NguyenPage reclamation feature needs the PRL to be suballocated into a GGTT-mapped BO. On allocation failure, fallback to default tlb invalidation with full PPC flush.
PRL's BO allocation is managed in separate pool to ensure 4K alignment for proper GGTT address.
With BO, pass into TLB invalidation backend and modify fence to accomadate accordingly.
v2:
- Removed page reclaim related variables from TLB fence. (Matthew B)
- Allocate PRL bo size to num_entries. (Matthew B)
- Move PRL bo allocation to tlb_inval run_job. (Matthew B)
--- drivers/gpu/drm/xe/xe_device_types.h | 7 +++++ drivers/gpu/drm/xe/xe_page_reclaim.c | 39 +++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_page_reclaim.h | 6 +++++ drivers/gpu/drm/xe/xe_tile.c | 5 ++++ drivers/gpu/drm/xe/xe_tlb_inval_job.c | 9 +++++++ 5 files changed, 66 insertions(+)
drivers/gpu/drm/xe/xe_device_types.h +7 -0
@@ -184,6 +184,13 @@ struct xe_tile {* Media GT shares a pool with its primary GT. */ struct xe_sa_manager *kernel_bb_pool; + +/** +* @mem.reclaim_pool: Pool for PRLs allocated. +* +* Only main GT has page reclaim list allocations. +*/ +struct xe_sa_manager *reclaim_pool; } mem;/** @sriov: tile level virtualization data */
drivers/gpu/drm/xe/xe_page_reclaim.c +39 -0
@@ -13,6 +13,45 @@#include "regs/xe_gt_regs.h" #include "xe_assert.h" #include "xe_macros.h" +#include "xe_sa.h" +#include "xe_tlb_inval_types.h" + +/** +* xe_page_reclaim_create_prl_bo() - Back a PRL with a suballocated GGTT BO +* @tlb_inval: TLB invalidation frontend associated with the request +* @prl: page reclaim list data that bo will copy from +* @fence: tlb invalidation fence that page reclaim action is paired to +* +* Suballocates a 4K BO out of the tile reclaim pool, copies the PRL CPU +* copy into the BO and queues the buffer for release when @fence signals. +* +* Return: struct drm_suballoc pointer on success or ERR_PTR on failure. +*/ +struct drm_suballoc *xe_page_reclaim_create_prl_bo (struct xe_tlb_inval *tlb_inval, +struct xe_page_reclaim_list *prl, +struct xe_tlb_inval_fence *fence) +{ + struct xe_gt *gt = container_of(tlb_inval, struct xe_gt, tlb_inval); +struct xe_tile *tile =gt_to_tile (gt); +/* (+1) for NULL page_reclaim_entry to indicate end of list */ +int prl_size =min (prl->num_entries +1 ,XE_PAGE_RECLAIM_MAX_ENTRIES ) * +sizeof (struct xe_guc_page_reclaim_entry ); +struct drm_suballoc *prl_sa; + +/* Maximum size of PRL is 1 4K-page */ + prl_sa =__xe_sa_bo_new (tile->mem.reclaim_pool, + prl_size,GFP_ATOMIC ); +if (IS_ERR (prl_sa)) +return prl_sa; + +memcpy (xe_sa_bo_cpu_addr (prl_sa), prl->entries, + prl_size); +xe_sa_bo_flush_write (prl_sa); +/* Queue up sa_bo_free on tlb invalidation fence signal */ +xe_sa_bo_free (prl_sa, &fence->base); + +return prl_sa; +}/** * xe_page_reclaim_list_invalidate() - Mark a PRL as invalid
drivers/gpu/drm/xe/xe_page_reclaim.h +6 -0
@@ -16,6 +16,9 @@#define XE_PAGE_RECLAIM_MAX_ENTRIES 512#define XE_PAGE_RECLAIM_LIST_MAX_SIZE SZ_4K +struct xe_tlb_inval ; +struct xe_tlb_inval_fence ; +struct xe_guc_page_reclaim_entry {u64 qw;/* valid reclaim entry bit */
@@ -41,6 +44,9 @@ struct xe_page_reclaim_list {#define XE_PAGE_RECLAIM_INVALID_LIST -1 }; +struct drm_suballoc *xe_page_reclaim_create_prl_bo (struct xe_tlb_inval *tlb_inval, +struct xe_page_reclaim_list *prl, +struct xe_tlb_inval_fence *fence);void xe_page_reclaim_list_invalidate (struct xe_page_reclaim_list *prl);void xe_page_reclaim_list_init (struct xe_page_reclaim_list *prl);int xe_page_reclaim_list_alloc_entries (struct xe_page_reclaim_list *prl);
drivers/gpu/drm/xe/xe_tile.c +5 -0
@@ -209,6 +209,11 @@ int xe_tile_init(struct xe_tile *tile)if (IS_ERR (tile->mem.kernel_bb_pool))return PTR_ERR (tile->mem.kernel_bb_pool); +/* Optimistically anticipate at most 256 TLB fences with PRL */ + tile->mem.reclaim_pool =xe_sa_bo_manager_init (tile,SZ_1M ,XE_PAGE_RECLAIM_LIST_MAX_SIZE ); +if (IS_ERR (tile->mem.reclaim_pool)) +return PTR_ERR (tile->mem.reclaim_pool); +return 0 ; }void xe_tile_migrate_wait (struct xe_tile *tile)
drivers/gpu/drm/xe/xe_tlb_inval_job.c +9 -0
@@ -24,6 +24,8 @@ struct xe_tlb_inval_job {struct xe_exec_queue *q;/** @vm: VM which TLB invalidation is being issued for */ struct xe_vm *vm; +/** @prl: Embedded copy of page reclaim list */ +struct xe_page_reclaim_list prl;/** @refcount: ref count of this job */ struct kref refcount;/**
@@ -47,6 +49,13 @@ static struct dma_fence *xe_tlb_inval_job_run(struct xe_dep_job *dep_job)container_of (dep_job,typeof (*job), dep);struct xe_tlb_inval_fence *ifence =container_of (job->fence,typeof (*ifence), base); +struct drm_suballoc *prl_sa =NULL ; + +if (job->prl.entries) { + prl_sa =xe_page_reclaim_create_prl_bo (job->tlb_inval, &job->prl, ifence); +if (IS_ERR (prl_sa)) + prl_sa =NULL ;/* Indicate fall back PPC flush with NULL */ + }xe_tlb_inval_range (job->tlb_inval, ifence, job->start, job->end, job->vm->usm.asid);
Signature · 1 line
2.52.0
PATCH v4 7/10 drm/xe: Prep page reclaim in tlb inval job
In reply to Brian NguyenUse page reclaim list as indicator if page reclaim action is desired and pass it to tlb inval fence to handle.
Job will need to maintain its own embedded copy to ensure lifetime of PRL exist until job has run.
v2:
- Use xe variant of WARN_ON (Michal)
v3:
- Add comments for PRL tile handling and flush behavior with media. (Matthew Brost)
--- drivers/gpu/drm/xe/xe_pt.c | 12 ++++++++++++ drivers/gpu/drm/xe/xe_tlb_inval_job.c | 26 ++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_tlb_inval_job.h | 4 ++++ 3 files changed, 42 insertions(+)
drivers/gpu/drm/xe/xe_pt.c +12 -0
@@ -2509,6 +2509,18 @@ xe_pt_update_ops_run(struct xe_tile *tile, struct xe_vma_ops *vops) goto kill_vm_tile1; } update.ijob = ijob; +/* +* Only add page reclaim for the primary GT. Media GT does not have +* any PPC to flush, so enabling the PPC flush bit for media is +* effectively a NOP and provides no performance benefit nor +* interfere with primary GT. +*/ +if (pt_update_ops->prl.num_entries !=XE_PAGE_RECLAIM_INVALID_LIST ) { +xe_tlb_inval_job_add_page_reclaim (ijob, &pt_update_ops->prl); +/* Release ref from alloc, job will now handle it */ +xe_page_reclaim_entries_put (pt_update_ops->prl.entries); + pt_update_ops->prl.entries =NULL ; + }if (tile->media_gt) { dep_scheduler =to_dep_scheduler (q, tile->media_gt);
drivers/gpu/drm/xe/xe_tlb_inval_job.c +26 -0
@@ -7,7 +7,9 @@#include "xe_dep_job_types.h" #include "xe_dep_scheduler.h" #include "xe_exec_queue.h" +#include "xe_gt_printk.h" #include "xe_gt_types.h" +#include "xe_page_reclaim.h" #include "xe_tlb_inval.h" #include "xe_tlb_inval_job.h" #include "xe_migrate.h"
@@ -116,6 +118,7 @@ xe_tlb_inval_job_create(struct xe_exec_queue *q, struct xe_tlb_inval *tlb_inval, job->start = start; job->end = end; job->fence_armed = false; +xe_page_reclaim_list_init (&job->prl); job->dep.ops = &dep_job_ops; job->type = type;kref_init (&job->refcount);
@@ -149,6 +152,25 @@ xe_tlb_inval_job_create(struct xe_exec_queue *q, struct xe_tlb_inval *tlb_inval,return ERR_PTR (err); } +/** +* xe_tlb_inval_job_add_page_reclaim() - Embed PRL into a TLB job +* @job: TLB invalidation job that may trigger reclamation +* @prl: Page reclaim list populated during unbind +* +* Copies @prl into the job and takes an extra reference to the entry page so +* ownership can transfer to the TLB fence when the job is pushed. +*/ +void xe_tlb_inval_job_add_page_reclaim (struct xe_tlb_inval_job *job, +struct xe_page_reclaim_list *prl) +{ +struct xe_device *xe =gt_to_xe (job->q->gt); + +xe_gt_WARN_ON (job->q->gt, !xe->info.has_page_reclaim_hw_assist); + job->prl = *prl; +/* Pair with put in job_destroy */ +xe_page_reclaim_entries_get (job->prl.entries); +} +static void xe_tlb_inval_job_destroy (struct kref *ref) { struct xe_tlb_inval_job *job = container_of(ref, typeof(*job),
@@ -159,6 +181,10 @@ static void xe_tlb_inval_job_destroy(struct kref *ref)struct xe_device *xe =gt_to_xe (q->gt);struct xe_vm *vm = job->vm; +/* BO creation retains a copy (if used), so no longer needed */ +if (job->prl.entries) +xe_page_reclaim_entries_put (job->prl.entries); +if (!job->fence_armed)kfree (ifence);else
drivers/gpu/drm/xe/xe_tlb_inval_job.h +4 -0
@@ -12,6 +12,7 @@ struct dma_fence;struct xe_dep_scheduler ;struct xe_exec_queue ;struct xe_migrate ; +struct xe_page_reclaim_list ;struct xe_tlb_inval ;struct xe_tlb_inval_job ;struct xe_vm ;
@@ -21,6 +22,9 @@ xe_tlb_inval_job_create(struct xe_exec_queue *q, struct xe_tlb_inval *tlb_inval,struct xe_dep_scheduler *dep_scheduler, struct xe_vm *vm, u64 start, u64 end, int type); +void xe_tlb_inval_job_add_page_reclaim (struct xe_tlb_inval_job *job, +struct xe_page_reclaim_list *prl); +int xe_tlb_inval_job_alloc_dep (struct xe_tlb_inval_job *job); struct dma_fence *xe_tlb_inval_job_push(struct xe_tlb_inval_job *job,
Signature · 1 line
2.52.0
Matthew Brost
maintainerRe: [PATCH v4 07/10] drm/xe: Prep page reclaim in tlb inval job
Quoted 26 lines · Brian Nguyen
Use page reclaim list as indicator if page reclaim action is desired and pass it to tlb inval fence to handle.
Job will need to maintain its own embedded copy to ensure lifetime of PRL exist until job has run.
v2:
- Use xe variant ofWARN_ON(Michal)v3:
- Add comments for PRL tile handling and flush behavior with media. (Matthew Brost)Signed-off-by Brian Nguyen <[email protected]>Cc Michal Wajdeczko <[email protected]>--- drivers/gpu/drm/xe/xe_pt.c | 12 ++++++++++++ drivers/gpu/drm/xe/xe_tlb_inval_job.c | 26 ++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_tlb_inval_job.h | 4 ++++ 3 files changed, 42 insertions(+)drivers/gpu/drm/xe/xe_pt.c +0
-0
drivers/gpu/drm/xe/xe_pt.c xe_pt_update_ops_run(struct xe_tile *tile, struct xe_vma_ops *vops) · line 2518
Quoted 10 lines
drivers/gpu/drm/xe/xe_pt.c +7
-0@@ -2509,6 +2509,18 @@ xe_pt_update_ops_run(struct xe_tile *tile, struct xe_vma_ops *vops) goto kill_vm_tile1; } update.ijob = ijob; +/* +* Only add page reclaim for the primary GT. Media GT does not have +* any PPC to flush, so enabling the PPC flush bit for media is +* effectively a NOP and provides no performance benefit nor +* interfere with primary GT. +*/ +if (pt_update_ops->prl.num_entries !=XE_PAGE_RECLAIM_INVALID_LIST ) {
I hate to be that guy, but would a helper like this be good thoughout the series:
static inline bool xe_page_reclaim_list_valid(struct xe_page_reclaim_list *prl)
{
return prl->prl.num_entries != XE_PAGE_RECLAIM_INVALID_LIST;
}Quoted 57 lines
drivers/gpu/drm/xe/xe_pt.c +5
-0+xe_tlb_inval_job_add_page_reclaim (ijob, &pt_update_ops->prl); +/* Release ref from alloc, job will now handle it */ +xe_page_reclaim_entries_put (pt_update_ops->prl.entries); + pt_update_ops->prl.entries =NULL ; + }if (tile->media_gt) { dep_scheduler =to_dep_scheduler (q, tile->media_gt);drivers/gpu/drm/xe/xe_tlb_inval_job.c +22
-0@@ -7,7 +7,9 @@#include "xe_dep_job_types.h" #include "xe_dep_scheduler.h" #include "xe_exec_queue.h" +#include "xe_gt_printk.h" #include "xe_gt_types.h" +#include "xe_page_reclaim.h" #include "xe_tlb_inval.h" #include "xe_tlb_inval_job.h" #include "xe_migrate.h" @@ -116,6 +118,7 @@ xe_tlb_inval_job_create(struct xe_exec_queue *q, struct xe_tlb_inval *tlb_inval, job->start = start; job->end = end; job->fence_armed = false; +xe_page_reclaim_list_init (&job->prl); job->dep.ops = &dep_job_ops; job->type = type;kref_init (&job->refcount);@@ -149,6 +152,25 @@ xe_tlb_inval_job_create(struct xe_exec_queue *q, struct xe_tlb_inval *tlb_inval,return ERR_PTR (err); } +/** +* xe_tlb_inval_job_add_page_reclaim() - Embed PRL into a TLB job +* @job: TLB invalidation job that may trigger reclamation +* @prl: Page reclaim list populated during unbind +* +* Copies @prl into the job and takes an extra reference to the entry page so +* ownership can transfer to the TLB fence when the job is pushed. +*/ +void xe_tlb_inval_job_add_page_reclaim (struct xe_tlb_inval_job *job, +struct xe_page_reclaim_list *prl) +{ +struct xe_device *xe =gt_to_xe (job->q->gt); + +xe_gt_WARN_ON (job->q->gt, !xe->info.has_page_reclaim_hw_assist); + job->prl = *prl; +/* Pair with put in job_destroy */ +xe_page_reclaim_entries_get (job->prl.entries); +} +static void xe_tlb_inval_job_destroy (struct kref *ref) { struct xe_tlb_inval_job *job = container_of(ref, typeof(*job),
drivers/gpu/drm/xe/xe_tlb_inval_job.c static void xe_tlb_inval_job_destroy(struct kref *ref) · line 186
Quoted 6 lines
drivers/gpu/drm/xe/xe_tlb_inval_job.c +3
-0@@ -159,6 +181,10 @@ static void xe_tlb_inval_job_destroy(struct kref *ref)struct xe_device *xe =gt_to_xe (q->gt);struct xe_vm *vm = job->vm; +/* BO creation retains a copy (if used), so no longer needed */ +if (job->prl.entries) +xe_page_reclaim_entries_put (job->prl.entries);
Nit: xe_page_reclaim_entries_put has a NULL check.
Matt
Quoted 29 lines
drivers/gpu/drm/xe/xe_tlb_inval_job.c +1
-0+if (!job->fence_armed)kfree (ifence);else drivers/gpu/drm/xe/xe_tlb_inval_job.h +4
-0@@ -12,6 +12,7 @@ struct dma_fence;struct xe_dep_scheduler ;struct xe_exec_queue ;struct xe_migrate ; +struct xe_page_reclaim_list ;struct xe_tlb_inval ;struct xe_tlb_inval_job ;struct xe_vm ;@@ -21,6 +22,9 @@ xe_tlb_inval_job_create(struct xe_exec_queue *q, struct xe_tlb_inval *tlb_inval,struct xe_dep_scheduler *dep_scheduler, struct xe_vm *vm, u64 start, u64 end, int type); +void xe_tlb_inval_job_add_page_reclaim (struct xe_tlb_inval_job *job, +struct xe_page_reclaim_list *prl); +int xe_tlb_inval_job_alloc_dep (struct xe_tlb_inval_job *job); struct dma_fence *xe_tlb_inval_job_push(struct xe_tlb_inval_job *job,Signature · 1 line
2.52.0
RE: [PATCH v4 07/10] drm/xe: Prep page reclaim in tlb inval job
Quoted 41 lines · Matthew Brost
Quoted 27 lines · Brian Nguyen
Use page reclaim list as indicator if page reclaim action is desired and pass it to tlb inval fence to handle.
Job will need to maintain its own embedded copy to ensure lifetime of PRL exist until job has run.
v2:
- Use xe variant ofWARN_ON(Michal)v3:
- Add comments for PRL tile handling and flush behavior with media. (Matthew Brost)Signed-off-by Brian Nguyen <[email protected]>Cc Michal Wajdeczko <[email protected]>--- drivers/gpu/drm/xe/xe_pt.c | 12 ++++++++++++ drivers/gpu/drm/xe/xe_tlb_inval_job.c | 26 ++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_tlb_inval_job.h | 4 ++++ 3 files changed, 42 insertions(+)drivers/gpu/drm/xe/xe_pt.c +0
-0@@ -2509,6 +2509,18 @@ xe_pt_update_ops_run(struct xe_tile *tile, struct xe_vma_ops *vops) goto kill_vm_tile1;drivers/gpu/drm/xe/xe_pt.c xe_pt_update_ops_run(struct xe_tile *tile, struct xe_vma_ops *vops) · line 2519
Quoted 10 lines
drivers/gpu/drm/xe/xe_pt.c +8
-0} update.ijob = ijob; +/* +* Only add page reclaim for the primary GT. Media GT does not have +* any PPC to flush, so enabling the PPC flush bit for media is +* effectively a NOP and provides no performance benefit nor +* interfere with primary GT. +*/ +if (pt_update_ops->prl.num_entries !=XE_PAGE_RECLAIM_INVALID_LIST ) +{I hate to be that guy, but would a helper like this be good thoughout the series:
Quoted 3 lines
static inline bool xe_page_reclaim_list_valid(struct xe_page_reclaim_list *prl) {
return prl->prl.num_entries != XE_PAGE_RECLAIM_INVALID_LIST; }NP, makes sense. Adding it mainly to the "Create page reclaim list (Patch 5)" definition and modifying throughout the patches accordingly. Alongside this, I realize that we should cleanup the other usage of XE_PAGE_RECLAIM_INVALID_LIST with xe_page_reclaim_list_invalidate helper to just clear the entries as well to make things clearer. Will be adding that too in the next revision.
Looks like only minor changes 1 to 2 line change in other previously reviewed patches but most changes will be in patch #5.
Quoted 60 lines
Quoted 60 lines
drivers/gpu/drm/xe/xe_pt.c +5
-0+xe_tlb_inval_job_add_page_reclaim (ijob, &pt_update_ops->prl); +/* Release ref from alloc, job will now handle it */ +xe_page_reclaim_entries_put (pt_update_ops->prl.entries); + pt_update_ops->prl.entries =NULL ; + }if (tile->media_gt) { dep_scheduler = to_dep_scheduler(q, tile->media_gt); diff --git
a/drivers/gpu/drm/xe/xe_tlb_inval_job.cb/drivers/gpu/drm/xe/xe_tlb_inval_job.c
indexdbd3171fff12..40e689063a57100644drivers/gpu/drm/xe/xe_tlb_inval_job.c +22
-1@@ -7,7 +7,9 @@#include "xe_dep_job_types.h" #include "xe_dep_scheduler.h" #include "xe_exec_queue.h" +#include "xe_gt_printk.h" #include "xe_gt_types.h" +#include "xe_page_reclaim.h" #include "xe_tlb_inval.h" #include "xe_tlb_inval_job.h" #include "xe_migrate.h" @@ -116,6 +118,7 @@ xe_tlb_inval_job_create(struct xe_exec_queue *q, struct xe_tlb_inval *tlb_inval, job->start = start; job->end = end; job->fence_armed = false; +xe_page_reclaim_list_init (&job->prl); job->dep.ops = &dep_job_ops; job->type = type;kref_init (&job->refcount);@@ -149,6 +152,25 @@ xe_tlb_inval_job_create(struct xe_exec_queue *q, struct xe_tlb_inval *tlb_inval,return ERR_PTR (err); } +/** +* xe_tlb_inval_job_add_page_reclaim() - Embed PRL into a TLB job +* @job: TLB invalidation job that may trigger reclamation +* @prl: Page reclaim list populated during unbind +* +* Copies @prl into the job and takes an extra reference to the entry +page so +* ownership can transfer to the TLB fence when the job is pushed. +*/ +void xe_tlb_inval_job_add_page_reclaim (struct xe_tlb_inval_job *job, +struct xe_page_reclaim_list *prl) { +struct xe_device *xe =gt_to_xe (job->q->gt); + +xe_gt_WARN_ON (job->q->gt, !xe->info.has_page_reclaim_hw_assist); + job->prl = *prl; +/* Pair with put in job_destroy */ +xe_page_reclaim_entries_get (job->prl.entries); +} +static void xe_tlb_inval_job_destroy (struct kref *ref) { struct xe_tlb_inval_job *job = container_of(ref, typeof(*job), @@ -159,6 +181,10 @@ static void xe_tlb_inval_job_destroy(struct kref *ref) struct xe_device *xe = gt_to_xe(q->gt);struct xe_vm *vm = job->vm;
Quoted 6 lines
drivers/gpu/drm/xe/xe_tlb_inval_job.c static void xe_tlb_inval_job_destroy(struct kref *ref) · line 186
Quoted 3 lines
drivers/gpu/drm/xe/xe_tlb_inval_job.c +3
-0+/* BO creation retains a copy (if used), so no longer needed */ +if (job->prl.entries) +xe_page_reclaim_entries_put (job->prl.entries);Nit:
xe_page_reclaim_entries_puthas a NULL check.
Ahh yea, missed that, removing the check.
Brian
Quoted 32 lines
Matt
Quoted 30 lines
drivers/gpu/drm/xe/xe_tlb_inval_job.c +1
-0+if (!job->fence_armed)kfree (ifence);else drivers/gpu/drm/xe/xe_tlb_inval_job.h +4
-1@@ -12,6 +12,7 @@ struct dma_fence;struct xe_dep_scheduler ;struct xe_exec_queue ;struct xe_migrate ; +struct xe_page_reclaim_list ;struct xe_tlb_inval ;struct xe_tlb_inval_job ;struct xe_vm ;@@ -21,6 +22,9 @@ xe_tlb_inval_job_create(struct xe_exec_queue *q, struct xe_tlb_inval *tlb_inval,struct xe_dep_scheduler *dep_scheduler, struct xe_vm *vm, u64 start, u64 end, int type); +void xe_tlb_inval_job_add_page_reclaim (struct xe_tlb_inval_job *job, +struct xe_page_reclaim_list *prl); +int xe_tlb_inval_job_alloc_dep (struct xe_tlb_inval_job *job); struct dma_fence *xe_tlb_inval_job_push(struct xe_tlb_inval_job *job, --2.52.0
PATCH v4 8/10 drm/xe: Append page reclamation action to tlb inval
In reply to Brian NguyenAdd page reclamation action to tlb inval backend. The page reclamation action is paired with range tlb invalidations so both are issued at the same time.
Page reclamation will issue the TLB invalidation with an invalid seqno and a H2G page reclamation action with the fence's corresponding seqno and handle the fence accordingly on page reclaim action done handler.
If page reclamation fails, tlb timeout handler will be responsible for signalling fence and cleaning up.
v2:
- add send_page_reclaim to patch.
- Remove flush_cache and use prl_sa pointer to determine PPC flush instead of explicit bool. Add NULL as fallback for others. (Matthew B)
v3:
- Add comments for flush_cache with media.
--- drivers/gpu/drm/xe/xe_guc_tlb_inval.c | 30 ++++++++++++++++++++----- drivers/gpu/drm/xe/xe_tlb_inval.c | 7 +++--- drivers/gpu/drm/xe/xe_tlb_inval.h | 2 +- drivers/gpu/drm/xe/xe_tlb_inval_job.c | 2 +- drivers/gpu/drm/xe/xe_tlb_inval_types.h | 4 +++- drivers/gpu/drm/xe/xe_vm.c | 4 ++-- 6 files changed, 36 insertions(+), 13 deletions(-)
drivers/gpu/drm/xe/xe_guc_tlb_inval.c +25 -5
@@ -13,6 +13,7 @@#include "xe_guc_tlb_inval.h" #include "xe_force_wake.h" #include "xe_mmio.h" +#include "xe_sa.h" #include "xe_tlb_inval.h" #include "regs/xe_guc_regs.h"
@@ -93,6 +94,20 @@ static int send_tlb_inval_ggtt(struct xe_tlb_inval *tlb_inval, u32 seqno)return -ECANCELED ; } +static int send_page_reclaim (struct xe_guc *guc,u32 seqno, +u64 gpu_addr) +{ +u32 action[] = { +XE_GUC_ACTION_PAGE_RECLAMATION , + seqno, +lower_32_bits (gpu_addr), +upper_32_bits (gpu_addr), + }; + +return xe_guc_ct_send (&guc->ct, action,ARRAY_SIZE (action), +G2H_LEN_DW_PAGE_RECLAMATION ,1 ); +} +/* * Ensure that roundup_pow_of_two(length) doesn't overflow. * Note that roundup_pow_of_two() operates on unsigned long,
@@ -101,20 +116,21 @@ static int send_tlb_inval_ggtt(struct xe_tlb_inval *tlb_inval, u32 seqno)#define MAX_RANGE_TLB_INVALIDATION_LENGTH (rounddown_pow_of_two(ULONG_MAX))static int send_tlb_inval_ppgtt (struct xe_tlb_inval *tlb_inval,u32 seqno, -u64 start,u64 end,u32 asid) +u64 start,u64 end,u32 asid, +struct drm_suballoc *prl_sa) {#define MAX_TLB_INVALIDATION_LEN 7struct xe_guc *guc = tlb_inval->private;struct xe_gt *gt =guc_to_gt (guc);u32 action[MAX_TLB_INVALIDATION_LEN ];u64 length = end - start; -int len =0 ; +int len =0 , err;if (guc_to_xe (guc)->info.force_execlist)return -ECANCELED ; action[len++] =XE_GUC_ACTION_TLB_INVALIDATION ; - action[len++] = seqno; + action[len++] = !prl_sa ? seqno :TLB_INVALIDATION_SEQNO_INVALID ;if (!gt_to_xe (gt)->info.has_range_tlb_inval || length >MAX_RANGE_TLB_INVALIDATION_LENGTH ) { action[len++] =MAKE_INVAL_OP (XE_GUC_TLB_INVAL_FULL );
@@ -155,7 +171,8 @@ static int send_tlb_inval_ppgtt(struct xe_tlb_inval *tlb_inval, u32 seqno, ilog2(SZ_2M) + 1)));xe_gt_assert (gt,IS_ALIGNED (start, length)); - action[len++] =MAKE_INVAL_OP_FLUSH (XE_GUC_TLB_INVAL_PAGE_SELECTIVE , true); +/* Flush on NULL case, Media is not required to modify flush due to no PPC so NOP */ + action[len++] =MAKE_INVAL_OP_FLUSH (XE_GUC_TLB_INVAL_PAGE_SELECTIVE , !prl_sa); action[len++] = asid; action[len++] =lower_32_bits (start); action[len++] =upper_32_bits (start);
@@ -164,7 +181,10 @@ static int send_tlb_inval_ppgtt(struct xe_tlb_inval *tlb_inval, u32 seqno,xe_gt_assert (gt, len <=MAX_TLB_INVALIDATION_LEN ); -return send_tlb_inval (guc, action, len); + err =send_tlb_inval (guc, action, len); +if (!err && prl_sa) + err =send_page_reclaim (guc, seqno,xe_sa_bo_gpu_addr (prl_sa)); +return err; }static bool tlb_inval_initialized (struct xe_tlb_inval *tlb_inval)
drivers/gpu/drm/xe/xe_tlb_inval.c +4 -3
@@ -313,6 +313,7 @@ int xe_tlb_inval_ggtt(struct xe_tlb_inval *tlb_inval)* @start: start address * @end: end address * @asid: address space id +* @prl_sa: suballocation of page reclaim list if used, NULL indicates PPC flush * * Issue a range based TLB invalidation if supported, if not fallback to a full * TLB invalidation. Completion of TLB is asynchronous and caller can use
@@ -322,10 +323,10 @@ int xe_tlb_inval_ggtt(struct xe_tlb_inval *tlb_inval)*/ int xe_tlb_inval_range (struct xe_tlb_inval *tlb_inval,struct xe_tlb_inval_fence *fence,u64 start,u64 end, -u32 asid) +u32 asid,struct drm_suballoc *prl_sa) {return xe_tlb_inval_issue (tlb_inval, fence, tlb_inval->ops->ppgtt, - start, end, asid); + start, end, asid, prl_sa); }/**
@@ -341,7 +342,7 @@ void xe_tlb_inval_vm(struct xe_tlb_inval *tlb_inval, struct xe_vm *vm)u64 range =1ull << vm->xe->info.va_bits;xe_tlb_inval_fence_init (tlb_inval, &fence, true); -xe_tlb_inval_range (tlb_inval, &fence,0 , range, vm->usm.asid); +xe_tlb_inval_range (tlb_inval, &fence,0 , range, vm->usm.asid,NULL );xe_tlb_inval_fence_wait (&fence); }
drivers/gpu/drm/xe/xe_tlb_inval.h +1 -1
@@ -23,7 +23,7 @@ int xe_tlb_inval_ggtt(struct xe_tlb_inval *tlb_inval);void xe_tlb_inval_vm (struct xe_tlb_inval *tlb_inval,struct xe_vm *vm);int xe_tlb_inval_range (struct xe_tlb_inval *tlb_inval,struct xe_tlb_inval_fence *fence, -u64 start,u64 end,u32 asid); +u64 start,u64 end,u32 asid,struct drm_suballoc *prl_sa); void xe_tlb_inval_fence_init(struct xe_tlb_inval *tlb_inval, struct xe_tlb_inval_fence *fence,
drivers/gpu/drm/xe/xe_tlb_inval_job.c +1 -1
@@ -60,7 +60,7 @@ static struct dma_fence *xe_tlb_inval_job_run(struct xe_dep_job *dep_job) }xe_tlb_inval_range (job->tlb_inval, ifence, job->start, - job->end, job->vm->usm.asid); + job->end, job->vm->usm.asid, prl_sa);return job->fence; }
drivers/gpu/drm/xe/xe_tlb_inval_types.h +3 -1
@@ -9,6 +9,7 @@#include <linux/workqueue.h> #include <linux/dma-fence.h> +struct drm_suballoc ;struct xe_tlb_inval ;/** struct xe_tlb_inval_ops - TLB invalidation ops (backend) */
@@ -40,12 +41,13 @@ struct xe_tlb_inval_ops {* @start: Start address * @end: End address * @asid: Address space ID +* @prl_sa: Suballocation for page reclaim list * * Return 0 on success, -ECANCELED if backend is mid-reset, error on * failure */ int (*ppgtt)(struct xe_tlb_inval *tlb_inval,u32 seqno,u64 start, -u64 end,u32 asid); +u64 end,u32 asid,struct drm_suballoc *prl_sa);/** * @initialized: Backend is initialized
drivers/gpu/drm/xe/xe_vm.c +2 -2
@@ -3928,7 +3928,7 @@ int xe_vm_range_tilemask_tlb_inval(struct xe_vm *vm, u64 start, err =xe_tlb_inval_range (&tile->primary_gt->tlb_inval, &fence[fence_id], start, end, - vm->usm.asid); + vm->usm.asid,NULL );if (err) goto wait; ++fence_id;
@@ -3941,7 +3941,7 @@ int xe_vm_range_tilemask_tlb_inval(struct xe_vm *vm, u64 start, err =xe_tlb_inval_range (&tile->media_gt->tlb_inval, &fence[fence_id], start, end, - vm->usm.asid); + vm->usm.asid,NULL );if (err) goto wait; ++fence_id;
Signature · 1 line
2.52.0
PATCH v4 9/10 drm/xe: Optimize flushing of L2$ by skipping unnecessary page reclaim
In reply to Brian NguyenThere are additional hardware managed L2$ flushing such as the transient display. In those scenarios, page reclamation is unnecessary resulting in redundant cacheline flushes, so skip over those corresponding ranges.
v2:
- Elaborated on reasoning for page reclamation skip based on Tejas's discussion. (Matthew A, Tejas)
v3:
- Removed MEDIA_IS_ON due to racy condition resulting in removal of relevant registers and values. (Matthew A)
- Moved l3 policy access to xe_pat. (Matthew A)
v4:
- Updated comments based on previous change. (Tejas)
- Move back PAT index macros to xe_pat.c.
--- drivers/gpu/drm/xe/xe_page_reclaim.c | 32 ++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_page_reclaim.h | 3 +++ drivers/gpu/drm/xe/xe_pat.c | 8 +++++++ drivers/gpu/drm/xe/xe_pat.h | 10 +++++++++ drivers/gpu/drm/xe/xe_pt.c | 4 +++- 5 files changed, 56 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_page_reclaim.c +32 -0
@@ -13,8 +13,40 @@#include "regs/xe_gt_regs.h" #include "xe_assert.h" #include "xe_macros.h" +#include "xe_mmio.h" +#include "xe_pat.h" #include "xe_sa.h" #include "xe_tlb_inval_types.h" +#include "xe_vm.h" + +/** +* xe_page_reclaim_skip() - Decide whether PRL should be skipped for a VMA +* @tile: Tile owning the VMA +* @vma: VMA under consideration +* +* PPC flushing may be handled by HW for specific PAT encodings. +* Skip PPC flushing/Page Reclaim for scenarios below due to redundant +* flushes. +* - pat_index is transient display (1) +* +* Return: true when page reclamation is unnecessary, false otherwise. +*/ +bool xe_page_reclaim_skip (struct xe_tile *tile,struct xe_vma *vma) +{ +u8 l3_policy; + + l3_policy =xe_pat_index_get_l3_policy (tile->xe, vma->attr.pat_index); + +/** +* - l3_policy: 0=WB, 1=XD ("WB - Transient Display"), 3=UC +* Transient display flushes is taken care by HW, l3_policy = 1. +* +* HW will sequence these transient flushes at various sync points so +* any event of page reclamation will hit these sync points before +* page reclamation could execute. +*/ +return (l3_policy ==XE_L3_POLICY_XD ); +}/** * xe_page_reclaim_create_prl_bo() - Back a PRL with a suballocated GGTT BO
drivers/gpu/drm/xe/xe_page_reclaim.h +3 -0
@@ -18,6 +18,8 @@struct xe_tlb_inval ;struct xe_tlb_inval_fence ; +struct xe_tile ; +struct xe_vma ;struct xe_guc_page_reclaim_entry {u64 qw;
@@ -44,6 +46,7 @@ struct xe_page_reclaim_list {#define XE_PAGE_RECLAIM_INVALID_LIST -1 }; +bool xe_page_reclaim_skip (struct xe_tile *tile,struct xe_vma *vma);struct drm_suballoc *xe_page_reclaim_create_prl_bo (struct xe_tlb_inval *tlb_inval,struct xe_page_reclaim_list *prl,struct xe_tlb_inval_fence *fence);
drivers/gpu/drm/xe/xe_pat.c +8 -0
@@ -9,6 +9,7 @@#include <generated/xe_wa_oob.h> +#include "regs/xe_gt_regs.h" #include "regs/xe_reg_defs.h" #include "xe_assert.h" #include "xe_device.h"
@@ -231,6 +232,13 @@ bool xe_pat_index_get_comp_en(struct xe_device *xe, u16 pat_index)return !!(xe->pat.table[pat_index].value &XE2_COMP_EN ); } +u16 xe_pat_index_get_l3_policy (struct xe_device *xe,u16 pat_index) +{ +WARN_ON (pat_index >= xe->pat.n_entries); + +return REG_FIELD_GET (XE2_L3_POLICY , xe->pat.table[pat_index].value); +} +static void program_pat (struct xe_gt *gt,const struct xe_pat_table_entry table[],int n_entries) {
drivers/gpu/drm/xe/xe_pat.h +10 -0
@@ -69,4 +69,14 @@ u16 xe_pat_index_get_coh_mode(struct xe_device *xe, u16 pat_index);*/ bool xe_pat_index_get_comp_en (struct xe_device *xe,u16 pat_index); +#define XE_L3_POLICY_WB 0/* Write-back */ +#define XE_L3_POLICY_XD 1/* WB - Transient Display */ +#define XE_L3_POLICY_UC 3/* Uncached */ +/** +* xe_pat_index_get_l3_policy - Extract the L3 policy for the given pat_index. +* @xe: xe device +* @pat_index: The pat_index to query +*/ +u16 xe_pat_index_get_l3_policy (struct xe_device *xe,u16 pat_index); +#endif
drivers/gpu/drm/xe/xe_pt.c +3 -1
@@ -2020,7 +2020,9 @@ static int unbind_op_prepare(struct xe_tile *tile,if (xe->info.has_page_reclaim_hw_assist && !pt_update_ops->prl.entries)xe_page_reclaim_list_alloc_entries (&pt_update_ops->prl); - pt_op->prl = (pt_update_ops->prl.entries) ? &pt_update_ops->prl :NULL ; +/* Page reclaim may not be needed due to other features, so skip the corresponding VMA */ + pt_op->prl = (pt_update_ops->prl.entries && + !xe_page_reclaim_skip (tile, vma)) ? &pt_update_ops->prl :NULL ; err =vma_reserve_fences (tile_to_xe (tile), vma);if (err)
Signature · 1 line
2.52.0
PATCH v4 10/10 drm/xe: Add debugfs support for page reclamation
In reply to Brian NguyenAllow for runtime modification to page reclamation feature through debugfs configuration. This parameter will only take effect if the platform supports the page reclamation feature by default.
v2:
- Minor comment tweaks. (Shuicheng)
- Convert to kstrtobool_from_user. (Michal)
- Only expose page reclaim file if page reclaim flag initially supported and with that, remove xe_match_desc usage. (Michal)
--- drivers/gpu/drm/xe/xe_debugfs.c | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/gpu/drm/xe/xe_debugfs.c +41 -0
@@ -291,6 +291,39 @@ static const struct file_operations wedged_mode_fops = { .write = wedged_mode_set, }; +static ssize_t page_reclaim_hw_assist_show (struct file *f,char __user *ubuf, +size_t size,loff_t *pos) +{ +struct xe_device *xe =file_inode (f)->i_private; +char buf[8 ]; +int len; + + len =scnprintf (buf,sizeof (buf),"%d\n" , xe->info.has_page_reclaim_hw_assist); +return simple_read_from_buffer (ubuf, size, pos, buf, len); +} + +static ssize_t page_reclaim_hw_assist_set (struct file *f,const char __user *ubuf, +size_t size,loff_t *pos) +{ +struct xe_device *xe =file_inode (f)->i_private; +bool val; +ssize_t ret; + + ret =kstrtobool_from_user (ubuf, size, &val); +if (ret) +return ret; + + xe->info.has_page_reclaim_hw_assist = val; + +return size; +} + +static const struct file_operations page_reclaim_hw_assist_fops = { + .owner =THIS_MODULE , + .read = page_reclaim_hw_assist_show, + .write = page_reclaim_hw_assist_set, +}; +static ssize_t atomic_svm_timeslice_ms_show (struct file *f,char __user *ubuf,size_t size,loff_t *pos) {
@@ -396,6 +429,14 @@ void xe_debugfs_register(struct xe_device *xe)debugfs_create_file ("disable_late_binding" ,0600 , root, xe, &disable_late_binding_fops); +/* +* Don't expose page reclaim configuration file if not supported by the +* hardware initially. +*/ +if (xe->info.has_page_reclaim_hw_assist) +debugfs_create_file ("page_reclaim_hw_assist" ,0600 , root, xe, + &page_reclaim_hw_assist_fops); + man =ttm_manager_type (bdev,XE_PL_TT );ttm_resource_manager_create_debugfs (man, root,"gtt_mm" );
Signature · 1 line
2.52.0