Skip to content

Commit 0c4574a

Browse files
authored
Update MDAPI Checks for xe Kernel Driver (intel#396)
* update README for xe kernel driver * print non-error cliloader output to stdout * update MDAPI permission checks for xe kernel driver
1 parent 7d0c64c commit 0c4574a

File tree

7 files changed

+81
-44
lines changed

7 files changed

+81
-44
lines changed

cliloader/cliloader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ static bool parseArguments(int argc, char *argv[])
594594
)
595595
{
596596
std::string defaultDumpDir = getDefaultDumpDirectory();
597-
fprintf(stdout,
597+
printf(
598598
"cliloader - A utility to simplify using the Intercept Layer for OpenCL Applications\n"
599599
" Version: %s%s%s\n"
600600
"\n"

cliloader/printcontrols.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ static void printControls()
5151
{
5252
if (control.IsSeparator)
5353
{
54-
fprintf(stdout, "%s\n", control.Name);
55-
fprintf(stdout, "========================================\n\n");
54+
printf("%s\n", control.Name);
55+
printf("========================================\n\n");
5656
}
5757
else
5858
{
59-
fprintf(stdout, "%s (%s):\n", control.Name, control.Type);
60-
fprintf(stdout, "%s\n\n", control.Description);
59+
printf("%s (%s):\n", control.Name, control.Type);
60+
printf("%s\n\n", control.Description);
6161
}
6262
}
6363
}

cliloader/printmetrics.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ static bool printMetricsForDevice(IMetricsDeviceLatest* pMetricsDevice)
9393
continue;
9494
}
9595

96-
fprintf(stderr, "\nMetric Group: %s (%d Metric Set%s)\n",
96+
printf("\nMetric Group: %s (%d Metric Set%s)\n",
9797
pGroupParams->Description,
9898
pGroupParams->MetricSetsCount,
9999
pGroupParams->MetricSetsCount > 1 ? "s" : "");
100-
fprintf(stderr, "========================================\n\n");
100+
printf("========================================\n\n");
101101

102102
for (uint32_t ms = 0; ms < pGroupParams->MetricSetsCount; ms++)
103103
{
@@ -109,11 +109,11 @@ static bool printMetricsForDevice(IMetricsDeviceLatest* pMetricsDevice)
109109
continue;
110110
}
111111

112-
fprintf(stderr, "Metric Set: %s (%d Metric%s)\n",
112+
printf("Metric Set: %s (%d Metric%s)\n",
113113
pSetParams->ShortName,
114114
pSetParams->MetricsCount,
115115
pSetParams->MetricsCount > 1 ? "s" : "");
116-
fprintf(stderr, "----------------------------------------\n\n");
116+
printf("----------------------------------------\n\n");
117117

118118
for (uint32_t m = 0; m < pSetParams->MetricsCount; m++)
119119
{
@@ -124,7 +124,7 @@ static bool printMetricsForDevice(IMetricsDeviceLatest* pMetricsDevice)
124124
continue;
125125
}
126126

127-
fprintf(stderr,
127+
printf(
128128
"%s\\%s (%s):\n"
129129
"%s\n\n",
130130
pSetParams->SymbolName,
@@ -165,7 +165,7 @@ static bool printMetricsForAdapterGroup(void* pLibrary, bool devicesOnly)
165165
return false;
166166
}
167167

168-
fprintf(stderr, "MDAPI Headers: v%d.%d.%d, MDAPI Lib: v%d.%d.%d\n",
168+
printf("MDAPI Headers: v%d.%d.%d, MDAPI Lib: v%d.%d.%d\n",
169169
MD_API_MAJOR_NUMBER_CURRENT,
170170
MD_API_MINOR_NUMBER_CURRENT,
171171
MD_API_BUILD_NUMBER_CURRENT,
@@ -179,7 +179,7 @@ static bool printMetricsForAdapterGroup(void* pLibrary, bool devicesOnly)
179179
}
180180
else
181181
{
182-
fprintf(stderr, "Found %u MDAPI Adapter%s:\n",
182+
printf("Found %u MDAPI Adapter%s:\n",
183183
pAdapterGroupParams->AdapterCount,
184184
pAdapterGroupParams->AdapterCount > 1 ? "s" : "");
185185
for (uint32_t a = 0; a < pAdapterGroupParams->AdapterCount; a++)
@@ -198,11 +198,11 @@ static bool printMetricsForAdapterGroup(void* pLibrary, bool devicesOnly)
198198
continue;
199199
}
200200

201-
fprintf(stderr, "Adapter %u: %s (%s)\n",
201+
printf("Adapter %u: %s (%s)\n",
202202
a,
203203
pAdapterParams->ShortName,
204204
adapterTypeToString(pAdapterParams->Type));
205-
fprintf(stderr, "\tPCI Vendor Id: %04X, Device Id: %04X, Bus Info: %02X:%02X.%02X\n",
205+
printf("\tPCI Vendor Id: %04X, Device Id: %04X, Bus Info: %02X:%02X.%02X\n",
206206
pAdapterParams->VendorId,
207207
pAdapterParams->DeviceId,
208208
pAdapterParams->BusNumber,
@@ -227,17 +227,17 @@ static bool printMetricsForAdapterGroup(void* pLibrary, bool devicesOnly)
227227
continue;
228228
}
229229

230-
fprintf(stderr, "\nAdapter %u: %s (%s)\n",
230+
printf("\nAdapter %u: %s (%s)\n",
231231
a,
232232
pAdapterParams->ShortName,
233233
adapterTypeToString(pAdapterParams->Type));
234-
fprintf(stderr, "\tPCI Vendor Id: %04X, Device Id: %04X, Bus Info: %02X:%02X.%02X\n",
234+
printf("\tPCI Vendor Id: %04X, Device Id: %04X, Bus Info: %02X:%02X.%02X\n",
235235
pAdapterParams->VendorId,
236236
pAdapterParams->DeviceId,
237237
pAdapterParams->BusNumber,
238238
pAdapterParams->DeviceNumber,
239239
pAdapterParams->FunctionNumber);
240-
fprintf(stderr, "########################################\n\n");
240+
printf("########################################\n\n");
241241

242242
IMetricsDeviceLatest* pMetricsDevice = NULL;
243243
res = pAdapter->OpenMetricsDevice(&pMetricsDevice);
@@ -303,7 +303,7 @@ static bool printMetricsForLegacyDevice(void* pLibrary)
303303
return false;
304304
}
305305

306-
fprintf(stderr, "MDAPI Headers: v%d.%d.%d, MDAPI Lib: v%d.%d.%d\n",
306+
printf("MDAPI Headers: v%d.%d.%d, MDAPI Lib: v%d.%d.%d\n",
307307
MD_API_MAJOR_NUMBER_CURRENT,
308308
MD_API_MINOR_NUMBER_CURRENT,
309309
MD_API_BUILD_NUMBER_CURRENT,

cliprof/cliprof.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static bool parseArguments(int argc, char *argv[])
282282
#endif
283283
)
284284
{
285-
fprintf(stdout,
285+
printf(
286286
"cliprof - A simple utility to enable profiling using the Intercept Layer for OpenCL Applications\n"
287287
" Version: %s%s%s\n"
288288
"\n"

docs/mdapi.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,41 @@ indices, use `cliloader` and pass the `--mdapi-devices` option.
110110
option.
111111
* Collecting MDAPI metrics currently requires elevated privileges
112112
because metrics are collected system-wide.
113-
* On Linux, MDAPI metrics may be enabled for non-root users
114-
by setting `/proc/sys/dev/i915/perf_stream_paranoid` to `0`:
113+
* On Linux, MDAPI metrics may be enabled for non-root users.
114+
The mechanism to do so depends on the kernel driver used for the GPU.
115+
To determine the kernel driver for your GPU, run:
115116

116117
```sh
117-
$ echo 0 > /proc/sys/dev/i915/perf_stream_paranoid
118+
$ lspci -nn -k | grep -Ei 'VGA|DISPLAY' -A2
119+
```
120+
121+
This will tell you if your kernel driver is the `i915` kernel driver or the
122+
`xe` kernel driver.
123+
124+
For the `i915` kernel driver, set `/proc/sys/dev/i915/perf_stream_paranoid`
125+
to `0`:
126+
127+
```sh
128+
$ echo 0 | sudo tee /proc/sys/dev/i915/perf_stream_paranoid
129+
```
130+
131+
or:
132+
133+
```sh
134+
$ sudo sysctl dev.i915.perf_stream_paranoid=0
135+
```
136+
137+
For the `xe` kernel driver, set `/proc/sys/dev/xe/observation_paranoid` to
138+
`0`:
139+
140+
```sh
141+
$ echo 0 | sudo tee /proc/sys/dev/xe/observation_paranoid
118142
```
119143

120144
or:
121145

122146
```sh
123-
$ sysctl dev.i915.perf_stream_paranoid=0
147+
$ sudo sysctl dev.xe.observation_paranoid=0
124148
```
125149

126150
For more information, see:

intercept/OS/OS_linux.h

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -199,35 +199,47 @@ inline bool Services::StopAubCapture(
199199
inline bool Services::CheckMDAPIPermissions(
200200
std::string& str ) const
201201
{
202-
const char* path = "/proc/sys/dev/i915/perf_stream_paranoid";
203-
bool available = false;
202+
const char* i915_path = "/proc/sys/dev/i915/perf_stream_paranoid";
203+
const char* xe_path = "/proc/sys/dev/xe/observation_paranoid";
204204

205-
uint64_t value = 1;
206-
int fd = open(path, 0);
207-
if( fd > 0 )
208-
{
209-
char buf[32];
210-
int n = read(fd, buf, sizeof(buf) - 1);
211-
close(fd);
212-
if( n > 0 )
205+
str.clear();
206+
207+
const auto readValueFromFile = [](const char* path) -> uint64_t {
208+
uint64_t value = 1;
209+
int fd = open(path, 0);
210+
if( fd > 0 )
213211
{
214-
buf[n] = 0;
215-
value = strtoull(buf, NULL, 0);
212+
char buf[32];
213+
int n = read(fd, buf, sizeof(buf) - 1);
214+
close(fd);
215+
216+
if( n > 0 )
217+
{
218+
buf[n] = 0;
219+
value = strtoull(buf, NULL, 0);
220+
}
216221
}
222+
return value;
223+
};
217224

218-
if( value == 0 || geteuid() == 0 )
225+
if( geteuid() != 0 )
226+
{
227+
uint64_t i915_value = readValueFromFile(i915_path);
228+
if (i915_value != 0)
219229
{
220-
available = true;
230+
str += "Warning: possibly insufficient permissions for MDAPI!"
231+
" Consider: sysctl dev.i915.perf_stream_paranoid=0\n";
221232
}
222-
}
223233

224-
if( available == false )
225-
{
226-
str = "Insufficient permissions for MDAPI!"
227-
" Consider: sysctl dev.i915.perf_stream_paranoid=0\n";
234+
uint64_t xe_value = readValueFromFile(xe_path);
235+
if (xe_value != 0)
236+
{
237+
str += "Warning: possibly insufficient permissions for MDAPI!"
238+
" Consider: sysctl dev.xe.observation_paranoid=0\n";
239+
}
228240
}
229241

230-
return available;
242+
return str.empty();
231243
}
232244

233245
}

intercept/mdapi/intercept_mdapi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ void CLIntercept::initCustomPerfCounters()
152152
{
153153
log( permissionString );
154154
}
155-
else if( config().DevicePerfCounterEventBasedSampling )
155+
156+
if( config().DevicePerfCounterEventBasedSampling )
156157
{
157158
m_pMDHelper = MetricsDiscovery::MDHelper::CreateEBS(
158159
config().DevicePerfCounterLibName,

0 commit comments

Comments
 (0)