33
35
// if set to 0, the update only happens when INT is received
35
37
#define HUGE_PAGE 1 // number of pages per huge page
36
#define TLP_SIZE 32 // TLP SIZE = 64 for 256B payload, 32 for 128B payload
38
#define TLP_SIZE 64 // TLP SIZE = 64 for 256B payload, 32 for 128B payload
37
39
#define PAGE_SIZE 4096 // other values are not supported in the kernel
39
//#define USE_64 // Lorenzo: use 64bit addressing
41
#define USE_64 // Lorenzo: use 64bit addressing
41
43
//#define DUAL_CORE // Lorenzo: DUAL Core
144
146
pcilib_kmem_handle_t *kdesc;
145
147
pcilib_kmem_handle_t *kbuf;
146
148
struct timeval start, end;
147
size_t run_time, size;
148
long long int size_mb;
149
151
void* volatile bar;
150
152
uintptr_t bus_addr[BUFFERS];
151
153
uintptr_t kdesc_bus;
152
154
volatile uint32_t *desc;
153
155
typedef volatile uint32_t *Tbuf;
154
156
Tbuf ptr[BUFFERS];
158
#ifdef SWITCH_GENERATOR
155
159
int switch_generator = 0;
160
#endif /* SWITCH_GENERATOR */
157
162
float performance, perf_counter;
158
163
pcilib_bar_t bar_tmp = BAR;
159
164
uintptr_t offset = 0;
161
166
unsigned int temp;
162
int iterations_completed, buffers_filled;
167
unsigned iterations_completed, buffers_filled;
168
173
printf("\n\n**** **** **** KIT-DMA TEST **** **** ****\n\n");
170
size = ITERATIONS * BUFFERS * HUGE_PAGE * PAGE_SIZE;
171
175
size_mb = ITERATIONS * BUFFERS * HUGE_PAGE * 4 / 1024;
172
176
printf("Total size of memory buffer: \t %.3lf GBytes\n", (float)size_mb/1024 );
173
printf("Using %d Buffers with %d iterations\n\n", BUFFERS, ITERATIONS );
177
printf("Using %u Buffers with %u iterations\n\n", BUFFERS, ITERATIONS );
175
179
#ifdef ADD_DELAYS
176
180
long rpt = 0, rpt2 = 0;
235
239
// Pointers for Virtualized Mem
236
240
for (j = 0; j < BUFFERS; j++) {
237
241
ptr[j] = (volatile uint32_t*)pcilib_kmem_get_block_ua(pci, kbuf, j);
238
memset((ptr[j]), 0, HUGE_PAGE * PAGE_SIZE);
242
memset((void*)ptr[j], 0, HUGE_PAGE * PAGE_SIZE);
329
332
#ifdef CHECK_READY
330
333
printf("* PCIe: Testing...");
332
if (err != 335746816) {
335
if (err == 335746816 || err == 335681280) {
336
printf("\xE2\x9C\x93 \n");
333
338
printf("\xE2\x9C\x98\n PCIe not ready!\n");
336
printf("\xE2\x9C\x93 \n");
400
403
bus_addr[j] = pcilib_kmem_get_block_ba(pci, kbuf, j);
401
404
// LEAVE THIS DELAY???!?!?!?!
403
printf("Writing descriptor num. %ld: \t %08lx \r", j, bus_addr[j]);
406
printf("Writing descriptor num. %d: \t %08lx \r", j, bus_addr[j]);
404
407
WR(0x50, bus_addr[j]);
550
553
pcilib_kmem_sync_block(pci, kbuf, PCILIB_KMEM_SYNC_FROMDEVICE, curbuf);
551
554
#ifdef CHECK_RESULTS
552
memcpy(temp_data[i][curbuf], ptr[curbuf], 4096);
555
memcpy(temp_data[i][curbuf], (void*)ptr[curbuf], 4096);
554
557
#ifdef SHARED_MEMORY
555
memcpy(shared_memory, ptr[curbuf], 4096);
558
memcpy(shared_memory, (void*)ptr[curbuf], 4096);
557
560
//printf("\ncurbuf: %08x", curbuf);
558
561
//printf("\nbus_addr[curbuf]\n: %08x",bus_addr[curbuf]);
616
619
iterations_completed = i;
617
620
buffers_filled = curbuf;
618
if (empty) printf("* DMA: Empty FIFO! Last iteration: %li of %li\n", i+1, ITERATIONS);
621
if (empty) printf("* DMA: Empty FIFO! Last iteration: %u of %u\n", i+1, ITERATIONS);
619
622
printf ("* DMA: Stop\n\n");
621
624
#ifdef CHECK_RESULTS
633
636
run_time = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec);
634
size = (long long int) (( BUFFERS * (iterations_completed) + buffers_filled) * HUGE_PAGE * PAGE_SIZE);
635
637
size_mb = (long long int) (( BUFFERS * (iterations_completed) + buffers_filled) * HUGE_PAGE * 4 / 1024);
636
printf("Performance: transfered %zu Mbytes in %zu us using %d buffers\n", (size_mb), run_time, BUFFERS);
638
printf("Performance: transfered %zu Mbytes in %zu us using %u buffers\n", (size_mb), run_time, BUFFERS);
637
639
//printf("Buffers: \t %d \n", BUFFERS);
638
640
//printf("Buf_Size: \t %d \n", PAGE_SIZE);
639
641
//printf("Perf_counter: \t %f \n", perf_counter);
681
683
if ((mem_diff == -1) || (k == 1023) )
684
fprintf(error_log, "Error in: \t IT %li \t BUF : %li \t OFFSET: %li \t | %08x --> %08x - DIFF: %d \n", i, j, k, temp_data[i][j][k], temp_data[i][j][k+1], mem_diff);
686
fprintf(error_log, "Error in: \t IT %u \t BUF : %u \t OFFSET: %u \t | %08x --> %08x - DIFF: %d \n", i, j, k, temp_data[i][j][k], temp_data[i][j][k+1], mem_diff);
691
693
if (mem_diff == (1))
694
fprintf(error_log, "Error_2 in: \t IT %li \t BUF : %li \t OFFSET: %li \t | %08x --> %08x - DIFF: %d \n", i, j, k, temp_data[i][j+1][0], temp_data[i][j][1023], mem_diff);
696
fprintf(error_log, "Error_2 in: \t IT %u \t BUF : %u \t OFFSET: %u \t | %08x --> %08x - DIFF: %d \n", i, j, k, temp_data[i][j+1][0], temp_data[i][j][1023], mem_diff);
700
702
loadBar(i+1, ITERATIONS, ITERATIONS, 30);
702
704
for (j = 0; j < buffers_filled; j++) {
703
for (k = 0; k < 1024 ; k++)
705
for (k = 0; k < 1024 ; k++) {
705
706
mem_diff = ((uint32_t)temp_data[iterations_completed][j][k] - (uint32_t)temp_data[iterations_completed][j][k+1]);
706
if ((mem_diff == -1) || (k == 1023) )
709
fprintf(error_log, "Error in: \t IT %li \t BUF : %li \t OFFSET: %li \t | %08x --> %08x - DIFF: %d \n", iterations_completed, j, k, temp_data[iterations_completed][j][k], temp_data[iterations_completed][j][k+1], mem_diff);
707
if ((mem_diff == -1) || (k == 1023) ) {
710
fprintf(error_log, "Error in: \t IT %u \t BUF : %u \t OFFSET: %u \t | %08x --> %08x - DIFF: %d \n", iterations_completed, j, k, temp_data[iterations_completed][j][k], temp_data[iterations_completed][j][k+1], mem_diff);
713
if (j != buffers_filled-1) {
714
if (j < (buffers_filled-1)) {
714
715
// Check first and Last
715
716
mem_diff = (uint32_t)(temp_data[i][j+1][0] - temp_data[i][j][1023]);
719
fprintf(error_log, "Error_2 in: \t IT %li \t BUF : %li \t OFFSET: %li \t | %08x --> %08x - DIFF: %d \n", iterations_completed, j, k, temp_data[iterations_completed][j+1][0], temp_data[iterations_completed][j][1023], mem_diff);
717
if (mem_diff == (1)) {
720
fprintf(error_log, "Error_2 in: \t IT %u \t BUF : %u \t OFFSET: %u \t | %08x --> %08x - DIFF: %d \n", iterations_completed, j, k, temp_data[iterations_completed][j+1][0], temp_data[iterations_completed][j][1023], mem_diff);
735
736
free(temp_data[i][j]);
739
#endif /* CHECK_RESULTS */
740
741
pcilib_free_kernel_memory(pci, kbuf, free_flags);
741
742
pcilib_free_kernel_memory(pci, kdesc, free_flags);