Odin icon indicating copy to clipboard operation
Odin copied to clipboard

NetBSD support

Open andreas-jonsson opened this issue 10 months ago • 10 comments

This is my attempt at an initial port of Odin to NetBSD. It targets NetBSD 10.0 (AMD64) with Clang/LLVM 17 from ~~the pkgsrc wip section~~ pkgsrc. If you don't want to taint your system with ~~WIP~~ libraries you can build LLVM using the mksandbox tool.

The current goal ~~(at the moment) is to have the compiler fully working on NetBSD as well as enough of the standard library to run demo.odin~~ is to have the NetBSD port be on par with the other BSD's.

Right now the compiler seems happy and the demo is running, ~~but there are concurrency issues in the runtime. This needs more investigation. One possible issue could be the thread id, that I do not know how to get a hold of atm and I'm currently investigating the issue. Another culprit could be the futex implementation that is pretty much the same as on Haiku.~~

There is also room for some more cleanup and possible joining or refactoring some code that could be shared with other BSDs. Generally this port follow the patterns outlined by the other BSD's.

andreas-jonsson avatar Apr 16 '24 13:04 andreas-jonsson

I think we are at a pretty good state right now. Would love to get some feedback.

andreas-jonsson avatar Apr 19 '24 10:04 andreas-jonsson

Add the appropriate build tag to core/crypto/rand_bsd.odin.

Yawning avatar Apr 19 '24 21:04 Yawning

Ah sorry, you also need to exclude netbsd in the generic core/crypto/rand_generic.odin. The tests under tests/core will fail to compile unless you do.

Yawning avatar Apr 22 '24 13:04 Yawning

Are you sure netbsd doesn't have native futexes?

laytan avatar Apr 24 '24 19:04 laytan

Are you sure netbsd doesn't have native futexes?

I don't think so. :( I was not able to find any documentation about it at least. Also, was not able to find any headers hinting of it's being supported.

(It could perhaps be called something else on NetBSD? I noticed it was not easy to find on FreeBSD either.)

andreas-jonsson avatar Apr 25 '24 07:04 andreas-jonsson

I think I can rewrite the futex implementation using raw syscalls. Will give it a go.

andreas-jonsson avatar Apr 25 '24 12:04 andreas-jonsson

Native futex support is in. Plz let me know if you have any other feedback.

andreas-jonsson avatar Apr 25 '24 20:04 andreas-jonsson

Native futex support is in. Plz let me know if you have any other feedback.

I looked into this a bit and came across this thread, which is concerning. Though the followup by thorpej seems to indicate that it may be usable in certain cases.

  • https://mail-index.netbsd.org/tech-kern/2023/12/11/msg029334.html
  • https://mail-index.netbsd.org/tech-kern/2023/12/11/msg029335.html

otoh Mesa doesn't use futexes on NetBSD when I peeked at the sourcecode, so I don't know if/how the followup progressed.

https://man.netbsd.org/_lwp_park.2 and co might be the "right" thing to do, but NetBSD appears to be unique among the BSDs here.

Yawning avatar Apr 25 '24 22:04 Yawning

Hm.. yea. That is an interesting read. I hope the NetBSD folks fix it because it is convenient for porting purposes to follow Linux here.

As for the current state of things I have hammered this code quite a bit and I have not found any issues. (That is not to say there is none.) But it could also be that this works well for Odin since the use of the API is quite simplistic, and it could be that most of the issues the Mesa team is experiencing comes from using more "complicated" patterns. Perhaps there use of futexes are not process private for example?

I would prefer keeping the code as is and do wider testing. If we see any problems it is only a few lines of code to switch to the _lwp_park API. Most of the work would just be to read up on the API documentation.

If this work, the codebase also gets cleaner because most code is just shared with Linux. :)

andreas-jonsson avatar Apr 26 '24 07:04 andreas-jonsson

There is now a working CI for Odin on NetBSD in a separate PR here #3482 Result can be seen here: https://github.com/andreas-jonsson/Odin/actions/runs/8925922741/job/24515753510

andreas-jonsson avatar May 02 '24 15:05 andreas-jonsson