Exemple #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;
}
Exemple #2
0
int main() {

    puts("Master");
    corethread_t worker_1 = 1; // For now the core ID
    int worker_1_param = 1;

    corethread_create(&worker_1,&func_worker_1,(void*)&worker_1_param);

    // Create the queuing ports
    spd_t * chan = mp_create_sport(MP_CHAN_1_ID, SINK, MP_CHAN_1_MSG_SIZE);

    volatile unsigned long long _SPM * time_sample = mp_alloc(MP_CHAN_1_MSG_SIZE);

    if (chan == NULL || time_sample == NULL) {
        DEBUGF(chan);
        abort();
    }

    // Initialize the communication channels
    int retval = mp_init_ports();
    // TODO: check on retval

    puts("Initialized ports");

    while(slave != 1) {
        ;
    }

    puts("Slave is ready");

    unsigned long long min_time_diff = -1;
    unsigned long long max_time_diff = 0;
    unsigned long long accum_time_diff = 0;
    unsigned long long cnt_time_diff = 0;
    unsigned long long percent = 0;
    int done = 0;
    unsigned long long start = get_cpu_usecs();
    while(!done) {
        int success = mp_read(chan,time_sample);
        unsigned long long time_diff = get_cpu_usecs() - (*time_sample);
        if (success == 0) {
            printf("No sample received\n");
        } else if ((*time_sample) == 0) {
            printf("Received empty sample, newest: %u, sample size: %u\n",chan->newest,chan->sample_size);
        } else {
            if (time_diff > 2000 ) {
                // Time difference is larger than a micro second
                printf("Time sample: %llu\tdiff: %llu\n",*time_sample,time_diff);
            }
            cnt_time_diff++;
            if (time_diff < min_time_diff) {
                min_time_diff = time_diff;
            }
            if (time_diff > max_time_diff) {
                max_time_diff = time_diff;
            }
            accum_time_diff += time_diff;
        }

        if (start + percent < get_cpu_usecs()) {
            percent += RUNTIME/10;
            printf("+");
            fflush(stdout);
        }
        if ( start + RUNTIME < get_cpu_usecs())  {
            done = 1;
        }
    }
    printf("\n");

    printf("Status:\n\tMin time diff: %llu\n\tMax time diff: %llu\n\tAvg time diff: %llu\n", min_time_diff,max_time_diff,accum_time_diff/cnt_time_diff);

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

    return *res;
}
Exemple #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;  
}