OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 5:14 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: How can I arrange a delay in your code the kernel in C++?
PostPosted: Wed Jul 24, 2019 10:17 am 
Offline
Member
Member
User avatar

Joined: Sun Jul 21, 2019 7:34 am
Posts: 300
Hi.
At first I thought I could do it with std::chrono, but then I realized that the functions of std::chrono depend on the system clock. And now I can't figure out how to pause while the code is running.
I write the kernel in C++.


Top
 Profile  
 
 Post subject: Re: How can I arrange a delay in your code the kernel in C++
PostPosted: Wed Jul 24, 2019 10:25 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Basically, you use the timer chip.

It's difficult to go into full detail, but that should provide a starting point for further research.


Top
 Profile  
 
 Post subject: Re: How can I arrange a delay in your code the kernel in C++
PostPosted: Wed Jul 24, 2019 10:47 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
To add to iansjack's answer (and hopefully provide a positive example for your future research), I offer this wiki search on the term 'timer', which brings up a number of relevant pages.

For an x86 PC (which I assume is your target given your earlier posts), the relevant pages in the wiki are Timer Interrupt Sources, Programmable Interval Timer, and APIC timer (and maybe Chip Numbers, Acronyms and Things for general reference, as well as Real Time Clock if you need to time something against external time at some point). For internal timing relative to the number of clock cycles, you would use the APIC timer, while the PIT is what you need for timing something over an absolute interval.

For Raspberry Pi, the relevant pages are BCM System Timer and ARM Local Timer - or will be someday, as right now both of them are only stub entries. For other SBCs, you'd need to see the documentation on the specific system.

You might also want to do a forum search on 'timer' or 'timing'; while you'll probably need to wade through a fair number of unrelated threads, it is likely to have details and advice which haven't made it into the wiki.

Having said all of that, I have the feeling that there is some missing context in your query; knowing your goal is usually relevant to giving a useful answer, and asking meaningful questions is itself a learned skill. What are you trying to pause, and for what reason? I ask specifically because halting the kernel itself for a fixed period is a very different matter from sleeping a kernel process (or a thread within one - every process has at least one thread, but for single-threading the two terms are often treated as synonymous), which may in turn be different from doing the same for a user process, and pausing a driver while waiting for an I/O operation's interrupt is yet different again. All but the first and possibly the last should be part of your scheduler, for which the interval timer is a necessary but not sufficient requirement.

In other words, what are you trying to have the kernel do, and why?

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 716 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group