ngc 1.5.0
 
Loading...
Searching...
No Matches
ngcbSched.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <sys/time.h>
#include <pthread.h>
#include <ngc/core/ngcb.h>

Go to the source code of this file.

Classes

struct  ngcb_sema_t
 
struct  ngcb_lock_t
 

Macros

#define _REENTRANT
 
#define NGC_CCV   11
 
#define ngcbCPU_PROFILE_DMA   1
 
#define ngcbCPU_PROFILE_UDP   2
 
#define ngcbCPU_ANY   -1
 
#define ngcbCPU_SHARED   -2
 
#define ngcbCPU_HIGH   -3
 
#define ngcbCPU_EXACT   0x1
 
#define ngcbCPU_EXCLUDE   0x2
 
#define ngcbGetAbsTime(t)
 
#define ngcbSEM_FAST   0
 
#define ngcbSEM_CHECKED   1
 
#define ngcbPRI_TS   1
 
#define ngcbPRI_IA   2
 
#define ngcbPRI_RT   3
 
#define ngcbTQ_DEF   0
 
#define ngcbTQ_NC   -1
 
#define ngcbTQ_INF   -2
 
#define ngcbClockWait(fd, waitTime)
 
#define ngcbPROC_MAX_SET   8
 
#define ngcbPROC_MAX_PROC   1024
 
#define ngcbProcId(x)
 
#define ngcbProcNum(x)
 

Typedefs

typedef pthread_t ngcb_thread_t
 
typedef struct timespec ngcb_abstime_t
 

Functions

int ngcbSetPrio (int priority, int schedClass, int quantum)
 
int ngcbGetPrio (int *priority, int *schedClass, int *quantum)
 
void ngcbClockInit (void)
 
void ngcbClockGet (ngcb_time_hr *t)
 
void ngcbClockGetAbs (ngcb_time_hr *t)
 
double ngcbTimeStamp ()
 
uint64_t ngcbTimeStamp64 ()
 
int _ngcbClockWait (int fd, int waitTime)
 
int ngcbThrCreate (void *(*startFunc)(void *), void *arg, size_t stack, ngcb_thread_t *thread)
 
void ngcbThrExit (void *status)
 
int ngcbThrCancel (ngcb_thread_t thread)
 
int ngcbThrKill (ngcb_thread_t thread, int sig)
 
int ngcbThrJoin (ngcb_thread_t thread)
 
ngcb_thread_t ngcbThrId (void)
 
int ngcbThrEqual (ngcb_thread_t t1, ngcb_thread_t t2)
 
int ngcbCpuNumCores (void)
 
int ngcbCpuRT (void)
 
int ngcbCpu2Thread (ngcb_thread_t thread, int cpu, int flag)
 
int ngcbCpuAssign (int cpu, int flag)
 
void ngcbCpuShow (const char *name)
 
int ngcbCpuDisableLatencyStates (char *erms)
 
void ngcbCpuResetLatencyStates (int fd)
 
int ngcbSemInit (ngcb_sema_t *sp, unsigned int count, int type, void *arg)
 
int ngcbSemDestroy (ngcb_sema_t *sp)
 
int ngcbSemLock (ngcb_sema_t *sp)
 
int ngcbSemUnlock (ngcb_sema_t *sp)
 
int ngcbSemTryLock (ngcb_sema_t *sp)
 
int ngcbSemPost (ngcb_sema_t *sp)
 
int ngcbSemSet (ngcb_sema_t *sp, unsigned int cnt)
 
int ngcbSemWait (ngcb_sema_t *sp)
 
size_t ngcbSemWaitCnt (ngcb_sema_t *sp, size_t cnt)
 
int ngcbSemWaitAbsTime (ngcb_sema_t *sp, ngcb_abstime_t *absTime)
 
int ngcbSemTryWait (ngcb_sema_t *sp)
 
size_t ngcbSemCnt (ngcb_sema_t *sp)
 
int ngcbRwLockInit (ngcb_lock_t *rwlp, int type, void *arg)
 
int ngcbRwLockDestroy (ngcb_lock_t *rwlp)
 
int ngcbRwRdLock (ngcb_lock_t *rwlp)
 
int ngcbRwTryRdLock (ngcb_lock_t *rwlp)
 
int ngcbRwWrLock (ngcb_lock_t *rwlp)
 
int ngcbRwTryWrLock (ngcb_lock_t *rwlp)
 
int ngcbRwUnlock (ngcb_lock_t *rwlp)
 
int ngcbProcCreate (void(*calcProcess)(void *), int n, char *erms)
 
int ngcbProcCreate2 (void(*calcProcess)(void *), int n, size_t stack, char *erms)
 
int ngcbProcWaitStart (int procId)
 
int ngcbProcWaitTrigger (int procId)
 
int ngcbProcAck (int procId)
 
int ngcbProcStart (int setId)
 
int ngcbProcTrigger (int setId)
 
int ngcbProcWaitAck (int setId)
 
int ngcbProcSync (int procId)
 
void ngcbProcJoin (int setId)
 
void ngcbProcFree (int setId)
 

Variables

int ngcbPrio
 
int ngcbCpuProfile
 

Detailed Description

Macro Definition Documentation

◆ _REENTRANT

#define _REENTRANT

◆ NGC_CCV

#define NGC_CCV   11

CC version

◆ ngcbClockWait

#define ngcbClockWait ( fd,
waitTime )
Value:
ngcbMicroSleep(fd, waitTime)
int ngcbMicroSleep(int fd, int waitTime)
Definition ngcbTime.c:291

High precision microsleep macro.

◆ ngcbCPU_ANY

#define ngcbCPU_ANY   -1

any CPU

◆ ngcbCPU_EXACT

#define ngcbCPU_EXACT   0x1

exact this CPU

◆ ngcbCPU_EXCLUDE

#define ngcbCPU_EXCLUDE   0x2

exclude this CPU

◆ ngcbCPU_HIGH

#define ngcbCPU_HIGH   -3

high-priority CPUs

◆ ngcbCPU_PROFILE_DMA

#define ngcbCPU_PROFILE_DMA   1

DMA interrupts

◆ ngcbCPU_PROFILE_UDP

#define ngcbCPU_PROFILE_UDP   2

UDP RT-polling

◆ ngcbCPU_SHARED

#define ngcbCPU_SHARED   -2

shared CPUs

◆ ngcbGetAbsTime

#define ngcbGetAbsTime ( t)
Value:
clock_gettime(CLOCK_REALTIME, t)

Read the real-time clock (absulute time since UNIX epoch)

◆ ngcbPRI_IA

#define ngcbPRI_IA   2

inter-active class id

◆ ngcbPRI_RT

#define ngcbPRI_RT   3

real-time class id

◆ ngcbPRI_TS

#define ngcbPRI_TS   1

time-sharing class id

◆ ngcbPROC_MAX_PROC

#define ngcbPROC_MAX_PROC   1024

Maximum number of processes per set

◆ ngcbPROC_MAX_SET

#define ngcbPROC_MAX_SET   8

Maximum number of processing sets

◆ ngcbProcId

#define ngcbProcId ( x)
Value:
(int)((unsigned long)x & 0xffffffff)

Get process id from argument.

◆ ngcbProcNum

#define ngcbProcNum ( x)
Value:
(int)(x & 0x0000ffff)

Get process number from id.

◆ ngcbSEM_CHECKED

#define ngcbSEM_CHECKED   1

Semaphore with error-checking

◆ ngcbSEM_FAST

#define ngcbSEM_FAST   0

Fast semaphore

◆ ngcbTQ_DEF

#define ngcbTQ_DEF   0

default time quantum

◆ ngcbTQ_INF

#define ngcbTQ_INF   -2

infinite time quantum

◆ ngcbTQ_NC

#define ngcbTQ_NC   -1

don't change time quantum

Typedef Documentation

◆ ngcb_abstime_t

typedef struct timespec ngcb_abstime_t

Absolute time

◆ ngcb_thread_t

typedef pthread_t ngcb_thread_t

Thread type

Function Documentation

◆ _ngcbClockWait()

int _ngcbClockWait ( int fd,
int waitTime )

Suspend process execution for waitTime microseconds. The sleep can be interrupted by writing to the file descriptor fd which will be closed in that case. If fd has a negative value then the sleep cannot be interrupted.

◆ ngcbClockGet()

void ngcbClockGet ( ngcb_time_hr * t)

Read a high resolution timestamp from the most stable available clock. To be used to measure time differences.

◆ ngcbClockGetAbs()

void ngcbClockGetAbs ( ngcb_time_hr * t)

Read a high resolution absolute timestamp representing the seconds since UNIX epoch. The functuion uses the most precise available clock.

◆ ngcbClockInit()

void ngcbClockInit ( void )

Select and initialize the high resolution clock.

◆ ngcbCpu2Thread()

int ngcbCpu2Thread ( ngcb_thread_t thread,
int cpu,
int flag )

Assign CPUs to a thread.

◆ ngcbCpuAssign()

int ngcbCpuAssign ( int cpu,
int flag )

Assign CPUs to the current process.

◆ ngcbCpuDisableLatencyStates()

int ngcbCpuDisableLatencyStates ( char * erms)

Disable CPU DMA latency states

◆ ngcbCpuNumCores()

int ngcbCpuNumCores ( void )

Return the number of available CPU cores.

◆ ngcbCpuResetLatencyStates()

void ngcbCpuResetLatencyStates ( int fd)

Reset CPU DMA latency states to default value

◆ ngcbCpuRT()

int ngcbCpuRT ( void )

Return the lowest number of the RT-service CPUs.

◆ ngcbCpuShow()

void ngcbCpuShow ( const char * name)

Print out CPU assignment (debugging function).

◆ ngcbGetPrio()

int ngcbGetPrio ( int * priority,
int * schedClass,
int * quantum )

Get the process scheduling priority,

◆ ngcbProcAck()

int ngcbProcAck ( int procId)

Acknowledge that the process is ready to get the next data.

◆ ngcbProcCreate()

int ngcbProcCreate ( void(* calcProcess )(void *),
int n,
char * erms )

Create a set of n user defined calculation threads with default stack size (1M) using the ngcbProc... routines to synchronize.

◆ ngcbProcCreate2()

int ngcbProcCreate2 ( void(* calcProcess )(void *),
int n,
size_t stack,
char * erms )

Create a set of n user defined calculation threads using the ngcbProc... routines to synchronize. The stack size is given in bytes. When the stack size is set to zero then the system default value (1M) is used.

◆ ngcbProcFree()

void ngcbProcFree ( int setId)

Free all thread-resources in set.

◆ ngcbProcJoin()

void ngcbProcJoin ( int setId)

Join all threads in set.

◆ ngcbProcStart()

int ngcbProcStart ( int setId)

Perform synchronous start of a set of threads.

◆ ngcbProcSync()

int ngcbProcSync ( int procId)

Synchronize a set of threads created with ngcbProcCreate() from inside the threads.

◆ ngcbProcTrigger()

int ngcbProcTrigger ( int setId)

Send trigger to a set of threads.

◆ ngcbProcWaitAck()

int ngcbProcWaitAck ( int setId)

Wait for acknowledge from a set threads.

◆ ngcbProcWaitStart()

int ngcbProcWaitStart ( int procId)

Wait for start signal from main process.

◆ ngcbProcWaitTrigger()

int ngcbProcWaitTrigger ( int procId)

Wait for next trigger from main process.

◆ ngcbRwLockDestroy()

int ngcbRwLockDestroy ( ngcb_lock_t * rwlp)

Destroy a readers/writer lock pointed to by rwlp.

◆ ngcbRwLockInit()

int ngcbRwLockInit ( ngcb_lock_t * rwlp,
int type,
void * arg )

Initialize a new readers/writer lock.

◆ ngcbRwRdLock()

int ngcbRwRdLock ( ngcb_lock_t * rwlp)

Get a read lock on the readers/writer lock pointed to by rwlp. If the readers/writer lock is currently locked for writing, the calling thread blocks until the write lock is freed. Multiple threads may simultaneously hold a read lock on a readers/writer lock.

◆ ngcbRwTryRdLock()

int ngcbRwTryRdLock ( ngcb_lock_t * rwlp)

Try to get a read lock on the readers/writer lock pointed to by rwlp. If the readers/writer lock is locked for writing, it returns (-1). Otherwise, the read lock is acquired.

◆ ngcbRwTryWrLock()

int ngcbRwTryWrLock ( ngcb_lock_t * rwlp)

Try to get a write lock on the readers/writer lock pointed to by rwlp. If the readers/writer lock is currently locked for reading or writing, it returns (-1).

◆ ngcbRwUnlock()

int ngcbRwUnlock ( ngcb_lock_t * rwlp)

Unlock a readers/writer lock pointed to by rwlp. If the readers/writer lock is currently locked for writing, the write-lock is released and all suspended readers or writers are unlocked. If the readers/writer lock is currently locked for reading then the number of readers is decremented. When the number of readers becomes zero the read-lock is released and one of the other threads that is waiting for the readers/writer lock will be unblocked.

◆ ngcbRwWrLock()

int ngcbRwWrLock ( ngcb_lock_t * rwlp)

Get a write lock on the readers/writer lock pointed to by rwlp. If the readers/writer lock is currently locked for reading or writing, the calling thread blocks until all the read/write locks are freed. At any given time, only one thread may have a write lock on a readers/writer lock.

◆ ngcbSemCnt()

size_t ngcbSemCnt ( ngcb_sema_t * sp)

Return the current counter value of the specified semaphore.

◆ ngcbSemDestroy()

int ngcbSemDestroy ( ngcb_sema_t * sp)

Destroy the specified semphore.

◆ ngcbSemInit()

int ngcbSemInit ( ngcb_sema_t * sp,
unsigned int count,
int type,
void * arg )

Create a new counting semaphore. The count specifies the initial semaphore counter value. Depending on the value of type either a fast (ngcbSEM_FAST) or a checked (ngcbSEM_CHECKED) semaphore will be created.

◆ ngcbSemLock()

int ngcbSemLock ( ngcb_sema_t * sp)

Acquire the fast lock associated with the semaphore. The function will block until the lock is available or an error occured (if error checking is requested).

◆ ngcbSemPost()

int ngcbSemPost ( ngcb_sema_t * sp)

Increment the semaphore counter for the specified semaphore.

◆ ngcbSemSet()

int ngcbSemSet ( ngcb_sema_t * sp,
unsigned int cnt )

Set the semaphore counter for the specified semaphore.

◆ ngcbSemTryLock()

int ngcbSemTryLock ( ngcb_sema_t * sp)

Try to get the fast lock associated with the semaphore. If the lock is not available, the function returns (-1). Otherwise the lock is acquired and zero is returned.

◆ ngcbSemTryWait()

int ngcbSemTryWait ( ngcb_sema_t * sp)

Decrement the semphore counter for the specified semaphore. If the counter was zero, the function returns (-1).

◆ ngcbSemUnlock()

int ngcbSemUnlock ( ngcb_sema_t * sp)

Release the fast lock associated with the semaphore.

◆ ngcbSemWait()

int ngcbSemWait ( ngcb_sema_t * sp)

Decrements the semphore counter for the specified semaphore. If the counter was zero, the calling process is suspended until the semaphore is posted.

◆ ngcbSemWaitAbsTime()

int ngcbSemWaitAbsTime ( ngcb_sema_t * sp,
ngcb_abstime_t * absTime )

Decrement the semphore counter for the specified semaphore. If the counter was zero, the calling process is suspended until either the semphore is posted or the given absolute time has been reached. When the semaphore counter is still zero the function returns (-1).

◆ ngcbSemWaitCnt()

size_t ngcbSemWaitCnt ( ngcb_sema_t * sp,
size_t cnt )

Suspend the calling process until the semaphore counter value is equal to or greater than cnt. The function returns the actual semaphore counter value.

◆ ngcbSetPrio()

int ngcbSetPrio ( int priority,
int schedClass,
int quantum )

Set the process scheduling priority,

◆ ngcbThrCancel()

int ngcbThrCancel ( ngcb_thread_t thread)

Cancel a thread defined by its thread-id.

◆ ngcbThrCreate()

int ngcbThrCreate ( void *(* startFunc )(void *),
void * arg,
size_t stack,
ngcb_thread_t * thread )

Create a new thread. The stack size is given in bytes. When the stack size is set to zero then the system default value (4M) is used.

◆ ngcbThrEqual()

int ngcbThrEqual ( ngcb_thread_t t1,
ngcb_thread_t t2 )

Test the equality of the two threads t1 and t2. The function returns non-zero if t1 and t2 refer to the same thread, otherwise zero.

◆ ngcbThrExit()

void ngcbThrExit ( void * status)

Function to be be called when exitig from a thread.

◆ ngcbThrId()

ngcb_thread_t ngcbThrId ( void )

Return the thread-id of the calling process.

◆ ngcbThrJoin()

int ngcbThrJoin ( ngcb_thread_t thread)

Waits until the thread given by its thread-id exits.

◆ ngcbThrKill()

int ngcbThrKill ( ngcb_thread_t thread,
int sig )

Send a signal to a thread defined by its thread-id.

◆ ngcbTimeStamp()

double ngcbTimeStamp ( )

Read a high-resolution timestamp and return a double precision floating point value representing the seconds since UNIX epoch.

◆ ngcbTimeStamp64()

uint64_t ngcbTimeStamp64 ( )

Read a high-resolution timestamp and return a double precision floating point value representing the seconds since UNIX epoch. The value is stored in 64-bit data field.

Variable Documentation

◆ ngcbCpuProfile

int ngcbCpuProfile
extern

CPU profile

◆ ngcbPrio

int ngcbPrio
extern

Global flag to apply priority setting