Skip to content

Fix high CPU usage when game paused#32

Merged
jserv merged 1 commit into
sysprog21:mainfrom
tobiichi3227:dev
Jul 17, 2026
Merged

Fix high CPU usage when game paused#32
jserv merged 1 commit into
sysprog21:mainfrom
tobiichi3227:dev

Conversation

@tobiichi3227

@tobiichi3227 tobiichi3227 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Stop reading kxo device when game is paused.
Only read STDIN for resume game.

Change-Id: I5c44adeed192167998cc71ca3174bc0edc50cdc4


Summary by cubic

Fix high CPU use when paused by excluding /dev/kxo from select and waiting only on STDIN.

Written for commit 0000878. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 1 file

Re-trigger cubic

@jserv jserv 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.

Check https://cbea.ms/git-commit/ carefully and enforce.

@jserv

jserv commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Provide test case for clarification/validation.

@tobiichi3227

Copy link
Copy Markdown
Contributor Author

Before this patch

1879 tobiich+  16  -4 9405948 966716 168404 S 168.6   4.1  80:08.72 ghostty
887523 root      16  -4    3132   1956   1832 R  99.4   0.0   1:08.25 xo-user

After this patch

1879 tobiich+  16  -4 9403900 966748 168404 R  11.0   4.1  80:52.51 ghostty
889561 root      16  -4    3132   1952   1832 S   0.0   0.0   0:00.00 xo-user

@tobiichi3227

Copy link
Copy Markdown
Contributor Author

Initialize read_attr to false instead of relying on Ctrl-P to reproduce the issue deterministically. Without the patch, select() continues monitoring the readable device file descriptor and returns immediately, causing a busy loop and a significant increase in CPU usage. With the patch applied, the device file descriptor is excluded and select() blocks on standard input, keeping CPU usage negligible.

@jserv jserv 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.

Check https://cbea.ms/git-commit/ carefully and enforce the rules.

When board display is paused, read_attr prevents task_io from consuming
data from /dev/kxo. The descriptor can remain readable, so keeping it
in the select set makes select return immediately and repeatedly run the
main loop.

Exclude /dev/kxo from the descriptor set and wait only for stdin while
paused. This lets select sleep until keyboard input resumes or exits the
program, avoiding needless CPU use.

Change-Id: I5c44adeed192167998cc71ca3174bc0edc50cdc4
@tobiichi3227
tobiichi3227 requested a review from jserv July 17, 2026 07:17
@jserv
jserv merged commit 0dc4be6 into sysprog21:main Jul 17, 2026
5 checks passed
@jserv

jserv commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Thank @tobiichi3227 for contributing!

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