Commit 229557c
authored
fix(timekeeping): restore monotonic clock and clocksource semantics (#2145)
* fix(timekeeping): restore monotonic clock and clocksource semantics
DragonOS used the realtime epoch as the basis for monotonic clocks and
spread clocksource cycle state across multiple owners. The resulting
updates could lose elapsed time, recurse through the timekeeper lock, and
make timeout consumers depend on wall-clock adjustments. KVM clock CPU
bring-up and interrupt-context locking also lacked transactional failure
handling.
Rework the timekeeping core around independently maintained monotonic and
raw read bases, with realtime and boottime represented as offsets. Keep
clocksource selection, watchdog state, switching, and rollback under a
single control transaction, and preserve elapsed time and fractional state
when a source changes.
Make KVM clock setup per-CPU and transactional, including AP failure
rollback. Add writer-preferred RwLock progress and explicit interrupt
context tracking so timekeeper writers cannot deadlock behind continuous
readers or acquire blocking paths from hardirq/softirq context.
Align POSIX clock reads, nanosleep restart handling, signal waits, and futex
timeouts with their Linux clock domains. Add kernel selftests, dunitest
coverage, a guest calibration workload, and a fail-closed host calibration
harness for KVM and TCG evidence.
Validation:
- x86_64 kernel build and link
- RISC-V Rust build and kernel ELF link
- 31 host calibration unit tests
- guest calibration workload static build
- QEMU runner and Python syntax checks
- KVM 2-vCPU timekeeping/restart suite: 19/19 relevant tests passed
- fixed-CPU and migrating 10,000,000-read monotonicity tests passed
Signed-off-by: longjin <longjin@dragonos.org>
* fix(timekeeping): address CI and review regressions
Serialize watchdog cleanup with clocksource registration and fully roll back partially published watchdog state. Keep hardirq nesting counters cache-line isolated and avoid the CAS loop on interrupt entry and exit.
Match Linux's settimeofday boundary after suspend, expose clocksource selftests through debugfs, and bound normal guest semantic loops while retaining the opt-in ten-million-read stress gates.
Make QEMU argv evidence fail closed, release partially initialized serial transport resources, and resolve the formatting regressions reported by CI.
Validated with make fmt, make kernel, host calibration tests, the calibration host build, and DragonOS guest timekeeping selftest and semantics suites.
Signed-off-by: longjin <longjin@dragonos.org>
* fix(timekeeping): preserve selftest execution state
Restore preemption when an already-registered rwlock writer acquisition fails, and cover the failure path in the debugfs selftest. Consolidate all selftest-only registered writer attempts behind the balanced helper.
Also preserve the underlying serial socket error in calibration diagnostics and verify both the reported detail and resource cleanup.
Validated with format and Clippy checks, the kernel build, calibration unit and host tests, and DragonOS guest timekeeping selftests.
Signed-off-by: longjin <longjin@dragonos.org>
* fix(net): snapshot bound sockets before notification
Network polling walked the bound-socket vector by index while dropping the lock around every notification. Concurrent socket teardown could remove an earlier entry, shift the vector, and make the next index skip a poll waiter entirely.
Take one coherent Arc snapshot and reuse the shared notification path for regular polling, NAPI polling, and listener teardown. Notifications still run outside the bounds lock, preserving the required lock order, while a single read-side acquisition avoids writer-fair reacquisition stalls under close-heavy workloads.
This prevents tcp_close_semantics poll timeouts during concurrent IPv4 and dual-stack reset/close stress.
Signed-off-by: longjin <longjin@dragonos.org>
* fix(process): serialize kernel stack allocation safely
Kernel stack allocation and reclamation used try_lock_irqsave().unwrap() on their shared mapper lock. Concurrent fork and exit activity therefore converted ordinary lock contention into a kernel panic, as observed when tcp_socket_test created processes on both CPUs.
Acquire KSTACK_LOCK with the blocking irqsave spin-lock operation in both paths. This preserves the existing mapper serialization and interrupt exclusion while allowing the contending CPU to wait for the current stack operation to finish.
The gVisor tcp_socket_test now completes all 184 tests without triggering the allocation race.
Signed-off-by: longjin <longjin@dragonos.org>
* fix(kernel): avoid poll allocation and TTY lock recursion
Make the network interface's bound-socket table copy-on-write. Poll and notification paths now clone only the outer Arc while interrupts are disabled, while the less frequent bind and unbind paths perform any required Vec clone. This preserves a coherent notification snapshot without O(n) IRQ-off allocation or the index-shift race fixed earlier.
Use one by-value termios snapshot for each N_TTY receive batch and pass it through the nested input helpers. The previous receive path recursively acquired the same read lock; once a termios writer queued, writer-fair admission blocked the recursive reader and deadlocked both CPUs. A value snapshot preserves consistent per-batch input semantics and removes the recursive locking dependency.
Validated with make kernel, all 27 CubeSandbox PTY exec-chain tests, and all 6 TCP close semantics tests.
Signed-off-by: longjin <longjin@dragonos.org>
* style(kernel): format N_TTY snapshot changes
Apply the repository rustfmt output required by the architecture format-check jobs. No behavior changes.
Signed-off-by: longjin <longjin@dragonos.org>
* fix(x86_64): roll back failed HPET enablement
Treat HPET enablement as a hardware transaction. If any validation, counter check, timer lookup, or IRQ registration step fails, restore the firmware general configuration instead of relying on the enabled flag, which is intentionally published only after IRQ setup succeeds.
Snapshot and restore each timer comparator together with its configuration. Restore timer state while the counter is disabled, then write the complete firmware general configuration last so a firmware-enabled counter resumes only after all timer registers are coherent. Normal HPET disable now reuses the same restoration path.
Validated with the repository format and Clippy checks, make kernel, and a DragonOS x86_64 fallback boot with HPET unavailable.
Signed-off-by: longjin <longjin@dragonos.org>
* fix(tty,time): eliminate PTY input hangs
Use a persistent waiter notification for nanosleep timers, preserve deadline semantics across signal and restart races, and avoid recursive N_TTY termios, flow, and line-discipline wakeup locking during input processing.
This fixes the ByteStream PTY deadlocks observed in CI while keeping absolute sleeps from returning before their POSIX clock deadline.
Signed-off-by: longjin <longjin@dragonos.org>
* fix(tty): satisfy clippy auto-deref lint
Signed-off-by: longjin <longjin@dragonos.org>
* fix(dunitest): synchronize reparent wait test
Signed-off-by: longjin <longjin@dragonos.org>
* fix(time): return EOPNOTSUPP for thread CPU nanosleep
Signed-off-by: longjin <longjin@dragonos.org>
---------
Signed-off-by: longjin <longjin@dragonos.org>1 parent 45931ee commit 229557c
52 files changed
Lines changed: 7842 additions & 1439 deletions
File tree
- kernel/src
- arch
- riscv64/interrupt
- x86_64
- driver
- init
- interrupt
- debug
- sysfs
- driver
- clocksource
- net
- tty
- tty_ldisc
- exception
- ipc
- syscall
- libs
- futex
- syscall
- net
- process
- smp
- cpu
- time
- syscall
- tools
- timekeeping
- user
- apps
- tests/dunitest
- suites/normal
- timekeeping_calibration
- dadk/config
- all
- sets/ubuntu2404
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| 73 | + | |
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| |||
127 | 129 | | |
128 | 130 | | |
129 | 131 | | |
| 132 | + | |
130 | 133 | | |
131 | 134 | | |
132 | 135 | | |
133 | 136 | | |
| 137 | + | |
134 | 138 | | |
135 | 139 | | |
136 | 140 | | |
| |||
140 | 144 | | |
141 | 145 | | |
142 | 146 | | |
| 147 | + | |
143 | 148 | | |
144 | 149 | | |
145 | 150 | | |
| |||
156 | 161 | | |
157 | 162 | | |
158 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
159 | 179 | | |
160 | 180 | | |
161 | 181 | | |
| |||
204 | 224 | | |
205 | 225 | | |
206 | 226 | | |
207 | | - | |
208 | | - | |
209 | 227 | | |
210 | 228 | | |
211 | 229 | | |
| |||
350 | 368 | | |
351 | 369 | | |
352 | 370 | | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
360 | 375 | | |
361 | 376 | | |
362 | 377 | | |
| |||
368 | 383 | | |
369 | 384 | | |
370 | 385 | | |
| 386 | + | |
371 | 387 | | |
372 | 388 | | |
373 | 389 | | |
374 | 390 | | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
380 | 395 | | |
381 | 396 | | |
382 | 397 | | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
383 | 408 | | |
384 | 409 | | |
385 | 410 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
123 | 156 | | |
124 | | - | |
125 | 157 | | |
126 | 158 | | |
127 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| |||
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
| 91 | + | |
88 | 92 | | |
89 | 93 | | |
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
94 | | - | |
95 | 98 | | |
96 | 99 | | |
97 | 100 | | |
| |||
117 | 120 | | |
118 | 121 | | |
119 | 122 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
| 123 | + | |
| 124 | + | |
134 | 125 | | |
135 | 126 | | |
136 | 127 | | |
| |||
0 commit comments