Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions media_driver/linux/ult/inc/devconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,4 @@ typedef enum
igfx_MAX = 4,
} Platform_t;

extern const char *g_platformName[];

#endif // __DEVCONFIG_H__
2 changes: 0 additions & 2 deletions media_driver/linux/ult/ult_app/cm/cm_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ class CmTest: public testing::Test
result &= (function_return == expected_return);

ReleaseMockDevice();

MemoryLeakDetector::Detect(m_driverLoader, platforms[i]);
}
return result;
}//===============
Expand Down
2 changes: 0 additions & 2 deletions media_driver/linux/ult/ult_app/ddi_test_caps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,5 @@ TEST_F(MediaCapsDdiTest, DecodeEncodeProfile)
ret = m_driverLoader.CloseDriver();
EXPECT_EQ (VA_STATUS_SUCCESS , ret) << "Platform = " << g_platformName[platforms[i]]
<< ", Failed function = m_driverLoader.CloseDriver" << endl;

MemoryLeakDetector::Detect(m_driverLoader, platforms[i]);
}
}
1 change: 0 additions & 1 deletion media_driver/linux/ult/ult_app/ddi_test_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ void MediaDecodeDdiTest::ExectueDecodeTest(DecTestData *pDecData)
{
CmdValidator::GpuCmdsValidationInit(m_GpuCmdFactory, platforms[i]);
DecodeExecute(pDecData, platforms[i]);
MemoryLeakDetector::Detect(m_driverLoader, platforms[i]);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion media_driver/linux/ult/ult_app/ddi_test_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ void MediaEncodeDdiTest::ExectueEncodeTest(EncTestData *pEncData)
{
CmdValidator::GpuCmdsValidationInit(m_GpuCmdFactory, platforms[i]);
EncodeExecute(pEncData, platforms[i]);
MemoryLeakDetector::Detect(m_driverLoader, platforms[i]);
}
}
}
Expand Down
16 changes: 13 additions & 3 deletions media_driver/linux/ult/ult_app/driver_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <stdlib.h>
#include <unistd.h>
#include "driver_loader.h"
#include "memory_leak_detector.h"

using namespace std;

Expand Down Expand Up @@ -78,28 +79,37 @@ DriverDllLoader::DriverDllLoader(char *path)
m_driver_path = path;
}

VAStatus DriverDllLoader::CloseDriver()
VAStatus DriverDllLoader::CloseDriver(bool detectMemLeak)
{
VAStatus vaStatus = m_ctx.vtable->vaTerminate(&m_ctx);

if (detectMemLeak)
{
MemoryLeakDetector::Detect(m_drvSyms.MOS_GetMemNinjaCounter(),
m_drvSyms.MOS_GetMemNinjaCounterGfx(),
m_currentPlatform);
}

m_drvSyms.Clear();

if(m_umdhandle)
{
dlclose(m_umdhandle);
m_umdhandle = nullptr;
}

return vaStatus;
}

VAStatus DriverDllLoader::InitDriver(int platform_id)
VAStatus DriverDllLoader::InitDriver(Platform_t platform_id)
{
int drm_fd = platform_id + 1 < 0 ? 1 : platform_id + 1;
m_drmstate.fd = drm_fd;
m_drmstate.auth_type = 3;
m_ctx.vtable = &m_vtable;
m_ctx.vtable_vpp = &m_vtable_vpp;
m_ctx.drm_state = &m_drmstate;
m_currentPlatform = platform_id;

if (LoadDriverSymbols() != VA_STATUS_SUCCESS)
{
Expand All @@ -115,7 +125,7 @@ VAStatus DriverDllLoader::LoadDriverSymbols()
const int buf_len = 256;
char init_func_s[buf_len] = {};

m_umdhandle = dlopen(m_driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
m_umdhandle = dlopen(m_driver_path, RTLD_NOW | RTLD_GLOBAL);
if (!m_umdhandle)
{
printf("ERROR: dlopen of %s failed.\n", m_driver_path);
Expand Down
17 changes: 9 additions & 8 deletions media_driver/linux/ult/ult_app/driver_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct DriverSymbols
void Clear()
Copy link
Contributor

@dvrogozh dvrogozh Aug 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Folks, I strongly suggest to remove constructor and Clear() entirely, You have class with all public members. C++11 already has a way to reset a structure to default value-initialization which is: m_drvSyms = {}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching this, "m_drvSyms = {}" is much better than a Clear function.

{
auto p = (const void **)this;
for (auto i = 0; i < sizeof(this) / sizeof(const void *); i++)
for (auto i = 0; i < sizeof(*this) / sizeof(const void *); i++)
{
p[i] = nullptr;
}
Expand All @@ -96,7 +96,7 @@ struct DriverSymbols
bool Initialized() const
{
auto p = (const void * const *)this;
for (auto i = 0; i < sizeof(this) / sizeof(const void *); i++)
for (auto i = 0; i < sizeof(*this) / sizeof(const void *); i++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Folks, please, remove this and check pointers directly. This is simply a freak over complex implementation of very simple thing: check 5 pointers that they are not NULL. You don't need any loop here!!

Copy link
Contributor Author

@walter-bai walter-bai Aug 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, checking 5 pointers is simpler and easier to understand than previous code.

{
if (p[i] == nullptr)
{
Expand Down Expand Up @@ -131,9 +131,9 @@ class DriverDllLoader

const DriverSymbols &GetDriverSymbols() const { return m_drvSyms; }

VAStatus InitDriver(int platform_id);
VAStatus InitDriver(Platform_t platform_id);

VAStatus CloseDriver();
VAStatus CloseDriver(bool detectMemLeak = true);

public:

Expand All @@ -147,11 +147,12 @@ class DriverDllLoader

private:

const char *m_driver_path;
void *m_umdhandle;
DriverSymbols m_drvSyms;
const char *m_driver_path = nullptr;
void *m_umdhandle = nullptr;
DriverSymbols m_drvSyms = {};
drm_state m_drmstate = {};
Platform_t m_currentPlatform = igfxSKLAKE;
std::vector<Platform_t> m_platformArray;
drm_state m_drmstate;
};

#endif // __DRIVER_LOADER_H__
4 changes: 1 addition & 3 deletions media_driver/linux/ult/ult_app/memory_leak_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

using namespace std;

void MemoryLeakDetector::Detect(const DriverDllLoader &drvLoader, Platform_t platform)
void MemoryLeakDetector::Detect(int32_t memNinjaCnt, int32_t memNinjaCntGfx, Platform_t platform)
{
static bool delReport = true;
if (delReport)
Expand All @@ -34,8 +34,6 @@ void MemoryLeakDetector::Detect(const DriverDllLoader &drvLoader, Platform_t pla
delReport = false;
}

int32_t memNinjaCnt = drvLoader.GetDriverSymbols().MOS_GetMemNinjaCounter();
int32_t memNinjaCntGfx = drvLoader.GetDriverSymbols().MOS_GetMemNinjaCounterGfx();
if (memNinjaCnt != 0 || memNinjaCntGfx != 0)
{
const ::testing::TestInfo* curTest = ::testing::UnitTest::GetInstance()->current_test_info();
Expand Down
4 changes: 2 additions & 2 deletions media_driver/linux/ult/ult_app/memory_leak_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include <map>
#include <vector>
#include "driver_loader.h"
#include "devconfig.h"

#define LOG_PATH "./igd_0.log"
#define HLT_PATH "./igd_0.hlt"
Expand Down Expand Up @@ -52,7 +52,7 @@ class MemoryLeakDetector
{
public:

static void Detect(const DriverDllLoader &drvLoader, Platform_t platform);
static void Detect(int32_t memNinjaCnt, int32_t memNinjaCntGfx, Platform_t platform);
};

class MemoryLeakDetectorIpl
Expand Down