111
|
1 /*
|
|
2 Copyright (c) 2014-2016 Intel Corporation. All Rights Reserved.
|
|
3
|
|
4 Redistribution and use in source and binary forms, with or without
|
|
5 modification, are permitted provided that the following conditions
|
|
6 are met:
|
|
7
|
|
8 * Redistributions of source code must retain the above copyright
|
|
9 notice, this list of conditions and the following disclaimer.
|
|
10 * Redistributions in binary form must reproduce the above copyright
|
|
11 notice, this list of conditions and the following disclaimer in the
|
|
12 documentation and/or other materials provided with the distribution.
|
|
13 * Neither the name of Intel Corporation nor the names of its
|
|
14 contributors may be used to endorse or promote products derived
|
|
15 from this software without specific prior written permission.
|
|
16
|
|
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
21 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28 */
|
|
29
|
|
30
|
|
31 #include "offload_orsl.h"
|
|
32 #include <stdlib.h>
|
|
33 #include "offload_host.h"
|
|
34 #include "orsl-lite/include/orsl-lite.h"
|
|
35
|
|
36 namespace ORSL {
|
|
37
|
|
38 static bool is_enabled = false;
|
|
39 static const ORSLTag my_tag = (const ORSLTag) "Offload";
|
|
40
|
|
41 void init()
|
|
42 {
|
|
43 const char *env_var = getenv("OFFLOAD_ENABLE_ORSL");
|
|
44 if (env_var != 0 && *env_var != '\0') {
|
|
45 int64_t new_val;
|
|
46 if (__offload_parse_int_string(env_var, new_val)) {
|
|
47 is_enabled = new_val;
|
|
48 }
|
|
49 else {
|
|
50 LIBOFFLOAD_ERROR(c_invalid_env_var_int_value,
|
|
51 "OFFLOAD_ENABLE_ORSL");
|
|
52 }
|
|
53 }
|
|
54
|
|
55 if (is_enabled) {
|
|
56 OFFLOAD_DEBUG_TRACE(2, "ORSL is enabled\n");
|
|
57 }
|
|
58 else {
|
|
59 OFFLOAD_DEBUG_TRACE(2, "ORSL is disabled\n");
|
|
60 }
|
|
61 }
|
|
62
|
|
63 bool reserve(int device)
|
|
64 {
|
|
65 if (is_enabled) {
|
|
66 int pnum = mic_engines[device].get_physical_index();
|
|
67 ORSLBusySet bset;
|
|
68
|
|
69 bset.type = BUSY_SET_FULL;
|
|
70 if (ORSLReserve(1, &pnum, &bset, my_tag) != 0) {
|
|
71 return false;
|
|
72 }
|
|
73 }
|
|
74 return true;
|
|
75 }
|
|
76
|
|
77 bool try_reserve(int device)
|
|
78 {
|
|
79 if (is_enabled) {
|
|
80 int pnum = mic_engines[device].get_physical_index();
|
|
81 ORSLBusySet bset;
|
|
82
|
|
83 bset.type = BUSY_SET_FULL;
|
|
84 if (ORSLTryReserve(1, &pnum, &bset, my_tag) != 0) {
|
|
85 return false;
|
|
86 }
|
|
87 }
|
|
88 return true;
|
|
89 }
|
|
90
|
|
91 void release(int device)
|
|
92 {
|
|
93 if (is_enabled) {
|
|
94 int pnum = mic_engines[device].get_physical_index();
|
|
95 ORSLBusySet bset;
|
|
96
|
|
97 bset.type = BUSY_SET_FULL;
|
|
98 if (ORSLRelease(1, &pnum, &bset, my_tag) != 0) {
|
|
99 // should never get here
|
|
100 }
|
|
101 }
|
|
102 }
|
|
103
|
|
104 } // namespace ORSL
|