diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/CMakeLists.txt | 8 | ||||
-rw-r--r-- | apps/compare_to_value.c | 66 | ||||
-rwxr-xr-x | apps/counters.sh | 117 | ||||
-rw-r--r-- | apps/heb_strip_bad_values.c | 98 | ||||
-rwxr-xr-x | apps/load.sh | 3 | ||||
-rw-r--r-- | apps/pio_test.c | 96 | ||||
-rw-r--r-- | apps/xilinx.c | 76 | ||||
-rw-r--r-- | apps/xilinx2.c | 225 |
8 files changed, 327 insertions, 362 deletions
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 80a506f..85457a1 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -7,5 +7,9 @@ link_directories(${UFODECODE_LIBRARY_DIRS}) add_executable(xilinx xilinx.c) target_link_libraries(xilinx pcilib rt) -add_executable(xilinx2 xilinx2.c) -target_link_libraries(xilinx2 pcilib rt) +add_executable(pio_test pio_test.c) +target_link_libraries(pio_test pcilib rt) + +add_executable(compare_to_value compare_to_value.c) + +add_executable(heb_strip_bad_values heb_strip_bad_values.c) diff --git a/apps/compare_to_value.c b/apps/compare_to_value.c new file mode 100644 index 0000000..75ad353 --- /dev/null +++ b/apps/compare_to_value.c @@ -0,0 +1,66 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +int main(int argc, char *argv[]) { + long i, j, size, num; + size_t count = 0, total = 0; + int offset = 0, toread = 1, toskip = 0; + uint32_t value; + uint32_t *buf; + + if ((argc != 4)&&(argc != 7)) { + printf("Usage: %s <file> <dwords> <value> [offset_dwords read_dwords skip_dwords] \n", argv[0]); + exit(0); + } + + FILE *f = fopen(argv[1], "r"); + if (!f) { + printf("Can't open %s\n", argv[1]); + exit(1); + } + + size = atol(argv[2]); + if (size <= 0) { + printf("Can't parse size %s\n", argv[2]); + exit(1); + } + + if (sscanf(argv[3], "%x", &value) != 1) { + printf("Can't parse register %s\n", argv[3]); + exit(1); + } + + buf = malloc(size * sizeof(uint32_t)); + if (!buf) { + printf("Can't allocate %lu bytes of memory\n", size * sizeof(uint32_t)); + exit(1); + } + + if (argc == 7) { + offset = atoi(argv[4]); + toread = atoi(argv[5]); + toskip = atoi(argv[6]); + } + + + num = fread(buf, 4, size, f); + if (num != size) { + printf("Only %lu of %lu dwords in the file\n", num, size); + exit(1); + } + fclose(f); + + for (i = offset; i < size; i += toskip) { + for (j = 0; j < toread; j++, i++) { + total++; + if (buf[i] != value) { + count++; + } + } + } + free(buf); + + printf("%lu of %lu is wrong\n", count, total); + return 0; +} diff --git a/apps/counters.sh b/apps/counters.sh deleted file mode 100755 index e3ba0f5..0000000 --- a/apps/counters.sh +++ /dev/null @@ -1,117 +0,0 @@ -#! /bin/bash - -BAR=0 -USE=1 -ITERATIONS=1 -TLP_SIZE=32 -BUFFER_SIZE=8 - -function pci { - PCILIB_PATH=`pwd`/.. - LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci $* -} - - -function reset { - pci -b $BAR -w 0 1 - usleep 1000 - pci -b $BAR -w 0 0 - pci -b $BAR -w 4 0 -} - -function read_cfg { -# echo $1 1>&2 - pci -a config -r 0x$1 | awk '{ print $2; }' -} - -function parse_config { - info=0x`pci -b $BAR -r 0 | awk '{ print $2; }'` - model=`printf "%X" $((info>>24))` - if [ $model -eq 14 ]; then - model="Xilinx Virtex-6" - else - model="Xilinx $model" - fi - version=$(((info >> 8) & 0xFF)) - data_width=$((16 * (2 ** ((info >> 16) & 0xF)))) - - echo "$model, build $version, $data_width bits" - - - next=`read_cfg 34 | cut -c 7-8` - - while [ $next -ne 0 ]; do - cap=`read_cfg $next` - capid=`echo $cap | cut -c 7-8` - if [ $capid -eq 10 ]; then - addr=`printf "%X" $((0x$next + 12))` - pcie_link1=`read_cfg $addr` - addr=`printf "%X" $((0x$next + 16))` - pcie_link2=`read_cfg $addr` - - link_speed=$((((0x$pcie_link2 & 0xF0000) >> 16))) - link_width=$((((0x$pcie_link2 & 0x3F00000) >> 20))) - - dev_link_speed=$((((0x$pcie_link1 & 0xF)))) - dev_link_width=$((((0x$pcie_link1 & 0x3F0) >> 4))) - fi - next=`echo $cap | cut -c 5-6` - done - - echo "Link: PCIe gen$link_speed x$link_width" - if [ $link_speed -ne $dev_link_speed -o $link_width -ne $dev_link_width ]; then - echo " * But device capable of gen$dev_link_speed x$dev_link_width" - fi - - info=0x`read_cfg 40` - max_tlp=$((2 ** (5 + ((info & 0xE0) >> 5)))) - echo "TLP: 32 dwords (transfering 32 TLP per request)" - if [ $max_tlp -ne $TLP_SIZE ]; then - echo " * But device is able to transfer TLP up to $max_tlp bytes" - fi - - # 2500 MT/s, but PCIe gen1 and gen2 uses 10 bit encoding - speed=$((link_width * link_speed * 2500 / 10)) -} - -reset -parse_config - -pci --enable-irq -pci --acknowledge-irq - -# TLP size -pci -b $BAR -w 0x0C 0x`echo "obase=16; $TLP_SIZE" | bc` -# TLP count -pci -b $BAR -w 0x10 0x`echo "obase=16; $BUFFER_SIZE * 1024 * 1024 / $TLP_SIZE / 4" | bc` -# Data -pci -b $BAR -w 0x14 0x13131313 - -bus="80000000" -dmaperf=0 -for i in `seq 1 $ITERATIONS`; do - for addr in $bus; do - pci -b $BAR -w 0x08 0x$addr - -#Trigger - pci -b $BAR -w 0x04 0x01 - pci --wait-irq - - status=`pci -b $BAR -r 0x04 | awk '{print $2; }' | cut -c 5-8` - if [ $status != "0101" ]; then - echo "Read failed, invalid status: $status" - fi - - dmaperf=$((dmaperf + 0x`pci -b $BAR -r 0x28 | awk '{print $2}'`)) - reset - done -done - -pci --free-kernel-memory $USE -pci --disable-irq - -echo -# Don't ask me about this formula -echo "Performance reported by FPGA: $(($BUFFER_SIZE * 1024 * 1024 * ITERATIONS * $speed / $dmaperf / 8)) MB/s" - -#pci -b $BAR -r 0 -s 32 diff --git a/apps/heb_strip_bad_values.c b/apps/heb_strip_bad_values.c new file mode 100644 index 0000000..e04a53c --- /dev/null +++ b/apps/heb_strip_bad_values.c @@ -0,0 +1,98 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> + +int main(int argc, char *argv[]) { + long i, num; + size_t count = 0, total = 0, size; + int offset = 3, toread = 1, toskip = 3; + uint32_t value; + uint32_t *buf; + uint32_t expected = 0; + uint32_t blocks = 0, status_good = 0; + + char fixed[4096]; + struct stat st_buf; + + if ((argc != 2)&&(argc != 5)) { + printf("Usage: %s <file> [offset_dwords read_dwords skip_dwords] \n", argv[0]); + exit(0); + } + + FILE *f = fopen(argv[1], "r"); + if (!f) { + printf("Can't open %s\n", argv[1]); + exit(1); + } + + stat(argv[1], &st_buf); + size = st_buf.st_size / sizeof(uint32_t); + + + buf = malloc(size * sizeof(uint32_t)); + if (!buf) { + printf("Can't allocate %lu bytes of memory\n", size * sizeof(uint32_t)); + exit(1); + } + + if (argc == 5) { + offset = atoi(argv[2]); + toread = atoi(argv[3]); + toskip = atoi(argv[4]); + } + + + num = fread(buf, 4, size, f); + if (num != size) { + printf("Failed to read %lu dwords, only %lu read\n", size, num); + exit(1); + } + fclose(f); + + sprintf(fixed, "%s.fixed", argv[1]); + f = fopen(fixed, "w"); + if (!f) { + printf("Failed to open %s for output\n", fixed); + exit(1); + } + + expected = (buf[offset]>>24) + 2; + for (i = 1; i < size; i += (toread + toskip)) { + total++; + + value = buf[i + offset] >> 24; +// printf("0x%lx: value (%lx) = expected (%lx)\n", i + offset, value, expected); + if (value == expected) { + if (!status_good) { + status_good = 1; + blocks++; + } + fwrite(&buf[i], 4, toread + toskip, f); + expected += 2; + if (expected == 0xb8) + expected = 0; + } else if ((!status_good)&&(value == 0)&&((i + toread + toskip)< size)) { + value = buf[i + offset + toread + toskip] >> 24; + if (value == 2) { + status_good = 1; + blocks++; + fwrite(&buf[i], 4, toread + toskip, f); + expected = 2; + } else { + count++; + } + } else { + printf("0x%lx: value (%x) = expected (%x)\n", (i + offset)*sizeof(uint32_t), value, expected); + status_good = 0; + count++; + } + } + fclose(f); + free(buf); + + printf("%lu of %lu is wrong\n", count, total); + return 0; +} diff --git a/apps/load.sh b/apps/load.sh deleted file mode 100755 index 6456c63..0000000 --- a/apps/load.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/bash - -echo "10ee 6028" > /sys/bus/pci/drivers/pciDriver/new_id diff --git a/apps/pio_test.c b/apps/pio_test.c new file mode 100644 index 0000000..84439ee --- /dev/null +++ b/apps/pio_test.c @@ -0,0 +1,96 @@ +#define _BSD_SOURCE +#define _POSIX_C_SOURCE 199309L +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <stdarg.h> +#include <time.h> +#include <sched.h> +#include <sys/time.h> + +#include "pcilib.h" +#include "irq.h" +#include "kmem.h" + +#define DEVICE "/dev/fpga0" +//#define REALTIME + +#define BAR PCILIB_BAR0 +#define BITS 32 +#define MASK ((1ll << BITS) - 1) + + +#define WR(addr, value) { *(uint32_t*)(bar + addr) = value; } +#define RD(addr, value) { value = *(uint32_t*)(bar + addr); } + +unsigned long long bits[BITS]; + +int main(int argc, char *argv[]) { + uint32_t i, j; + pcilib_t *pci; + uint32_t reg, value, diff, errors; + void* volatile bar; + + unsigned long long attempts = 0, failures = 0; + + if (argc < 2) { + printf("Usage: %s <register>\n", argv[0]); + exit(0); + } + + if (sscanf(argv[1], "%x", ®) != 1) { + printf("Can't parse register %s\n", argv[1]); + exit(1); + } + +#ifdef REALTIME + pid_t pid; + struct sched_param sched = {0}; + + pid = getpid(); + sched.sched_priority = sched_get_priority_min(SCHED_FIFO); + if (sched_setscheduler(pid, SCHED_FIFO, &sched)) + printf("Warning: not able to get real-time priority\n"); +#endif /* REALTIME */ + + pci = pcilib_open(DEVICE, PCILIB_MODEL_DETECT); + if (!pci) { + printf("pcilib_open\n"); + exit(1); + } + + bar = pcilib_map_bar(pci, BAR); + if (!bar) { + pcilib_close(pci); + printf("map bar\n"); + exit(1); + } + + for (i = 0; 1; i++) { + WR(reg, (i%MASK)); + RD(reg, value); + + attempts++; + if (value != (i%MASK)) { + failures++; + + diff = value ^ (i%MASK); + for (errors = 0, j = 0; j < BITS; j++) + if (diff&(1<<j)) errors++; + bits[errors]++; + + //printf("written: %x, read: %x\n", i, value); + } + + if ((i % 1048576 ) == 0) { + printf("Attempts %llu, failures %llu (", attempts, failures); + for (j = 1; j < BITS; j++) + printf("%llu ", bits[j]); + printf(")\n"); + } + + } + + pcilib_unmap_bar(pci, BAR, bar); + pcilib_close(pci); +} diff --git a/apps/xilinx.c b/apps/xilinx.c index 1ec31d7..757c388 100644 --- a/apps/xilinx.c +++ b/apps/xilinx.c @@ -2,6 +2,7 @@ #define _POSIX_C_SOURCE 199309L #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #include <stdarg.h> #include <time.h> @@ -15,23 +16,27 @@ #define DEVICE "/dev/fpga0" #define BAR PCILIB_BAR0 #define USE PCILIB_KMEM_USE(PCILIB_KMEM_USE_USER, 1) -#define BUFFERS 16 -#define ITERATIONS 16384 +#define STATIC_REGION 0x80000000 // to reserve 512 MB at the specified address, add "memmap=512M$2G" to kernel parameters +#define BUFFERS 1 +#define ITERATIONS 100 +#define TLP_SIZE 64 +#define HUGE_PAGE 4096 // number of pages per huge page #define PAGE_SIZE 4096 // other values are not supported in the kernel #define TIMEOUT 100000 /* IRQs are slow for some reason. REALTIME mode is slower. Adding delays does not really help, otherall we have only 3 checks in average. Check ready seems to be not needed and adds quite much extra time */ -//#define USE_IRQ +#define USE_IRQ //#define CHECK_READY //#define REALTIME //#define ADD_DELAYS +#define CHECK_RESULT //#define WR(addr, value) { val = value; pcilib_write(pci, BAR, addr, sizeof(val), &val); } //#define RD(addr, value) { pcilib_read(pci, BAR, addr, sizeof(val), &val); value = val; } -#define WR(addr, value) { *(uint32_t*)(bar + addr) = value; } -#define RD(addr, value) { value = *(uint32_t*)(bar + addr); } +#define WR(addr, value) { *(uint32_t*)(bar + addr + offset) = value; } +#define RD(addr, value) { value = *(uint32_t*)(bar + addr + offset); } static void fail(const char *msg, ...) { va_list va; @@ -63,7 +68,7 @@ void hpsleep(size_t ns) { int main() { int err; - int i, j; + long i, j; pcilib_t *pci; pcilib_kmem_handle_t *kbuf; uint32_t status; @@ -72,12 +77,15 @@ int main() { void* volatile bar; uintptr_t bus_addr[BUFFERS]; + pcilib_bar_t bar_tmp = BAR; + uintptr_t offset = 0; + pcilib_kmem_flags_t clean_flags = PCILIB_KMEM_FLAG_HARDWARE|PCILIB_KMEM_FLAG_PERSISTENT|PCILIB_KMEM_FLAG_EXCLUSIVE; #ifdef ADD_DELAYS long rpt = 0, rpt2 = 0; size_t best_time; - best_time = 1000000000L * PAGE_SIZE / (4L * 1024 * 1024 * 1024); + best_time = 1000000000L * HUGE_PAGE * PAGE_SIZE / (4L * 1024 * 1024 * 1024); #endif /* ADD_DELAYS */ #ifdef REALTIME @@ -99,22 +107,46 @@ int main() { fail("map bar"); } + pcilib_detect_address(pci, &bar_tmp, &offset, 1); + + // Reset + WR(0x00, 1) + usleep(1000); + WR(0x00, 0) + pcilib_enable_irq(pci, PCILIB_IRQ_TYPE_ALL, 0); pcilib_clear_irq(pci, PCILIB_IRQ_SOURCE_DEFAULT); pcilib_clean_kernel_memory(pci, USE, clean_flags); +#ifdef STATIC_REGION + kbuf = pcilib_alloc_kernel_memory(pci, PCILIB_KMEM_TYPE_REGION_C2S, BUFFERS, HUGE_PAGE * PAGE_SIZE, STATIC_REGION, USE, 0); +#else /* STATIC_REGION */ + kbuf = pcilib_alloc_kernel_memory(pci, PCILIB_KMEM_TYPE_DMA_C2S_PAGE, BUFFERS, HUGE_PAGE * PAGE_SIZE, 4096, USE, 0); +#endif /* STATIC_REGION */ - kbuf = pcilib_alloc_kernel_memory(pci, PCILIB_KMEM_TYPE_DMA_C2S_PAGE, BUFFERS, PAGE_SIZE, 4096, USE, 0); + if (!kbuf) { + printf("KMem allocation failed\n"); + exit(0); + } + + +#ifdef CHECK_RESULT + volatile uint32_t *ptr0 = pcilib_kmem_get_block_ua(pci, kbuf, 0); + memset((void*)ptr0, 0, (HUGE_PAGE * PAGE_SIZE)); - WR(0x00, 1) - usleep(1000); - WR(0x00, 0) + for (i = 0; i < (HUGE_PAGE * PAGE_SIZE / 4); i++) { + if (ptr0[i] != 0) break; + } + if (i < (HUGE_PAGE * PAGE_SIZE / 4)) { + printf("Initialization error in position %lu, value = %x\n", i * 4, ptr0[i]); + } +#endif /* CHECK_RESULT */ + WR(0x04, 0) - - WR(0x0C, 0x20) - WR(0x10, (PAGE_SIZE / 0x80)) + WR(0x0C, TLP_SIZE) + WR(0x10, (HUGE_PAGE * (PAGE_SIZE / (4 * TLP_SIZE)))) WR(0x14, 0x13131313) for (j = 0; j < BUFFERS; j++ ) { @@ -163,17 +195,31 @@ int main() { } gettimeofday(&end, NULL); +#ifdef CHECK_RESULT + pcilib_kmem_sync_block(pci, kbuf, PCILIB_KMEM_SYNC_FROMDEVICE, 0); + + for (i = 0; i < (HUGE_PAGE * PAGE_SIZE / 4); i++) { +// printf("%lx ", ptr0[i]); + if (ptr0[i] != 0x13131313) break; + } + if (i < (HUGE_PAGE * PAGE_SIZE / 4)) { + printf("Error in position %lu, value = %x\n", i * 4, ptr0[i]); + } +#endif /* CHECK_RESULT */ + pcilib_free_kernel_memory(pci, kbuf, 0); pcilib_disable_irq(pci, 0); pcilib_unmap_bar(pci, BAR, bar); pcilib_close(pci); run_time = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec); - size = (long long int)ITERATIONS * BUFFERS * PAGE_SIZE; + size = (long long int)ITERATIONS * BUFFERS * HUGE_PAGE * PAGE_SIZE; printf("%.3lf GB/s: transfered %zu bytes in %zu us using %u buffers\n", 1000000. * size / run_time / 1024 / 1024 / 1024, size, run_time, BUFFERS); # ifdef ADD_DELAYS printf("Repeats: %lf, %lf\n",1. * rpt / (ITERATIONS * BUFFERS), 1. * rpt2 / (ITERATIONS * BUFFERS)); #endif /* USE_IRQ */ + + } diff --git a/apps/xilinx2.c b/apps/xilinx2.c deleted file mode 100644 index 757c388..0000000 --- a/apps/xilinx2.c +++ /dev/null @@ -1,225 +0,0 @@ -#define _BSD_SOURCE -#define _POSIX_C_SOURCE 199309L -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <stdarg.h> -#include <time.h> -#include <sched.h> -#include <sys/time.h> - -#include "pcilib.h" -#include "irq.h" -#include "kmem.h" - -#define DEVICE "/dev/fpga0" -#define BAR PCILIB_BAR0 -#define USE PCILIB_KMEM_USE(PCILIB_KMEM_USE_USER, 1) -#define STATIC_REGION 0x80000000 // to reserve 512 MB at the specified address, add "memmap=512M$2G" to kernel parameters -#define BUFFERS 1 -#define ITERATIONS 100 -#define TLP_SIZE 64 -#define HUGE_PAGE 4096 // number of pages per huge page -#define PAGE_SIZE 4096 // other values are not supported in the kernel -#define TIMEOUT 100000 - -/* IRQs are slow for some reason. REALTIME mode is slower. Adding delays does not really help, -otherall we have only 3 checks in average. Check ready seems to be not needed and adds quite -much extra time */ -#define USE_IRQ -//#define CHECK_READY -//#define REALTIME -//#define ADD_DELAYS -#define CHECK_RESULT - -//#define WR(addr, value) { val = value; pcilib_write(pci, BAR, addr, sizeof(val), &val); } -//#define RD(addr, value) { pcilib_read(pci, BAR, addr, sizeof(val), &val); value = val; } -#define WR(addr, value) { *(uint32_t*)(bar + addr + offset) = value; } -#define RD(addr, value) { value = *(uint32_t*)(bar + addr + offset); } - -static void fail(const char *msg, ...) { - va_list va; - - va_start(va, msg); - vprintf(msg, va); - va_end(va); - printf("\n"); - - exit(-1); -} - -void hpsleep(size_t ns) { - struct timespec wait, tv; - - clock_gettime(CLOCK_REALTIME, &wait); - - wait.tv_nsec += ns; - if (wait.tv_nsec > 999999999) { - wait.tv_sec += 1; - wait.tv_nsec = 1000000000 - wait.tv_nsec; - } - - do { - clock_gettime(CLOCK_REALTIME, &tv); - } while ((wait.tv_sec > tv.tv_sec)||((wait.tv_sec == tv.tv_sec)&&(wait.tv_nsec > tv.tv_nsec))); -} - - -int main() { - int err; - long i, j; - pcilib_t *pci; - pcilib_kmem_handle_t *kbuf; - uint32_t status; - struct timeval start, end; - size_t size, run_time; - void* volatile bar; - uintptr_t bus_addr[BUFFERS]; - - pcilib_bar_t bar_tmp = BAR; - uintptr_t offset = 0; - - pcilib_kmem_flags_t clean_flags = PCILIB_KMEM_FLAG_HARDWARE|PCILIB_KMEM_FLAG_PERSISTENT|PCILIB_KMEM_FLAG_EXCLUSIVE; - -#ifdef ADD_DELAYS - long rpt = 0, rpt2 = 0; - size_t best_time; - best_time = 1000000000L * HUGE_PAGE * PAGE_SIZE / (4L * 1024 * 1024 * 1024); -#endif /* ADD_DELAYS */ - -#ifdef REALTIME - pid_t pid; - struct sched_param sched = {0}; - - pid = getpid(); - sched.sched_priority = sched_get_priority_min(SCHED_FIFO); - if (sched_setscheduler(pid, SCHED_FIFO, &sched)) - printf("Warning: not able to get real-time priority\n"); -#endif /* REALTIME */ - - pci = pcilib_open(DEVICE, PCILIB_MODEL_DETECT); - if (!pci) fail("pcilib_open"); - - bar = pcilib_map_bar(pci, BAR); - if (!bar) { - pcilib_close(pci); - fail("map bar"); - } - - pcilib_detect_address(pci, &bar_tmp, &offset, 1); - - // Reset - WR(0x00, 1) - usleep(1000); - WR(0x00, 0) - - pcilib_enable_irq(pci, PCILIB_IRQ_TYPE_ALL, 0); - pcilib_clear_irq(pci, PCILIB_IRQ_SOURCE_DEFAULT); - - pcilib_clean_kernel_memory(pci, USE, clean_flags); - -#ifdef STATIC_REGION - kbuf = pcilib_alloc_kernel_memory(pci, PCILIB_KMEM_TYPE_REGION_C2S, BUFFERS, HUGE_PAGE * PAGE_SIZE, STATIC_REGION, USE, 0); -#else /* STATIC_REGION */ - kbuf = pcilib_alloc_kernel_memory(pci, PCILIB_KMEM_TYPE_DMA_C2S_PAGE, BUFFERS, HUGE_PAGE * PAGE_SIZE, 4096, USE, 0); -#endif /* STATIC_REGION */ - - if (!kbuf) { - printf("KMem allocation failed\n"); - exit(0); - } - - -#ifdef CHECK_RESULT - volatile uint32_t *ptr0 = pcilib_kmem_get_block_ua(pci, kbuf, 0); - - memset((void*)ptr0, 0, (HUGE_PAGE * PAGE_SIZE)); - - for (i = 0; i < (HUGE_PAGE * PAGE_SIZE / 4); i++) { - if (ptr0[i] != 0) break; - } - if (i < (HUGE_PAGE * PAGE_SIZE / 4)) { - printf("Initialization error in position %lu, value = %x\n", i * 4, ptr0[i]); - } -#endif /* CHECK_RESULT */ - - WR(0x04, 0) - WR(0x0C, TLP_SIZE) - WR(0x10, (HUGE_PAGE * (PAGE_SIZE / (4 * TLP_SIZE)))) - WR(0x14, 0x13131313) - - for (j = 0; j < BUFFERS; j++ ) { - bus_addr[j] = pcilib_kmem_get_block_ba(pci, kbuf, j); - } - - gettimeofday(&start, NULL); - - for (i = 0; i < ITERATIONS; i++) { - for (j = 0; j < BUFFERS; j++ ) { -// uintptr_t ba = pcilib_kmem_get_block_ba(pci, kbuf, j); -// WR(0x08, ba) - WR(0x08, bus_addr[j]); - WR(0x04, 0x01) - -#ifdef USE_IRQ - err = pcilib_wait_irq(pci, PCILIB_IRQ_SOURCE_DEFAULT, TIMEOUT, NULL); - if (err) printf("Timeout waiting for IRQ, err: %i\n", err); - - RD(0x04, status); - if ((status&0xFFFF) != 0x101) printf("Invalid status %x\n", status); -// WR(0x04, 0x00); -#else /* USE_IRQ */ -# ifdef ADD_DELAYS -// hpsleep(best_time); - do { - rpt++; - RD(0x04, status); - } while (status != 0x101); -# else /* ADD_DELAYS */ - do { - RD(0x04, status); - } while (status != 0x101); -# endif /* ADD_DELAYS */ -#endif /* USE_IRQ */ - - WR(0x00, 1) -#ifdef CHECK_READY - do { - rpt2++; - RD(0x04, status); - } while (status != 0); -#endif /* CHECK_READY */ - WR(0x00, 0) - } - } - gettimeofday(&end, NULL); - -#ifdef CHECK_RESULT - pcilib_kmem_sync_block(pci, kbuf, PCILIB_KMEM_SYNC_FROMDEVICE, 0); - - for (i = 0; i < (HUGE_PAGE * PAGE_SIZE / 4); i++) { -// printf("%lx ", ptr0[i]); - if (ptr0[i] != 0x13131313) break; - } - if (i < (HUGE_PAGE * PAGE_SIZE / 4)) { - printf("Error in position %lu, value = %x\n", i * 4, ptr0[i]); - } -#endif /* CHECK_RESULT */ - - pcilib_free_kernel_memory(pci, kbuf, 0); - pcilib_disable_irq(pci, 0); - pcilib_unmap_bar(pci, BAR, bar); - pcilib_close(pci); - - run_time = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec); - size = (long long int)ITERATIONS * BUFFERS * HUGE_PAGE * PAGE_SIZE; - - printf("%.3lf GB/s: transfered %zu bytes in %zu us using %u buffers\n", 1000000. * size / run_time / 1024 / 1024 / 1024, size, run_time, BUFFERS); - -# ifdef ADD_DELAYS - printf("Repeats: %lf, %lf\n",1. * rpt / (ITERATIONS * BUFFERS), 1. * rpt2 / (ITERATIONS * BUFFERS)); -#endif /* USE_IRQ */ - - -} |