Пример #1
0
void func_worker_1(void* arg) {
  mp_init();
  
  spd_t * sport2 = mp_create_sport(CHAN_ID_TWO,SINK,SAMPLE_SIZE*sizeof(short));
  spd_t * sport1 = mp_create_sport(CHAN_ID_ONE,SOURCE,SAMPLE_SIZE*sizeof(short));
  if (sport1 == NULL || sport2 == NULL) {
    //exit(1);
  }
  volatile short _SPM * sample = mp_alloc(SAMPLE_SIZE*sizeof(short));

  for (int i = 0; i < SAMPLE_SIZE; ++i) {
    sample[i] = i;
  }

  mp_init_ports();


  while(done == 0);

  for (int i = 0; i < ITERATIONS; ++i) {
      int ret = mp_read(sport2,sample);
      for (int i = 0; i < SAMPLE_SIZE; ++i) {
        if(sample[i] != i) {
          break;
        }
      }
      for (int i = 0; i < 100000; ++i)
      {
        asm volatile (""::);
      }
  }

  //for (int i = 0; i < ITERATIONS/2; ++i) {
  for (int i = 0; i < ITERATIONS*20; ++i) {
    mp_write(sport1,sample);
    for (int i = 0; i < SAMPLE_SIZE; ++i) {
      sample[i] = i;
    }
    //for (int i = 0; i < 100000; ++i) {
    //  asm volatile (""::);
    //}
    mp_write(sport1,sample);
    for (int i = 0; i < SAMPLE_SIZE; ++i) {
      sample[SAMPLE_SIZE-1-i] = i;
    }
    //for (int i = 0; i < 100000; ++i) {
    //  asm volatile (""::);
    //}
  }

  
  
  int ret = 0;
  corethread_exit(&ret);
  return;
}
Пример #2
0
void func_worker_1(void* arg) {
    // Cast and load the parameter
    int worker_1_param = *((int*)arg);
    // Create the queuing ports
    spd_t * chan = mp_create_sport(MP_CHAN_1_ID, SOURCE, MP_CHAN_1_MSG_SIZE);
    if (chan == NULL) {
        DEBUGF(chan);
        abort();
    }
    volatile unsigned long long _SPM * time_sample = mp_alloc(MP_CHAN_1_MSG_SIZE);
    // Initialize the communication channels
    int retval = mp_init_ports();
    // TODO: check on retval

    slave= 1;

    for (unsigned long long start = get_cpu_usecs(); start + RUNTIME > get_cpu_usecs(); ) {
        *time_sample = get_cpu_usecs();
        mp_write(chan,time_sample);
    }

    int ret = 0;
    corethread_exit(&ret);
    return;
}
Пример #3
0
int main() {
  
  corethread_t worker_1 = SLAVE_CORE; // For now the core ID
     
  corethread_create(&worker_1,&func_worker_1,(void*)&worker_1);
  puts("Corethread created");

  unsigned short int local_phase = 0;
  min_time = ULONG_MAX;
  max_time = 0;
  accum_time = 0;
  cnt_time = 0;

  unsigned long long int start = 0;
  unsigned long long int stop = 0;

  spd_t * sport1 = mp_create_sport(CHAN_ID_ONE,SINK,SAMPLE_SIZE*sizeof(short));
  spd_t * sport2 = mp_create_sport(CHAN_ID_TWO,SOURCE,SAMPLE_SIZE*sizeof(short));
  if (sport1 == NULL || sport2 == NULL) {
    //exit(1);
  }
  volatile short _SPM * sample = mp_alloc(SAMPLE_SIZE*sizeof(short));

  mp_init_ports();

  done = 1;

  int balance = 0;
  for (int i = 0; i < SAMPLE_SIZE; ++i) {
    sample[i] = i;
  }
  for (int i = 0; i < ITERATIONS/2; ++i) {
    mp_write(sport2,sample);
    for (int i = 0; i < SAMPLE_SIZE; ++i) {
      sample[i] = i;
    }
  }

  for (int i = 0; i < ITERATIONS/2; ++i) {
    mp_write(sport2,sample);
    for (int i = 0; i < SAMPLE_SIZE; ++i) {
      sample[SAMPLE_SIZE-1-i] = i;
    }
  }



  for (int i = 0; i < ITERATIONS; ++i) {
    start = get_cpu_usecs();
    int ret = mp_read(sport1,sample);
    stop = get_cpu_usecs();
    if (ret == 0)
    {
      puts("No value written yet.");
    } else {
      unsigned long long int exe_time = stop - start;
      min_time = (exe_time < min_time) ? exe_time : min_time;
      max_time = (exe_time > max_time) ? exe_time : max_time;
      accum_time += exe_time;
      cnt_time++;
      if (sample[0] == 0) {
        balance++;
        for (int i = 0; i < SAMPLE_SIZE; ++i) {
          if(sample[i] != i) {
            printf("Error: sample[%i] = %i\n",i,sample[i]);
            break;
          }
        }
      } else if (sample[0] == SAMPLE_SIZE-1) {
        balance--;
        for (int i = 0; i < SAMPLE_SIZE; ++i) {
          if(sample[SAMPLE_SIZE-1-i] != i) {
            printf("Error: sample[%i] = %i\n",i,sample[i]);
            break;
          }
        }
      } else {
        printf("Wrong sample values sample[0] = %i\n",sample[0]);
      }
    }
  }

  printf("Local phase: %d\n",local_phase);
  
  inval_dcache();

  int* res;
  corethread_join(worker_1,&res);

  printf("Balance: %i\n",balance);
  printf("Min time: %llu\tMax time: %llu\tAccumulated time: %llu\nCount time: %llu\tAverage time: %llu\n", min_time,max_time,accum_time,cnt_time,accum_time/cnt_time);

  puts("Corethread joined");

  return *res;  
}