Skip to content

Commit

Permalink
Enable virtual engine (single pipe) on Gen11.
Browse files Browse the repository at this point in the history
  • Loading branch information
zxye committed Dec 26, 2018
1 parent ec6738e commit 7fe0bd2
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 6 deletions.
15 changes: 15 additions & 0 deletions media_driver/linux/common/os/i915/include/mos_bufmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ int mos_get_aperture_sizes(int fd, size_t *mappable, size_t *total);
int mos_bufmgr_gem_get_devid(struct mos_bufmgr *bufmgr);

struct mos_linux_context *mos_gem_context_create(struct mos_bufmgr *bufmgr);
struct mos_linux_context *mos_gem_context_create_v2(struct mos_bufmgr *bufmgr, __u32 flags);
struct class_instance {
uint16_t engine_class;
uint16_t instance;
};
#define MAX_VDBOX_NUM 64
int mos_query_engines(int fd,
__u16 engine_class,
__u64 caps,
unsigned int *nengine,
struct class_instance *ci);
int mos_set_context_param_load_balance(struct mos_linux_context *ctx,
const struct class_instance *ci,
unsigned int count);

void mos_gem_context_destroy(struct mos_linux_context *ctx);
int mos_gem_bo_context_exec(struct mos_linux_bo *bo, struct mos_linux_context *ctx,
int used, unsigned int flags);
Expand Down
143 changes: 143 additions & 0 deletions media_driver/linux/common/os/i915/mos_bufmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4529,3 +4529,146 @@ mos_bufmgr_gem_init(int fd, int batch_size)

return bufmgr_gem != nullptr ? &bufmgr_gem->bufmgr : nullptr;
}

struct mos_linux_context *
mos_gem_context_create_v2(struct mos_bufmgr *bufmgr, __u32 flags)
{
struct mos_bufmgr_gem *bufmgr_gem = (struct mos_bufmgr_gem *)bufmgr;
struct drm_i915_gem_context_create_v2 create;
struct mos_linux_context *context = nullptr;
int ret;

context = (struct mos_linux_context *)calloc(1, sizeof(*context));
if (!context)
return nullptr;

memclear(create);
create.flags = flags;
create.share_ctx = 0;
ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE_v2, &create);
if (ret != 0) {
MOS_DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE failed: %s\n",
strerror(errno));
free(context);
return nullptr;
}

context->ctx_id = create.ctx_id;
context->bufmgr = bufmgr;

return context;
}


int mos_query_engines(int fd,
__u16 engine_class,
__u64 caps,
unsigned int *nengine,
struct class_instance *ci)
{
struct drm_i915_query query;
struct drm_i915_query_item query_item;
struct drm_i915_query_engine_info *engines;
int ret, len;

engines = (drm_i915_query_engine_info *)malloc(4096);
memset(engines,0,4096);
memclear(query_item);
query_item.query_id = DRM_I915_QUERY_ENGINE_INFO;
query_item.length = 0;
query_item.data_ptr = (uintptr_t)engines;
memclear(query);
query.num_items = 1;
query.items_ptr = (uintptr_t)&query_item;

ret = drmIoctl(fd, DRM_IOCTL_I915_QUERY, &query);
if (ret)
{
goto fini;
}
len = query_item.length;

memset(engines,0,4096);
memclear(query_item);
query_item.query_id = DRM_I915_QUERY_ENGINE_INFO;
query_item.length = len;
query_item.data_ptr = (uintptr_t)engines;
memclear(query);
query.num_items = 1;
query.items_ptr = (uintptr_t)&query_item;

ret = drmIoctl(fd, DRM_IOCTL_I915_QUERY, &query);
if (ret)
{
goto fini;
}

int i, num;
for (i = 0, num = 0; i < engines->num_engines; i++) {
struct drm_i915_engine_info *engine =
(struct drm_i915_engine_info *)&engines->engines[i];
if ( engine_class == engine->engine_class
&& ((caps & engine->capabilities) || caps == 0))
{
ci->engine_class = engine_class;
ci->instance = engine->instance;
ci++;
num++;
}
}
if (num > *nengine)
{
fprintf(stderr,"%s: Number of engine instances out of range, %d,%d\n",
__FUNCTION__, num, *nengine);
goto fini;
}
*nengine = num;


fini:
free(engines);
return ret;
}

int mos_set_context_param_load_balance(struct mos_linux_context *ctx,
const struct class_instance *ci,
unsigned int count)
{
int ret;

assert(ci);

struct balancer {
uint64_t next_extension;
uint64_t name;

uint64_t flags;
uint64_t mask;

uint64_t mbz[4];
} balancer;
memclear(balancer);
balancer.name = I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE;
balancer.mask = ~0ull;

/*
struct set_engines {
uint64_t extension;
struct class_instance engines[count];
} set_engines;
*/
uint32_t size = sizeof(uint64_t) + count*sizeof(struct class_instance);
uint32_t* set_engines = (uint32_t*) malloc(size);
if (NULL == set_engines)
{
return ENOMEM;
}
*((uint64_t*)set_engines) = (uintptr_t)(&balancer); /*set_engines->extension*/
memcpy(set_engines+2, ci, count * sizeof(struct class_instance)); /*set_engines->engines*/
ret = mos_set_context_param(ctx,
size,
I915_CONTEXT_PARAM_ENGINES,
(uintptr_t)set_engines);
free(set_engines);
return ret;
}
11 changes: 10 additions & 1 deletion media_driver/linux/common/os/mos_context_specific.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,16 @@ MOS_STATUS OsContextSpecific::Init(PMOS_CONTEXT pOsDriverContext)
m_tileYFlag = MEDIA_IS_SKU(&m_skuTable, FtrTileY);

#ifndef ANDROID
m_intelContext = mos_gem_context_create(pOsDriverContext->bufmgr);

if (MEDIA_IS_SKU(&m_skuTable, FtrContextBasedScheduling))
{
m_intelContext = mos_gem_context_create_v2(pOsDriverContext->bufmgr,
I915_GEM_CONTEXT_SHARE_GTT | I915_GEM_CONTEXT_SINGLE_TIMELINE);
}
else
{
m_intelContext = mos_gem_context_create(pOsDriverContext->bufmgr);
}

if (m_intelContext == nullptr)
{
Expand Down
68 changes: 66 additions & 2 deletions media_driver/linux/common/os/mos_gpucontext_specific.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ MOS_STATUS GpuContextSpecific::Init(OsContext *osContext)
MOS_OS_CHK_NULL_RETURN(m_writeModeList);

m_GPUStatusTag = 1;
m_createOptionEnhanced = nullptr;

return MOS_STATUS_SUCCESS;
}
Expand Down Expand Up @@ -154,6 +155,8 @@ void GpuContextSpecific::Clear()
MOS_SafeFreeMemory(m_patchLocationList);
MOS_SafeFreeMemory(m_attachedResources);
MOS_SafeFreeMemory(m_writeModeList);
MOS_SafeFreeMemory(m_createOptionEnhanced);
m_createOptionEnhanced = nullptr;
}

MOS_STATUS GpuContextSpecific::RegisterResource(
Expand Down Expand Up @@ -326,6 +329,7 @@ MOS_STATUS GpuContextSpecific::GetCommandBuffer(

// zero comamnd buffer
MOS_ZeroMemory(comamndBuffer->pCmdBase, comamndBuffer->iRemaining);
MOS_ZeroMemory(&comamndBuffer->Attributes,sizeof(comamndBuffer->Attributes));

// update command buffer relared filed in GPU context
m_cmdBufFlushed = false;
Expand Down Expand Up @@ -655,9 +659,53 @@ MOS_STATUS GpuContextSpecific::SubmitCommandBuffer(
int32_t DR4 = osContext->uEnablePerfTag ? perfData : 0;

//Since CB2 command is not supported, remove it and set cliprects to nullprt as default.
if (gpuNode != I915_EXEC_RENDER)
if (gpuNode == MOS_GPU_NODE_3D && osInterface->ctxBasedScheduling)
{
if (osContext->bKMDHasVCS2)
struct class_instance engine_map;
engine_map.engine_class = I915_ENGINE_CLASS_RENDER;
engine_map.instance = 0;

ret = mos_set_context_param_load_balance(osContext->intel_context,&engine_map, 1);
if (ret)
{
MOS_OS_ASSERTMESSAGE("MOS failed to set balancer. Check if virtual engine is supported by KMD.\n");
eStatus = MOS_STATUS_UNKNOWN;
}
execFlag = I915_EXEC_DEFAULT;
}
else if (gpuNode == MOS_GPU_NODE_VIDEO || gpuNode == MOS_GPU_NODE_VIDEO2)
{
if (osInterface->ctxBasedScheduling)
{
unsigned int nengine = MAX_VDBOX_NUM;
struct class_instance engine_map[MAX_VDBOX_NUM];
__u16 engine_class = I915_ENGINE_CLASS_VIDEO;
__u64 caps = 0;

if (m_createOptionEnhanced->UsingSFC)
{
caps |= I915_VIDEO_AND_ENHANCE_CLASS_CAPABILITY_SFC;
}

MOS_ZeroMemory(engine_map, sizeof(engine_map));
ret = mos_query_engines(osContext->fd,engine_class,caps,&nengine,engine_map);
if (ret)
{
MOS_OS_ASSERTMESSAGE("MOS failed to query engines. Check if virtual engine is supported by KMD.\n");
eStatus = MOS_STATUS_UNKNOWN;
}

ret = mos_set_context_param_load_balance(osContext->intel_context, engine_map, nengine);
if (ret)
{
MOS_OS_ASSERTMESSAGE("MOS failed to set balancer. Check if virtual engine is supported by KMD.\n");
eStatus = MOS_STATUS_UNKNOWN;
}

osContext->ctx_caps = caps;
execFlag = I915_EXEC_DEFAULT;
}
else if (osContext->bKMDHasVCS2)
{
if (osContext->bPerCmdBufferBalancing && osInterface->pfnGetVdboxNodeId)
{
Expand Down Expand Up @@ -905,3 +953,19 @@ MOS_STATUS GpuContextSpecific::AllocateGPUStatusBuf()
m_statusBufferResource = graphicsResource;
return MOS_STATUS_SUCCESS;
}

MOS_STATUS GpuContextSpecific::SetContextParam(PMOS_GPUCTX_CREATOPTIONS_ENHANCED createOptionEnhanced)
{
MOS_OS_FUNCTION_ENTER;
if (m_createOptionEnhanced == nullptr)
{
m_createOptionEnhanced = (MOS_GPUCTX_CREATOPTIONS_ENHANCED*)MOS_AllocAndZeroMemory(sizeof(MOS_GPUCTX_CREATOPTIONS_ENHANCED));
}

MOS_OS_CHK_STATUS_RETURN(MOS_SecureMemcpy(m_createOptionEnhanced,
sizeof(MOS_GPUCTX_CREATOPTIONS_ENHANCED),
createOptionEnhanced,
sizeof(MOS_GPUCTX_CREATOPTIONS_ENHANCED)));

return MOS_STATUS_SUCCESS;
}
4 changes: 4 additions & 0 deletions media_driver/linux/common/os/mos_gpucontext_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ class GpuContextSpecific : public GpuContext
//!
MOS_STATUS AllocateGPUStatusBuf();

MOS_STATUS SetContextParam(PMOS_GPUCTX_CREATOPTIONS_ENHANCED createOptionEnhanced);

#if MOS_COMMAND_RESINFO_DUMP_SUPPORTED
void PushCmdResPtr(const void *p) { m_cmdResPtrs.push_back(p); }
void ClearCmdResPtrs() { m_cmdResPtrs.clear(); }
Expand Down Expand Up @@ -228,6 +230,8 @@ class GpuContextSpecific : public GpuContext
//! \brief Os context
OsContext *m_osContext = nullptr;

MOS_GPUCTX_CREATOPTIONS_ENHANCED *m_createOptionEnhanced;

#if MOS_COMMAND_RESINFO_DUMP_SUPPORTED
std::vector<const void *> m_cmdResPtrs; //!< Command OS resource pointers registered by pfnRegisterResource
#endif // MOS_COMMAND_RESINFO_DUMP_SUPPORTED
Expand Down
20 changes: 18 additions & 2 deletions media_driver/linux/common/os/mos_os_specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -1288,13 +1288,22 @@ MOS_STATUS Linux_InitContext(
// when MODS enabled, intel_context will be created by pOsContextSpecific, should not recreate it here, or will cause memory leak.
if (!MODSEnabled)
{
pContext->intel_context = mos_gem_context_create(pOsDriverContext->bufmgr);
if (MEDIA_IS_SKU(&pContext->SkuTable, FtrContextBasedScheduling))
{
pContext->intel_context = mos_gem_context_create_v2(pOsDriverContext->bufmgr,
I915_GEM_CONTEXT_SHARE_GTT | I915_GEM_CONTEXT_SINGLE_TIMELINE);
}
else
{
pContext->intel_context = mos_gem_context_create(pOsDriverContext->bufmgr);
}

if (pContext->intel_context == nullptr)
{
MOS_OS_ASSERTMESSAGE("Failed to create drm intel context");
return MOS_STATUS_UNKNOWN;
}
pContext->ctx_caps = -1;
}

pContext->intel_context->pOsContext = pContext;
Expand Down Expand Up @@ -4073,6 +4082,12 @@ MOS_STATUS Mos_Specific_CreateGpuContext(
MOS_OS_CHK_STATUS_RETURN(gpuContextSpecific->Init(gpuContextMgr->GetOsContext()));

pOsContextSpecific->SetGpuContextHandle(mosGpuCxt, gpuContextSpecific->GetGpuContextHandle());

if (typeid(*createOption) == typeid(MOS_GPUCTX_CREATOPTIONS_ENHANCED))
{
PMOS_GPUCTX_CREATOPTIONS_ENHANCED createOptionEnhanced = static_cast<PMOS_GPUCTX_CREATOPTIONS_ENHANCED>(createOption);
gpuContextSpecific->SetContextParam(createOptionEnhanced);
}
}

return MOS_STATUS_SUCCESS;
Expand Down Expand Up @@ -6008,7 +6023,7 @@ MOS_STATUS Mos_Specific_InitInterface(
MOS_OS_NORMALMESSAGE("mm:Mos_Specific_InitInterface called.");

pOsInterface->modularizedGpuCtxEnabled = true;
pOsInterface->veDefaultEnable = false;
pOsInterface->veDefaultEnable = true;

// Create Linux OS Context
pOsContext = (PMOS_OS_CONTEXT)MOS_AllocAndZeroMemory(sizeof(MOS_OS_CONTEXT));
Expand Down Expand Up @@ -6052,6 +6067,7 @@ MOS_STATUS Mos_Specific_InitInterface(

OsContextSpecific *pOsContextSpecific = static_cast<OsContextSpecific *>(pOsInterface->osContextPtr);
pOsContext->intel_context = pOsContextSpecific->GetDrmContext();
pOsContext->ctx_caps = -1;
pOsContext->pGmmClientContext = nullptr;
}
else
Expand Down
1 change: 1 addition & 0 deletions media_driver/linux/common/os/mos_os_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ struct _MOS_OS_CONTEXT
// Controlled OS resources (for analysis)
MOS_BUFMGR *bufmgr;
MOS_LINUX_CONTEXT *intel_context;
__u64 ctx_caps;
uint32_t uEnablePerfTag; //!< 0: Do not pass PerfTag to KMD, perf data collection disabled;
//!< 1: Pass PerfTag to MVP driver, perf data collection enabled;
//!< 2: Pass PerfTag to DAPC driver, perf data collection enabled;
Expand Down
2 changes: 1 addition & 1 deletion media_driver/linux/gen11/ddi/media_sku_wa_g11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static bool InitIclMediaSku(struct GfxDeviceInfo *devInfo,
MEDIA_WR_SKU(skuTable, FtrVp10BitSupport, 1);
MEDIA_WR_SKU(skuTable, FtrVp16BitSupport, 0);

MEDIA_WR_SKU(skuTable, FtrContextBasedScheduling, 0);
MEDIA_WR_SKU(skuTable, FtrContextBasedScheduling, 1);

MEDIA_WR_SKU(skuTable, FtrTileY, 1);

Expand Down

0 comments on commit 7fe0bd2

Please sign in to comment.