EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  <19992000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  <19992000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: iocCore port
From: Marty Kraimer <[email protected]>
To: [email protected]
Date: Fri, 10 Sep 1999 15:05:34 -0500
Work on porting iocCore to other operating systems besides vxWorks is
progressing.

The following has been accomplised

Almost all of base except Channel Access, the sequencer, and hardware support
has been changed to use the new osi routines rather than vxWorks specific calls.
I have not touched Channel Access becuse this needs help from Jeff Hill. William
Lupton is already working on a version of the sequencer that is independent of
vxWorks. The hardware dependent code will be unbundled from base.

Janet Anderson has modified the make system so that it works for non vxWorks IOC
targets. The new system is actually easier than the old.

Using the new osi independent code the example application generated by
makeBaseApp has been run successfully. This was a major milestone.

A document describing the iocCore port is attached. Note that to port to other
systems only the libraries osiSem and osiThread need to be implemented. It
should be possible to implement these using posix calls. If this is done we
should be able to run iocCore on many platforms.

Marty Kraimer

Porting iocCore

Sept 10, 1999

iocCore includes the following components of epics base:
  • Database locking, scanning, and processing
  • Channel access client and server support
  • Standard record types and soft device support
  • Access security
  • Other non-hardware support presently packaged with base


The port is based on the following assumptions:

  • All hardware support  is unbundled from base and thus does not need to be ported.
  • For iocCore a multithreaded environment is necessary.
  • osi  components are defined such that
    • vxWorks implementation has minimal overhead compared to vxWorks specific calls
    • The components can be implemented via a combination of POSIX, POSIX.4 (posix real time), and POSIX threads (pthreads).
  • For components that require different implementation for different environments
    • The implementation may be via header and/or source files as long as user code can use the "prototype" header files.

Overview of Changes

Replacements for existing vxWorks and epics components

The following Operating System Independent libraries replace vxWorks specific libraries.
  • osiClock

  • replaces tickGet, sysClockRateGet, TSgetTimeStamp and TSgetCurrentTime.
    A generic and a vxWorks version is available
  • osiFindGlobalSymbol

  • A generic version is provided that always returns failure.
    a vxWorks version is provided that calls symFindByName.
  • osiInterrupt

  • Replaces intLib
    A generic version is provided that uses a global semaphore. It can be used for winXX, Unix, Linux, etc.
    A vxWorks specific version is provided.
  • osiRing

  • Replaces rngLib.
    A generic version usable on all platforms is provided.
    A vxWorks specific version is provided.
  • osiSem

  • replaces semLib.h
    A vxWorks version is provided.
    No version has been written for other platforms.
  • osiThread

  • replaces taskLib.h
    A vxWorks version is provided.
    No version exists for other platforms.
  • osiWatchdog

  • replaces wdLib.h
    A vxWorks version is provided.
    No version exists for other platforms.
In addition the following new base components are provided
  • cantProceed

  • This is called by code that doesnt know what to do when an error occurs.
  • registry

  • replaces symFindByName

Registry

It is not possible to expect every environment to supply an environment that makes it easy to implement  vxWorks symFindByName. Instead a facility to register and find pointers to functions and structures is provided. This leaves the problem of registering everything currently located via calls to symFindByName. The following solves the problem:
  • Each "ioc" loads a single dbd file defining the complete set of record types, device support, and drivers for that "ioc". A utility is provided that reads this dbd file and generates a C routine registerRecordDeviceDriver, which registers the record,  device, and driver support.
  • dbLoadDatabase calls registerRecordDeviceDriver after loading the database.
  • A version of registerRecordDeviceSupport is also provided which calls osiFindGlobalSymbol. If the underlying operating system properly implements  osiFindGlobalSymbol, this version can be used without running the utility that generates the special version. For example this version works on vxWorks
  • Nothing has been done to support things like subroutine records. It should not be hard.

Build Environment (Everyone's favorite subject :-)

The build environment is different. The principal features are:
  • Each source directory has a single Makefile. This build for both the host and for all IOC targets
  • The new configuration files are located in base/configure
  • At least for awhile base/config is still present so that old applications still build without major changes


UNRESOLVED ISSUE: Should we have the ability to distinguish building for a single vw multithreaded environment? My guess is YES.

task_params.h

This will go away.
  • Thread names are determined by code that calls threadCreate
  • Priorites and stack sizes are handled as described below in the description of thread
  • Task creation options are  determined by each platform specific version of thread.

vxWorks shell

If the target is not for vxWorks, the vxWorks target shell is not available. IocInit, dbLoadRecords, etc  must be  called directly by main or the equivalent. The "nice" vxWorks debugging environment is not available although a nicer one using xgdb may be available.

How do we run dbpr, dbgf, etc?

Interrupt Level

The vxWorks intLock/intUnlock routines are an essential part of base. For example any code, including interrupt routines, can call callbackRequest. osiInterrupt is provided to solve this problem. For operating systems like vxWorks, in which everything runs in a shared memory, multithreaded kernel environment, an osi specific version must be provided. For other operating systems, e.g. winxx, Unix, Linux, a generic version is provided. The only restriction is that kernel code MUST not call any of the osi routines.

Status Of Port

The following has been done:
  • All code except Channel Access, Sequencer, and vxWorks dependent device and driver support has been converted to use the new libraries
  • The registry has been implemented
  • The example generated by makeBaseApp has been successfully tested on vxWorks.
  • A separate subdirectory base/src/vxWorks has been created and all vxWorks specific code moved to this subdirectory. This makes it possible for existing vxWorks ioc applications to use the new system with only minor changes to the applications.
  • Work Remaining

  • Implement osiSem and osiThread for other platforms. If the implementation is done via posix (including posix real time and posix threads) then many platforms should be supported.
  • Convert Channel Access (client and server) to use osi calls.
  • Convert the sequencer to use osi calls. William Lupton has already implemented an alpha version. Also the sequencer will be unbundled from base.
  • Finish the config and Makefile Changes.
  • Modify makeBaseApp so that it uses the new method of building
  • TEST TEST TEST
  • Prototype Definitions

This section contains prototype definitions of what needs to be implemented for each port of iocCore.

A particular implementation may implement each function as desired BUT the final result must appear to user code like the definitions in this section. For example  functions can be implemented via macros defined in a header file that replace the generic header file.
 

osiClock

unsigned long clockGetCurrentTick();
int clockGetRate();
int clockGetEventTime(int event_number,TS_STAMP *ts);
int clockGetCurrentTime(TS_STAMP* ts);
A vxWorks specific version is provided that provides exactly the same semantics as 3.13.

A generic version is provided that should work on most platforms.

Perhaps it should be implemented via libCom/osiTime.

osiFindGlobalSymbol

void * osiFindGlobalSymbol(const char *name);
A vxWorks version is provided that calls symFindByName. It is called by the registry if a name is not found in the registry itself.

A generic version is provided that always returns failure. If the generic version is used then all external symbols must be registered, See the registry for details.

osiInterrupt

int interruptLock();
void interruptUnlock(int key);
int interruptIsInterruptContext();
void interruptContextMessage(const char *message);
A vxWorks specific version is provided. It maps directly to intLib calls.

A generic version is provided that uses a global semaphore to lock. This version is intended for operating systems in which iocCore will run as a multithreaded process. The global semaphore is thus only global within the process.

osiRing

ringId  ringCreate(int nbytes);
void    ringDelete(ringId id);
int     ringGet(ringId id, char *value,int nbytes);
int     ringPut(ringId id, char *value,int nbytes);
void    ringFlush(ringId id);
int     ringFreeBytes(ringId id);
int     ringUsedBytes(ringId id);
int     ringSize(ringId id);
int     ringIsEmpty(ringId id);
int     ringIsFull(ringId id);
A vxWorks specific version is provided that maps directly to rngLib calls.

A generic version is provided that works on all platforms.  This version is currently 1.5 times slower than the vxWorks specific version. Perhaps some clever thought can make it as fast as rngLib.

osiRing has the following properties.

  • For a single writer it is not necessary to lock puts
  • For a single reader it is not necessary to lock gets

  • ringFlush should only be used if both gets and puts are locked.

osiSem.h

typedef void *semId;
typedef enum {semTakeOK,semTakeTimeout} semTakeStatus;
typedef enum {semEmpty,semFull} semInitialState;

semId semBinaryCreate(int initialState);
void semBinaryDestroy(semId id);
void semBinaryGive(semId id);
semTakeStatus semBinaryTake(semId id);
void semBinaryTakeAssert(semId id);
semTakeStatus semBinaryTakeTimeout(semId id, double timeOut);
semTakeStatus semBinaryTakeNoWait(semId id);
void semBinaryFlush(semId id);

semId semMutexCreate(void);
void semMutexDestroy(semId id);
void semMutexGive(semId id);
semTakeStatus semMutexTake(semId id);
void semMutexTakeAssert(semId id);
semTakeStatus semMutexTakeTimeout(semId id, double timeOut);
semTakeStatus semMutexTakeNoWait(semId id);
void semMutexFlush(semId id);


Mutual exclusion semaphores

  • MUST implement recursive locking
  • SHOULD implement priority inheritance and be deletion safe
For POSIX
  • Binary can be implemented easily as a condition variable
  • Mutex can be implemented via various POSIX facilities. Takes careful thought. A pthread mutex is not sufficient.
For vxWorks
  • the entire implementation of  Binary and Mutex is via macros in a vxWorks specific header file.


On a single threaded environment

  • Mutex and context are implemented as though the caller always has access to the resource.
  • Binary issues an error message and terminates if an attempt is made to create an instance.

osiThread

#define threadPriorityMax 99
#define threadPriorityMin  0

/*some generic values */
#define threadPriorityLow 10
#define threadPriorityMedium 50
#define threadPriorityHigh 90


/*some iocCore specific values */
#define threadPriorityChannelAccessClient 10
#define threadPriorityChannelAccessServer 20
#define threadPriorityScanLow 60
#define threadPriorityScanHigh 70

/*
 *The following functions convert to/from osi (operating system independent)
 * and oss (operating system specific) priority values
 * NOTE THAT ALL OTHER CALLS USE osi priority values
*/

int threadGetOsiPriorityValue(int ossPriority);
int threadGetOssPriorityValue(int osiPriority);

/* stack sizes for each stackSizeClass are implementation and CPU dependent */
typedef enum {
    threadStackSmall, threadStackMedium, threadStackBig
} threadStackSizeClass;

unsigned int threadGetStackSize(threadStackSizeClass size);

typedef void *threadId;
threadId threadCreate(const char *name,
    unsigned int priority, unsigned int stackSize,
    THREADFUNC funptr,void *parm);
void threadDestroy(threadId id);
void threadSuspend(threadId id);
void threadResume(threadId id);
int threadGetPriority(threadId id);
void threadSetPriority(threadId id,int priority);
void threadSetDestroySafe(threadId id);
void threadSetDestroyUnsafe(threadId id);
const char *threadGetName(threadId id);
int threadIsEqual(threadId id1, threadId id2);
int threadIsReady(threadId id);
int threadIsSuspended(threadId id);
void threadSleep(double seconds);
threadId threadGetIdSelf(void);
void threadLockContextSwitch(void);
void threadUnlockContextSwitch(void);
threadId threadNameToId(const char *name);
Thread priorities are assigned a value from 0 to 99. A higher value means higher priority

Thread stack values are handled as follows:

  • threadGetStackSize cal be called to get one of three default sizes. Thus should be done whenever possible.
  • Code can just set any size it desires. Such code is not portable.
For vxWorks osiThread is implement via calls to taskLib

For posix it should be possible (I hope)  to implement thread via a combination of:

  • osiSem
  • pthread and POSIX.4
  • Special code
Thread is not implemented for a single threaded environment.

osiWatchdog

typedef void *watchdogId;
typedef void (*WATCHDOGFUNC)(void *parm);

watchdogId watchdogCreate ();
void watchdogDestroy (watchdogId id);
void watchdogStart(watchdogId id, int delaySeconds,WATCHDOGFUNC funptr,*parm);
void watchdogCancel(watchdogId id);
A vxWorks version is provided that maps directly into mwdLib calls.

I think a generic version can be implemented via base/srcf/libCom/osiTimer. This has not yet been implemented.

New base supplied component

cantProceed

void cantProceed(const char *errorMessage);
void *callocMustSucceed(size_t count, size_t size, const char *errorMessage);
void *mallocMustSucceed(size_t size, const char *errorMessage);
cantProceed prints error message and then
  • For a threaded environment suspends. This is for debugging purposes.
  • For a non-threaded environment exits.
callocMustSucceed is like calloc except that it does not return if storage is not available. A lot of iocCore is initialized by iocInit. If memory allocation fails during iocInit it is not possible to recover. mallocMustSucceed is like malloc except that it does not return if storage is not available.

REGISTRY

iocCore currently uses symFindByName to dynamically bind the following:
  • record/device/driver support.

  • The registration facility provides a safe and easy to use alternative to symFindByName
  • subroutine record subroutines.

  • An easy to use solution must be developed.
  • initHooks

  • A new implementation of initHooks is now provided. It provides a routine initHookRegister. This MUST be called by any routine that wants to be called during initialization.
  • devLib

  • This has been moved to base/src/vxWorks. Thus for now it is only supported on vxWorks
  • drvTS.c

  • This has been moved to base/src/vxWorks. Thus for now it is only supported on vxWorks
  • errSymLib.c

  • This was rewritten to be independent of vxWorks.
  • epicsDynLink - obsolete. Gone.
  • dev/symbDev

  • Moved to base/src/vxWorks. Thus for now it is only supported on vxWorks.
  • any hardware related component

  • Either moved to base/src/vxWorks. or unbundled from base.
This only the first two items need a solution. The existing implementation solves the first problem. No solution has been provided for the subroutine records but it will not be hard implement.

Overview

The basic idea is to provide a registration facility. Any storage meant to be "globally" accessable must be registered before it can be accessed by other code.

A perl script is provided that reads the xxxApp.dbd file and produces a c file containing a routine registerRecordDeviceDriver, which registers all record/device/driver support defined in the xxxApp.dbd file.

registry

int registryAdd(void *registryID,const char *name,void *data);
void *registryFind(void *registryID,const char *name);
int registrySetTableSize(int size);
void registryFree();
int registryDump(void);
This is the code which does the work. Each different set of things to register must have it's own unique ID. Everything to be registered is stored in the same gpHash table.

Routine registrySetTableSize is provided in case the default hash table size (1024 entries)  is not sufficient.

registryRecordType.h

typedef int (*computeSizeOffset)(dbRecordType *pdbRecordType);

typedef struct recordTypeLocation {
    struct rset *prset;
    computeSizeOffset sizeOffset;
}recordTypeLocation;


int registryRecordTypeAdd(const char *name,recordTypeLocation *prtl);
recordTypeLocation *registryRecordTypeFind(const char *name);
Some features:
  • Access to both the record support entry table and to the routine which computes the size and offset of each field are provided
  • Type safe access is provided.

registryDeviceSupport

int registryDeviceSupportAdd(const char *name,struct dset *pdset)
struct dset *registryDeviceSupportFind(const char *name);
This provides access to the device support entry table.

registryDriverSupport

int registryDriverSupportAdd(const char *name,struct drvet *pdrvet);
struct drvet *registryDriverSupportFind(const char *name);

/* The following function is generated by registerRecordDeviceDriver/pl */
int registerRecordDeviceDriver(DBBASE *pdbbase);
This provides access to the driver support entry table.
 

registerRecordDeviceDriver.pl

This is the perl script which creates a c source file that registers record/device/driver support. Make rules are provided that
  • execute this script using the dbd file created by dbExpand
  • compile the resulting C file
  • Make the object file part of the xxxLib file

registerRecordDeviceDriver.c

A version of this is provided for vxWorks. This version makes it unnecessary to use registerRecordDeviceDriver.pl or register other external names. Thus for vxWorks everything can work almost exactly like it did in release 3.13.x
Navigate by Date:
Prev: problems with downloading EPICS Lifang Zheng
Next: Unix sequencer William Lupton
Index: 1994  1995  1996  1997  1998  <19992000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: problems with downloading EPICS Lifang Zheng
Next: RE: iocCore port Peregrine McGehee
Index: 1994  1995  1996  1997  1998  <19992000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 10 Aug 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·