/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to apps/lorenzo_ipedma_test.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-04-20 20:01:04 UTC
  • Revision ID: csa@suren.me-20150420200104-b5xny65io8lvoz3w
Big redign of model structures

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#define _POSIX_C_SOURCE 199309L
 
1
#define _POSIX_C_SOURCE 200809L
 
2
#define _BSD_SOURCE
2
3
#include <stdio.h>
3
4
#include <stdlib.h>
4
5
#include <string.h>
15
16
#include "pcilib.h"
16
17
#include "irq.h"
17
18
#include "kmem.h"
 
19
#include "pci.h"
18
20
 
19
21
//#include <sys/ipc.h>
20
22
//#include <sys/shm.h>
33
35
                                    // if set to 0, the update only happens when INT is received
34
36
 
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
38
40
 
39
 
//#define USE_64                    // Lorenzo: use 64bit addressing
 
41
#define USE_64                    // Lorenzo: use 64bit addressing
40
42
 
41
43
//#define DUAL_CORE                 // Lorenzo: DUAL Core
42
44
 
138
140
 
139
141
 
140
142
    int err;
141
 
    long i, j, k;
 
143
    int i, j, k;
142
144
    int mem_diff;
143
145
    pcilib_t *pci;
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
    size_t run_time;
 
150
    size_t 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];
 
157
 
 
158
#ifdef SWITCH_GENERATOR
155
159
    int switch_generator = 0;
156
 
   
 
160
#endif /* SWITCH_GENERATOR */
 
161
 
157
162
    float performance, perf_counter; 
158
163
    pcilib_bar_t bar_tmp = BAR; 
159
164
    uintptr_t offset = 0;
160
165
 
161
166
    unsigned int temp;
162
 
    int iterations_completed, buffers_filled;
 
167
    unsigned iterations_completed, buffers_filled;
163
168
 
164
169
 
165
170
//    int shmid;
167
172
 
168
173
    printf("\n\n**** **** **** KIT-DMA TEST **** **** ****\n\n");
169
174
 
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 );
174
178
 
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);
239
243
        }
240
244
 
241
245
        err = 0;
268
272
    FILE * error_log;
269
273
 
270
274
#ifdef CHECK_RESULTS
271
 
 
272
275
    uint32_t *temp_data[ITERATIONS][BUFFERS];
273
276
 
274
277
    for (j=0; j < ITERATIONS; j++) {
329
332
#ifdef CHECK_READY       
330
333
    printf("* PCIe: Testing...");
331
334
    RD(0x0, err);
332
 
    if (err != 335746816) {
 
335
    if (err == 335746816 || err == 335681280) {
 
336
        printf("\xE2\x9C\x93 \n");
 
337
    } else {
333
338
        printf("\xE2\x9C\x98\n PCIe not ready!\n");
334
339
        exit(0);
335
 
    } else {
336
 
        printf("\xE2\x9C\x93 \n");
337
340
    }
338
341
#endif
339
342
    
400
403
        bus_addr[j] = pcilib_kmem_get_block_ba(pci, kbuf, j);
401
404
        // LEAVE THIS DELAY???!?!?!?!
402
405
        usleep(1000);
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]);
405
408
    }
406
409
 
538
541
 
539
542
        do {
540
543
#ifdef USE_64   
541
 
                hwptr = htonl(desc[3]);
 
544
                hwptr = desc[3];
542
545
#else // 32-bit
543
 
                hwptr = htonl(desc[4]);
 
546
                hwptr = desc[4];
544
547
#endif
545
548
        j++;    
546
549
        //printf("\rcurptr: %lx \t \t hwptr: %lx", curptr, hwptr);
549
552
        do {    
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);
553
556
#endif
554
557
#ifdef SHARED_MEMORY
555
 
            memcpy(shared_memory, ptr[curbuf], 4096); 
 
558
            memcpy(shared_memory, (void*)ptr[curbuf], 4096); 
556
559
#endif            
557
560
            //printf("\ncurbuf: %08x", curbuf); 
558
561
            //printf("\nbus_addr[curbuf]\n: %08x",bus_addr[curbuf]);
615
618
 
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");
620
623
 
621
624
#ifdef CHECK_RESULTS
631
634
 
632
635
 
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);
647
649
    // ******************************************************************
648
650
 
649
651
 
650
 
    #ifdef PRINT_RESULTS
 
652
#ifdef PRINT_RESULTS
651
653
    printf("Writing Data to HDD... \n");
652
654
    for (i=0; i < iterations_completed; i++) {
653
655
        for (j=0; j < BUFFERS; j++)
666
668
        fclose(Output);
667
669
    }   
668
670
    printf("Data saved in data.out. \n");
669
 
    #endif
 
671
#endif
670
672
 
671
 
   #ifdef CHECK_RESULTS
 
673
#ifdef CHECK_RESULTS
672
674
    err = 0;
673
675
    error_log = fopen ("error_log.txt", "a");
674
676
    printf("\nChecking data ...\n");
681
683
                if ((mem_diff == -1) || (k == 1023) ) 
682
684
                    {;}
683
685
                else {
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);
685
687
                    err++;
686
688
                }
687
689
            }
691
693
                if (mem_diff == (1)) 
692
694
                    {;}
693
695
                else {
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);
695
697
                    err++;
696
698
                }
697
699
            }
700
702
        loadBar(i+1, ITERATIONS, ITERATIONS, 30);
701
703
    }
702
704
    for (j = 0; j < buffers_filled; j++) {
703
 
        for (k = 0; k < 1024 ; k++) 
704
 
        {
 
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) ) 
707
 
                {;}
708
 
            else {
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) ) {
 
708
                ;
 
709
            } else {
 
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);
710
711
                err++;
711
712
            }
712
713
        }
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]);
716
 
            if (mem_diff == (1)) 
717
 
                {;}
718
 
            else {
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)) {
 
718
                ;
 
719
            } else {
 
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);
720
721
                err++;
721
722
            }
722
723
        }
724
725
    if (err != 0) printf("\rChecking data: \xE2\x9C\x98 %d errors found  \n See \"error_log.txt\" for details \n\n", err);
725
726
    else printf("\rChecking data: \xE2\x9C\x93 no errors found  \n\n");
726
727
    fclose(error_log);
727
 
    #endif
 
728
#endif
728
729
 
729
730
 
730
731
    // *********** Free Memory
735
736
            free(temp_data[i][j]);
736
737
        }
737
738
    }
738
 
#endif CHECK_RESULTS
 
739
#endif /* CHECK_RESULTS */
739
740
 
740
741
    pcilib_free_kernel_memory(pci, kbuf,  free_flags);
741
742
    pcilib_free_kernel_memory(pci, kdesc,  free_flags);