Skip to content

Let the socket server run in user-mode threads - #89

Open
amitchone wants to merge 11 commits into
userspace-6-can-fixes-and-load-testsfrom
userspace-7-socket-server-user-mode
Open

amitchone wants to merge 11 commits into
userspace-6-can-fixes-and-load-testsfrom
userspace-7-socket-server-user-mode

Conversation

@amitchone

Copy link
Copy Markdown
Collaborator

No description provided.

@amitchone
amitchone changed the base branch from main to userspace-6-can-fixes-and-load-tests December 2, 2026 16:55

@garethpotter garethpotter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Mostly wading through the excessively florid (and so not very helpful) comments. I think I need to review a prior PR to make more sense of this one as it is diffing against something I haven't seen yet.

Comment on lines +24 to +25
* - A transport has to be made in supervisor mode: it asks the network stack for the
* address of its interface, which a user thread may not.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If this is a blocker at any point, perhaps it can be passed in instead.

Comment on lines +51 to +53
*
* It does nothing else: no thread is started, and no memory is made accessible.
*

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Redundant.

Comment on lines +54 to +55
* To be called in supervisor mode, for a thread that exists and has yet to make its
* first call to the transport: typically one that was created not to start by itself

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"This function should be called in supervisor mode with a thread that exists..."

* (a delay of K_FOREVER), and is started after this call. A thread defined with
* K_THREAD_DEFINE does not exist until the kernel has run the initialisation functions
* of the application, so main() is the earliest place for the call. What is given ends
* with the thread: for a thread that is started anew, call it anew.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We are not writing poetry here.

Comment on lines +61 to +65
* The resource pool is small, and sized for the transports alone. A thread that has
* been assigned a pool already keeps it, and the threads of the transport use that one:
* it then needs room for a copy of what they wait on at all times, eight bytes for each
* of the clients that a server takes at once and eight more for each of the two other
* threads.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I have no idea what the second sentence here means.

Comment thread src/zephyr/kernel_objects.c Outdated
* IP transport on sockets, with poll(). For a user thread the kernel works on a copy of
* what is waited on, which it takes from the resource pool of the thread for as long as
* the call lasts. This is that pool. It has room for one such call by each of the
* threads, which is all that is ever asked of it: none of them makes a second call

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

...again with the overly dramatic phrasing: "all I ever ask of thee is that my request for a kernel object might be granted, that I may poll it in perpetuity like an unrequited lover pines for his heart's desire...".

Comment thread src/zephyr/kernel_objects.c Outdated
#ifdef CONFIG_USERSPACE
#include <zephyr/internal/syscall_handler.h>

/* A copy of so many bytes, the reference to the pool that the kernel keeps with it, and

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So many bytes, bytes innumerable...

Comment thread src/zephyr/kernel_objects.c Outdated
Comment on lines +46 to +48
* works on a copy of the sockets that are waited on. It does the same with the value of
* an option that is set on a socket, which is an integer when a server is told to
* listen. */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't quite understand this last sentence.

#endif

/* What the heap needs for itself, with a little to spare */
#define RESOURCE_HEAP_OVERHEAD 96

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How is this calculated?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice to have tests for this.

@amitchone
amitchone force-pushed the userspace-7-socket-server-user-mode branch from ca9546d to 0ad8440 Compare December 3, 2026 10:05
@amitchone
amitchone force-pushed the userspace-7-socket-server-user-mode branch 2 times, most recently from da5a6cd to af0752e Compare December 3, 2026 11:47
@amitchone
amitchone force-pushed the userspace-7-socket-server-user-mode branch from af0752e to 6efd300 Compare December 3, 2026 12:04
@amitchone
amitchone added this pull request to stack #93 December 3, 2026 12:39
@amitchone
amitchone force-pushed the userspace-7-socket-server-user-mode branch from 6efd300 to bd9e716 Compare December 3, 2026 16:06
@amitchone
amitchone force-pushed the userspace-7-socket-server-user-mode branch from bd9e716 to baaa069 Compare December 3, 2026 17:33
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