OpenCores
URL https://opencores.org/ocsvn/fade_ether_protocol/fade_ether_protocol/trunk

Subversion Repositories fade_ether_protocol

[/] [fade_ether_protocol/] [trunk/] [stable_jumbo_frames_version/] [linux/] [receiver2t.c] - Diff between revs 15 and 18

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 15 Rev 18
Line 26... Line 26...
#include <sys/time.h>
#include <sys/time.h>
#include <pthread.h>
#include <pthread.h>
 
 
int frs[3]={-1,-1,-1};
int frs[3]={-1,-1,-1};
int active[3]={0,0,0};
int active[3]={0,0,0};
 
int leave[3]={0,0,0};
pthread_t ucmd_thread;
pthread_t ucmd_thread;
 
double tend=0.0;
 
 
void * user_cmd_thread(void * a1)
void * user_cmd_thread(void * a1)
{
{
  uint16_t cmd;
  uint16_t cmd;
  int i;
  int i;
  int res;
  int res;
 
  struct timeval tv;
 
  double tstart=0.0;
 
  sleep(2);
 
  for(i=0;i<=2;i++) {
 
    if(active[i]) {
 
      res = ioctl(frs[i],L3_V1_IOC_STARTMAC,NULL);
 
      printf("Result of startmac for slave %d : %d\n",i,res);
 
    }
 
  }
 
  gettimeofday(&tv, NULL);
 
  tstart=tv.tv_sec+1.0e-6*tv.tv_usec;
  //Send three commands to each slave
  //Send three commands to each slave
  //Waiting 10 seconds
  //Waiting 10 seconds
  for(cmd=0x112; cmd<=0x114; cmd++) {
  for(cmd=0x112; cmd<=0x114; cmd++) {
    sleep(10);
    sleep(10);
    //Send user command
    //Send user command
Line 55... Line 68...
        }
        }
        printf("\n");
        printf("\n");
      }
      }
    }
    }
  }
  }
 
  //Wait for 500 seconds
 
  sleep(500);
 
  for(i=0;i<=2;i++) {
 
    if(active[i]) {
 
      res = ioctl(frs[i],L3_V1_IOC_STOPMAC,NULL);
 
      printf("Result of usercmd for slave %d : %d\n",i,res);
 
    }
 
  }
 
  gettimeofday(&tv, NULL);
 
  tend=tv.tv_sec+1.0e-6*tv.tv_usec;
 
  tend=tend-tstart;
}
}
 
 
void main(int argc, char * argv[])
void main(int argc, char * argv[])
{
{
  struct l3_v1_buf_pointers bp;
  struct l3_v1_buf_pointers bp;
  struct l3_v1_slave sl[3] = {
  struct l3_v1_slave sl[3] = {
    {
    {
      .mac = {0xde, 0xad, 0xba, 0xbe, 0xbe,0xef},
      .mac = {0xde, 0xad, 0xba, 0xbe, 0xbe,0xef},
      .devname = "p4p1"
      .devname = "eth0"
    },
    },
    {
    {
      .mac = {0xde, 0xad, 0xba, 0xbe, 0xbe,0xe1},
      .mac = {0xde, 0xad, 0xba, 0xbe, 0xbe,0xe1},
      .devname = "p4p1"
      .devname = "eth0"
    },
    },
    {
    {
      .mac = {0xde, 0xad, 0xba, 0xbe, 0xbe,0xe2},
      .mac = {0xde, 0xad, 0xba, 0xbe, 0xbe,0xe2},
      .devname = "p4p1"
      .devname = "eth0"
    }
    }
  };
  };
  int i,j;
  int i,j;
  int res;
  int res;
  int blen[3];
  int blen[3];
  uint64_t data[3] = {0,0,0};
  uint64_t data[3] = {0,0,0};
  long long total_len[3]={0,0,0};
  long long total_len[3]={0,0,0};
  unsigned char * v[3];
  unsigned char * v[3];
  struct timeval tv;
 
  double tstart=0.0 , tend=0.0;
 
  int stop;
  int stop;
  struct sched_param s;
  struct sched_param s;
  s.sched_priority = 90;
  s.sched_priority = 90;
  //Read active channels
  //Read active channels
  for(i=1;i<argc;i++) {
  for(i=1;i<argc;i++) {
Line 113... Line 135...
    if(!v[i]) {
    if(!v[i]) {
      printf("mmap for device %s failed\n",devname);
      printf("mmap for device %s failed\n",devname);
      exit(1);
      exit(1);
    }
    }
  }
  }
  //Start the second thread, which uses user commands
 
  pthread_create(&ucmd_thread, NULL, user_cmd_thread, NULL);
 
  //Start the transmission
  //Start the transmission
  gettimeofday(&tv, NULL);
 
  tstart=tv.tv_sec+1.0e-6*tv.tv_usec;
 
  stop=tv.tv_sec+300;
 
  for(i=0;i<=2;i++) {
  for(i=0;i<=2;i++) {
    if(active[i]) {
    if(active[i]) {
      res = ioctl(frs[i],L3_V1_IOC_GETMAC,&sl[i]);
      res = ioctl(frs[i],L3_V1_IOC_GETMAC,&sl[i]);
      printf("Result of get for slave %d : %d\n",i,res);
      printf("Result of get for slave %d : %d\n",i,res);
      res = ioctl(frs[i],L3_V1_IOC_STARTMAC,0l);
    } else {
      printf("Result of start for slave %d : %d\n",i,res);
      leave[i]=1;
    }
    }
  }
  }
 
  //Start the second thread, which uses user commands
 
  pthread_create(&ucmd_thread, NULL, user_cmd_thread, NULL);
  int first_served=0;
  int first_served=0;
  do{
  do{
    struct pollfd pfd[3] = {{.fd = frs[0], .events = POLLIN, .revents = 0},
    struct pollfd pfd[3];
                            {.fd = frs[1], .events = POLLIN, .revents = 0},
 
                            {.fd = frs[2], .events = POLLIN, .revents = 0},
 
    };
 
    int ptr=0;
    int ptr=0;
    int len=0;
    int len=0;
    int pres;
    int pres;
 
    for(i=0;i<3;i++) {
 
      pfd[i].fd = active[i] ? frs[i] : -1;
 
      pfd[i].events = POLLIN;
 
      pfd[i].revents = 0;
 
    }
    //Wait for data using "poll"
    //Wait for data using "poll"
    pres = poll(pfd,3,-1);
    pres = poll(pfd,3,1000);
    if(pres<0) {
    if(pres<0) {
      perror("Error in poll:");
      perror("Error in poll:");
      exit(1);
      exit(1);
    }
    }
    first_served = (first_served+1) %3; //Rotate priority of slaves
    first_served = (first_served+1) %3; //Rotate priority of slaves
    for(j=0;j<3;j++) {
    for(j=0;j<3;j++) {
      i=(j+first_served) % 3;
      i=(j+first_served) % 3;
      if(pfd[i].revents) {
      if(pfd[i].revents) {
        int ofs=0;
        int ofs=0;
        len = ioctl(frs[i],L3_V1_IOC_READPTRS,&bp);
        len = ioctl(frs[i],L3_V1_IOC_READPTRS,&bp);
 
        if(bp.eof) leave[i]=1;
        //OK. The data are read, let's analyze them
        //OK. The data are read, let's analyze them
        while (bp.head != bp.tail)  {
        while (bp.head != bp.tail)  {
          uint64_t c;
          uint64_t c;
          c = be64toh(*(uint64_t *)(v[i]+bp.tail));
          c = be64toh(*(uint64_t *)(v[i]+bp.tail));
          bp.tail=(bp.tail+8) & (blen[i]-1); //Adjust tail pointer modulo blen[i]-1
          bp.tail=(bp.tail+8) & (blen[i]-1); //Adjust tail pointer modulo blen[i]
          if (__builtin_expect((c != data[i]), 0)) {
          if (__builtin_expect((c != data[i]), 0)) {
            printf("Error! received: %lld expected: %lld position: %8.8x\n",c,data[i],total_len[i]+ofs);
            printf("Error! received: %llx expected: %llx position: %8.8x\n",c,data[i],total_len[i]+ofs);
            exit(1);
            exit(1);
          }
          }
          data[i] += 0x1234567809abcdefL;
          data[i] += 0x1234567809abcdefL;
          ofs++;
          ofs++;
        }
        }
        total_len[i] += len;
        total_len[i] += len;
        //printf("i=%d len=%d total=%lld head:%d tail: %d\n",i,len,total_len[i],bp.head, bp.tail);
        //printf("i=%d len=%d total=%lld head:%d tail: %d revents=%d eof=%d\n",i,len,total_len[i],bp.head, bp.tail,pfd[i].revents,(int)bp.eof);
        ioctl(frs[i],L3_V1_IOC_WRITEPTRS,len);
        ioctl(frs[i],L3_V1_IOC_WRITEPTRS,len);
      }
      }
    }
    }
    fflush(stdout);
    fflush(stdout);
    gettimeofday(&tv, NULL);
  } while ((leave[0] && leave[1] && leave[2]) == 0);
    if(tv.tv_sec > stop) {
 
      tend=tv.tv_sec+1.0e-6*tv.tv_usec;
 
      break;
 
    }
 
  } while (1);
 
  tend=tend-tstart;
 
  fprintf(stderr,"act0:%d act1:%d act2:%d\n",active[0],active[1],active[2]);
 
  for(i=0;i<3;i++) {
 
    fprintf(stderr,"total data %d=%lld time=%g throughput=%g [Mb/s]\n",i,total_len[i], tend, total_len[i]/tend*8.0);
 
  }
 
  for(i=0;i<=2;i++) {
  for(i=0;i<=2;i++) {
    res = ioctl(frs[i],L3_V1_IOC_STOPMAC,0);
    if(active[i]) {
    res = ioctl(frs[i],L3_V1_IOC_FREEMAC,0);
    res = ioctl(frs[i],L3_V1_IOC_FREEMAC,0);
 
    }
    munmap(v[i],blen[i]);
    munmap(v[i],blen[i]);
    close(frs[i]);
    close(frs[i]);
  }
  }
  pthread_join(ucmd_thread, NULL);
  pthread_join(ucmd_thread, NULL);
 
  fprintf(stderr,"act0:%d act1:%d act2:%d\n",active[0],active[1],active[2]);
 
  for(i=0;i<3;i++) {
 
    fprintf(stderr,"total data %d=%lld time=%g throughput=%g [Mb/s]\n",i,total_len[i], tend, total_len[i]/tend*8.0);
 
  }
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.