nova-core: add initial support for gpu timer
Subsystems (6)
cover nova-core: add initial support for gpu timer
The GPU has a timer, one of the pieces of information we need to pass into GSP init later is the timer offset.
This series just adds support for setting up the timer on Turing+, with hals for Turing and Hopper.
Right now it calculates the value to send to GSP but the code to send it will be added later.
For some hardware variants sending a proper value is required for GSP init to succeed.
Dave.
---
Dave Airlie (2):
rust/timer: expose as_nanos for clock sources.
gpu: nova-core: add support for GPU timer block.
drivers/gpu/nova-core/gpu.rs | 5 +++ drivers/gpu/nova-core/nova_core.rs | 1 + drivers/gpu/nova-core/regs.rs | 40 +++++++++++++++++++++ drivers/gpu/nova-core/timer.rs | 37 +++++++++++++++++++ drivers/gpu/nova-core/timer/hal.rs | 32 +++++++++++++++++ drivers/gpu/nova-core/timer/hal/gh100.rs | 61 ++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/timer/hal/tu102.rs | 55 ++++++++++++++++++++++++++++ rust/kernel/time.rs | 3 +- 8 files changed, 233 insertions(+), 1 deletion(-)
---
base-commit: 3497a403264b094ebd61b8b755165d56e7d9dc37
change-id: 20261026-drm-rust-next-d81ce0f4ecdf
Best regards,
Signature · 1 line
Dave Airlie <[email protected]>
PATCH 1/2 rust/timer: expose as_nanos for clock sources.
The nouveau C driver does ktime_to_ns(ktime_get()) to program the cpu ns into some hw/fw, so allow this method for rust drivers.
--- rust/kernel/time.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
rust/kernel/time.rs +2 -1
@@ -211,8 +211,9 @@ pub fn elapsed(&self) -> Delta {Self ::now () - *self } +/// Return the raw nanonseconds values from the clock source. #[inline] -pub (crate )fn as_nanos (&self) ->i64 { +pub fn as_nanos (&self) ->i64 { self.inner }
Signature · 1 line
2.56.0
Re: [PATCH 1/2] rust/timer: expose as_nanos for clock sources.
"Dave Airlie via B4 Relay" <[email protected]>
Quoted 6 lines · writes:
From: Dave Airlie <[email protected]>
The nouveau C driver does ktime_to_ns(ktime_get()) to program the cpu ns into some hw/fw, so allow this method for rust drivers.
Signed-off-by Dave Airlie <[email protected]>
Best regards,
Andreas Hindborg
Danilo Krummrich
maintainerRe: [PATCH 1/2] rust/timer: expose as_nanos for clock sources.
In reply to Dave AirlieQuoted 2 lines · On Mon Oct 26, 2026 at 3:56 AM CET, Dave Airlie via B4 Relay wrote:
The nouveau C driver does ktime_to_ns(ktime_get()) to program the cpu ns into some hw/fw, so allow this method for rust drivers.
It's kinda implicit, but I'd rather justify the change through how the HW timer within some NVIDIA GPUs works.
There's also other HW that works similarly (e.g. a bunch of net devices), which share a common abstraction through struct cyclecounter / struct timecounter.
Having similar Rust infrastructure seems reasonable for use-cases as the nova one.
Re: [PATCH 1/2] rust/timer: expose as_nanos for clock sources.
Quoted 5 lines · On Mon, 26 Oct 2026 20:04:05 +0100 "Danilo Krummrich" <[email protected]> wrote:
There's also other HW that works similarly (e.g. a bunch of net devices), which share a common abstraction through struct cyclecounter / struct timecounter.
Having similar Rust infrastructure seems reasonable for use-cases as the nova one.
Agreed. Making Delta and Instant work with a timecounter is reasonable. If there is a driver which needs timecounter abstractions, I'll make the changes, such as splitting the ClockId trait so that Instant can take a clock that has no clockid_t.
Re: [PATCH 1/2] rust/timer: expose as_nanos for clock sources.
In reply to Danilo KrummrichQuoted 5 lines · Danilo Krummrich
Quoted 2 lines · On Mon Oct 26, 2026 at 3:56 AM CET, Dave Airlie via B4 Relay wrote:
The nouveau C driver does ktime_to_ns(ktime_get()) to program the cpu ns into some hw/fw, so allow this method for rust drivers.
Quoted 8 lines
It's kinda implicit, but I'd rather justify the change through how the HW timer within some NVIDIA GPUs works.
There's also other HW that works similarly (e.g. a bunch of net devices), which share a common abstraction through struct cyclecounter / struct timecounter.
Having similar Rust infrastructure seems reasonable for use-cases as the nova one.
Just to clarify what I talked to Danilo about, I've no intention of publishing the nvidia timer hw as a timer for use in the driver or system.
We have to initialise the timer hardware for the GSP init process. Depending on the hw platform we have to read the timer once to do that, but we do not want to provide a time source from this timer at this point in time.
Dave.
Re: [PATCH 1/2] rust/timer: expose as_nanos for clock sources.
In reply to Dave AirlieQuoted 15 lines · On Mon, 26 Oct 2026 12:56:48 +1000 Dave Airlie via B4 Relay…
From: Dave Airlie <[email protected]>
The nouveau C driver does ktime_to_ns(ktime_get()) to program the cpu ns into some hw/fw, so allow this method for rust drivers.
Signed-off-by Dave Airlie <[email protected]>--- rust/kernel/time.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)rust/kernel/time.rs +0
-0
rust/kernel/time.rs pub fn elapsed(&self) -> Delta { · line 214
Quoted 4 lines
rust/kernel/time.rs +1
-0@@ -211,8 +211,9 @@ pub fn elapsed(&self) -> Delta {Self ::now () - *self } +/// Return the raw nanonseconds values from the clock source.
Typo: nanoseconds. How about:
/// Return the number of nanoseconds since the epoch of the clock `C`.
Nit: the subject prefix for this file has been "rust: time:", not "rust/timer:".
With those fixed:
PATCH 2/2 gpu: nova-core: add support for GPU timer block.
In reply to Dave AirlieThis is needed to calculate the system timer offset that is passed to GSP init.
2 HALs exist:
a) tu102 is the gv100 path from open-gpu, the priv level is checked and the cpu time is written to the gpu timer. no offset is used.
b) gh100 is the gh100 path from open-gpu, where the secure system timer is read, the offset is calculated and on everything after GH100 the offset gets written to secure registers, and also sent to GSP.
--- drivers/gpu/nova-core/gpu.rs | 5 +++ drivers/gpu/nova-core/nova_core.rs | 1 + drivers/gpu/nova-core/regs.rs | 40 +++++++++++++++++++++ drivers/gpu/nova-core/timer.rs | 37 +++++++++++++++++++ drivers/gpu/nova-core/timer/hal.rs | 32 +++++++++++++++++ drivers/gpu/nova-core/timer/hal/gh100.rs | 61 ++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/timer/hal/tu102.rs | 55 ++++++++++++++++++++++++++++ 7 files changed, 231 insertions(+)
drivers/gpu/nova-core/gpu.rs +5 -0
@@ -53,6 +53,7 @@ GpuMm, VramAddress, // }, + timer::Timer, vgpu::VgpuManager, // };
@@ -331,6 +332,8 @@ struct GspResources<'gpu> {// TODO: use different resource types for each boot method, and make the relevant Gsp methods // generic against them. fsp: Option<Fsp<'gpu>>, + /// Timer instance - contains offset + timer: Timer,/// vGPU state detected before GSP boot. vgpu: VgpuManager,/// GSP runtime data.
@@ -497,6 +500,8 @@ pub(crate) fn new<'a>( fsp: Fsp::try_new(dev, bar, spec.chipset)?, + timer: Timer::new(bar, spec.chipset)?, + vgpu: VgpuManager::new(pdev, spec.chipset, fsp.as_mut()), gsp <- Gsp::new(pdev, bar),
drivers/gpu/nova-core/nova_core.rs +1 -0
@@ -27,6 +27,7 @@mod sbuffer;#[cfg( CONFIG_NOVA_CORE_SELFTESTS )] mod selftest; +mod timer;mod vbios;mod vgpu;
drivers/gpu/nova-core/regs.rs +40 -0
@@ -419,6 +419,24 @@ pub(crate) fn mem_scrubbing_done(self) -> bool { } } +// PTIMER + +register! { + base:NovaRegisters ; + +pub (crate )NV_PTIMER_TIME_PRIV_LEVEL_MASK (u32 ) @0x00009430 { +4 :4 level0 =>bool ; + } + +pub (crate )NV_PTIMER_TIME_0 (u32 ) @0x00009400 { +31 :5 nsec; + } + +pub (crate )NV_PTIMER_TIME_1 (u32 ) @0x00009410 { +28 :0 nsec; + } +} +// The modules below provide registers that are not identical on all supported chips. They should // only be used in HAL modules.
@@ -520,6 +538,28 @@ pub(crate) mod gh100 { 31:0 fsp_boot_complete; } } + +// PGC6/TIMER +register! { + base:NovaRegisters ; + +pub (crate )NV_PGC6_SCI_SEC_TIMER_TIME_0 (u32 ) @0x00118f54 { +31 :5 nsec; + } + +pub (crate )NV_PGC6_SCI_SEC_TIMER_TIME_1 (u32 ) @0x00118f58 { +28 :0 nsec; + } + +pub (crate )NV_PGC6_SCI_SYS_TIMER_OFFSET_0 (u32 ) @0x00118df4 { +0 :0 update; +31 :5 nsec; + } + +pub (crate )NV_PGC6_SCI_SYS_TIMER_OFFSET_1 (u32 ) @0x00118df8 { +28 :0 nsec; + } + } }pub (crate )mod gb202 {
drivers/gpu/nova-core/timer.rs new file +37 -0
@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +mod hal; + +use kernel::{ + prelude::*, + time::*,// +}; + +use crate ::{ + driver::Bar0 , + gpu::Chipset ,// +}; + +#[pin_data] +pub (crate )struct Timer { + chipset:Chipset , + sys_timer_offset_ns:i64 , +} + +impl Timer { +pub (crate )fn new (bar:Bar0 <'_>, chipset:Chipset ) ->Result <Self > { +Ok (Self { + chipset, + sys_timer_offset_ns: hal::timer_hal (chipset).init (chipset, bar)?, + }) + } + +#[expect(dead_code)] +pub (crate )fn sys_timer_offset_ns (&self) ->i64 { + self.sys_timer_offset_ns + } +} + +pub (crate )fn get_cpu_time_ns () ->i64 { +Instant ::<Monotonic >::now ().as_nanos () +}
drivers/gpu/nova-core/timer/hal.rs new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 + +use kernel::prelude::*; + +use crate ::{ + driver::Bar0 , + gpu::{ +Architecture , +Chipset ,// + }, +}; + +mod gh100; +mod tu102; + +pub (crate )trait TimerHal { +/// return system timer offset ns +fn init (&self, chipset:Chipset , bar:Bar0 <'_>) ->Result <i64 >; + +/// read the timer +#[allow(dead_code)] +fn timer_read (&self, bar:Bar0 <'_>) ->u64 ; +} + +pub (super )fn timer_hal (chipset:Chipset ) -> &'staticdyn TimerHal { +match chipset.arch () { +Architecture ::Turing |Architecture ::Ampere |Architecture ::Ada => tu102::TU102_HAL , +Architecture ::Hopper |Architecture ::BlackwellGB10x |Architecture ::BlackwellGB20x => { + gh100::GH100_HAL + } + } +}
drivers/gpu/nova-core/timer/hal/gh100.rs new file +61 -0
61 lines not on this page · raw message
drivers/gpu/nova-core/timer/hal/tu102.rs new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 2/2] gpu: nova-core: add support for GPU timer block.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] gpu: nova-core: infinite loop on rollover in timer_read() and timer_time() - [High] gpu…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] gpu: nova-core: infinite loop on rollover in timer_read() and timer_time()
- [High] gpu: nova-core: unshifted nsec value in timer_time() causes EOVERFLOW
- [High] gpu: nova-core: wrong value and missing update bit in gh100::timer_time()
- [High] gpu: nova-core: u64 underflow on negative offset in gh100::timer_time() --
commit 5b1f5a3805c6ab01f8b19ff029b873428252d6b5
Author: Dave Airlie <[email protected]>
gpu: nova-core: add support for GPU timer block.
This commit adds GPU timer block support to nova-core with HAL implementations for TU102 and GH100 to initialize the GPU timer or calculate the system timer offset for GSP initialization.
Quoted 6 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +0
-0@@ -0,0 +1,61 @@
[ ... ]
drivers/gpu/nova-core/timer/hal/gh100.rs line 30
Quoted 11 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +11
-0+pub (crate )fn timer_time (bar:Bar0 <'_>, chipset:Chipset , time_ns:u64 ) ->Result <u64 > { +let sec_hi2 = u32::from (bar.read (regs::gh100::NV_PGC6_SCI_SEC_TIMER_TIME_1 )); +let sec_timer_ns:u64 ; +loop { +let sec_lo = u32::from (bar.read (regs::gh100::NV_PGC6_SCI_SEC_TIMER_TIME_0 )); +let sec_hi = u32::from (bar.read (regs::gh100::NV_PGC6_SCI_SEC_TIMER_TIME_1 )); +if sec_hi == sec_hi2 { + sec_timer_ns = u64::from (sec_hi) <<32 | u64::from (sec_lo); +break ; + } + }
[Severity: High]
Can this loop in timer_time() in drivers/gpu/nova-core/timer/hal/gh100.rs spin forever if NV_PGC6_SCI_SEC_TIMER_TIME_0 rolls over?
During Gpu::new() -> Timer::new() -> Gh100::init() -> timer_time(), sec_hi2 is read from NV_PGC6_SCI_SEC_TIMER_TIME_1 once before the loop and is never updated if sec_hi != sec_hi2. If the lower 32-bit register wraps around between the initial read of sec_hi2 and the in-loop read of sec_hi, sec_hi increments while sec_hi2 remains at its old value, causing the loop to never terminate. Should sec_hi2 be made mutable and updated to sec_hi at the end of each iteration?
drivers/gpu/nova-core/timer/hal/gh100.rs line 39
Quoted 9 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +9
-0+ +let sys_timer_offset_ns = time_ns - sec_timer_ns; + +// kfspRequiresBug3957833WAR_HAL +if chipset !=Chipset ::GH100 { + bar.write_reg ( + regs::gh100::NV_PGC6_SCI_SYS_TIMER_OFFSET_1 ::zeroed () + .try_with_nsec ((sys_timer_offset_ns >>32 )as u32 )?, + );
[Severity: High]
What happens in timer_time() in drivers/gpu/nova-core/timer/hal/gh100.rs when time_ns is smaller than sec_timer_ns?
In drivers/gpu/nova-core/timer.rs, get_cpu_time_ns() returns monotonic time since OS boot via Instant::<Monotonic>::now().as_nanos(), whereas sec_timer_ns is read from the always-on PGC6 timer which persists across warm reboots, kexec, and guest VM restarts.
When time_ns < sec_timer_ns, the u64 subtraction time_ns - sec_timer_ns will underflow and panic the kernel when CONFIG_RUST_OVERFLOW_CHECKS=y. Even if wrapping subtraction is used, a negative 64-bit two's-complement offset has its upper bits set to 1, so passing an unmasked (sys_timer_offset_ns >> 32) as u32 to NV_PGC6_SCI_SYS_TIMER_OFFSET_1::zeroed().try_with_nsec() will exceed the 29-bit (28:0 nsec) field and fail with EOVERFLOW.
drivers/gpu/nova-core/timer/hal/gh100.rs line 46
Quoted 7 lines
drivers/gpu/nova-core/timer/hal/gh100.rs new file +7
-0+ bar.write_reg ( + regs::gh100::NV_PGC6_SCI_SYS_TIMER_OFFSET_0 ::zeroed () + .try_with_nsec ((time_ns &0xffffffff )as u32 )?, + ); + } +Ok (sys_timer_offset_ns) +}
[Severity: High]
Are there a few issues with how NV_PGC6_SCI_SYS_TIMER_OFFSET_0 is written here in timer_time() in drivers/gpu/nova-core/timer/hal/gh100.rs?
In drivers/gpu/nova-core/regs.rs, NV_PGC6_SCI_SYS_TIMER_OFFSET_0 is defined as:
pub(crate) NV_PGC6_SCI_SYS_TIMER_OFFSET_0(u32) @ 0x00118df4 {
0:0 update;
31:5 nsec;
}First, this call passes (time_ns & 0xffffffff) as u32 instead of the lower bits of sys_timer_offset_ns, and it does not set the update bit (0:0 update) to trigger hardware latching of the offset.
Second, because nsec is a 27-bit field at bits 31:5, try_with_nsec() checks that the argument fits in 27 bits (< 1 << 27) and then shifts it left by 5. Passing an unshifted 32-bit value causes try_with_nsec() to fail with EOVERFLOW whenever any of bits 31:27 are non-zero, and shifts the value left by an extra 5 bits when bits 31:27 happen to be zero. Should this pass ((sys_timer_offset_ns as u32) >> 5) and set update?
Quoted 6 lines
drivers/gpu/nova-core/timer/hal/tu102.rs new file +0
-0@@ -0,0 +1,55 @@
[ ... ]
drivers/gpu/nova-core/timer/hal/tu102.rs line 27
Quoted 10 lines
drivers/gpu/nova-core/timer/hal/tu102.rs new file +10
-0+pub (crate )fn timer_read (bar:Bar0 <'_>) ->u64 { +let hi2:u32 = u32::from (bar.read (regs::NV_PTIMER_TIME_1 )); +loop { +let lo = u32::from (bar.read (regs::NV_PTIMER_TIME_0 )); +let hi = u32::from (bar.read (regs::NV_PTIMER_TIME_1 )); +if hi == hi2 { +return u64::from (hi) <<32 | u64::from (lo); + } + } +}
[Severity: High]
Similarly, in timer_read() in drivers/gpu/nova-core/timer/hal/tu102.rs, hi2 is read once before the loop and never updated to hi when hi != hi2. If NV_PTIMER_TIME_0 wraps around between the initial read of hi2 and the in-loop read of hi, won't this loop spin forever?
drivers/gpu/nova-core/timer/hal/tu102.rs line 34
Quoted 7 lines
drivers/gpu/nova-core/timer/hal/tu102.rs new file +7
-0+ +pub (crate )fn timer_time (bar:Bar0 <'_>, time_ns:u64 ) ->Result { +if bar.read (regs::NV_PTIMER_TIME_PRIV_LEVEL_MASK ).level0 () { + bar.write_reg (regs::NV_PTIMER_TIME_1 ::zeroed ().try_with_nsec ((time_ns >>32 )as u32 )?); + bar.write_reg ( + regs::NV_PTIMER_TIME_0 ::zeroed ().try_with_nsec ((time_ns &0xffffffff )as u32 )?, + );
[Severity: High]
In timer_time() in drivers/gpu/nova-core/timer/hal/tu102.rs, NV_PTIMER_TIME_0 also defines nsec as a 27-bit field at bits 31:5:
pub(crate) NV_PTIMER_TIME_0(u32) @ 0x00009400 {
31:5 nsec;
}When called during probe via Gpu::new() -> Timer::new() -> Tu102::init() -> timer_time(), won't passing the unshifted (time_ns & 0xffffffff) as u32 to try_with_nsec() return EOVERFLOW whenever bits 31:27 of the low 32-bit timestamp are non-zero, and otherwise shift the value left by an extra 5 bits?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Danilo Krummrich
maintainerRe: [PATCH 2/2] gpu: nova-core: add support for GPU timer block.
In reply to Dave AirlieQuoted 46 lines · On Mon Oct 26, 2026 at 3:56 AM CET, Dave Airlie via B4 Relay wrote:
drivers/gpu/nova-core/regs.rs +31
-0@@ -419,6 +419,24 @@ pub(crate) fn mem_scrubbing_done(self) -> bool { } } +// PTIMER + +register! { + base:NovaRegisters ; + +pub (crate )NV_PTIMER_TIME_PRIV_LEVEL_MASK (u32 ) @0x00009430 { +4 :4 level0 =>bool ; + } + +pub (crate )NV_PTIMER_TIME_0 (u32 ) @0x00009400 { +31 :5 nsec; + } + +pub (crate )NV_PTIMER_TIME_1 (u32 ) @0x00009410 { +28 :0 nsec; + } +} +// The modules below provide registers that are not identical on all supported chips. They should // only be used in HAL modules. @@ -520,6 +538,28 @@ pub(crate) mod gh100 { 31:0 fsp_boot_complete; } } + +// PGC6/TIMER +register! { + base:NovaRegisters ; + +pub (crate )NV_PGC6_SCI_SEC_TIMER_TIME_0 (u32 ) @0x00118f54 { +31 :5 nsec; + } + +pub (crate )NV_PGC6_SCI_SEC_TIMER_TIME_1 (u32 ) @0x00118f58 { +28 :0 nsec; + } +
drivers/gpu/nova-core/regs.rs pub(crate) mod gh100 { · line 563
Quoted 10 lines
drivers/gpu/nova-core/regs.rs +9
-0+ pub(crate) NV_PGC6_SCI_SYS_TIMER_OFFSET_0(u32) @ 0x00118df4 { + 0:0 update; + 31:5 nsec; + } + + pub(crate) NV_PGC6_SCI_SYS_TIMER_OFFSET_1(u32) @ 0x00118df8 { + 28:0 nsec; + } + } }
Timer specific register definitions should go into the timer module.
drivers/gpu/nova-core/regs.rs pub(crate) mod gh100 { · line 564
Quoted 1 line
drivers/gpu/nova-core/regs.rs +1
-0+#[pin_data]
Why is this #[pin_data]?
drivers/gpu/nova-core/regs.rs pub(crate) mod gh100 {
Quoted 2 lines
drivers/gpu/nova-core/regs.rs +2
-0+pub (crate )struct Timer { + chipset:Chipset ,
Why does this carry the Chipset?
drivers/gpu/nova-core/regs.rs
Quoted 2 lines
drivers/gpu/nova-core/regs.rs +2
-0+ sys_timer_offset_ns: i64, +}
More generally, what's the purpose of this struct? What does it represent?
Nothing seems to tie this object to a particular GPU or prevents constructing multiple instances for the same GPU.
It also doesn't seem to provide any access to the underlying HAL's functions?
drivers/gpu/nova-core/regs.rs
Quoted 12 lines
drivers/gpu/nova-core/regs.rs +12
-0+impl Timer { +pub (crate )fn new (bar:Bar0 <'_>, chipset:Chipset ) ->Result <Self > { +Ok (Self { + chipset, + sys_timer_offset_ns: hal::timer_hal (chipset).init (chipset, bar)?, + }) + } + +#[expect(dead_code)] +pub (crate )fn sys_timer_offset_ns (&self) ->i64 { + self.sys_timer_offset_ns + }
What do we need this method for?
drivers/gpu/nova-core/regs.rs
Quoted 5 lines
drivers/gpu/nova-core/regs.rs +5
-0+} + +pub (crate )fn get_cpu_time_ns () ->i64 { +Instant ::<Monotonic >::now ().as_nanos () +}
I don't think this helper adds much value, let's just make users call Instant::<Monotonic>::now().as_nanos() themselves.
Re: [PATCH 2/2] gpu: nova-core: add support for GPU timer block.
Quoted 3 lines
Quoted 1 line
+#[pin_data]
Why is this #[pin_data]?
cut-n-paste fail.
Quoted 5 lines
drivers/gpu/nova-core/timer.rs line 17
Quoted 3 lines
drivers/gpu/nova-core/timer.rs new file +2
-0+pub (crate )struct Timer { + chipset:Chipset ,Why does this carry the Chipset?
indeed don't need it.
Quoted 10 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ sys_timer_offset_ns: i64, +}More generally, what's the purpose of this struct? What does it represent?
Nothing seems to tie this object to a particular GPU or prevents constructing multiple instances for the same GPU.
It also doesn't seem to provide any access to the underlying HAL's functions?
At the moment this object has one job to store the 64-bit value from when we init the timer to give it to GSP. Do we need an object for that, I'm not sure, but handing around a 64-bit value sys_timer_offset_ns seems a bit raw, and there may be some time in the future we need to add more timer stuff.
Quoted 15 lines
drivers/gpu/nova-core/timer.rs line 32
Quoted 13 lines
drivers/gpu/nova-core/timer.rs new file +12
-0+impl Timer { +pub (crate )fn new (bar:Bar0 <'_>, chipset:Chipset ) ->Result <Self > { +Ok (Self { + chipset, + sys_timer_offset_ns: hal::timer_hal (chipset).init (chipset, bar)?, + }) + } + +#[expect(dead_code)] +pub (crate )fn sys_timer_offset_ns (&self) ->i64 { + self.sys_timer_offset_ns + }What do we need this method for?
This just gets the offset value, I've added a comment on where this value needs to end up once more GspInit is done.
Quoted 9 lines
drivers/gpu/nova-core/timer.rs line 37
Quoted 6 lines
drivers/gpu/nova-core/timer.rs new file +5
-0+} + +pub (crate )fn get_cpu_time_ns () ->i64 { +Instant ::<Monotonic >::now ().as_nanos () +}I don't think this helper adds much value, let's just make users call Instant::<Monotonic>::now().as_nanos() themselves.
Done.
Will be sending v2 soon.
Dave.