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

Add Haiku OS support #3230

Merged
merged 39 commits into from
Mar 8, 2024
Merged

Add Haiku OS support #3230

merged 39 commits into from
Mar 8, 2024

Conversation

avanspector
Copy link
Contributor

core:sync works although has some FIXMEs
core:fmt works
core:sys/haiku is added

generally in Odin Haiku is considered a Unix-like OS, even though technically it is not true

(core:os additions are quite remarkable in their raw quality, albeit being functional enough. As sys/haiku grows, core:os_haiku improves too though)

Copy link
Contributor

@Skytrias Skytrias left a comment

Choose a reason for hiding this comment

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

small files looking good, does the futex sim have tests or are they implemented the same as something we got already

Copy link
Contributor

@Skytrias Skytrias left a comment

Choose a reason for hiding this comment

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

rest looks fine, good work 👍

}

@(private="file")
B_GENERAL_ERROR_BASE :: min(i32)
Copy link
Member

Choose a reason for hiding this comment

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

I would do -(1<<31) instead here to keep it untyped.

}

_futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expect: u32, duration: time.Duration) -> bool {
// FIXME: Add timeout!
Copy link
Member

Choose a reason for hiding this comment

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

Make sure that you do! This is necessary for the sync primitives

Comment on lines 12 to 14
phys_addr_t :: u64 when ODIN_ARCH == .amd64 || ODIN_ARCH == .arm64 else u32
phys_size_t :: phys_addr_t
generic_addr_t :: u64 when ODIN_ARCH == .amd64 || ODIN_ARCH == .arm64 else u32
Copy link
Member

Choose a reason for hiding this comment

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

Why not uintptr here?

global_module_path_set = true;


// array_free(&path_buf);
Copy link
Member

Choose a reason for hiding this comment

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

Why is this commented out?


void lock() {
while (spinlock.test_and_set(std::memory_order_acquire)) {
; // spin...
Copy link
Member

Choose a reason for hiding this comment

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

At least put a cpu_relax in there of some sort.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is there an alternative for this in the compiler codebase?

Copy link
Member

@gingerBill gingerBill Feb 29, 2024

Choose a reason for hiding this comment

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

intrinsics.cpu_relax() in Odin.

auto head = &waitq->list;
for (auto waiter = head->next; waiter != head; waiter = waiter->next) {
if (waiter->futex == f) {
pthread_kill(waiter->thread, SIGCONT);
Copy link
Member

Choose a reason for hiding this comment

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

Does Haiku not have a distinction between signal and broadcast?

package sync

import "core:c"
import "core:c/libc"
Copy link
Member

Choose a reason for hiding this comment

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

Do not use libc here the atomics. package sync has all of the atomics stuff in it already.

waitq_lock :: proc "contextless" (waitq: ^Wait_Queue) {
// FIXME: Get rid of context here.
context = runtime.default_context()
for libc.atomic_flag_test_and_set_explicit(&waitq.lock, .acquire) {
Copy link
Member

Choose a reason for hiding this comment

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

Use the atomics built into the language.

waitq_unlock :: proc "contextless" (waitq: ^Wait_Queue) {
// FIXME: Get rid of context here.
context = runtime.default_context()
libc.atomic_flag_clear_explicit(&waitq.lock, .release)
Copy link
Member

Choose a reason for hiding this comment

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

Use the atomics built into the language.

@avanspector
Copy link
Contributor Author

avanspector commented Feb 27, 2024

small files looking good, does the futex sim have tests or are they implemented the same as something we got already

futex for Haiku was simulated using libc, implementation taken from here https://tavianator.com/2023/futex.html
im a novice in the whole futexes/multithreading situation, all test was basically running on the OS, negating chances of deadlocking as much as possible (i'll try reaching out to the haiku devs to make the implementation as reliable as possible since this simulation of futexes works fine on Linux)

@gingerBill gingerBill merged commit 53ce945 into odin-lang:master Mar 8, 2024
4 checks passed
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.

4 participants