Skip to content

switch random number generators used by sampling - #110

Merged
weyrick merged 2 commits into
developfrom
bug/RDRAND-109
Jul 14, 2021
Merged

weyrick merged 2 commits into
developfrom
bug/RDRAND-109

Conversation

@weyrick

@weyrick weyrick commented Jul 14, 2021 •

Copy link
Copy Markdown
Contributor
  • address RDRAND failure on Arista switch #109 by switching to a non cryptographic pseudorandom number generator for sampling
  • fix inefficiency in sampler
  • fix pktvisor-pcap signal handler

@weyrick
weyrick merged commit 46bc07d into develop Jul 14, 2021
@weyrick
weyrick deleted the bug/RDRAND-109 branch July 14, 2021 21:00
leoparente added a commit that referenced this pull request Jun 23, 2026
…700)

Removes the vendored 3rd/rng/jsf.h (178 lines, Bob Jenkins Small Fast) in favor
of a ~6-line inline SplitMix64 in AbstractMetricsManager.h. This is the deep-
sampling gate's PRNG (roll 0-99, deep-sample when the roll is under
deep_sample_rate), used in exactly one place; sampling RATE is unchanged (only
which events get deep-sampled differs, and nothing depends on the specific set).

Why SplitMix64 over the issue's suggested pcg-cpp conan package: it removes the
maintained code (the whole 3rd/rng dir) without ADDING a third-party dependency,
keeps an 8-byte state (vs jsf's 16, vs std::mt19937's ~2.5KB), and has
BigCrush-grade quality.

CRITICAL invariant preserved (issue #109 "RDRAND failure on Arista switch"): the
generator is seeded from a fixed constant and never from std::random_device /
hardware entropy. The pre-JSF randutils-based RNG auto-seeded via random_device
-> RDRAND, which faulted and threw on startup on some hardware; PR #110 fixed
that by switching to a fixed-seeded PRNG. A prominent comment documents this so
nobody "improves" it into entropy seeding (a particular footgun with pcg-cpp's
idiomatic seed_seq_from<random_device>).

Build wiring:
- Delete 3rd/rng/ and its add_subdirectory + the `rng` link in visor-core.
- Fix a latent copy-paste bug in 3rd/timer/CMakeLists.txt: it called
  target_include_directories(rng ...) instead of (timer ...), so timer.hpp's
  include dir was being attached to the rng target and only reached visor-core
  transitively through it. Removing rng would have broken <timer.hpp>; pointing
  it at timer makes the timer target self-contained.
- Update the NOMINMAX comment in CMakeLists.txt (it cited jsf.h's static
  min()/max()); keep the define for general Windows hygiene.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
leoparente added a commit that referenced this pull request Jun 24, 2026
…700) (#786)

Removes the vendored 3rd/rng/jsf.h (178 lines, Bob Jenkins Small Fast) in favor
of a ~6-line inline SplitMix64 in AbstractMetricsManager.h. This is the deep-
sampling gate's PRNG (roll 0-99, deep-sample when the roll is under
deep_sample_rate), used in exactly one place; sampling RATE is unchanged (only
which events get deep-sampled differs, and nothing depends on the specific set).

Why SplitMix64 over the issue's suggested pcg-cpp conan package: it removes the
maintained code (the whole 3rd/rng dir) without ADDING a third-party dependency,
keeps an 8-byte state (vs jsf's 16, vs std::mt19937's ~2.5KB), and has
BigCrush-grade quality.

CRITICAL invariant preserved (issue #109 "RDRAND failure on Arista switch"): the
generator is seeded from a fixed constant and never from std::random_device /
hardware entropy. The pre-JSF randutils-based RNG auto-seeded via random_device
-> RDRAND, which faulted and threw on startup on some hardware; PR #110 fixed
that by switching to a fixed-seeded PRNG. A prominent comment documents this so
nobody "improves" it into entropy seeding (a particular footgun with pcg-cpp's
idiomatic seed_seq_from<random_device>).

Build wiring:
- Delete 3rd/rng/ and its add_subdirectory + the `rng` link in visor-core.
- Fix a latent copy-paste bug in 3rd/timer/CMakeLists.txt: it called
  target_include_directories(rng ...) instead of (timer ...), so timer.hpp's
  include dir was being attached to the rng target and only reached visor-core
  transitively through it. Removing rng would have broken <timer.hpp>; pointing
  it at timer makes the timer target self-contained.
- Update the NOMINMAX comment in CMakeLists.txt (it cited jsf.h's static
  min()/max()); keep the define for general Windows hygiene.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant