Skip to content

Commit e43d651

Browse files
jkool702jkool702
authored andcommitted
preemptive NUMA fixes
1 parent 4ad9633 commit e43d651

11 files changed

Lines changed: 4533 additions & 3969 deletions

File tree

forkrun_ring.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,11 @@ static int ring_indexer_numa_main(int argc, char **argv) {
10341034
char tail_buf[65536];
10351035
uint64_t actual_start = 0;
10361036
uint32_t last_major_seen = 0;
1037+
uint32_t last_node_id = 0;
10371038

10381039
while (read(index_pipe, &pkt, sizeof(pkt)) == sizeof(pkt)) {
10391040
if (pkt.major_id == UINT32_MAX) break;
1041+
last_node_id = pkt.node_id;
10401042

10411043
uint64_t chunk_end = pkt.offset + pkt.length;
10421044
uint64_t actual_end = chunk_end;
@@ -1085,13 +1087,17 @@ static int ring_indexer_numa_main(int argc, char **argv) {
10851087
}
10861088

10871089
if (pkt.major_id == UINT32_MAX && actual_start < pkt.offset) {
1090+
// Guard against UINT32_MAX wrap-around sentinel confusion
1091+
uint32_t final_major = (last_major_seen < UINT32_MAX - 1) ? last_major_seen + 1 : last_major_seen;
10881092
struct ScannerTask final_task = {
1089-
.major_id = last_major_seen + 1,
1093+
.major_id = final_major,
10901094
.pad = 0,
10911095
.start_off = actual_start,
10921096
.length = pkt.offset - actual_start
10931097
};
1094-
write(node_pipes[0], &final_task, sizeof(final_task));
1098+
// Route exactly to the last node instead of defaulting to 0
1099+
int target = node_pipes[last_node_id % num_node_pipes];
1100+
write(target, &final_task, sizeof(final_task));
10951101
}
10961102

10971103
xfree(node_pipes);
@@ -2173,7 +2179,9 @@ static int ring_ack_main(int argc, char **argv) {
21732179

21742180
struct SharedState *local_state = (my_numa_node != -1 && my_numa_node < (int)global_num_nodes) ? &state[my_numa_node] : &state[0];
21752181

2182+
uint64_t my_idx;
21762183
if (worker_last_cnt > 0) {
2184+
my_idx = worker_last_idx;
21772185
if (local_state && local_state->numa_enabled) {
21782186
op.major_idx = worker_last_major;
21792187
op.minor_idx = worker_last_minor;
@@ -2188,15 +2196,26 @@ static int ring_ack_main(int argc, char **argv) {
21882196
if (local_state && local_state->numa_enabled) {
21892197
op.major_idx = (uint32_t)atoi(get_string_value("RING_MAJOR"));
21902198
op.minor_idx = (uint32_t)atoi(get_string_value("RING_MINOR"));
2199+
my_idx = (uint64_t)atoll(get_string_value("RING_BATCH_IDX"));
21912200
} else {
21922201
op.major_idx = (uint32_t)atoi(get_string_value("RING_BATCH_IDX"));
21932202
op.minor_idx = 0;
2203+
my_idx = op.major_idx;
21942204
}
21952205
}
21962206

21972207
if (fd_fallow > 0) {
2198-
struct IndexPacket ip = { .idx = op.major_idx, .cnt = op.cnt };
2199-
SYS_CHK(write(fd_fallow, &ip, sizeof(ip)));
2208+
if (local_state && local_state->numa_enabled) {
2209+
// NUMA MODE: Push exact physical byte coordinates to fallow_phys
2210+
uint64_t start = local_state->offset_ring[my_idx & RING_MASK] & ~FLAG_PARTIAL_BATCH;
2211+
uint64_t end = local_state->end_ring[(my_idx + op.cnt - 1) & RING_MASK];
2212+
struct PhysPacket pp = { .off = start, .len = end - start };
2213+
SYS_CHK(write(fd_fallow, &pp, sizeof(pp)));
2214+
} else {
2215+
// FLAT MODE: Legacy behavior
2216+
struct IndexPacket ip = { .idx = op.major_idx, .cnt = op.cnt };
2217+
SYS_CHK(write(fd_fallow, &ip, sizeof(ip)));
2218+
}
22002219
}
22012220

22022221
if (fd_target > 0) {

frun.bash

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,11 @@ toc() { :; }
278278
ring_pipe fd_fallow_r fd_fallow_w
279279
(
280280
exec {fd_fallow_w}>&-
281-
ring_fallow ${fd_fallow_r} ${fd_write}
281+
if (( FORKRUN_NUM_NODES > 1 )); then
282+
ring_fallow_phys ${fd_fallow_r} ${fd_write}
283+
else
284+
ring_fallow ${fd_fallow_r} ${fd_write}
285+
fi
282286
) &
283287
exec {fd_fallow_r}<&-
284288

@@ -365,8 +369,9 @@ toc() { :; }
365369
shift 2
366370
ring_worker inc $fd_read
367371
while ring_claim; do
368-
[[ "$REPLY" == "0" ]] && break
369-
'"$pCode"'
372+
if [[ "$REPLY" != "0" ]]; then
373+
'"$pCode"'
374+
fi
370375
'"${ring_ack_str}"'
371376
done
372377
ring_worker dec

ring_loadables/.time

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
real 0m1.724s
2-
user 0m16.051s
3-
sys 0m26.836s

0 commit comments

Comments
 (0)