Skip to content

Commit

Permalink
Kernel: Add kernel tick for counting time
Browse files Browse the repository at this point in the history
  • Loading branch information
corigan01 committed Jan 12, 2025
1 parent 74b54e7 commit 4a179be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use mem::{
pmm::Pmm,
};
use serial::{Serial, baud::SerialBaud};
use timer::kernel_ticks;
use util::bytes::HumanBytes;

#[global_allocator]
Expand Down Expand Up @@ -80,5 +81,6 @@ fn main(kbh: &KernelBootHeader) {
logln!("Init PhysMemoryManager");
let _pmm = Pmm::new(kbh.phys_mem_map).unwrap();

logln!("Finished in {}ms", kernel_ticks());
loop {}
}
14 changes: 12 additions & 2 deletions kernel/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

use core::sync::atomic::{AtomicU64, Ordering};

use arch::{
critcal_section,
idt64::InterruptInfo,
Expand All @@ -46,12 +48,20 @@ pub fn init_timer() {
);

// Set the trigger time
logln!("({}Hz)", set_pit_hz(TIMER_HZ));
log!("({}Hz)", set_pit_hz(TIMER_HZ));

// Attach our IRQ
attach_irq_handler(pit_interrupt_handler, 0);
}
logln!("OK");
}

fn pit_interrupt_handler(_args: &InterruptInfo) {}
static KERNEL_TICKS: AtomicU64 = AtomicU64::new(0);

fn pit_interrupt_handler(_args: &InterruptInfo) {
KERNEL_TICKS.fetch_add(1, Ordering::AcqRel);
}

pub fn kernel_ticks() -> u64 {
KERNEL_TICKS.load(Ordering::Relaxed)
}

0 comments on commit 4a179be

Please sign in to comment.