Q:

How os dispatch threads and process on cpu

I am wondering how linux os populates /proc/cpuinfo special file. Is there a cpu instruction that gives the number of cpu and cores ?
Is there an x86 assembly instruction can switch a thread or process on a specific cpu ?

A:

The BIOS populates the ACPI tables (specifically, the APIC and MADT) with information about the processors in the system. Linux reads these tables to find out how many processors there are.
The processor does have ways to switch a thread or process*, but no modern OS uses them. If you care to, you can read about tasks in the Software Developers Manual (volume 3, section 7).
* Specifically, a far jump or call through a task gate, an iret from a nested task, or an interrupt through a task gate.

