Skip to content

Commit

Permalink
update MDAPI permission checks for xe kernel driver
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbaug committed Dec 19, 2024
1 parent ff50284 commit 9e72940
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
52 changes: 32 additions & 20 deletions intercept/OS/OS_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,35 +199,47 @@ inline bool Services::StopAubCapture(
inline bool Services::CheckMDAPIPermissions(
std::string& str ) const
{
const char* path = "/proc/sys/dev/i915/perf_stream_paranoid";
bool available = false;
const char* i915_path = "/proc/sys/dev/i915/perf_stream_paranoid";
const char* xe_path = "/proc/sys/dev/xe/observation_paranoid";

uint64_t value = 1;
int fd = open(path, 0);
if( fd > 0 )
{
char buf[32];
int n = read(fd, buf, sizeof(buf) - 1);
close(fd);
if( n > 0 )
str.clear();

const auto readValueFromFile = [](const char* path) -> uint64_t {
uint64_t value = 1;
int fd = open(path, 0);
if( fd > 0 )
{
buf[n] = 0;
value = strtoull(buf, NULL, 0);
char buf[32];
int n = read(fd, buf, sizeof(buf) - 1);
close(fd);

if( n > 0 )
{
buf[n] = 0;
value = strtoull(buf, NULL, 0);
}
}
return value;
};

if( value == 0 || geteuid() == 0 )
if( geteuid() != 0 )
{
uint64_t i915_value = readValueFromFile(i915_path);
if (i915_value != 0)
{
available = true;
str += "Warning: possibly insufficient permissions for MDAPI!"
" Consider: sysctl dev.i915.perf_stream_paranoid=0\n";
}
}

if( available == false )
{
str = "Insufficient permissions for MDAPI!"
" Consider: sysctl dev.i915.perf_stream_paranoid=0\n";
uint64_t xe_value = readValueFromFile(xe_path);
if (xe_value != 0)
{
str += "Warning: possibly insufficient permissions for MDAPI!"
" Consider: sysctl dev.xe.observation_paranoid=0\n";
}
}

return available;
return str.empty();
}

}
3 changes: 2 additions & 1 deletion intercept/mdapi/intercept_mdapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ void CLIntercept::initCustomPerfCounters()
{
log( permissionString );
}
else if( config().DevicePerfCounterEventBasedSampling )

if( config().DevicePerfCounterEventBasedSampling )
{
m_pMDHelper = MetricsDiscovery::MDHelper::CreateEBS(
config().DevicePerfCounterLibName,
Expand Down

0 comments on commit 9e72940

Please sign in to comment.