RTAI API 5.1
Loading...
Searching...
No Matches
api.c File Reference

Common scheduling function. More...

Functions

int rt_get_prio (RT_TASK *task)
  More...
 
int rt_get_inher_prio (RT_TASK *task)
  More...
 
RTAI_SYSCALL_MODE int rt_get_priorities (RT_TASK *task, int *priority, int *base_priority)
  More...
 
RTAI_SYSCALL_MODE int rt_task_get_info (RT_TASK *task, RT_TASK_INFO *task_info)
  More...
 
RTAI_SYSCALL_MODE int rt_change_prio (RT_TASK *task, int priority)
  More...
 
RT_TASK * rt_whoami (void)
  More...
 
void rt_task_yield (void)
 Yield the current task. More...
 
RTAI_SYSCALL_MODE int rt_task_suspend (RT_TASK *task)
 rt_task_suspend suspends execution of the task task. More...
 
RTAI_SYSCALL_MODE int rt_task_resume (RT_TASK *task)
 Resume a task. More...
 
int rt_get_task_state (RT_TASK *task)
 Query task state More...
 
void rt_linux_use_fpu (int use_fpu_flag)
  More...
 
RTAI_SYSCALL_MODE int rt_task_use_fpu (RT_TASK *task, int use_fpu_flag)
  More...
 
RTAI_SYSCALL_MODE int rt_task_signal_handler (RT_TASK *task, void(*handler)(void))
  More...
 
RTAI_SYSCALL_MODE int rt_task_make_periodic_relative_ns (RT_TASK *task, RTIME start_delay, RTIME period)
 Make a task run periodically. More...
 
RTAI_SYSCALL_MODE int rt_task_make_periodic (RT_TASK *task, RTIME start_time, RTIME period)
 Make a task run periodically More...
 
int rt_task_wait_period (void)
 Wait till next period. More...
 
RTIME next_period (void)
  More...
 
RTAI_SYSCALL_MODE void rt_busy_sleep (int ns)
  More...
 
RTAI_SYSCALL_MODE int rt_sleep (RTIME delay)
  More...
 
RTAI_SYSCALL_MODE int rt_sleep_until (RTIME time)
  More...
 
int rt_register (unsigned long name, void *adr, int type, struct task_struct *t)
 Register an object. More...
 
int rt_drg_on_name (unsigned long name)
 Deregister an object by its name. More...
 
int rt_drg_on_adr (void *adr)
 Deregister an object by its address. More...
 

Detailed Description

Common scheduling function.

Author
Paolo Mantegazza

This file is part of the RTAI project.

Note
Copyright © 1999-2017 Paolo Mantegazza mante.nosp@m.gazz.nosp@m.a@aer.nosp@m.o.po.nosp@m.limi..nosp@m.it

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Function Documentation

◆ next_period()

RTIME next_period ( void  )

Get the time a periodic task will be resumed after calling rt_task_wait_period.

this function returns the time when the caller task will run next. Combined with the appropriate rt_get_time function() it can be used for checking the fraction of period used or any period overrun.

Returns
Next period time in internal count units.

◆ rt_busy_sleep()

RTAI_SYSCALL_MODE void rt_busy_sleep ( int  ns)

Delay/suspend execution for a while.

rt_busy_sleep delays the execution of the caller task without giving back the control to the scheduler. This function burns away CPU cycles in a busy wait loop so it should be used only for very short synchronization delays. On machine not having a TSC clock it can lead to many microseconds uncertain busy sleeps because of the need of reading the 8254 timer.

Parameters
nsis the number of nanoseconds to wait.

See also: rt_sleep(), rt_sleep_until().

Note
A higher priority task or interrupt handler can run before the task goes to sleep, so the actual time spent in these functions may be longer than that specified.

◆ rt_change_prio()

RTAI_SYSCALL_MODE int rt_change_prio ( RT_TASK *  task,
int  priority 
)

Change a task priority.

rt_change_prio changes the base priority of task task to prio.

Recall that a task has a base native priority, assigned at its birth or by rt_change_prio(), and an actual, inherited, priority. They can be different because of priority inheritance.

Parameters
taskis the affected task.
priorityis the new priority, it can range within 0 < prio < RT_SCHED_LOWEST_PRIORITY.
Returns
rt_change_prio returns the base priority task task had before the change.

◆ rt_get_inher_prio()

int rt_get_inher_prio ( RT_TASK *  task)

Check a task priority.

rt_get_prio returns the base priority task task has inherited from other tasks, either blocked on resources owned by or waiting to pass a message to task task.

Recall that a task has a base native priority, assigned at its birth or by rt_change_prio(), and an actual, inherited, priority. They can be different because of priority inheritance.

Parameters
taskis the affected task.
Returns
rt_get_inher_prio returns the priority of task task.

◆ rt_get_prio()

int rt_get_prio ( RT_TASK *  task)

Check a task priority.

rt_get_prio returns the base priority of task task.

Recall that a task has a base native priority, assigned at its birth or by rt_change_prio(), and an actual, inherited, priority. They can be different because of priority inheritance.

Parameters
taskis the affected task.
Returns
rt_get_prio returns the priority of task task.

◆ rt_get_priorities()

RTAI_SYSCALL_MODE int rt_get_priorities ( RT_TASK *  task,
int *  priority,
int *  base_priority 
)

Check inheredited and base priority.

rt_get_priorities returns the base and inherited priorities of a task.

Recall that a task has a base native priority, assigned at its birth or by rt_change_prio(), and an actual, inherited, priority. They can be different because of priority inheritance.

Parameters
taskis the affected task.
prioritythe actual, e.e. inherited priority.
base_prioritythe base priority.
Returns
rt_get_priority returns 0 if non NULL priority addresses are given, EINVAL if addresses are NULL or task is not a valid object.

◆ rt_get_task_state()

int rt_get_task_state ( RT_TASK *  task)

Query task state

rt_get_task_state returns the state of a real time task.

Parameters
taskis a pointer to the task structure.

Task state is formed by the bitwise OR of one or more of the following flags:

Return values
READYTask task is ready to run (i.e. unblocked). Note that on a UniProcessor machine the currently running task is just in READY state, while on MultiProcessors can be (READY | RUNNING), see below.
SUSPENDEDTask task blocked waiting for a resume.
DELAYEDTask task blocked waiting for its next running period or expiration of a timeout.
SEMAPHORETask task blocked on a semaphore, waiting for the semaphore to be signaled.
SENDTask task blocked on sending a message, receiver was not in RECEIVE state.
RECEIVETask task blocked waiting for incoming messages, sends or rpcs.
RPCTask task blocked on a Remote Procedure Call, receiver was not in RECEIVE state.
RETURNTask task blocked waiting for a return from a Remote Procedure Call, receiver got the RPC but has not replied yet.
RUNNINGTask task is running, used only for SMP schedulers.

The returned task state is just an approximate information. Timer and other hardware interrupts may cause a change in the state of the queried task before the caller could evaluate the returned value. Caller should disable interrupts if it wants reliable info about an other task. rt_get_task_state does not perform any check on pointer task.

◆ rt_linux_use_fpu()

void rt_linux_use_fpu ( int  use_fpu_flag)

Set indication of FPU usage.

rt_linux_use_fpu informs the scheduler that floating point arithmetic operations will be used also by foreground Linux processes, i.e. the Linux kernel itself (unlikely) and any of its processes.

Parameters
use_fpu_flagIf this parameter has a nonzero value, the Floating Point Unit (FPU) context is also switched when task or the kernel becomes active. This makes task switching slower, negligibly, on all 32 bits CPUs but 386s and the oldest 486s. This flag can be set also by rt_task_init when the real time task is created. With UP and MUP schedulers care is taken to avoid useless saves/ restores of the FPU environment. Under SMP tasks can be moved from CPU to CPU so saves/restores for tasks using the FPU are always carried out. Note that by default Linux has this flag cleared. Beside by using rt_linux_use_fpu you can change the Linux FPU flag when you insmod any RTAI scheduler module by setting the LinuxFpu command line parameter of the rtai_sched module itself.
Returns
0 on success. A negative value on failure as described below:
  • EINVAL: task does not refer to a valid task.

See also: rt_linux_use_fpu().

◆ rt_sleep()

RTAI_SYSCALL_MODE int rt_sleep ( RTIME  delay)

Delay/suspend execution for a while.

rt_sleep suspends execution of the caller task for a time of delay internal count units. During this time the CPU is used by other tasks.

Parameters
delayCorresponds to the time the task is going to be suspended.

See also: rt_busy_sleep(), rt_sleep_until().

Returns
0 if the delay expires as expected. An abnormal termination returns as described below:
  • RTE_UNBLKD: the task was unblocked while sleeping;
  • RTE_TMROVRN: an immediate return was taken because the delay is too short to be honoured.
Note
A higher priority task or interrupt handler can run before the task goes to sleep, so the actual time spent in these functions may be longer than the the one specified.

◆ rt_sleep_until()

RTAI_SYSCALL_MODE int rt_sleep_until ( RTIME  time)

Delay/suspend execution for a while.

rt_sleep_until is similar to rt_sleep() but the parameter time is the absolute time till the task have to be suspended. If the given time is already passed this call has no effect.

Parameters
timeAbsolute time till the task have to be suspended

See also: rt_busy_sleep(), rt_sleep_until().

Returns
0 if the sleeping expires as expected. An abnormal termination returns as described below:
  • RTE_UNBLKD: the task was unblocked while sleeping;
  • RTE_TMROVRN: an immediate return was taken because the time deadline has already expired.
Note
A higher priority task or interrupt handler can run before the task goes to sleep, so the actual time spent in these functions may be longer than the the one specified.

◆ rt_task_get_info()

RTAI_SYSCALL_MODE int rt_task_get_info ( RT_TASK *  task,
RT_TASK_INFO *  task_info 
)

Get task task data listed in RT_TASK_INFO type.

rt_task_get_info returns task data listed in RT_TASK_INFO type.

Parameters
taskis the task of interest, NULL can be used for the current task.
task_infoa pointer to RT_TASK_INFO.
Returns
-EINVAL if task is not valid or task_info is NULL, 0 if OK.

◆ rt_task_make_periodic()

RTAI_SYSCALL_MODE int rt_task_make_periodic ( RT_TASK *  task,
RTIME  start_time,
RTIME  period 
)

Make a task run periodically

rt_task_make_periodic mark the task task, previously created with rt_task_init(), as suitable for a periodic execution, with period period, when rt_task_wait_period() is called.

The time of first execution is defined through start_time or start_delay. start_time is an absolute value measured in clock ticks. start_delay is relative to the current time and measured in nanoseconds.

Parameters
taskis a pointer to the task you want to make periodic.
start_timeis the absolute time to wait before the task start running, in clock ticks.
periodcorresponds to the period of the task, in clock ticks.
Return values
0on success. A negative value on failure as described below:
  • EINVAL: task does not refer to a valid task.

See also: rt_task_make_periodic_relative_ns(). Recall that the term clock ticks depends on the mode in which the hard timer runs. So, since only oneshot is used, a clock tick will last as the inverse of the running frequency of the hard timer in use, irrespective of any period used in the call to start_rt_timer.

◆ rt_task_make_periodic_relative_ns()

RTAI_SYSCALL_MODE int rt_task_make_periodic_relative_ns ( RT_TASK *  task,
RTIME  start_delay,
RTIME  period 
)

Make a task run periodically.

rt_task_make_periodic_relative_ns mark the task task, previously created with rt_task_init(), as suitable for a periodic execution, with period period, when rt_task_wait_period() is called.

The time of first execution is defined through start_time or start_delay. start_time is an absolute value measured in clock ticks. start_delay is relative to the current time and measured in nanoseconds.

Parameters
taskis a pointer to the task you want to make periodic.
start_delayis the time, to wait before the task start running, in nanoseconds.
periodcorresponds to the period of the task, in nanoseconds.
Return values
0on success. A negative value on failure as described below:
  • EINVAL: task does not refer to a valid task.

Recall that the term clock ticks depends on the mode in which the hard timer runs. So, since only oneshot is used, a clock tick will last as the inverse of the running frequency of the hard timer in use, irrespective of any period used in the call to start_rt_timer.

◆ rt_task_resume()

RTAI_SYSCALL_MODE int rt_task_resume ( RT_TASK *  task)

Resume a task.

rt_task_resume resumes execution of the task task previously suspended by rt_task_suspend(), or makes a newly created task ready to run, if it makes the task ready. Since no account is made for multiple suspend rt_task_resume unconditionally resumes any task it makes ready.

Parameters
taskpointer to a task structure.
Returns
0 on success. A negative value on failure as described below:
  • EINVAL: task does not refer to a valid task.

◆ rt_task_signal_handler()

RTAI_SYSCALL_MODE int rt_task_signal_handler ( RT_TASK *  task,
void(*)(void)  handler 
)

Set the signal handler of a task.

rt_task_signal_handler installs, or changes, the signal function of a real time task.

Parameters
taskis a pointer to the real time task.
handleris the entry point of the signal function.

A signal handler function can be set also when the task is newly created with rt_task_init(). The signal handler is a function called within the task environment and with interrupts disabled, when the task becomes the current running task after a context switch, except at its very first scheduling. It allows you to implement whatever signal management policy you think useful, and many other things as well (FIXME).

Returns
0 on success.A negative value on failure as described below:
  • EINVAL: task does not refer to a valid task.

◆ rt_task_suspend()

RTAI_SYSCALL_MODE int rt_task_suspend ( RT_TASK *  task)

rt_task_suspend suspends execution of the task task.

It will not be executed until a call to rt_task_resume() or rt_task_make_periodic() is made. Multiple suspends and require as many rt_task_resume() as the rt_task_suspends placed on a task.

Parameters
taskpointer to a task structure.
Returns
the task suspend depth. An abnormal termination returns as described below:
  • -EINVAL: task does not refer to a valid task.
  • RTE_UNBLKD: the task was unblocked while suspended;

◆ rt_task_use_fpu()

RTAI_SYSCALL_MODE int rt_task_use_fpu ( RT_TASK *  task,
int  use_fpu_flag 
)

rt_task_use_fpu informs the scheduler that floating point arithmetic operations will be used by the real time task task.

Parameters
taskis a pointer to the real time task.
use_fpu_flagIf this parameter has a nonzero value, the Floating Point Unit (FPU) context is also switched when task or the kernel becomes active. This makes task switching slower, negligibly, on all 32 bits CPUs but 386s and the oldest 486s. This flag can be set also by rt_task_init() when the real time task is created. With UP and MUP schedulers care is taken to avoid useless saves/restores of the FPU environment. Under SMP tasks can be moved from CPU to CPU so saves/restores for tasks using the FPU are always carried out.
Returns
0 on success. A negative value on failure as described below:
  • EINVAL: task does not refer to a valid task.

See also: rt_linux_use_fpu().

◆ rt_task_wait_period()

int rt_task_wait_period ( void  )

Wait till next period.

rt_task_wait_period suspends the execution of the currently running real time task until the next period is reached. The task must have been previously marked for a periodic execution by calling rt_task_make_periodic() or rt_task_make_periodic_relative_ns().

Returns
0 if the period expires as expected. An abnormal termination returns as described below:
  • RTE_UNBLKD: the task was unblocked while sleeping;
  • RTE_TMROVRN: an immediate return was taken because the next period has already expired.
Note
The task is suspended only temporarily, i.e. it simply gives up control until the next time period.

◆ rt_task_yield()

void rt_task_yield ( void  )

Yield the current task.

rt_task_yield() stops the current task and takes it at the end of the list of ready tasks having its same priority. The scheduler makes the next ready task of the same priority active. If the current task has the highest priority no more then it results in an immediate rescheduling.

Recall that RTAI schedulers allow only higher priority tasks to preempt the execution of lower priority ones. So equal priority tasks cannot preempt each other and rt_task_yield() should be used if a user needs a cooperative time slicing among equal priority tasks. The implementation of the related policy is wholly in the hand of the user. It is believed that time slicing is too much an overhead for the most demanding real time applications, so it is left up to you.

◆ rt_whoami()

RT_TASK * rt_whoami ( void  )

Get the task pointer of the current task.

Calling rt_whoami from a task can get a pointer to its own task structure.

Returns
The pointer to the current task.