EVT
Event Signaling for Linux

 

Currently, under
development and test

 

Introduction

Concepts

A simple example

Implementation Notes

Performances

API Functions

Licensing

Status – Version

Download

Introduction

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

Concepts

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.

A simple example

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"
#include "lib_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"
#include "lib_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;

}

Implementation notes

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.

Performances

Event Signalement driver:

 
Hardware
HZ
Prioritiy Tasks
(SCHED_FIFO)
 Timing in Microseconds
(average)

Task Signaled

Task Signaler

t1-t0

t2-t0

t2-t1

Embedded PowerPC
(MPC5200 LITE5200)

250

2

1

20

12

8

1

2

4

480

-476

Pentium Desktop
(2.4 GHz)

 

 

 

 

 

 

 

 

 

 

 

UNIX signals (kill, sigwait):

 
Hardware
HZ
Prioritiy Tasks
(SCHED_FIFO)
 Timing in Microseconds
(average)
Notes

Task Signaled

Task Signaler

t1-t0

t2-t0

t2-t1

Embedded PowerPC
(MPC5200 LITE5200)

250

2

1

54

32

22

All 30 signals received

1

2

56

252

-196

Only the 1st signal is received

Pentium Desktop
(2.4 GHz)

 

 

 

 

 

 

 

 

 

 

 

 

 

Notes:

‘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.

API Functions (libevt.so user-space library)

Function

Type
Prototype

Description

evt_open

signaler and
signaled

evt_cnx_t *evt_open( void )

Connection to the driver

evt_close

signaler and
signaled

int evt_close( evt_cnx_t * )

Release the connection to the driver

evt_create_channel

signaled

int evt_create_channel( const evt_cnx_t *evtcnx, int id, int maxnb_evt_pending, void **channel_handle )

Create an event channel

evt_delete_channel

signaled

int evt_delete_channel( const evt_cnx_t *evtcnx, void *channel_handle )

Delete an event channel

evt_locate_channel

signaler

int evt_channel_locate( const evt_cnx_t*evtcnx, int id,

void **channel_handle )

Locate an event channel

evt_post_event

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)

evt_post_events

signaler

int evt_post_events( const evt_cnx_t *evtcnx,  int nhandles, void *channels_handles[], int values[] )

Trigger several event channels (signal multiple events)

evt_fetch_event

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

evt_fetch_events

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

evt_create_timer

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.

evt_delete_timer

signaler

int evt_delete_timer( const evt_cnx *evtcnx, void *timer_handle )

Delete a timer.

Licensing

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

Status - Version

Still in pre-alpha quality (‘proof of concept’).

Todo:

·        heaving testing

·        timeout testing (both post and fetch)

·        signal handling (wait_event_interruptible)

Download

C Sources + Examples

svn co https://evts.svn.sourceforge.net/svnroot/evts evts

Anonymous SVN access (current code)

Browse SVN

 

Olivier Singla

Pages created:
November 2005

Pages last revised:
September 16th 2007

SourceForge.net Logo