CS452 - Real-Time Programming - Spring 2013

Lecture 10 - Name Server

Pubilc Service Annoucements

  1. Due date for kernel 2: 31 May.
  2. Error returns for Send

    The kernel document describes three error returns that are required.

    General comments on the handing of errors.


Inter-task Communication

There are two cases

Send before Receive

Sender

Action

Sender

State

Receiver

Action

Receiver

State

Comments
active
Send RCV_BL sender added to receiver's sendQ
active
RPL_BL Receive ready request copied

sender deleted from receiver's sendQ

active service performed
ready Reply ready reply copied

Receive before Send

Sender

Action

Sender

State

Receiver

Action

Receiver

State

Comments
active
Receive SND_BL receiver's sendQ empty
active
Send RPL_BL ready request copied
active service perfomed
ready Reply ready reply copied


Practical Details

Example of a Difficult Bug

A group noticed that

They decided to implement this optimization, using reasoning based on the following scenario.

  1. Sender calls Send while receiver is in some state other than SND_BL.
  2. Sender is made RCV_BL and placed on receiver's SendQ.
  3. A second sender calls Send before first sender has been received.
  4. The second sender is put on the first sender's next pointer. Both senders are now RCV_BL.
  5. Duplicate 3 & 4 as many times as you like.
  6. Receiver calls Receive and immediately has a transaction with first sender.
  7. Receiver calls Reply; both receiver and first sender are RDY.
  8. Receiver runs first, calls Receive and handles second sender

Servers

What is a server?

How are servers implemented?


Name Server

What is a name server?

Why Do We Need a Name Server

Names constant across applications
& executions
interface Associated with a set of services (an API)
Task Ids vary across applications
& executions
implementation Associated with a particular set of instructions
and data (an execution)

How do You Get the Task Id of the Name Server?

  1. Make it a constant across executions

Name Server API

int RegisterAs( char *name );
int WhoIs( char *name );

Name Server Semantics

RegisterAs

WhoIs

Comments

Name Server Implementation

What does the client need to know in order to use the name server

  1. its taskid
  2. the requests it services
  3. its API: function signatures and type definitions

User Pseudo-Code

int RegisterAs( char *name ) {
    NSstruct *req, *result;
    // pack structures
    bytes = Send( NSTid, (char *) req, sizeof(NSstruct), (char *) result, sizeof(NSstruct) );
    // unpack structures}

There are lots of possible variations.

Generic Server Code

typedef struct {
    int type;
    // other stuff
} ReqStr;
int tid;
NSstruct req;
// initialize server internals
FOREVER {
    Receive( &tid, &req, sizeof(NSstruct) );
    switch( req.type ) {
        case SERV1:
            do1( &req );
            Reply( tid, ... );
            break;
        case SERV2:
            do2( &req );
            Reply( tid, ... );
            break;
        ...
        default:
            // This should never happen
    }
}
    }
}

Name Server

  1. One service associates a taskid with a name
  2. The second service looks up the taskid and replys it to the requestor

Questions

  1. How much will this code run?
  2. What should happen when a WhoIs request is made for an unregistered name?
  3. How would you implement insert & lookup?
  4. What should be allowable as a name?

Hardware Interrupts

What is a Hardware Interrupt?

In the CPU

  1. Test interrupt signal before fetching the next instruction
  2. If asserted, change mode to IRQ
  3. Disable interrupt in CPSR
  4. Execute instruction at 0x18

In the Interrupt Control Unit (ICU)

In the Peripheral Hardware

When two interrupts are present

May have been two present when interrupt processing started

May have occurred since interrupt processing started

What happens next?

  1. Kernel executes with interrupts disabled
  2. Context switch into user task turns on interrupts
  3. Before fetching the first user task instruction test interrupt signal
  4. If asserted, re-initiate interrupt processing

Context Switches for Interrupts

Difference from Software Interrupts

It is impossible to predict where they occur

Assymmetry between User Task and Kernel

Scratch Registers must be saved

Two Link Registers

  1. One to return from interrupt
  2. One to move to the caller's stack frame

Helpful Features of the ICU

  1. Several places where you can read state
  2. Several places where you can block interrupt flow
  3. Trigger hardware interrupt from software

The Hardware in the Trains Lab

32-bit Timer

Base address: 0x80810080

Three registers:

Offset Function R/W Bits Comments
0x0 Timer3Load R/W 32: <Load/Reload Value>
0x4 Timer3Value R 32:<Current value> Set when Load is written,
even when counting
0x8 Timer3Control R/W 3:xxx<CLKSEL>xx<MODE><ENABLE> <CLKSEL>: 0, 2KHz clock; 1, 508KHz
<MODE>: 1, count continuously; 0, count once
<ENABLE>: Clock turned on
0xc Timer3Clear W 32: Writing anything clears the interrupt

Interrupt Control Unit (ICU)

The actual device is the ARM PL190

The logic in this design is completely asynchronous, so it functions when the CPU clock is turned off.

All input signals are

Base addresses

Basic Operation

VIC powers up with

Procedure

Initialization

  1. leave protection off
  2. enable in VICxIntEnable when you are ready to handle the interrupt

On an interrupt

  1. Read VICxIRQStatus
  2. Choose which interrupt you wish to handle
  3. Clear the interrupt source in the device

For debugging

  1. Use VICxSoftInt and VICxSoftIntClear to turn interrupt sources off and on in software

Hardware Definitions

Registers for Basic Operation
Register Name Offset R/W Description
VICxIRQStatus 0x00 RO One bit for each interrupt source

1 if interrupt is asserted and enabled

VICxFIQStatus 0x04 RO As above for FIQ
VICxRawIntr 0x08 RO As above but not masked
VICxIntSelect 0x0c R/W 0: IRQ, 1: FIQ
VICxIntEnable 0x10 R/W 0: Masked, 1: Enabled
VICxIntEnClear 0x14 WO Clears bits in VICxIntEnable
VICxSoftInt 0x18 R/W Asserts interrupt from software
VICxSoftIntClear 0x1c WO Clears interrupt from software
VICxProtection 0x20 R/W Bit 0 enables protection from user mode access
VICxVectAddr 0x30 R/W Enables priority hardware

See documentation.

Helpful Features of the ICU

  1. Several places where you can read state
  2. Several places where you can block interrupt flow
  3. Trigger hardware interrupt from softwareonce
    1. What makes interrupts hard is that you are doing two semi-hard things at once
      • Making the hardware produce the interrupt
      • Responding to the interrupt
    2. Software interrupt generation allows you to separate them in developing/debugging


Non-vectored Operation

Initialization

  1. Enable interrupt in device
  2. Enable interrupt in ICU
  3. Enable interrupt in CPU, usually by MOVS

Interrupt occurs

  1. AND of IRQ and NOT( IRQ disabled bit in CPSR ) is checked before each instruction fetch.
  2. If set IRQ exception is taken in place of next instruction fetch.
  3. Context switch into kernel


    Context switch novelties

    Difference from Software Interrupts


  4. Turn off interrupt in device

You are now ready to process the interrupt in the kernel


Return to: