Skip to content

Conversation

@Koichi98
Copy link
Contributor

@Koichi98 Koichi98 commented Jan 8, 2025

Description

This PR is one of a series of PRs that consolidates #252. This PR implements socket-level locking.

A straightforward approach would be to wrap both meta and socket defined here with Mutex. However, this would make it difficult to return pre-lock objects in SocketSet methods like get() and iter() defined in the same file. Therefore, wrapping each member variable in these structures (meta, socket ) with locks and modifying the rest of the code to accommodate this structure.

Related links

PR #252

How was this PR tested?

In applications/tests/test_network, verified:

  • Successfully ran scripts/udp.py for udp_test
  • Successfully received 'Hello Awkernel!' using nc command for tcp_connect_test
  • Successfully received HTTP response after sending data with nc command for tcp_listen_test

Notes for reviewers

  • When wrapping UDP, TCP, and other sockets with mutex, we needed to specify the Send trait as a trait bound for the AnySocket trait that these sockets implement. Are there any potential issues or drawbacks to consider with this approach? (smoltcp/src/socket/mod.rs L118)
  • I have made efforts to avoid acquiring multiple locks simultaneously to prevent deadlocks, but would like reviewers to double-check.
  • In situations where we need a write lock only for certain code paths within an RwLock, the read lock is released first before acquiring the write lock.
    I would appreciate any feedback on these implementation decisions.

Koichi98 and others added 12 commits January 3, 2025 09:23
Signed-off-by: koichiimai <kotty.0704@gmail.com>
Signed-off-by: koichiimai <kotty.0704@gmail.com>
Signed-off-by: koichiimai <kotty.0704@gmail.com>
Signed-off-by: koichiimai <kotty.0704@gmail.com>
Signed-off-by: koichiimai <kotty.0704@gmail.com>
Signed-off-by: Koichi Imai <koichi.imai.2@tier4.jp>
Signed-off-by: Koichi Imai <koichi.imai.2@tier4.jp>
Signed-off-by: Koichi Imai <koichi.imai.2@tier4.jp>
Signed-off-by: Koichi Imai <koichi.imai.2@tier4.jp>
Signed-off-by: koichiimai <kotty.0704@gmail.com>
Signed-off-by: koichiimai <kotty.0704@gmail.com>
@Koichi98 Koichi98 marked this pull request as ready for review January 9, 2025 04:25
@Koichi98 Koichi98 requested a review from ytakano January 9, 2025 05:43
@ytakano ytakano merged commit 4b374f6 into main Jan 9, 2025
1 check passed
@Koichi98 Koichi98 deleted the fine_grained_lock_in_smoltcp branch February 3, 2025 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants