SIMPL Refresher

Course content Enter chat room Send email 
to mailing list
Check calendar

JUST A REMINDER:  for those of you who have not yet received your confirmation that you have been
subscribed to the mailing list please contact us by email immediately.

In memory of Linda.  Worldwide Cancer sites here.    Canadian Cancer donations here.
 
 

Hint:

All of these lessons  are designed to be worked on offline.  For those of you with dialup Internet access  you might find it helpful to print off the page for each lesson and work from the printout. 

 
 

SIMPL toolbox

What exactly is SIMPL?

SIMPL is really two things.

First of all SIMPL represents a very good paradigm for designing software.    It promotes encapsulation of complexity and ready extendability ... both good things in a software package.

SIMPL is also an LGPL'd open source library that you can link to (dynamically or statically) that enables you to write software that readily exchanges Send/Receive/Reply (QNX ) style messages.

OK what does it really do?

It is a library.     Once you have it installed you can write your code using a rich (yet simple) set of functions for Interprocess Communication (IPC).    These functions include:

name_attach()
name_locate()
Send()
Receive()
Reply()
and a few lesser used ones.

So as you can see the SIMPL library API is very clean indeed.

How does it work?


In SIMPL vocabulary we speak of Linux processes as being of one of two types:

As you can see in the figure above there are several elements associated with a SIMPL message pass.

The first of these is the container for the bytes in the message itself.    That is contained within a shared memory area allocated by the sender process.   Actually there are two areas:  one for the outgoing message and one for the reply message.

To help with process blocking (more on that later) and synchronization a slotID is exchanged on a named pipe or fifo prior to each message pass.

A typical message exchange between a sender and a receiver would go something like this:

  1. SIMPL receiver process starts up and does a name_attach() to register its SIMPL name
  2. SIMPL receiver then does some initialization and drops into a Receive blocked state by calling the Receive() function
  3. SIMPL sender process starts up and does a name_attach() to register its unique SIMPL name
  4. sender then does a name_locate() to connect to the receiver's fifo
  5. sender composes a message and drops it into the outgoing shared memory area
  6. sender places its slotID onto the receiver's fifo and drops into a Send blocked state by calling the Send() function
  7. receiver wakes up and retrieves the slotID from the fifo and then connects to the shared memory area and retrieves the actual message contents
  8. receiver processes the message and composes a reply which is then placed directly into the sender's reply shared memory area
  9. receiver places its slotID onto the sender's fifo and drops back into Receive blocked state by calling the Receive() function
  10. sender wakes up and retrieves the reply
Before I lose you all in the details let's illustrate these things by way of some examples.
 
 

The first step: getting the SIMPL tools and installing them on your system

Before you begin you will need to decide where your SIMPL source tree will exist and make a couple of environment variables accordingly.
 
Hint on environment variables:
If you have never heard of environment variables please look them up in your Linux reference material.     The two environment variables that SIMPL uses must be set up so as to be always available after a login ... in much the same way as the Linux PATH enviroment variable is.    Typically this involves adding some "export" commands into one of the shell initialization files on your system.   $HOME/.bash_profile,  $HOME/.bashrc,   $HOME/.profile or /etc/profile are some examples of shell initialization files.

If you don't know which "dot file" to use for your Linux distribution   try the following experiment.      Add in an "echo hi" line to one of the "dot" files.     Logout and back into your system (if you are a GUI person open a text console window also).      If you see your "hi" then that is the file in which to add the export lines below.

You can elect to place your SIMPL source anywhere you please as long as the subdirectory is called "simpl".   Suppose you decided to place all the SIMPL source at:

/home/simpl
then you would need to create an environment variable called SIMPL_HOME which pointed to this directory.   ie. in your local .bashrc (or other suitable hidden file) you would add the following line:
export SIMPL_HOME=/home/simpl
The SIMPL library will also need to access a various fifos involved in the SIMPL message exchange.     You will need to create a directory to hold the inodes for the various fifo's used by the SIMPL environment.    Once again you can place this directory anywhere you please ... no requirement to call this subdirectory fifo.    Suppose that you elect to place this "fifo" directory at:
/home/simpl/fifo
then you would need to create a second environment variable called FIFO_PATH which points to this directory. ie.
export FIFO_PATH=/home/simpl/fifo
Note:

The SIMPL source tree has been carefully designed not to "pollute" your system.    All SIMPL related files will exist under one of these two directories above.

You are now ready to go online and grab the latest version of SIMPL  source code from the SIMPL Open Source project website.

main SIMPL home page
or
sourceforge SIMPL site
Note:

The SIMPL project is a dynamic Open Source project and releases are made regularly.   It is also quite stable.

It is important that you pickup the latest release to capture all the bug fixes that have been done.    When in doubt which version to use the Sourceforge site always only contains the latest release.

Once you have downloaded the latest tarball you need to place it at the subdirectory immediately above the SIMPL_HOME.  ie.

cd $SIMPL_HOME
cd ..
<place your SIMPL tarball here>
then you can undo your tarball by typing
tar -zxvf whateveryourSIMPLtarballnameis
At this point you should have a whole bunch of source code sitting at SIMPL_HOME.
 
 

The next step: building the SIMPL libraries

After installing all the source on your system the next step is to build all this source code into the SIMPL libraries.

To do this you will need to:

              cd $SIMPL_HOME/scripts
              ./buildsimpl

This should cause the SIMPL source to completely build and install itself.
 
Note:

The SIMPL source tree has some Tcl/Tk hooks built into it.    If you do not have Tcl/Tk installed on your Linux system you will need to do this now as we will be using Tcl/Tk in a later lesson as our GUI language.


 
 

 Making sure that the SIMPL tools work

One of the subdirectories under the SIMPL_HOME tree is called benchmarks.     Some SIMPL executables were build here.   They can be used to "time" the SIMPL message passing on your system.

We will be using them here to verify that you have SIMPL installed and the environment variables correctly defined.

The buildsimpl script should have caused two executables to be built.

To run this benchmark test you will need to open 2 text consoles on your system and point each to the
$SIMPL_HOME/benchmarks/bin
directory.

On console 1: logged onto $SIMPL_HOME/benchmarks/bin  type

receiver -n BOBR
where BOBR - is an arbitrary SIMPL name you have chosen for this receiver.


On console 2: logged onto $SIMPL_HOME/benchmarks/bin  type

sender -n BOBS -r BOBR -t 100000 -s 1024
where -n BOBS - is the SIMPL name for the sender
              -r BOBR - is SIMPL name used for the receiver above
              -t 100000  - means send 100000 messages before displaying timing
              -s 1024 - says make each message 1024 bytes in length (same size for replies)
When you hit enter on console 2 the sender locates receiver and then marks the time. It then procedes to send 100000 1k  messages to the receiver each time blocking for the same size reply.
 
 
If you see seg faults in the above:
This is a clear indication that you do not have your environment variables (in particular FIFO_PATH) defined in such a way that they are set for each login.   ie. if you were to type "echo $FIFO_PATH" nothing would show up.

SIMPL uses these two environment variables both at build time (SIMPL_HOME) and at run time (FIFO_PATH) so it is very important that you  export both of these environment variables so that they are always set.
 

When this preset number of  messages have been exchanged the sender calculates and reports the total elapsed time in msec.

You have asked your system to do a substantial piece of work here.    Depending on your processor type and speed this may take several tens of seconds to complete.

Once you have the number you can easily compute the number of SIMPL messages per second that your system is capable of exchanging.
 
 
Congratulations!  You have successfully installed SIMPL on your system!

It might be nice to share your benchmark results with the mailing list.

For those of you who are interested in such things SIMPL's benchmarks are within an order of magnitude of QNX on the same hardware.   ie. QNX will exchange messages about 10 times faster than SIMPL under Linux.      With modern computing hardware the SIMPL message passing speed is more than adequate for most applications, however.     Besides SIMPL is Open Source and you can't beat its price point.

Because SIMPL does not use the TCP/IP stack for local message passing it will be significantly faster at passing messages between Linux processes on the same box.
 
 

The concept of a software IC

Computer hardware is complex.

So is computer software.

It is instructive to examine how the hardware designs have evolved to handle this complexity.

It wasn't that many years ago when electronic circuits were built up of discrete components (transistors, resistors, capacitors etc.).

As complexity of electronic circuits increased it became impossible for hardware engineers to manage this complexity.     Enter the integrated circuit (IC).     What this did for the hardware engineer was to take functionality which would have previously been provided by a custom circuit board with discrete components and replace it by a silicon chip with well defined behavior characteristics and pin outs.     This innovation is what has allowed the hardware engineers to make the spectacular progress we have witnessed in the past 25 years.

Software never had that equivalent encapsulating technology.     Object Oriented Programming (OOP) languages such as C++ or JAVA attempt to attack the software complexity problem at the programming language level.     For some classes of problems such as GUI design they have been successful.     Unfortunately for whole other classes of problems all they have succeeding in accomplishing is a shift of complexity to another location:  namely the source code.

Fortunately, modern multitasking languages provide us with a ready analog to the hardware integrated circuit:   namely a process running in a protected mode.      All of us have used processes on the Linux box already without giving them much thought.     If one of those processes encounters a fatal error it rarely brings down the whole machine.      If for some reason we do something that sends one of those processes into a locked state it rarely hangs the whole rest of the machine.

This protection from error propogation is a very desirable feature to have in a software IC.

So the process can act as our container for our complex algorithms in much the same way as the silcon chip inside the plastic case does for the hardware IC.

It wouldn't do us much good, however if we didn't have a simple and flexible way to expose this algorithm to interation from the outside world:   ie. the analogy to the pins on the hardwareIC.

Fortunately with SIMPL messaging we have exactly such a tool.

With SIMPL and a basic language such as C we are going to see that we can achieve something remarkably close to a software IC without having to resort to an OOP language and unreadable source code.

First we need to understand a little more about how SIMPL works.
 

The SIMPL "sandbox"

SIMPL maintains a kind of "phone book" to keep information about all running SIMPL processes.

This "phone book" is kept as a set of special files in the directory you named:

$FIFO_PATH
There are several utilities that come with the SIMPL package for viewing and manipulating this fifo directory.

The first of these is affectionately called "the hammer" by some folks:

cd $FIFO_PATH
rm *
If you are careful when you run the "hammer" it will ensure that your SIMPL sandbox is clean.     It will not, however, insure that any rogue processes you had running were terminated properly.

For that you will need to run another pair of utilities before invoking the "hammer".

The first of these  utilities is the slot viewer:

$SIMPL_HOME/bin/fcshow
If you run this it will show all the SIMPL names currently registered  along with the pid they are associated with.

Try rerunning the benchmark test from lesson #1 and while the timing is taking place,  change to  another console and run fcshow.

Finally if you have a need to kill a rogue SIMPL process by its SIMPL name then there is a utility called:

$SIMPL_HOME/bin/fcslay
which you use as
fcslay <SIMPLname>
Once again give this a try by starting up the receiver above and from another console typing
fcslay BOBR

Download the softwareIC code from the SIMPL project

The SIMPL project contains a set of very basic software ICs in the form of a tarball which can be downloaded from the SIMPL website.

Go ahead download this tarball.

You'll want to install it at exactly the same place that you installed the SIMPL toolset.     Not to worry,  the softwareIC tarball will safely install all its code at:

$SIMPL_HOME/softwareICs


Before we go forward let's make sure that this code all compiles.

cd $SIMPL_HOME/softwareICs
make install
 
 
 
Makefile refresher:
If you need a refresher on Makefiles click here to view an excerpt from the iCanProgram Introduction to Linux Programming course.

If you take a look at the softwareICs directory above you will see several subdirectories.     Each of these represents a different softwareIC.       You are welcome to read up more on some of the more complex softwareICs such as the agency by perusing the documentation on the SIMPL website.
 


Copyright of iCanProgram Inc.  2003