update
This commit is contained in:
parent
232a325ada
commit
262dbf710d
|
|
@ -27,20 +27,18 @@ function saveCoreState(array $state): void
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
NUMA + SMT TOPOLOGY (SOURCE OF TRUTH)
|
NUMA TOPOLOGY
|
||||||
--------------------------------------------------------- */
|
--------------------------------------------------------- */
|
||||||
|
|
||||||
function getNumaTopology(): array
|
function getNumaTopology(): array
|
||||||
{
|
{
|
||||||
$nodes = [];
|
$nodes = [];
|
||||||
|
|
||||||
/* discover NUMA nodes */
|
|
||||||
foreach (glob('/sys/devices/system/node/node*') as $nodePath) {
|
foreach (glob('/sys/devices/system/node/node*') as $nodePath) {
|
||||||
$node = (int)str_replace('node', '', basename($nodePath));
|
$node = (int)str_replace('node', '', basename($nodePath));
|
||||||
$nodes[$node] = [];
|
$nodes[$node] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* map cpu -> node -> core_id */
|
|
||||||
foreach (glob('/sys/devices/system/cpu/cpu[0-9]*') as $cpuPath) {
|
foreach (glob('/sys/devices/system/cpu/cpu[0-9]*') as $cpuPath) {
|
||||||
$cpu = (int)str_replace('cpu', '', basename($cpuPath));
|
$cpu = (int)str_replace('cpu', '', basename($cpuPath));
|
||||||
$topo = "$cpuPath/topology";
|
$topo = "$cpuPath/topology";
|
||||||
|
|
@ -64,12 +62,11 @@ function getNumaTopology(): array
|
||||||
$nodes[$node][$coreId][] = $cpu;
|
$nodes[$node][$coreId][] = $cpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* normalize ordering */
|
|
||||||
ksort($nodes);
|
ksort($nodes);
|
||||||
foreach ($nodes as &$cores) {
|
foreach ($nodes as &$cores) {
|
||||||
ksort($cores);
|
ksort($cores);
|
||||||
foreach ($cores as &$threads) {
|
foreach ($cores as &$threads) {
|
||||||
sort($threads); // primary thread first
|
sort($threads);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,37 +74,50 @@ function getNumaTopology(): array
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
BUILD GLOBAL ROUND-ROBIN PLAN
|
NUMA-AWARE ROUND-ROBIN PLAN
|
||||||
EVEN CPUs FIRST → ODD CPUs
|
|
||||||
--------------------------------------------------------- */
|
--------------------------------------------------------- */
|
||||||
|
|
||||||
function buildAllocationPlan(array $nodes): array
|
function buildAllocationPlan(array $nodes): array
|
||||||
{
|
{
|
||||||
|
$perNode = [];
|
||||||
|
|
||||||
|
/* build per-node even → odd cpu lists */
|
||||||
|
foreach ($nodes as $node => $cores) {
|
||||||
$even = [];
|
$even = [];
|
||||||
$odd = [];
|
$odd = [];
|
||||||
|
|
||||||
foreach ($nodes as $node => $cores) {
|
foreach ($cores as $threads) {
|
||||||
foreach ($cores as $coreId => $threads) {
|
|
||||||
foreach ($threads as $cpu) {
|
foreach ($threads as $cpu) {
|
||||||
$entry = [
|
|
||||||
"node" => $node,
|
|
||||||
"cpu" => $cpu
|
|
||||||
];
|
|
||||||
|
|
||||||
if (($cpu % 2) === 0) {
|
if (($cpu % 2) === 0) {
|
||||||
$even[] = $entry;
|
$even[] = $cpu;
|
||||||
} else {
|
} else {
|
||||||
$odd[] = $entry;
|
$odd[] = $cpu;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* deterministic ordering */
|
sort($even);
|
||||||
usort($even, fn($a, $b) => $a["cpu"] <=> $b["cpu"]);
|
sort($odd);
|
||||||
usort($odd, fn($a, $b) => $a["cpu"] <=> $b["cpu"]);
|
|
||||||
|
|
||||||
return array_merge($even, $odd);
|
$perNode[$node] = array_merge($even, $odd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* interleave nodes (true NUMA rotation) */
|
||||||
|
$plan = [];
|
||||||
|
$max = max(array_map('count', $perNode));
|
||||||
|
|
||||||
|
for ($i = 0; $i < $max; $i++) {
|
||||||
|
foreach ($perNode as $node => $cpus) {
|
||||||
|
if (isset($cpus[$i])) {
|
||||||
|
$plan[] = [
|
||||||
|
"node" => $node,
|
||||||
|
"cpu" => $cpus[$i]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $plan;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
|
|
@ -141,12 +151,9 @@ function allocateCore(int $serviceId): array
|
||||||
function freeCore(int $serviceId): void
|
function freeCore(int $serviceId): void
|
||||||
{
|
{
|
||||||
$state = loadCoreState();
|
$state = loadCoreState();
|
||||||
|
|
||||||
if (isset($state["allocations"][$serviceId])) {
|
|
||||||
unset($state["allocations"][$serviceId]);
|
unset($state["allocations"][$serviceId]);
|
||||||
saveCoreState($state);
|
saveCoreState($state);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function getServiceCore(int $serviceId): ?array
|
function getServiceCore(int $serviceId): ?array
|
||||||
{
|
{
|
||||||
|
|
@ -270,9 +277,9 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && $_POST["action"] === "edit") {
|
||||||
];
|
];
|
||||||
|
|
||||||
$new = $row;
|
$new = $row;
|
||||||
$alloc = getServiceCore($id);
|
$alloc = getServiceCore($new["id"]);
|
||||||
if ($alloc === null) {
|
if ($alloc === null) {
|
||||||
$alloc = allocateCore($id);
|
$alloc = allocateCore($new["id"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$core = (int)$alloc["cpu"];
|
$core = (int)$alloc["cpu"];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue