Presentation is loading. Please wait.

Presentation is loading. Please wait.

EPICS Internals Nick Rees. Outline Introduction Libraries and modules Data Structures Process types Examples of processing.

Similar presentations


Presentation on theme: "EPICS Internals Nick Rees. Outline Introduction Libraries and modules Data Structures Process types Examples of processing."— Presentation transcript:

1 EPICS Internals Nick Rees

2 Outline Introduction Libraries and modules Data Structures Process types Examples of processing

3 INTRODUCTION

4 Background When I accepted this challenge I thought there was an EPICS internals talk I could copy. –It turns out there wasn’t. I decided the aim of the talk was to provide EPICS developers with a vague idea of what to expect to see when they look at a running EPICS system. –It turns out this wasn’t that easy –It also was very difficult to do this in 40 minutes. –By focussing on this I missed out more than I covered. The result is something which even I find a bit difficult to understand (and I wrote the talk), so I don’t know about the rest of you. –For the non-programmers out there, good luck.

5 What is EPICS core?

6 109 directories 1567 files, lines of all types –281 files, lines of C –203 files, lines of C++ –329 files, lines of header files –28 files, lines of html Over 20 years of development by a competent world-wide team. Not an enormous body of code. A pretty reliable body of code that does what it is designed to do. A reasonably useful, flexible and portable tool

7 What isn’t EPICS core? Consistently designed Designed Buzzword compliant, or even object-oriented Well understood by lots of people. Stylistically consistent. Pretty, elegant or pure

8 Another view The Application Developers guide states: –“EPICS consists of a set of core software and a set of optional components. The core software, i.e. the components of EPICS without which EPICS would not function, are: Channel Access - Client and Server software IOC Database Scanners Monitors Database Definition Tools Source/Release” This talk focuses on the first 4 points, with most emphasis on the IOC Database.

9 LIBRARIES AND MODULES

10 Helper libraries If you write EPICS base software you must know, understand and use the basic helper libraries it provides. For example: –ellLib – doubly linked list library identical to VxWorks listLib –gpHash – efficient hashes –freeList – malloc replacement giving efficient handling of fixed size blocks. –epicsRingBytes – ring buffers. –epicsThread – thead creation and control –epicsMutex – OS independent mutexes –etc...

11 Essential EPICS code dbStaticLib.c –Static database access routines Used during EPICS development or before iocInit. dbAccess.c –Run-time database access routines. –dbNameToAddr, dbPutField, dbPut, dbGetField, dbGet, dbProcess etc. dbConvert.c –Type conversions camessage.c –Channel Access server function table implementations. dbEvent.c –Implements database event handling etc.....

12 What EPICS libraries are there? Common –Cap5 –ca –cas –Com –gdd Host and IOC: –asHost –asIoc –dbStaticHost –dbStaticIoc IOC only –dbIoc –dbtoolsIoc –miscIoc –recIoc –registryIoc –rsrvIoc –softDevIoc –testDevIoc

13 EPICS library dependencies

14 Conclusion If you want to know more, consult the source.

15 DATA STRUCTURES

16 dbBase.h Basic database data structures are in dbBase.h These define the structures that hold the database. The are defined in the dbd and db files, and created by dbStaticLib. At run-time, they are accessed by dbAccess routines.

17 dbBase.h record tree dbBase └recordTypeList └dbRecordType └recordList └dbRecordNode └name └precord └dset └lset etc. └... └deviceList └... └dbFldDes[] └rset └...

18 dbBase.h tree

19 dbBase definition typedef struct dbBase { ELLLISTmenuList; ELLLISTrecordTypeList; ELLLISTdrvList; ELLLISTregistrarList; ELLLISTfunctionList; ELLLISTvariableList; ELLLISTbptList; void*pathPvt; struct dbPvd*ppvd; struct gphPvt*pgpHash; shortignoreMissingMenus; shortloadCdefs; }dbBase;

20 dbRecordType definition typedef struct dbRecordType { ELLNODEnode; ELLLISTattributeList;/*LIST of attributes*/ ELLLISTrecList;/*LIST of sorted dbRecordNodes*/ ELLLISTdevList;/*LIST of device support*/ ELLLISTcdefList;/*LIST of Cdef text items*/ char*name; shortno_fields;/* number of fields defined*/ shortno_prompt;/* number of fields to configure*/ shortno_links;/* number of links*/ shortno_aliases;/* number of aliases in recList */ short*link_ind; /* addr of array of ind in papFldDes*/ char**papsortFldName;/* ptr to array of ptr to fld names*/ short*sortFldInd; /* addr of array of ind in papFldDes*/ dbFldDes*pvalFldDes;/*pointer dbFldDes for VAL field*/ shortindvalFlddes;/*ind in papFldDes*/ dbFldDes **papFldDes;/* ptr to array of ptr to fldDes*/ /*The following are only available on run time system*/ structrset*prset; intrec_size;/*record size in bytes */ }dbRecordType;

21 dbRecordNode definition typedef struct dbRecordNode { ELLNODEnode; void*precord; char*recordname; ELLLISTinfoList;/*LIST of info nodes*/ intflags; }dbRecordNode;

22 Record (dbCommon) definition typedef struct dbCommon { charname[61]; /* Record Name */ chardesc[41]; /* Descriptor */ charasg[29]; /* Access Security Group */ epicsEnum16scan;/* Scan Mechanism */ epicsEnum16pini;/* Process at iocInit */ epicsInt16 phas;/* Scan Phase */ epicsInt16 evnt;/* Event Number */ epicsInt16tse;/* Time Stamp Event */ DBLINKtsel;/* Time Stamp Link */ epicsEnum16dtyp;/* Device Type */ epicsInt16disv;/* Disable Value */ epicsInt16disa;/* Disable */ DBLINKsdis;/* Scanning Disable */ epicsMutexIdmlok;/* Monitor lock */ ELLLISTmlis;/* Monitor List */ epicsUInt8disp;/* Disable putField */ epicsUInt8proc;/* Force Processing */ epicsEnum16stat;/* Alarm Status */ epicsEnum16sevr;/* Alarm Severity */ epicsEnum16nsta;/* New Alarm Status */ epicsEnum16nsev;/* New Alarm Severity */ epicsEnum16acks;/* Alarm Ack Severity */ epicsEnum16ackt;/* Alarm Ack Transient */ epicsEnum16diss;/* Disable Alarm Sevrty */ epicsUInt8lcnt;/* Lock Count */ epicsUInt8pact;/* Record active */ epicsUInt8putf;/* dbPutField process */ epicsUInt8rpro;/* Reprocess */ struct asgMember *asp; /* Access Security Pvt */ struct putNotify *ppn; /* addr of PUTNOTIFY */ struct putNotifyRecord *ppnr; struct scan_element *spvt; /* Scan Private */ struct rset*rset;/* Address of RSET */ struct dset*dset;/* DSET address */ void*dpvt; /* Device Private */ struct dbRecordType *rdes; /* dbRecordType */ struct lockRecord *lset;/* Lock Set */ epicsEnum16prio;/* Scheduling Priority */ epicsUInt8tpro;/* Trace Processing */ char bkpt;/* Break Point */ epicsUInt8udf;/* Undefined */ epicsTimeStamptime;/* Time */ DBLINKflnk;/* Forward Process Link */ } dbCommon;

23 dbAddr definition Virtually all runtime access to the database is via a dbAddr handle. typedef struct dbAddr { struct dbCommon *precord; /* address of record */ void *pfield; /* address of field */ struct dbFldDes *pfldDes; /* address of fldDes */ long no_elements; /* number of elements */ short field_type; /* type of field */ short field_size; /* size of the field */ short special; /* special processing */ short dbr_field_type; /* request type */ /* DBR_STRING,...,DBR_ENUM,DBR_NOACCESS */ } dbAddr;

24 PROCESS TYPES

25 EPICS and threads A typical C/C++ programmer’s first reaction is that EPICS has lots of threads However, they all have there uses, and once you understand them they are not so confusing. The need arises from the need to have non- blocking processing and strict priorities. It is actually simpler and more efficient than a lot of select() calls.

26 EPICS Threads NamePriority cbHigh71 timerQueue70 scanOnce70 scan0.166 scan0.265 cbMedium64 scan0.564 scan163 scan262 scan561 scan1060 cbLow59 CAC-event51 dbCaLink50 CAS-client20 CAS-event19 CAS-TCP18 CAS-beacon17 CAS-UDP16 errlog10 taskwd10 IOC management: –timerQueue –taskwd –errlog Database processing: –cb* –scan* Channel Access: –CAS-* –CAC-event –dbCaLink Plus various driver threads...

27 IOC management threads timerQueue –Implements all EPICS base delays taskwd –Monitors tasks for any suspensions errlog –Handles asynchronous processing of log messages. –Forwards log messages to the console or to files at low priority.

28 Database processing threads cb* –callback tasks – used for event and I/O Interrupt scanned records. –Calls any specified function asynchronously –3 priorities (low, medium high) scan* –periodic scan tasks –Calls record process() routines at regular intervals. –Higher scan rates have higher priorities. + all driver threads –Every asyn port has its own thread

29 Channel Access threads CAS-* –Channel access server tasks CAS-UDP listens for channel lookups CAS-TCP listens for TCP connections CAS-beacon looks for CA beacons One CAS-client and CAS-event task per client dbCaLink –Channel Access client that processes CA requests on behalf of the database. CAC-event –Handles the CA client callback events (I think)

30 EXAMPLES OF PROCESSING

31 Example sequence diagram IOC function callsIOC tasksClient Task nameC filename C function

32 CA server call processing Every CA client message has a function code defined in caProto.h of the form CA_PROTO_XXXX –E.g.: CA_PROTO_WRITE This will convert into a function in one of the CA jump tables (tcpJumpTable or udpJumpTable). Functions are off the form xxxx_action(mp,pPayload,client) –Parameters are pointers to CA header block Data client structure. –Performs: Net to host byte swapping Access security checks –E.g.: write_action(mp,pPayload,client)

33 CA server call processing xxxx_action often calls a “CA db_access” routine with underscores, which handles an ugly “old to new” type enumeration conversion –E.g.: db_put_field(pAddr, oldDataType,pPayload,count) This calls a dbAccess routine which is part of the database code. –E.g.: dbPutField(pAddr,newDataType,pDate,count) This locks the database and implements the appropriate action.

34 caget from a record

35 Channel life cycle

36 Channel connection CAS-UDP task performs name resolution –When client has resolved name it sends TCP request to nominated server. TCP request is received by CAS-TCP task (function req_server in caservertask.c ) which: –Calls create_tcp_client which: Creates and initialises event queue Creates CAS-event thread to service events on event queue –Creates CAS-client thread to service incoming requests from client i.e. camsgtask in camsgtask.c

37 caput to an ai record

38 dbPutField long epicsShareAPI dbPutField(DBADDR *paddr, short dbrType, const void *pbuffer, long nRequest) { longstatus = 0; dbFldDes*pfldDes = paddr->pfldDes; dbCommon*precord = paddr->precord; shortdbfType = paddr->field_type; /* Various sanity tests deleted here... */ dbScanLock(precord); status = dbPut(paddr, dbrType, pbuffer, nRequest); if (status == 0) { if (paddr->pfield == (void *)&precord->proc || (pfldDes->process_passive && precord->scan == 0 && dbrType < DBR_PUT_ACKT)) { if (precord->pact) { precord->rpro = TRUE; } else { /* indicate that dbPutField called dbProcess */ precord->putf = TRUE; status = dbProcess(precord); } dbScanUnlock(precord); return status; }

39 dbPut dbPut(DBADDR *paddr, short dbrType, const void *pbuffer, long nRequest) { long special = paddr->special; short field_type = paddr->field_type; long no_elements = paddr->no_elements; if (special) dbPutSpecial(paddr, 0); if ( IS AN ARRAY ) prset->get_array_info(paddr, &dummy, &offset); dbPutConvertRoutine[dbrType][field_type](paddr, pbuffer, nRequest, no_elements, offset); if ( IS AN ARRAY ) prset->put_array_info(paddr, nRequest); if (special) dbPutSpecial(paddr,1); if ( not ( VALUE FIELD and PP )) db_post_events(precord, paddr->pfield, DBE_VALUE | DBE_LOG); return; }

40 dbProcess Check for breakpoints. Check the process active flag (PACT). Check the disable link. Check the RSET (record support entry table) exists. Runs the process routine specific to the record type. Check to see if record contents should be automatically printed.

41 camonitor from an ai record

42 caput callback from an ai record

43 What’s the stack trace like? CallLocation clone()libc.so.6 start_thread()libpthread.so.0 start_routine(arg)osdThread.c:320 camsgtask(pParm)camsgtask.c:123 camessage(client)camessage.c:2442 write_action(mp,pPayload,client)camessage.c:810 db_put_field(paddr,src_type,psrc,no_elements)db_access.c:1216 dbPutField(paddr,dbrType,pbuffer,nRequest)dbAccess.c:1257 dbProcess(precord)dbAccess.c:630 process(pao)librecIoc.so writeValue(pao)aoRecord.c:537 write_ao(pao)devAoSoft.c:72 CAS-client thread Socket recv call (caput starts here) Process CA messages caput CA action

44 caput to an ai record CallLocation clone()libc.so.6 start_thread()libpthread.so.0 start_routine(arg)osdThread.c:320 camsgtask(pParm)camsgtask.c:123 camessage(client)camessage.c:2442 write_action(mp,pPayload,client)camessage.c:810 db_put_field(paddr,src_type,psrc,no_elements)db_access.c:1216 dbPutField(paddr,dbrType,pbuffer,nRequest)dbAccess.c:1257 dbProcess(precord)dbAccess.c:630 process(pao)librecIoc.so writeValue(pao)aoRecord.c:537 write_ao(pao)devAoSoft.c:72 CAS-client thread Socket recv call (caput starts here) Process CA messages caput CA action

45 caput callback to an ai record CallLocation clone()libc.so.6 start_thread()libpthread.so.0 start_routine(arg)osdThread.c:282 camsgtask(pParm)camsgtask.c:123 camessage(client)camessage.c:2508 write_notify_action(mp,pPayload,client)camessage.c:1823 dbPutNotify(ppn)dbNotify.c:342 putNotifyCommon(ppn,precord)dbNotify.c:236 dbProcess(precord)dbAccess.c:643 process(precord)aiRecord.c:177 recGblFwdLink(precord)recGbl.c:267 dbNotifyCompletion(precord)dbNotify.c:422 callbackRequest(pcallback)callback.c:154 CAS-client task

46 camonitor from an ai record CallLocation clone()libc.so.6 start_thread()libpthread.so.0 start_routine(arg)osdThread.c:282 periodicTask(arg)dbScan.c:553 scanList(psl)dbScan.c:658 dbProcess(precord)dbAccess.c:643 process(prec)calcRecord.c:126 recGblFwdLink(precord)recGbl.c:265 dbScanFwdLink(plink)dbAccess.c:519 dbScanPassive(pfrom,pto)dbAccess.c:490 dbProcess(precord)dbAccess.c:643 process(precord)aiRecord.c:175 monitor(prec)aiRecord.c:403 db_post_events(pRecord,pField,caEventMask)dbEvent.c:767 db_post_single_event_private(event)dbEvent.c:715 scan1 task

47 Camonitor event CallLocation clone()libc.so.6 start_thread()libpthread.so.0 start_routine(arg)osdThread.c:282 event_task(pParm)dbEvent.c:941 event_read(ev_que)dbEvent.c:865 read_reply(pArg,paddr,eventsRemaining,pfl)camessage.c:627 cas_send_bs_msg(pclient,lock_needed)caserverio.c:63 send()libc.so.6 CAS-event task

48 caget from an ai record CallLocation clone()libc.so.6 start_thread()libpthread.so.0 start_routine(arg)osdThread.c:282 camsgtask(pParm)camsgtask.c:123 camessage(client)camessage.c:2508 read_notify_action(mp,pPayload,client)camessage.c:757 read_reply(pArg,paddr,eventsRemaining,pfl)camessage.c:557 db_get_field(paddr,buffer_type,pbuffer,no_elements,pfl)db_access.c:543 dbGetField(paddr,dbrType,pbuffer,options,nRequest,pflin)dbAccess.c:989 dbGet(paddr,dbrType,pbuffer,options,nRequest,pflin)dbAccess.c:1009 getOptions(paddr,poriginal,options,pflin)dbAccess.c:393 dbFastGetConvertRoutine[field_type][dbrType] (localAddr.pfield, pbuffer, &localAddr) dbAccess.c:1069 CAS-client task

49 The end What did I miss? –IOC initialisation –Database definition –Static database access –dbStatic –Test facilities –Access security –IOC shell –Registry –OSI –libCom –Build rules –Record, device and driver support Basically everything.....

50 Resources EPICS Application Developers Guide Channel Access Protocol Specification –http://epics.cosylab.com/cosyjava/JCA- Common/Documentation/CAproto.htmlhttp://epics.cosylab.com/cosyjava/JCA- Common/Documentation/CAproto.html Training slides on EPICS web site Eclipse is your friend... “module load ddd” gives you the ddd graphical debugger.


Download ppt "EPICS Internals Nick Rees. Outline Introduction Libraries and modules Data Structures Process types Examples of processing."

Similar presentations


Ads by Google