Skip to content

Commit

Permalink
applying 'GNU Coding Standards' style to data_dev/app/src
Browse files Browse the repository at this point in the history
  • Loading branch information
ruck314 committed Feb 23, 2024
1 parent 1776188 commit 94e3060
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 270 deletions.
188 changes: 97 additions & 91 deletions data_dev/app/src/dmaRate.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
/**
*-----------------------------------------------------------------------------
* Company : SLAC National Accelerator Laboratory
*-----------------------------------------------------------------------------
* Description:
* This program will open up a AXIS DMA port and attempt to read data.
* ----------------------------------------------------------------------------
* This file is part of the aes_stream_drivers package. It is subject to
* the license terms in the LICENSE.txt file found in the top-level directory
* of this distribution and at:
* Opens an AXIS DMA port and attempts to read data.
*-----------------------------------------------------------------------------
* This file is part of the aes_stream_drivers package. It is subject to the
* license terms in the LICENSE.txt file found in the top-level directory of
* this distribution and at:
* https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
* No part of the aes_stream_drivers package, including this file, may be
* copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE.txt file.
* ----------------------------------------------------------------------------
*-----------------------------------------------------------------------------
**/

#include <sys/types.h>
Expand All @@ -23,67 +25,67 @@
#include <stdlib.h>
#include <argp.h>
#include <AxisDriver.h>
//#include <PrbsData.h>
// #include <PrbsData.h>
using namespace std;

#define MAX_RET_CNT_C 1000

const char * argp_program_version = "dmaRate 1.0";
const char * argp_program_bug_address = "[email protected]";
const char *argp_program_version = "dmaRate 1.0";
const char *argp_program_bug_address = "[email protected]";

struct PrgArgs {
const char * path;
uint32_t count;
const char *path;
uint32_t count;
};

#define DEF_DEV_PATH "/dev/datadev_0"
#define DEF_COUNT 10000000
static struct PrgArgs DefArgs = { DEF_DEV_PATH, DEF_COUNT };
#define DEF_DEV_PATH "/dev/datadev_0"
#define DEF_COUNT 10000000
static struct PrgArgs DefArgs = {DEF_DEV_PATH, DEF_COUNT};

static char args_doc[] = "";
static char doc[] = "";
static char args_doc[] = "";
static char doc[] = "";

#define STRING(N) #N
#define XSTRING(N) STRING(N)
#define STRING(N) #N
#define XSTRING(N) STRING(N)
static struct argp_option options[] = {
{ "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of datadev device to use. Default=" DEF_DEV_PATH, 0},
{ "count", 'c', "COUNT", OPTION_ARG_OPTIONAL, "Total iterations. Default=" XSTRING(DEF_COUNT),0},
{"path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of datadev device. Default=" DEF_DEV_PATH, 0},
{"count", 'c', "COUNT", OPTION_ARG_OPTIONAL, "Total iterations. Default=" XSTRING(DEF_COUNT), 0},
{0}
};

error_t parseArgs ( int key, char *arg, struct argp_state *state ) {
error_t parseArgs(int key, char *arg, struct argp_state *state) {
struct PrgArgs *args = (struct PrgArgs *)state->input;

switch(key) {
case 'p': args->path = arg; break;
case 'c': args->count = atoi(arg); break;
case 'p': args->path = arg; break;
case 'c': args->count = atoi(arg); break;
default: return ARGP_ERR_UNKNOWN; break;
}
return(0);
return 0;
}

static struct argp argp = {options,parseArgs,args_doc,doc};

int main (int argc, char **argv) {
uint8_t mask[DMA_MASK_SIZE];
int32_t ret;
int32_t s;
uint32_t rxFlags[MAX_RET_CNT_C];
//PrbsData prbs(32,4,1,2,6,31);
void ** dmaBuffers;
uint32_t dmaSize;
uint32_t dmaCount;
uint32_t dmaIndex[MAX_RET_CNT_C];
int32_t dmaRet[MAX_RET_CNT_C];
int32_t x;
float last;
float rate;
float bw;
float duration;
int32_t max;
int32_t total;

uint32_t getCnt = MAX_RET_CNT_C;
static struct argp argp = {options, parseArgs, args_doc, doc};

int main(int argc, char **argv) {
uint8_t mask[DMA_MASK_SIZE];
int32_t ret;
int32_t s;
uint32_t rxFlags[MAX_RET_CNT_C];
// PrbsData prbs(32,4,1,2,6,31);
void **dmaBuffers;
uint32_t dmaSize;
uint32_t dmaCount;
uint32_t dmaIndex[MAX_RET_CNT_C];
int32_t dmaRet[MAX_RET_CNT_C];
int32_t x;
float last;
float rate;
float bw;
float duration;
int32_t max;
int32_t total;

uint32_t getCnt = MAX_RET_CNT_C;

struct timeval sTime;
struct timeval eTime;
Expand All @@ -92,77 +94,81 @@ int main (int argc, char **argv) {

struct PrgArgs args;

memcpy(&args,&DefArgs,sizeof(struct PrgArgs));
argp_parse(&argp,argc,argv,0,0,&args);
// Initialize program arguments with default values
memcpy(&args, &DefArgs, sizeof(struct PrgArgs));
argp_parse(&argp, argc, argv, 0, 0, &args);

printf(" maxCnt size count duration rate bw Read uS Return uS\n");

// Initialize DMA mask
dmaInitMaskBytes(mask);
memset(mask,0xFF,DMA_MASK_SIZE);
memset(mask, 0xFF, DMA_MASK_SIZE);

if ( (s = open(args.path, O_RDWR)) <= 0 ) {
printf("Error opening %s\n",args.path);
return(1);
// Open device
if ((s = open(args.path, O_RDWR)) <= 0) {
printf("Error opening %s\n", args.path);
return 1;
}

#if 1
if ( (dmaBuffers = dmaMapDma(s,&dmaCount,&dmaSize)) == NULL ) {
// Map DMA buffers
if ((dmaBuffers = dmaMapDma(s, &dmaCount, &dmaSize)) == NULL) {
printf("Failed to map dma buffers!\n");
return(0);
return 0;
}
#endif

if (dmaSetMaskBytes(s,mask) != 0 ) {
// Set DMA mask
if (dmaSetMaskBytes(s, mask) != 0) {
printf("Failed to get receive dma!\n");
return(0);
return 0;
}

while(1) {

bw = 0.0;
rate = 0.0;
last = 0.0;
max = 0;
total = 0;
gettimeofday(&sTime,NULL);

while ( rate < args.count ) {

// DMA Read
gettimeofday(&(pTime[0]),NULL);
ret = dmaReadBulkIndex(s,getCnt,dmaRet,dmaIndex,rxFlags,NULL,NULL); // 24 usec
gettimeofday(&(pTime[1]),NULL);

for (x=0; x < ret; ++x) {
if ( (last = dmaRet[x]) > 0.0 ) {
// Main processing loop
while (1) {
bw = 0.0;
rate = 0.0;
last = 0.0;
max = 0;
total = 0;
gettimeofday(&sTime, NULL);

while (rate < args.count) {
// Perform DMA Read
gettimeofday(&(pTime[0]), NULL);
ret = dmaReadBulkIndex(s, getCnt, dmaRet, dmaIndex, rxFlags, NULL, NULL);
gettimeofday(&(pTime[1]), NULL);

// Process read data
for (x = 0; x < ret; ++x) {
if ((last = dmaRet[x]) > 0.0) {
rate += 1.0;
bw += (last * 8.0);
}
}

gettimeofday(&(pTime[2]),NULL);
if ( ret > 0 ) dmaRetIndexes(s,ret,dmaIndex); // 721 usec
gettimeofday(&(pTime[3]),NULL);
gettimeofday(&(pTime[2]), NULL);
if (ret > 0) dmaRetIndexes(s, ret, dmaIndex);
gettimeofday(&(pTime[3]), NULL);

if ( total == 0 ) if ( ret > max ) max = ret;
total += ret; // 0 usec
if (total == 0) if (ret > max) max = ret;
total += ret;
}

gettimeofday(&eTime,NULL);

timersub(&eTime,&sTime,&dTime);
duration = dTime.tv_sec + (float)dTime.tv_usec/1000000.0;
// Calculate duration and data rates
gettimeofday(&eTime, NULL);
timersub(&eTime, &sTime, &dTime);
duration = dTime.tv_sec + (float)dTime.tv_usec / 1000000.0;

rate = rate / duration;
bw = bw / duration;
bw = bw / duration;

printf("%8i %1.3e %8i %1.2e %1.2e %1.2e %8li %8li \n",max,last,args.count,duration,rate,bw,
(pTime[1].tv_usec-pTime[0].tv_usec), (pTime[3].tv_usec-pTime[2].tv_usec));
// Output results
printf("%8i %1.3e %8i %1.2e %1.2e %1.2e %8li %8li \n",
max, last, args.count, duration, rate, bw,
(pTime[1].tv_usec - pTime[0].tv_usec), (pTime[3].tv_usec - pTime[2].tv_usec));

rate = 0.0;
bw = 0.0;
bw = 0.0;
}

return(0);
return 0;
}

Loading

0 comments on commit 94e3060

Please sign in to comment.