EVT
|
|||
|
|
![]()
EVT implements a simple Event Signaling mechanism for Linux. It provides as simple and fast way to signal processes and threads from other processes and threads. It is designed to replace signals when they are used as a notification tool between processes and threads. EVT is implemented in two parts:
· a driver (IOCTl interface)
· and a user-space shared library
How the signaler task target the signaled task ? The process ID is used when UNIX signals. In a multi-threaded environment, this is not making things simple. For this reason, in EVT we introduced the concept of ‘event channel’:
· the task which want to be signaled create an ‘event channel’, which is identified by a 32-bits unique number;
· the task(s) which want to signal, first locate the ‘event channel’ (by using the 32-bits number), then signal (‘trigger’) an event.
Each event triggering carry a 32-bits number, which is specified at the time of the signaling (trigger action).
The driver take care of queuing the pending event notifications. The maximum number of events that can be queued are specified when the ‘event channel’ is created. Note that it can be set to zero, meaning that the signaling task will be blocked until either the signaled task is ready to read the event, or the timeout expires.
This is a very simple example, with 2 tasks (which could be either a process or a thread):
· the 1st process attach to the event channel number 100 and wait for an event, with a 10 seconds timeout
· the 2nd process locate the event channel (using the number 100), then signal the event to the 1st process.
|
// This is the
‘signaled’ task #include <stdio.h> #include <stdlib.h> #include <assert.h> #include
"evt.h" int main( int argc, char
*argv[] ) { //
Connection to the driver evt_cnx_t
*evtcnx = evt_open( ); //
Create the ‘event channel’ number 100 void
*channel_handle; int
status = evt_create_channel( evtcnx, 100,
50, &channel_handle ); //
Wait up to 10 seconds to be ‘signaled’ int
value; status
= evt_fetch_event( evtcnx, channel_handle, &value,
10000 ); return
value; // Should be 123 } |
// This is the
‘signaler’ task #include <stdio.h> #include <stdlib.h> #include <assert.h> #include
"evt.h" int main( int argc, char
*argv[] ) { //
Connection to the driver evt_cnx_t
*evtcnx = evt_open( ); //
Locate ‘event channel’ number 100 void
*channel_handle; int
status = evt_locate_channel( evtcnx, 100,
&channel_handle ); //
‘Signal’ the owner of the channel number 100 status
= evt_post_event( evtcnx, channel_handle, 123,
0 ); return
0; } |
This software has been designed and tested only for Linux. So far, we have tested it with Linux 2.6.14 on a Pentium Desktop PC and also on an embedded PowerPC board (Freescale LITE5200). It should run without problems on other CPU such as MIPS, ARM and SH4.
Hardware
|
HZ
|
Prioritiy Tasks
|
Timing in Microseconds
|
|||
|
Task Signaled |
Task Signaler |
t1-t0 |
t2-t0 |
t2-t1 |
||
|
Embedded PowerPC |
250 |
2 |
1 |
20 |
12 |
8 |
|
1 |
2 |
4 |
480 |
-476 |
||
|
Pentium Desktop |
|
|
|
|
|
|
|
|
|
|
|
|
||
Hardware
|
HZ
|
Prioritiy Tasks
|
Timing in Microseconds
|
Notes
|
|||
|
Task Signaled |
Task Signaler |
t1-t0 |
t2-t0 |
t2-t1 |
|||
|
Embedded PowerPC |
250 |
2 |
1 |
54 |
32 |
22 |
All 30 signals received |
|
1 |
2 |
56 |
252 |
-196 |
Only the 1st signal is received |
||
|
Pentium Desktop |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
‘signaler’ |
‘signaled’ |
|
t0 = ticks( ) |
evt_fetch_event( ) |
|
evt_post_event( ) |
t2 = ticks( ) |
|
t1 = ticks( ) |
|
· t0 : before the evt_post_event() call
· t1 : after the evt_post_event() call
· t2 : after the evt_fetch_event() call
· All timing measured with CPU real-time registers (Pentium and PowerPC)
· Priorities of tasks set with SCHED_FIFO scheduling.
|
Function |
Type
|
Prototype
|
Description |
|
signaler
and |
evt_cnx_t
*evt_open( void ) |
Connection to the driver |
|
|
signaler
and |
int
evt_close( evt_cnx_t * ) |
Release the connection to
the driver |
|
|
signaled |
int
evt_create_channel( const evt_cnx_t *evtcnx, int id,
int maxnb_evt_pending, void **channel_handle ) |
Create an event channel |
|
|
signaled |
int
evt_delete_channel( const evt_cnx_t *evtcnx,
void *channel_handle ) |
Delete an event channel |
|
|
signaler |
int
evt_channel_locate( const evt_cnx_t*evtcnx, int id, void **channel_handle ) |
Locate an event channel |
|
|
signaler |
int
evt_post_event( const evt_cnx_t *evtcnx, void *channel_handle, int value,
int timeout_msec ) |
Trigger an event channel
(signal an event) |
|
|
signaler |
int
evt_post_events( const evt_cnx_t *evtcnx, int nhandles,
void *channels_handles[], int values[] ) |
Trigger several event
channels (signal multiple events) |
|
|
signaled |
int
evt_fetch_event( const evt_cnx_t *evtcnx, void *channel_handle,
int *value, int timeout_msec ) |
Wait for a single event to
be signaled |
|
|
signaled |
int
evt_fetch_events( const evt_cnx_t *evtcnx, void *channel_handle,
int *nvalues, int values[], int timeout_msec ) |
Wait for all events to be
signaled |
|
|
signaler |
int
evt_create_timer( const evt_cnx_t *evtcnx,
void *channel_handle, int value, int first_shot,
int rep_shot, void **timer_handle ) |
Signal an event using a
timer. |
|
|
signaler |
int
evt_delete_timer( const evt_cnx *evtcnx,
void *timer_handle ) |
Delete a timer. |
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
Please take a look at the GNU Web Pages for a copy of the LGPL license: GNU - LGPL
Still in pre-alpha quality (‘proof of concept’).
Todo:
· heaving testing
· timeout testing (both post and fetch)
· signal handling (wait_event_interruptible)
|
C Sources + Examples |
svn co
https://evts.svn.sourceforge.net/svnroot/evts evts |
|
Anonymous SVN access (current code) |
Browse SVN |
|
|
|
Pages created: |
Pages last
revised: |
![]()
![]()