[PATCH v5 3/3] drm/xe: Add WA BB to capture active context utilization

Lucas De Marchi lucas.demarchi at intel.com
Tue May 20 14:57:44 UTC 2025


On Tue, May 20, 2025 at 10:01:59AM +0100, Tvrtko Ursulin wrote:
>
>Hi,
>
>One question below in the context of the missing workarounds series I 
>am working on:
>
>On 09/05/2025 17:12, Umesh Nerlige Ramappa wrote:
>
>8><
>
>>+#define CONTEXT_ACTIVE 1ULL
>>+static void xe_lrc_setup_utilization(struct xe_lrc *lrc)
>>+{
>>+	u32 *cmd;
>>+
>>+	cmd = lrc->bb_per_ctx_bo->vmap.vaddr;
>>+
>>+	*cmd++ = MI_STORE_REGISTER_MEM | MI_SRM_USE_GGTT | MI_SRM_ADD_CS_OFFSET;
>>+	*cmd++ = ENGINE_ID(0).addr;
>>+	*cmd++ = __xe_lrc_engine_id_ggtt_addr(lrc);
>>+	*cmd++ = 0;
>>+
>>+	*cmd++ = MI_STORE_DATA_IMM | MI_SDI_GGTT | MI_SDI_NUM_DW(1);
>>+	*cmd++ = __xe_lrc_ctx_timestamp_ggtt_addr(lrc);
>>+	*cmd++ = 0;
>>+	*cmd++ = lower_32_bits(CONTEXT_ACTIVE);
>>+
>>+	if (lrc_to_xe(lrc)->info.has_64bit_timestamp) {
>>+		*cmd++ = MI_STORE_DATA_IMM | MI_SDI_GGTT | MI_SDI_NUM_DW(1);
>>+		*cmd++ = __xe_lrc_ctx_timestamp_udw_ggtt_addr(lrc);
>>+		*cmd++ = 0;
>>+		*cmd++ = upper_32_bits(CONTEXT_ACTIVE);
>>+	}
>>+
>>+	*cmd++ = MI_BATCH_BUFFER_END;
>
>Matt Roper raised the suggestion in another series that we should 
>always use the iosys helpers for writing into mapped BOs. Later I 
>realised this code uses the same shortcut as I did. I probably even 
>lifted the concept since I placed my function right next to this one. 
>:)
>
>So question is what is the definitive recommended way to write into 
>mapped BOs? Is the direct writes shortcut acceptable, or this also 
>needs changing?

right, I missed that during review. We may have a problem in !x86 if we
have __iomem here. So yes, we need to change. So probably:

cmd = &lrc->bb_per_ctx_bo->vmap;
xe_map_write32(xe, cmd, MI_STORE_REGISTER_MEM | MI_SRM_USE_GGTT | MI_SRM_ADD_CS_OFFSET);
xe_map_write32(xe, cmd, ENGINE_ID(0).addr);
...

maybe we could add an iosys_map_wr_many() that would be a variadic
version with offset incr and hopefully the check for is_iomem in a
single place. Another option would be a local buffer that we memcpy at
the end.

+Thomas Zimmerman / +Sima

Lucas De Marchi


>
>>+
>>+	xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR,
>>+			     xe_bo_ggtt_addr(lrc->bb_per_ctx_bo) | 1);
>
>Btw here code uses the iosys helpers. It is a different BO but they 
>are created/mapped the same AFAICT.
>
>Regards,
>
>Tvrtko
>


More information about the dri-devel mailing list