Skip to content

Commit 19328b4

Browse files
danilrwxfl64mortelumina98
authored
feat(vm): calculate sockets count by cores count (#747)
## Description Update CPU configuration to dynamically calculate the number of sockets based on the number of cores and set a maximum of 8 sockets. ## Why do we need it, and what problem does it solve? Currently, each core has its own socket. However, some operating systems do not function correctly with this setup. ## What is the expected result? The system will dynamically calculate the number of sockets based on the number of cores, ensuring compatibility with various operating systems. The maximum number of sockets will be limited to 8. --------- Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com> Signed-off-by: mortelumina98 <ekaterina.matseevska@flant.com> Signed-off-by: Ekaterina Matseevska <ekaterina.matseevska@flant.com> Co-authored-by: Pavel Tishkov <pavel.tishkov@flant.com> Co-authored-by: mortelumina98 <ekaterina.matseevska@flant.com>
1 parent e8c19a4 commit 19328b4

16 files changed

Lines changed: 512 additions & 20 deletions

File tree

api/core/v1alpha2/virtual_machine.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ type CPUSpec struct {
159159
// +kubebuilder:validation:Format:=int32
160160
// +kubebuilder:validation:Minimum=1
161161
Cores int `json:"cores"`
162+
162163
// Guaranteed share of CPU that will be allocated to the VM. Specified as a percentage.
163164
// +kubebuilder:default:="100%"
164165
// +kubebuilder:validation:Enum:={"5%", "10%", "25%", "50%", "100%"}
@@ -353,6 +354,16 @@ type CPUStatus struct {
353354
RequestedCores resource.Quantity `json:"requestedCores,omitempty"`
354355
// runtime overhead.
355356
RuntimeOverhead resource.Quantity `json:"runtimeOverhead,omitempty"`
357+
// Topology with Cores count and Sockets count.
358+
Topology Topology `json:"topology,omitempty"`
359+
}
360+
361+
// Topology defines count of used CPU cores and sockets.
362+
type Topology struct {
363+
// Current number of cores inside the VM.
364+
CoresPerSocket int `json:"coresPerSocket"`
365+
// Current number of cores inside the VM.
366+
Sockets int `json:"sockets"`
356367
}
357368

358369
// MemoryStatus defines statistics about the Memory resource usage.

api/core/v1alpha2/zz_generated.deepcopy.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go

Lines changed: 39 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crds/doc-ru-virtualmachines.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,16 @@ spec:
679679
cores:
680680
description: Текущее количество ядер виртуальной машины.
681681
requestedCores:
682-
description: Запрошенные ядра.
682+
description: Количество ядер CPU, запрошенных виртуальной машиной.
683683
runtimeOverhead:
684684
description: Накладные расходы на CPU во время выполнения.
685+
topology:
686+
description: Информация о текущей топологии CPU.
687+
properties:
688+
coresPerSocket:
689+
description: Количество ядер CPU на один сокет виртуальной машины.
690+
sockets:
691+
description: Текущее количество сокетов виртуальной машины.
685692
memory:
686693
description: Статистика использования ресурсов памяти.
687694
properties:

crds/virtualmachines.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,11 +1204,24 @@ spec:
12041204
description: CPU overhead required by the runtime.
12051205
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
12061206
x-kubernetes-int-or-string: true
1207+
topology:
1208+
description: Information on the current CPU topology.
1209+
type: object
1210+
required:
1211+
- coresPerSocket
1212+
- sockets
1213+
properties:
1214+
coresPerSocket:
1215+
description: Current number of CPU cores per socket.
1216+
type: integer
1217+
sockets:
1218+
description: Current number of CPU sockets.
1219+
type: integer
12071220
required:
12081221
- cores
12091222
type: object
12101223
memory:
1211-
description: Statistics on used memory resources.
1224+
description: Memory usage statistics.
12121225
properties:
12131226
runtimeOverhead:
12141227
anyOf:

docs/USER_GUIDE.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ There are different types of images:
157157
- ISO image - an installation image used for the initial installation of an operating system. Such images are released by OS vendors and are used for installation on physical and virtual servers.
158158
- Preinstalled disk image - contains an already installed and configured operating system ready for use after the virtual machine is created. These images are offered by several vendors and can be provided in formats such as qcow2, raw, vmdk, and others.
159159

160-
Example of resource for obtaining virtual machine images **Ubuntu**: https://cloud-images.ubuntu.com
160+
Example of resource for obtaining virtual machine images **Ubuntu**: <https://cloud-images.ubuntu.com>.
161161

162162
Once a share is created, the image type and size are automatically determined, and this information is reflected in the share status.
163163

@@ -742,6 +742,54 @@ Example output:
742742

743743
After creation, the virtual machine will automatically get an IP address from the range specified in the module settings (`virtualMachineCIDRs` block).
744744

745+
### Automatic CPU Topology Configuration
746+
747+
The number of sockets is calculated automatically and depends on the number of cores.
748+
749+
For .spec.cpu.cores <= 16:
750+
751+
- One socket is created with the number of cores equal to the specified value.
752+
- Core increment step: 1
753+
- Allowed values: any number from 1 to 16 inclusive.
754+
755+
For 16 < .spec.cpu.cores <= 32:
756+
757+
- Two sockets are created with the same number of cores in each.
758+
- Core increment step: 2
759+
- Allowed values: 18, 20, 22, ..., 32.
760+
- Minimum cores per socket: 9
761+
- Maximum cores per socket: 16
762+
763+
For 32 < .spec.cpu.cores <= 64:
764+
765+
- Four sockets are created with the same number of cores in each.
766+
- Core increment step: 4
767+
- Allowed values: 36, 40, 44, ..., 64.
768+
- Minimum cores per socket: 9
769+
- Maximum cores per socket: 16
770+
771+
For .spec.cpu.cores > 64:
772+
773+
- Eight sockets are created with the same number of cores in each.
774+
- Core increment step: 8
775+
- Allowed values: 72, 80, ...
776+
- Minimum cores per socket: 8
777+
778+
The current VM topology (actual number of sockets and cores) is displayed in the VM status in the following format:
779+
780+
```yaml
781+
status:
782+
resources:
783+
cpu:
784+
coreFraction: 100%
785+
cores: 18
786+
requestedCores: "18"
787+
runtimeOverhead: "0"
788+
topology:
789+
sockets: 2
790+
coresPerSocket: 9
791+
```
792+
745793
### Connecting to a virtual machine
746794
747795
The following methods are available for connecting to the virtual machine:

docs/USER_GUIDE_RU.md

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ weight: 50
159159

160160
Примеры ресурсов для получения образов виртуальной машины:
161161

162-
- **Ubuntu**: https://cloud-images.ubuntu.com.
163-
- **Alt Linux**: https://ftp.altlinux.ru/pub/distributions/ALTLinux/platform/images/cloud/x86_64.
164-
- **Astra Linux**: https://download.astralinux.ru/ui/native/mg-generic/alse/cloudinit.
162+
- **Ubuntu**: <https://cloud-images.ubuntu.com>.
163+
- **Alt Linux**: <https://ftp.altlinux.ru/pub/distributions/ALTLinux/platform/images/cloud/x86_64>.
164+
- **Astra Linux**: <https://download.astralinux.ru/ui/native/mg-generic/alse/cloudinit>.
165165

166166
После создания ресурса, тип и размер образа определяются автоматически и эта информация отражается в статусе ресурса.
167167

@@ -426,6 +426,7 @@ EOF
426426
Можно создать образ из [снимка](#снимки). Для этого необходимо чтобы снимок диска находился в фазе готовности.
427427

428428
Пример создания образа из моментального снимка диска:
429+
429430
```yaml
430431
d8 k apply -f - <<EOF
431432
apiVersion: virtualization.deckhouse.io/v1alpha2
@@ -748,6 +749,54 @@ d8 k get vm linux-vm
748749

749750
После создания виртуальная машина автоматически получит IP-адрес из диапазона, указанного в настройках модуля (блок `virtualMachineCIDRs`).
750751

752+
### Автоматическая конфигурация топологии CPU
753+
754+
Количество сокетов рассчитывается автоматически и зависит от количества ядер.
755+
756+
Для .spec.cpu.cores <= 16:
757+
758+
- Создается один сокет с количеством ядер, равным указанному значению.
759+
- Шаг инкремента ядер: 1
760+
- Допустимые значения: любое число от 1 до 16 включительно.
761+
762+
Для 16 < .spec.cpu.cores <= 32:
763+
764+
- Создается два сокета с одинаковым количеством ядер в каждом.
765+
- Шаг инкремента ядер: 2
766+
- Допустимые значения: 18, 20, 22, ..., 32.
767+
- Минимум ядер в сокете: 9
768+
- Максимум ядер в сокете: 16
769+
770+
Для 32 < .spec.cpu.cores <= 64:
771+
772+
- Создается четыре сокета с одинаковым количеством ядер в каждом.
773+
- Шаг инкремента ядер: 4
774+
- Допустимые значения: 36, 40, 44, ..., 64.
775+
- Минимум ядер в сокете: 9
776+
- Максимум ядер в сокете: 16
777+
778+
Для .spec.cpu.cores > 64:
779+
780+
- Создается восемь сокетов с одинаковым количеством ядер в каждом.
781+
- Шаг инкремента ядер: 8
782+
- Допустимые значения: 72, 80, ...
783+
- Минимум ядер в сокете: 8
784+
785+
Текущая топология ВМ (реальное количество сокетов и ядер) отображается в статусе ВМ в следующем формате:
786+
787+
```yaml
788+
status:
789+
resources:
790+
cpu:
791+
coreFraction: 100%
792+
cores: 18
793+
requestedCores: "18"
794+
runtimeOverhead: "0"
795+
topology:
796+
sockets: 2
797+
coresPerSocket: 9
798+
```
799+
751800
### Подключение к виртуальной машине
752801
753802
Для подключения к виртуальной машине доступны следующие способы:

docs/internal/cpu_cores_count.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Number of CPU cores
2+
3+
## Logic for calculating the number of sockets and cores
4+
5+
For .spec.cpu.cores <= 16:
6+
7+
- One socket is created with the number of cores equal to the specified value.
8+
- Core increment step: 1
9+
- Allowed values: any number from 1 to 16 inclusive.
10+
11+
For 16 < .spec.cpu.cores <= 32:
12+
13+
- Two sockets are created with the same number of cores in each.
14+
- Core increment step: 2
15+
- Allowed values: 18, 20, 22, ..., 32.
16+
- Minimum cores per socket: 9
17+
- Maximum cores per socket: 16
18+
19+
For 32 < .spec.cpu.cores <= 64:
20+
21+
- Four sockets are created with the same number of cores in each.
22+
- Core increment step: 4
23+
- Allowed values: 36, 40, 44, ..., 64.
24+
- Minimum cores per socket: 9
25+
- Maximum cores per socket: 16
26+
27+
For .spec.cpu.cores > 64:
28+
29+
- Eight sockets are created with the same number of cores in each.
30+
- Core increment step: 8
31+
- Allowed values: 72, 80, ...
32+
- Minimum cores per socket: 8
33+
34+
## Value validation
35+
36+
Validation of .spec.cpu.cores values is performed via a webhook.
37+
38+
## Displaying VM topology
39+
40+
The current VM topology (actual number of sockets and cores) is displayed in the VM status in the following format:
41+
42+
```yaml
43+
status:
44+
resources:
45+
cpu:
46+
coreFraction: 100%
47+
cores: 18
48+
requestedCores: "18"
49+
runtimeOverhead: "0"
50+
topology:
51+
sockets: 2
52+
coresPerSocket: 9
53+
```

0 commit comments

Comments
 (0)