Coder Social home page Coder Social logo

librtpi's People

Contributors

bstreiff avatar dvhart avatar gratian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

librtpi's Issues

Adapt pre glibc v2.25 condvar implementation and patch for librtpi

To complete the core purpose of this library, we need to replace the wrapper of the pthread condvar implementation with a patched version of the condvar implementation from before v2.25 of glibc.

The patches to add Priority Inheritance support to the condvar is tracked in the glibc bug 11588 [1]

The implementation should be adapted from this implementation, but can be simplified to only support the defined usages (see README.md).

  1. https://sourceware.org/bugzilla/show_bug.cgi?id=11588

tst-condpi2 hangs

With the current futex syscall implementation, tst-condpi2.c is hanging:

$ sudo ./tst-condpi2
low_tf: locked
high_tf: locked
med_tf: spinning
high_tf: done waiting
med_tf: done spinning
[it doesn't progress past this point]

Current librtpi API breaks down for process shared condvars

The current librtpi API creates a strong association between a user mutex and a conditional variable by passing a pointer to the mutex to pi_cond_init() along with the pointer to the conditional variable to be initialized. The pointer to the associated mutex is stored in the private data for the conditional variable.

This is done because in order to guarantee proper RT behaviour we have to use the FUTEX_WAIT_REQUEUE_PI and FUTEX_CMP_REQUEUE_PI futex ops for waiting and signalling respectively and the user mutex is a parameter for both calls. Storing a pointer to the user mutex at init time prevents the practice of signalling the condition prior to the association of the mutex.

The problem is the current librtpi API breaks down for process shared conditional variables as illustrated by glibc tests: tst-cond4.c, tst-cond6.c, tst-cond12.c, and tst-cond13.c.

For process-shared use cases the user mutex and the condvar are allocated in shared memory. This shared memory is (usually) mapped at different addresses in the different processes that interact with the condvar. As a result the pointer to the mutex stored by the pi_cond_init() call points to a valid address only for the process that calls init. All other processes that interact with the process-shared condvar will cause an invalid memory access when accessing the stored mutex pointer.

A good example of this problem is glibc test tst-cond12.c. In this test a parent process creates a memory mapping for a process shared conditional variable and mutex that is later re-mapped by the child process at a different address and the old mapping is unmapped via munmap(). Because the conditional variable was initialized before the fork() the stored mutex pointer now points to an unmapped address in the child process and it results in a SIGSEGV crash when the mutex is
accessed inside the pi_cond.c code.

A proposed solution would be to change the librtpi API to pass the user mutex for the condvar operations that need it and do away with storing a pointer to the user mutex inside the condvar at init.

The new API would look like this:

int pi_cond_init(pi_cond_t *cond, uint32_t flags)
int pi_cond_destroy(pi_cond_t *cond)
int pi_cond_wait(pi_cond_t *cond, pi_mutex_t *mutex)
int pi_cond_timedwait(pi_cond_t *cond, pi_mutex_t *mutex, const struct timespec *restrict abstime)
int pi_cond_signal(pi_cond_t *cond, pi_mutex_t *mutex)
int pi_cond_broadcast(pi_cond_t *cond, pi_mutex_t *mutex)

I can follow up with patches if we're in agreement this is the correct path forward.

Make an include guard unique

I find that an include guard like “RPTI_H” can be too short for the safe reuse of your header file (when it belongs to an application programming interface).

Testcases

The test cases from the original mailing list do not reproduce the hang case.

The library should include test programs that verify correct functioning.

Makefile doesn't build tst-condpi2-orig

tst-condpi2-orig is the original testcase which demonstrated failure on the previous glibc condvar implementation. We need to add the build steps to Makefile.am. (we'll track if this properly reproduces the original bug in a separate issue).

Project status/plans for official release?

Hi everyone,

we are currently considering the use of librtpi in a part of our software stack and were wondering what the current status of the project is. Are there any issues left to solve? As the upstream glibc bug report is still open, I assume that glibc itself still has not fixed the issue or is planning to address it in the foreseeable future.

In the 2020 ELC talk, @gratian mentioned that there could be an "official" release when remaining issues are merged. Is this still something you consider doing? With an official release, it might also be easier to create packages of librtpi for various distributions as they can refer to a specific version instead of a commit hash. Do you have any plans for packaging the library yourself?

In any case, thanks for building this library already!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.