1#include <string.h>
2#include <stdio.h>
3#include <rcce/RCCE.h>
4#include <assert.h>
5#include <inttypes.h>
6
7//#define CHECKBUF
8#define ENDLESS
9#define NO_FLOAT
10
11#ifdef NO_FLOAT
12#       include <barrelfish/barrelfish.h>
13#endif
14
15#define BUFSIZE  32
16#define MAXROUND 100000
17#define ROUNDS_PER_SLICE 5
18
19int RCCE_APP(int argc, char **argv){
20  int YOU, ME, round;
21#ifndef NO_FLOAT
22  double timer;
23#else
24  uint64_t timer = 0, sum = 0;
25#endif
26  char buffer[BUFSIZE+1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
27
28  RCCE_init(&argc, &argv);
29
30  RCCE_debug_set(RCCE_DEBUG_ALL);
31  ME = RCCE_ue();
32  printf("Core %d passed RCCE_init\n", ME);
33  if (RCCE_num_ues() != 2) {
34    if (!ME) printf("Ping pong needs exactly two UEs; try again\n");
35    return(1);
36  }
37  YOU = !ME;
38
39  // synchronize before starting the timer
40  RCCE_barrier(&RCCE_COMM_WORLD);
41#ifdef ENDLESS
42  for(;;) {
43#endif
44#ifndef NO_FLOAT
45  timer = RCCE_wtime();
46#else
47#endif
48  for (round=0; round <MAXROUND; round++) {
49    if (ME)  {
50#ifdef CHECKBUF
51        char oldcnt = buffer[0];
52#endif
53
54      RCCE_send(buffer, BUFSIZE, YOU);
55      RCCE_recv(buffer, BUFSIZE, YOU);
56
57#ifdef CHECKBUF
58      if((++oldcnt) != buffer[0]) {
59          printf("wrong value %d received, asserted %d would be there.\n",
60                 buffer[0], oldcnt);
61          for(int i = 0; i < BUFSIZE; i++) {
62              printf("%d ", buffer[i]);
63          }
64          printf("\n");
65          abort();
66      }
67      for(int i = 1; i <= 16; i++) {
68          assert(buffer[i] == i);
69      }
70#endif
71    }
72    else {
73        timer = rdtsc();
74
75      RCCE_recv(buffer, BUFSIZE, YOU);
76#ifdef CHECKBUF
77      buffer[0]++;
78#endif
79      RCCE_send(buffer, BUFSIZE, YOU);
80
81      sum += rdtsc() - timer;
82    }
83  }
84#ifndef NO_FLOAT
85  timer = RCCE_wtime()-timer;
86
87  if (!ME) printf("Round trip latency for %d bytes = %1.9lf\n", BUFSIZE, timer/MAXROUND);
88#else
89
90  if (!ME) printf("RTL %d b = %" PRIu64 "\n", BUFSIZE, sum/MAXROUND);
91  sum = 0;
92#endif
93
94#ifdef ENDLESS
95  }
96#endif
97
98  return(0);
99}
100
101