cross-platform-actions / action

Cross-platform GitHub action
MIT License
139 stars 19 forks source link

Configuration option for CPU count #17

Closed straight-shoota closed 1 year ago

straight-shoota commented 1 year ago

The number of CPUs is currently hard-coded to two. But runners can have more cores (GitHub hosted macOS runners have 3, for example).

This setting should be configurable to allow using more cores in the guest system, like with memory size (#16). Potentially with autodetection of available cores as default.

jacob-carlborg commented 1 year ago

The question is, what should CPU count actually mean? In you're test run in #16, you're running FreeBSD on macOS. That means using the xhyve hypervisor. The description of the -cpu flag for the xhyve hypervisor is almost non existing, so I don't know exactly what it does. But there's not much choice either than just specifying a number.

Xhyve is macOS only. On Linux QEMU is used instead. QEMU supports a more fine grained control of specifying the CPU count, like number of cores, number of sockets, number of dies and number of threads. Currently for QEMU the CPU count is hardcoded to -smp 2,sockets=2. Honestly, I'm not entirely sure what this means but I think it means: two sockets with one core each. This is probably a pretty bad configuration taking into consideration that it's not particular common with computers with multiple sockets, the norm now is a single socket with multiple cores.

Conclusion: I'm leaning towards CPU count should mean number of cores. With xhyve, we just pass a number to the -cpu flag and it means whatever it means for xhyve. How does that sound like?

This contains some info on how to specify CPU count with QEMU [1] (do an in browser search for "-smp").

[1] https://www.qemu.org/docs/master/system/qemu-manpage.html

straight-shoota commented 1 year ago

Considering xhyve is a port of bhyve, I would expect the cpu configuration to work the same way as in bhyve, which has some documentation on it.

bhyve ... [-c [[cpus=]numcpus][,sockets=n][,cores=n][,threads=n]] ...

      -c    [setting ...]
         Number of guest virtual CPUs and/or the CPU topology.  The
         default value for each of numcpus, sockets, cores, and
         threads is 1.  The current maximum number of guest virtual
         CPUs is 16.  If numcpus is not specified then it will be cal-
         culated from the other arguments.  The topology must be con-
         sistent in that the numcpus must equal the product of
         sockets, cores, and threads.  If a setting is specified more
         than once the last one has precedence.

https://www.freebsd.org/cgi/man.cgi?query=bhyve&sektion=8

jacob-carlborg commented 1 year ago

As far that I can see in the source code it's much simpler in Xhyve. It's just one value: https://github.com/machyve/xhyve/blob/dfbe09b9db0ef9384c993db8e72fb3e96f376e7b/src/xhyve.c#L869-L870