NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
cache_invalidate_sample.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.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 <doca_mmap_advise.h>
#include <samples/common.h>
Include dependency graph for cache_invalidate_sample.c:

Go to the source code of this file.

Data Structures

struct  cache_invalidate_sample_state
 

Macros

#define EXIT_ON_FAILURE(_expression_)
 
#define NUM_TASKS   (1)
 
#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 (CACHE_INVALIDATE::SAMPLE)
 
static doca_error_t allocate_buffer (struct cache_invalidate_sample_state *state)
 
static doca_error_t check_dev_capable (struct doca_devinfo *devinfo)
 
static doca_error_t open_device (struct cache_invalidate_sample_state *state)
 
static doca_error_t create_mmap (struct cache_invalidate_sample_state *state)
 
static doca_error_t create_buf_inventory (struct cache_invalidate_sample_state *state)
 
static doca_error_t create_pe (struct cache_invalidate_sample_state *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)
 
static doca_error_t create_dma (struct cache_invalidate_sample_state *state)
 
static void cache_invalidate_completed_callback (struct doca_mmap_advise_task_invalidate_cache *cache_invalidate_task, union doca_data task_user_data, union doca_data ctx_user_data)
 
static void cache_invalidate_error_callback (struct doca_mmap_advise_task_invalidate_cache *cache_invalidate_task, union doca_data task_user_data, union doca_data ctx_user_data)
 
static doca_error_t create_mmap_advise (struct cache_invalidate_sample_state *state)
 
static doca_error_t allocate_dma_task (struct cache_invalidate_sample_state *state)
 
static doca_error_t allocate_cache_invalidate_task (struct cache_invalidate_sample_state *state)
 
static doca_error_t submit_dma_task (struct cache_invalidate_sample_state *state)
 
static doca_error_t poll_for_completion (struct cache_invalidate_sample_state *state)
 
static void cleanup (struct cache_invalidate_sample_state *state)
 
static doca_error_t run (struct cache_invalidate_sample_state *state)
 
doca_error_t run_cache_invalidate_sample (void)
 

Macro Definition Documentation

◆ BUF_INVENTORY_SIZE

#define BUF_INVENTORY_SIZE   (NUM_TASKS * 2)

Definition at line 66 of file cache_invalidate_sample.c.

◆ BUFFER_SIZE

#define BUFFER_SIZE   (DMA_BUFFER_SIZE * 2 * NUM_TASKS)

Definition at line 65 of file cache_invalidate_sample.c.

◆ DMA_BUFFER_SIZE

#define DMA_BUFFER_SIZE   (1024)

Definition at line 64 of file cache_invalidate_sample.c.

◆ EXIT_ON_FAILURE

#define EXIT_ON_FAILURE (   _expression_)
Value:
{ \
doca_error_t _status_ = _expression_; \
if (_status_ != DOCA_SUCCESS) { \
DOCA_LOG_ERR("%s failed with status %s", __func__, doca_error_get_descr(_status_)); \
return _status_; \
} \
}
if(bitoffset % 64+bitlength > 64) result|
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_SUCCESS
Definition: doca_error.h:38

This sample demonstrates how to invalidate a cache of a buffer after DMA operation 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 53 of file cache_invalidate_sample.c.

◆ NUM_TASKS

#define NUM_TASKS   (1)

Definition at line 63 of file cache_invalidate_sample.c.

Function Documentation

◆ allocate_buffer()

static doca_error_t allocate_buffer ( struct cache_invalidate_sample_state state)
static

Allocates a buffer that will be used for the source and destination buffers.

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 103 of file cache_invalidate_sample.c.

◆ allocate_cache_invalidate_task()

static doca_error_t allocate_cache_invalidate_task ( struct cache_invalidate_sample_state state)
static

This method allocate the DMA tasks but does not submit them. This is a sample choice. A task can be submitted immediately after it is allocated.

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 395 of file cache_invalidate_sample.c.

◆ allocate_dma_task()

static doca_error_t allocate_dma_task ( struct cache_invalidate_sample_state state)
static

This method allocate the DMA tasks but does not submit them. This is a sample choice. A task can be submitted immediately after it is allocated.

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Using doca_buf_inventory_buf_get_by_addr leaves the buffer head uninitialized. The DMA context will set the head and length at the task completion.

Definition at line 357 of file cache_invalidate_sample.c.

◆ cache_invalidate_completed_callback()

static void cache_invalidate_completed_callback ( struct doca_mmap_advise_task_invalidate_cache *  cache_invalidate_task,
union doca_data  task_user_data,
union doca_data  ctx_user_data 
)
static

Definition at line 281 of file cache_invalidate_sample.c.

◆ cache_invalidate_error_callback()

static void cache_invalidate_error_callback ( struct doca_mmap_advise_task_invalidate_cache *  cache_invalidate_task,
union doca_data  task_user_data,
union doca_data  ctx_user_data 
)
static

Definition at line 302 of file cache_invalidate_sample.c.

◆ check_dev_capable()

static doca_error_t check_dev_capable ( struct doca_devinfo *  devinfo)
static

Definition at line 120 of file cache_invalidate_sample.c.

◆ cleanup()

static void cleanup ( struct cache_invalidate_sample_state state)
static

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 458 of file cache_invalidate_sample.c.

◆ create_buf_inventory()

static doca_error_t create_buf_inventory ( struct cache_invalidate_sample_state state)
static

Create buffer inventory, initialize and start it.

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 174 of file cache_invalidate_sample.c.

◆ create_dma()

static doca_error_t create_dma ( struct cache_invalidate_sample_state state)
static

Create DMA

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

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 246 of file cache_invalidate_sample.c.

◆ create_mmap()

static doca_error_t create_mmap ( struct cache_invalidate_sample_state state)
static

Create MMAP, initialize and start it.

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 155 of file cache_invalidate_sample.c.

◆ create_mmap_advise()

static doca_error_t create_mmap_advise ( struct cache_invalidate_sample_state state)
static

Create MMAP advise

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

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 cache_invalidate_completed_callback for usage.

Definition at line 322 of file cache_invalidate_sample.c.

◆ create_pe()

static doca_error_t create_pe ( struct cache_invalidate_sample_state state)
static

Creates a progress engine

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 190 of file cache_invalidate_sample.c.

◆ dma_memcpy_completed_callback()

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

Definition at line 206 of file cache_invalidate_sample.c.

◆ dma_memcpy_error_callback()

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 
)
static

Definition at line 226 of file cache_invalidate_sample.c.

◆ DOCA_LOG_REGISTER()

DOCA_LOG_REGISTER ( CACHE_INVALIDATE::SAMPLE  )

◆ open_device()

static doca_error_t open_device ( struct cache_invalidate_sample_state state)
static

Opens a device that supports cache invalidate and DMA

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 140 of file cache_invalidate_sample.c.

◆ poll_for_completion()

static doca_error_t poll_for_completion ( struct cache_invalidate_sample_state state)
static

Poll the PE until all tasks are completed.

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

doca_pe_progress shall return 1 if a task was completed and 0 if not. In this case the sample does not have anything to do with the return value because it is a polling sample.

Definition at line 430 of file cache_invalidate_sample.c.

◆ run()

static doca_error_t run ( struct cache_invalidate_sample_state state)
static

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

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 514 of file cache_invalidate_sample.c.

◆ run_cache_invalidate_sample()

doca_error_t run_cache_invalidate_sample ( void  )

Run the PE polling sample

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 540 of file cache_invalidate_sample.c.

◆ submit_dma_task()

static doca_error_t submit_dma_task ( struct cache_invalidate_sample_state state)
static

This method submits the DMA task

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 415 of file cache_invalidate_sample.c.