Realtime kernel causes "Assertion `!counting_period || measure_val <= adjusted_counting_period' failed to hold"
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.7k
- Forks
- 662
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 2
Description
I see this error while synchronizing on a condition variable, after calling sched_setscheduler() with SCHED_FIFO on a kernel with the RT-preempt patch applied. It reproduces on Linux 4.4.53-rt66 and 4.9.15-rt12, while failing to reproduce on Linux 4.13.0.
This seems like the same problem as https://github.com/mozilla/rr/issues/2056, but involving the RT patch. Could it be that the RT patch includes the change which caused that bug? It seems to have been fixed in mainline kernels, but where can I find more information on what exactly that fix entailed?
Here's a minimal test program. Compiling this as gcc -Wall -g3 counter_bug.c -o counter_bug -lpthread -lrt and running it as sudo rr record ./counter_bug will immediately result in the assertion failure. Note the number of detected ticks is roughly the same as the argument to WAIT().
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <stdbool.h>
pthread_mutex_t mut;
pthread_cond_t down_cond;
pthread_cond_t up_cond;
bool flag;
volatile int counter;
#define WAIT(N) for (counter = N; counter > 0; --counter)
void *
up (void *_)
{
pthread_mutex_lock (&mut);
for (;;)
{
while (flag)
pthread_cond_wait (&down_cond, &mut);
flag = true;
pthread_cond_signal (&up_cond);
WAIT (50000);
}
}
void *
down (void *_)
{
pthread_mutex_lock (&mut);
for (;;)
{
while (! flag)
pthread_cond_wait (&up_cond, &mut);
flag = false;
pthread_cond_signal (&down_cond);
WAIT (50000);
}
}
int
main (int argc, char *argv[])
{
pthread_mutexattr_t mattr;
pthread_condattr_t cattr;
pthread_mutexattr_init (&mattr);
pthread_mutex_init (&mut, &mattr);
pthread_condattr_init (&cattr);
pthread_cond_init (&up_cond, &cattr);
pthread_cond_init (&down_cond, &cattr);
struct sched_param param;
param.sched_priority = 10;
if (sched_setscheduler (0, SCHED_FIFO, ¶m) == -1)
{
perror ("error setting scheduler");
return 1;
}
pthread_t sender;
if (pthread_create (&sender, NULL, up, NULL))
{
perror ("error creating sender thread");
return 1;
}
down (NULL);
return 2;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal test program in counter_bug.c and reproduce it using the stated gcc command and sudo rr record ./counter_bug on the listed RT-preempt kernels. Compare the assertion behavior with Linux 4.13.0 and review the related rr issue; done means identifying the kernel or rr change responsible and documenting or correcting the failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cpp, linux
- Domain
- devtools, operating-systems, reverse-engineering
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100