1PMAF(3)                    Library Functions Manual                    PMAF(3)
2
3
4

NAME

6       __pmAFsetup,  __pmAFregister,  __pmAFunregister, __pmAFblock, __pmAFun‐
7       block, __pmAFisempty - event queue services for  periodic  asynchronous
8       callbacks
9

C SYNOPSIS

11       #include <pcp/pmapi.h>
12       #include <pcp/impl.h>
13
14       int __pmAFsetup(const struct timeval *start, const struct timeval
15               *delta, void *data, void (*func)(int, void *));
16       int __pmAFregister(const struct timeval *delta, void *data,
17               void (*func)(int, void *));
18       int __pmAFunregister(int afid);
19       void __pmAFblock(void);
20       void __pmAFunblock(void);
21       int __pmAFisempty(void);
22
23       cc ... -lpcp
24

DESCRIPTION

26       The  routines implement an event queue and callback framework that sup‐
27       ports periodic evaluation of a series of events with  varying  frequen‐
28       cies for Performance Co-Pilot (PCP) applications.
29
30       The  pmlogger(1)  application,  the  pmdatrace(1) PMDA and the pmdahot‐
31       proc(1) PMDA are the principal users of these services.
32
33       An event is created by calling __pmAFsetup  or  __pmAFregister  and  on
34       success  the  return  value  is an event number greater than zero.  The
35       event has associated event data identified by the opaque pointer  data.
36       The  event  will occur with frequency delta and each time the event oc‐
37       curs the function func will be called with the  event  number  and  the
38       event data as arguments.
39
40       If  __pmAFsetup  is used then the first event is scheduled for the cur‐
41       rent time plus start, else if __pmAFregister is  used  then  the  first
42       event is scheduled for the current time plus delta.
43
44       func  is called in a SIGALRM signal handler context and so the routines
45       that may be safely called from func are  restricted  to  the  so-called
46       async-signal-safe  set.   In  particular  there must be no Standard I/O
47       calls nor calls to any of the malloc(3) routines to modify the state of
48       the  heap.   Refer  to  the  Pointer  to  a  Function  Section  of  the
49       POSIX.1-2013      document       at       http://pubs.opengroup.org/on
50       linepubs/9699919799/functions/V2_chap02.html for a fuller description.
51
52       The  safest and simplest class of func routines are those that do mini‐
53       mal processing, set some global state and return.  The real work  asso‐
54       ciated  with the event is done subsequently from the application's main
55       loop when the global state change is detected.
56
57       Once the event occurs and the callback has  been  executed,  the  event
58       will be rescheduled for delta into the future, except if all the fields
59       of delta are zero, in which case the event will not be  rescheduled  (a
60       ``one trip'' event).
61
62       Internally, events are processed serially so there is no possibility of
63       nested callbacks or re-entrant callbacks from the event management rou‐
64       tines.
65
66       Given  an  event  number afid, __pmAFunregister will permanently remove
67       the corresponding entry from the event queue.
68
69       To control the event queue processing,  __pmAFblock  and  __pmAFunblock
70       may  be  used  to  explicitly block and unblock the dispatch of events.
71       This is most useful when the caller wishes to set up a number of events
72       via  __pmAFsetup  or __pmAFregister and complete the registration phase
73       before the first event callback occurs.
74
75       A call to __pmAFisempty returns 1 or 0 depending on whether  the  event
76       queue is empty or not.
77

SEE ALSO

79       PMAPI(3)
80

DIAGNOSTICS

82       __pmAFsetup,  __pmAFregister  and  __pmAFunregister  return values less
83       than zero in the case of an error.  These values are PCP  error  codes,
84       and may be used to produce error messages via pmErrStr(3).
85
86       The  routines  support  the  standard  PCP debug tracing, and the value
87       DBG_TRACE_AF (or -D af on the command line) will produce diagnostics on
88       standard error that trace the enqueuing and execution of events.
89

CAVEATS

91       These  routines  rely  on  setitimer(2)  and manipulate the handling of
92       SIGALRM signals, and hence are  probably  ill-suited  for  applications
93       that  require  direct  and  concurrent access to these services and re‐
94       sources.
95
96       If the callback functions are slow, or delayed, it is possible that the
97       event scheduling could fall behind and never catchup.  When this begins
98       to happen, events are silently skipped and rescheduled at the  earliest
99       possible  time in the future according to the fixed schedule defined by
100       the time of the call to __pmAFsetup and the  value  of  the  start  and
101       delta  arguments  (or defined by the time of the call to __pmAFregister
102       and the value of the delta argument).
103
104       In addition, the semantics of the  interval  timer(s)  and  the  global
105       state needed to support these services demand that applications calling
106       these routines must do so from a single thread.   This  restriction  is
107       enforced  at  the  PMAPI(3),  where  routines may return the error code
108       PM_ERR_THREAD if the library detects calls from more than one thread.
109
110
111
112Performance Co-Pilot                  PCP                              PMAF(3)
Impressum