NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
telemetry_dpa_sample.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2025 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #include <doca_error.h>
27 #include <doca_log.h>
28 #include <doca_dev.h>
29 #include <doca_telemetry_dpa.h>
30 #include <errno.h>
31 #include <math.h>
32 #include <time.h>
33 #include <unistd.h>
34 
35 #include "common.h"
36 #include "telemetry_dpa_sample.h"
37 
38 DOCA_LOG_REGISTER(TELEMETRY_DPA::SAMPLE);
39 
41  struct doca_telemetry_dpa *telemetry_dpa_obj; /* doca telemetry dpa perf object*/
42  struct doca_dev *dev; /* Doca device*/
43  doca_telemetry_dpa_process_info_t *dpa_process_list; /* Structure that represent the DPA process running */
44  doca_telemetry_dpa_thread_info_t *dpa_thread_list; /* Structure that represent the DPA threads running */
45  doca_telemetry_dpa_cumul_info_t *cumul_info_list; /* Structure that represent the DPA cumul counter results */
46  doca_telemetry_dpa_event_sample_t *event_info_list; /* Structure that represent the DPA perf event results */
47  uint32_t process_id;
48  uint32_t thread_id;
49  uint32_t dpa_process_num;
50  uint32_t dpa_timer_freq;
51  uint32_t dpa_threads_num;
52  uint32_t cumul_samples_num;
54 };
55 
56 /*
57  * Return perf event type description string
58  *
59  * @event_sample_type [in]: Event type to match
60  * @return: String that describes the perf event type
61  */
63 {
64  switch (event_sample_type) {
66  return "Event sample type empty sample";
68  return "Event sample type schedule in";
70  return "Event sample type schedule out";
72  return "Event sample type buffer full";
73  default:
74  return "Unrecognized event sample type";
75  }
76 }
77 
78 /*
79  * Print process list
80  *
81  * Print the contents of the extracted process list.
82  *
83  * @dpa_process_num [in]: Number of DPA process list to print
84  * @dpa_process_list [in]: Extracted list to print
85  * @return: DOCA_SUCCESS in case of success, DOCA_ERROR otherwise
86  */
87 static doca_error_t telemetry_dpa_print_process_list(uint32_t dpa_process_num,
88  doca_telemetry_dpa_process_info_t *dpa_process_list)
89 {
90  if (dpa_process_list == NULL) {
91  DOCA_LOG_ERR("Failed to print processes list: parameter dpa_process_list=NULL");
93  }
94 
95  if (dpa_process_num == 0) {
96  DOCA_LOG_ERR("Failed to print processes list: no processes found in context");
98  }
99 
100  DOCA_LOG_INFO("Number of processes extracted: %u", dpa_process_num);
101  DOCA_LOG_INFO("Extracted process list:");
102  for (uint32_t idx = 0; idx < dpa_process_num; idx++) {
103  DOCA_LOG_INFO(" dpa_process_id=%u", dpa_process_list[idx].dpa_process_id);
104  DOCA_LOG_INFO(" num_of_threads=%u", dpa_process_list[idx].num_of_threads);
105  DOCA_LOG_INFO(" process_name=%s", dpa_process_list[idx].process_name);
106  }
107 
108  return DOCA_SUCCESS;
109 }
110 
111 /*
112  * Print thread list
113  *
114  * Print the contents of the extracted thread list.
115  *
116  * @dpa_threads_num [in]: Number of DPA threads list to print
117  * @dpa_process_list [in]: Extracted list to print
118  * @return: DOCA_SUCCESS in case of success, DOCA_ERROR otherwise
119  */
120 static doca_error_t telemetry_dpa_print_thread_list(uint32_t dpa_threads_num,
121  doca_telemetry_dpa_thread_info_t *dpa_thread_list)
122 {
123  if (dpa_thread_list == NULL) {
124  DOCA_LOG_ERR("Failed to print thread list: parameter dpa_thread_list=NULL");
126  }
127 
128  if (dpa_threads_num == 0) {
129  DOCA_LOG_ERR("Failed to print thread list: no threads found in context");
131  }
132 
133  DOCA_LOG_INFO("Number of threads extracted: %u", dpa_threads_num);
134  DOCA_LOG_INFO("Extracted thread list:");
135  for (uint32_t idx = 0; idx < dpa_threads_num; idx++) {
136  DOCA_LOG_INFO(" dpa_process_id=%u", dpa_thread_list[idx].dpa_process_id);
137  DOCA_LOG_INFO(" dpa_thread_id=%u", dpa_thread_list[idx].dpa_thread_id);
138  DOCA_LOG_INFO(" thread_name=%s", dpa_thread_list[idx].thread_name);
139  }
140 
141  return DOCA_SUCCESS;
142 }
143 
144 /*
145  * Print cumul list
146  *
147  * Print the contents of the extracted cumul list.
148  *
149  * @cumul_samples_num [in]: Number of cumul samples to print
150  * @cumul_info_list [in]: Extracted list to print
151  * @return: DOCA_SUCCESS in case of success, DOCA_ERROR otherwise
152  */
153 static doca_error_t telemetry_dpa_print_cumul_list(uint32_t cumul_samples_num,
154  doca_telemetry_dpa_cumul_info_t *cumul_info_list)
155 {
156  if (cumul_info_list == NULL) {
157  DOCA_LOG_ERR("Failed to print cumul list: parameter cumul_info_list=NULL");
159  }
160 
161  if (cumul_samples_num == 0) {
162  DOCA_LOG_ERR("Failed to print cumul list: no samples found in context");
164  }
165 
166  DOCA_LOG_INFO("Number of cumul samples_num: %u", cumul_samples_num);
167  DOCA_LOG_INFO("Extracted cumul list:");
168  for (uint32_t idx = 0; idx < cumul_samples_num; idx++) {
169  if (cumul_info_list[idx].instructions == 0)
170  continue;
171  DOCA_LOG_INFO(" dpa_process_id=%u", cumul_info_list[idx].dpa_process_id);
172  DOCA_LOG_INFO(" dpa_thread_id=%u", cumul_info_list[idx].dpa_thread_id);
173  DOCA_LOG_INFO(" time=%lu", cumul_info_list[idx].time);
174  DOCA_LOG_INFO(" cycles=%lu", cumul_info_list[idx].cycles);
175  DOCA_LOG_INFO(" instructions=%lu", cumul_info_list[idx].instructions);
176  DOCA_LOG_INFO(" num_executions=%lu", cumul_info_list[idx].num_executions);
177  }
178 
179  return DOCA_SUCCESS;
180 }
181 
182 /*
183  * Print perf event list
184  *
185  * Print the contents of the extracted perf event list.
186  *
187  * @perf_event_samples_num [in]: Number of perf event samples to print
188  * @event_info_list [in]: Extracted list to print
189  * @return: DOCA_SUCCESS in case of success, DOCA_ERROR otherwise
190  */
191 static doca_error_t telemetry_dpa_print_perf_event_list(uint32_t perf_event_samples_num,
192  doca_telemetry_dpa_event_sample_t *event_info_list)
193 {
194  if (event_info_list == NULL) {
195  DOCA_LOG_ERR("Failed to print perf event list: parameter event_info_list=NULL");
197  }
198 
199  if (perf_event_samples_num == 0) {
200  DOCA_LOG_ERR("Failed to print perf event list: no samples found in context");
202  }
203 
204  DOCA_LOG_DBG("Number of perf event samples_num: %u", perf_event_samples_num);
205  DOCA_LOG_DBG("Extracted perf event counter list:");
206  for (uint32_t idx = 0; idx < perf_event_samples_num; idx++) {
207  if (event_info_list[idx].instructions == 0)
208  continue;
209  DOCA_LOG_INFO(" dpa_thread_id=%u", event_info_list[idx].dpa_thread_id);
210  DOCA_LOG_INFO(" timestamp=%lu", event_info_list[idx].timestamp);
211  DOCA_LOG_INFO(" cycles=%lu", event_info_list[idx].cycles);
212  DOCA_LOG_INFO(" instructions=%u", event_info_list[idx].instructions);
213  DOCA_LOG_INFO(" sample id per execution unit=%u", event_info_list[idx].sample_id_in_eu);
214  DOCA_LOG_INFO(" execution unit id=%u", event_info_list[idx].eu_id);
215  DOCA_LOG_INFO(" type=%s", telemetry_dpa_event_sample_type_get_str(event_info_list[idx].type));
216  }
217 
218  return DOCA_SUCCESS;
219 }
220 
221 /*
222  * Clean sample objects
223  *
224  * Closes and frees sample resources.
225  *
226  * @sample_objects [in]: sample objects to clean
227  * @sample_objects [in]: type of counter to be reset
228  * @return: DOCA_SUCCESS in case of success, DOCA_ERROR otherwise
229  */
231  enum doca_telemetry_dpa_counter_type counter_type)
232 {
234 
235  if (sample_objects->dpa_process_list) {
236  DOCA_LOG_INFO("process_list %p: process list was destroyed", sample_objects->dpa_process_list);
237  free(sample_objects->dpa_process_list);
238  sample_objects->dpa_process_list = NULL;
239  }
240 
241  if (sample_objects->dpa_thread_list) {
242  DOCA_LOG_INFO("process_list %p: thread list was destroyed", sample_objects->dpa_thread_list);
243  free(sample_objects->dpa_thread_list);
244  sample_objects->dpa_thread_list = NULL;
245  }
246 
247  if (sample_objects->cumul_info_list) {
248  DOCA_LOG_INFO("cumul_info_list %p: list of cumulative info counter was destroyed",
249  sample_objects->cumul_info_list);
250  free(sample_objects->cumul_info_list);
251  sample_objects->cumul_info_list = NULL;
252  }
253 
254  if (sample_objects->event_info_list) {
255  DOCA_LOG_INFO("perf_event_list %p: event counters list was destroyed", sample_objects->event_info_list);
256  free(sample_objects->event_info_list);
257  sample_objects->event_info_list = NULL;
258  }
259 
260  if (sample_objects->telemetry_dpa_obj != NULL) {
262  sample_objects->process_id,
263  counter_type);
264  if (result != DOCA_SUCCESS) {
265  DOCA_LOG_WARN("Failed to restart telemetry_dpa counter counter with error=%s",
267  return result;
268  }
269 
271  if (result != DOCA_SUCCESS) {
272  DOCA_LOG_WARN("Failed to stop telemetry_dpa with error=%s", doca_error_get_name(result));
273  return result;
274  }
275 
277  if (result != DOCA_SUCCESS) {
278  DOCA_LOG_WARN("Failed to destroy telemetry_dpa with error=%s", doca_error_get_name(result));
279  return result;
280  }
281  sample_objects->telemetry_dpa_obj = NULL;
282  }
283 
284  if (sample_objects->dev != NULL) {
285  result = doca_dev_close(sample_objects->dev);
286  if (result != DOCA_SUCCESS) {
287  DOCA_LOG_WARN("Failed to close device with error=%s", doca_error_get_name(result));
288  return result;
289  }
290  sample_objects->dev = NULL;
291  }
292 
293  return DOCA_SUCCESS;
294 }
295 
296 /*
297  * Allocate telemetry dpa output object
298  *
299  * @sample_objects [in]: sample objects struct for the sample
300  *
301  * @return: DOCA_SUCCESS on success, DOCA_ERROR otherwise.
302  */
304  uint32_t max_event_sample,
305  struct telemetry_dpa_sample_objects *sample_objects)
306 {
308  uint32_t dpa_process_list_size = 0;
309  uint32_t dpa_thread_list_size = 0;
310  uint32_t dpa_cumul_samples_size = 0;
311  uint32_t dpa_max_perf_event_samples = 0;
312 
314  sample_objects->process_id,
315  &dpa_process_list_size);
316  if (result != DOCA_SUCCESS) {
317  DOCA_LOG_ERR("Failed to create process list: failed to retrieve the process list size");
318  return DOCA_ERROR_NO_MEMORY;
319  }
320  sample_objects->dpa_process_list = (doca_telemetry_dpa_process_info_t *)malloc(dpa_process_list_size);
321  if (sample_objects->dpa_process_list == NULL) {
322  DOCA_LOG_ERR("Failed to create process list: failed to allocate memory for processes info");
323  return DOCA_ERROR_NO_MEMORY;
324  }
325 
327  sample_objects->process_id,
328  sample_objects->thread_id,
329  &dpa_thread_list_size);
330  if (result != DOCA_SUCCESS) {
331  DOCA_LOG_ERR("Failed to create thread list: failed to retrieve the thread list size");
332  return DOCA_ERROR_NO_MEMORY;
333  }
334  sample_objects->dpa_thread_list = (doca_telemetry_dpa_thread_info_t *)malloc(dpa_thread_list_size);
335  if (sample_objects->dpa_thread_list == NULL) {
336  DOCA_LOG_ERR("Failed to create thread list: failed to allocate memory for threads info");
337  return DOCA_ERROR_NO_MEMORY;
338  }
339 
342  sample_objects->process_id,
343  sample_objects->thread_id,
344  &dpa_cumul_samples_size);
345  if (result != DOCA_SUCCESS) {
346  DOCA_LOG_ERR("Failed to create cumul info list: failed to retrieve cumul samples list size");
347  return DOCA_ERROR_NO_MEMORY;
348  }
349  sample_objects->cumul_info_list = (doca_telemetry_dpa_cumul_info_t *)malloc(dpa_cumul_samples_size);
350  if (sample_objects->cumul_info_list == NULL) {
351  DOCA_LOG_ERR(
352  "Failed to create cumul info list: failed to allocate memory for cumul samples info");
353  return DOCA_ERROR_NO_MEMORY;
354  }
355  } else {
356  if (max_event_sample != 0) {
358  max_event_sample);
359  if (result != DOCA_SUCCESS) {
360  DOCA_LOG_ERR(
361  "Failed to create event info list: failed to set maximum number of perf event samples");
362  return DOCA_ERROR_NO_MEMORY;
363  }
364  }
365 
367  &dpa_max_perf_event_samples);
368  if (result != DOCA_SUCCESS) {
369  DOCA_LOG_ERR(
370  "Failed to create event info list: failed to retrieve maximum number of perf event samples");
371  return DOCA_ERROR_NO_MEMORY;
372  }
373 
374  if (dpa_max_perf_event_samples != 0) {
375  sample_objects->event_info_list = (doca_telemetry_dpa_event_sample_t *)malloc(
376  sizeof(doca_telemetry_dpa_event_sample_t) * dpa_max_perf_event_samples);
377  if (sample_objects->event_info_list == NULL) {
378  DOCA_LOG_ERR(
379  "Failed to create event info list: failed to allocate memory for perf event samples info");
380  return DOCA_ERROR_NO_MEMORY;
381  }
382  } else {
383  DOCA_LOG_ERR(
384  "Failed to create event info list: maximum number of perf event samples is set to 0");
385  return DOCA_ERROR_NO_MEMORY;
386  }
387  }
388 
389  return DOCA_SUCCESS;
390 }
391 
392 /*
393  * Initialize telemetry dpa context object
394  *
395  * @sample_objects [in]: sample objects struct for the sample
396  *
397  * @return: DOCA_SUCCESS on success, DOCA_ERROR otherwise.
398  */
399 static doca_error_t telemetry_dpa_sample_context_init(uint8_t process_id_set,
400  uint8_t thread_id_set,
401  uint32_t process_id,
402  uint32_t thread_id,
403  enum doca_telemetry_dpa_counter_type counter_type,
404  uint32_t max_event_sample,
405  struct telemetry_dpa_sample_objects *sample_objects)
406 {
407  doca_error_t result, teardown_result;
408 
409  struct doca_devinfo *devinfo = doca_dev_as_devinfo(sample_objects->dev);
410 
413  DOCA_LOG_ERR("Failed to start telemetry_dpa: device does not support doca_telemetry_dpa");
415  } else if (result != DOCA_SUCCESS) {
416  DOCA_LOG_ERR("Failed to start telemetry_dpa: failed to query capability");
417  return result;
418  }
419 
420  /* Create context and set properties */
421  result = doca_telemetry_dpa_create(sample_objects->dev, &sample_objects->telemetry_dpa_obj);
422  if (result != DOCA_SUCCESS) {
423  DOCA_LOG_ERR("Failed to start telemetry_dpa: failed to create telemetry dpa object with error=%s",
425  goto teardown_init;
426  }
427 
428  if (!process_id_set) {
429  result = doca_telemetry_dpa_get_all_process_id(devinfo, &sample_objects->process_id);
430  if (result != DOCA_SUCCESS) {
431  DOCA_LOG_ERR("Failed to start telemetry_dpa: failed to retrieve all process id with error=%s",
433  goto teardown_init;
434  }
435  } else {
436  sample_objects->process_id = process_id;
437  }
438  if (!thread_id_set) {
439  result = doca_telemetry_dpa_get_all_thread_id(devinfo, &sample_objects->thread_id);
440  if (result != DOCA_SUCCESS) {
441  DOCA_LOG_ERR("Failed to start telemetry_dpa: failed to retrieve all threads id with error=%s",
443  goto teardown_init;
444  }
445  } else {
446  sample_objects->thread_id = thread_id;
447  }
448 
449  result = telemetry_dpa_sample_allocate_output_objects(counter_type, max_event_sample, sample_objects);
450  if (result != DOCA_SUCCESS) {
451  DOCA_LOG_ERR("Failed to start telemetry_dpa: failed to init sample objects with error=%s",
453  goto teardown_init;
454  }
455 
457  if (result != DOCA_SUCCESS) {
458  DOCA_LOG_ERR("Failed to start telemetry dpa object with error=%s", doca_error_get_name(result));
459  goto teardown_init;
460  }
461 
462  return DOCA_SUCCESS;
463 
464 teardown_init:
465  teardown_result = telemetry_dpa_sample_cleanup(sample_objects, counter_type);
466  if (teardown_result != DOCA_SUCCESS) {
467  DOCA_LOG_ERR("Failed to start telemetry_dpa: Teardown failed with error=%s",
468  doca_error_get_name(teardown_result));
469  }
470 
471  return result;
472 }
473 
475 {
476  doca_error_t result = DOCA_SUCCESS, teardown_result = DOCA_SUCCESS;
477  struct telemetry_dpa_sample_objects sample_objects = {0};
478 
479  DOCA_LOG_INFO("Started doca_telemetry_dpa sample with the following parameters: ");
480  DOCA_LOG_INFO(" pci_addr='%s'", cfg->pci_addr);
481  DOCA_LOG_INFO(" sample_run_time=%u", cfg->run_time);
482  if (cfg->process_id_set) {
483  DOCA_LOG_INFO(" process_id=%u", cfg->process_id);
484  }
485  if (cfg->thread_id_set) {
486  DOCA_LOG_INFO(" thread_id=%u", cfg->thread_id);
487  }
488  if (cfg->counter_type) {
489  DOCA_LOG_INFO(" counter_type=%u", cfg->counter_type);
490  }
491 
492  /* Open DOCA device based on the given PCI address */
493  result = open_doca_device_with_pci(cfg->pci_addr, NULL, &sample_objects.dev);
494  if (result != DOCA_SUCCESS) {
495  DOCA_LOG_ERR("Failed to open device with error=%s", doca_error_get_name(result));
496  return result;
497  }
498 
499  result = telemetry_dpa_sample_context_init(cfg->process_id_set,
500  cfg->thread_id_set,
501  cfg->process_id,
502  cfg->thread_id,
503  cfg->counter_type,
504  cfg->max_event_sample,
505  &sample_objects);
506  if (result != DOCA_SUCCESS) {
507  DOCA_LOG_ERR("Failed to init sample objects with error=%s", doca_error_get_name(result));
508  goto teardown;
509  }
510 
512  sample_objects.process_id,
513  &sample_objects.dpa_process_num,
514  sample_objects.dpa_process_list);
515  if (result != DOCA_SUCCESS) {
516  DOCA_LOG_ERR("Failed to read the process list with error=%s", doca_error_get_name(result));
517  goto teardown;
518  }
519 
521  if (result != DOCA_SUCCESS) {
522  DOCA_LOG_ERR("Failed to print the process list with error=%s", doca_error_get_name(result));
523  goto teardown;
524  }
525 
526  result =
528  if (result != DOCA_SUCCESS) {
529  DOCA_LOG_ERR("Failed to retrieve telemetry_dpa dpa timer freq with error=%s",
531  goto teardown;
532  }
533  DOCA_LOG_INFO("DPA timer ticks frequency (in kHZ): %u", sample_objects.dpa_timer_freq);
534 
536  sample_objects.process_id,
537  sample_objects.thread_id,
538  &sample_objects.dpa_threads_num,
539  sample_objects.dpa_thread_list);
540  if (result != DOCA_SUCCESS) {
541  DOCA_LOG_ERR("Failed to read the thread list with error=%s", doca_error_get_name(result));
542  goto teardown;
543  }
544 
545  result = telemetry_dpa_print_thread_list(sample_objects.dpa_threads_num, sample_objects.dpa_thread_list);
546  if (result != DOCA_SUCCESS) {
547  DOCA_LOG_ERR("Failed to print the thread list with error=%s", doca_error_get_name(result));
548  goto teardown;
549  }
550 
552  sample_objects.process_id,
553  cfg->counter_type);
554  if (result != DOCA_SUCCESS) {
555  DOCA_LOG_WARN("Failed to restart telemetry_dpa counter counter with error=%s",
557  return result;
558  }
559 
561  sample_objects.process_id,
562  cfg->counter_type);
563  if (result != DOCA_SUCCESS) {
564  DOCA_LOG_ERR("Failed to start telemetry_dpa counter with error=%s", doca_error_get_name(result));
565  goto teardown;
566  }
567 
568  usleep(cfg->run_time * 1000);
569 
571  sample_objects.process_id,
572  cfg->counter_type);
573  if (result != DOCA_SUCCESS) {
574  DOCA_LOG_ERR("Failed to stop telemetry_dpa counter with error=%s", doca_error_get_name(result));
575  goto teardown;
576  }
577 
580  sample_objects.process_id,
581  sample_objects.thread_id,
582  &sample_objects.cumul_samples_num,
583  sample_objects.cumul_info_list);
584  if (result != DOCA_SUCCESS) {
585  DOCA_LOG_ERR("Failed to read the cumul counter list with error=%s",
587  goto teardown;
588  }
589 
591  sample_objects.cumul_info_list);
592  if (result != DOCA_SUCCESS) {
593  DOCA_LOG_ERR("Failed to print the cumul list with error=%s", doca_error_get_name(result));
594  goto teardown;
595  }
596  } else {
598  sample_objects.process_id,
599  sample_objects.thread_id,
600  &sample_objects.perf_event_samples_num,
601  sample_objects.event_info_list);
602  if (result != DOCA_SUCCESS) {
603  DOCA_LOG_ERR("Failed to read the perf event list with error=%s", doca_error_get_name(result));
604  goto teardown;
605  }
607  sample_objects.event_info_list);
608  if (result != DOCA_SUCCESS) {
609  DOCA_LOG_ERR("Failed to print the perf event list with error=%s", doca_error_get_name(result));
610  goto teardown;
611  }
612  }
613 
614 teardown:
615  teardown_result = telemetry_dpa_sample_cleanup(&sample_objects, cfg->counter_type);
616  if (teardown_result != DOCA_SUCCESS) {
617  DOCA_LOG_ERR("Teardown failed with error=%s", doca_error_get_name(teardown_result));
618  DOCA_ERROR_PROPAGATE(result, teardown_result);
619  }
620 
621  return result;
622 }
#define NULL
Definition: __stddef_null.h:26
doca_telemetry_exporter_timestamp_t timestamp
int32_t result
static doca_error_t open_doca_device_with_pci(const char *pcie_value, struct doca_dev **retval)
Definition: device.c:43
DOCA_STABLE struct doca_devinfo * doca_dev_as_devinfo(const struct doca_dev *dev)
Get local device info from device. This should be useful when wanting to query information about devi...
DOCA_STABLE doca_error_t doca_dev_close(struct doca_dev *dev)
Destroy allocated local device instance.
#define DOCA_ERROR_PROPAGATE(r, t)
Save the first encountered doca_error_t.
Definition: doca_error.h:83
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_name(doca_error_t error)
Returns the string representation of an error code name.
@ DOCA_ERROR_INVALID_VALUE
Definition: doca_error.h:44
@ DOCA_ERROR_NOT_SUPPORTED
Definition: doca_error.h:42
@ DOCA_SUCCESS
Definition: doca_error.h:38
@ DOCA_ERROR_NO_MEMORY
Definition: doca_error.h:45
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
#define DOCA_LOG_WARN(format,...)
Generates a WARNING application log message.
Definition: doca_log.h:476
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
Definition: doca_log.h:486
#define DOCA_LOG_DBG(format,...)
Generates a DEBUG application log message.
Definition: doca_log.h:496
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_get_max_perf_event_samples(struct doca_telemetry_dpa *dpa, uint32_t *dpa_max_perf_event_samples)
Get maximum number of perf event samples.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_get_thread_list_size(struct doca_telemetry_dpa *dpa, uint32_t process_id, uint32_t thread_id, uint32_t *dpa_thread_list_size)
Get memory size (in bytes) to allocate the thread list.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_counter_start(struct doca_telemetry_dpa *dpa, uint32_t process_id, enum doca_telemetry_dpa_counter_type type)
Start device counters sampling - trigger device to collect performance metrics.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_stop(struct doca_telemetry_dpa *dpa)
Stop telemetry DPA context.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_get_cumul_samples_size(struct doca_telemetry_dpa *dpa, uint32_t process_id, uint32_t thread_id, uint32_t *dpa_cumul_samples_size)
Get memory size (in bytes) to allocate the cumul samples.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_create(struct doca_dev *dev, struct doca_telemetry_dpa **dpa)
Create a DOCA telemetry DPA instance.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_read_thread_list(struct doca_telemetry_dpa *dpa, uint32_t process_id, uint32_t thread_id, uint32_t *dpa_threads_num, doca_telemetry_dpa_thread_info_t *thread_list)
Read threads info.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_read_perf_event_list(struct doca_telemetry_dpa *dpa, uint32_t process_id, uint32_t thread_id, uint32_t *perf_event_samples_num, doca_telemetry_dpa_event_sample_t *perf_event_list)
Read list of the performance event samples.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_set_max_perf_event_samples(struct doca_telemetry_dpa *dpa, uint32_t dpa_max_perf_event_samples)
Set maximum number of perf event samples.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_start(struct doca_telemetry_dpa *dpa)
Start context for telemetry DPA.
doca_telemetry_dpa_counter_type
Performance counters type.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_get_process_list_size(struct doca_telemetry_dpa *dpa, uint32_t process_id, uint32_t *dpa_process_list_size)
Get memory size (in bytes) to allocate the process list.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_get_all_process_id(const struct doca_devinfo *devinfo, uint32_t *all_process_id)
Get all process mask.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_read_processes_list(struct doca_telemetry_dpa *dpa, uint32_t process_id, uint32_t *dpa_process_num, doca_telemetry_dpa_process_info_t *process_list)
Read the processes info.
doca_telemetry_dpa_event_sample_type
List of the performance event samples type.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_destroy(struct doca_telemetry_dpa *dpa)
Destroy doca_telemetry_dpa previously created by doca_telemetry_dpa_create().
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_counter_restart(struct doca_telemetry_dpa *dpa, uint32_t process_id, enum doca_telemetry_dpa_counter_type type)
Restart device counters sampling.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_get_all_thread_id(const struct doca_devinfo *devinfo, uint32_t *all_thread_id)
Get all threads mask.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_get_dpa_timer_freq(struct doca_telemetry_dpa *dpa, uint32_t *dpa_timer_freq)
Get DPA timer frequency.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_counter_stop(struct doca_telemetry_dpa *dpa, uint32_t process_id, enum doca_telemetry_dpa_counter_type type)
Stop device counters sampling.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_read_cumul_info_list(struct doca_telemetry_dpa *dpa, uint32_t process_id, uint32_t thread_id, uint32_t *cumul_samples_num, doca_telemetry_dpa_cumul_info_t *cumul_info_list)
Read list of the cumulative info counters.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_dpa_cap_is_supported(const struct doca_devinfo *devinfo)
Check if given device is capable of executing telemetry DPA operations.
@ DOCA_TELEMETRY_DPA_COUNTER_TYPE_CUMULATIVE_EVENT
@ DOCA_TELEMETRY_DPA_EVENT_SAMPLE_TYPE_SCHEDULE_OUT
@ DOCA_TELEMETRY_DPA_EVENT_SAMPLE_TYPE_BUFFER_FULL
@ DOCA_TELEMETRY_DPA_EVENT_SAMPLE_TYPE_EMPTY_SAMPLE
@ DOCA_TELEMETRY_DPA_EVENT_SAMPLE_TYPE_SCHEDULE_IN
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
uint8_t type
Definition: packets.h:0
Single cumulative info structure.
Single performance events tracer structure.
Single process structure.
Single thread structure.
doca_telemetry_dpa_process_info_t * dpa_process_list
doca_telemetry_dpa_event_sample_t * event_info_list
struct doca_telemetry_dpa * telemetry_dpa_obj
doca_telemetry_dpa_cumul_info_t * cumul_info_list
doca_telemetry_dpa_thread_info_t * dpa_thread_list
doca_error_t telemetry_dpa_sample_run(const struct telemetry_dpa_sample_cfg *cfg)
DOCA_LOG_REGISTER(TELEMETRY_DPA::SAMPLE)
static doca_error_t telemetry_dpa_print_perf_event_list(uint32_t perf_event_samples_num, doca_telemetry_dpa_event_sample_t *event_info_list)
static doca_error_t telemetry_dpa_sample_context_init(uint8_t process_id_set, uint8_t thread_id_set, uint32_t process_id, uint32_t thread_id, enum doca_telemetry_dpa_counter_type counter_type, uint32_t max_event_sample, struct telemetry_dpa_sample_objects *sample_objects)
static doca_error_t telemetry_dpa_print_process_list(uint32_t dpa_process_num, doca_telemetry_dpa_process_info_t *dpa_process_list)
static doca_error_t telemetry_dpa_sample_allocate_output_objects(enum doca_telemetry_dpa_counter_type counter_type, uint32_t max_event_sample, struct telemetry_dpa_sample_objects *sample_objects)
static doca_error_t telemetry_dpa_print_cumul_list(uint32_t cumul_samples_num, doca_telemetry_dpa_cumul_info_t *cumul_info_list)
static doca_error_t telemetry_dpa_sample_cleanup(struct telemetry_dpa_sample_objects *sample_objects, enum doca_telemetry_dpa_counter_type counter_type)
static doca_error_t telemetry_dpa_print_thread_list(uint32_t dpa_threads_num, doca_telemetry_dpa_thread_info_t *dpa_thread_list)
const char * telemetry_dpa_event_sample_type_get_str(enum doca_telemetry_dpa_event_sample_type event_sample_type)
char process_name[MAX_PROCESS_NAME_LEN+1]