#2843 closed enhancement (fixed)

Use self-contained objects instead of Classic API for drivers and support libraries

Reported by: Sebastian Huber Owned by: Sebastian Huber
Priority: normal Milestone: 5.1
Component: unspecified Version: 5
Severity: normal Keywords:
Cc: Blocked By:
Blocking:

Description (last modified by Sebastian Huber)

The Classic API has some weaknesses:

  • Dynamic memory (the workspace) is used to allocate object pools. This requires a complex configuration with heavy use of the C pre-processor.
  • Objects are created via function calls which return an object identifier. The object operations use this identifier and map it internally to an object representation.
  • The objects reside in a table, e.g. they are suspect to false sharing of cache lines.
  • The object operations use a rich set of options and attributes. For each object operation these parameters must be evaluated and validated at run-time to figure out what to do exactly for this operation.

The overhead for Classic API mutexes used for example in Termios and the SPI framework is significant, see discussion:

https://lists.rtems.org/pipermail/devel/2016-December/016543.html

There are some API options available:

  1. Use C11 mutexes and condition variables.
  2. Turn the POSIX synchronization objects into self-contained objects and use them.
  3. Use FreeBSD synchronization objects like MUTEX(9) or CONDVAR(9).
  4. Add RTEMS-specific self-contained synchronization objects and use them.

Option 1. and 2. lack support for binary semaphores which are used for task/interrupt synchronization, e.g. Termios.

Option 2. needs run-time evaluation to figure out the actual object variant, e.g. non-recursive, recursive, ceiling, error-checking, robust POSIX mutex.

Option 3. uses hash tables, thus it is not suitable for real-time systems.

Option 1. and 2. lack support for user-defined object names that may help for system diagnostic, tracing and debugging.

Option 4. could be used to avoid all shortcomings of options 1-3. It would be trivial to implement, test and document.

In order to enable user-defined object names one option is to add a const char *name member to Thread_queue_Queue.

Change History (43)

comment:1 Changed on Dec 20, 2016 at 8:15:06 AM by Sebastian Huber

Description: modified (diff)
Summary: Use C11 mutexes instead of Classic API priority inheritance semaphoresUse self-contained objects instead of Classic API for drivers and support libraries

comment:2 Changed on Dec 20, 2016 at 10:23:41 AM by Chris Johns

Can Option 4 be NP extensions to POSIX after Option 2 is done?

comment:3 in reply to:  2 Changed on Dec 20, 2016 at 10:28:54 AM by Sebastian Huber

Replying to chrisj:

Can Option 4 be NP extensions to POSIX after Option 2 is done?

Binary semaphores are not available out of the box with POSIX. You need a mutex and a condition variable for this, e.g. http://stackoverflow.com/questions/7478684/how-to-initialise-a-binary-semaphore-in-c.

Option 4. should be implementable via POSIX to allow to run the software without RTEMS, however, it should use a specialized implementation on RTEMS to minimize run-time and space overheads.

comment:4 Changed on Dec 20, 2016 at 7:34:28 PM by Gedare Bloom

What are the downsides for self-contained objects? (Is there a clear definition of what self-contained objects are?)

comment:5 Changed on Dec 21, 2016 at 6:43:21 AM by Sebastian Huber

Self-contained means the user must provide the storage for the object.

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/libc/sys/rtems/include/sys/lock.h;h=c0549db67cbb559edacbef49584156fb8ac346fd;hb=HEAD

What you cannot do with self-contained objects is using them in a distributed system with distinct address spaces, e.g. a usage case RTEMS was initially designed for. Here you need one level of indirection to identify objects globally.

With object identifiers you can detect a use of deleted objects under certain conditions. You cannot detect use of a deleted and re-used object. To detect/prevent the use of deleted objects in SMP configurations is quite difficult (e.g. hazard pointers) and not implemented in RTEMS.

From my point of view the advantages of self-contained objects are apparent.

comment:6 Changed on May 11, 2017 at 7:31:02 AM by Sebastian Huber

Milestone: 4.124.12.0

comment:7 Changed on May 11, 2017 at 7:42:40 AM by Sebastian Huber

Milestone: 4.12.05.0

comment:8 Changed on Aug 14, 2017 at 12:55:55 AM by Chris Johns

Milestone: 5.04.12.0

Please review and update the milestone. Thanks.

comment:9 Changed on Oct 12, 2017 at 2:23:15 AM by Joel Sherrill

Component: scorebsps
Milestone: 4.12.04.13.0

comment:10 Changed on Nov 9, 2017 at 6:26:20 AM by Sebastian Huber

Milestone: 4.13.05.0

comment:11 Changed on Nov 9, 2017 at 6:26:42 AM by Sebastian Huber

Milestone: 5.06.1

Milestone renamed

comment:12 Changed on Jan 22, 2018 at 9:40:28 AM by Sebastian Huber <sebastian.huber@…>

In 6bc5e47/rtems:

smptests: Fix configuration

Update #2843.

comment:13 Changed on Feb 2, 2018 at 2:21:23 PM by Sebastian Huber <sebastian.huber@…>

In f14a04c6/rtems:

Add RTEMS thread API

Update #2843.

comment:14 Changed on Feb 2, 2018 at 2:21:36 PM by Sebastian Huber <sebastian.huber@…>

In 1b2da177/rtems:

libblock: Use self-contained mutex for disk lock

Update #2843.

comment:15 Changed on Feb 2, 2018 at 2:21:48 PM by Sebastian Huber <sebastian.huber@…>

In 8d7f3680/rtems:

libblock: Use self-contained mutex and cond var

Update #2843.

comment:16 Changed on Feb 2, 2018 at 2:22:11 PM by Sebastian Huber <sebastian.huber@…>

In dc158ad/rtems:

i2c: Use self-contained mutex

Update #2843.

comment:17 Changed on Feb 2, 2018 at 2:22:23 PM by Sebastian Huber <sebastian.huber@…>

In 36304f3/rtems:

spi: Use self-contained mutex

Update #2843.

comment:18 Changed on Feb 2, 2018 at 2:22:35 PM by Sebastian Huber <sebastian.huber@…>

In 16fc3f9a/rtems:

network: Use self-contained recursive mutex

Update #2843.

comment:19 Changed on Feb 2, 2018 at 2:22:47 PM by Sebastian Huber <sebastian.huber@…>

In b17bcb3/rtems:

JFFS2: Use self-contained recursive mutex

Update #2843.

comment:20 Changed on Feb 2, 2018 at 2:22:59 PM by Sebastian Huber <sebastian.huber@…>

In 3b77417/rtems:

dosfs: Use self-contained recursive mutex

Update #2843.

comment:21 Changed on Feb 2, 2018 at 2:23:11 PM by Sebastian Huber <sebastian.huber@…>

In 0940648f/rtems:

RFS: Use self-contained recursive mutex

Update #2843.

comment:22 Changed on Feb 2, 2018 at 2:23:22 PM by Sebastian Huber <sebastian.huber@…>

In 8ddd92d/rtems:

pipe: Use self-contained mutex

Update #2843.

comment:23 Changed on Feb 2, 2018 at 2:23:34 PM by Sebastian Huber <sebastian.huber@…>

In 03e5a780/rtems:

NFS: Use self-contained recursive mutex

Update #2843.

comment:24 Changed on Feb 4, 2018 at 10:31:46 PM by Chris Johns

These changes are fantastic. It is so nice after all this time to see the internal allocation issue being solved in this way. Thank you.

comment:25 Changed on Feb 5, 2018 at 8:47:18 AM by Sebastian Huber <sebastian.huber@…>

In 1472f84/rtems-docs:

c-user: Add self-contained objects chapter

Update #2843.

comment:26 Changed on Feb 5, 2018 at 8:58:31 AM by Sebastian Huber <sebastian.huber@…>

In 53b6484/rtems:

termios: Remove obsolete configuration options

Update #2843.

comment:27 Changed on Feb 5, 2018 at 9:01:16 AM by Sebastian Huber <sebastian.huber@…>

In 0851404/rtems-docs:

c-user: Document obsolete termios config options

Update #2843.

comment:28 Changed on Feb 5, 2018 at 10:39:43 AM by Sebastian Huber <sebastian.huber@…>

In 8b3da13/rtems-libbsd:

termios: Update due to API changes

Update #2843.

comment:29 Changed on Feb 5, 2018 at 11:14:17 AM by Sebastian Huber

Component: bspsunspecified
Milestone: 6.15.1

comment:30 Changed on Feb 7, 2018 at 1:14:31 PM by Sebastian Huber <sebastian.huber@…>

In e16111b/rtems:

NFS: Fix use of self-contained objects

Update #2843.

comment:31 Changed on Feb 8, 2018 at 8:16:35 AM by Sebastian Huber <sebastian.huber@…>

In c8d5bed/rtems:

libblock: Use self-contained mutex for nvdisk

Update #2843.

comment:32 Changed on Feb 8, 2018 at 8:16:50 AM by Sebastian Huber <sebastian.huber@…>

In f9027ccf/rtems:

libblock: Use self-contained mutex for flashdisk

Update #2843.

comment:33 Changed on Feb 8, 2018 at 8:17:02 AM by Sebastian Huber <sebastian.huber@…>

In 868ca746/rtems:

libblock: Use self-contained mutex for sparse disk

Update #2843.

comment:34 Changed on Feb 8, 2018 at 8:17:17 AM by Sebastian Huber <sebastian.huber@…>

In a59a6182/rtems:

libblock: Use self-contained mutex for media

Update #2843.

comment:35 Changed on Feb 8, 2018 at 8:17:32 AM by Sebastian Huber <sebastian.huber@…>

In 0a593c2d/rtems:

ftpd: Use self-contained synchronization objects

Update #2843.

comment:36 Changed on Feb 8, 2018 at 8:17:45 AM by Sebastian Huber <sebastian.huber@…>

In d9800ac/rtems:

libdl: Use self-contained recursive mutex

Update #2843.

comment:37 Changed on Feb 8, 2018 at 8:17:59 AM by Sebastian Huber <sebastian.huber@…>

In 87b7117f/rtems:

libdl: Use self-contained mutex for RAP

Update #2843.

comment:38 Changed on Feb 8, 2018 at 8:18:12 AM by Sebastian Huber <sebastian.huber@…>

In 71a8446/rtems:

libdl: Fix potential overwrite of dest buffer

Update #2843.

comment:39 Changed on Feb 8, 2018 at 8:18:26 AM by Sebastian Huber <sebastian.huber@…>

In 3535439f/rtems:

tftpfs: Use self-contained mutex

Update #2843.

comment:40 Changed on Feb 8, 2018 at 8:18:38 AM by Sebastian Huber <sebastian.huber@…>

In 2aa5b98/rtems:

syslog: Use self-contained recursive mutex

Update #2843.

comment:41 Changed on Feb 8, 2018 at 8:18:51 AM by Sebastian Huber <sebastian.huber@…>

In 2fd31117/rtems:

stdio-redirector: Use self-contained mutex

Update #2843.

comment:42 Changed on Feb 8, 2018 at 8:38:11 AM by Sebastian Huber <sebastian.huber@…>

In 9ace2648/rtems:

fdt: Use self-contained mutex

Update #2843.

comment:43 Changed on Feb 8, 2018 at 8:59:06 AM by Sebastian Huber

Resolution: fixed
Status: newclosed

All cpukit services use now self-contained objects, except:

  • gxx_wrappers.c (legacy, would need GCC patch)
  • ada_intrsupp.c (would need GCC patch)
  • libi2c.c (legacy, I2C drivers should use new framework)
  • sse_test.c (seems to be dead code)
Note: See TracTickets for help on using tickets.