Skip to content

Commit

Permalink
Set subslice mask according to the per-context option. Fixed intel#267.
Browse files Browse the repository at this point in the history
  • Loading branch information
zxye authored and cchunbo committed Dec 5, 2018
1 parent e2e9a81 commit 1705eec
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 21 deletions.
7 changes: 5 additions & 2 deletions media_driver/linux/common/os/libdrm/include/mos_bufmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,6 @@ int mos_get_context_param_sseu(struct mos_linux_context *ctx,
int mos_set_context_param_sseu(struct mos_linux_context *ctx,
struct drm_i915_gem_context_param_sseu sseu);

int mos_get_slice_mask(uint32_t slice_count);

int mos_get_context_param(struct mos_linux_context *ctx,
uint32_t size,
uint64_t param,
Expand All @@ -356,6 +354,11 @@ int mos_set_context_param(struct mos_linux_context *ctx,

int mos_get_subslice_total(int fd, unsigned int *subslice_total);
int mos_get_eu_total(int fd, unsigned int *eu_total);
int mos_get_subslice_mask(int fd, unsigned int *subslice_mask);
int mos_get_slice_mask(int fd, unsigned int *slice_mask);
uint8_t mos_switch_off_n_bits(uint8_t in_mask, int n);
unsigned int mos_hweight8(uint8_t w);

#if defined(__cplusplus)
extern "C" {
#endif
Expand Down
74 changes: 63 additions & 11 deletions media_driver/linux/common/os/libdrm/mos_bufmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4527,23 +4527,42 @@ mos_get_reset_stats(struct mos_linux_context *ctx,
return ret;
}

int mos_get_slice_mask(uint32_t slice_count)
unsigned int mos_hweight8(uint8_t w)
{
uint32_t bitflag = 1;
uint32_t bitmask = 0;
uint32_t count = 0;
uint32_t i, weight = 0;

while (count < slice_count)
for (i=0; i<8; i++)
{
bitmask = bitflag;
bitflag = bitmask | (bitflag << 1);
count++;
weight += !!((w) & (1UL << i));
}
return weight;
}

uint8_t mos_switch_off_n_bits(uint8_t in_mask, int n)
{
int i,count;
uint8_t bi,out_mask;

return bitmask;
assert (n>0 && n<=8);

out_mask = in_mask;
count = n;
for(i=0; i<8; i++)
{
bi = 1UL<<i;
if (bi & in_mask)
{
out_mask &= ~bi;
count--;
}
if (count==0)
{
break;
}
}
return out_mask;
}

#if defined(MEDIA_EXT)
int
mos_get_context_param_sseu(struct mos_linux_context *ctx,
struct drm_i915_gem_context_param_sseu *sseu)
Expand All @@ -4560,6 +4579,7 @@ mos_get_context_param_sseu(struct mos_linux_context *ctx,
context_param.ctx_id = ctx->ctx_id;
context_param.param = I915_CONTEXT_PARAM_SSEU;
context_param.value = (uint64_t) sseu;
context_param.size = sizeof(struct drm_i915_gem_context_param_sseu);

ret = drmIoctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM,
Expand All @@ -4584,14 +4604,14 @@ mos_set_context_param_sseu(struct mos_linux_context *ctx,
context_param.ctx_id = ctx->ctx_id;
context_param.param = I915_CONTEXT_PARAM_SSEU;
context_param.value = (uint64_t) &sseu;
context_param.size = sizeof(struct drm_i915_gem_context_param_sseu);

ret = drmIoctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM,
&context_param);

return ret;
}
#endif

int
mos_get_context_param(struct mos_linux_context *ctx,
Expand Down Expand Up @@ -4680,6 +4700,38 @@ mos_get_subslice_total(int fd, unsigned int *subslice_total)
return 0;
}

int
mos_get_subslice_mask(int fd, unsigned int *subslice_mask)
{
drm_i915_getparam_t gp;
int ret;

memclear(gp);
gp.value = (int*)subslice_mask;
gp.param = I915_PARAM_SUBSLICE_MASK;
ret = drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
if (ret)
return -errno;

return 0;
}

int
mos_get_slice_mask(int fd, unsigned int *slice_mask)
{
drm_i915_getparam_t gp;
int ret;

memclear(gp);
gp.value = (int*)slice_mask;
gp.param = I915_PARAM_SLICE_MASK;
ret = drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
if (ret)
return -errno;

return 0;
}

int
mos_get_eu_total(int fd, unsigned int *eu_total)
{
Expand Down
39 changes: 33 additions & 6 deletions media_driver/linux/common/os/mos_context_specific.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,24 +475,42 @@ void OsContextSpecific::SetSliceCount(uint32_t *pSliceCount)
}
}

struct drm_i915_gem_context_param_sseu sseu = { .flags = I915_EXEC_RENDER };
sseu.value = m_sseu;
sliceMask = mos_get_slice_mask(sliceCount);
struct drm_i915_gem_context_param_sseu sseu;
MOS_ZeroMemory(&sseu, sizeof(sseu));
sseu.engine_class = 0;
sseu.instance = 0;

if (sliceMask != sseu.packed.slice_mask)
if (sliceCount != mos_hweight8(m_sseu.slice_mask))
{
if (mos_get_context_param_sseu(m_intelContext, &sseu))
{
MOS_OS_ASSERTMESSAGE("Failed to get context parameter.");
return ;
};
sseu.packed.slice_mask = sliceMask;

unsigned int device_slice_mask;
if (mos_get_slice_mask(m_fd, &device_slice_mask))
{
MOS_OS_ASSERTMESSAGE("Failed to get device slice mask.");
return ;
}

if (mos_hweight8(device_slice_mask) > sliceCount)
{
sseu.slice_mask = mos_switch_off_n_bits((uint8_t)device_slice_mask,
mos_hweight8(device_slice_mask) - sliceCount);
}
else
{
sseu.slice_mask = device_slice_mask;
}

if (mos_set_context_param_sseu(m_intelContext, sseu))
{
MOS_OS_ASSERTMESSAGE("Failed to set context parameter.");
return ;
}
m_sseu = sseu.value;
m_sseu = sseu;
}

*pSliceCount = sliceCount;
Expand Down Expand Up @@ -589,6 +607,15 @@ MOS_STATUS OsContextSpecific::Init(PMOS_CONTEXT pOsDriverContext)
MOS_OS_ASSERTMESSAGE("Failed to create drm intel context");
return MOS_STATUS_UNKNOWN;
}

MOS_ZeroMemory(&m_sseu, sizeof(m_sseu));
m_sseu.engine_class = 0;
m_sseu.instance = 0;
if (mos_get_context_param_sseu(m_intelContext, &m_sseu))
{
MOS_OS_ASSERTMESSAGE("Failed to get context parameter sseu.");
return MOS_STATUS_UNKNOWN;
};
#else
m_intelContext = nullptr;
#endif
Expand Down
2 changes: 1 addition & 1 deletion media_driver/linux/common/os/mos_context_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class OsContextSpecific : public OsContext
//!
//! \brief sseu for current context
//!
uint64_t m_sseu = 0;
struct drm_i915_gem_context_param_sseu m_sseu;
//!
//! \brief Semophore ID for ruling SSEU configration
//!
Expand Down
34 changes: 34 additions & 0 deletions media_driver/linux/common/os/mos_os_specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -4111,6 +4111,40 @@ MOS_STATUS Mos_Specific_CreateGpuContext(
pOsContextSpecific->SetGpuContextHandle(mosGpuCxt, gpuContextSpecific->GetGpuContextHandle());
}

MOS_OS_CHK_NULL_RETURN(createOption);
if (GpuNode == MOS_GPU_NODE_3D && createOption->SSEUValue != 0)
{
unsigned int subslice_mask;
struct drm_i915_gem_context_param_sseu sseu;
MOS_ZeroMemory(&sseu, sizeof(sseu));
sseu.engine_class = I915_ENGINE_CLASS_RENDER;
sseu.instance = 0;

if (mos_get_context_param_sseu(pOsInterface->pOsContext->intel_context, &sseu))
{
MOS_OS_ASSERTMESSAGE("Failed to get sseu configuration.");
return MOS_STATUS_UNKNOWN;
};

if (mos_get_subslice_mask(pOsInterface->pOsContext->fd, &subslice_mask))
{
MOS_OS_ASSERTMESSAGE("Failed to get subslice mask.");
return MOS_STATUS_UNKNOWN;
}

if (mos_hweight8(sseu.subslice_mask) > createOption->packed.SubSliceCount)
{
sseu.subslice_mask = mos_switch_off_n_bits(subslice_mask,
mos_hweight8((uint8_t)subslice_mask)-createOption->packed.SubSliceCount);
}

if (mos_set_context_param_sseu(pOsInterface->pOsContext->intel_context, sseu))
{
MOS_OS_ASSERTMESSAGE("Failed to set sseu configuration.");
return MOS_STATUS_UNKNOWN;
};
}

return MOS_STATUS_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion media_driver/linux/ult/libdrm_mock/xf86drm_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ mosdrmIoctl(int fd, unsigned long request, void *arg)
case DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM:
case DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM:
{
ret = -1;
ret = 0;
}
break;
default:
Expand Down

0 comments on commit 1705eec

Please sign in to comment.