| NVIDIA DOCA SDK | Data Center on a Chip Framework Documentation |
#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <stdint.h>#include <sys/epoll.h>#include <sys/eventfd.h>#include <unistd.h>#include <doca_mmap.h>#include <doca_buf.h>#include <doca_buf_inventory.h>#include <doca_ctx.h>#include <doca_dma.h>#include <doca_types.h>#include <doca_log.h>#include <doca_pe.h>#include <samples/common.h>#include "pe_common.h"
Go to the source code of this file.
Data Structures | |
| struct | pe_event_sample_state |
Macros | |
| #define | EXIT_ON_FAILURE(_expression_) |
| #define | NUM_TASKS (16) |
| #define | DMA_BUFFER_SIZE (1024) |
| #define | BUFFER_SIZE (DMA_BUFFER_SIZE * 2 * NUM_TASKS) |
| #define | BUF_INVENTORY_SIZE (NUM_TASKS * 2) |
Functions | |
| DOCA_LOG_REGISTER (PE_EVENT::SAMPLE) | |
| static void | dma_memcpy_completed_callback (struct doca_dma_task_memcpy *dma_task, union doca_data task_user_data, union doca_data ctx_user_data) |
| static void | dma_memcpy_error_callback (struct doca_dma_task_memcpy *dma_task, union doca_data task_user_data, union doca_data ctx_user_data) |
| doca_error_t | register_pe_event (struct pe_event_sample_state *state) |
| doca_error_t | create_dma (struct pe_event_sample_state *state) |
| doca_error_t | run_for_completion (struct pe_event_sample_state *state) |
| void | cleanup (struct pe_event_sample_state *state) |
| doca_error_t | run (struct pe_event_sample_state *state) |
| doca_error_t | run_pe_event_sample (void) |
| #define BUF_INVENTORY_SIZE (NUM_TASKS * 2) |
Definition at line 76 of file pe_event_sample.c.
| #define BUFFER_SIZE (DMA_BUFFER_SIZE * 2 * NUM_TASKS) |
Definition at line 75 of file pe_event_sample.c.
| #define DMA_BUFFER_SIZE (1024) |
Definition at line 74 of file pe_event_sample.c.
| #define EXIT_ON_FAILURE | ( | _expression_ | ) |
This sample demonstrates how to use DOCA PE (progress engine) in event mode. Using event mode facilitates waiting on an event until a task or more is completed. Using event mode introduces a performance - CPU utilization trade off. Waiting on event implies that the PE thread is suspended. On the other hand, polling will take much more CPU, even when there is no completed task. The sample uses DOCA_DMA context as an example (DOCA PE can run any library that abides to the PE context API). The sample runs 16 DMA memcpy tasks. Diff between this sample and pe_polling sample to see the differences when using event. This macro is used to minimize code size. The macro runs an expression and returns error if the expression status is not DOCA_SUCCESS
Definition at line 63 of file pe_event_sample.c.
| #define NUM_TASKS (16) |
Definition at line 73 of file pe_event_sample.c.
| void cleanup | ( | struct pe_event_sample_state * | state | ) |
This method cleans up the sample resources in reverse order of their creation. This method does not check for destroy return values for simplify. Real code should check the return value and act accordingly (e.g. if doca_ctx_stop failed with DOCA_ERROR_IN_PROGRESS it means that some contexts are still added or even that there are still in flight tasks in the progress engine).
@state [in]: sample state
Definition at line 268 of file pe_event_sample.c.
| doca_error_t create_dma | ( | struct pe_event_sample_state * | state | ) |
Create DMA
@state [in]: sample state
The ctx user data is received in the task completion callback. Setting the state to the user data binds the program to the callback. See dma_memcpy_completed_callback for usage.
Definition at line 180 of file pe_event_sample.c.
|
static |
process_completed_dma_memcpy_task returns doca_error_t to be able to use EXIT_ON_FAILURE, but there is nothing to do with the return value.
Definition at line 97 of file pe_event_sample.c.
|
static |
Definition at line 123 of file pe_event_sample.c.
| DOCA_LOG_REGISTER | ( | PE_EVENT::SAMPLE | ) |
| doca_error_t register_pe_event | ( | struct pe_event_sample_state * | state | ) |
Register to the PE event.
This function creates an epoll and adds the PE event to that epoll.
@state [in]: sample state
Definition at line 149 of file pe_event_sample.c.
| doca_error_t run | ( | struct pe_event_sample_state * | state | ) |
Run the sample The method (and the method it calls) does not cleanup anything in case of failures. It assumes that cleanup is called after it at any case.
@state [in]: sample state
Definition at line 289 of file pe_event_sample.c.
| doca_error_t run_for_completion | ( | struct pe_event_sample_state * | state | ) |
Run the PE until all tasks are completed. This method sleeps on an event until there is a completed task (or more).
@state [in]: sample state
This loop shall iterate until all tasks are completed. The loop will break if all tasks are completed or if one of the event APIs fails.
The internal loop shall run as long as progress one returns 1 because it implies that there may be more tasks to complete. Once it returns 0 the external loop shall arm the PE event (by calling doca_pe_request_notification) and shall wait until the event is fired, signaling that there is a completed task to progress. Calling doca_pe_request_notification implies enabling an interrupt, but it also reduces CPU utilization because the program can sleep until the event is fired.
Calling doca_pe_request_notification arms the PE event. The event will be signaled when a task is completed.
Definition at line 215 of file pe_event_sample.c.
| doca_error_t run_pe_event_sample | ( | void | ) |
Run the PE event sample
Definition at line 316 of file pe_event_sample.c.