-
Notifications
You must be signed in to change notification settings - Fork 7
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
Update to upstream pthread #27
Conversation
Ugh, this is really unfortunate, especially since the I am glad we will have less to maintain here in favor of the "canonical" upstream implementation, but the loss of some functionality is definitely unfortunate. I think we'd also need to implement stuff like Edit: closed PR by mistake |
If we are sure we're able to set priority and ideal processor after thread creation, it wouldn't hurt as much to just leave to set afterwards, like most I could try to run some tests, but I'm very low on time. |
I can try to do some testing today, and see what all the various functions actually do. My guess is that those functions wouldn't exist if they didn't do something, but it's also possible they are just backports or something from Switch (or they only work in kernelspace and not userspace, require privileged app etc). |
Ok, got some preliminary results based on the test app setting all the thread properties
(I spawned the I found some references indicating that this has probably been stubbed out for a long time in the kernel: So, this leaves us in a tough position. I guess the best way would probably be to ask for some kind of parameter support in the Edit: actually, since switchbrew is As far as the |
Yeah, after some rudimentary tests I got to the same conclusions. Priority can and should be handled by About the processorId: the first thing we should do is try to contact (via an issue or whatever) dkArm. If we manage to change the Regardless, I wasn't able to find the changes to |
I have been looking into that too, the only place I can find existence of it is https://github.com/devkitPro/buildscripts/blob/cd5e224d6a14f7d32712ab10cfc08e0c6a2daea3/dkarm-eabi/patches/newlib-4.3.0.20230120.patch so far, but perhaps the intention is deliver the same patch to https://github.com/devkitPro/newlib/tree/devkitARM eventually (I see an older commit from when they updated to 4.2.0, and the patch to I think probably what we should do is open an issue against https://github.com/devkitPro/newlib, asking what the general status / expectations of pthreads on 3DS/devkitARM are, without asking for anything just yet. Depending on how that goes we can try to figure out the best path forward, but I don't want to rush into asking for features from the devkitPro team especially since we are trying to do some pretty nonstandard / unsupported stuff as far as they are concerned. |
Can I leave the diplomacy to you? You seem pretty experienced on this side of things, lol. |
Haha, sure. I don't know that I'm so experienced, just know they have discouraged people from trying to use unsupported languages etc. in the past. I'll try to write something up in the next few days. |
@ian-h-chamberlain Well, it seems like this issue got where we predicted. I've just noticed that @fincs has officially started supporting the new signature in In their implementation the cpu-id issue got "ignored" (obviously, there isn't much to do about it), and instead they just default to spawning threads on the main core. Those changes also invalidate the need for even more functions which are still present in this PR, so my guess is that this repo as a whole will end up exactly like From one point of view it's great, we need to maintain less code thanks to the advancements in the upstream toolchain, which is exactly what I wanted when I wrote this crate. However, unlike At the end of the day, I can't really complain. Our best bet for now is to just adapt and stabilize our tools as much as possible. I believe we should port what remains of this repo over to |
Maybe I missed a thread, but I don't see much follow-up from our side besides this issue: We can reply again and ask for this feature request to be considered, and/or open an PR ourselves. |
I was thinking about re-discussing the issue in that thread/possible PRs and to generally work on it, but there is some complexity regarding the cross-support with Nintendo Switch code (which doesn't need our changes but would get impacted by them) and the newly added implementations in |
Fwiw, the current impl in libctru is still experimental/unfinished, do not expect it to ship in the near future. As mentioned previously, specifying custom thread priorities/affinity masks is currently not supported. The 3DS's version of the Horizon kernel has some limitations that are not a good match for the pthreads interface, and do not play nice with typical pthread-using code that expects a mainstream Unix-like kernel. For example:
With this said, we are nonetheless open to improving the configurability of standard threading APIs in order to better exploit Horizon's threading system and facilitate compatibility with ported software. Any suggestions or proposals are of course welcome. |
As an update, it looks like an initial implementation has landed in It might be a good time to revive this work — we could probably eliminate even more of this library now that the syscalls are implemented upstream in https://github.com/devkitPro/libctru/blob/master/libctru/source/system/syscalls.c |
Alright, it happened. I will look into the changes once I get a break from university exams. Thanks for the heads up @ian-h-chamberlain. |
After looking into it a bit more, I've chosen not to merge the changes in the current state, since we are able to avoid using If we ever need to use them in the future, we should work on those upstream C definitions to regain compatibility, rather than change stuff here. |
Closes #26
This is an update to base our implementation on top of the upstread
pthread
that has been recently added.Most calls have been either removed (if they were fully re-implemented by
newlib
, like those for Mutexes and Condvars) or have been morphed into "syscalls" (as they call them), which are downstream implementations of the pthread functions.There are a few things to note here:
libc
seems to be already compatible with the changes, so there are no changes we need to do over there.__syscall_thread_create
function CANNOT receive priority or cpu affinity as its parameters, since it doesn't receive apthread_attr_t
as argument (very infuriating)The last part is absolutely horrendous, since it would mean a BIG step back on our progress to "normalize" priority and affinity. However, we can't ignore the massive importance of these new impls, and that probably
libctru
itself will one day support them directly.As such, I made this PR to show you what a "new"
pthread-3ds
may look like, and to discuss its future.I'll start the discussion on 2 questions:
pthread-3ds
and instead use a different solution? (something like a temporary thread local variable which we can set fromctru-rs
and read inpthread-3ds
).I know these solutions are pretty ugly and unstable, but I honestly don't think we can stop the changes made in
newlib
orlibctru
simply because "we are against that". There is progress being made on those fronts and perhaps we should just adapt. However, we should try to PR some changes regarding to “sched_yield” and “thread_create”, because as it stands we just lose functionality.Edit: This PR has been thoroughly tested with
std::thread::spawn
andstd::sync::Mutex
, so I am 100% certain it works. However, it requires the latest dependencies from dkARM and thisctru-sys
.