Skip to content

Fix slow-clocksource check for HW monotonic clock and non-x86 advisories - #4272

Merged
zuiderkwast merged 5 commits into
valkey-io:unstablefrom
quanyeyang:fix/slow-clocksource-advisory-4269
Aug 11, 2026
Merged

Fix slow-clocksource check for HW monotonic clock and non-x86 advisories#4272
zuiderkwast merged 5 commits into
valkey-io:unstablefrom
quanyeyang:fix/slow-clocksource-advisory-4269

Conversation

@quanyeyang

@quanyeyang quanyeyang commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #4269

Summary

valkey-server --check-system used to probe clock_gettime(CLOCK_MONOTONIC)
and, on failure, always suggested switching to tsc. That is wrong on ARM64,
where arch_sys_counter is normal and often the only available clocksource.

Two changes, as discussed in #4269:

  1. Skip the probe when Valkey uses a hardware monotonic clock
    (monotonicGetType() == MONOTONIC_CLOCK_HW, e.g. aarch64 CNTVCT /
    x86 TSC). In that case the server hot path does not depend on the Linux
    clock_gettime / clocksource path, so the warning is not actionable for
    Valkey and can also false-positive due to short getrusage() noise.
    The probe is kept for the POSIX fallback path.

  2. Fix the advisory text when the probe still runs

    • Suggest a concrete vDSO-capable alternative when one is available
      (tsc, arch_sys_counter, kvm-clock, hyperv_clocksource_tsc_page).
    • If none exists, do not recommend switching (and do not hard-code tsc).
    • If sysfs cannot be read, say so instead of claiming there is no alternative.

This does not whitelist arch_sys_counter by name.

Test plan

  • With CFLAGS=-DNO_PROCESSOR_CLOCK (POSIX fallback): probe still runs;
    warning does not hard-code tsc
  • On aarch64/x86 with HW monotonic clock: --check-system shows
    [slow-clocksource]...skipped
  • Single-clocksource system: no suggestion to switch to an unavailable source
  • Multi-clocksource system with a slow current source: suggests a suitable
    fast alternative when available

The --check-system warning always suggested switching to tsc, which is
x86-specific and misleading on ARM64 where arch_sys_counter is often the
only available clocksource. Suggest an actual alternative when one exists,
and otherwise explain that switching is not possible.

Fixes valkey-io#4269

Signed-off-by: quanyeyang <quanyemostima@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The slow-clocksource check now recognizes hardware monotonic clocks, reads current and available kernel clocksources, selects a suitable alternative when possible, and reports either a switch command or why switching cannot be recommended.

Changes

Clocksource check

Layer / File(s) Summary
Clocksource selection and reporting
src/syscheck.c
Adds monotonic-clock detection, token matching, and alternative selection, then makes slow-clocksource diagnostics conditional on sysfs results and available alternatives.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The change stops suggesting tsc unconditionally and handles cases with no available alternative clocksource, matching #4269.
Out of Scope Changes check ✅ Passed The patch stays focused on syscheck clocksource advisory logic and does not introduce unrelated changes.
Title check ✅ Passed The title clearly summarizes the main fix: slow-clocksource checks for hardware monotonic clocks and non-x86 advisories.
Description check ✅ Passed The description directly matches the changeset and explains the clocksource probe and advisory updates.

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.

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/syscheck.c (1)

64-108: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for clocksource selection and advisory branches.

Add src/unit/ GoogleTests for tsc preference, fallback selection, a sole available source, and unreadable sysfs values. This behavior change otherwise has no regression coverage. As per coding guidelines, “Code changes should include relevant tests when the repository has a matching test location,” and low-level logic tests belong in src/unit/ as C++ GoogleTest tests.

Also applies to: 151-172

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/syscheck.c` around lines 64 - 108, Add C++ GoogleTest coverage under
src/unit for clocksource selection, exercising tsc preference, fallback to the
first alternative, a sole available source, and unreadable or missing sysfs
values. Target the clocksourceHasToken and pickAlternativeClocksource behavior,
including advisory branches, while preserving the existing selection semantics.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/syscheck.c`:
- Around line 149-171: Update the error-message branching around
pickAlternativeClocksource() to distinguish unreadable clocksource data from a
successfully read list with no alternative. Emit a “could not determine
clocksources” diagnostic when curr or avail was not read, retain the existing
no-alternative message only when both values are available, and preserve the
suggestion path when suggest is non-NULL.

---

Nitpick comments:
In `@src/syscheck.c`:
- Around line 64-108: Add C++ GoogleTest coverage under src/unit for clocksource
selection, exercising tsc preference, fallback to the first alternative, a sole
available source, and unreadable or missing sysfs values. Target the
clocksourceHasToken and pickAlternativeClocksource behavior, including advisory
branches, while preserving the existing selection semantics.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6d0a4928-a743-4b6d-bbb0-70ae328077c9

📥 Commits

Reviewing files that changed from the base of the PR and between 4733aed and 97635ed.

📒 Files selected for processing (1)
  • src/syscheck.c

Comment thread src/syscheck.c Outdated

@valkey-review-bot valkey-review-bot 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.

Reviewed the advisory rework in src/syscheck.c. The direction is right (no hard-coded tsc), and the code compiles clean and the tokenizers terminate correctly (verified by running both helpers verbatim over the realistic sysfs inputs). Two issues with the picked suggestion and with the "no alternative" wording are below.

Comment thread src/syscheck.c Outdated
Comment thread src/syscheck.c
Comment thread src/syscheck.c
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.82%. Comparing base (4733aed) to head (f83d61f).

Files with missing lines Patch % Lines
src/syscheck.c 0.00% 28 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #4272      +/-   ##
============================================
- Coverage     76.84%   76.82%   -0.03%     
============================================
  Files           162      162              
  Lines         81479    81507      +28     
============================================
+ Hits          62610    62615       +5     
- Misses        18869    18892      +23     
Files with missing lines Coverage Δ
src/syscheck.c 30.43% <0.00%> (-9.80%) ⬇️

... and 16 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: quanyeyang <quanyemostima@gmail.com>
Comment thread src/syscheck.c Outdated
quanyeyang and others added 2 commits July 26, 2026 15:21
Co-authored-by: Shubham S Taple <subbutaple@gmail.com>
Signed-off-by: Quanye Yang <quanyemostima@gmail.com>
Signed-off-by: quanyeyang <quanyemostima@gmail.com>
Signed-off-by: quanyeyang <quanyemostima@gmail.com>

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/syscheck.c`:
- Line 34: Remove the monotonic.h include and the early return based on
monotonicGetType() in the syscheck flow, allowing the existing kernel
clocksource performance probe to run unconditionally. Retain sysfs clocksource
detection only for tailoring the advisory message.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 66bf37e1-695a-4cdc-a2a2-de169e3e8c34

📥 Commits

Reviewing files that changed from the base of the PR and between 6ae0206 and f83d61f.

📒 Files selected for processing (1)
  • src/syscheck.c

Comment thread src/syscheck.c
@quanyeyang quanyeyang changed the title Fix slow-clocksource advisory for non-x86 Fix slow-clocksource check for HW monotonic clock and non-x86 advisories Jul 27, 2026

@dvkashapov dvkashapov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@ShubhamTaple

Copy link
Copy Markdown
Contributor

@quanyeyang Maybe you can check the failing CI (I don't think its failing because of your changes though)

@quanyeyang

Copy link
Copy Markdown
Contributor Author

@ShubhamTaple Emmm,I think it's flaky.

@quanyeyang

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @dvkashapov.

It looks like the PR is still blocked because it requires an approving review from someone with write access. Could you help request a review from an appropriate maintainer, or let me know who I should ask?

Thanks!

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

LGMT, thanks!

Thanks also to @dal1wg and @dvkashapov for sorting this out in the discussion in the issue!

Comment thread src/syscheck.c
Comment on lines +65 to +66
/* Return 1 if `name` appears as a whitespace-separated token in `list`. */
static int clocksourceHasToken(const char *list, const char *name) {

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.

Minor: This is a generic string function. We could put it in util.c – or we can move it there later if we need it for anything else.

@zuiderkwast
zuiderkwast merged commit 8abd07f into valkey-io:unstable Aug 11, 2026
63 of 64 checks passed
@github-project-automation github-project-automation Bot moved this to To be backported in Valkey 9.1 Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To be backported

Development

Successfully merging this pull request may close these issues.

[BUG]ARM64: valkey-server --check-system reports false slow clocksource warning with arch_sys_counter

4 participants