kerf-multikernel 0.2.0__tar.gz → 0.3.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.2.0 → kerf_multikernel-0.3.0}/PKG-INFO +2 -3
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/README.md +1 -1
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/pyproject.toml +1 -2
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/__init__.py +1 -1
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/cli.py +1 -1
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/create/main.py +17 -14
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/data/kerf-init +0 -0
- kerf_multikernel-0.3.0/src/kerf/devices.py +87 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/dtc/extractor.py +12 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/dtc/overlay.py +31 -12
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/dtc/parser.py +92 -19
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/dtc/validator.py +3 -2
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/exec/main.py +0 -3
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/init/main.py +109 -47
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/kill/main.py +8 -1
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/models.py +18 -1
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/pool_diff.py +17 -4
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/runtime.py +28 -1
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/show/main.py +2 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/update/main.py +48 -101
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/LICENSE +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/baseline.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/console/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/console/main.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/create/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/data/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/daxfs/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/daxfs/mkdaxfs.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/delete/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/delete/main.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/docker/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/docker/image.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/dtc/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/dtc/cells.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/dtc/reporter.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/dump/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/dump/main.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/exceptions.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/exec/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/init/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/kill/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/load/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/load/main.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/metadata.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/resources.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/show/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/topology.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/unload/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/unload/main.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/update/__init__.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.0}/src/kerf/utils.py +0 -0
- {kerf_multikernel-0.2.0 → kerf_multikernel-0.3.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.3.0
|
|
4
4
|
Summary: Multikernel Management CLI tool
|
|
5
5
|
Author: Cong Wang
|
|
6
6
|
Requires-Python: >=3.9,<4.0
|
|
@@ -14,7 +14,6 @@ Requires-Dist: click (>=8.0.0,<9.0.0)
|
|
|
14
14
|
Requires-Dist: pylibfdt (>=1.7.0,<2.0.0)
|
|
15
15
|
Requires-Dist: pyudev (>=0.24.0,<0.25.0)
|
|
16
16
|
Requires-Dist: pyyaml (>=6.0,<7.0)
|
|
17
|
-
Requires-Dist: rdtsc (>=0.2.1,<0.3.0)
|
|
18
17
|
Description-Content-Type: text/markdown
|
|
19
18
|
|
|
20
19
|

|
|
@@ -151,7 +150,7 @@ Baseline DTB (static)
|
|
|
151
150
|
kerf init --cpus=4-7 --memory=2GB
|
|
152
151
|
|
|
153
152
|
# Initialize with CPUs, per-node memory and devices
|
|
154
|
-
kerf init --cpus=4-31 --memory=8GB@0,8GB@1 --devices=
|
|
153
|
+
kerf init --cpus=4-31 --memory=8GB@0,8GB@1 --devices=nvme0n1,enp9s0
|
|
155
154
|
|
|
156
155
|
# Re-run to reshape the live pool; "none" asks for none of a resource
|
|
157
156
|
kerf init --cpus=4-15 --memory=4GB
|
|
@@ -132,7 +132,7 @@ Baseline DTB (static)
|
|
|
132
132
|
kerf init --cpus=4-7 --memory=2GB
|
|
133
133
|
|
|
134
134
|
# Initialize with CPUs, per-node memory and devices
|
|
135
|
-
kerf init --cpus=4-31 --memory=8GB@0,8GB@1 --devices=
|
|
135
|
+
kerf init --cpus=4-31 --memory=8GB@0,8GB@1 --devices=nvme0n1,enp9s0
|
|
136
136
|
|
|
137
137
|
# Re-run to reshape the live pool; "none" asks for none of a resource
|
|
138
138
|
kerf init --cpus=4-15 --memory=4GB
|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
4
4
|
|
|
5
5
|
[tool.poetry]
|
|
6
6
|
name = "kerf-multikernel"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
description = "Multikernel Management CLI tool"
|
|
9
9
|
authors = ["Cong Wang"]
|
|
10
10
|
readme = "README.md"
|
|
@@ -19,7 +19,6 @@ pylibfdt = "^1.7.0"
|
|
|
19
19
|
click = "^8.0.0"
|
|
20
20
|
pyyaml = "^6.0"
|
|
21
21
|
pyudev = "^0.24.0"
|
|
22
|
-
rdtsc = "^0.2.1"
|
|
23
22
|
|
|
24
23
|
[tool.poetry.group.dev.dependencies]
|
|
25
24
|
pytest = "^7.0.0"
|
|
@@ -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.3.0"
|
|
23
23
|
__author__ = "Cong Wang"
|
|
24
24
|
|
|
25
25
|
# Export main runtime components for easy access
|
|
@@ -31,7 +31,7 @@ from .console.main import console
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
@click.group()
|
|
34
|
-
@click.version_option(version="0.
|
|
34
|
+
@click.version_option(version="0.3.0", prog_name="kerf")
|
|
35
35
|
@click.option("--debug", is_flag=True, help="Enable debug mode")
|
|
36
36
|
@click.pass_context
|
|
37
37
|
def main(ctx, debug):
|
|
@@ -341,19 +341,16 @@ def parse_memory_base(base_spec: str) -> int:
|
|
|
341
341
|
|
|
342
342
|
def parse_device_list(device_spec: Optional[str]) -> List[str]:
|
|
343
343
|
"""
|
|
344
|
-
Parse device specification string into list of device
|
|
344
|
+
Parse device specification string into list of device references.
|
|
345
345
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
- "enp9s0_dev,nvme0" (comma-separated device names)
|
|
349
|
-
|
|
350
|
-
Device names must match device node names in the baseline DTB.
|
|
346
|
+
A reference is an alias ("nvme0"), a PCI address ("0000:4f:01.0") or a
|
|
347
|
+
device node name ("pci_0000_4f_01_0") from the baseline, comma-separated.
|
|
351
348
|
|
|
352
349
|
Args:
|
|
353
|
-
device_spec: Device specification string or None
|
|
350
|
+
device_spec: Device specification string or None
|
|
354
351
|
|
|
355
352
|
Returns:
|
|
356
|
-
List of device
|
|
353
|
+
List of device references (e.g., ["nvme0", "0000:09:00.0"])
|
|
357
354
|
"""
|
|
358
355
|
if not device_spec:
|
|
359
356
|
return []
|
|
@@ -443,8 +440,8 @@ def dump_overlay_for_debug(
|
|
|
443
440
|
@click.option(
|
|
444
441
|
"--devices",
|
|
445
442
|
"-d",
|
|
446
|
-
help='
|
|
447
|
-
|
|
443
|
+
help='Pool devices to assign, by alias, PCI address or node name '
|
|
444
|
+
'(comma-separated, e.g. "nvme0,0000:09:00.0"), as listed by kerf show.',
|
|
448
445
|
)
|
|
449
446
|
@click.option(
|
|
450
447
|
"--input",
|
|
@@ -507,7 +504,7 @@ def create( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
|
507
504
|
kerf create database --cpus=128-142 --memory=8GB --memory-base=0x100000000
|
|
508
505
|
|
|
509
506
|
# Create instance with devices
|
|
510
|
-
kerf create compute --cpus=128-142 --memory=4GB --devices=
|
|
507
|
+
kerf create compute --cpus=128-142 --memory=4GB --devices=enp9s0
|
|
511
508
|
|
|
512
509
|
# Create instance with explicit single APIC ID
|
|
513
510
|
kerf create web-server --cpus=128 --memory=2GB
|
|
@@ -711,13 +708,20 @@ def create( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
|
711
708
|
else:
|
|
712
709
|
validate_memory_allocation(modified, memory_base_addr, memory_bytes)
|
|
713
710
|
|
|
711
|
+
device_nodes = []
|
|
712
|
+
for ref in device_list:
|
|
713
|
+
node = modified.hardware.find_device(ref)
|
|
714
|
+
if node is None:
|
|
715
|
+
raise ResourceError(f"Device '{ref}' is not in the pool")
|
|
716
|
+
device_nodes.append(node)
|
|
717
|
+
|
|
714
718
|
# Create instance resources with topology settings
|
|
715
719
|
uring_enabled = uring or uring_sq_entries is not None or uring_cq_entries is not None or uring_shim_pages is not None
|
|
716
720
|
resources = InstanceResources(
|
|
717
721
|
cpus=cpu_list,
|
|
718
722
|
memory_base=memory_base_addr,
|
|
719
723
|
memory_bytes=memory_bytes,
|
|
720
|
-
devices=
|
|
724
|
+
devices=device_nodes,
|
|
721
725
|
numa_nodes=numa_node_list,
|
|
722
726
|
cpu_affinity=cpu_affinity,
|
|
723
727
|
memory_policy=memory_policy,
|
|
@@ -793,8 +797,7 @@ def create( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
|
793
797
|
|
|
794
798
|
click.echo(f"✓ Created instance '{name}' (transaction {tx_id})")
|
|
795
799
|
if verbose:
|
|
796
|
-
|
|
797
|
-
instance = current.instances[name]
|
|
800
|
+
instance = manager.read_instance(name)
|
|
798
801
|
click.echo(f" Instance ID: {instance.id}")
|
|
799
802
|
click.echo(f" CPUs: {', '.join(map(str, instance.resources.cpus))}")
|
|
800
803
|
if instance.resources.cpu_affinity:
|
|
Binary file
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Copyright 2026 Multikernel Technologies, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
Naming of pool PCI devices.
|
|
17
|
+
|
|
18
|
+
A pool device is identified by its PCI address and nothing else: host
|
|
19
|
+
names such as nvme0n1 or enp9s0 are probe-order or udev artifacts that
|
|
20
|
+
differ between kernels, while the address is fixed by the fabric. The
|
|
21
|
+
device node is named after the address, and a standard device tree
|
|
22
|
+
/aliases entry gives the device a stable name: the name the device has in
|
|
23
|
+
the kernel that owns it, which a spawned kernel then applies ("nvme0"
|
|
24
|
+
stays nvme0 and its namespaces nvme0n1, "enp9s0" stays enp9s0).
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
import re
|
|
28
|
+
from typing import Optional, Tuple
|
|
29
|
+
|
|
30
|
+
PCI_ID_RE = re.compile(r'^([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,2}):([0-9a-fA-F]{1,2})\.([0-9a-fA-F])$')
|
|
31
|
+
PCI_NODE_RE = re.compile(r'^pci_([0-9a-fA-F]{1,4})_([0-9a-fA-F]{1,2})_([0-9a-fA-F]{1,2})_([0-9a-fA-F])$')
|
|
32
|
+
ALIAS_RE = re.compile(r'^[a-z0-9-]{1,31}$')
|
|
33
|
+
NVME_NAME_RE = re.compile(r'^(nvme\d+)(?:n\d+(p\d+)?)?$')
|
|
34
|
+
IFNAMSIZ = 16
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def normalize_pci_id(text: str) -> Optional[str]:
|
|
38
|
+
"""Canonical "dddd:bb:ss.f" for a PCI address or the node name derived from one."""
|
|
39
|
+
match = PCI_ID_RE.match(text) or PCI_NODE_RE.match(text)
|
|
40
|
+
if not match:
|
|
41
|
+
return None
|
|
42
|
+
domain, bus, slot, func = (int(part, 16) for part in match.groups())
|
|
43
|
+
return f"{domain:04x}:{bus:02x}:{slot:02x}.{func:x}"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def pci_node_name(pci_id: str) -> str:
|
|
47
|
+
"""Device node name for a PCI address, as the kernel derives it."""
|
|
48
|
+
normalized = normalize_pci_id(pci_id)
|
|
49
|
+
if normalized is None:
|
|
50
|
+
raise ValueError(f"Invalid PCI ID '{pci_id}', expected DDDD:BB:SS.F")
|
|
51
|
+
return "pci_" + normalized.replace(":", "_").replace(".", "_")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def split_alias(entry: str) -> Tuple[str, Optional[str]]:
|
|
55
|
+
"""Split a "device" or "device=alias" request into its parts."""
|
|
56
|
+
name, sep, alias = entry.partition("=")
|
|
57
|
+
if not sep:
|
|
58
|
+
return name, None
|
|
59
|
+
if not ALIAS_RE.match(alias):
|
|
60
|
+
raise ValueError(
|
|
61
|
+
f"Invalid alias '{alias}' for device '{name}': "
|
|
62
|
+
"use 1 to 31 characters from a-z, 0-9 and '-', like nvme0 or enp9s0"
|
|
63
|
+
)
|
|
64
|
+
return name, alias
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def is_partition(host_name: str) -> bool:
|
|
68
|
+
match = NVME_NAME_RE.match(host_name)
|
|
69
|
+
return bool(match and match.group(2))
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def default_alias(host_name: str, compatible: Optional[str]) -> Optional[str]:
|
|
73
|
+
"""
|
|
74
|
+
The alias a host device name implies, None when it implies nothing.
|
|
75
|
+
|
|
76
|
+
An NVMe name carries its controller name, which the namespaces follow.
|
|
77
|
+
A network interface name is the alias itself, when the kernel can
|
|
78
|
+
apply it. A raw PCI address implies no name at all.
|
|
79
|
+
"""
|
|
80
|
+
if normalize_pci_id(host_name):
|
|
81
|
+
return None
|
|
82
|
+
match = NVME_NAME_RE.match(host_name)
|
|
83
|
+
if match:
|
|
84
|
+
return match.group(1)
|
|
85
|
+
if compatible == "pci-network" and ALIAS_RE.match(host_name) and len(host_name) < IFNAMSIZ:
|
|
86
|
+
return host_name
|
|
87
|
+
return None
|
|
@@ -109,6 +109,8 @@ class InstanceExtractor:
|
|
|
109
109
|
|
|
110
110
|
fdt_sw.end_node() # End resources
|
|
111
111
|
|
|
112
|
+
self._add_aliases_sw(fdt_sw, tree.hardware.devices)
|
|
113
|
+
|
|
112
114
|
if tree.instances:
|
|
113
115
|
self._add_instances_section_sw(fdt_sw, tree.instances)
|
|
114
116
|
|
|
@@ -192,6 +194,16 @@ class InstanceExtractor:
|
|
|
192
194
|
|
|
193
195
|
fdt_sw.end_node()
|
|
194
196
|
|
|
197
|
+
def _add_aliases_sw(self, fdt_sw, devices):
|
|
198
|
+
aliases = {info.alias: name for name, info in (devices or {}).items() if info.alias}
|
|
199
|
+
if not aliases:
|
|
200
|
+
return
|
|
201
|
+
|
|
202
|
+
fdt_sw.begin_node("aliases")
|
|
203
|
+
for alias, name in aliases.items():
|
|
204
|
+
fdt_sw.property_string(alias, f"/resources/devices/{name}")
|
|
205
|
+
fdt_sw.end_node()
|
|
206
|
+
|
|
195
207
|
def _add_instances_section_sw(self, fdt_sw, instances):
|
|
196
208
|
"""Add instances section using FdtSw."""
|
|
197
209
|
fdt_sw.begin_node("instances")
|
|
@@ -20,7 +20,7 @@ overlays (DTBO) that represent incremental changes to the device tree state.
|
|
|
20
20
|
"""
|
|
21
21
|
|
|
22
22
|
import struct
|
|
23
|
-
from typing import Optional, Set, Tuple
|
|
23
|
+
from typing import Dict, Optional, Set, Tuple
|
|
24
24
|
|
|
25
25
|
import libfdt
|
|
26
26
|
|
|
@@ -77,7 +77,9 @@ class OverlayGenerator:
|
|
|
77
77
|
if name not in modified.instances:
|
|
78
78
|
instances_to_remove.add(name)
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
pci_ids = {name: d.pci_id for name, d in modified.hardware.devices.items() if d.pci_id}
|
|
81
|
+
return self._create_overlay_dtb(instances_to_add, instances_to_update, instances_to_remove,
|
|
82
|
+
pci_ids)
|
|
81
83
|
|
|
82
84
|
def generate_removal_overlay(self, instance_name: str) -> bytes:
|
|
83
85
|
"""
|
|
@@ -94,7 +96,8 @@ class OverlayGenerator:
|
|
|
94
96
|
"""
|
|
95
97
|
return self._create_overlay_dtb({}, {}, {instance_name})
|
|
96
98
|
|
|
97
|
-
def generate_update_overlay(self, instance_name: str, old_instance, new_instance
|
|
99
|
+
def generate_update_overlay(self, instance_name: str, old_instance, new_instance,
|
|
100
|
+
pci_ids: Optional[Dict[str, str]] = None) -> bytes:
|
|
98
101
|
"""
|
|
99
102
|
Generate resource update overlay for an existing instance.
|
|
100
103
|
|
|
@@ -106,6 +109,7 @@ class OverlayGenerator:
|
|
|
106
109
|
instance_name: Name of the instance to update
|
|
107
110
|
old_instance: Current instance state
|
|
108
111
|
new_instance: New instance state
|
|
112
|
+
pci_ids: PCI address of each device, by the node name the instances use
|
|
109
113
|
|
|
110
114
|
Returns:
|
|
111
115
|
DTBO blob as bytes containing resource update operations
|
|
@@ -134,8 +138,9 @@ class OverlayGenerator:
|
|
|
134
138
|
|
|
135
139
|
old_devices = set(old_instance.resources.devices)
|
|
136
140
|
new_devices = set(new_instance.resources.devices)
|
|
137
|
-
|
|
138
|
-
|
|
141
|
+
pci_ids = pci_ids or {}
|
|
142
|
+
devices_to_remove = sorted(pci_ids.get(d, d) for d in old_devices - new_devices)
|
|
143
|
+
devices_to_add = sorted(pci_ids.get(d, d) for d in new_devices - old_devices)
|
|
139
144
|
|
|
140
145
|
# Single fragment with all operations
|
|
141
146
|
fdt_sw.begin_node("fragment@0")
|
|
@@ -210,7 +215,7 @@ class OverlayGenerator:
|
|
|
210
215
|
self._cpu_op(fdt_sw, "cpu-remove", diff.cpus_to_host)
|
|
211
216
|
self._cpu_op(fdt_sw, "cpu-add", diff.cpus_to_pool)
|
|
212
217
|
self._device_op(fdt_sw, "device-remove", diff.devices_to_host)
|
|
213
|
-
self._device_op(fdt_sw, "device-add", diff.devices_to_pool)
|
|
218
|
+
self._device_op(fdt_sw, "device-add", diff.devices_to_pool, diff.device_aliases)
|
|
214
219
|
|
|
215
220
|
fdt_sw.end_node() # End __overlay__
|
|
216
221
|
fdt_sw.end_node() # End fragment@0
|
|
@@ -243,7 +248,7 @@ class OverlayGenerator:
|
|
|
243
248
|
fdt_sw.end_node()
|
|
244
249
|
fdt_sw.end_node()
|
|
245
250
|
|
|
246
|
-
def _device_op(self, fdt_sw, operation, pci_ids):
|
|
251
|
+
def _device_op(self, fdt_sw, operation, pci_ids, aliases=None):
|
|
247
252
|
"""Write a device operation node, or nothing when there are no devices."""
|
|
248
253
|
if not pci_ids:
|
|
249
254
|
return
|
|
@@ -252,11 +257,14 @@ class OverlayGenerator:
|
|
|
252
257
|
for idx, pci_id in enumerate(pci_ids):
|
|
253
258
|
fdt_sw.begin_node(f"pci@{idx}")
|
|
254
259
|
fdt_sw.property_string("pci-id", pci_id)
|
|
260
|
+
if aliases and pci_id in aliases:
|
|
261
|
+
fdt_sw.property_string("alias", aliases[pci_id])
|
|
255
262
|
fdt_sw.end_node()
|
|
256
263
|
fdt_sw.end_node()
|
|
257
264
|
|
|
258
265
|
def _create_overlay_dtb(
|
|
259
|
-
self, instances_to_add: dict, instances_to_update: dict, instances_to_remove: Set[str]
|
|
266
|
+
self, instances_to_add: dict, instances_to_update: dict, instances_to_remove: Set[str],
|
|
267
|
+
pci_ids: Optional[Dict[str, str]] = None,
|
|
260
268
|
) -> bytes:
|
|
261
269
|
"""
|
|
262
270
|
Create overlay DTB with instance changes using fragment format.
|
|
@@ -265,6 +273,7 @@ class OverlayGenerator:
|
|
|
265
273
|
instances_to_add: Dict of instance name -> Instance to add
|
|
266
274
|
instances_to_update: Dict of instance name -> Instance to update
|
|
267
275
|
instances_to_remove: Set of instance names to remove
|
|
276
|
+
pci_ids: PCI address of each pool device, by node name
|
|
268
277
|
|
|
269
278
|
Returns:
|
|
270
279
|
DTBO blob as bytes
|
|
@@ -296,10 +305,6 @@ class OverlayGenerator:
|
|
|
296
305
|
|
|
297
306
|
fdt_sw.property_u64("memory-bytes", instance.resources.memory_bytes)
|
|
298
307
|
|
|
299
|
-
if instance.resources.devices:
|
|
300
|
-
stringlist_data = b'\0'.join(d.encode('utf-8') for d in instance.resources.devices) + b'\0'
|
|
301
|
-
fdt_sw.property("device-names", stringlist_data)
|
|
302
|
-
|
|
303
308
|
if instance.resources.numa_nodes:
|
|
304
309
|
numa_data = struct.pack(
|
|
305
310
|
">" + "I" * len(instance.resources.numa_nodes), *instance.resources.numa_nodes
|
|
@@ -341,6 +346,20 @@ class OverlayGenerator:
|
|
|
341
346
|
fdt_sw.end_node() # End fragment
|
|
342
347
|
fragment_id += 1
|
|
343
348
|
|
|
349
|
+
# Devices join the instance the same way "kerf update" hands them
|
|
350
|
+
# over, by PCI address against the live pool: the kernel resolves
|
|
351
|
+
# device-names against its baseline snapshot, which never learns
|
|
352
|
+
# of devices pooled after init.
|
|
353
|
+
if instance.resources.devices:
|
|
354
|
+
fdt_sw.begin_node(f"fragment@{fragment_id:x}")
|
|
355
|
+
fdt_sw.property_string("target-path", f"{self.INSTANCES_PATH}/{name}")
|
|
356
|
+
fdt_sw.begin_node("__overlay__")
|
|
357
|
+
self._device_op(fdt_sw, "device-add",
|
|
358
|
+
[(pci_ids or {}).get(d, d) for d in instance.resources.devices])
|
|
359
|
+
fdt_sw.end_node()
|
|
360
|
+
fdt_sw.end_node()
|
|
361
|
+
fragment_id += 1
|
|
362
|
+
|
|
344
363
|
for name in instances_to_remove:
|
|
345
364
|
fdt_sw.begin_node(f"fragment@{fragment_id:x}")
|
|
346
365
|
fdt_sw.property_string("target-path", self.INSTANCES_PATH)
|
|
@@ -22,6 +22,7 @@ from typing import Dict, List, Optional
|
|
|
22
22
|
import libfdt
|
|
23
23
|
|
|
24
24
|
from ..exceptions import ParseError
|
|
25
|
+
from ..devices import pci_node_name
|
|
25
26
|
from ..pool_diff import ANY_NODE
|
|
26
27
|
from .cells import unpack_cpu_ids
|
|
27
28
|
from ..models import (
|
|
@@ -96,10 +97,25 @@ class DeviceTreeParser:
|
|
|
96
97
|
self.fdt = libfdt.Fdt(dtb_data)
|
|
97
98
|
except Exception as e:
|
|
98
99
|
raise ParseError(f"Failed to parse instance DTB: {e}") from e
|
|
99
|
-
name = self.fdt.
|
|
100
|
-
if
|
|
101
|
-
raise ParseError("Not an instance device tree: the root node carries no
|
|
102
|
-
return self._parse_instance(0, name)
|
|
100
|
+
name = self.fdt.getprop(0, 'model', libfdt.QUIET_NOTFOUND)
|
|
101
|
+
if name == -libfdt.NOTFOUND:
|
|
102
|
+
raise ParseError("Not an instance device tree: the root node carries no model")
|
|
103
|
+
return self._parse_instance(0, name.as_str())
|
|
104
|
+
|
|
105
|
+
def parse_instance_devices_from_bytes(self, dtb_data: bytes) -> Dict[str, DeviceInfo]:
|
|
106
|
+
"""The PCI devices an instance tree describes, keyed like the pool's."""
|
|
107
|
+
try:
|
|
108
|
+
self.fdt = libfdt.Fdt(dtb_data)
|
|
109
|
+
except Exception as e:
|
|
110
|
+
raise ParseError(f"Failed to parse instance DTB: {e}") from e
|
|
111
|
+
devices = {}
|
|
112
|
+
offsets = {}
|
|
113
|
+
for offset, (name, device_info) in self._parse_pci_tree().items():
|
|
114
|
+
devices[name] = device_info
|
|
115
|
+
offsets[offset] = name
|
|
116
|
+
for alias, name in self._parse_aliases(offsets).items():
|
|
117
|
+
devices[name].alias = alias
|
|
118
|
+
return devices
|
|
103
119
|
|
|
104
120
|
def _build_global_tree(self) -> GlobalDeviceTree:
|
|
105
121
|
"""Build GlobalDeviceTree from parsed FDT."""
|
|
@@ -309,29 +325,85 @@ class DeviceTreeParser:
|
|
|
309
325
|
def _parse_devices(self, resources_node: int) -> Dict[str, DeviceInfo]:
|
|
310
326
|
"""Parse device information from resources node."""
|
|
311
327
|
devices = {}
|
|
328
|
+
offsets = {}
|
|
312
329
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
return devices
|
|
317
|
-
|
|
318
|
-
# Iterate through device nodes
|
|
319
|
-
offset = self.fdt.first_subnode(devices_node)
|
|
320
|
-
while offset >= 0:
|
|
330
|
+
devices_node = self.fdt.subnode_offset(resources_node, 'devices',
|
|
331
|
+
libfdt.QUIET_NOTFOUND)
|
|
332
|
+
for offset in self._subnodes(devices_node) if devices_node >= 0 else ():
|
|
321
333
|
name = self.fdt.get_name(offset)
|
|
322
334
|
try:
|
|
323
|
-
|
|
324
|
-
|
|
335
|
+
devices[name] = self._parse_device_info(offset, name)
|
|
336
|
+
offsets[offset] = name
|
|
325
337
|
except ParseError:
|
|
326
|
-
# Skip nodes that don't have required properties (not valid devices)
|
|
327
338
|
pass
|
|
339
|
+
|
|
340
|
+
for offset, (name, device_info) in self._parse_pci_tree().items():
|
|
341
|
+
devices[name] = device_info
|
|
342
|
+
offsets[offset] = name
|
|
343
|
+
|
|
344
|
+
for alias, name in self._parse_aliases(offsets).items():
|
|
345
|
+
devices[name].alias = alias
|
|
346
|
+
|
|
347
|
+
return devices
|
|
348
|
+
|
|
349
|
+
def _parse_pci_tree(self) -> Dict[int, tuple]:
|
|
350
|
+
"""
|
|
351
|
+
PCI devices under the host-bridge nodes, keyed by node offset.
|
|
352
|
+
|
|
353
|
+
The kernel describes a device under the bus it sits on, in the
|
|
354
|
+
devicetree PCI bus binding: a bridge is recursed into, a leaf
|
|
355
|
+
carries vendor-id, and the unit address in reg names the bus,
|
|
356
|
+
device and function.
|
|
357
|
+
"""
|
|
358
|
+
found = {}
|
|
359
|
+
for bridge in self._subnodes(0):
|
|
328
360
|
try:
|
|
329
|
-
|
|
361
|
+
compatible = self.fdt.getprop(bridge, 'compatible').as_str()
|
|
330
362
|
except libfdt.FdtException:
|
|
331
|
-
|
|
332
|
-
|
|
363
|
+
continue
|
|
364
|
+
if compatible != 'multikernel,pci-host-bridge':
|
|
365
|
+
continue
|
|
366
|
+
domain = 0
|
|
367
|
+
try:
|
|
368
|
+
domain = self.fdt.getprop(bridge, 'linux,pci-domain').as_uint32()
|
|
369
|
+
except libfdt.FdtException:
|
|
370
|
+
pass
|
|
371
|
+
self._walk_pci_bus(bridge, domain, found)
|
|
372
|
+
return found
|
|
333
373
|
|
|
334
|
-
|
|
374
|
+
def _walk_pci_bus(self, bus: int, domain: int, found: Dict[int, tuple]) -> None:
|
|
375
|
+
for node in self._subnodes(bus):
|
|
376
|
+
try:
|
|
377
|
+
phys_hi = self.fdt.getprop(node, 'reg').as_uint32_list()[0]
|
|
378
|
+
except (libfdt.FdtException, IndexError):
|
|
379
|
+
continue
|
|
380
|
+
if self.fdt.getprop(node, 'vendor-id', libfdt.QUIET_NOTFOUND) == -libfdt.NOTFOUND:
|
|
381
|
+
self._walk_pci_bus(node, domain, found)
|
|
382
|
+
continue
|
|
383
|
+
pci_id = (f"{domain:04x}:{phys_hi >> 16 & 0xff:02x}:"
|
|
384
|
+
f"{phys_hi >> 11 & 0x1f:02x}.{phys_hi >> 8 & 0x7}")
|
|
385
|
+
name = pci_node_name(pci_id)
|
|
386
|
+
device_info = self._parse_device_info(node, name)
|
|
387
|
+
device_info.device_type = 'pci'
|
|
388
|
+
device_info.pci_id = pci_id
|
|
389
|
+
found[node] = (name, device_info)
|
|
390
|
+
|
|
391
|
+
def _parse_aliases(self, offsets: Dict[int, str]) -> Dict[str, str]:
|
|
392
|
+
"""Map each /aliases entry to the device node it points at."""
|
|
393
|
+
aliases = {}
|
|
394
|
+
aliases_node = self.fdt.path_offset('/aliases', libfdt.QUIET_NOTFOUND)
|
|
395
|
+
if aliases_node < 0:
|
|
396
|
+
return aliases
|
|
397
|
+
|
|
398
|
+
prop_offset = self.fdt.first_property_offset(aliases_node, libfdt.QUIET_NOTFOUND)
|
|
399
|
+
while prop_offset >= 0:
|
|
400
|
+
prop = self.fdt.get_property_by_offset(prop_offset)
|
|
401
|
+
target = self.fdt.path_offset(prop.as_str(), libfdt.QUIET_NOTFOUND)
|
|
402
|
+
if target in offsets:
|
|
403
|
+
aliases[prop.name] = offsets[target]
|
|
404
|
+
prop_offset = self.fdt.next_property_offset(prop_offset, libfdt.QUIET_NOTFOUND)
|
|
405
|
+
|
|
406
|
+
return aliases
|
|
335
407
|
|
|
336
408
|
def _parse_device_info(self, node_offset: int, name: str) -> DeviceInfo:
|
|
337
409
|
"""Parse individual device information."""
|
|
@@ -651,6 +723,7 @@ class DeviceTreeParser:
|
|
|
651
723
|
devices = [self.fdt.get_name(o) for o in self._subnodes(devices_node)]
|
|
652
724
|
except libfdt.FdtException:
|
|
653
725
|
pass
|
|
726
|
+
devices += sorted(name for name, _ in self._parse_pci_tree().values())
|
|
654
727
|
|
|
655
728
|
uring_enabled = False
|
|
656
729
|
uring_sq = None
|
|
@@ -400,6 +400,7 @@ class MultikernelValidator:
|
|
|
400
400
|
device_name = device_ref.split("_vf")[0]
|
|
401
401
|
vf_id = int(device_ref.split("_vf")[1])
|
|
402
402
|
|
|
403
|
+
device_name = tree.hardware.find_device(device_name) or device_name
|
|
403
404
|
if device_name not in tree.hardware.devices:
|
|
404
405
|
available_devices = list(tree.hardware.devices.keys())
|
|
405
406
|
error_msg = self._format_error_with_context(
|
|
@@ -430,6 +431,7 @@ class MultikernelValidator:
|
|
|
430
431
|
device_name = device_ref.split("_ns")[0]
|
|
431
432
|
ns_id = int(device_ref.split("_ns")[1])
|
|
432
433
|
|
|
434
|
+
device_name = tree.hardware.find_device(device_name) or device_name
|
|
433
435
|
if device_name not in tree.hardware.devices:
|
|
434
436
|
self.errors.append(
|
|
435
437
|
f"Instance {instance.name}: Reference to non-existent device '{device_name}'"
|
|
@@ -443,8 +445,7 @@ class MultikernelValidator:
|
|
|
443
445
|
)
|
|
444
446
|
|
|
445
447
|
else:
|
|
446
|
-
|
|
447
|
-
if device_ref not in tree.hardware.devices:
|
|
448
|
+
if tree.hardware.find_device(device_ref) is None:
|
|
448
449
|
self.errors.append(
|
|
449
450
|
f"Instance {instance.name}: Reference to non-existent device '{device_ref}'"
|
|
450
451
|
)
|
|
@@ -24,7 +24,6 @@ from pathlib import Path
|
|
|
24
24
|
from typing import Optional
|
|
25
25
|
|
|
26
26
|
import click
|
|
27
|
-
import rdtsc
|
|
28
27
|
|
|
29
28
|
from ..models import InstanceState
|
|
30
29
|
from ..utils import get_instance_id_from_name
|
|
@@ -211,8 +210,6 @@ def exec_cmd(name: Optional[str], id: Optional[int], attach_console: bool, verbo
|
|
|
211
210
|
click.echo(f"✓ Kernel image found for instance '{instance_name}'")
|
|
212
211
|
click.echo(f"Instance ID to boot: {instance_id}")
|
|
213
212
|
click.echo(f"Using reboot syscall with command: 0x{LINUX_REBOOT_CMD_MULTIKERNEL:x}")
|
|
214
|
-
tsc = rdtsc.get_cycles()
|
|
215
|
-
click.echo(f"Calling reboot syscall at TSC {tsc}")
|
|
216
213
|
else:
|
|
217
214
|
click.echo(f"Booting instance '{instance_name}' (ID: {instance_id})...")
|
|
218
215
|
|