| NVIDIA DOCA SDK | Data Center on a Chip Framework Documentation |
#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include <stdint.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_reactive_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_REACTIVE::SAMPLE) | |
| static void | dma_state_changed_callback (const union doca_data user_data, struct doca_ctx *ctx, enum doca_ctx_states prev_state, enum doca_ctx_states next_state) |
| 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 | create_dma (struct pe_reactive_sample_state *state) |
| void | cleanup (struct pe_reactive_sample_state *state) |
| doca_error_t | run (struct pe_reactive_sample_state *state) |
| doca_error_t | run_pe_reactive_sample (void) |
| #define BUF_INVENTORY_SIZE (NUM_TASKS * 2) |
Definition at line 69 of file pe_reactive_sample.c.
| #define BUFFER_SIZE (DMA_BUFFER_SIZE * 2 * NUM_TASKS) |
Definition at line 68 of file pe_reactive_sample.c.
| #define DMA_BUFFER_SIZE (1024) |
Definition at line 67 of file pe_reactive_sample.c.
| #define EXIT_ON_FAILURE | ( | _expression_ | ) |
This sample demonstrates how to use DOCA PE (progress engine) in a reactive pattern. The main loop does nothing but calling doca_pe_progress and the program is maintained in the callbacks. 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. 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 56 of file pe_reactive_sample.c.
| #define NUM_TASKS (16) |
Definition at line 66 of file pe_reactive_sample.c.
| void cleanup | ( | struct pe_reactive_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 257 of file pe_reactive_sample.c.
| doca_error_t create_dma | ( | struct pe_reactive_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.
This will allow sample to react to any state changes that occur during doca_pe_progress().
This will allow sample to allocate DMA tasks, while providing method that will react to completed tasks both in case task is successful or fails.
Definition at line 212 of file pe_reactive_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.
The DMA context can be stopped when all tasks are completed. This section demonstrates that a context can be stopped during a completion callback, but it can be stopped at any other flow in the program.
Definition at line 153 of file pe_reactive_sample.c.
|
static |
Definition at line 188 of file pe_reactive_sample.c.
|
static |
Callback that reacts to DMA state changes
@user_data [in]: user data associated with the DMA context. Will hold struct pe_reactive_sample_state @ctx [in]: the DMA context that had a state change @prev_state [in]: previous context state @next_state [in]: next context state (context is already in this state when the callback is called)
The context is in starting state, this is unexpected for DMA.
doca_ctx_stop() has been called. In this sample, this happens either due to a failure encountered, in which case doca_pe_progress() will cause any inflight task to be flushed, or due to the successful compilation of the sample flow. In both cases, in this sample, doca_pe_progress() will eventually transition the context to idle state.
Definition at line 90 of file pe_reactive_sample.c.
| DOCA_LOG_REGISTER | ( | PE_REACTIVE::SAMPLE | ) |
| doca_error_t run | ( | struct pe_reactive_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
This is the main loop of the sample. During these calls any can happen:
Definition at line 276 of file pe_reactive_sample.c.
| doca_error_t run_pe_reactive_sample | ( | void | ) |
Run the PE reactive sample
Definition at line 312 of file pe_reactive_sample.c.