Skip to content

Add Synchronous Gain acceleration mode - #119

Open
Gnarus-G wants to merge 8 commits into
mainfrom
feat/78-synchronous-gain
Open

Add Synchronous Gain acceleration mode#119
Gnarus-G wants to merge 8 commits into
mainfrom
feat/78-synchronous-gain

Conversation

@Gnarus-G

@Gnarus-G Gnarus-G commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Closes #78.

Summary

  • add synchronous-gain as a distinct acceleration mode while preserving all existing mode ordinals
  • keep legacy Synchronous and Synchronous Gain in independent code modules with separate argument types and implementations
  • give the gain mode independent SYNC_GAIN_GAMMA, SYNC_GAIN_SMOOTH, SYNC_GAIN_MOTIVITY, and SYNC_GAIN_SPEED parameters
  • port Raw Accel's integrated-velocity lookup math with 97 logarithmically spaced points and two integration partitions per interval
  • rebuild the gain lookup table only when Synchronous Gain parameters change, outside the mouse-event hot path
  • expose a dedicated Synchronous Gain screen through the CLI, TUI, and NixOS module

Implementation

  • Add a separate driver and Rust mode with stable ordinal 4
  • Remove the GAIN boolean and its runtime branch
  • Split synchronous.h and synchronous_gain.h into independent implementations
  • Add independent SYNC_GAIN_* configuration
  • Match Raw Accel's interpolation and boundary behavior
  • Publish parameter updates safely under concurrent input handling
  • Preserve the existing legacy Synchronous snapshot and configuration
  • Add Raw Accel parity, mode-dispatch, ordinal, and parameter-name tests
  • Document CLI and NixOS configuration
  • Exercise the installed module and mouse flow on a test machine

Verification

  • make test
  • make test name=synchronous_gain DRIVER_CFLAGS=-DFIXEDPT_BITS=32
  • make build
  • cargo test --all
  • cargo fmt --all --check
  • clang-format --dry-run --Werror driver/accel.h driver/accel/synchronous.h driver/accel/synchronous_gain.h driver/accel/mode.h driver/accel_k.h driver/maccel.c driver/params.h driver/tests/synchronous_gain.test.c

Nix parsing was not run locally because Nix is not installed in the development environment; release tags remain intentionally deferred while the PR is a draft.

On pre-6.11 kernels the handler returns void and cannot communicate
a new event count, so injecting synthetic events into the vals buffer
is undefined behavior. Restrict ensure_axes_for_rotation() and the
memmove injection to __cleanup_events (>= 6.11) only.
* Improve C test reporting

* Handle snapshot diff pipe failures
* Add root cause analysis for divide-by-zero kernel panic in maccel_events

Add three RCA documents analyzing the #DE divide-by-zero panic in
maccel_events (issue #112). The documents cover the fault mechanism
where consecutive EV_SYN events with identical ktime_get() timestamps
produce a zero divisor in input_speed(), triggering a fatal idivq in
interrupt context. Each RCA examines the call path, root causes
including unguarded fixed-point divisions and missing parameter
validation, and potential fix strategies.

* Add tests for division-by-zero and invalid timing guards

Add a test for div128_s64_s64 with a zero divisor, running it in a
forked child to catch the current SIGFPE trap and assert a clean exit
once the guard is implemented.

Create a new test suite for acceleration functions that validates
survival and correct behavior when given zero or negative time deltas,
zero input DPI, and a motivity of exactly one (which produces a zero
logarithm divisor). Each case runs in a forked child to prevent the
current SIGFPE from killing the test runner.

* Add guard tests for division-by-zero kernel panic

Encode the safety invariant for maccel#112: division by zero in the
fixed-point hot path (time_ms, input_dpi, motivity) must return a defined
value, not trap #DE/SIGFPE. Each case runs in a forked child so the current
unsafe behavior fails as an assertion instead of core-dumping the suite.
Red until the guards are implemented.

* Guard fixed-point division and input speed against zero/invalid divisors

fpt_div and div128_s64_s64 returned undefined behavior (SIGFPE in
userspace, #DE in IRQ context) on a zero divisor. input_speed also
divided by time_ms without checking, and left LAST_INPUT_MOUSE_SPEED
stale on early return. Return 0 on zero divisor, and return 0 / clear
the published speed when time_ms <= 0 or distance calculation fails.
Fixes the panic in maccel#112.

* Remove outdated RCAs for divide-by-zero kernel panic

The root cause analysis documents for issue #112 are no longer
relevant as the fix has been implemented. These files contained
duplicate and superseded analysis from multiple AI models, and
keeping them in the repository would cause confusion about the
current state of the fix.

* Handle interrupted test child waits
@vercel

vercel Bot commented Aug 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
maccel Ready Ready Preview Aug 2, 2026 1:37am

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Gnarus-G, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 37 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d6ca4c38-46ca-4e8b-92f3-cb4710d98a7c

📥 Commits

Reviewing files that changed from the base of the PR and between 4ebdf1c and cedcd08.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (19)
  • PKGBUILD
  • README.md
  • README_NIXOS.md
  • cli/Cargo.toml
  • cli/src/main.rs
  • crates/core/src/context.rs
  • crates/core/src/params.rs
  • crates/core/src/persist.rs
  • crates/core/src/sens_fns.rs
  • driver/accel.h
  • driver/accel/mode.h
  • driver/accel/synchronous.h
  • driver/accel/synchronous_gain.h
  • driver/accel_k.h
  • driver/maccel.c
  • driver/params.h
  • driver/tests/synchronous_gain.test.c
  • module.nix
  • tui/src/app.rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Gnarus-G Gnarus-G changed the title Add synchronous gain mode Add Synchronous Gain acceleration mode Aug 2, 2026
@Gnarus-G
Gnarus-G marked this pull request as ready for review August 2, 2026 01:26
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.

Add gain version of Synchronous

1 participant