Add isb before timer read

pull/110/head
Andre Richter 3 years ago
parent 8324b1fdac
commit dc9b3c0f38
No known key found for this signature in database
GPG Key ID: 2116C1AB102F615E

@ -175,7 +175,7 @@ diff -uNr 07_uart_chainloader/src/_arch/aarch64/cpu.rs 08_timestamps/src/_arch/a
diff -uNr 07_uart_chainloader/src/_arch/aarch64/time.rs 08_timestamps/src/_arch/aarch64/time.rs
--- 07_uart_chainloader/src/_arch/aarch64/time.rs
+++ 08_timestamps/src/_arch/aarch64/time.rs
@@ -0,0 +1,105 @@
@@ -0,0 +1,118 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) 2018-2021 Andre Richter <andre.o.richter@gmail.com>
@ -191,7 +191,7 @@ diff -uNr 07_uart_chainloader/src/_arch/aarch64/time.rs 08_timestamps/src/_arch/
+
+use crate::{time, warn};
+use core::time::Duration;
+use cortex_a::regs::*;
+use cortex_a::{barrier, regs::*};
+
+//--------------------------------------------------------------------------------------------------
+// Private Definitions
@ -209,6 +209,19 @@ diff -uNr 07_uart_chainloader/src/_arch/aarch64/time.rs 08_timestamps/src/_arch/
+static TIME_MANAGER: GenericTimer = GenericTimer;
+
+//--------------------------------------------------------------------------------------------------
+// Private Code
+//--------------------------------------------------------------------------------------------------
+
+impl GenericTimer {
+ #[inline(always)]
+ fn read_cntpct(&self) -> u64 {
+ // Prevent that the counter is read ahead of time due to out-of-order execution.
+ unsafe { barrier::isb(barrier::SY) };
+ CNTPCT_EL0.get()
+ }
+}
+
+//--------------------------------------------------------------------------------------------------
+// Public Code
+//--------------------------------------------------------------------------------------------------
+
@ -227,8 +240,8 @@ diff -uNr 07_uart_chainloader/src/_arch/aarch64/time.rs 08_timestamps/src/_arch/
+ }
+
+ fn uptime(&self) -> Duration {
+ let current_count: u64 = self.read_cntpct() * NS_PER_S;
+ let frq: u64 = CNTFRQ_EL0.get() as u64;
+ let current_count: u64 = CNTPCT_EL0.get() * NS_PER_S;
+
+ Duration::from_nanos(current_count / frq)
+ }

@ -13,7 +13,7 @@
use crate::{time, warn};
use core::time::Duration;
use cortex_a::regs::*;
use cortex_a::{barrier, regs::*};
//--------------------------------------------------------------------------------------------------
// Private Definitions
@ -30,6 +30,19 @@ struct GenericTimer;
static TIME_MANAGER: GenericTimer = GenericTimer;
//--------------------------------------------------------------------------------------------------
// Private Code
//--------------------------------------------------------------------------------------------------
impl GenericTimer {
#[inline(always)]
fn read_cntpct(&self) -> u64 {
// Prevent that the counter is read ahead of time due to out-of-order execution.
unsafe { barrier::isb(barrier::SY) };
CNTPCT_EL0.get()
}
}
//--------------------------------------------------------------------------------------------------
// Public Code
//--------------------------------------------------------------------------------------------------
@ -49,8 +62,8 @@ impl time::interface::TimeManager for GenericTimer {
}
fn uptime(&self) -> Duration {
let current_count: u64 = self.read_cntpct() * NS_PER_S;
let frq: u64 = CNTFRQ_EL0.get() as u64;
let current_count: u64 = CNTPCT_EL0.get() * NS_PER_S;
Duration::from_nanos(current_count / frq)
}

@ -13,7 +13,7 @@
use crate::{time, warn};
use core::time::Duration;
use cortex_a::regs::*;
use cortex_a::{barrier, regs::*};
//--------------------------------------------------------------------------------------------------
// Private Definitions
@ -30,6 +30,19 @@ struct GenericTimer;
static TIME_MANAGER: GenericTimer = GenericTimer;
//--------------------------------------------------------------------------------------------------
// Private Code
//--------------------------------------------------------------------------------------------------
impl GenericTimer {
#[inline(always)]
fn read_cntpct(&self) -> u64 {
// Prevent that the counter is read ahead of time due to out-of-order execution.
unsafe { barrier::isb(barrier::SY) };
CNTPCT_EL0.get()
}
}
//--------------------------------------------------------------------------------------------------
// Public Code
//--------------------------------------------------------------------------------------------------
@ -49,8 +62,8 @@ impl time::interface::TimeManager for GenericTimer {
}
fn uptime(&self) -> Duration {
let current_count: u64 = self.read_cntpct() * NS_PER_S;
let frq: u64 = CNTFRQ_EL0.get() as u64;
let current_count: u64 = CNTPCT_EL0.get() * NS_PER_S;
Duration::from_nanos(current_count / frq)
}

@ -13,7 +13,7 @@
use crate::{time, warn};
use core::time::Duration;
use cortex_a::regs::*;
use cortex_a::{barrier, regs::*};
//--------------------------------------------------------------------------------------------------
// Private Definitions
@ -30,6 +30,19 @@ struct GenericTimer;
static TIME_MANAGER: GenericTimer = GenericTimer;
//--------------------------------------------------------------------------------------------------
// Private Code
//--------------------------------------------------------------------------------------------------
impl GenericTimer {
#[inline(always)]
fn read_cntpct(&self) -> u64 {
// Prevent that the counter is read ahead of time due to out-of-order execution.
unsafe { barrier::isb(barrier::SY) };
CNTPCT_EL0.get()
}
}
//--------------------------------------------------------------------------------------------------
// Public Code
//--------------------------------------------------------------------------------------------------
@ -49,8 +62,8 @@ impl time::interface::TimeManager for GenericTimer {
}
fn uptime(&self) -> Duration {
let current_count: u64 = self.read_cntpct() * NS_PER_S;
let frq: u64 = CNTFRQ_EL0.get() as u64;
let current_count: u64 = CNTPCT_EL0.get() * NS_PER_S;
Duration::from_nanos(current_count / frq)
}

@ -13,7 +13,7 @@
use crate::{time, warn};
use core::time::Duration;
use cortex_a::regs::*;
use cortex_a::{barrier, regs::*};
//--------------------------------------------------------------------------------------------------
// Private Definitions
@ -30,6 +30,19 @@ struct GenericTimer;
static TIME_MANAGER: GenericTimer = GenericTimer;
//--------------------------------------------------------------------------------------------------
// Private Code
//--------------------------------------------------------------------------------------------------
impl GenericTimer {
#[inline(always)]
fn read_cntpct(&self) -> u64 {
// Prevent that the counter is read ahead of time due to out-of-order execution.
unsafe { barrier::isb(barrier::SY) };
CNTPCT_EL0.get()
}
}
//--------------------------------------------------------------------------------------------------
// Public Code
//--------------------------------------------------------------------------------------------------
@ -49,8 +62,8 @@ impl time::interface::TimeManager for GenericTimer {
}
fn uptime(&self) -> Duration {
let current_count: u64 = self.read_cntpct() * NS_PER_S;
let frq: u64 = CNTFRQ_EL0.get() as u64;
let current_count: u64 = CNTPCT_EL0.get() * NS_PER_S;
Duration::from_nanos(current_count / frq)
}

@ -13,7 +13,7 @@
use crate::{time, warn};
use core::time::Duration;
use cortex_a::regs::*;
use cortex_a::{barrier, regs::*};
//--------------------------------------------------------------------------------------------------
// Private Definitions
@ -30,6 +30,19 @@ struct GenericTimer;
static TIME_MANAGER: GenericTimer = GenericTimer;
//--------------------------------------------------------------------------------------------------
// Private Code
//--------------------------------------------------------------------------------------------------
impl GenericTimer {
#[inline(always)]
fn read_cntpct(&self) -> u64 {
// Prevent that the counter is read ahead of time due to out-of-order execution.
unsafe { barrier::isb(barrier::SY) };
CNTPCT_EL0.get()
}
}
//--------------------------------------------------------------------------------------------------
// Public Code
//--------------------------------------------------------------------------------------------------
@ -49,8 +62,8 @@ impl time::interface::TimeManager for GenericTimer {
}
fn uptime(&self) -> Duration {
let current_count: u64 = self.read_cntpct() * NS_PER_S;
let frq: u64 = CNTFRQ_EL0.get() as u64;
let current_count: u64 = CNTPCT_EL0.get() * NS_PER_S;
Duration::from_nanos(current_count / frq)
}

@ -13,7 +13,7 @@
use crate::{time, warn};
use core::time::Duration;
use cortex_a::regs::*;
use cortex_a::{barrier, regs::*};
//--------------------------------------------------------------------------------------------------
// Private Definitions
@ -30,6 +30,19 @@ struct GenericTimer;
static TIME_MANAGER: GenericTimer = GenericTimer;
//--------------------------------------------------------------------------------------------------
// Private Code
//--------------------------------------------------------------------------------------------------
impl GenericTimer {
#[inline(always)]
fn read_cntpct(&self) -> u64 {
// Prevent that the counter is read ahead of time due to out-of-order execution.
unsafe { barrier::isb(barrier::SY) };
CNTPCT_EL0.get()
}
}
//--------------------------------------------------------------------------------------------------
// Public Code
//--------------------------------------------------------------------------------------------------
@ -49,8 +62,8 @@ impl time::interface::TimeManager for GenericTimer {
}
fn uptime(&self) -> Duration {
let current_count: u64 = self.read_cntpct() * NS_PER_S;
let frq: u64 = CNTFRQ_EL0.get() as u64;
let current_count: u64 = CNTPCT_EL0.get() * NS_PER_S;
Duration::from_nanos(current_count / frq)
}

@ -13,7 +13,7 @@
use crate::{time, warn};
use core::time::Duration;
use cortex_a::regs::*;
use cortex_a::{barrier, regs::*};
//--------------------------------------------------------------------------------------------------
// Private Definitions
@ -30,6 +30,19 @@ struct GenericTimer;
static TIME_MANAGER: GenericTimer = GenericTimer;
//--------------------------------------------------------------------------------------------------
// Private Code
//--------------------------------------------------------------------------------------------------
impl GenericTimer {
#[inline(always)]
fn read_cntpct(&self) -> u64 {
// Prevent that the counter is read ahead of time due to out-of-order execution.
unsafe { barrier::isb(barrier::SY) };
CNTPCT_EL0.get()
}
}
//--------------------------------------------------------------------------------------------------
// Public Code
//--------------------------------------------------------------------------------------------------
@ -49,8 +62,8 @@ impl time::interface::TimeManager for GenericTimer {
}
fn uptime(&self) -> Duration {
let current_count: u64 = self.read_cntpct() * NS_PER_S;
let frq: u64 = CNTFRQ_EL0.get() as u64;
let current_count: u64 = CNTPCT_EL0.get() * NS_PER_S;
Duration::from_nanos(current_count / frq)
}

@ -13,7 +13,7 @@
use crate::{time, warn};
use core::time::Duration;
use cortex_a::regs::*;
use cortex_a::{barrier, regs::*};
//--------------------------------------------------------------------------------------------------
// Private Definitions
@ -30,6 +30,19 @@ struct GenericTimer;
static TIME_MANAGER: GenericTimer = GenericTimer;
//--------------------------------------------------------------------------------------------------
// Private Code
//--------------------------------------------------------------------------------------------------
impl GenericTimer {
#[inline(always)]
fn read_cntpct(&self) -> u64 {
// Prevent that the counter is read ahead of time due to out-of-order execution.
unsafe { barrier::isb(barrier::SY) };
CNTPCT_EL0.get()
}
}
//--------------------------------------------------------------------------------------------------
// Public Code
//--------------------------------------------------------------------------------------------------
@ -49,8 +62,8 @@ impl time::interface::TimeManager for GenericTimer {
}
fn uptime(&self) -> Duration {
let current_count: u64 = self.read_cntpct() * NS_PER_S;
let frq: u64 = CNTFRQ_EL0.get() as u64;
let current_count: u64 = CNTPCT_EL0.get() * NS_PER_S;
Duration::from_nanos(current_count / frq)
}

Binary file not shown.

Binary file not shown.

@ -13,7 +13,7 @@
use crate::{time, warn};
use core::time::Duration;
use cortex_a::regs::*;
use cortex_a::{barrier, regs::*};
//--------------------------------------------------------------------------------------------------
// Private Definitions
@ -30,6 +30,19 @@ struct GenericTimer;
static TIME_MANAGER: GenericTimer = GenericTimer;
//--------------------------------------------------------------------------------------------------
// Private Code
//--------------------------------------------------------------------------------------------------
impl GenericTimer {
#[inline(always)]
fn read_cntpct(&self) -> u64 {
// Prevent that the counter is read ahead of time due to out-of-order execution.
unsafe { barrier::isb(barrier::SY) };
CNTPCT_EL0.get()
}
}
//--------------------------------------------------------------------------------------------------
// Public Code
//--------------------------------------------------------------------------------------------------
@ -49,8 +62,8 @@ impl time::interface::TimeManager for GenericTimer {
}
fn uptime(&self) -> Duration {
let current_count: u64 = self.read_cntpct() * NS_PER_S;
let frq: u64 = CNTFRQ_EL0.get() as u64;
let current_count: u64 = CNTPCT_EL0.get() * NS_PER_S;
Duration::from_nanos(current_count / frq)
}

Loading…
Cancel
Save