VXWorks IPC Mechanism Vxworks implements two APIs for

  • Slides: 18
Download presentation
VXWorks IPC Mechanism Ø Vxworks implements two APIs for IPC i) ii) Ø Native

VXWorks IPC Mechanism Ø Vxworks implements two APIs for IPC i) ii) Ø Native wind API POSIX 1003. lb Semaphores: Semaphores are the basis for synchronization and mutual exclusion in Vx. Works. They are powerful in their simplicity and form the foundation for numerous Vx. Works facilities. Semaphores are used to provide the synchronization and mutual exclusion between the tasks, when more than one task is going to access the shared data. By using semaphores we can avoid the deadlocks. We have 3 types of semaphores 1) Binary semaphore 2) Counting semaphore 3) Mutual Exclusion Ø Binary Semaphore: it is fast and most general purpose semaphores. it is for synchronization and mutual exclusion. This library provides the interface to Vx. Works binary semaphores. Binary semaphores are the most versatile, efficient, and conceptually simple type of semaphore.

They can be used to: (1) control mutually exclusive access to shared devices or

They can be used to: (1) control mutually exclusive access to shared devices or data structures, or (2) synchronize multiple tasks, or task-level and interrupt-level processes. we have some system calls like, sem. BCreate( ) - create and initialize a binary semaphore sem. Delete( ) - delete a semaphore sem. Take( ) – It takes a semaphore (if semaphore is available, otherwise it goes into blocking state until semaphore is available. Duration of blocking depends on parameter timeout which can be WAIT_FOREVER, WAIT_NOWAIT or any nonzero value which specifies the timeout). sem. Flush( ) - unblock every task pended on a semaphore sem. Give( ) - give a semaphore Ø Mutual Exclusion: Mutual-exclusion semaphores offer convenient options suited for situations requiring mutually exclusive access to resources.

 Typical applications include sharing devices and protecting data structures. Mutual-exclusion semaphores are used

Typical applications include sharing devices and protecting data structures. Mutual-exclusion semaphores are used by many higher-level Vx. Works facilities. The mutual-exclusion semaphore is a specialized version of the binary semaphore, designed to address issues inherent in mutual exclusion, such as recursive access to resources, priority inversion, and deletion safety. We have some system calls like, sem. MCreate( ) - create and initialize a mutual-exclusion semaphore sem. MGive. Force( ) - give a mutual-exclusion semaphore without restrictions sem. Give( ) - give a semaphore sem. Take( ) - take a semaphore sem. Delete( ) - delete a semaphore - It can only be used for mutual exclusion. - It can only be given by the task that took it. - It may not be taken or given from interrupt level. - The sem. Flush( ) operation is illegal.

we can use SEM_INVERSION_SAFE and SEM_DELETE_SAFE for safety deletion Ø Counting Semaphore: It same

we can use SEM_INVERSION_SAFE and SEM_DELETE_SAFE for safety deletion Ø Counting Semaphore: It same as binary semaphore, but keep track of the number of times a semaphore is given, optimized for guarding multiple instances of a resource. We have some system calls like, sem. CCreate( ) - create and initialize a counting semaphore sem. Give( ) - give a semaphore sem. Take( ) - take a semaphore sem. Flush( ) - unblock every task pended on a semaphore sem. Delete( ) - delete a semaphore

Ø Message Queues: The message queues are used to provide communication between tasks. Message

Ø Message Queues: The message queues are used to provide communication between tasks. Message queues allow a variable number of messages (varying in length) to be queued in first-in-firstout (FIFO) order Any task running on any CPU in the system can send message to or receive message from a message queue. Tasks can also send to and receive from the same message queue. Full duplex communication between two tasks generally requires two message queue, one for each direction. we have some system calls like, msg. QCreate( ) - create and initialize a message queue msg. QDelete( ) - delete a message queue msg. QSend( ) - send a message to a message queue msg. QReceive( ) - receive a message from a message queue msg. QNum. Msgs( ) - get the number of messages queued to a message queue Message Q Task 1 Task 2 Message Q

 Ø Signals: This library provides a signal interface for tasks. Signals are used

Ø Signals: This library provides a signal interface for tasks. Signals are used to alter the flow control of tasks by communicating asynchronous events within or between task contexts. Any task or interrupt service can "raise" (or send) a signal to a particular task. The task being signaled will immediately suspend its current thread of execution and invoke a task-specified "signal handler" routine. The signal handler is a user-supplied routine that is bound to a specific signal and performs whatever actions are necessary whenever the signal is received. Signals are most appropriate for error and exception handling, rather than as a general purpose intertask communication mechanism. The wind kernel support two types of signal interfaces: i) Unix BSD-style signal ii) POSIX compitable signal The signal facility provides a set of 31 distinct signals. A signal can be raised by calling kill(). Signal facility is included in INCLUDE_SIGNALS. we have some signals like,

sig. Init( ) - initialize the signal facilities sigqueue. Init( ) - initialize the

sig. Init( ) - initialize the signal facilities sigqueue. Init( ) - initialize the queued signal facilities sigemptyset( ) - initialize a signal set with no signals included (POSIX) sigfillset( ) - initialize a signal set with all signals included (POSIX) sigaddset( ) - add a signal to a signal set (POSIX) sigdelset( ) - delete a signal from a signal set (POSIX) sigismember( ) - test to see if a signal is in a signal set (POSIX) signal( ) - specify the handler associated with a signal sigaction( ) - examine and/or specify the action associated with a signal (POSIX) sigprocmask( ) - examine and/or change the signal mask (POSIX) sigpending( ) - retrieve the set of pending signals blocked from delivery (POSIX) sigsuspend( ) - suspend the task until delivery of a signal (POSIX) pause( ) - suspend the task until delivery of a signal (POSIX) sigtimedwait( ) - wait for a signal sigwaitinfo( ) - wait for real-time signals sigwait( ) - wait for a signal to be delivered (POSIX) sigvec( ) - install a signal handler sigsetmask( ) - set the signal mask sigblock( ) - add to a set of blocked signals raise( ) - send a signal to the caller's task kill( ) - send a signal to a task (POSIX) sigqueue( ) - send a queued signal to a task

Ø Shared Memory: Vx. MP supports 3 kinds of shared memory objects i) Shared

Ø Shared Memory: Vx. MP supports 3 kinds of shared memory objects i) Shared Memory (Binary and Counting semaphores) ii) Shared Message Queues iii) Shared Memory Partitions( System and User created partitions) Shared memory objects provide high-speed synchronization and communication among tasks running on separate CPUs that have access to a common shared memory. Shared memory objects are system objects (e. g. , semaphores and message queues) that can be used across processors. The main uses of shared memory objects are interprocessor synchronization, mutual exclusion on multiprocessor shared data structures, and high-speed data exchange Shared Memory Provide the following Advantages: 1) High speed interprocessor Communication. 2) The shared memory can reside either in dual-ported RAM or on separate memory board. Task 1 Tasks Memory Access Shared Data Task 2 Access Shared Data Task 3 Access Shared Data Shared. Data

The component of Vx. MP consists of the following: 1) A Name Database( sm.

The component of Vx. MP consists of the following: 1) A Name Database( sm. Name. Lib) 2) Shared Semaphores( sem. Sm. Lib) 3) Shared Message Queue( msg. QSm. Lib) 4) Shared Memory Allocator( sm. Mem. Lib) Ø Name Database: we have some service routines sm. Name. Add( ) - add a name to the shared memory name database (Vx. MP Option) sm. Name. Find( ) - look up a shared memory object by name (Vx. MP Option) sm. Name. Find. By. Value( ) - look up a shared memory object by value (Vx. MP Option) sm. Name. Remove( ) - remove an object from the shared memory objects name database (Vx. MP Option) sm. Name. Show() – Display the name database to the standard output device

 Ø Shared Semaphore: sem. Sm. Lib - shared memory semaphore library (Vx. MP

Ø Shared Semaphore: sem. Sm. Lib - shared memory semaphore library (Vx. MP Option) we have shared semaphore library that is sem. Sm. Lib() we have some routines under the shared semaphore like sem. BSm. Create( ) - create and initialize a shared memory binary semaphore (Vx. MP Option) sem. CSm. Create( ) - create and initialize a shared memory counting semaphore (Vx. MP Option) Shared memory binary semaphores are used to control mutual exclusive access to multiprocessor shared datastructures. Sychronize multiple tasks running in a multiprocessor system. Shared memory counting semaphores are used for guarding multiple instances of a resource used by multiple CPUs. The memory partition is common to binary and counting semaphore. Thus SM_OBJ_MAX_SEM must be set to the sum total of binary and counting semaphores to be used in the system. Shared semaphore may not be given, taken or flushed at interrupt level. There is no way to delete a shared semaphore and free its associated shared memory. Attempts to delete a shared memory return ERROR.

 Shared memory queuing style specified when semaphore is created must be FIFO. The

Shared memory queuing style specified when semaphore is created must be FIFO. The maximum number of shared memory semaphore( Binary + Counting) that can be created is SM_OBJ_MAX_SEM. Ø Shared Binary Semaphore: syntax: SEM_ID sem. BSm. Create(int options, SEM_B_STATE initialstate); This routine allocates and initialize a shared memory binary semaphore. The semaphore is initialized to an either SEM_FULL( available) or SEM_EMPTY (not available). The shared memory structure is allocated from the shared memory dedicated memory partition. The semaphore ID returned by the routine can be used directly by the generic semahore handling routines in sem. Lib( sem. Give(), sem. Take(), sem. Flush(), sem. Show()). The queuing style for blocked tasks is set by options only supported queuing style is FIFO by SEM_Q_FIFO. The maximum number of shared memory semaphore( Binary + Counting) that can be created is SM_OBJ_MAX_SEM.

Ø Shared Counting semaphores: syntax: SEM_ID sem. CSm. Create( int options, int initialcount); This

Ø Shared Counting semaphores: syntax: SEM_ID sem. CSm. Create( int options, int initialcount); This routine allocates and initialize a shared memory counting semaphore. The initial count values of the semaphore is specified by initailcount. The semaphore ID returned by the routine can be used directly by the generic semahore handling routines in sem. Lib( sem. Give(), sem. Take(), sem. Flush(), sem. Show()). The queuing style for blocked tasks is set by options only supported queuing style is FIFO by SEM_Q_FIFO. The maximum number of shared memory semaphore( Binary + Counting) that can be created is SM_OBJ_MAX_SEM. Ø Shared Message Queue: msg. QSm. Lib msg. QSm. Create( ) --Shared memory message queue library. -- create and initialize a shared memory message queue (Vx. MP Option) This library provides the interface to shared memory message queue. Shared memory message queue allow a variable number of messages( varying in length) to be queued in FIFO order.

 Any task running on any CPU in the system can send message to

Any task running on any CPU in the system can send message to or receive message from a shared message queue. Tasks can also send to and receive from the same shared message queue. Full duplex communication between two tasks generally requires tow shared message queue, one for each direction. Shared memory message queues are created with msg. QSmcreate() once created, they can be manipulated using generic routines for local message queues. The size of this partition is defined by the maximum number of shared message queues. SM_OBJ_MAX_MSG_Q. Shared memory message queues may not be used( sent to or receive from) at interrupt level. There is no way to delete a shared memory message queue and free its associated shared memory. Attempts to delete a shared memory message queue return ERROR. The queuing style for messages queue is FIFO. Ø msg. QSm. Create(): syntax: MSG_Q_ID msg. QSm. Create( int maxmsg, int maxmsglength, int options); The queue can only be created with the options MSG_Q_FIFO(0), thus queuing pended tasks in FIFO order.

 The global message queue identifier returned can be used directly by generic message

The global message queue identifier returned can be used directly by generic message queue handling routines in msg. QLib (msg. QSend(), msg. QReceive(), msg. QNum. Msg()). Ø Shared Memory Allocator: sm. Mem. Lib -- shared memory management library (Vx. MP Option) we have some routines under this library mem. Part. Sm. Create( ) - sm. Mem. Add. To. Pool( ) - sm. Mem. Options. Set( ) - sm. Mem. Malloc( ) - sm. Mem. Calloc( ) - sm. Mem. Realloc( ) - sm. Mem. Free( ) - sm. Mem. Find. Max( ) - create a shared memory partition (Vx. MP Option) add memory to shared memory system partition (Vx. MP Option) set debug options for shared memory system partition (Vx. MP Option) allocate block of memory from shared memory system partition (Vx. MP Option) allocate memory for array from shared memory system partition (Vx. MP Option) reallocate block of memory from shared memory system partition (Vx. MP Option) free a shared memory system partition block of memory (Vx. MP Option) find largest free block in shared memory system partition (Vx. MP Option)

Ø Shared Memory Object: sm. Obj. Lib - shared memory objects library (Vx. MP

Ø Shared Memory Object: sm. Obj. Lib - shared memory objects library (Vx. MP Option) This library contains miscellaneous functions used by the shared memory objects facility (Vx. MP). Shared memory objects provide high-speed synchronization and communication among tasks running on separate CPUs that have access to a common shared memory. Shared memory objects are system objects (e. g. , semaphores and message queues) that can be used across processors. The main uses of shared memory objects are interprocessor synchronization, mutual exclusion on multiprocessor shared data structures, and high-speed data exchange. Routines for displaying shared memory objects statistics are provided by the sm. Obj. Show module. we have some routines under this library. sm. Obj. Lib. Init( ) - install the shared memory objects facility (Vx. MP Option) sm. Obj. Setup( ) - initialize the shared memory objects facility (Vx. MP Option) sm. Obj. Init( ) - initialize a shared memory objects descriptor (Vx. MP Option) sm. Obj. Attach( ) - attach the calling CPU to the shared memory objects facility (Vx. MP Option) sm. Obj. Local. To. Global( ) - convert a local address to a global address (Vx. MP Option) sm. Obj. Global. To. Local( ) - convert a global address to a local address (Vx. MP Option) sm. Obj. Timeout. Log. Enable( ) - control logging of failed attempts to take a spin-lock (Vx. MP Option)

Ø Sockets: sock. Lib - generic socket library This library provides UNIX BSD 4.

Ø Sockets: sock. Lib - generic socket library This library provides UNIX BSD 4. 4 compatible socket calls. Use these calls to open, close, read, and write sockets. These sockets can join processes on the same CPU or on different CPUs between which there is a network connection. The calling sequences of these routines are identical to their equivalents under UNIX BSD 4. 4. However, although the socket interface is compatible with Vx. Works, the Vx. Works environment does affect how you use sockets. Specifically, the globally accessible file descriptors available in the single address space world of Vx. Works require that you take extra precautions when closing a file descriptor. You must make sure that you do not close the file descriptor on which a task is pending during an accept( ). Although the accept( ) on the closed file descriptor sometimes returns with an error, the accept( ) can also fail to return at all. Thus, if you need to be able to close a socket connections file descriptor asynchronously, you may need to set up a semaphore-based locking mechanism that prevents the close while an accept( ) is pending on the file descriptor. ADDRESS FAMILY Vx. Works sockets support only the Internet Domain address family. Use AF_INET for the domain argument in subroutines that require it. There is no support for the UNIX Domain address family.

 • Socket Type: we have 3 types of sockets SOCK_STREAM – Specifies a

• Socket Type: we have 3 types of sockets SOCK_STREAM – Specifies a connection-based (stream) socket. SOCK_DGRAM – Specifies a datagram (UDP) socket. SOCK_RAW – Specifies a raw socket. we have some routines under sock. Lib library, socket( ) - open a socket bind( ) - bind a name to a socket listen( ) - enable connections to a socket accept( ) - accept a connection from a socket connect( ) - initiate a connection to a socket sendto( ) - send a message to a socket send( ) - send data to a socket

sendmsg( ) - send a message to a socket recvfrom( ) - receive a

sendmsg( ) - send a message to a socket recvfrom( ) - receive a message from a socket recv( ) - receive data from a socket recvmsg( ) - receive a message from a socket setsockopt( ) - set socket options getsockopt( ) - get socket options getsockname( ) - get a socket name getpeername( ) - get the name of a connected peer shutdown( ) - shut down a network connection connect. With. Timeout( ) - attempt socket connection within a specified duration