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

core/msg: use disable/restoreIRQ #1887

Merged
merged 2 commits into from
Nov 25, 2014

Conversation

LudwigKnuepfer
Copy link
Member

  • needed to change internal msg_send to allow external disabling of interrupts

Disclaimer:
This is not beautiful, but I thought it's better than the status quo and might serve as a starting point for discussion.

@LudwigKnuepfer LudwigKnuepfer added Area: core Area: RIOT kernel. Handle PRs marked with this with care! Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation labels Oct 28, 2014
@LudwigKnuepfer
Copy link
Member Author

@kaspar030 Do you think it's worthwhile to fix the old module now? I assume it might take a while before #1890 gets merged.

@LudwigKnuepfer
Copy link
Member Author

@kaspar030 ping

@Kijewski
Copy link
Contributor

This patch is needed in the meantime! I just stumbled upon the fact that msg_send() activates interrupts without me asking it to do so.

@kaspar030
Copy link
Contributor

Ok, let's get this in. +1 for the concept, looks OK to me, have no time to test at the moment.
I'd prefer a different prefix than "__" as "__msg_send" looks too similar to "_msg_send".

@LudwigKnuepfer
Copy link
Member Author

rebased, comment addressed

@LudwigKnuepfer
Copy link
Member Author

(Now it might be confused with msg_send_int on a bad day, but as this is just a hot fix... anyways - suggest a better name and I'll apply it.)

@Kijewski
Copy link
Contributor

int msg_send(msg_t *m, kernel_pid_t target_pid)
{
    return _msg_send(m, target_pid, true, disableIRQ());
}

int msg_try_send(msg_t *m, kernel_pid_t target_pid)
{
    return _msg_send(m, target_pid, false, disableIRQ());
}

static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned state)
{
    ....
}

@LudwigKnuepfer
Copy link
Member Author

Yes, that would have been the right thing to do from the start =)

@LudwigKnuepfer LudwigKnuepfer added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Nov 12, 2014
tcb_t *me = (tcb_t*) sched_threads[sched_active_pid];
sched_set_status(me, STATUS_REPLY_BLOCKED);
me->wait_data = (void*) reply;

/* msg_send blocks until reply received */

return msg_send(m, target_pid);
return _msg_send(m, target_pid, true, state);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After more thinking, I'm not sure this works as expected.
This will restore IRQ state on reply reception to the state before sending the request.
This will disable IRQ, then switch to other threads. Whatever they do, IRQs are disabled. Imagine a hwtimer_sleep() in the thread receiving the msg_send_received message, that would never return.

I think we have to just protect this function with a pair of disable/restore and then call the old msg_send.
Don't know if it can cause problems if active_thread is REPLY_BLOCKED, though...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that something we want to fix in a separate PR? At least this PR fixes things as it is (and this particular issue is not introduced by it).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the problem, @kaspar030, can you try a different wording, plz?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaspar030 reading _msg_send() you'll notice that every exit/control hand off is prefixed with a restoreIRQ. Did you overlook this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LudwigOrtmann You are right. Sorry. ACK!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

@LudwigKnuepfer
Copy link
Member Author

Squashed.

@LudwigKnuepfer LudwigKnuepfer removed the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Nov 13, 2014
@Kijewski Kijewski added this to the Release NEXT MAJOR milestone Nov 13, 2014
}

static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block)
static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned state)
{
if (inISR()) {
return msg_send_int(m, target_pid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about this return? By calling _msg_send interrupts are disabled (even if we are inside an ISR). But returning here just leaves them disabled...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this error was introduced with the application of #1887 (comment) ... addressed now.

@LudwigKnuepfer LudwigKnuepfer added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Nov 14, 2014

int msg_try_send(msg_t *m, kernel_pid_t target_pid)
{
return _msg_send(m, target_pid, false, disableIRQ());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think msg_try_send() still needs the inISR() test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I just noticed myself.

@LudwigKnuepfer
Copy link
Member Author

@Kijewski @haukepetersen @kaspar030 shall I squash? ACK?

@kaspar030
Copy link
Contributor

ACK after squashing.

* needed to change internal `msg_send` to allow external disabling of interrupts
@LudwigKnuepfer LudwigKnuepfer removed the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Nov 25, 2014
@haukepetersen
Copy link
Contributor

ACK

LudwigKnuepfer added a commit that referenced this pull request Nov 25, 2014
@LudwigKnuepfer LudwigKnuepfer merged commit 8f8714b into RIOT-OS:master Nov 25, 2014
@LudwigKnuepfer LudwigKnuepfer deleted the msg_new_irq_api branch November 25, 2014 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: core Area: RIOT kernel. Handle PRs marked with this with care! Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants