ngc 1.4.0
 
Loading...
Searching...
No Matches
ngcbSched.h
Go to the documentation of this file.
1
7#ifndef ngcbSched_h
8#define ngcbSched_h
9
10
11
12#ifndef _REENTRANT
13#define _REENTRANT
14#endif
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <unistd.h>
19#include <signal.h>
20#include <string.h>
21#include <errno.h>
22#include <sys/time.h>
23#include <pthread.h>
24
25#include <ngc/core/ngcb.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/*
32 * CPU profiles
33 */
34#ifndef NGC_CCV
35#define NGC_CCV 11
36#endif
37#define ngcbCPU_PROFILE_DMA 1
38#define ngcbCPU_PROFILE_UDP 2
39
40/*
41 * CPU affinity flags
42 */
43#define ngcbCPU_ANY -1
44#define ngcbCPU_SHARED -2
45#define ngcbCPU_HIGH -3
46#define ngcbCPU_EXACT 0x1
47#define ngcbCPU_EXCLUDE 0x2
48
52typedef pthread_t ngcb_thread_t;
53
57typedef struct timespec ngcb_abstime_t;
58
62#define ngcbGetAbsTime(t) clock_gettime(CLOCK_REALTIME, t)
63
67#define ngcbSEM_FAST 0
68
72#define ngcbSEM_CHECKED 1
73
77typedef struct {
78 pthread_mutex_t mutex_v;
79 pthread_cond_t lck;
80 size_t val;
82
86typedef struct {
87 pthread_mutex_t mutex_v;
88 pthread_cond_t lckr;
89 pthread_cond_t lckw;
90 unsigned int val;
91 unsigned char wr;
93
94/*
95 * Priority control
96 */
97#define ngcbPRI_TS 1
98#define ngcbPRI_IA 2
99#define ngcbPRI_RT 3
100#define ngcbTQ_DEF 0
101#define ngcbTQ_NC -1
102#define ngcbTQ_INF -2
103
107extern int ngcbPrio;
108
112int ngcbSetPrio(int priority, int schedClass, int quantum);
113
117int ngcbGetPrio(int *priority, int *schedClass, int *quantum);
118
122void ngcbClockInit(void);
123
129
135
140double ngcbTimeStamp();
141
147uint64_t ngcbTimeStamp64();
148
155int _ngcbClockWait(int fd, int waitTime);
156
160#define ngcbClockWait(fd, waitTime) ngcbMicroSleep(fd, waitTime)
161
162/*
163 * Threads
164 */
165
170int ngcbThrCreate(void *(*startFunc)(void *), void *arg, size_t stack,
171 ngcb_thread_t *thread);
172
176void ngcbThrExit(void *status);
177
181int ngcbThrCancel(ngcb_thread_t thread);
182
186int ngcbThrKill(ngcb_thread_t thread, int sig);
187
191int ngcbThrJoin(ngcb_thread_t thread);
192
197
203
207extern int ngcbCpuProfile;
208
212int ngcbCpuNumCores(void);
213
217int ngcbCpuRT(void);
218
222int ngcbCpu2Thread(ngcb_thread_t thread, int cpu, int flag);
223
227int ngcbCpuAssign(int cpu, int flag);
228
232void ngcbCpuShow(const char *name);
233
237int ngcbCpuDisableLatencyStates(char *erms);
238
242void ngcbCpuResetLatencyStates(int fd);
243
244/*
245 * Semaphores
246 */
247
254int ngcbSemInit(ngcb_sema_t *sp, unsigned int count, int type, void *arg);
255
260
266int ngcbSemLock(ngcb_sema_t *sp);
267
272
279
283int ngcbSemPost(ngcb_sema_t *sp);
284
288int ngcbSemSet(ngcb_sema_t *sp, unsigned int cnt);
289
295int ngcbSemWait(ngcb_sema_t *sp);
296
302size_t ngcbSemWaitCnt(ngcb_sema_t *sp, size_t cnt);
303
312
318
322size_t ngcbSemCnt(ngcb_sema_t *sp);
323
324
325/*
326 * Readers/writer locks
327 */
328
332int ngcbRwLockInit(ngcb_lock_t *rwlp, int type, void *arg);
333
338
346int ngcbRwRdLock(ngcb_lock_t *rwlp);
347
354
362int ngcbRwWrLock(ngcb_lock_t *rwlp);
363
370
381int ngcbRwUnlock(ngcb_lock_t *rwlp);
382
383
384/*
385 * Synchronous multi-threading
386 */
387
392int ngcbProcCreate(void (*calcProcess)(void *), int n, char *erms);
393
400int ngcbProcCreate2(void (*calcProcess)(void *), int n, size_t stack,
401 char *erms);
402
406int ngcbProcWaitStart(int procId);
407
411int ngcbProcWaitTrigger(int procId);
412
416int ngcbProcAck(int procId);
417
421int ngcbProcStart(int setId);
422
426int ngcbProcTrigger(int setId) ;
427
431int ngcbProcWaitAck(int setId);
432
437int ngcbProcSync(int procId);
438
442void ngcbProcJoin(int setId);
443
447void ngcbProcFree(int setId);
448
452#define ngcbPROC_MAX_SET 8
453
457#define ngcbPROC_MAX_PROC 1024
458
462#define ngcbProcId(x) (int)((unsigned long)x & 0xffffffff)
463
467#define ngcbProcNum(x) (int)(x & 0x0000ffff)
468
469#ifdef __cplusplus
470}
471#endif
472
473#endif
int ngcbRwLockDestroy(ngcb_lock_t *rwlp)
Definition ngcbSchedSem.c:307
int ngcbCpuAssign(int cpu, int flag)
Definition ngcbSchedCpu.c:193
ngcb_thread_t ngcbThrId(void)
Definition ngcbSchedThread.c:94
int ngcbProcWaitTrigger(int procId)
Definition ngcbSchedProc.c:371
int ngcbRwRdLock(ngcb_lock_t *rwlp)
Definition ngcbSchedSem.c:333
int _ngcbClockWait(int fd, int waitTime)
Definition ngcbSchedClock.c:130
int ngcbProcStart(int setId)
Definition ngcbSchedProc.c:328
int ngcbCpuDisableLatencyStates(char *erms)
Definition ngcbSchedCpu.c:233
void ngcbCpuResetLatencyStates(int fd)
Definition ngcbSchedCpu.c:254
uint64_t ngcbTimeStamp64()
Definition ngcbSchedClock.c:122
int ngcbPrio
Definition ngcbSchedPrio.c:22
void ngcbThrExit(void *status)
Definition ngcbSchedThread.c:53
int ngcbSemSet(ngcb_sema_t *sp, unsigned int cnt)
Definition ngcbSchedSem.c:141
int ngcbSemLock(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:87
pthread_t ngcb_thread_t
Definition ngcbSched.h:52
int ngcbSemWaitAbsTime(ngcb_sema_t *sp, ngcb_abstime_t *absTime)
Definition ngcbSchedSem.c:197
int ngcbRwUnlock(ngcb_lock_t *rwlp)
Definition ngcbSchedSem.c:442
int ngcbProcAck(int procId)
Definition ngcbSchedProc.c:391
int ngcbRwTryWrLock(ngcb_lock_t *rwlp)
Definition ngcbSchedSem.c:404
void ngcbClockGet(ngcb_time_hr *t)
Definition ngcbSchedClock.c:77
int ngcbSemUnlock(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:95
int ngcbSemPost(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:122
int ngcbRwLockInit(ngcb_lock_t *rwlp, int type, void *arg)
Definition ngcbSchedSem.c:267
int ngcbCpuRT(void)
Definition ngcbSchedCpu.c:31
struct timespec ngcb_abstime_t
Definition ngcbSched.h:57
int ngcbSetPrio(int priority, int schedClass, int quantum)
Definition ngcbSchedPrio.c:73
int ngcbProcTrigger(int setId)
Definition ngcbSchedProc.c:404
int ngcbSemInit(ngcb_sema_t *sp, unsigned int count, int type, void *arg)
Definition ngcbSchedSem.c:18
size_t ngcbSemCnt(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:253
int ngcbProcCreate2(void(*calcProcess)(void *), int n, size_t stack, char *erms)
Definition ngcbSchedProc.c:70
int ngcbCpu2Thread(ngcb_thread_t thread, int cpu, int flag)
Definition ngcbSchedCpu.c:47
int ngcbRwTryRdLock(ngcb_lock_t *rwlp)
Definition ngcbSchedSem.c:352
void ngcbProcFree(int setId)
Definition ngcbSchedProc.c:300
int ngcbThrEqual(ngcb_thread_t t1, ngcb_thread_t t2)
Definition ngcbSchedThread.c:99
int ngcbRwWrLock(ngcb_lock_t *rwlp)
Definition ngcbSchedSem.c:381
void ngcbClockInit(void)
Definition ngcbSchedClock.c:31
int ngcbSemDestroy(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:69
int ngcbSemTryWait(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:222
int ngcbCpuProfile
Definition ngcbSchedCpu.c:21
int ngcbProcCreate(void(*calcProcess)(void *), int n, char *erms)
Definition ngcbSchedProc.c:64
int ngcbSemTryLock(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:103
int ngcbThrKill(ngcb_thread_t thread, int sig)
Definition ngcbSchedThread.c:70
void ngcbClockGetAbs(ngcb_time_hr *t)
Definition ngcbSchedClock.c:39
int ngcbSemWait(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:160
int ngcbProcWaitAck(int setId)
Definition ngcbSchedProc.c:414
int ngcbGetPrio(int *priority, int *schedClass, int *quantum)
Definition ngcbSchedPrio.c:44
void ngcbCpuShow(const char *name)
Definition ngcbSchedCpu.c:199
size_t ngcbSemWaitCnt(ngcb_sema_t *sp, size_t cnt)
Definition ngcbSchedSem.c:176
int ngcbThrJoin(ngcb_thread_t thread)
Definition ngcbSchedThread.c:82
int ngcbCpuNumCores(void)
Definition ngcbSchedCpu.c:24
void ngcbProcJoin(int setId)
Definition ngcbSchedProc.c:318
int ngcbThrCreate(void *(*startFunc)(void *), void *arg, size_t stack, ngcb_thread_t *thread)
Definition ngcbSchedThread.c:18
int ngcbProcWaitStart(int procId)
Definition ngcbSchedProc.c:351
double ngcbTimeStamp()
Definition ngcbSchedClock.c:115
int ngcbThrCancel(ngcb_thread_t thread)
Definition ngcbSchedThread.c:58
int ngcbProcSync(int procId)
Definition ngcbSchedProc.c:429
Definition ngcbSched.h:86
unsigned int val
Definition ngcbSched.h:90
unsigned char wr
Definition ngcbSched.h:91
pthread_mutex_t mutex_v
Definition ngcbSched.h:87
pthread_cond_t lckr
Definition ngcbSched.h:88
pthread_cond_t lckw
Definition ngcbSched.h:89
Definition ngcbSched.h:77
pthread_cond_t lck
Definition ngcbSched.h:79
pthread_mutex_t mutex_v
Definition ngcbSched.h:78
size_t val
Definition ngcbSched.h:80
Definition ngcb.h:207