| 60 | } |
| 61 | |
| 62 | static void decisions() { |
| 63 | // two nodes, the card on node 1: restricted to node 1's 64 logical CPUs, the pool keeps the quota's 12 workers |
| 64 | { |
| 65 | const auto d = cpu::decide_card_node(pod()); |
| 66 | expect(d.on && d.why.empty(), "pod: restricted (" + d.why + ")"); |
| 67 | expect(d.node == 1, "pod: node 1"); |
| 68 | expect(d.cpus == cpus_of(machine(32, 32), 1) && d.cpus.size() == 64, "pod: node 1's 64 CPUs"); |
| 69 | expect(d.node_cores == 32 && d.node_workers == 12, "pod: 32 cores, 12 workers on the node (quota)"); |
| 70 | } |
| 71 | // the card on node 0 |
| 72 | { |
| 73 | auto in = pod(); |
| 74 | in.card_nodes = {0}; |
| 75 | const auto d = cpu::decide_card_node(in); |
| 76 | expect(d.on && d.node == 0 && d.cpus == cpus_of(in.mask, 0), "card on node 0: node 0's CPUs"); |
| 77 | } |
| 78 | // one node: nothing |
| 79 | { |
| 80 | auto in = pod(); |
| 81 | in.nodes_with_cpus = 1; |
| 82 | const auto d = cpu::decide_card_node(in); |
| 83 | expect(!d.on && d.why == "one NUMA node" && d.cpus.empty(), "one node: left as is"); |
| 84 | } |
| 85 | // the switch off |
| 86 | { |
| 87 | auto in = pod(); |
| 88 | in.switch_off = true; |
| 89 | const auto d = cpu::decide_card_node(in); |
| 90 | expect(!d.on && d.why == "STRATA_NUMA_CARD=0", "switch off: left as is"); |
| 91 | } |
| 92 | // the card's node not known (sysfs -1 or unreadable) |
| 93 | { |
| 94 | auto in = pod(); |
| 95 | in.card_nodes = {-1}; |
| 96 | expect(!cpu::decide_card_node(in).on, "card node -1: left as is"); |
| 97 | in.card_nodes = {}; |
| 98 | expect(!cpu::decide_card_node(in).on, "no card: left as is"); |
| 99 | } |
| 100 | // two cards on different nodes; two on the same node |
| 101 | { |
| 102 | auto in = pod(); |
| 103 | in.card_nodes = {1, 0}; |
| 104 | const auto d = cpu::decide_card_node(in); |
| 105 | expect(!d.on && d.why == "the cards sit on different NUMA nodes", "cards on nodes 1 and 0: left as is"); |
| 106 | in.card_nodes = {1, 1}; |
| 107 | expect(cpu::decide_card_node(in).on, "two cards on node 1: restricted"); |
| 108 | in.card_nodes = {1, -1}; |
| 109 | expect(!cpu::decide_card_node(in).on, "one card's node unknown: left as is"); |
| 110 | } |
| 111 | // a process already restricted to one node (taskset / numactl / cpuset): left as is, also when it is the other node |
| 112 | { |
| 113 | auto in = pod(); |
| 114 | std::vector<cpu::CardNodeCpu> one; |
| 115 | for (const auto& c : in.mask) |
| 116 | if (c.node == 0) one.push_back(c); |
| 117 | in.mask = one; |
| 118 | const auto d = cpu::decide_card_node(in); |
| 119 | expect(!d.on && d.why == "the process already runs on one NUMA node", "pre-restricted to node 0: left as is"); |