Tizen RT Libs&Environment  v1.0 D5

Provides APIs for Scheduling. More...

Collaboration diagram for SCHED:

Data Structures

struct  sched_param
 POSIX-like scheduling parameter structure. More...
 

Macros

#define PR_SET_NAME   1
 
#define PR_GET_NAME   2
 

Enumerations

Functions

int task_create (FAR const char *name, int priority, int stack_size, main_t entry, FAR char *const argv[])
 creates and activates a new task with a specified priority and returns its system-assigned ID. More...
 
int task_delete (pid_t pid)
 causes a specified task to cease to exist. More...
 
int task_restart (pid_t pid)
 restart a task. More...
 
int sched_setparam (pid_t pid, const struct sched_param *param)
 POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/) More...
 
int sched_getparam (pid_t pid, struct sched_param *param)
 POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/) More...
 
int sched_setscheduler (pid_t pid, int policy, FAR const struct sched_param *param)
 POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/) More...
 
int sched_getscheduler (pid_t pid)
 POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/) More...
 
int sched_yield (void)
 POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/) More...
 
int sched_get_priority_max (int policy)
 POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/) More...
 
int sched_get_priority_min (int policy)
 POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/) More...
 
int sched_rr_get_interval (pid_t pid, FAR struct timespec *interval)
 POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/) More...
 
int sched_lock (void)
 disable context switching More...
 
int sched_unlock (void)
 re-enable the context switching which blocked from sched_lock() More...
 
int sched_lockcount (void)
 returns the current value of the lockcount More...
 
int prctl (int option,...)
 called with a first argument describing what to do (with values PR_* defined above) and with additional arguments depending on the specific command. More...
 
EXTERN pid_t wait (FAR int *stat_loc)
 suspend execution of the calling thread More...
 
EXTERN int waitid (idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
 suspend execution of the calling thread More...
 
EXTERN pid_t waitpid (pid_t pid, FAR int *stat_loc, int options)
 suspend execution of the calling thread More...
 
FAR struct tcb_ssched_self (void)
 returns the TCB of the currently running task (i.e., the caller) More...
 
void sched_foreach (sched_foreach_t handler, FAR void *arg)
 enumerate over each task and provide the TCB of each task or thread to a callback function. Interrupts will be disabled throughout this enumeration! More...
 
FAR struct tcb_ssched_gettcb (pid_t pid)
 Give a task ID, look up the corresponding TCB. More...
 
#define SCHED_FIFO   1 /* FIFO per priority scheduling policy */
 
#define SCHED_RR   2 /* Round robin scheduling policy */
 
#define SCHED_SPORADIC   3 /* Not supported */
 
#define SCHED_OTHER   4 /* Not supported */
 
#define PTHREAD_KEYS_MAX   CONFIG_NPTHREAD_KEYS
 

Detailed Description

Provides APIs for Scheduling.

Macro Definition Documentation

#define PR_GET_NAME   2

Definition at line 92 of file prctl.h.

#define PR_SET_NAME   1

Definition at line 88 of file prctl.h.

#define PTHREAD_KEYS_MAX   CONFIG_NPTHREAD_KEYS

Definition at line 93 of file sched.h.

#define SCHED_FIFO   1 /* FIFO per priority scheduling policy */

Definition at line 86 of file sched.h.

#define SCHED_OTHER   4 /* Not supported */

Definition at line 89 of file sched.h.

#define SCHED_RR   2 /* Round robin scheduling policy */

Definition at line 87 of file sched.h.

#define SCHED_SPORADIC   3 /* Not supported */

Definition at line 88 of file sched.h.

Enumeration Type Documentation

enum idtype_e

Enumeration for waitid idtype.

Enumerator
P_PID 
P_GID 
P_ALL 

Definition at line 106 of file wait.h.

Function Documentation

int prctl ( int  option,
  ... 
)

called with a first argument describing what to do (with values PR_* defined above) and with additional arguments depending on the specific command.

param[in] options for what to do return The returned value may depend on the specific commnand. For PR_SET_NAME and PR_GET_NAME, the returned value of 0 indicates successful operation. On any failure, -1 is retruend and the errno value is set appropriately.

EINVAL The value of 'option' is not recognized. EFAULT optional arg1 is not a valid address. ESRCH No task/thread can be found corresponding to that specified by optional arg1.

Since
Tizen RT v1.0
void sched_foreach ( sched_foreach_t  handler,
FAR void *  arg 
)

enumerate over each task and provide the TCB of each task or thread to a callback function. Interrupts will be disabled throughout this enumeration!

Parameters
[in]Thefunction to be called with the TCB of each task
[in]param
Returns
none
Since
Tizen RT v1.0
int sched_get_priority_max ( int  policy)

POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Since
Tizen RT v1.0
int sched_get_priority_min ( int  policy)

POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Since
Tizen RT v1.0
int sched_getparam ( pid_t  pid,
struct sched_param param 
)

POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

[SYSTEM CALL API]

Since
Tizen RT v1.0
int sched_getscheduler ( pid_t  pid)

POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

[SYSTEM CALL API]

Since
Tizen RT v1.0
FAR struct tcb_s* sched_gettcb ( pid_t  pid)

Give a task ID, look up the corresponding TCB.

Given a task ID, this function will return the a pointer to the corresponding TCB (or NULL if there is no such task ID).

Parameters
[in]Pidfor tcb
Returns
TCB structure about pid
Since
Tizen RT v1.0
int sched_lock ( void  )

disable context switching

[SYSTEM CALL API]

Returns
On success, OK is returned. On failure, ERROR is returned.
Since
Tizen RT v1.0
int sched_lockcount ( void  )

returns the current value of the lockcount

[SYSTEM CALL API] This function returns the current value of the lockcount. If zero, pre-emption is enabled; if non-zero, this value indicates the number of times that sched_lock() has been called on this thread of execution. sched_unlock() will have to called that many times from this thread in order to re-enable pre-emption.

Returns
On success, lockcount is returned.
Since
Tizen RT v1.0
int sched_rr_get_interval ( pid_t  pid,
FAR struct timespec interval 
)

POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

[SYSTEM CALL API]

Since
Tizen RT v1.0
FAR struct tcb_s* sched_self ( void  )

returns the TCB of the currently running task (i.e., the caller)

Basically, this function just wraps the head of the ready-to-run list and manages access to the TCB from outside of the sched/ sub-directory.

Returns
TCB structure
Since
Tizen RT v1.0
int sched_setparam ( pid_t  pid,
const struct sched_param param 
)

POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

[SYSTEM CALL API]

Since
Tizen RT v1.0
int sched_setscheduler ( pid_t  pid,
int  policy,
FAR const struct sched_param param 
)

POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

[SYSTEM CALL API]

Since
Tizen RT v1.0
int sched_unlock ( void  )

re-enable the context switching which blocked from sched_lock()

[SYSTEM CALL API] This function decrements the preemption lock count. Typically this is paired with sched_lock() and concludes a critical section of code. Preemption will not be unlocked until sched_unlock() has been called as many times as sched_lock(). When the lockcount is decremented to zero, any tasks that were eligible to preempt the current task will execute.

Returns
On success, OK is returned. On failure, ERROR is returned.
Since
Tizen RT v1.0
int sched_yield ( void  )

POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

[SYSTEM CALL API]

Since
Tizen RT v1.0
int task_create ( FAR const char *  name,
int  priority,
int  stack_size,
main_t  entry,
FAR char *const  argv[] 
)

creates and activates a new task with a specified priority and returns its system-assigned ID.

[SYSTEM CALL API] The entry address entry is the address of the "main" function of the task. This function will be called once the C environment has been set up. The specified function will be called with four arguments. Should the specified routine return, a call to exit() will automatically be made.

Parameters
[in]Nameof the new task
[in]Priorityof the new task
[in]size(in bytes) of the stack needed
[in]Entrypoint of a new task
[in]Apointer to an array of input parameters. Up to CONFIG_MAX_TASK_ARG parameters may be provided. If fewer than CONFIG_MAX_TASK_ARG parameters are passed, the list should be terminated with a NULL argv[] value. If no parameters are required, argv may be NULL.
Returns
non-zero process ID of the new task or ERROR if memory is insufficient or the task cannot be created. The errno will be set to indicate the nature of the error (always ENOMEM).
Since
Tizen RT v1.0
int task_delete ( pid_t  pid)

causes a specified task to cease to exist.

[SYSTEM CALL API] Its stack and TCB will be deallocated. This function is the companion to task_create(). This is the version of the function exposed to the user; it is simply a wrapper around the internal, task_terminate function.

The logic in this function only deletes non-running tasks. If the 'pid' parameter refers to to the currently runing task, then processing is redirected to exit(). This can only happen if a task calls task_delete() in order to delete itself.

In fact, this function (and task_terminate) are the final functions called all task termination sequences. task_delete may be called from:

Other exit paths (exit(), _eixt(), and pthread_exit()) will go through task_terminate()

Parameters
[in]Thetask ID of the task to delete. A pid of zero signifies the calling task.
Returns
OK on success; or ERROR on failure
Since
Tizen RT v1.0
int task_restart ( pid_t  pid)

restart a task.

[SYSTEM CALL API] The task is first terminated and then reinitialized with same ID, priority, original entry point, stack size, and parameters it had when it was first started.

This function can fail if: (1) A pid of zero or the pid of the calling task is provided (functionality not implemented) (2) The pid is not associated with any task known to the system.

Parameters
[in]Thetask ID of the task to delete. An ID of zero signifies the calling task.
Returns
OK on success; or ERROR on failure
Since
Tizen RT v1.0
EXTERN pid_t wait ( FAR int *  stat_loc)

suspend execution of the calling thread

[SYSTEM CALL API] suspend execution of the calling thread until status information for one of its terminated child processes is available, or until delivery of a signal whose action is either to execute a signal-catching function or to terminate the process. If more than one thread is suspended in wait() or waitpid() awaiting termination of the same process, exactly one thread will return the process status at the time of the target process termination. If status information is available prior to the call to wait(), return will be immediate.

The waitpid() function will behave identically to wait(), if the pid argument is (pid_t)-1 and the options argument is 0. Otherwise, its behaviour will be modified by the values of the pid and options arguments.

Parameters
[in]Thelocation to return the exit status
Returns
return a value equal to the process ID of the child process for which status is reported.
Since
Tizen RT v1.0
EXTERN int waitid ( idtype_t  idtype,
id_t  id,
FAR siginfo_t info,
int  options 
)

suspend execution of the calling thread

[SYSTEM CALL API] The waitid() function suspends the calling thread until one child of the process containing the calling thread changes state. It records the current state of a child in the structure pointed to by 'info'. If a child process changed state prior to the call to waitid(), waitid() returns immediately. If more than one thread is suspended in wait() or waitpid() waiting termination of the same process, exactly one thread will return the process status at the time of the target process termination

The idtype and id arguments are used to specify which children waitid() will wait for.

If idtype is P_PID, waitid() will wait for the child with a process ID equal to (pid_t)id.

If idtype is P_PGID, waitid() will wait for any child with a process group ID equal to (pid_t)id.

If idtype is P_ALL, waitid() will wait for any children and id is ignored.

The options argument is used to specify which state changes waitid() will will wait for. It is formed by OR-ing together one or more of the following flags:

WEXITED - Wait for processes that have exited. WSTOPPED - Status will be returned for any child that has stopped upon receipt of a signal. WCONTINUED - Status will be returned for any child that was stopped and has been continued. WNOHANG - Return immediately if there are no children to wait for. WNOWAIT - Keep the process whose status is returned in 'info' in a waitable state. This will not affect the state of the process; the process may be waited for again after this call completes.

The 'info' argument must point to a siginfo_t structure. If waitid() returns because a child process was found that satisfied the conditions indicated by the arguments idtype and options, then the structure pointed to by 'info' will be filled in by the system with the status of the process. The si_signo member will always be equal to SIGCHLD.

Parameters
[in]specifywhich children waitid() will wait for
[in]specifywhich children waitid() will wait for
[in]optionto specify which state changes waitid() will wait for
Returns
If waitid() returns due to the change of state of one of its children, 0 is returned. Otherwise, -1 is returned and errno is set to indicate the error.

The waitid() function will fail if:

ECHILD - The calling process has no existing unwaited-for child processes. EINTR - The waitid() function was interrupted by a signal. EINVAL - An invalid value was specified for options, or idtype and id specify an invalid set of processes.

Since
Tizen RT v1.0
EXTERN pid_t waitpid ( pid_t  pid,
FAR int *  stat_loc,
int  options 
)

suspend execution of the calling thread

[SYSTEM CALL API] obtain status information pertaining to one of the caller's child processes. The waitpid() function will suspend execution of the calling thread until status information for one of the terminated child processes of the calling process is available, or until delivery of a signal whose action is either to execute a signal-catching function or to terminate the process. If more than one thread is suspended in waitpid() awaiting termination of the same process, exactly one thread will return the process status at the time of the target process termination. If status information is available prior to the call to waitpid(), return will be immediate.

The pid argument specifies a set of child processes for which status is requested. The waitpid() function will only return the status of a child process from this set:

  • If pid is equal to (pid_t)-1, status is requested for any child process. In this respect, waitpid() is then equivalent to wait().
  • If pid is greater than 0, it specifies the process ID of a single child process for which status is requested.
  • If pid is 0, status is requested for any child process whose process group ID is equal to that of the calling process.
  • If pid is less than (pid_t)-1, status is requested for any child process whose process group ID is equal to the absolute value of pid.

The options argument is constructed from the bitwise-inclusive OR of zero or more of the following flags, defined in the <sys/wait.h> header:

WCONTINUED - The waitpid() function will report the status of any continued child process specified by pid whose status has not been reported since it continued from a job control stop. WNOHANG - The waitpid() function will not suspend execution of the calling thread if status is not immediately available for one of the child processes specified by pid. WUNTRACED - The status of any child processes specified by pid that are stopped, and whose status has not yet been reported since they stopped, will also be reported to the requesting process.

If the calling process has SA_NOCLDWAIT set or has SIGCHLD set to SIG_IGN, and the process has no unwaited-for children that were transformed into zombie processes, the calling thread will block until all of the children of the process containing the calling thread terminate, and waitpid() will fail and set errno to ECHILD.

If waitpid() returns because the status of a child process is available, these functions will return a value equal to the process ID of the child process. In this case, if the value of the argument stat_loc is not a null pointer, information will be stored in the location pointed to by stat_loc. The value stored at the location pointed to by stat_loc will be 0 if and only if the status returned is from a terminated child process that terminated by one of the following means:

  1. The process returned 0 from main().
  2. The process called _exit() or exit() with a status argument of 0.
  3. The process was terminated because the last thread in the process terminated.

Regardless of its value, this information may be interpreted using the following macros, which are defined in <sys/wait.h> and evaluate to integral expressions; the stat_val argument is the integer value pointed to by stat_loc.

WIFEXITED(stat_val) - Evaluates to a non-zero value if status was returned for a child process that terminated normally. WEXITSTATUS(stat_val) - If the value of WIFEXITED(stat_val) is non-zero, this macro evaluates to the low-order 8 bits of the status argument that the child process passed to _exit() or exit(), or the value the child process returned from main(). WIFSIGNALED(stat_val) - Evaluates to a non-zero value if status was returned for a child process that terminated due to the receipt of a signal that was not caught (see <signal.h>). WTERMSIG(stat_val) - If the value of WIFSIGNALED(stat_val) is non-zero, this macro evaluates to the number of the signal that caused the termination of the child process. WIFSTOPPED(stat_val) - Evaluates to a non-zero value if status was returned for a child process that is currently stopped. WSTOPSIG(stat_val) - If the value of WIFSTOPPED(stat_val) is non-zero, this macro evaluates to the number of the signal that caused the child process to stop. WIFCONTINUED(stat_val) - Evaluates to a non-zero value if status was returned for a child process that has continued from a job control stop.

Parameters
[in]Thetask ID of the thread to waid for
[in]Thelocation to return the exit status
[in]ignored
Returns
If waitpid() returns because the status of a child process is available, it will return a value equal to the process ID of the child process for which status is reported.

If waitpid() returns due to the delivery of a signal to the calling process, -1 will be returned and errno set to EINTR.

If waitpid() was invoked with WNOHANG set in options, it has at least one child process specified by pid for which status is not available, and status is not available for any process specified by pid, 0 is returned.

Otherwise, (pid_t)-1 will be returned, and errno set to indicate the error:

ECHILD - The process specified by pid does not exist or is not a child of the calling process, or the process group specified by pid does not exist or does not have any member process that is a child of the calling process. EINTR - The function was interrupted by a signal. The value of the location pointed to by stat_loc is undefined. EINVAL - The options argument is not valid.

Since
Tizen RT v1.0