Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MDAPI Checks for xe Kernel Driver #396

Merged
merged 3 commits into from
Dec 20, 2024
Merged
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: 1 addition & 1 deletion cliloader/cliloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ static bool parseArguments(int argc, char *argv[])
)
{
std::string defaultDumpDir = getDefaultDumpDirectory();
fprintf(stdout,
printf(
"cliloader - A utility to simplify using the Intercept Layer for OpenCL Applications\n"
" Version: %s%s%s\n"
"\n"
Expand Down
8 changes: 4 additions & 4 deletions cliloader/printcontrols.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ static void printControls()
{
if (control.IsSeparator)
{
fprintf(stdout, "%s\n", control.Name);
fprintf(stdout, "========================================\n\n");
printf("%s\n", control.Name);
printf("========================================\n\n");
}
else
{
fprintf(stdout, "%s (%s):\n", control.Name, control.Type);
fprintf(stdout, "%s\n\n", control.Description);
printf("%s (%s):\n", control.Name, control.Type);
printf("%s\n\n", control.Description);
}
}
}
26 changes: 13 additions & 13 deletions cliloader/printmetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ static bool printMetricsForDevice(IMetricsDeviceLatest* pMetricsDevice)
continue;
}

fprintf(stderr, "\nMetric Group: %s (%d Metric Set%s)\n",
printf("\nMetric Group: %s (%d Metric Set%s)\n",
pGroupParams->Description,
pGroupParams->MetricSetsCount,
pGroupParams->MetricSetsCount > 1 ? "s" : "");
fprintf(stderr, "========================================\n\n");
printf("========================================\n\n");

for (uint32_t ms = 0; ms < pGroupParams->MetricSetsCount; ms++)
{
Expand All @@ -109,11 +109,11 @@ static bool printMetricsForDevice(IMetricsDeviceLatest* pMetricsDevice)
continue;
}

fprintf(stderr, "Metric Set: %s (%d Metric%s)\n",
printf("Metric Set: %s (%d Metric%s)\n",
pSetParams->ShortName,
pSetParams->MetricsCount,
pSetParams->MetricsCount > 1 ? "s" : "");
fprintf(stderr, "----------------------------------------\n\n");
printf("----------------------------------------\n\n");

for (uint32_t m = 0; m < pSetParams->MetricsCount; m++)
{
Expand All @@ -124,7 +124,7 @@ static bool printMetricsForDevice(IMetricsDeviceLatest* pMetricsDevice)
continue;
}

fprintf(stderr,
printf(
"%s\\%s (%s):\n"
"%s\n\n",
pSetParams->SymbolName,
Expand Down Expand Up @@ -165,7 +165,7 @@ static bool printMetricsForAdapterGroup(void* pLibrary, bool devicesOnly)
return false;
}

fprintf(stderr, "MDAPI Headers: v%d.%d.%d, MDAPI Lib: v%d.%d.%d\n",
printf("MDAPI Headers: v%d.%d.%d, MDAPI Lib: v%d.%d.%d\n",
MD_API_MAJOR_NUMBER_CURRENT,
MD_API_MINOR_NUMBER_CURRENT,
MD_API_BUILD_NUMBER_CURRENT,
Expand All @@ -179,7 +179,7 @@ static bool printMetricsForAdapterGroup(void* pLibrary, bool devicesOnly)
}
else
{
fprintf(stderr, "Found %u MDAPI Adapter%s:\n",
printf("Found %u MDAPI Adapter%s:\n",
pAdapterGroupParams->AdapterCount,
pAdapterGroupParams->AdapterCount > 1 ? "s" : "");
for (uint32_t a = 0; a < pAdapterGroupParams->AdapterCount; a++)
Expand All @@ -198,11 +198,11 @@ static bool printMetricsForAdapterGroup(void* pLibrary, bool devicesOnly)
continue;
}

fprintf(stderr, "Adapter %u: %s (%s)\n",
printf("Adapter %u: %s (%s)\n",
a,
pAdapterParams->ShortName,
adapterTypeToString(pAdapterParams->Type));
fprintf(stderr, "\tPCI Vendor Id: %04X, Device Id: %04X, Bus Info: %02X:%02X.%02X\n",
printf("\tPCI Vendor Id: %04X, Device Id: %04X, Bus Info: %02X:%02X.%02X\n",
pAdapterParams->VendorId,
pAdapterParams->DeviceId,
pAdapterParams->BusNumber,
Expand All @@ -227,17 +227,17 @@ static bool printMetricsForAdapterGroup(void* pLibrary, bool devicesOnly)
continue;
}

fprintf(stderr, "\nAdapter %u: %s (%s)\n",
printf("\nAdapter %u: %s (%s)\n",
a,
pAdapterParams->ShortName,
adapterTypeToString(pAdapterParams->Type));
fprintf(stderr, "\tPCI Vendor Id: %04X, Device Id: %04X, Bus Info: %02X:%02X.%02X\n",
printf("\tPCI Vendor Id: %04X, Device Id: %04X, Bus Info: %02X:%02X.%02X\n",
pAdapterParams->VendorId,
pAdapterParams->DeviceId,
pAdapterParams->BusNumber,
pAdapterParams->DeviceNumber,
pAdapterParams->FunctionNumber);
fprintf(stderr, "########################################\n\n");
printf("########################################\n\n");

IMetricsDeviceLatest* pMetricsDevice = NULL;
res = pAdapter->OpenMetricsDevice(&pMetricsDevice);
Expand Down Expand Up @@ -303,7 +303,7 @@ static bool printMetricsForLegacyDevice(void* pLibrary)
return false;
}

fprintf(stderr, "MDAPI Headers: v%d.%d.%d, MDAPI Lib: v%d.%d.%d\n",
printf("MDAPI Headers: v%d.%d.%d, MDAPI Lib: v%d.%d.%d\n",
MD_API_MAJOR_NUMBER_CURRENT,
MD_API_MINOR_NUMBER_CURRENT,
MD_API_BUILD_NUMBER_CURRENT,
Expand Down
2 changes: 1 addition & 1 deletion cliprof/cliprof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static bool parseArguments(int argc, char *argv[])
#endif
)
{
fprintf(stdout,
printf(
"cliprof - A simple utility to enable profiling using the Intercept Layer for OpenCL Applications\n"
" Version: %s%s%s\n"
"\n"
Expand Down
32 changes: 28 additions & 4 deletions docs/mdapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,41 @@ indices, use `cliloader` and pass the `--mdapi-devices` option.
option.
* Collecting MDAPI metrics currently requires elevated privileges
because metrics are collected system-wide.
* On Linux, MDAPI metrics may be enabled for non-root users
by setting `/proc/sys/dev/i915/perf_stream_paranoid` to `0`:
* On Linux, MDAPI metrics may be enabled for non-root users.
The mechanism to do so depends on the kernel driver used for the GPU.
To determine the kernel driver for your GPU, run:

```sh
$ echo 0 > /proc/sys/dev/i915/perf_stream_paranoid
$ lspci -nn -k | grep -Ei 'VGA|DISPLAY' -A2
```

This will tell you if your kernel driver is the `i915` kernel driver or the
`xe` kernel driver.

For the `i915` kernel driver, set `/proc/sys/dev/i915/perf_stream_paranoid`
to `0`:

```sh
$ echo 0 | sudo tee /proc/sys/dev/i915/perf_stream_paranoid
```

or:

```sh
$ sudo sysctl dev.i915.perf_stream_paranoid=0
```

For the `xe` kernel driver, set `/proc/sys/dev/xe/observation_paranoid` to
`0`:

```sh
$ echo 0 | sudo tee /proc/sys/dev/xe/observation_paranoid
```

or:

```sh
$ sysctl dev.i915.perf_stream_paranoid=0
$ sudo sysctl dev.xe.observation_paranoid=0
```

For more information, see:
Expand Down
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
Loading