Skip to content

Commit

Permalink
fix: Automaticly adjust CPU core count (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Jun 12, 2024
1 parent c12f9c4 commit c4e3ccc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
27 changes: 0 additions & 27 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,33 +126,6 @@ kubectl apply -f kubernetes.yml
CPU_CORES: "4"
```

Please be aware that macOS may have issues when the configured CPU core count is not a power of two (2, 4, 8, 16, etc).

* ### How do I add multiple disks?

To create additional disks, modify your compose file like this:

```yaml
environment:
DISK2_SIZE: "32G"
DISK3_SIZE: "64G"
volumes:
- /home/example:/storage2
- /mnt/data/example:/storage3
```

* ### How do I pass-through a disk?

It is possible to pass-through disk devices directly by adding them to your compose file in this way:

```yaml
devices:
- /dev/sdb:/disk1
- /dev/sdc:/disk2
```

Use `/disk1` if you want it to become your main drive, and use `/disk2` and higher to add them as secondary drives.

* ### How do I pass-through a USB device?

To pass-through a USB device, first lookup its vendor and product id via the `lsusb` command, then add them to your compose file like this:
Expand Down
25 changes: 24 additions & 1 deletion src/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ DEFAULT_FLAGS="vendor=GenuineIntel,vmware-cpuid-freq=on,-pdpe1gb"

if [[ "$CPU_VENDOR" != "GenuineIntel" ]] || [[ "${KVM:-}" == [Nn]* ]]; then
[ -z "${CPU_MODEL:-}" ] && CPU_MODEL="Haswell-noTSX"
DEFAULT_FLAGS+=",+pcid,+ssse3,+sse4.2,+popcnt,+avx,+avx2,+aes,+fma,+bmi1,+bmi2,+xsave,+xsaveopt,+rdrand,check"
DEFAULT_FLAGS+=",+pcid,+ssse3,+sse4.2,+popcnt,+avx,+avx2,+aes,+fma,+bmi1,+bmi2,+smep,+xsave,+xsavec,+xsaveopt,+xgetbv1,+movbe,+rdrand,check"
fi

if [ -z "${CPU_FLAGS:-}" ]; then
Expand All @@ -98,6 +98,29 @@ else
CPU_FLAGS="$DEFAULT_FLAGS,$CPU_FLAGS"
fi

[ -z "${CPU_CORES:-}" ] && CPU_CORES="2"

if [[ "$CPU_VENDOR" != "GenuineIntel" ]] || [[ "${KVM:-}" == [Nn]* ]]; then
SMP="$CPU_CORES,sockets=$CPU_CORES,dies=1,cores=1,threads=1"
else
case "$CPU_CORES" in
"3" ) CPU_CORES="2" ;;
"5" ) CPU_CORES="4" ;;
"9" ) CPU_CORES="8" ;;
esac
case "$CPU_CORES" in
"1" | "2" | "4" | "8" ) SMP="$CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1" ;;
"6" | "7" ) SMP="$CPU_CORES,sockets=3,dies=1,cores=2,threads=1" ;;
"10" | "11" ) SMP="$CPU_CORES,sockets=5,dies=1,cores=2,threads=1" ;;
"12" | "13" ) SMP="$CPU_CORES,sockets=3,dies=1,cores=4,threads=1" ;;
"14" | "15" ) SMP="$CPU_CORES,sockets=7,dies=1,cores=2,threads=1" ;;
"16" | "32" | "64" ) SMP="$CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1" ;;
*)
error "Invalid amount of CPU_CORES, value \"${CPU_CORES}\" is not a power of 2!" && exit 35
;;
esac
fi

USB="nec-usb-xhci,id=xhci"
USB+=" -device usb-kbd,bus=xhci.0"
USB+=" -global nec-usb-xhci.msi=off"
Expand Down

0 comments on commit c4e3ccc

Please sign in to comment.