OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 11:02 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Best or fastest way to determine which CPU is running (S
PostPosted: Sun Jul 30, 2017 5:54 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 31, 2016 1:43 am
Posts: 48
Location: China
I prefer rdtscp. IA32_TSC_AUX is only a model specific register. Reading it can be faster than memory access.

EDIT: And when booting, you can store APIC ID in IA32_TSC_AUX so that you can read it faster later.

_________________
Doing steadfastly, or doing nil.


Top
 Profile  
 
 Post subject: Re: Best or fastest way to determine which CPU is running (S
PostPosted: Mon Jul 31, 2017 2:50 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 11, 2005 11:00 pm
Posts: 1110
Location: Tartu, Estonia
samiam95124 wrote:
Task register, to unique TSS, (which is usually per core in any case), then to a value in the TSS. The TSS span is set in the descriptor, which implies that you can make it longer than needed to store goodies in the TSS data, so voila, there is a place for a core number using a simple offset. You will have more than one thread per core, but in most implementations you don't use the hardware task switching but rather use the (fake) tss to bounce the stack pointer. Thus all threads use the same TSS, and thus all threads on the same core yield the same core number from the TSS.

Other idea: since you are not actually using the TSS to store registers, you can repurpose those fields so that you are not wasting the whole TSS per core.

If you are reading the task register, why not simply use the index part of the TSS selector itself as a core ID, since it is unique per core? This way you don't need another memory access to the TSS. You can use sequential selectors, and so your core ID function becomes something like
Code:
(ReadTaskRegister() - FIRST_TSS) >> 3

_________________
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 85 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