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

all platforms: update Mycelium dependencies #343

Merged
merged 14 commits into from
Dec 27, 2024
Merged

Conversation

hawkw
Copy link
Contributor

@hawkw hawkw commented Oct 13, 2024

This updates our dependencies on Mycelium crates to
hawkw/mycelium@ba56bb4.

This picks up the new maitake timer API, as well as the upstream
change hawkw/mycelium#487 to allow raw access to the IDT in the Mycelium
x86_64 HAL, which we need to do an async UART driver (see #337).

While updating everything to use the new timer API, I also made some
tweaks to our existing timer code, including implementing 32-bit timer
rollover for the D1's TIMER0 (our current timestamp source on that
platform). This was an ancient TODO item since basically forever.

Fixes #337

Copy link
Contributor Author

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

trying to figure out why the timer is wedged on D1

platforms/allwinner-d1/src/lib.rs Show resolved Hide resolved
Comment on lines +14 to +15
self.set_prescaler(TimerPrescaler::P8); // 24M / 8: 3.00M ticks/s
self.set_mode(TimerMode::PERIODIC);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same prescaler and mode configuration we set in the older code, so that's presumably not the problem...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

UPDATE: indeed it was not! #343 (comment)

Copy link
Contributor Author

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

more notes

Comment on lines +29 to +32
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_micros() as u64
Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably we could make this use Instant rather than SystemTime, but we'd need to stuff an initial start time Instant in a global so that this function can get at it. eventually i'd like to redo the Clock API to let you actually put data into the Clock at init...

if let Some(timer) = ptr::NonNull::new(TIMER.load(Ordering::Acquire)) {
unsafe { timer.as_ref() }.advance_ticks(1);
}
IDIOTIC_CLOCK_TICKS.fetch_add(1, Ordering::Relaxed);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

XXX ELIZA THIS SUCKS SO BAD LOL

platforms/pomelo/src/main.rs Outdated Show resolved Hide resolved
@hawkw hawkw force-pushed the eliza/myco-update-2k24 branch from 25bdccb to 5e4ff79 Compare December 27, 2024 18:30
@hawkw
Copy link
Contributor Author

hawkw commented Dec 27, 2024

oh, the D1 timer0 problem is actually something much stupider; it's just that the interval timer mode is counting down from 0xFFFF_FFFF rather than up from 0, and maitake's timer wheel expects timestamps to go up rather than down. So we need to change our timer impl to subtract the current value from 0xFFFF_FFFF. lol.

@hawkw
Copy link
Contributor Author

hawkw commented Dec 27, 2024

oh, the D1 timer0 problem is actually something much stupider; it's just that the interval timer mode is counting down from 0xFFFF_FFFF rather than up from 0, and maitake's timer wheel expects timestamps to go up rather than down. So we need to change our timer impl to subtract the current value from 0xFFFF_FFFF. lol.

also, why did @jamesmunns make the downcounting interval start at u16::MAX rather than u32::MAX? IIUC we have an entire 32 bits of precision...doesn't this just eat half of our timestamp precision? or do i not actually get how the D1 timers work?

idk why james did it that way
This implements an ancient TODO about how we ought to handle 32-bit
timer 0 rollovers. I also abstracted a bunch more of the timer 0
configuration behind the timer module, so the rest of the kernel doesn't
have to know about it.
@hawkw hawkw requested a review from jamesmunns December 27, 2024 19:11
@hawkw hawkw changed the title update Mycelium dependencies all platforms: update Mycelium dependencies Dec 27, 2024
platforms/pomelo/src/main.rs Outdated Show resolved Hide resolved
platforms/allwinner-d1/src/lib.rs Show resolved Hide resolved
Comment on lines +14 to +15
self.set_prescaler(TimerPrescaler::P8); // 24M / 8: 3.00M ticks/s
self.set_mode(TimerMode::PERIODIC);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

UPDATE: indeed it was not! #343 (comment)

@hawkw hawkw added this pull request to the merge queue Dec 27, 2024
Merged via the queue into main with commit 4b26795 Dec 27, 2024
12 checks passed
@hawkw hawkw deleted the eliza/myco-update-2k24 branch December 27, 2024 19:29
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.

mycelium-hal's interrupts trait is stupid
1 participant