Developer World
Spresense SDK Library v3.3.0-375c679
mptask.h
Go to the documentation of this file.
1/****************************************************************************
2 * modules/include/asmp/mptask.h
3 *
4 * Copyright 2018 Sony Semiconductor Solutions Corporation
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17 * the names of its contributors may be used to endorse or promote
18 * products derived from this software without specific prior written
19 * permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************/
39#ifndef __INCLUDE_ASMP_MPTASK_H
40#define __INCLUDE_ASMP_MPTASK_H
41
52#include <sys/types.h>
53#include <asmp/types.h>
54#include <semaphore.h>
55#include <stdbool.h>
56
57#ifndef __DOCUMENT__
58#ifndef CONFIG_SMP
59
60/* void CPU_ZERO(FAR cpu_set_t *set); */
61
62# define CPU_ZERO(s) do { *(s) = 0; } while (0)
63
64/* void CPU_SET(int cpu, FAR cpu_set_t *set); */
65
66# define CPU_SET(c,s) do { *(s) |= (1 << (c)); } while (0)
67
68/* void CPU_CLR(int cpu, FAR cpu_set_t *set); */
69
70# define CPU_CLR(c,s) do { *(s) &= ~(1 << (c)); } while (0)
71
72/* int CPU_ISSET(int cpu, FAR const cpu_set_t *set); */
73
74# define CPU_ISSET(c,s) ((*(s) & (1 << (c))) != 0)
75
76/* int CPU_COUNT(FAR const cpu_set_t *set); */
77
78# define CPU_COUNT(s) sched_cpu_count(s)
79
80/* void CPU_AND(FAR cpu_set_t *destset, FAR const cpu_set_t *srcset1,
81 * FAR const cpu_set_t *srcset2);
82 */
83
84# define CPU_AND(d,s1,s2) do { *(d) = *(s1) & *(s2); } while (0)
85
86/* void CPU_OR(FAR cpu_set_t *destset, FAR const cpu_set_t *srcset1,
87 * FAR const cpu_set_t *srcset2);
88 */
89
90# define CPU_OR(d,s1,s2) do { *(d) = *(s1) | *(s2); } while (0)
91
92/* void CPU_XOR(FAR cpu_set_t *destset, FAR const cpu_set_t *srcset1,
93 * FAR const cpu_set_t *srcset2);
94 */
95
96# define CPU_XOR(d,s1,s2) do { *(d) = *(s1) ^ *(s2); } while (0)
97
98/* int CPU_EQUAL(FAR const cpu_set_t *set1, FAR const cpu_set_t *set2); */
99
100# define CPU_EQUAL(s1,s2) (*(s2) == *(s2))
101
102/* REVISIT: Variably sized CPU sets are not supported */
103/* FAR cpu_set_t *CPU_ALLOC(int num_cpus); */
104
105# define CPU_ALLOC(n) (FAR cpu_set_t *)malloc(sizeof(cpu_set_t));
106
107/* void CPU_FREE(cpu_set_t *set); */
108
109# define CPU_FREE(s) free(s)
110
111/* size_t CPU_ALLOC_SIZE(int num_cpus); */
112
113# define CPU_ALLOC_SIZE(n) sizeof(cpu_set_t)
114
115/* void CPU_ZERO_S(size_t setsize, FAR cpu_set_t *set); */
116
117# define CPU_ZERO_S(n,s) CPU_ZERO_S(s)
118
119/* void CPU_SET_S(int cpu, size_t setsize, FAR cpu_set_t *set); */
120
121# define CPU_SET_S(c,n,s) CPU_SET(c,s)
122
123/* void CPU_CLR_S(int cpu, size_t setsize, FAR cpu_set_t *set); */
124
125# define CPU_CLR_S(c,n,s) CPU_CLR(c,s)
126
127/* int CPU_ISSET_S(int cpu, size_t setsize, FAR const cpu_set_t *set); */
128
129# define CPU_ISSET_S(c,n,s) CPU_ISSET(c,s)
130
131/* int CPU_COUNT_S(size_t setsize, FAR const cpu_set_t *set); */
132
133# define CPU_COUNT_S(n,s) CPU_COUNT(s)
134
135/* void CPU_AND_S(size_t setsize, FAR cpu_set_t *destset,
136 * FAR const cpu_set_t *srcset1,
137 * FAR const cpu_set_t *srcset2);
138 */
139
140# define CPU_AND_S(n,d,s1,s2) CPU_AND(d,s1,s2)
141
142/* void CPU_OR_S(size_t setsize, FAR cpu_set_t *destset,
143 * FAR const cpu_set_t *srcset1,
144 * FAR const cpu_set_t *srcset2);
145 */
146
147# define CPU_OR_S(n,d,s1,s2) CPU_OR(d,s1,s2)
148
149/* void CPU_XOR_S(size_t setsize, FAR cpu_set_t *destset,
150 * FAR const cpu_set_t *srcset1,
151 * FAR const cpu_set_t *srcset2);
152 */
153
154# define CPU_XOR_S(n,d,s1,s2) CPU_XOR(d,s1,s2)
155
156/* int CPU_EQUAL_S(size_t setsize, FAR const cpu_set_t *set1,
157 * FAR const cpu_set_t *set2);
158 */
159
160# define CPU_EQUAL_S(n,s1,s2) CPU_EQUAL(s1,s2)
161
162#endif
163#endif
164
165#define NMPBINDS 8
166
174#define mptask_bindobj(t, o) mptask_bind((t), (mpobj_t *)(o))
175
187typedef enum mptask_state
188{
193} mptask_state_t;
194
208typedef struct mptask_attr
209{
210 int8_t status;
211 int8_t flags;
212 cpu_set_t affinity;
213 uint32_t exit_status;
215
222typedef struct mpbindobj
223{
224 key_t key;
225 mpobjtype_t type;
226 uint32_t value;
228
229typedef struct unified_binary
230{
231 int nr_offs; /* Number of offsets has been stored */
232 uint8_t offset[5]; /* Offset table, except CPU 0 */
233 uint8_t size[5]; /* Size table, except CPU 0 */
235
236typedef struct binary_info
237{
238 uint32_t loadaddr;
240
247typedef struct mptask
248{
249 int fd;
250 off_t filelen;
251 uintptr_t loadaddr;
252 size_t loadsize;
253 cpu_set_t cpuids;
254 int groupid;
255 mptask_attr_t attr;
256
257 /* filename is used when secure loading, and bounds is used for normal binary.
258 * So I made them into union for prevent increasing the object size.
259 */
260
261 union {
262 char filename[32];
263 mpbindobj_t bounds[NMPBINDS];
264 };
265
266 int nbounds;
267 sem_t wait;
268
269 union {
270 unified_binary_t ubin; /* Unified binary */
271 binary_info_t bin[5]; /* binary */
272 };
274
277#ifdef __cplusplus
278#define EXTERN extern "C"
279extern "C"
280{
281#else
282#define EXTERN extern
283#endif
284
285/********************************************************************************
286 * Public Function Prototypes
287 ********************************************************************************/
307int mptask_init(mptask_t *task, const char *filename);
308
324int mptask_init_secure(mptask_t *task, const char *filename);
325
339
353int mptask_destroy(mptask_t *task, bool force, int *exit_status);
354
371int mptask_bind(mptask_t *task, mpobj_t *obj);
372
387int mptask_setattr(mptask_t *task, const mptask_attr_t *attr);
388
403
419
435int mptask_assign_cpus(mptask_t *task, int ncpus);
436
450
464
480int mptask_getcpuidset(mptask_t *task, cpu_set_t *cpuids);
481
500
514int mptask_join(mptask_t *task, int *exit_status);
515
516#ifdef SDK_EXPERIMENTAL
517
532int mptask_pause(mptask_t *task);
533
547int mptask_restart(mptask_t *task);
548
549#endif /* SDK_EXPERIMENTAL */
550
553#undef EXTERN
554#ifdef __cplusplus
555}
556#endif
557
560#endif /* __INCLUDE_ASMP_MPTASK_H */
int16_t cpuid_t
Definition: types.h:64
int16_t mpobjtype_t
Definition: types.h:71
struct mptask_attr mptask_attr_t
struct mptask mptask_t
MP task object.
struct mpbindobj mpbindobj_t
Bind object type.
mptask_state
Definition: mptask.h:188
@ STATE_PAUSED
Definition: mptask.h:191
@ STATE_EXIT
Definition: mptask.h:192
@ STATE_EXEC
Definition: mptask.h:190
@ STATE_INIT
Definition: mptask.h:189
int mptask_getcpuidset(mptask_t *task, cpu_set_t *cpuids)
int mptask_getattr(mptask_t *task, mptask_attr_t *attr)
int mptask_exec(mptask_t *task)
int mptask_init(mptask_t *task, const char *filename)
cpuid_t mptask_getsubcoreid(mptask_t *task)
int mptask_init_secure(mptask_t *task, const char *filename)
int mptask_join(mptask_t *task, int *exit_status)
int mptask_assign_cpus(mptask_t *task, int ncpus)
int mptask_assign(mptask_t *task)
int mptask_destroy(mptask_t *task, bool force, int *exit_status)
int mptask_attr_init(mptask_attr_t *attr)
int mptask_setattr(mptask_t *task, const mptask_attr_t *attr)
int mptask_bind(mptask_t *task, mpobj_t *obj)
cpuid_t mptask_getcpuid(mptask_t *task)
Definition: mptask.h:237
Definition: mptask.h:223
Definition: types.h:78
Definition: mptask.h:209
int8_t status
Definition: mptask.h:210
uint32_t exit_status
Definition: mptask.h:213
cpu_set_t affinity
Definition: mptask.h:212
int8_t flags
Definition: mptask.h:211
Definition: mptask.h:248
Definition: mptask.h:230