1/*
2 * Copyright (c) 2007-12 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 <stdio.h>
11#include <string.h>
12#include <stdlib.h>
13
14#include <barrelfish/barrelfish.h>
15#include <barrelfish/dispatch.h>
16
17#include <xeon_phi/xeon_phi.h>
18#include <xeon_phi/xeon_phi_client.h>
19#include <xeon_phi/xeon_phi_domain.h>
20
21#include "benchmark.h"
22
23#include "common.h"
24
25
26int main(int argc,
27         char **argv)
28{
29    errval_t err;
30
31    debug_printf("Xeon Phi Test started on the card %u.\n", disp_xeon_phi_id());
32
33    xeon_phi_client_set_callbacks(&callbacks);
34
35    err = xeon_phi_client_init(disp_xeon_phi_id());
36    EXPECT_SUCCESS(err, "xeon_phi_client_init");
37
38    alloc_local();
39
40    if (disp_xeon_phi_id() == 0) {
41        char *iface = xeon_phi_domain_build_iface(disp_name(), 1, 2);
42        debug_printf("waiting for up: %s\n", iface);
43        err = xeon_phi_domain_blocking_lookup(iface, &domainid);
44        EXPECT_SUCCESS(err, "xeon_phi_domain_blocking_lookup");
45
46        debug_printf("sending open message to %s on node 1\n", iface);
47        err = xeon_phi_client_chan_open(1, domainid, 0xcafebabe, local_frame, 2);
48        EXPECT_SUCCESS(err, "xeon_phi_client_chan_open");
49    }
50
51    wait_for_connection();
52
53    if (disp_xeon_phi_id() != 0) {
54        err = xeon_phi_client_chan_open(0, domainid, 0xdeadbeef, local_frame, 2);
55        if (err_is_fail(err)) {
56            USER_PANIC_ERR(err, "could not open channel");
57        }
58    }
59
60    if (disp_xeon_phi_id() == 1) {
61#ifndef XPHI_BENCH_THROUGHPUT
62        debug_printf("---------------- normal run -----------------\n");
63        xphi_bench_start_initator_rtt(&xphi_uc);
64        debug_printf("---------------- reversed run -----------------\n");
65        xphi_bench_start_initator_rtt(&xphi_uc_rev);
66#else
67#ifdef XPHI_BENCH_SEND_SYNC
68        debug_printf("---------------- normal run -----------------\n");
69        xphi_bench_start_initator_sync(&xphi_uc);
70        debug_printf("---------------- reversed run -----------------\n");
71        xphi_bench_start_initator_sync(&xphi_uc_rev);
72#else
73        debug_printf("---------------- normal run -----------------\n");
74        xphi_bench_start_initator_async(&xphi_uc);
75        debug_printf("---------------- reversed run -----------------\n");
76        xphi_bench_start_initator_async(&xphi_uc_rev);
77#endif
78#endif
79    } else {
80        debug_printf("giving time for host to initialize...\n");
81        for (uint32_t i = 0; i < 10; ++i) {
82            delay_ms(4000);
83            thread_yield();
84        }
85#ifndef XPHI_BENCH_THROUGHPUT
86        debug_printf("---------------- normal run -----------------\n");
87        xphi_bench_start_echo(&xphi_uc);
88        debug_printf("---------------- reversed run -----------------\n");
89        xphi_bench_start_echo(&xphi_uc_rev);
90#else
91        debug_printf("---------------- normal run -----------------\n");
92        xphi_bench_start_processor( &xphi_uc);
93        debug_printf("---------------- reversed run -----------------\n");
94        xphi_bench_start_processor( &xphi_uc_rev);
95#endif
96    }
97
98
99    while (1) {
100        messages_wait_and_handle_next();
101    }
102}
103
104