IXP1200 Network Processor Family ATM OC-3/12/Ethernet IP Router Example Design
42 Application Note
Modified on: 3/20/02,

4.5.2 Usage Model

The following model is described by an analogy to waiting in line at a bakery:.

4.5.2.1 Example

#define MY_SEQUENCE_HANDLE my_seq_number, @enter, @one, @exit, @one, 32
sequence_init(MY_SEQUENCE_HANDLE) // initilize global state
while()
<...> // get work in order
sequence_enter(MY_SEQUENCE_HANDLE) // record the order
<...> // process non-critical section
sequence_wait(MY_SEQUENCE_HANDLE) // wait my turn
msgq_send() // process critical section
sequence_exit(MY_SEQUENCE_HANDLE) // let the next guy go
4.6 Message Queues - msgq.uc
The Message Queue subsystem supports 31-bit messages between microengines. The queues are
implemented with circular buffers, typically in scratchpad RAM. The queues are point-to-point,
there can be only one sender microengine, and one receiver microengine because the queue indexes
are stored privately in microengine registers rather than shared in RAM.
If the sender sends to a full queue, it will return an error so that the sender is able to determin e what
to do with the unsent message.
The threads within the sender must cooperate and not simultaneously access the same queue. This
is typically done by putting the msgq_send() or msgq_receive() inside a critical section.
The message queue handle can specify that receives be either asynchronous or synchronous:
Asynchronous receives (MSGQ_ASYNC) will return after reading what was in the queue, no
matter if it was valid or invalid. The invoking thread must look at the invalid bit to decide what
to do with the message.
Synchronous receives can either loop internally on receipt of invalid messages
(MSGQ_SYNC_POLL), or go to sleep after receiving an invalid message
(MSGQ_SYNC_SLEEP). The sender must know to (always) wake up the receiver if
MSGQ_SYNC_SLEEP is used.
Step Sequence Operation Bakery Line Analogy
1
sequence_enter() returns a sequence number to a thread
and updates the absolute.enter so that the next time
sequence_enter() is invoked, the following sequence
number will be returned
Enter bakery and take a ticket.
2sequence_wait() compares its sequence number with the
absolute.exit, and context swaps until they are the same. Wait in line for the "Now Serving" sign to
match your ticket.
3Having gotten past sequence_wait(), the thread
processes the critical region. Get served, keep others in line away from
counter.
4sequence_exit() increments absolute.exit to let the next
sequence number past sequence_wait().
Exit bakery, "Now Serving..." sign gets
incremented to let next customer to
counter.