1/*
2 * Copyright (c) 2014 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, Universitaetsstrasse 64, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#ifndef __BOMP_INTERNAL_H
11#define	__BOMP_INTERNAL_H
12
13#include <assert.h>
14#include <stdio.h>
15#include <stdbool.h>
16#include <omp.h>
17#include <spin.h>
18#include <mutex.h>
19#include <environment.h>
20#include <abi.h>
21#include <icv.h>
22#include <bomp_backend.h>
23
24#include <barrelfish/barrelfish.h>
25
26
27#if XOMP_BENCH_ENABLED
28#define XOMP_BENCH_WORKER_EN 0
29#define XOMP_BENCH_MASTER_EN 0
30#include <bench/bench.h>
31#else
32#define XOMP_BENCH_WORKER_EN 0
33#define XOMP_BENCH_MASTER_EN 0
34#endif
35
36#ifdef __k1om__
37#define BOMP_DEFAULT_CORE_STRIDE 1
38#else
39/* TODO: this should been taken from the configuration i.e. use of
40 *       hyperthreads if enabled.
41 */
42#define BOMP_DEFAULT_CORE_STRIDE 1
43#endif
44typedef void (*bomp_thread_fn_t)(void *);
45
46/**
47 * \brief this struct stores thread local data such as the team / task
48 *        of this thread
49 */
50struct bomp_thread
51{
52    bomp_thread_fn_t fn;
53    void *arg;
54
55    struct bomp_task *task;
56
57};
58
59struct bomp_work {
60    void (*fn)(void *);
61    void *data;
62    unsigned thread_id;
63    unsigned num_threads;
64    unsigned num_vtreads;
65    struct bomp_barrier *barrier;
66};
67
68struct bomp_thread_local_data {
69    void *thr; // thread reference
70    struct bomp_work *work;
71    struct bomp_icv_data *icv;
72};
73
74
75extern uint32_t g_thread_limit;;
76extern struct bomp_state *g_bomp_state;
77
78/*
79 * Functions to obtain the Backend specific state pointer
80 */
81struct bomp_state * bomp_get_backend_state_bomp(void);
82struct bomp_state * bomp_get_backend_state_xomp(void);
83struct bomp_state * bomp_get_backend_state_linux(void);
84
85/* common state initialization */
86void bomp_common_init(struct bomp_state *st);
87
88/* obtaining ICV pointers */
89static inline struct omp_icv_task *bomp_get_icv_task(void)
90{
91    struct omp_icv_task *icv = NULL;
92    /*
93     * TODO: get icv_task from thread
94     */
95    void *task = NULL;
96    if (task) {
97        //
98    } else {
99        assert(g_bomp_state);
100        icv = &g_bomp_state->icv_task;
101    }
102    return icv;
103}
104
105static inline struct omp_icv_device *bomp_get_icv_device(void)
106{
107    assert(g_bomp_state);
108    return &g_bomp_state->icv_dev;
109}
110
111
112
113void bomp_set_tls(void *xdata);
114
115
116
117void bomp_start_processing(void (*fn) (void *), void *data, unsigned nthreads);
118void bomp_end_processing(void);
119
120
121#endif	/* _LIBBOMP_H */
122