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

mbox: provide function to unset initialized mbox #15485

Merged
merged 2 commits into from
Mar 20, 2024

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Nov 20, 2020

Contribution description

Split out of #15484, as suggested in #15484 (comment).

Testing procedure

The following tests should still compile and run successfully:

  • tests/lwip
  • tests/lwip_sock_ip (both with LWIP_IPV4=1 and LWIP_IPV6=1 and their combination)
  • tests/lwip_sock_tcp (both with LWIP_IPV4=1 and LWIP_IPV6=1 and their combination)
  • tests/lwip_sock_udp (both with LWIP_IPV4=1 and LWIP_IPV6=1 and their combination)

Issues/PRs references

Split out of #15484

@miri64 miri64 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: network Area: Networking Area: core Area: RIOT kernel. Handle PRs marked with this with care! Area: pkg Area: External package ports labels Nov 20, 2020
@miri64 miri64 requested a review from kaspar030 as a code owner November 20, 2020 14:10
@@ -185,6 +185,17 @@ static inline size_t mbox_avail(mbox_t *mbox)
return cib_avail(&mbox->cib);
}

/**
* @brief Unset's the mbox, effectively deinitializing and invalidating it.
Copy link
Member Author

Choose a reason for hiding this comment

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

From #15484 (comment)

This leaks a possibly supplied queue. Maybe better call it mbox_release_queue?
The mbox actually works without queue, it'd just be synchronous from that point on.

This is also a bit dangerous, if this is called with messages in the queue, they get lost. If there's a sender that was previously waiting, it would be stuck there until the queue transitions from full to empty again.

The sys_mbox_set_invalid() function is called whenever a netconn (lwIP's sock equivalent) is closed or finished, so this isn't a risk, but maybe that function should be fixed in the way that readers and writers are also released and removed somehow.

Copy link
Contributor

Choose a reason for hiding this comment

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

So I still see issues:

  • as is, this is not thread safe, something could send/rx a message between those two lines. I think mbox breaks if the array is NULL but cib mask not. (this could be mitigated by changing the order, but that seems hacky).
  • any waiters on that mbox would be blocked indefinitely.
    I don't see any nice way around this. even while (mbox_try_ receive(tmp) {} would be racey.

I'm fine adding this function (if needed), but maybe those should be fixed or mentioned?

benpicco
benpicco previously approved these changes Dec 1, 2020
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Please squash, changes are minimal and make sense.

@miri64
Copy link
Member Author

miri64 commented Dec 1, 2020

I squashed, but have you read my own worries in #15485 (comment)?

@miri64 miri64 force-pushed the mbox/enh/mbox-unset branch from cd29ef3 to e22e1df Compare December 1, 2020 18:52
@benpicco
Copy link
Contributor

benpicco commented Dec 1, 2020

Hm it's a strange low-level function, if it's useful there is no harm in adding it.
If you doubt it's usefulness, we shouldn't add it.

Maybe you want something that can take a callback function and iterates over the mbox, calling each element with that function if it's not NULL?

But if it's not currently useful that way, we shouldn't merge a bad API.

@benpicco benpicco dismissed their stale review December 1, 2020 19:04

open for discussion

@miri64
Copy link
Member Author

miri64 commented Dec 1, 2020

It's not really about usefulness, but about exposing such a feature in the first place.

@miri64
Copy link
Member Author

miri64 commented Dec 1, 2020

Useful proper encapsulation is always ;-)

@miri64
Copy link
Member Author

miri64 commented Jan 13, 2021

Ping @kaspar030?

@MrKevinWeiss MrKevinWeiss added this to the Release 2021.07 milestone Jun 22, 2021
@MrKevinWeiss MrKevinWeiss removed this from the Release 2021.07 milestone Jul 15, 2021
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Sep 2, 2021
@stale
Copy link

stale bot commented Apr 16, 2022

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 Apr 16, 2022
@miri64 miri64 removed the State: stale State: The issue / PR has no activity for >185 days label Apr 16, 2022
@stale
Copy link

stale bot commented Nov 2, 2022

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 Nov 2, 2022
@maribu maribu added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 2, 2022
@miri64
Copy link
Member Author

miri64 commented Nov 2, 2022

Ping @kaspar030 the second ;-)

@stale stale bot removed the State: stale State: The issue / PR has no activity for >185 days label Nov 2, 2022
@miri64
Copy link
Member Author

miri64 commented May 30, 2023

@kaspar030 do you have something like this on your radar for the rework?

Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

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

ACK.

@kaspar030
Copy link
Contributor

@kaspar030 do you have something like this on your radar for the rework?

rework postponed ...

@OlegHahm
Copy link
Member

This PR seems mostly ready to go if I'm not mistaken!?

@Teufelchen1 Teufelchen1 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 18, 2024
@Teufelchen1
Copy link
Contributor

@miri64 ping

@miri64
Copy link
Member Author

miri64 commented Mar 19, 2024

@miri64 ping

I agree with @OlegHahm. What do I need to do, to get this in? @kaspar030 approved this, there seems to be no merge conflict, I guess all this needs is a second ACK due to the (inconsequential) core change?

Copy link
Contributor

@Teufelchen1 Teufelchen1 left a comment

Choose a reason for hiding this comment

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

LGTM

@miri64
Copy link
Member Author

miri64 commented Mar 19, 2024

Just to be sure, I ran the testing procedures I provided on native and samr21-xpro (where possible) rebased on top of current master and they are still succeeding.

BOARD=native make -C tests/pkg/lwip -j flash test
for ipv4 in 0 1; do
    for ipv6 in 0 1; do
        for board in native samr21-xpro; do
            for app in lwip_sock_ip lwip_sock_tcp lwip_sock_udp; do
                if [ $ipv4 == 0 ] && [ $ipv6 == 0 ]; then
                    continue
                fi
                BOARD=$board LWIP_IPV4=$ipv4 LWIP_IPV6=$ipv6 make -C tests/pkg/${app} -j flash test
            done
        done
    done
done

@miri64
Copy link
Member Author

miri64 commented Mar 19, 2024

I think I need to rebase here, too, just for the Github Actions to succeeds though :-/

@miri64 miri64 force-pushed the mbox/enh/mbox-unset branch from e22e1df to 6229fda Compare March 19, 2024 12:12
@miri64
Copy link
Member Author

miri64 commented Mar 19, 2024

$ git range-diff upstream/master e22e1df 6229fda
1:  0334583749 = 1:  12194ad9e6 mbox: provide function to unset initialized mbox
2:  e22e1dfecf = 2:  6229fda7bd lwip: use new mbox_unset() function

;-) so no changes to the commits themselves ;-)

@riot-ci
Copy link

riot-ci commented Mar 19, 2024

Murdock results

✔️ PASSED

6229fda lwip: use new mbox_unset() function

Success Failures Total Runtime
10009 0 10009 07m:43s

Artifacts

@Teufelchen1 Teufelchen1 added this pull request to the merge queue Mar 19, 2024
Merged via the queue into RIOT-OS:master with commit 5242533 Mar 20, 2024
25 checks passed
@miri64 miri64 deleted the mbox/enh/mbox-unset branch March 20, 2024 08:36
@MrKevinWeiss MrKevinWeiss added this to the Release 2024.04 milestone Apr 30, 2024
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! Area: network Area: Networking Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR 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.

8 participants