#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 12/20/16 at 08:15:06 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 12/20/16 at 10:23:41 by Chris Johns

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

comment:3 in reply to:  2 Changed on 12/20/16 at 10:28:54 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 12/20/16 at 19:34:28 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 12/21/16 at 06:43:21 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 05/11/17 at 07:31:02 by Sebastian Huber

Milestone: 4.124.12.0

comment:7 Changed on 05/11/17 at 07:42:40 by Sebastian Huber

Milestone: 4.12.05.0

comment:8 Changed on 08/14/17 at 00:55:55 by Chris Johns

Milestone: 5.04.12.0

Please review and update the milestone. Thanks.

comment:9 Changed on 10/12/17 at 02:23:15 by Joel Sherrill

Component: scorebsps
Milestone: 4.12.04.13.0

comment:10 Changed on 11/09/17 at 06:26:20 by Sebastian Huber

Milestone: 4.13.05.0

comment:11 Changed on 11/09/17 at 06:26:42 by Sebastian Huber

Milestone: 5.06.1

Milestone renamed

comment:12 Changed on 01/22/18 at 09:40:28 by Sebastian Huber <sebastian.huber@…>

In 6bc5e47/rtems:

smptests: Fix configuration

Update #2843.

comment:13 Changed on 02/02/18 at 14:21:23 by Sebastian Huber <sebastian.huber@…>

In f14a04c6/rtems:

Add RTEMS thread API

Update #2843.

comment:14 Changed on 02/02/18 at 14:21:36 by Sebastian Huber <sebastian.huber@…>

In 1b2da177/rtems:

libblock: Use self-contained mutex for disk lock

Update #2843.

comment:15 Changed on 02/02/18 at 14:21:48 by Sebastian Huber <sebastian.huber@…>

In 8d7f3680/rtems:

libblock: Use self-contained mutex and cond var

Update #2843.

comment:16 Changed on 02/02/18 at 14:22:11 by Sebastian Huber <sebastian.huber@…>

In dc158ad/rtems:

i2c: Use self-contained mutex

Update #2843.

comment:17 Changed on 02/02/18 at 14:22:23 by Sebastian Huber <sebastian.huber@…>

In 36304f3/rtems:

spi: Use self-contained mutex

Update #2843.

comment:18 Changed on 02/02/18 at 14:22:35 by Sebastian Huber <sebastian.huber@…>

In 16fc3f9a/rtems:

network: Use self-contained recursive mutex

Update #2843.

comment:19 Changed on 02/02/18 at 14:22:47 by Sebastian Huber <sebastian.huber@…>

In b17bcb3/rtems:

JFFS2: Use self-contained recursive mutex

Update #2843.

comment:20 Changed on 02/02/18 at 14:22:59 by Sebastian Huber <sebastian.huber@…>

In 3b77417/rtems:

dosfs: Use self-contained recursive mutex

Update #2843.

comment:21 Changed on 02/02/18 at 14:23:11 by Sebastian Huber <sebastian.huber@…>

In 0940648f/rtems:

RFS: Use self-contained recursive mutex

Update #2843.

comment:22 Changed on 02/02/18 at 14:23:22 by Sebastian Huber <sebastian.huber@…>

In 8ddd92d/rtems:

pipe: Use self-contained mutex

Update #2843.

comment:23 Changed on 02/02/18 at 14:23:34 by Sebastian Huber <sebastian.huber@…>

In 03e5a780/rtems:

NFS: Use self-contained recursive mutex

Update #2843.

comment:24 Changed on 02/04/18 at 22:31:46 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 02/05/18 at 08:47:18 by Sebastian Huber <sebastian.huber@…>

In 1472f84/rtems-docs:

c-user: Add self-contained objects chapter

Update #2843.

comment:26 Changed on 02/05/18 at 08:58:31 by Sebastian Huber <sebastian.huber@…>

In 53b6484/rtems:

termios: Remove obsolete configuration options

Update #2843.

comment:27 Changed on 02/05/18 at 09:01:16 by Sebastian Huber <sebastian.huber@…>

In 0851404/rtems-docs:

c-user: Document obsolete termios config options

Update #2843.

comment:28 Changed on 02/05/18 at 10:39:43 by Sebastian Huber <sebastian.huber@…>

In 8b3da13/rtems-libbsd:

termios: Update due to API changes

Update #2843.

comment:29 Changed on 02/05/18 at 11:14:17 by Sebastian Huber

Component: bspsunspecified
Milestone: 6.15.1

comment:30 Changed on 02/07/18 at 13:14:31 by Sebastian Huber <sebastian.huber@…>

In e16111b/rtems:

NFS: Fix use of self-contained objects

Update #2843.

comment:31 Changed on 02/08/18 at 08:16:35 by Sebastian Huber <sebastian.huber@…>

In c8d5bed/rtems:

libblock: Use self-contained mutex for nvdisk

Update #2843.

comment:32 Changed on 02/08/18 at 08:16:50 by Sebastian Huber <sebastian.huber@…>

In f9027ccf/rtems:

libblock: Use self-contained mutex for flashdisk

Update #2843.

comment:33 Changed on 02/08/18 at 08:17:02 by Sebastian Huber <sebastian.huber@…>

In 868ca746/rtems:

libblock: Use self-contained mutex for sparse disk

Update #2843.

comment:34 Changed on 02/08/18 at 08:17:17 by Sebastian Huber <sebastian.huber@…>

In a59a6182/rtems:

libblock: Use self-contained mutex for media

Update #2843.

comment:35 Changed on 02/08/18 at 08:17:32 by Sebastian Huber <sebastian.huber@…>

In 0a593c2d/rtems:

ftpd: Use self-contained synchronization objects

Update #2843.

comment:36 Changed on 02/08/18 at 08:17:45 by Sebastian Huber <sebastian.huber@…>

In d9800ac/rtems:

libdl: Use self-contained recursive mutex

Update #2843.

comment:37 Changed on 02/08/18 at 08:17:59 by Sebastian Huber <sebastian.huber@…>

In 87b7117f/rtems:

libdl: Use self-contained mutex for RAP

Update #2843.

comment:38 Changed on 02/08/18 at 08:18:12 by Sebastian Huber <sebastian.huber@…>

In 71a8446/rtems:

libdl: Fix potential overwrite of dest buffer

Update #2843.

comment:39 Changed on 02/08/18 at 08:18:26 by Sebastian Huber <sebastian.huber@…>

In 3535439f/rtems:

tftpfs: Use self-contained mutex

Update #2843.

comment:40 Changed on 02/08/18 at 08:18:38 by Sebastian Huber <sebastian.huber@…>

In 2aa5b98/rtems:

syslog: Use self-contained recursive mutex

Update #2843.

comment:41 Changed on 02/08/18 at 08:18:51 by Sebastian Huber <sebastian.huber@…>

In 2fd31117/rtems:

stdio-redirector: Use self-contained mutex

Update #2843.

comment:42 Changed on 02/08/18 at 08:38:11 by Sebastian Huber <sebastian.huber@…>

In 9ace2648/rtems:

fdt: Use self-contained mutex

Update #2843.

comment:43 Changed on 02/08/18 at 08:59:06 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.