Skip to content

fix: register halt_irq PM ops to poll sockets during cooperative scheduler idle#106

Closed
danbugs wants to merge 4 commits into
mainfrom
fix/unikraft-idle-poll
Closed

fix: register halt_irq PM ops to poll sockets during cooperative scheduler idle#106
danbugs wants to merge 4 commits into
mainfrom
fix/unikraft-idle-poll

Conversation

@danbugs

@danbugs danbugs commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Point both networking-py and python-agent-driver kraft.yaml at danbugs/unikraft:fix/net-poll-sleep, which registers a halt_irq PM ops callback so the cooperative scheduler's idle thread polls sockets via __hl_sleep instead of spinning
  • Add urllib_get_no_timeout.py CI test that exercises urlopen() without an explicit timeout — the code path used by mxc that currently hangs on Windows

Key kernel changes (in danbugs/unikraft:fix/net-poll-sleep)

  • Remove dead uk_lcpu_halt_irq from plat/hyperlight/x86/lcpu.c (was shadowed by lib/uklcpu/lcpu.c)
  • Register halt_irq PM ops in plat/hyperlight/shutdown.c that calls time_block_until() — polls sockets via __hl_sleep from the scheduler's idle thread
  • Re-register after uk_boot_early_init() in setup.c so the native platform's HLT-based halt_irq doesn't overwrite it

Context

When urllib.request.urlopen() is called without an explicit timeout, Python never sets SO_RCVTIMEO/SO_SNDTIMEO. The cooperative scheduler's idle thread then calls uk_lcpu_halt_irq() which was a no-op spinwait — sockets were never polled, so the connection hung indefinitely. This fix makes the idle thread poll sockets, matching the behavior when timeouts are set.

Test plan

  • urllib_get_no_timeout.py passes on Linux
  • urllib_get_no_timeout.py passes on Windows
  • Existing networking tests unaffected

danbugs added 2 commits June 30, 2026 22:45
Signed-off-by: danbugs <danilochiarlone@gmail.com>
Signed-off-by: danbugs <danilochiarlone@gmail.com>
Copilot AI review requested due to automatic review settings June 30, 2026 22:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the Hyperlight example builds to use a Unikraft branch that polls sockets during cooperative-scheduler idle (via halt_irq PM ops), and adds a regression test covering urllib.request.urlopen() without an explicit timeout (the path that previously hung due to lack of socket polling).

Changes:

  • Point examples/networking-py and examples/python-agent-driver at danbugs/unikraft:fix/net-poll-sleep.
  • Add urllib_get_no_timeout.py and include it in the networking-py rootfs.
  • Extend CI (test-examples.yml) to run the new networking test on both Linux and Windows.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
examples/python-agent-driver/kraft.yaml Switch Unikraft source/version to the branch containing the halt_irq socket-polling fix.
examples/networking-py/kraft.yaml Switch Unikraft source/version to the branch containing the halt_irq socket-polling fix.
examples/networking-py/urllib_get_no_timeout.py New urllib GET test that omits timeout= to exercise the previously-hanging code path.
examples/networking-py/Dockerfile Include the new test script in the example rootfs.
.github/workflows/test-examples.yml Run the new networking test in CI on Linux and Windows.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/networking-py/kraft.yaml Outdated
Comment on lines +4 to +6
unikraft:
source: https://github.com/unikraft/unikraft.git
version: plat-hyperlight
source: https://github.com/danbugs/unikraft.git
version: fix/net-poll-sleep
Comment thread examples/python-agent-driver/kraft.yaml Outdated
Comment on lines +4 to +6
unikraft:
source: https://github.com/unikraft/unikraft.git
version: plat-hyperlight
source: https://github.com/danbugs/unikraft.git
version: fix/net-poll-sleep
Comment on lines +619 to +621
- example: networking-py
args: "--net -- /urllib_get_no_timeout.py"
expect: "SUCCESS: urllib GET \\(no timeout\\) worked!"

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux Benchmarks

Details
Benchmark suite Current: 7bed20f Previous: 682ad20 Ratio
hello_world (median) 20 ms 20 ms 1
pandas (median) 110 ms 120 ms 0.92
density (per VM) 8 MB 8 MB 1
snapshot (disk) 654 MiB 653 MiB 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows Benchmarks

Details
Benchmark suite Current: 7bed20f Previous: 682ad20 Ratio
hello_world (median) 284 ms 291 ms 0.98
pandas (median) 920 ms 1024 ms 0.90
density (per VM) 7 MB 7 MB 1
snapshot (disk) 661 MiB 661 MiB 1

This comment was automatically generated by workflow using github-action-benchmark.

danbugs added 2 commits July 3, 2026 13:44
Signed-off-by: danbugs <danilochiarlone@gmail.com>
Signed-off-by: danbugs <danilochiarlone@gmail.com>
@danbugs danbugs closed this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants