IPC 1 - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

IPC 1

Description:

unidirectional, first-in first-out, unstructured data stream ... User-level program called netmsgserver extends Mack IPC across a network. node A. client ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 24
Provided by: chunchu
Category:
Tags: ipc | mack

less

Transcript and Presenter's Notes

Title: IPC 1


1
Chapter 6. Interprocess Communications
  • Introduction
  • Universal IPC facilities
  • System V IPC
  • Mach IPC

2
Introduction
  • Purposes of IPC
  • data transfer
  • sharing data
  • event notification
  • resource sharing
  • process control

3
Universal IPC Facilities
  • Signals
  • expensive, limited bandwidth
  • Pipes
  • unidirectional, first-in first-out, unstructured
    data stream
  • simple flow control mechanism
  • pipe( ) system call
  • return two file descriptor, one for reading an
    one for writing

4
Universal IPC Facilities (cont)
  • I/O is performed through read and write system
    calls
  • implementation of pipe
  • SVR2 inode
  • BSD socket
  • SVR4 STREAM (bi-directional pipe)
  • Process tracing ptrace( )
  • used by debuggers such as dbx
  • control the execution of a child process

5
System V IPC
  • Semaphores, Message queues, Shared memory
  • Common elements
  • attributes
  • key, creator, owner, permission
  • acquires a resource
  • shmget( ), semget( ), msgget( )
  • IPC_CREAT, IPC_EXCL flags
  • control system call
  • shmctl( ), semctl( ), msgctl( )
  • IPC_STAT, IPC_SET, IPC_RMID commands

6
Semaphores
  • Creates and obtains an array of semaphores
  • semid semget(key, count, flag)
  • Operations on individual semaphore
  • status semop(semid, sops, nsops)
  • sops is a pointer to an nsops-element array of
    sembuf structures
  • struct sembuf unsigned short sem-num short se
    m_op short sem_flag

7
Semaphores (cont)
  • sem_op gt 0
  • add sem_op to the semaphores current value. This
    may result in waking up processes
  • sem_op 0
  • block until the semaphores value becomes zero
  • sem_op lt 0
  • block until the semaphores value becomes greater
    than or equal to the absolute value of sem_op,
    then subtract sem_op from that value
  • Race condition and deadlock

8
Message Queues
  • Creates or obtains a message queue
  • msgqid msgget(key, flag)
  • Places messages on the queue
  • msgsnd(msgqid, msgp, count, flag)
  • Removes messages from the queue
  • count msgrcv(msgqid, msgp, maxcnt, msgtype,
    flag)

9
Message Queues (cont)
  • Using a message queue

receivers
senders
struct msgqid_ds
P
P
msg
new messages added at tail
messages read from head
msg
msg
P
P
10
Message Queues (cont)
  • Discussion
  • message type can be used to associate priorities
    with messages
  • effective for transferring small amounts of data
  • expensive for large transfers
  • each message transfer involves two data copy
    operations

11
Shared Memory
  • A portion of physical memory shard by multiple
    processes
  • Creates and obtains a shared memory
  • shmid shmget(key, size, flag)
  • Attaches the region to a virtual address
  • addr shmat(shmid, shmaddr, shmflag)
  • Implementation depends heavily on the virtual
    memory architecture
  • Does not provide synchronization
  • Modern UNIX (SVR4) provides mmap( )
  • maps a file into the address space of callers

12
Shared Memory (cont)
memory map of process B
memory map of process A
0
0
0x30000
0x50000
0x50000
0x70000
Attaching a shared memory region
13
Mach IPC
  • Based on message passing
  • Supports secure communications
  • Provides communications btw user tasks, also btw
    user and kernel
  • extensible to a distributed environment
  • Basic concepts
  • messages
  • a collection of typed data
  • port
  • a protected queue of messages
  • send rights, receiver rights

14
Mach IPC (cont)
  • task_self port, thread_self port
  • task_notify port, reply port
  • exception port

senders
port
T
receiver
msg
msg
T
T
T
Communicating via a Mach port
15
Messages
  • Three basic types of data
  • ordinary data
  • not interpreted by kernel and is passed on to the
    receiver by physically copying it
  • out-of-line memory
  • used to transfer large chunks of data using
    copy-on-write techniques
  • send or receive rights to ports

16
Mach Message Format
type
size
Message header
Local port
Destination port
Message id
name
size
Type descriptor
number
flags
data
Type descriptor
name
size
number
flags
data
. . .
17
Ports
  • Port name space
  • simple integer local to each task
  • Port data structure
  • kern_port_t data structure for each port
  • Port translation
  • translation entry lttask, port, local_name, typegt
  • TP_chain hash chain based on lttask, portgt
  • TL_chain hash chain based on lttask,
    local_namegt
  • task_chain list of all translations owned by the
    same task
  • obj_chain list of all translations for this port

18
Port Translation
struct kernel_port_t
struct task
Task
Port
a
b
c
d
f
g
TP hash chain
e
TL hash chain
Translation entries (port_hash_t)
19
Message Passing
sender
receiver
kernel
Task
Task
outgoing message
kern_msg_t (internal message)
received message
copy
copy
in-line data
copy of data
copy of data
pointers to data copied into address space
pointers to out-of-line memory
holding map
copy mappings
copy mappings
port right (local name)
pointer to port object
port right (local name)
translate
translate
20
Out-of-Line Memory
  • Copy-on-write
  • a page must be copied only if and when one of the
    two tasks attempts to modify it
  • Message copied to holding map

address map
sender
holding map
T
COW
COW
COW
COW
COW copy-on-write
pages in memory
21
Out-of-Line Memory (cont)
  • Message copied to receiver task

address map
address map
sender
receiver
T
T
COW
COW
COW
COW
pages in memory
22
Out-of-Line Memory (cont)
  • Receiver modifies a page

address map
address map
sender
receiver
T
T
COW
COW
COW
pages in memory
23
Extensibility of Mach IPC
  • User-level program called netmsgserver extends
    Mack IPC across a network

node A
node B
RP
SP
client
server
reply port
reply port
netmsgserver
netmsgserver
proxy for SP
proxy for RP
SP
RP
Write a Comment
User Comments (0)
About PowerShow.com