Skip to content
Snippets Groups Projects
Commit 279ce21a authored by Karen Xie's avatar Karen Xie
Browse files

XDMA: dma_from/to_device: do NOT mark partial completion as failure. the bw is...

XDMA: dma_from/to_device: do NOT mark partial completion as failure. the bw is not calculated in the case of underflow (partial completion).
parent 98e3a9af
No related branches found
No related tags found
No related merge requests found
...@@ -46,8 +46,8 @@ static struct option const long_opts[] = { ...@@ -46,8 +46,8 @@ static struct option const long_opts[] = {
}; };
static int test_dma(char *devname, uint64_t addr, uint64_t aperture, static int test_dma(char *devname, uint64_t addr, uint64_t aperture,
uint64_t size, uint64_t offset, uint64_t count, uint64_t size, uint64_t offset, uint64_t count,
char *ofname); char *ofname);
static int no_write = 0; static int no_write = 0;
static void usage(const char *name) static void usage(const char *name)
...@@ -156,8 +156,8 @@ int main(int argc, char *argv[]) ...@@ -156,8 +156,8 @@ int main(int argc, char *argv[])
} }
static int test_dma(char *devname, uint64_t addr, uint64_t aperture, static int test_dma(char *devname, uint64_t addr, uint64_t aperture,
uint64_t size, uint64_t offset, uint64_t count, uint64_t size, uint64_t offset, uint64_t count,
char *ofname) char *ofname)
{ {
ssize_t rc; ssize_t rc;
uint64_t i; uint64_t i;
...@@ -170,6 +170,7 @@ static int test_dma(char *devname, uint64_t addr, uint64_t aperture, ...@@ -170,6 +170,7 @@ static int test_dma(char *devname, uint64_t addr, uint64_t aperture,
long total_time = 0; long total_time = 0;
float result; float result;
float avg_time = 0; float avg_time = 0;
int underflow = 0;
if (fpga_fd < 0) { if (fpga_fd < 0) {
fprintf(stderr, "unable to open device %s, %d.\n", fprintf(stderr, "unable to open device %s, %d.\n",
...@@ -210,29 +211,34 @@ static int test_dma(char *devname, uint64_t addr, uint64_t aperture, ...@@ -210,29 +211,34 @@ static int test_dma(char *devname, uint64_t addr, uint64_t aperture,
char *buf = buffer; char *buf = buffer;
for (j = 0; j < apt_loop; j++, len -= aperture, buf += aperture) { for (j = 0; j < apt_loop; j++, len -= aperture, buf += aperture) {
/* lseek & read data from AXI MM into buffer using SGDMA */ uint64_t bytes = (len > aperture) ? aperture : len,
rc = read_to_buffer(devname, fpga_fd, buf, rc = read_to_buffer(devname, fpga_fd, buf,
(len > aperture) ? aperture : len, bytes, addr);
addr);
if (rc < 0) if (rc < 0)
goto out; goto out;
if (!underflow && rc < bytes)
underflow = 1;
} }
} else { } else {
/* lseek & read data from AXI MM into buffer using SGDMA */
rc = read_to_buffer(devname, fpga_fd, buffer, size, addr); rc = read_to_buffer(devname, fpga_fd, buffer, size, addr);
if (rc < 0) if (rc < 0)
goto out; goto out;
if (!underflow && rc < size)
underflow = 1;
} }
clock_gettime(CLOCK_MONOTONIC, &ts_end); clock_gettime(CLOCK_MONOTONIC, &ts_end);
/* subtract the start time from the end time */ /* subtract the start time from the end time */
timespec_sub(&ts_end, &ts_start); timespec_sub(&ts_end, &ts_start);
total_time += ts_end.tv_nsec; total_time += ts_end.tv_nsec;
/* a bit less accurate but side-effects are accounted for */ /* a bit less accurate but side-effects are accounted for */
if (verbose) if (verbose)
fprintf(stdout, fprintf(stdout,
"#%lu: CLOCK_MONOTONIC %ld.%09ld sec. read %ld bytes\n", "#%lu: CLOCK_MONOTONIC %ld.%09ld sec. read %ld/%ld bytes\n",
i, ts_end.tv_sec, ts_end.tv_nsec, size); i, ts_end.tv_sec, ts_end.tv_nsec, rc, size);
/* file argument given? */ /* file argument given? */
if ((out_fd >= 0) & (no_write == 0)) { if ((out_fd >= 0) & (no_write == 0)) {
...@@ -242,14 +248,17 @@ static int test_dma(char *devname, uint64_t addr, uint64_t aperture, ...@@ -242,14 +248,17 @@ static int test_dma(char *devname, uint64_t addr, uint64_t aperture,
goto out; goto out;
} }
} }
avg_time = (float)total_time/(float)count;
result = ((float)size)*1000/avg_time;
if (verbose)
printf("** Avg time device %s, total time %ld nsec, avg_time = %f, size = %lu, BW = %f \n",
devname, total_time, avg_time, size, result);
printf("** Average BW = %lu, %f\n", size, result);
rc = 0;
if (!underflow) {
avg_time = (float)total_time/(float)count;
result = ((float)size)*1000/avg_time;
if (verbose)
printf("** Avg time device %s, total time %ld nsec, avg_time = %f, size = %lu, BW = %f \n",
devname, total_time, avg_time, size, result);
printf("%s ** Average BW = %lu, %f\n", devname, size, result);
}
rc = 0;
out: out:
close(fpga_fd); close(fpga_fd);
if (out_fd >= 0) if (out_fd >= 0)
......
...@@ -183,6 +183,7 @@ static int test_dma(char *devname, uint64_t addr, uint64_t aperture, ...@@ -183,6 +183,7 @@ static int test_dma(char *devname, uint64_t addr, uint64_t aperture,
long total_time = 0; long total_time = 0;
float result; float result;
float avg_time = 0; float avg_time = 0;
int underflow = 0;
if (fpga_fd < 0) { if (fpga_fd < 0) {
fprintf(stderr, "unable to open device %s, %d.\n", fprintf(stderr, "unable to open device %s, %d.\n",
...@@ -243,17 +244,23 @@ static int test_dma(char *devname, uint64_t addr, uint64_t aperture, ...@@ -243,17 +244,23 @@ static int test_dma(char *devname, uint64_t addr, uint64_t aperture,
for (j = 0; j < apt_loop; j++, len -= aperture, for (j = 0; j < apt_loop; j++, len -= aperture,
buf += aperture) { buf += aperture) {
uint64_t bytes = (len > aperture) ? aperture : len,
rc = write_from_buffer(devname, fpga_fd, buf, rc = write_from_buffer(devname, fpga_fd, buf,
(len > aperture) ? aperture : len, bytes, addr);
addr);
if (rc < 0) if (rc < 0)
goto out; goto out;
if (!underflow && rc < bytes)
underflow = 1;
} }
} else { } else {
rc = write_from_buffer(devname, fpga_fd, buffer, size, rc = write_from_buffer(devname, fpga_fd, buffer, size,
addr); addr);
if (rc < 0) if (rc < 0)
goto out; goto out;
if (!underflow && rc < size)
underflow = 1;
} }
rc = clock_gettime(CLOCK_MONOTONIC, &ts_end); rc = clock_gettime(CLOCK_MONOTONIC, &ts_end);
...@@ -273,13 +280,15 @@ static int test_dma(char *devname, uint64_t addr, uint64_t aperture, ...@@ -273,13 +280,15 @@ static int test_dma(char *devname, uint64_t addr, uint64_t aperture,
goto out; goto out;
} }
} }
avg_time = (float)total_time/(float)count;
result = ((float)size)*1000/avg_time;
if (verbose)
printf("** Avg time device %s, total time %ld nsec, avg_time = %f, size = %lu, BW = %f \n",
devname, total_time, avg_time, size, result);
printf("** Average BW = %lu, %f\n",size, result); if (!underflow) {
avg_time = (float)total_time/(float)count;
result = ((float)size)*1000/avg_time;
if (verbose)
printf("** Avg time device %s, total time %ld nsec, avg_time = %f, size = %lu, BW = %f \n",
devname, total_time, avg_time, size, result);
printf("%s ** Average BW = %lu, %f\n", devname, size, result);
}
rc = 0; rc = 0;
out: out:
......
...@@ -66,23 +66,28 @@ ssize_t read_to_buffer(char *fname, int fd, char *buffer, uint64_t size, ...@@ -66,23 +66,28 @@ ssize_t read_to_buffer(char *fname, int fd, char *buffer, uint64_t size,
/* read data from file into memory buffer */ /* read data from file into memory buffer */
rc = read(fd, buf, bytes); rc = read(fd, buf, bytes);
if (rc != bytes) { if (rc < 0) {
fprintf(stderr, "%s, R off 0x%lx, 0x%lx != 0x%lx.\n", fprintf(stderr, "%s, read 0x%lx @ 0x%lx failed %d.\n",
fname, count, rc, bytes); fname, bytes, offset, rc);
perror("read file"); perror("read file");
return -EIO; return -EIO;
} }
count += bytes; count += rc;
if (rc != bytes) {
fprintf(stderr, "%s, read underflow 0x%lx/0x%lx, off 0x%lx.\n",
fname, rc, bytes, offset);
break;
}
buf += bytes; buf += bytes;
offset += bytes; offset += bytes;
} }
if (count != size) { if (count != size)
fprintf(stderr, "%s, R failed 0x%lx != 0x%lx.\n", fprintf(stderr, "%s, read underflow 0x%lx != 0x%lx.\n",
fname, count, size); fname, count, size);
return -EIO;
}
return count; return count;
} }
...@@ -112,23 +117,27 @@ ssize_t write_from_buffer(char *fname, int fd, char *buffer, uint64_t size, ...@@ -112,23 +117,27 @@ ssize_t write_from_buffer(char *fname, int fd, char *buffer, uint64_t size,
/* write data to file from memory buffer */ /* write data to file from memory buffer */
rc = write(fd, buf, bytes); rc = write(fd, buf, bytes);
if (rc != bytes) { if (rc < 0) {
fprintf(stderr, "%s, W off 0x%lx, 0x%lx != 0x%lx.\n", fprintf(stderr, "%s, write 0x%lx @ 0x%lx failed %d.\n",
fname, offset, rc, bytes); fname, bytes, offset, rc);
perror("write file"); perror("write file");
return -EIO; return -EIO;
} }
count += bytes; count += rc;
if (rc != bytes) {
fprintf(stderr, "%s, write underflow 0x%lx/0x%lx, off 0x%lx.\n",
fname, rc, bytes, offset);
break;
}
buf += bytes; buf += bytes;
offset += bytes; offset += bytes;
} }
if (count != size) { if (count != size)
fprintf(stderr, "%s, R failed 0x%lx != 0x%lx.\n", fprintf(stderr, "%s, write underflow 0x%lx != 0x%lx.\n",
fname, count, size); fname, count, size);
return -EIO;
}
return count; return count;
} }
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#define DRV_MOD_MAJOR 2020 #define DRV_MOD_MAJOR 2020
#define DRV_MOD_MINOR 1 #define DRV_MOD_MINOR 1
#define DRV_MOD_PATCHLEVEL 06 #define DRV_MOD_PATCHLEVEL 07
#define DRV_MODULE_VERSION \ #define DRV_MODULE_VERSION \
__stringify(DRV_MOD_MAJOR) "." \ __stringify(DRV_MOD_MAJOR) "." \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment