Skip to content

Commit

Permalink
[Media Common] [VP] Enable pat index setting when creating bo
Browse files Browse the repository at this point in the history
Enable pat index setting for perf
close #1680
  • Loading branch information
LhGu authored and Sherry-Lin committed Jun 28, 2023
1 parent 3b5369d commit cf94234
Show file tree
Hide file tree
Showing 14 changed files with 393 additions and 117 deletions.
12 changes: 6 additions & 6 deletions media_driver/linux/ult/libdrm_mock/mos_bufmgr_api_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@

struct mos_linux_bo *
mos_bo_alloc(struct mos_bufmgr *bufmgr, const char *name,
unsigned long size, unsigned int alignment, int mem_type)
unsigned long size, unsigned int alignment, int mem_type, unsigned int pat_index, bool cpu_cacheable)
{
return bufmgr->bo_alloc(bufmgr, name, size, alignment, mem_type);
return bufmgr->bo_alloc(bufmgr, name, size, alignment, mem_type, pat_index, cpu_cacheable);
}

struct mos_linux_bo *
mos_bo_alloc_for_render(struct mos_bufmgr *bufmgr, const char *name,
unsigned long size, unsigned int alignment, int mem_type)
unsigned long size, unsigned int alignment, int mem_type, unsigned int pat_index, bool cpu_cacheable)
{
return bufmgr->bo_alloc_for_render(bufmgr, name, size, alignment, mem_type);
return bufmgr->bo_alloc_for_render(bufmgr, name, size, alignment, mem_type, pat_index, cpu_cacheable);
}

struct mos_linux_bo *
Expand All @@ -77,10 +77,10 @@ mos_bo_alloc_userptr(struct mos_bufmgr *bufmgr,
struct mos_linux_bo *
mos_bo_alloc_tiled(struct mos_bufmgr *bufmgr, const char *name,
int x, int y, int cpp, uint32_t *tiling_mode,
unsigned long *pitch, unsigned long flags, int mem_type)
unsigned long *pitch, unsigned long flags, int mem_type, unsigned int pat_index, bool cpu_cacheable)
{
return bufmgr->bo_alloc_tiled(bufmgr, name, x, y, cpp,
tiling_mode, pitch, flags, mem_type);
tiling_mode, pitch, flags, mem_type, pat_index, cpu_cacheable);
}

void
Expand Down
24 changes: 17 additions & 7 deletions media_driver/linux/ult/libdrm_mock/mos_bufmgr_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,12 @@ mos_gem_bo_alloc_internal(struct mos_bufmgr *bufmgr,
uint32_t tiling_mode,
unsigned long stride,
unsigned int alignment,
int mem_type)
int mem_type,
unsigned int pat_index,
bool cpu_cacheable)
{
MOS_UNUSED(pat_index);
MOS_UNUSED(cpu_cacheable);
struct mos_bufmgr_gem *bufmgr_gem = (struct mos_bufmgr_gem *) bufmgr;
struct mos_bo_gem *bo_gem;
unsigned int page_size = getpagesize();
Expand Down Expand Up @@ -1049,31 +1053,37 @@ mos_gem_bo_alloc_for_render(struct mos_bufmgr *bufmgr,
const char *name,
unsigned long size,
unsigned int alignment,
int mem_type)
int mem_type,
unsigned int pat_index,
bool cpu_cacheable)
{
return mos_gem_bo_alloc_internal(bufmgr, name, size,
I915_TILING_NONE, 0,
BO_ALLOC_FOR_RENDER,
alignment,
mem_type);
mem_type,
pat_index,
cpu_cacheable);
}

static struct mos_linux_bo *
mos_gem_bo_alloc(struct mos_bufmgr *bufmgr,
const char *name,
unsigned long size,
unsigned int alignment,
int mem_type)
int mem_type,
unsigned int pat_index,
bool cpu_cacheable)
{
return mos_gem_bo_alloc_internal(bufmgr, name, size, 0,
I915_TILING_NONE, 0, 0, mem_type);
I915_TILING_NONE, 0, 0, mem_type, pat_index, cpu_cacheable);
}

static struct mos_linux_bo *
mos_gem_bo_alloc_tiled(struct mos_bufmgr *bufmgr, const char *name,
int x, int y, int cpp, uint32_t *tiling_mode,
unsigned long *pitch, unsigned long flags,
int mem_type)
int mem_type, unsigned int pat_index, bool cpu_cacheable)
{
struct mos_bufmgr_gem *bufmgr_gem = (struct mos_bufmgr_gem *)bufmgr;
unsigned long size, stride;
Expand Down Expand Up @@ -1116,7 +1126,7 @@ mos_gem_bo_alloc_tiled(struct mos_bufmgr *bufmgr, const char *name,
if (tiling == I915_TILING_NONE)
stride = 0;
return mos_gem_bo_alloc_internal(bufmgr, name, size, flags,
tiling, stride, 0, mem_type);
tiling, stride, 0, mem_type, pat_index, cpu_cacheable);
}

static struct mos_linux_bo *
Expand Down
15 changes: 15 additions & 0 deletions media_softlet/agnostic/common/os/mos_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,21 @@ class MosInterface
static GMM_CLIENT_CONTEXT *GetGmmClientContext(
MOS_STREAM_HANDLE streamState);

//!
//! \brief Get PAT index from gmm
//!
//! \param [in] gmmClient
//! GMM client context
//! \param [in] gmmResourceInfo
//! gmm resource info
//!
//! \return unsigned int
//! Pat index
//!
static unsigned int GetPATIndexFromGmm(
GMM_CLIENT_CONTEXT *gmmClient,
GMM_RESOURCE_INFO *gmmResourceInfo);

//!
//! \brief Get current Gpu context priority
//! \details Get current Gpu context priority
Expand Down
18 changes: 14 additions & 4 deletions media_softlet/linux/common/ddi/media_libva_util_next.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,16 +734,19 @@ VAStatus MediaLibvaUtilNext::CreateInternalSurface(

params.memType = MemoryPolicyManager::UpdateMemoryPolicy(&memPolicyPar);

unsigned int patIndex = MosInterface::GetPATIndexFromGmm(mediaDrvCtx->pGmmClientContext, gmmResourceInfo);
bool isCpuCacheable = gmmResourceInfo->GetResFlags().Info.Cacheable;

if ( params.tileFormat == I915_TILING_NONE )
{
bo = mos_bo_alloc(mediaDrvCtx->pDrmBufMgr, "MEDIA", gmmSize, 4096, params.memType);
bo = mos_bo_alloc(mediaDrvCtx->pDrmBufMgr, "MEDIA", gmmSize, 4096, params.memType, patIndex, isCpuCacheable);
params.pitch = gmmPitch;
}
else
{
unsigned long ulPitch = 0;
bo = mos_bo_alloc_tiled(mediaDrvCtx->pDrmBufMgr, "MEDIA", gmmPitch, (gmmSize + gmmPitch -1)/gmmPitch, 1, &params.tileFormat,
(unsigned long *)&ulPitch, 0, params.memType);
(unsigned long *)&ulPitch, 0, params.memType, patIndex, isCpuCacheable);
params.pitch = ulPitch;
}

Expand Down Expand Up @@ -1658,8 +1661,11 @@ VAStatus MediaLibvaUtilNext::Allocate2DBuffer(

mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&memPolicyPar);

unsigned int patIndex = MosInterface::GetPATIndexFromGmm(mediaBuffer->pMediaCtx->pGmmClientContext, gmmResourceInfo);
bool isCpuCacheable = gmmResourceInfo->GetResFlags().Info.Cacheable;

MOS_LINUX_BO *bo;
bo = mos_bo_alloc(bufmgr, "Media 2D Buffer", gmmSize, 4096, mem_type);
bo = mos_bo_alloc(bufmgr, "Media 2D Buffer", gmmSize, 4096, mem_type, patIndex, isCpuCacheable);

mediaBuffer->bMapped = false;
if (bo)
Expand Down Expand Up @@ -1731,7 +1737,11 @@ VAStatus MediaLibvaUtilNext::AllocateBuffer(
memPolicyPar.preferredMemType = mediaBuffer->bUseSysGfxMem ? MOS_MEMPOOL_SYSTEMMEMORY : 0;

mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&memPolicyPar);
MOS_LINUX_BO *bo = mos_bo_alloc(bufmgr, "Media Buffer", size, 4096, mem_type);

unsigned int patIndex = MosInterface::GetPATIndexFromGmm(mediaBuffer->pMediaCtx->pGmmClientContext, mediaBuffer->pGmmResourceInfo);
bool isCpuCacheable = mediaBuffer->pGmmResourceInfo->GetResFlags().Info.Cacheable;

MOS_LINUX_BO *bo = mos_bo_alloc(bufmgr, "Media Buffer", size, 4096, mem_type, patIndex, isCpuCacheable);
mediaBuffer->bMapped = false;
if (bo)
{
Expand Down
12 changes: 9 additions & 3 deletions media_softlet/linux/common/os/i915/include/mos_bufmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,17 @@ struct mos_aub_annotation {

#define BO_ALLOC_FOR_RENDER (1<<0)

#define PAT_INDEX_INVALID ((uint32_t)-1)

struct mos_linux_bo *mos_bo_alloc(struct mos_bufmgr *bufmgr, const char *name,
unsigned long size, unsigned int alignment, int mem_type);
unsigned long size, unsigned int alignment, int mem_type, unsigned int pat_index = PAT_INDEX_INVALID, bool cpu_cacheable = true);
struct mos_linux_bo *mos_bo_alloc_for_render(struct mos_bufmgr *bufmgr,
const char *name,
unsigned long size,
unsigned int alignment,
int mem_type);
int mem_type,
unsigned int pat_index = PAT_INDEX_INVALID,
bool cpu_cacheable = true);
struct mos_linux_bo *mos_bo_alloc_userptr(struct mos_bufmgr *bufmgr,
const char *name,
void *addr, uint32_t tiling_mode,
Expand All @@ -188,7 +192,9 @@ struct mos_linux_bo *mos_bo_alloc_tiled(struct mos_bufmgr *bufmgr,
uint32_t *tiling_mode,
unsigned long *pitch,
unsigned long flags,
int mem_type);
int mem_type,
unsigned int pat_index = PAT_INDEX_INVALID,
bool cpu_cacheable = true);
void mos_bo_reference(struct mos_linux_bo *bo);
void mos_bo_unreference(struct mos_linux_bo *bo);
int mos_bo_map(struct mos_linux_bo *bo, int write_enable);
Expand Down
10 changes: 7 additions & 3 deletions media_softlet/linux/common/os/i915/include/mos_bufmgr_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct mos_bufmgr {
* using bo_map() or drm_intel_gem_bo_map_gtt() to be used by the CPU.
*/
struct mos_linux_bo *(*bo_alloc) (struct mos_bufmgr *bufmgr, const char *name,
unsigned long size, unsigned int alignment, int mem_type);
unsigned long size, unsigned int alignment, int mem_type, unsigned int pat_index, bool cpu_cacheable);

/**
* Allocate a buffer object, hinting that it will be used as a
Expand All @@ -60,7 +60,9 @@ struct mos_bufmgr {
const char *name,
unsigned long size,
unsigned int alignment,
int mem_type);
int mem_type,
unsigned int pat_index,
bool cpu_cacheable);

/**
* Allocate a buffer object from an existing user accessible
Expand Down Expand Up @@ -95,7 +97,9 @@ struct mos_bufmgr {
uint32_t *tiling_mode,
unsigned long *pitch,
unsigned long flags,
int mem_type);
int mem_type,
unsigned int pat_index,
bool cpu_cacheable);

/** Takes a reference on a buffer object */
void (*bo_reference) (struct mos_linux_bo *bo);
Expand Down
92 changes: 51 additions & 41 deletions media_softlet/linux/common/os/i915/include/uapi/README
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,55 @@ $ make headers_install INSTALL_HDR_PATH=/path/to/install

The last update was done at the following kernel commit:

commit 1cc064dce4ed0ff111b6d6cb06b3cccf1cba29f5
Author: Umesh Nerlige Ramappa <[email protected]>
Date: Thu Mar 23 15:58:59 2023 -0700

drm/i915/perf: Add support for OA media units

MTL introduces additional OA units dedicated to media use cases. Add
support for programming these OA units by passing the media engine class
and instance parameters.

UMD specific changes for GPUvis support:
https://patchwork.freedesktop.org/patch/522827/?series=114023
https://patchwork.freedesktop.org/patch/522822/?series=114023
https://patchwork.freedesktop.org/patch/522826/?series=114023
https://patchwork.freedesktop.org/patch/522828/?series=114023
https://patchwork.freedesktop.org/patch/522816/?series=114023
https://patchwork.freedesktop.org/patch/522825/?series=114023

v2: (Ashutosh)
- check for IP_VER(12, 70) instead of MTL
- remove PERF_GROUP_OAG comment in mtl_oa_base
- remove oa_buffer.group
- use engine->oa_group->type in engine_supports_oa_format
- remove fw_domains and use FORCEWAKE_ALL
- remove MPES/MPEC comment
- s/xehp/mtl/ in b counter validation function name
- remove engine_supports_oa in __oa_engine_group
- remove warn_ON from __oam_engine_group
- refactor oa_init_groups and oa_init_regs
- assign g->type correctly
- use enum oa_type definition

v3: (Ashutosh)
- Drop oa_unit_functional as engine_supports_oa is enough

v4:
- s/DRM_DEBUG/drm_dbg/

Signed-off-by: Umesh Nerlige Ramappa <[email protected]>
Reviewed-by: Ashutosh Dixit <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
commit 81b1b599dfd71c958418dad586fa72c8d30d1065
Author: Fei Yang <[email protected]>
Date: Tue Jun 6 12:00:42 2023 +0200

drm/i915: Allow user to set cache at BO creation

To comply with the design that buffer objects shall have immutable
cache setting through out their life cycle, {set, get}_caching ioctl's
are no longer supported from MTL onward. With that change caching
policy can only be set at object creation time. The current code
applies a default (platform dependent) cache setting for all objects.
However this is not optimal for performance tuning. The patch extends
the existing gem_create uAPI to let user set PAT index for the object
at creation time.
The new extension is platform independent, so UMD's can switch to using
this extension for older platforms as well, while {set, get}_caching are
still supported on these legacy paltforms for compatibility reason.
However, since PAT index was not clearly defined for platforms prior to
GEN12 (TGL), so we are limiting this externsion to GEN12+ platforms
only. See ext_set_pat() in for the implementation details.

The documentation related to the PAT/MOCS tables is currently available
for Tiger Lake here:
https://www.intel.com/content/www/us/en/docs/graphics-for-linux/developer-reference/1-0/tiger-lake.html

The documentation for other platforms is currently being updated.

BSpec: 45101

Mesa support has been submitted in this merge request:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22878

The media driver supprt has bin submitted in this merge request:
https://github.com/intel/media-driver/pull/1680

The IGT test related to this change is
igt@gem_create@create-ext-set-pat

Signed-off-by: Fei Yang <[email protected]>
Cc: Chris Wilson <[email protected]>
Cc: Matt Roper <[email protected]>
Cc: Andi Shyti <[email protected]>
Reviewed-by: Andi Shyti <[email protected]>
Acked-by: Jordan Justen <[email protected]>
Tested-by: Jordan Justen <[email protected]>
Acked-by: Carl Zhang <[email protected]>
Tested-by: Lihao Gu <[email protected]>
Signed-off-by: Andi Shyti <[email protected]>
Acked-by: Tvrtko Ursulin <[email protected]>
Acked-by: Slawomir Milczarek <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]

Loading

0 comments on commit cf94234

Please sign in to comment.