1/*
2 * Copyright (c) 2009, 2010, 2011, ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#include <string.h>
11#include <stdio.h>
12#include <rcce/RCCE.h>
13#include <assert.h>
14#include <inttypes.h>
15#include <barrelfish/barrelfish.h>
16
17#define BUFSIZE  (64 * 1024)
18#define MAXROUND 10000
19
20static char buffer[BUFSIZE+1] = { 0 };
21
22int RCCE_APP(int argc, char **argv)
23{
24  int YOU, ME, round;
25  uint64_t timer = 0, sum = 0;
26
27  RCCE_init(&argc, &argv);
28
29  ME = RCCE_ue();
30  if (RCCE_num_ues() != 2) {
31    if (!ME) printf("Ping pong needs exactly two UEs; try again\n");
32    return(1);
33  }
34  YOU = !ME;
35
36  // synchronize before starting the timer
37  for(;;) {
38      RCCE_barrier(&RCCE_COMM_WORLD);
39      for (round=0; round < MAXROUND; round++) {
40          if (ME)  {
41              RCCE_send(buffer, BUFSIZE, YOU);
42              RCCE_recv(buffer, BUFSIZE, YOU);
43          } else {
44              timer = rdtsc();
45              RCCE_recv(buffer, BUFSIZE, YOU);
46              RCCE_send(buffer, BUFSIZE, YOU);
47              sum += rdtsc() - timer;
48          }
49      }
50      if (!ME) printf("RTL %d bytes = %" PRIu64 "\n", BUFSIZE, sum/MAXROUND);
51      sum = 0;
52  }
53
54  return 0;
55}
56