aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-dpdk/odp_schedule_if.c
blob: 2ccadf285c6e1b5a0a20598decd05a221750efcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/* Copyright (c) 2018, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

#include <odp/autoheader_internal.h>

#include <odp_schedule_if.h>
#include <odp_init_internal.h>
#include <odp_debug_internal.h>
#include <odp_global_data.h>

#include <stdlib.h>
#include <string.h>

extern const schedule_fn_t _odp_schedule_sp_fn;
extern const schedule_api_t _odp_schedule_sp_api;

extern const schedule_fn_t _odp_schedule_basic_fn;
extern const schedule_api_t _odp_schedule_basic_api;

extern const schedule_fn_t _odp_schedule_eventdev_fn;
extern const schedule_api_t _odp_schedule_eventdev_api;

const schedule_fn_t *_odp_sched_fn;
const schedule_api_t *_odp_sched_api;

uint64_t odp_schedule_wait_time(uint64_t ns)
{
	return _odp_sched_api->schedule_wait_time(ns);
}

int odp_schedule_capability(odp_schedule_capability_t *capa)
{
	return _odp_sched_api->schedule_capability(capa);
}

void odp_schedule_config_init(odp_schedule_config_t *config)
{
	memset(config, 0, sizeof(*config));

	_odp_sched_api->schedule_config_init(config);
}

int odp_schedule_config(const odp_schedule_config_t *config)
{
	int ret;
	odp_schedule_config_t defconfig;

	if (odp_global_rw->schedule_configured) {
		ODP_ERR("Scheduler has been configured already\n");
		return -1;
	}

	if (!config) {
		odp_schedule_config_init(&defconfig);
		config = &defconfig;
	}

	ret = _odp_sched_api->schedule_config(config);

	if (ret >= 0)
		odp_global_rw->schedule_configured = 1;

	return ret;
}

odp_event_t odp_schedule(odp_queue_t *from, uint64_t wait)
{
	ODP_ASSERT(odp_global_rw->schedule_configured);

	return _odp_sched_api->schedule(from, wait);
}

int odp_schedule_multi(odp_queue_t *from, uint64_t wait, odp_event_t events[],
		       int num)
{
	ODP_ASSERT(odp_global_rw->schedule_configured);

	return _odp_sched_api->schedule_multi(from, wait, events, num);
}

int odp_schedule_multi_wait(odp_queue_t *from, odp_event_t events[], int num)
{
	return _odp_sched_api->schedule_multi_wait(from, events, num);
}

int odp_schedule_multi_no_wait(odp_queue_t *from, odp_event_t events[], int num)
{
	return _odp_sched_api->schedule_multi_no_wait(from, events, num);
}

void odp_schedule_pause(void)
{
	return _odp_sched_api->schedule_pause();
}

void odp_schedule_resume(void)
{
	return _odp_sched_api->schedule_resume();
}

void odp_schedule_release_atomic(void)
{
	return _odp_sched_api->schedule_release_atomic();
}

void odp_schedule_release_ordered(void)
{
	return _odp_sched_api->schedule_release_ordered();
}

void odp_schedule_prefetch(int num)
{
	return _odp_sched_api->schedule_prefetch(num);
}

int odp_schedule_min_prio(void)
{
	return _odp_sched_api->schedule_min_prio();
}

int odp_schedule_max_prio(void)
{
	return _odp_sched_api->schedule_max_prio();
}

int odp_schedule_default_prio(void)
{
	return _odp_sched_api->schedule_default_prio();
}

int odp_schedule_num_prio(void)
{
	return _odp_sched_api->schedule_num_prio();
}

odp_schedule_group_t odp_schedule_group_create(const char *name,
					       const odp_thrmask_t *mask)
{
	return _odp_sched_api->schedule_group_create(name, mask);
}

int odp_schedule_group_destroy(odp_schedule_group_t group)
{
	return _odp_sched_api->schedule_group_destroy(group);
}

odp_schedule_group_t odp_schedule_group_lookup(const char *name)
{
	return _odp_sched_api->schedule_group_lookup(name);
}

int odp_schedule_group_join(odp_schedule_group_t group,
			    const odp_thrmask_t *mask)
{
	return _odp_sched_api->schedule_group_join(group, mask);
}

int odp_schedule_group_leave(odp_schedule_group_t group,
			     const odp_thrmask_t *mask)
{
	return _odp_sched_api->schedule_group_leave(group, mask);
}

int odp_schedule_group_thrmask(odp_schedule_group_t group,
			       odp_thrmask_t *thrmask)
{
	return _odp_sched_api->schedule_group_thrmask(group, thrmask);
}

int odp_schedule_group_info(odp_schedule_group_t group,
			    odp_schedule_group_info_t *info)
{
	return _odp_sched_api->schedule_group_info(group, info);
}

void odp_schedule_order_lock(uint32_t lock_index)
{
	return _odp_sched_api->schedule_order_lock(lock_index);
}

void odp_schedule_order_unlock(uint32_t lock_index)
{
	return _odp_sched_api->schedule_order_unlock(lock_index);
}

void odp_schedule_order_unlock_lock(uint32_t unlock_index, uint32_t lock_index)
{
	_odp_sched_api->schedule_order_unlock_lock(unlock_index, lock_index);
}

void odp_schedule_order_lock_start(uint32_t lock_index)
{
	_odp_sched_api->schedule_order_lock_start(lock_index);
}

void odp_schedule_order_lock_wait(uint32_t lock_index)
{
	_odp_sched_api->schedule_order_lock_wait(lock_index);
}

int _odp_schedule_init_global(void)
{
	const char *sched = getenv("ODP_SCHEDULER");

	if (sched == NULL || !strcmp(sched, "default"))
		sched = _ODP_SCHEDULE_DEFAULT;

	ODP_PRINT("Using scheduler '%s'\n", sched);

	if (!strcmp(sched, "basic")) {
		_odp_sched_fn = &_odp_schedule_basic_fn;
		_odp_sched_api = &_odp_schedule_basic_api;
	} else if (!strcmp(sched, "sp")) {
		_odp_sched_fn = &_odp_schedule_sp_fn;
		_odp_sched_api = &_odp_schedule_sp_api;
	} else if (!strcmp(sched, "eventdev")) {
		_odp_sched_fn = &_odp_schedule_eventdev_fn;
		_odp_sched_api = &_odp_schedule_eventdev_api;
	} else {
		ODP_ABORT("Unknown scheduler specified via ODP_SCHEDULER\n");
		return -1;
	}

	return _odp_sched_fn->init_global();
}

int _odp_schedule_term_global(void)
{
	return _odp_sched_fn->term_global();
}