Skip to content

Conversation

lbajolet-hashicorp
Copy link
Contributor

In order to mirror more closely the options offered by qemu when it comes to expressing the topology of the SMP architecture we are building an image upon, we add more options to the configuration supported by the plugin.

In addition to cpus, we now support sockets, cores and threads. These may be used in conjunction with the cpus, or left to be computed by the plugin directly.

By default, any configuration which only defined cpus will work potentially differently from before, since this is supported by qemu, but the behaviour changes depending on the version.

Closes #55

@nywilken
Copy link
Contributor

nywilken commented Sep 30, 2022

By default, any configuration which only defined cpus will work potentially differently from before, since this is supported by qemu, but the behaviour changes depending on the version.

By configuration do you mean Packer template configuration?

If so, I take this to mean that it will change behavior for a user, and that we will need to bump the minor version for this change. Is that correct?

@lbajolet-hashicorp
Copy link
Contributor Author

With the new code it will indeed potentially change the behaviour for clients, since what we specified with cpus before used to set the cpus and sockets to the value given by the user.
This PR changes this to fallback on qemu's default behaviour when it comes to interpret smp=%d. This changes depending on the version of qemu:

  • before v6.2, it would behave as we defined it earlier, the number of sockets will be set to cpus, each socket with 1 core/thread, so that would be equivalent to set -smp cpus=%d,sockets=%d,cores=1,threads=1.
  • 6.2 and onwards, the default preference goes to cores instead of sockets, hence the cpus will be equivalent to set -smp cpus=%d,sockets=1,cores=%d,threads=1.

So depending on the version of qemu, this may not change the topology reported by the system, and more fundamentally, the number of vCPUs exposed to the guest OS will remain the same.

@lbajolet-hashicorp
Copy link
Contributor Author

I guess it could mean a minor bump though because of the behaviour change, you are right on that.

Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good. I left a couple of nitpicky suggestions and a request for clarification on the comment for CPUCount.

return smpStr
}

func (c QemuSMPConfig) getMaxCPUs() int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this is a unexported method I recommend adding comment to explain how getMaxCPUs works. More specifically that it calculates the max cpu based off the QemuSMPConfig values. At first I thought that it was making a call to the underlying system to determine max allowed cpu.

Comment on lines 137 to 161
totalVCPUs := c.SocketCount

if c.CoreCount > 0 {
if totalVCPUs == 0 {
totalVCPUs = c.CoreCount
} else {
totalVCPUs *= c.CoreCount
}
}

if c.ThreadCount > 0 {
if totalVCPUs == 0 {
totalVCPUs = c.ThreadCount
} else {
totalVCPUs *= c.ThreadCount
}
}

return totalVCPUs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The nested if statements is a little confusing. Does something like the following make it clearer?

Suggested change
totalVCPUs := c.SocketCount
if c.CoreCount > 0 {
if totalVCPUs == 0 {
totalVCPUs = c.CoreCount
} else {
totalVCPUs *= c.CoreCount
}
}
if c.ThreadCount > 0 {
if totalVCPUs == 0 {
totalVCPUs = c.ThreadCount
} else {
totalVCPUs *= c.ThreadCount
}
}
return totalVCPUs
totalVCPUs := c.SocketCount
if totalVCPUs > 0 && c.CoreCount > 0 {
totalVCPUs *= c.CoreCount
}
// If number of sockets were not provided take the number of cores
if totalVCPUs == 0 {
totalVCPUs = c.CoreCount
}
// CPUCount, SocketCount, and ThreadCount were set return the final product of all.
if totalVCPUs > 0 && c.ThreadCount > 0 {
return totalVCPUs *= c.ThreadCount
}
// If nothing else was set take the value set for thread count
if totalVCPUs == 0 {
return c.ThreadCount
}
return totalVCPUs

}

if cpuCount > totalVCpus && totalVCpus != 0 {
log.Printf("CPU count greater than what topology allows, setting to %d", totalVCpus)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Printf("CPU count greater than what topology allows, setting to %d", totalVCpus)
log.Printf("CPU count is greater than what topology allows, setting to CPU count to the allowed topology %d", totalVCpus)

Comment on lines 78 to 79
// If both any topology element, or this is set, the final value will be the
// largest of the two.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear to me me which topology elements are being referred to here. Could you reword to call out which elements you are referring to.

@nywilken nywilken added version/bump minor A PR that changes behavior or contains breaking changes template configuration options. and removed breaking-change labels Sep 30, 2022
In order to mirror more closely the options offered by qemu when it
comes to expressing the topology of the SMP architecture we are
building an image upon, we add more options to the configuration
supported by the plugin.

In addition to cpus, we now support sockets, cores and threads. These
may be used in conjunction with the cpus, or left to be computed by the
plugin directly.

By default, any configuration which only defined cpus will work
potentially differently from before, since this is supported by qemu,
but the behaviour changes depending on the version.
Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lbajolet-hashicorp lbajolet-hashicorp merged commit 3d043b4 into main Sep 30, 2022
@lbajolet-hashicorp lbajolet-hashicorp deleted the smp_topology_changes branch September 30, 2022 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement version/bump minor A PR that changes behavior or contains breaking changes template configuration options.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change the default CPU topology given to QEMU when numCpus > 1
2 participants