Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Getting CPU ID: (5 Items)
   
Getting CPU ID  
Hi

Is there a way to get the CPU ID using the QNX API?

I found how to tie to a specific CPU, but I couldnt find any documentation on getting the CPU number of the current 
thread
Re: Getting CPU ID  
Hi,

Just to be clear - you're looking for the equivalent of Linux's getcpu(2) or glibc's sched_getcpu(3) ?    I had a 
similar goal in an implementation of ntp's nanosecond kernel for an SMP system.   I couldn't find a nicely packaged 
solution.   You might be able to get what you want by running the DCMD_PROC_TIDSTATUS command on one's own thread and 
checking the last_cpu field.   I needed something safe to run even in an ISR (so I could capture timestamps with the 
lowest possible latencies), so I never investigated that solution further.

-Will
Re: Getting CPU ID  
Hi Will

Yes, that is what I needed!

I ended up using a platform specific solution, reading one of system registers indicating the CPU ID
Re: Getting CPU ID  
> Hi Will
> 
> Yes, that is what I needed!
> 
> I ended up using a platform specific solution, reading one of system registers
>  indicating the CPU ID

Can you notice, what register already contain cpu number you read? 
I just found how to read Lapic Id and have to transform it into cpu id, using smpinfo from syspage - they are generally 
not the same.
Re: Getting CPU ID  
Hi Artem,

On x86 as of the QNX version I'm using, it's stored in the task register, which you can retrieve via the STR instruction
.   I believe the full expression is:

cpunum = ( TR / 8 ) - 32

where TR is the value in the task register.

I haven't personally investigated any other architectures yet.

-Will