Skip to content

Commit

Permalink
[Media Common] add INTEL MEDIA ALLOC refineE to specify the memory al…
Browse files Browse the repository at this point in the history
…ignment

this key is used to allocate bigger pages
env variable INTEL_MEDIA_ALLOC_refineE also could be used
and was not enabled by default
mode 0 is default mode
mode 1 is < 64 align to 64
mode 2 is > 1M &&  <= 3M align to 1M, >3M align to 2M
mode 3 is mode 1 & mode 2
  • Loading branch information
XinfengZhang authored and intel-mediadev committed Dec 27, 2023
1 parent 95330b3 commit 765dd93
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 14 deletions.
75 changes: 62 additions & 13 deletions media_softlet/linux/common/os/i915/mos_bufmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ struct mos_bufmgr_gem {
int exec_count;

/** Array of lists of cached gem objects of power-of-two sizes */
struct mos_gem_bo_bucket cache_bucket[14 * 4];
struct mos_gem_bo_bucket cache_bucket[64];
int num_buckets;
time_t time;

Expand Down Expand Up @@ -3852,9 +3852,9 @@ add_bucket(struct mos_bufmgr_gem *bufmgr_gem, int size)
}

static void
init_cache_buckets(struct mos_bufmgr_gem *bufmgr_gem)
init_cache_buckets(struct mos_bufmgr_gem *bufmgr_gem, uint8_t alloc_mode)
{
unsigned long size, cache_max_size = 64 * 1024 * 1024;
unsigned long size, cache_max_size = 64 * 1024 * 1024, unit_size;

/* OK, so power of two buckets was too wasteful of memory.
* Give 3 other sizes between each power of two, to hopefully
Expand All @@ -3864,17 +3864,63 @@ init_cache_buckets(struct mos_bufmgr_gem *bufmgr_gem)
* width/height alignment and rounding of sizes to pages will
* get us useful cache hit rates anyway)
*/
add_bucket(bufmgr_gem, 4096);
add_bucket(bufmgr_gem, 4096 * 2);
add_bucket(bufmgr_gem, 4096 * 3);
/* alloc_mode 0 is default alloc_mode
* alloc_mode 1 rounding up to 64K for all < 1M
* alloc_mode 2 rounding up to 2M for size> 1M
* alloc_mode 3 rounding up to 2M for size > 1M and 64K for size <= 1M */
if( alloc_mode > 3 )
alloc_mode = 0;

if ( 0 == alloc_mode || 2 == alloc_mode)
{
// < 1M normal alloc_mode
add_bucket(bufmgr_gem, 4096);
add_bucket(bufmgr_gem, 4096 * 2);
add_bucket(bufmgr_gem, 4096 * 3);
/* Initialize the linked lists for BO reuse cache. */
for (size = 4 * 4096; size < 1024 * 1024; size *= 2) {
add_bucket(bufmgr_gem, size);
add_bucket(bufmgr_gem, size + size * 1 / 4);
add_bucket(bufmgr_gem, size + size * 2 / 4);
add_bucket(bufmgr_gem, size + size * 3 / 4);
}

/* Initialize the linked lists for BO reuse cache. */
for (size = 4 * 4096; size <= cache_max_size; size *= 2) {
add_bucket(bufmgr_gem, size);
add_bucket(bufmgr_gem, 1024 * 1024);
}
if (1 == alloc_mode || 3 == alloc_mode)
{
// < 1M 64k alignment
unit_size = 64 * 1024;
for (size = unit_size; size <= 1024 * 1024; size += unit_size)
{
add_bucket(bufmgr_gem, size);
}
}
if( 0 == alloc_mode || 1 == alloc_mode)
{
//> 1M is normal alloc_mode
add_bucket(bufmgr_gem, 1280 * 1024);
add_bucket(bufmgr_gem, 1536 * 1024);
add_bucket(bufmgr_gem, 1792 * 1024);

for (size = 2 * 1024 * 1024; size < cache_max_size; size *= 2) {
add_bucket(bufmgr_gem, size);
add_bucket(bufmgr_gem, size + size * 1 / 4);
add_bucket(bufmgr_gem, size + size * 2 / 4);
add_bucket(bufmgr_gem, size + size * 3 / 4);
}
}
if( 2 == alloc_mode || 3 == alloc_mode)
{
//> 1M rolling to 2M
unit_size = 2 * 1024 * 1024;
add_bucket(bufmgr_gem, unit_size);
add_bucket(bufmgr_gem, 3 * 1024 * 1024);

add_bucket(bufmgr_gem, size + size * 1 / 4);
add_bucket(bufmgr_gem, size + size * 2 / 4);
add_bucket(bufmgr_gem, size + size * 3 / 4);
for (size = 4 * 1024 * 1024; size <= cache_max_size; size += unit_size)
{
add_bucket(bufmgr_gem, size);
}
}
}

Expand Down Expand Up @@ -5100,6 +5146,7 @@ mos_bufmgr_gem_init_i915(int fd, int batch_size)
struct drm_i915_gem_get_aperture aperture;
drm_i915_getparam_t gp;
int ret, tmp;
uint8_t alloc_mode;
bool exec2 = false;

pthread_mutex_lock(&bufmgr_list_mutex);
Expand Down Expand Up @@ -5352,10 +5399,12 @@ mos_bufmgr_gem_init_i915(int fd, int batch_size)
*
* Every 4 was too few for the blender benchmark.
*/
alloc_mode = (uint8_t)(batch_size & 0xff);
batch_size &= 0xffffff00;
bufmgr_gem->max_relocs = batch_size / sizeof(uint32_t) / 2 - 2;

DRMINITLISTHEAD(&bufmgr_gem->named);
init_cache_buckets(bufmgr_gem);
init_cache_buckets(bufmgr_gem,alloc_mode);

DRMLISTADD(&bufmgr_gem->managers, &bufmgr_list);

Expand Down
1 change: 1 addition & 0 deletions media_softlet/linux/common/os/i915_production/mos_bufmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -5403,6 +5403,7 @@ mos_bufmgr_gem_init_i915(int fd, int batch_size)
*
* Every 4 was too few for the blender benchmark.
*/
batch_size &= 0xffffff00;
bufmgr_gem->max_relocs = batch_size / sizeof(uint32_t) / 2 - 2;

DRMINITLISTHEAD(&bufmgr_gem->named);
Expand Down
21 changes: 20 additions & 1 deletion media_softlet/linux/common/os/mos_context_specific_next.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ MOS_STATUS OsContextSpecificNext::Init(DDI_DEVICE_CONTEXT ddiDriverContext)
uint32_t iDeviceId = 0;
MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
uint32_t value = 0;
uint32_t mode = 0;
MediaUserSettingSharedPtr userSettingPtr = nullptr;

MOS_OS_FUNCTION_ENTER;
Expand All @@ -89,7 +90,25 @@ MOS_STATUS OsContextSpecificNext::Init(DDI_DEVICE_CONTEXT ddiDriverContext)

userSettingPtr = MosInterface::MosGetUserSettingInstance(osDriverContext);

m_bufmgr = mos_bufmgr_gem_init(m_fd, BATCH_BUFFER_SIZE, &m_deviceType);
mode = BATCH_BUFFER_SIZE;
ReadUserSetting(
userSettingPtr,
value,
"INTEL MEDIA ALLOC MODE",
MediaUserSetting::Group::Device);

if (value)
{
mode |= (value & 0x000000ff);
}
value = 0;
/* no need to set batch buffer size after switch to softpin
* keep it, just for test during relocation to softpin transition
* now , it could be a debug method , but is actually useless
* so it is safe to reuse the lowest 8bit to convey addtional information
* more suitable solution is deleting it , or add additional parameter*/

m_bufmgr = mos_bufmgr_gem_init(m_fd, (int)mode, &m_deviceType);
if (nullptr == m_bufmgr)
{
MOS_OS_ASSERTMESSAGE("Not able to allocate buffer manager, fd=0x%d", m_fd);
Expand Down
7 changes: 7 additions & 0 deletions media_softlet/linux/common/os/mos_user_setting_specific.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ MOS_STATUS MosUserSetting::InitMosUserSettingSpecific(MediaUserSettingSharedPtr
0,
true); //"Enable VM Bind."

DeclareUserSettingKey(
userSettingPtr,
"INTEL MEDIA ALLOC MODE",
MediaUserSetting::Group::Device,
0,
false); //

return MOS_STATUS_SUCCESS;
}

0 comments on commit 765dd93

Please sign in to comment.