jonhoo / jonhoo/drwmutex

No support for >256 CPUs.

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
356
Forks
17
PR merge metrics
No merged PRs in 30d

Description

The current implementation uses the single byte of CPU ID information in `EBX` from `CPUID` with `EAX=1` to play nicely with CPUs that do not support x2APIC (such as AMDs and older Intels). However, this limits the number of processors to 256. `CPUID` also supports giving x2APIC IDs using `EAX=0xb` and reading the 4 bytes in `EDX`. `cpu_amd64.s` should use this feature if the CPU supports it.

A patch to correctly use the x2APIC CPUID instruction is given below:

``` diff
diff --git a/cpu_amd64.s b/cpu_amd64.s
index b485f31..354f8f9 100644
--- a/cpu_amd64.s
+++ b/cpu_amd64.s
@@ -2,14 +2,12 @@

// func cpu() uint64
TEXT ·cpu(SB),NOSPLIT,$0-8
- MOVL $0x01, AX // version information
+ MOVL $0x0b, AX // version information
MOVL $0x00, BX // any leaf will do
MOVL $0x00, CX // any subleaf will do

// call CPUID
BYTE $0x0f
BYTE $0xa2
-
- SHRQ $24, BX // logical cpu id is put in EBX[31-24]
- MOVQ BX, ret+0(FP)
+ MOVQ DX, ret+0(FP) // logical cpu id is put in EDX
RET
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.