Commit Graph

123 Commits

Author SHA1 Message Date
Qiu Qichen ad1875e1eb replace printf with DEBUG_PRINT.
If you want to use DEBUG_PRINT,pass a D=1 when compiling libevl
2023-12-10 06:26:55 +00:00
Philippe Gerum 41dc88ab52 lib: add socket interface
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2021-08-21 18:13:57 +02:00
Philippe Gerum edb5af7fb7 include/tube: fix queue remove/add race
A receiver could get a spurious empty tube status, due to
receive_tube() racing with send_tube(). See the added comments into
the code for details about the resolution.

At this chance, guard against load/store tearing on shared pointers.

Pending issue: we still have a potential connectivity issue between
the prep and finish ops when pushing to a tube.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2021-03-01 19:07:10 +01:00
Philippe Gerum 354e0eb91e lib/thread: move evl_detach_self() out of line
Refrain from inlining core services, so that interposing on them via
dynamic linking tricks is made easier.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-12-13 12:33:17 +01:00
Philippe Gerum 04db253a39 lib/thread: hide low-level details from applications
evl_get_current() contains implementation details which are definitely
not part of the API and the way this works should not be exposed.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-12-13 12:29:25 +01:00
Philippe Gerum 6c7838c862 lib/heap: move stats accessors out of line
Refrain from inlining core services, so that interposing on them via
dynamic linking tricks is made easier.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-12-13 12:14:01 +01:00
Philippe Gerum 03baa08b76 lib/clock: move evl_read_clock() out of line
What evl_read_clock() does is non-trivial, enough to call for an out
of line implementation.

In general, refrain from inlining core services, so that interposing
on them via dynamic linking tricks is made easier.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-12-13 12:08:03 +01:00
Philippe Gerum 455b4f176c include/compiler: drop likely/unlikely annotations
We have no more in-tree users of these. Besides, let's assume that the
CPU's branch predictor always has better clues than we might have when
assessing the likeliness of a condition.

Bonus: this clears a recurring source of namespace clashes with C++
frameworks like Boost.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-12-12 19:11:42 +01:00
Philippe Gerum 4be045bb76 include/tube: remove likely branch annotations
In user-space at least, we'd be better off trusting the CPU's branch
predictor, instead of relying on our limited perception when it comes
to determining the likeliness of a condition, or every compiler to do
the right thing with respect to efficient branching.

We only have a couple of likely predictions in-tree on straightforward
conditions from the tube implementation code, which we can remove
safely.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-12-12 19:10:43 +01:00
Philippe Gerum acf10e3a56 benchmarks/latmus: add sirq latency measurement
This mode measures the delay between the moment a synthetic interrupt
is posted from the oob stage and when it is eventually received by its
in-band handler. When measured under significant pressure, this gives
the typical interrupt latency experienced by the in-band kernel due to
local interrupt disabling.

Therefore, this is an in-band only test which measures IRQ latency
experienced by the common kernel infrastructure, _NOT_ by EVL.

Measurement is requested with '-s' option.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-06-01 12:02:17 +02:00
Philippe Gerum c0b54070e5 build: copy tidbits only if install_all is given
Do build them unconditionally though.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-05-04 15:42:36 +02:00
Philippe Gerum 3fef97c67b lib: convert to HM diagnostic messages
Since ABI 23, the core is able to channel T_WOSS, T_WOLI and T_WOSX
error notifications through the offender's observable component if
present.

Convert all SIGDEBUG_xxx cause codes to the new EVL_HMDIAG_xxx naming,
so that we have a single nomenclature for these errors regardless of
whether threads are notified via SIGDEBUG or their observable
component.

The API rev. is bumped to #17 as a result of these changes.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-30 12:11:14 +02:00
Philippe Gerum f27fc99387 lib: introduce the interface to observables
Since ABI 23, the core provides the new observable element, which
enables the observer design pattern. Any EVL thread is in and of
itself an observable which can be monitored for events too.

As a by-product, the poll interface can now be given a user-defined
opaque data when subscribing file descriptors to poll elements, which
the core passes back on return to evl_poll().

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-30 12:11:14 +02:00
Philippe Gerum dbb8d32f08 lib/thread: add services to set/clear thread mode bits
Open-coding oob_ioctl() calls to set/clear mode bits in apps is
unhandy and fairly ugly. Let's provide sanctioned services for these
requests, namely evl_set_thread_mode() and evl_clear_thread_mode()
respectively.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-23 14:30:58 +02:00
Philippe Gerum 207ad9feb3 lib/thread: add unblock and demotion services
Starting with ABI 22, we can ask for the core to unblock a thread from
a wait state, which may include forcing it out of any real-time
scheduling class by demoting it to SCHED_WEAK in the same move.

Export evl_unblock_thread() and evl_demote_thread() as the
corresponding wrappers.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-23 12:52:54 +02:00
Philippe Gerum 55bb9159aa lib/sched: add evl_yield() for manual round-robin
An equivalent of sched_yield().

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-23 12:52:54 +02:00
Philippe Gerum c8b3bb1cca lib/thread: rename evl_attach_self_flags() to evl_attach_thread()
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-21 19:08:05 +02:00
Philippe Gerum 9b42b85ed8 lib: introduce element visibility attribute
Since core ABI 21, users can decide whether a new element should be
made public or private depending on the value of clone flags added to
the new long form of all element creation calls, i.e. evl_create_*().
All evl_new_*() calls become a shorthand for their respective long
form with reasonable default arguments, including private visibility.

As a shorthand, libevl also interprets a slash character leading the
name argument passed to these services as an implicit request for
creating a public element. In other words, this is the same as passing
EVL_CLONE_PUBLIC in the clone flags.

A public element appears as a cdev in the /dev/evl hierarchy, which
means that it is visible to other processes, which may share it. On
the contrary, a private element is only known from the process
creating it, although it does appear in the /sysfs hierarchy
regardless.

e.g.:

efd = evl_attach_self("/visible-thread");

total 0
crw-rw----    1 root     root      248,   1 Apr 17 11:59 clone
crw-rw----    1 root     root      246,   0 Apr 17 11:59 visible-thread

or,

efd = evl_attach_self("private-thread");

total 0
crw-rw----    1 root     root      248,   1 Apr 17 11:59 clone

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-18 20:43:02 +02:00
Philippe Gerum a30208946c lib/sched: rename evl_sched_control() to evl_control_sched()
Given that evl_sched_control() was hardly usable prior to the latest
fixes to the scheduler control code in the core and no feedback ever
happened about such issues, we may assume that such call has no user
yet. Take this opportunity to fix a naming inconsistency in the API.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-17 07:51:44 +02:00
Philippe Gerum d32a11700c include/evl: fix unresolved references to evl_sched_attrs.sched_priority
sched_priority is implemented as a macro by glibc which serves as a
wrapper to the real attribute field in schedparam. Some architectures
may use this trick to hide the actual identifier from the user code,
so make sure to always pull <sched.h> before referencing
sched_priority in uapi/ headers, so that such wrapping also happens
when struct evl_sched_attrs is defined.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-17 07:00:12 +02:00
Philippe Gerum f518a3cab9 all: convert to ABI enabling compat syscall support
These changes fix up the argument passed to the core system calls in
order to abide by the new ABI allowing 32bit applications to issue
requests to 64bit kernels.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-03-28 11:23:55 +01:00
Philippe Gerum 03d260ac62 include/sem: make interface C++ friendly
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-03-26 10:20:16 +01:00
Philippe Gerum fd0c23029c include/event: make interface C++ friendly
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-03-26 10:20:16 +01:00
Philippe Gerum a39c0882f2 include/flags: make interface C++ friendly
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-03-26 10:20:16 +01:00
Philippe Gerum 46868bd894 include/mutex: make interface C++ friendly
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-03-26 10:20:16 +01:00
Philippe Gerum 5a3237e580 include/tube: make interface C++ friendly
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-03-26 10:20:16 +01:00
Philippe Gerum 0de829ffcb lib/sem: fix syntax of static initializer
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-03-26 10:20:16 +01:00
Philippe Gerum 54c8f22839 lib/flags: fix syntax of static initializer
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-03-26 10:20:16 +01:00
Philippe Gerum 8ec81636da lib/sched: constify control parameter
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-03-26 10:20:16 +01:00
Philippe Gerum a9f1e2f678 lib: fix unfortunate misnomer 2020-03-19 12:30:55 +01:00
Philippe Gerum 865d8f62da build: catch obviously wrong UAPI setting 2020-03-19 12:30:55 +01:00
Philippe Gerum a9653c72b4 include: do not export uapi/linux
uapi/evl should not directly depend on uapi/linux from the same kernel
release. The kernel definitions we need in uapi/evl should be limited
to linux/types.h, as available from a current toolchain. Revert the
uapi/linux export introduced by commit #5f68658b8.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-03-19 12:30:55 +01:00
Philippe Gerum 4204f25b5c lib: y2038: convert to timespec64 kernel interface
This set of changes makes libevl y2038-safe by switching to the ABI
revision 19 of the EVL core, which generalizes the use of a 64bit
timespec type. These changes also go a long way preparing for the
upcoming mixed 32/64 ABI support (aka compat mode).

The changes only affect the internal interface between libevl and the
kernel, not the API.  Nevertheless, the API was bumped to revision 10
with the removal of the evl_adjust_clock() service, which neither had
proper specification nor defined use case currently, but would stand
in the way of the sanitization work for y2038. At any rate, any future
service implementing some sort of EVL clock adjustment should
definitely not depend on the legacy struct timex which is
y2038-unsafe.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-03-19 12:30:55 +01:00
Philippe Gerum 1565744da2 lib/init: state ABI requirement explicitly
Instead of matching whatever ABI we might be compiled against like
previously, define the kernel ABI we need as a prerequisite
(EVL_KABI_PREREQ), checking for sanity at build time and runtime.

This prerequisite is matched against the range of ABI revisions the
kernel supports (from EVL_ABI_BASE to EVL_ABI_CURRENT). In the
simplest case, the kernel implements a single ABI with no backward
compatibility mechanism (EVL_ABI_BASE == EVL_ABI_CURRENT).

This addresses two issues:

- the fact that libevl might build against a given set of uapi/ files
  does not actually mean that the corresponding kernel ABI found there
  is fully compatible with what libevl expects. Specifying a
  compatible ABI prereq explicitly addresses this problem.

- we can obtain services from EVL cores supporting multiple ABI
  revisions (i.e. providing backward compat feat).

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-03-19 12:30:45 +01:00
Philippe Gerum 01f1cc273d include/evl: drop leftover declaration 2020-02-26 18:56:20 +01:00
Philippe Gerum 278f8d308f lib/proxy: output calls should return ssize_t for consistency 2020-02-14 19:00:21 +01:00
Philippe Gerum ceea63ef00 include/atomic: add atomic_load() 2020-01-22 11:57:11 +01:00
Philippe Gerum db712cc191 lib: rename evl_udelay() to evl_usleep()
evl_udelay() was an annoying misnomer for people with kernel
development background, as this relates to a busy wait loop, not to a
sleeping call, which evl_udelay() actually was.

Rename this call to evl_usleep(), converging to the glibc signature
for usleep(3) in the same move.
2020-01-21 14:52:21 +01:00
Philippe Gerum 78d1e3dd44 include/tube: simplify canister macro declarators
No need to mention TUBE in canister macro declarators, there is no
other type of canisters in the API but those flowing through tubes
anyway.
2019-12-03 11:56:23 +01:00
Philippe Gerum 3985fd94aa include/tube: fix API inconsistency regarding canister declaration
Just like DECLARE_EVL_TUBE_CANISTER() should be used explicitly for
declaring a new canister type for a local tube, the same should be
done with DECLARE_EVL_TUBE_CANISTER_REL() for a shared tube. Stop
calling the latter implicitly from DECLARE_EVL_TUBE_REL(), to remain
consist with DECLARE_EVL_TUBE() usage.
2019-12-03 11:47:06 +01:00
Philippe Gerum 243ce101a3 include/tube: guard against store tearing/fusing (take #2)
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2019-11-28 18:27:13 +01:00
Philippe Gerum 4f4b3a3955 include/tube: guard against store tearing/fusing
We need concurrent readers to always observe consistent ->next pointer
values. We don't want the compiler to combine updates to it.
2019-11-27 16:55:05 +01:00
Philippe Gerum bcd69eaba5 lib/heap: use 'raw size' to denote the full storage length
The raw size is the length of the memory area which includes both the
user data _and_ the meta-data we need for maintaining the heap.
2019-11-27 10:01:15 +01:00
Philippe Gerum 08592109f8 include: add 'tube' data path
A lighweight, lockless multi-reader/multi-writer FIFO with a
base-offset variant which can work over a memory segment shared
between processes. Scalar data or simple (small!) aggregates are
conveyed though a tube inside canisters which exactly fit their type.
By design, a tube is meant to be a basic, spartan mechanism: it
imposes no usage policy whatsoever on users.

As a result, a tube is strictly non-blocking, it solely detects and
notifies the caller on return about empty input (no message in) and
output contention (no buffer space for output). If required, the
caller can implement blocking states, typically with a pair of EVL
semaphores, e.g. setting up a tube conveying integers which supports
blocking mode:

    DECLARE_EVL_TUBE_CANISTER(canister_type, int); /* defines struct canister_type */
    DECLARE_EVL_TUBE(tube_type, cannister_type) tube;
    struct cannister_type items[1024];

    evl_init_tube(&tube, items, 1024);
    evl_new_sem(&in, ...);
    evl_new_sem_any(&out, CLOCK_MONOTONIC, tube.max_items, ...);

    evl_get_sem(&in, ...);           @      evl_get_sem(&out);
    evl_tube_receive(&tube, ...);    @      evl_tube_send(&tube, ...);
    evl_put_sem(&out);               @      evl_put_sem(&in, ...);
2019-11-19 10:30:13 +01:00
Philippe Gerum 43807a1793 include/compiler: add helpers for offset-based addressing 2019-11-18 16:11:47 +01:00
Philippe Gerum 309948a52e include/atomic: move compiler barrier to the proper header 2019-11-18 12:28:47 +01:00
Philippe Gerum d04d98df91 lib/proxy: fix error code propagation 2019-11-13 12:02:32 +01:00
Philippe Gerum d9f26b70b0 lib, eshi: move version string to evl_version 2019-11-13 10:00:39 +01:00
Philippe Gerum 154e577193 lib, eshi: add evl_get_version()
Returns version information about the running EVL interface including
the API and kernel ABI levels. A negative ABI level denotes the EVL
shim layer (eshi).
2019-11-13 09:25:53 +01:00
Philippe Gerum cba6a9958b lib/proxy: improve self-documentation 2019-11-12 19:04:27 +01:00