kerf-multikernel 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/PKG-INFO +34 -17
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/README.md +33 -16
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/pyproject.toml +1 -1
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/__init__.py +3 -3
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/cli.py +3 -1
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/create/main.py +74 -17
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/dtc/extractor.py +9 -75
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/dtc/overlay.py +110 -129
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/dtc/parser.py +125 -701
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/dtc/reporter.py +9 -4
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/dtc/validator.py +39 -90
- kerf_multikernel-0.2.0/src/kerf/dump/__init__.py +20 -0
- kerf_multikernel-0.2.0/src/kerf/dump/main.py +86 -0
- kerf_multikernel-0.2.0/src/kerf/init/main.py +1117 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/models.py +31 -5
- kerf_multikernel-0.2.0/src/kerf/pool_diff.py +98 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/resources.py +96 -97
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/runtime.py +58 -96
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/show/main.py +57 -35
- kerf_multikernel-0.2.0/src/kerf/topology.py +139 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/update/main.py +15 -66
- kerf_multikernel-0.1.0/src/kerf/init/main.py +0 -696
- kerf_multikernel-0.1.0/src/kerf/lazy_cma.py +0 -132
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/LICENSE +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/baseline.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/console/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/console/main.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/create/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/data/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/data/kerf-init +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/daxfs/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/daxfs/mkdaxfs.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/delete/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/delete/main.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/docker/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/docker/image.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/dtc/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/dtc/cells.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/exceptions.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/exec/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/exec/main.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/init/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/kill/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/kill/main.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/load/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/load/main.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/metadata.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/show/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/unload/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/unload/main.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/update/__init__.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/utils.py +0 -0
- {kerf_multikernel-0.1.0 → kerf_multikernel-0.2.0}/src/kerf/vmlinuz.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: kerf-multikernel
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Multikernel Management CLI tool
|
|
5
5
|
Author: Cong Wang
|
|
6
6
|
Requires-Python: >=3.9,<4.0
|
|
@@ -146,11 +146,19 @@ Baseline DTB (static)
|
|
|
146
146
|
|
|
147
147
|
### Command Line Interface
|
|
148
148
|
```bash
|
|
149
|
-
# Initialize resource pool with CPUs
|
|
150
|
-
|
|
149
|
+
# Initialize resource pool with CPUs and pool memory
|
|
150
|
+
# A plain size lands on the NUMA node of the requested CPUs
|
|
151
|
+
kerf init --cpus=4-7 --memory=2GB
|
|
151
152
|
|
|
152
|
-
# Initialize with CPUs and devices
|
|
153
|
-
kerf init --cpus=4-31 --devices=enp9s0_dev,nvme0
|
|
153
|
+
# Initialize with CPUs, per-node memory and devices
|
|
154
|
+
kerf init --cpus=4-31 --memory=8GB@0,8GB@1 --devices=enp9s0_dev,nvme0
|
|
155
|
+
|
|
156
|
+
# Re-run to reshape the live pool; "none" asks for none of a resource
|
|
157
|
+
kerf init --cpus=4-15 --memory=4GB
|
|
158
|
+
kerf init --cpus=4-15 --memory=none
|
|
159
|
+
|
|
160
|
+
# Hand everything back to the host
|
|
161
|
+
kerf init --cpus=none --memory=none
|
|
154
162
|
|
|
155
163
|
# Create kernel instance with resource allocation
|
|
156
164
|
kerf create web-server --cpus=4-7 --memory=2GB
|
|
@@ -167,6 +175,11 @@ kerf exec web-server
|
|
|
167
175
|
kerf show
|
|
168
176
|
kerf show web-server
|
|
169
177
|
|
|
178
|
+
# Dump the device tree the kernel holds: DTB to replay, --dts to read
|
|
179
|
+
kerf dump -o host.dtb
|
|
180
|
+
kerf dump web-server -o web.dtb
|
|
181
|
+
kerf dump web-server --dts
|
|
182
|
+
|
|
170
183
|
# Shutdown a running kernel instance
|
|
171
184
|
kerf kill web-server
|
|
172
185
|
|
|
@@ -345,22 +358,26 @@ pip install -e .
|
|
|
345
358
|
kerf --help
|
|
346
359
|
kerf init --help
|
|
347
360
|
|
|
348
|
-
#
|
|
349
|
-
kerf init --
|
|
361
|
+
# Carve a pool out of the host: 7 CPUs (by APIC ID) and 1GB on their NUMA node
|
|
362
|
+
sudo kerf init --cpus=128-134 --memory=1GB --report
|
|
350
363
|
```
|
|
351
364
|
|
|
352
|
-
|
|
365
|
+
### Reusing a Dumped Baseline
|
|
353
366
|
|
|
354
|
-
|
|
367
|
+
`kerf dump` writes the device tree the kernel holds, byte for byte, and
|
|
368
|
+
`kerf init --input` and `kerf create --input` accept it back. This is the
|
|
369
|
+
supported way to capture a configuration and replay it later or on another
|
|
370
|
+
host; hand-written device tree files are not supported. An instance dump
|
|
371
|
+
carries its CPUs, memory size, devices and id; options such as --uring and
|
|
372
|
+
--enable-host-kcore are given again on the command line.
|
|
355
373
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
**Note**: All baseline files contain **only** hardware resources - no instances. Instances are created dynamically via overlays using `kerf create` command.
|
|
374
|
+
```bash
|
|
375
|
+
sudo kerf dump -o host.dtb # baseline
|
|
376
|
+
sudo kerf dump web-server -o web.dtb # a running instance
|
|
377
|
+
sudo kerf init --input=host.dtb # replay the baseline
|
|
378
|
+
sudo kerf create --input=web.dtb # recreate the instance
|
|
379
|
+
sudo kerf dump --dts # read it; text is not replayable
|
|
380
|
+
```
|
|
364
381
|
|
|
365
382
|
## CPU and NUMA Topology Support
|
|
366
383
|
|
|
@@ -127,11 +127,19 @@ Baseline DTB (static)
|
|
|
127
127
|
|
|
128
128
|
### Command Line Interface
|
|
129
129
|
```bash
|
|
130
|
-
# Initialize resource pool with CPUs
|
|
131
|
-
|
|
130
|
+
# Initialize resource pool with CPUs and pool memory
|
|
131
|
+
# A plain size lands on the NUMA node of the requested CPUs
|
|
132
|
+
kerf init --cpus=4-7 --memory=2GB
|
|
132
133
|
|
|
133
|
-
# Initialize with CPUs and devices
|
|
134
|
-
kerf init --cpus=4-31 --devices=enp9s0_dev,nvme0
|
|
134
|
+
# Initialize with CPUs, per-node memory and devices
|
|
135
|
+
kerf init --cpus=4-31 --memory=8GB@0,8GB@1 --devices=enp9s0_dev,nvme0
|
|
136
|
+
|
|
137
|
+
# Re-run to reshape the live pool; "none" asks for none of a resource
|
|
138
|
+
kerf init --cpus=4-15 --memory=4GB
|
|
139
|
+
kerf init --cpus=4-15 --memory=none
|
|
140
|
+
|
|
141
|
+
# Hand everything back to the host
|
|
142
|
+
kerf init --cpus=none --memory=none
|
|
135
143
|
|
|
136
144
|
# Create kernel instance with resource allocation
|
|
137
145
|
kerf create web-server --cpus=4-7 --memory=2GB
|
|
@@ -148,6 +156,11 @@ kerf exec web-server
|
|
|
148
156
|
kerf show
|
|
149
157
|
kerf show web-server
|
|
150
158
|
|
|
159
|
+
# Dump the device tree the kernel holds: DTB to replay, --dts to read
|
|
160
|
+
kerf dump -o host.dtb
|
|
161
|
+
kerf dump web-server -o web.dtb
|
|
162
|
+
kerf dump web-server --dts
|
|
163
|
+
|
|
151
164
|
# Shutdown a running kernel instance
|
|
152
165
|
kerf kill web-server
|
|
153
166
|
|
|
@@ -326,22 +339,26 @@ pip install -e .
|
|
|
326
339
|
kerf --help
|
|
327
340
|
kerf init --help
|
|
328
341
|
|
|
329
|
-
#
|
|
330
|
-
kerf init --
|
|
342
|
+
# Carve a pool out of the host: 7 CPUs (by APIC ID) and 1GB on their NUMA node
|
|
343
|
+
sudo kerf init --cpus=128-134 --memory=1GB --report
|
|
331
344
|
```
|
|
332
345
|
|
|
333
|
-
|
|
346
|
+
### Reusing a Dumped Baseline
|
|
334
347
|
|
|
335
|
-
|
|
348
|
+
`kerf dump` writes the device tree the kernel holds, byte for byte, and
|
|
349
|
+
`kerf init --input` and `kerf create --input` accept it back. This is the
|
|
350
|
+
supported way to capture a configuration and replay it later or on another
|
|
351
|
+
host; hand-written device tree files are not supported. An instance dump
|
|
352
|
+
carries its CPUs, memory size, devices and id; options such as --uring and
|
|
353
|
+
--enable-host-kcore are given again on the command line.
|
|
336
354
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
**Note**: All baseline files contain **only** hardware resources - no instances. Instances are created dynamically via overlays using `kerf create` command.
|
|
355
|
+
```bash
|
|
356
|
+
sudo kerf dump -o host.dtb # baseline
|
|
357
|
+
sudo kerf dump web-server -o web.dtb # a running instance
|
|
358
|
+
sudo kerf init --input=host.dtb # replay the baseline
|
|
359
|
+
sudo kerf create --input=web.dtb # recreate the instance
|
|
360
|
+
sudo kerf dump --dts # read it; text is not replayable
|
|
361
|
+
```
|
|
345
362
|
|
|
346
363
|
## CPU and NUMA Topology Support
|
|
347
364
|
|
|
@@ -19,7 +19,7 @@ A comprehensive multikernel management system designed to orchestrate
|
|
|
19
19
|
and manage multiple kernel instances on a single host.
|
|
20
20
|
"""
|
|
21
21
|
|
|
22
|
-
__version__ = "0.
|
|
22
|
+
__version__ = "0.2.0"
|
|
23
23
|
__author__ = "Cong Wang"
|
|
24
24
|
|
|
25
25
|
# Export main runtime components for easy access
|
|
@@ -41,7 +41,7 @@ from .resources import (
|
|
|
41
41
|
get_available_cpus,
|
|
42
42
|
get_allocated_cpus,
|
|
43
43
|
get_allocated_memory_regions,
|
|
44
|
-
|
|
44
|
+
chunk_containing,
|
|
45
45
|
validate_cpu_allocation,
|
|
46
46
|
validate_memory_allocation,
|
|
47
47
|
find_next_instance_id,
|
|
@@ -67,7 +67,7 @@ __all__ = [
|
|
|
67
67
|
"get_available_cpus",
|
|
68
68
|
"get_allocated_cpus",
|
|
69
69
|
"get_allocated_memory_regions",
|
|
70
|
-
"
|
|
70
|
+
"chunk_containing",
|
|
71
71
|
"validate_cpu_allocation",
|
|
72
72
|
"validate_memory_allocation",
|
|
73
73
|
"find_next_instance_id",
|
|
@@ -26,11 +26,12 @@ from .kill.main import kill_cmd
|
|
|
26
26
|
from .unload.main import unload
|
|
27
27
|
from .delete.main import delete
|
|
28
28
|
from .show.main import show
|
|
29
|
+
from .dump.main import dump
|
|
29
30
|
from .console.main import console
|
|
30
31
|
|
|
31
32
|
|
|
32
33
|
@click.group()
|
|
33
|
-
@click.version_option(version="0.
|
|
34
|
+
@click.version_option(version="0.2.0", prog_name="kerf")
|
|
34
35
|
@click.option("--debug", is_flag=True, help="Enable debug mode")
|
|
35
36
|
@click.pass_context
|
|
36
37
|
def main(ctx, debug):
|
|
@@ -49,6 +50,7 @@ main.add_command(kill_cmd)
|
|
|
49
50
|
main.add_command(unload)
|
|
50
51
|
main.add_command(delete)
|
|
51
52
|
main.add_command(show)
|
|
53
|
+
main.add_command(dump)
|
|
52
54
|
main.add_command(console)
|
|
53
55
|
|
|
54
56
|
|
|
@@ -23,15 +23,16 @@ creating an overlay and applying it to the kernel.
|
|
|
23
23
|
import copy
|
|
24
24
|
import sys
|
|
25
25
|
import traceback
|
|
26
|
+
from pathlib import Path
|
|
26
27
|
from typing import List, Optional
|
|
27
28
|
import click
|
|
28
29
|
|
|
29
30
|
from ..runtime import DeviceTreeManager
|
|
31
|
+
from ..dtc.parser import DeviceTreeParser, is_dts_text
|
|
30
32
|
from ..models import Instance, InstanceResources
|
|
31
33
|
from ..resources import (
|
|
32
34
|
validate_cpu_allocation,
|
|
33
35
|
validate_memory_allocation,
|
|
34
|
-
find_available_memory_base,
|
|
35
36
|
get_available_cpus,
|
|
36
37
|
)
|
|
37
38
|
from ..exceptions import ValidationError, KernelInterfaceError, ResourceError, ParseError
|
|
@@ -302,6 +303,12 @@ def parse_memory_spec(memory_spec: str) -> int:
|
|
|
302
303
|
) from exc
|
|
303
304
|
|
|
304
305
|
|
|
306
|
+
def _placement(instance) -> str:
|
|
307
|
+
"""Name the base only when one was asked for; the kernel picks otherwise."""
|
|
308
|
+
base = instance.resources.memory_base
|
|
309
|
+
return f" at {hex(base)}" if base else ""
|
|
310
|
+
|
|
311
|
+
|
|
305
312
|
def parse_memory_base(base_spec: str) -> int:
|
|
306
313
|
"""
|
|
307
314
|
Parse memory base address specification.
|
|
@@ -371,9 +378,7 @@ def dump_overlay_for_debug(
|
|
|
371
378
|
dtbo_data = manager.overlay_gen.generate_overlay(current, modified)
|
|
372
379
|
|
|
373
380
|
try:
|
|
374
|
-
# pylint: disable=import-outside-toplevel
|
|
375
|
-
from ..dtc.parser import DeviceTreeParser
|
|
376
|
-
import libfdt # pylint: disable=import-error
|
|
381
|
+
import libfdt # pylint: disable=import-error,import-outside-toplevel
|
|
377
382
|
|
|
378
383
|
fdt = libfdt.Fdt(dtbo_data)
|
|
379
384
|
parser = DeviceTreeParser()
|
|
@@ -428,11 +433,12 @@ def dump_overlay_for_debug(
|
|
|
428
433
|
"interleave (across NUMA nodes), or bind (specific NUMA nodes)",
|
|
429
434
|
)
|
|
430
435
|
@click.option(
|
|
431
|
-
"--memory", "-m",
|
|
436
|
+
"--memory", "-m", help='Memory allocation (e.g., "2GB", "2048MB", or bytes)'
|
|
432
437
|
)
|
|
433
438
|
@click.option(
|
|
434
439
|
"--memory-base",
|
|
435
|
-
help="Memory base address (hex: 0x80000000 or decimal
|
|
440
|
+
help="Memory base address to request (hex: 0x80000000 or decimal). "
|
|
441
|
+
"Only checked against the pool; the kernel places instance memory itself.",
|
|
436
442
|
)
|
|
437
443
|
@click.option(
|
|
438
444
|
"--devices",
|
|
@@ -440,6 +446,15 @@ def dump_overlay_for_debug(
|
|
|
440
446
|
help='Device names (comma-separated, e.g., "enp9s0_dev,nvme0"). '
|
|
441
447
|
"Device names must match device node names in the baseline DTB.",
|
|
442
448
|
)
|
|
449
|
+
@click.option(
|
|
450
|
+
"--input",
|
|
451
|
+
"-i",
|
|
452
|
+
"input_path",
|
|
453
|
+
type=click.Path(exists=True, dir_okay=False),
|
|
454
|
+
help="Replay an instance dumped with 'kerf dump NAME -o FILE': its CPUs, memory "
|
|
455
|
+
"size, devices and id, unless overridden by NAME or --id. The memory base is "
|
|
456
|
+
"left to the kernel. Mutually exclusive with the resource options above.",
|
|
457
|
+
)
|
|
443
458
|
@click.option(
|
|
444
459
|
"--enable-host-kcore", is_flag=True, help="Enable host kcore access for this instance"
|
|
445
460
|
)
|
|
@@ -461,6 +476,7 @@ def create( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
|
461
476
|
memory: str,
|
|
462
477
|
memory_base: Optional[str],
|
|
463
478
|
devices: Optional[str],
|
|
479
|
+
input_path: Optional[str],
|
|
464
480
|
enable_host_kcore: bool,
|
|
465
481
|
uring: bool,
|
|
466
482
|
uring_sq_entries: Optional[int],
|
|
@@ -507,6 +523,9 @@ def create( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
|
507
523
|
|
|
508
524
|
# Validate without applying
|
|
509
525
|
kerf create web-server --cpu-count=4 --memory=2GB --dry-run
|
|
526
|
+
|
|
527
|
+
# Recreate an instance from 'kerf dump web-server -o web.dtb'
|
|
528
|
+
kerf create --input=web.dtb
|
|
510
529
|
"""
|
|
511
530
|
try:
|
|
512
531
|
if name is None and ctx is not None:
|
|
@@ -518,6 +537,46 @@ def create( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
|
518
537
|
name = arg
|
|
519
538
|
break
|
|
520
539
|
|
|
540
|
+
dumped = None
|
|
541
|
+
if input_path:
|
|
542
|
+
given = [
|
|
543
|
+
flag
|
|
544
|
+
for flag, value in (
|
|
545
|
+
("--cpus", cpus),
|
|
546
|
+
("--cpu-count", cpu_count),
|
|
547
|
+
("--memory", memory),
|
|
548
|
+
("--memory-base", memory_base),
|
|
549
|
+
("--devices", devices),
|
|
550
|
+
("--numa-nodes", numa_nodes),
|
|
551
|
+
("--memory-policy", memory_policy),
|
|
552
|
+
)
|
|
553
|
+
if value is not None
|
|
554
|
+
]
|
|
555
|
+
if given:
|
|
556
|
+
click.echo(
|
|
557
|
+
f"Error: --input is mutually exclusive with {', '.join(given)}; "
|
|
558
|
+
"the dump supplies those.",
|
|
559
|
+
err=True,
|
|
560
|
+
)
|
|
561
|
+
sys.exit(2)
|
|
562
|
+
if is_dts_text(Path(input_path)):
|
|
563
|
+
click.echo(f"Error: {input_path} is DTS text; only the DTB from 'kerf dump' "
|
|
564
|
+
"(without --dts) can be replayed.", err=True)
|
|
565
|
+
sys.exit(2)
|
|
566
|
+
try:
|
|
567
|
+
dumped = DeviceTreeParser().parse_instance_dtb_from_bytes(
|
|
568
|
+
Path(input_path).read_bytes()
|
|
569
|
+
)
|
|
570
|
+
except ParseError as e:
|
|
571
|
+
click.echo(f"Error: {input_path} is not an instance dump: {e}", err=True)
|
|
572
|
+
sys.exit(2)
|
|
573
|
+
name = name or dumped.name
|
|
574
|
+
if instance_id is None:
|
|
575
|
+
instance_id = dumped.id
|
|
576
|
+
cpus = ",".join(map(str, dumped.resources.cpus))
|
|
577
|
+
memory = str(dumped.resources.memory_bytes)
|
|
578
|
+
devices = ",".join(dumped.resources.devices) or None
|
|
579
|
+
|
|
521
580
|
# Validate name is provided
|
|
522
581
|
if not name:
|
|
523
582
|
click.echo("Error: Instance name is required", err=True)
|
|
@@ -525,6 +584,10 @@ def create( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
|
525
584
|
click.echo(" kerf create [OPTIONS] <name>", err=True)
|
|
526
585
|
sys.exit(2)
|
|
527
586
|
|
|
587
|
+
if memory is None:
|
|
588
|
+
click.echo("Error: --memory is required unless --input is given", err=True)
|
|
589
|
+
sys.exit(2)
|
|
590
|
+
|
|
528
591
|
# Validate that exactly one of --cpus or --cpu-count is provided
|
|
529
592
|
if cpus and cpu_count is not None:
|
|
530
593
|
click.echo(
|
|
@@ -641,17 +704,11 @@ def create( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
|
641
704
|
# Validate CPU allocation (against baseline and existing instances)
|
|
642
705
|
validate_cpu_allocation(modified, cpu_list)
|
|
643
706
|
|
|
644
|
-
#
|
|
707
|
+
# The kernel places instance memory itself; a base is only ever
|
|
708
|
+
# a caller's request, so it is all there is to validate.
|
|
645
709
|
if memory_base_addr is None:
|
|
646
|
-
|
|
647
|
-
if found_base is None:
|
|
648
|
-
raise ResourceError(
|
|
649
|
-
f"No available memory region found for {memory_bytes} bytes. "
|
|
650
|
-
"Try specifying --memory-base or reduce memory size."
|
|
651
|
-
)
|
|
652
|
-
memory_base_addr = found_base
|
|
710
|
+
memory_base_addr = 0
|
|
653
711
|
else:
|
|
654
|
-
# Validate specified memory base
|
|
655
712
|
validate_memory_allocation(modified, memory_base_addr, memory_bytes)
|
|
656
713
|
|
|
657
714
|
# Create instance resources with topology settings
|
|
@@ -705,7 +762,7 @@ def create( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
|
705
762
|
click.echo(
|
|
706
763
|
f" NUMA Nodes: {', '.join(map(str, instance.resources.numa_nodes))}"
|
|
707
764
|
)
|
|
708
|
-
click.echo(f" Memory: {memory}
|
|
765
|
+
click.echo(f" Memory: {memory}{_placement(instance)}")
|
|
709
766
|
if instance.resources.memory_policy:
|
|
710
767
|
click.echo(f" Memory Policy: {instance.resources.memory_policy}")
|
|
711
768
|
if instance.resources.devices:
|
|
@@ -745,7 +802,7 @@ def create( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
|
745
802
|
if instance.resources.numa_nodes:
|
|
746
803
|
numa_str = ", ".join(map(str, instance.resources.numa_nodes))
|
|
747
804
|
click.echo(f" NUMA Nodes: {numa_str}")
|
|
748
|
-
click.echo(f" Memory: {memory}
|
|
805
|
+
click.echo(f" Memory: {memory}{_placement(instance)}")
|
|
749
806
|
if instance.resources.memory_policy:
|
|
750
807
|
click.echo(f" Memory Policy: {instance.resources.memory_policy}")
|
|
751
808
|
if instance.resources.devices:
|
|
@@ -18,6 +18,7 @@ DTB generation from device tree models.
|
|
|
18
18
|
|
|
19
19
|
import libfdt
|
|
20
20
|
from ..models import GlobalDeviceTree, Instance
|
|
21
|
+
from ..pool_diff import ANY_NODE
|
|
21
22
|
from .cells import pack_cpu_ids
|
|
22
23
|
|
|
23
24
|
|
|
@@ -125,9 +126,14 @@ class InstanceExtractor:
|
|
|
125
126
|
fdt_sw.property("cpus", pack_cpu_ids(cpus.available))
|
|
126
127
|
|
|
127
128
|
def _add_memory_properties_sw(self, fdt_sw, memory):
|
|
128
|
-
"""Add memory
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
"""Add one memory@<idx> request node per requested size (or live chunk)."""
|
|
130
|
+
entries = list(memory.requested.items()) or [(r.node, r.size) for r in memory.regions]
|
|
131
|
+
for idx, (node, size) in enumerate(entries):
|
|
132
|
+
fdt_sw.begin_node(f"memory@{idx}")
|
|
133
|
+
fdt_sw.property_u64("size", size)
|
|
134
|
+
if node != ANY_NODE:
|
|
135
|
+
fdt_sw.property_u32("numa-node-id", node)
|
|
136
|
+
fdt_sw.end_node()
|
|
131
137
|
|
|
132
138
|
def _add_devices_section_sw(self, fdt_sw, devices):
|
|
133
139
|
"""Add devices section using FdtSw."""
|
|
@@ -244,78 +250,6 @@ class InstanceExtractor:
|
|
|
244
250
|
|
|
245
251
|
fdt_sw.end_node()
|
|
246
252
|
|
|
247
|
-
def _add_resources_section(self, parent_offset: int, tree: GlobalDeviceTree):
|
|
248
|
-
"""Add resources section to DTB."""
|
|
249
|
-
resources_offset = self.fdt.add_subnode(parent_offset, "resources")
|
|
250
|
-
|
|
251
|
-
# Add CPU information
|
|
252
|
-
self._add_cpu_section(resources_offset, tree.hardware.cpus)
|
|
253
|
-
|
|
254
|
-
# Add memory information
|
|
255
|
-
self._add_memory_section(resources_offset, tree.hardware.memory)
|
|
256
|
-
|
|
257
|
-
# Add device information
|
|
258
|
-
self._add_devices_section(resources_offset, tree.hardware.devices)
|
|
259
|
-
|
|
260
|
-
def _add_cpu_section(self, parent_offset: int, cpus):
|
|
261
|
-
"""Add CPU section to DTB."""
|
|
262
|
-
cpus_offset = self.fdt.add_subnode(parent_offset, "cpus")
|
|
263
|
-
self.fdt.setprop_u32(cpus_offset, "total", cpus.total)
|
|
264
|
-
|
|
265
|
-
self.fdt.setprop(cpus_offset, "host-reserved", pack_cpu_ids(cpus.host_reserved))
|
|
266
|
-
self.fdt.setprop(cpus_offset, "available", pack_cpu_ids(cpus.available))
|
|
267
|
-
|
|
268
|
-
def _add_memory_section(self, parent_offset: int, memory):
|
|
269
|
-
"""Add memory section to DTB."""
|
|
270
|
-
memory_offset = self.fdt.add_subnode(parent_offset, "memory")
|
|
271
|
-
self.fdt.setprop_u64(memory_offset, "total-bytes", memory.total_bytes)
|
|
272
|
-
self.fdt.setprop_u64(memory_offset, "host-reserved-bytes", memory.host_reserved_bytes)
|
|
273
|
-
self.fdt.setprop_u64(memory_offset, "memory-pool-base", memory.memory_pool_base)
|
|
274
|
-
self.fdt.setprop_u64(memory_offset, "memory-pool-bytes", memory.memory_pool_bytes)
|
|
275
|
-
|
|
276
|
-
def _add_devices_section(self, parent_offset: int, devices):
|
|
277
|
-
"""Add devices section to DTB."""
|
|
278
|
-
devices_offset = self.fdt.add_subnode(parent_offset, "devices")
|
|
279
|
-
|
|
280
|
-
for name, device_info in devices.items():
|
|
281
|
-
device_offset = self.fdt.add_subnode(devices_offset, name)
|
|
282
|
-
self.fdt.setprop_str(device_offset, "compatible", device_info.compatible)
|
|
283
|
-
|
|
284
|
-
if device_info.pci_id:
|
|
285
|
-
self.fdt.setprop_str(device_offset, "pci-id", device_info.pci_id)
|
|
286
|
-
|
|
287
|
-
if device_info.sriov_vfs is not None:
|
|
288
|
-
self.fdt.setprop_u32(device_offset, "sriov-vfs", device_info.sriov_vfs)
|
|
289
|
-
|
|
290
|
-
if device_info.host_reserved_vf is not None:
|
|
291
|
-
self.fdt.setprop_u32(
|
|
292
|
-
device_offset, "host-reserved-vf", device_info.host_reserved_vf
|
|
293
|
-
)
|
|
294
|
-
|
|
295
|
-
if device_info.available_vfs:
|
|
296
|
-
import struct
|
|
297
|
-
|
|
298
|
-
vfs_data = struct.pack(
|
|
299
|
-
">" + "I" * len(device_info.available_vfs), *device_info.available_vfs
|
|
300
|
-
)
|
|
301
|
-
self.fdt.setprop(device_offset, "available-vfs", vfs_data)
|
|
302
|
-
|
|
303
|
-
if device_info.namespaces is not None:
|
|
304
|
-
self.fdt.setprop_u32(device_offset, "namespaces", device_info.namespaces)
|
|
305
|
-
|
|
306
|
-
if device_info.host_reserved_ns is not None:
|
|
307
|
-
self.fdt.setprop_u32(
|
|
308
|
-
device_offset, "host-reserved-ns", device_info.host_reserved_ns
|
|
309
|
-
)
|
|
310
|
-
|
|
311
|
-
if device_info.available_ns:
|
|
312
|
-
import struct
|
|
313
|
-
|
|
314
|
-
ns_data = struct.pack(
|
|
315
|
-
">" + "I" * len(device_info.available_ns), *device_info.available_ns
|
|
316
|
-
)
|
|
317
|
-
self.fdt.setprop(device_offset, "available-ns", ns_data)
|
|
318
|
-
|
|
319
253
|
def _add_instances_section(self, parent_offset: int, tree: GlobalDeviceTree):
|
|
320
254
|
"""Add instances section to DTB."""
|
|
321
255
|
instances_offset = self.fdt.add_subnode(parent_offset, "instances")
|