Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/native: timer interrupt issue #6442

Closed
lebrush opened this issue Jan 20, 2017 · 15 comments
Closed

cpu/native: timer interrupt issue #6442

lebrush opened this issue Jan 20, 2017 · 15 comments
Assignees
Labels
Area: timers Area: timer subsystems Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Comments

@lebrush
Copy link
Member

lebrush commented Jan 20, 2017

AFAIK all interrupts shall cause a thread yield (thread_yield_higher), right?

EDIT 01/02/17:
Timer in native stops "working" if fired too fast sometimes. See #6442 (comment)

@miri64 miri64 added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: timers Area: timer subsystems TimerTaskForce labels Jan 20, 2017
@miri64 miri64 added this to the Release 2017.01 milestone Jan 20, 2017
@OlegHahm
Copy link
Member

@lebrush
Copy link
Member Author

lebrush commented Jan 20, 2017

I observed it while testing the callback of the xtimer_mutex_lock_timeout. Removing the thread_yield_higher call from the _mutex_timeout callback, blocks indefinitely.
I thought it might be because no yielding is done, but I've not enough inside on this implementation. So maybe the issue is somewhere else.

@LudwigKnuepfer
Copy link
Member

Please provide a minimal application that reliably shows the defect.

@lebrush
Copy link
Member Author

lebrush commented Jan 23, 2017

So far I'm using tests/posix_semaphore, keeping/removing the thread_yield_higher in the callback of the timer to trigger this. I can't promise I have time to look further into this for this release.

@lebrush
Copy link
Member Author

lebrush commented Jan 24, 2017

As just mentioned in #6441 I also realized that in native when one xtimer is set and fired I can't any future xtimer does not fire...

EDIT: had a quick look at it. The scheduler brings riot to the idle thread. There pm_set_lowest is called and it never comes back. Commenting out the code in pm_set_lowest (or adding there a thread_yield_higher) doesn't help. It really seems that it doesn't trigger any "interrupt" more after one has occurred.

If it helps, running the test application in #6441 enabling output in periph/timer.c and in native_cpu.c produces the following output: http://pastebin.com/T3xRNMUZ

@PeterKietzmann PeterKietzmann modified the milestones: Release 2017.01, Release 2017.04 Jan 26, 2017
@lebrush
Copy link
Member Author

lebrush commented Feb 1, 2017

@LudwigKnuepfer try the following "snippet" to see what I mean. It's not that the thread doesn't yield but that the timer stops "working" if fired to fast. Main will print dots until thread 1 wakes and prints a newline character.

If you set the line with the /* change this value */ to around 1000 the thing works forever on my laptop (or until the battery runs flat). If you set it to 500 or lower it stops working. Not always at the same moment, so I guess that the SIG Alarm is not caught or maybe too late (?). Didn't dig into it yet.

#include <stdio.h>
#include "thread.h"
#include "mutex.h"
#include "xtimer.h"

static char stack[THREAD_STACKSIZE_MAIN];
static void *second_thread(void *arg)
{
    (void) arg;
    while (1) {
        xtimer_usleep(1000000);
        printf("\n");
    }

    return NULL;
}

int main(void)
{
    xtimer_init();
    thread_create(stack,
                  sizeof(stack),
                  THREAD_PRIORITY_MAIN - 1,
                  THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
                  second_thread,
                  NULL,
                  "second_thread");

    while (1) {
        printf(".");
        xtimer_usleep(500); /* change this value */
    }
}

@lebrush lebrush changed the title cpu/native: timer interrupt does not yield thread cpu/native: timer interrupt issue Feb 1, 2017
@smlng
Copy link
Member

smlng commented Feb 2, 2017

@lebrush: I just tested your snippet on macOS and got an interesting behavior:

  • with xtimer_usleep(500) the application stops working after some time, not printing dots . or newlines
  • with xtimer_usleep(1000) the application runs forever, but after some time it stops printing dots and only newlines from threads get printed.

So for the latter case the main thread seems to stuck or nor context switch is happening. I'll try again with some debug output enabled.

@smlng
Copy link
Member

smlng commented Feb 2, 2017

btw. setting it to 100 also runs forever (very long), but with 500 it stops even with 1000 sometimes. So firing too fast might not be the real/exact issue here?!

@lebrush
Copy link
Member Author

lebrush commented Feb 2, 2017

Thanks for testing! Description changed :-)

@LudwigKnuepfer
Copy link
Member

Terribly sorry, but I have no time to properly investigate right now.
As a general remark: signals/interrupts in POSIX may be lost. I.e. if the next timer fires while signal for the current one is still being processed, there will be no signal for the next timer. This is what I would check for first.

@LudwigKnuepfer
Copy link
Member

Also: thank you for the thorough bug report!

@stale
Copy link

stale bot commented Aug 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 10, 2019
@stale stale bot closed this as completed Sep 10, 2019
@aabadie aabadie reopened this Sep 21, 2019
@stale stale bot removed the State: stale State: The issue / PR has no activity for >185 days label Sep 21, 2019
@MichelRottleuthner
Copy link
Contributor

For reference, may be related to #6052

@miri64 miri64 added this to the Release 2020.07 milestone Jul 1, 2020
@MrKevinWeiss MrKevinWeiss removed this from the Release 2021.07 milestone Jul 15, 2021
@maribu
Copy link
Member

maribu commented May 17, 2023

I'm inclined to just close this one and blame xtimer. Anyone against this?

@kaspar030
Copy link
Contributor

Yeah.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: timers Area: timer subsystems Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

No branches or pull requests