mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 13:05:32 +09:00
chore(repo): prune dead code and duplicate abstractions (#3413)
This commit is contained in:
1 parent
c17091768c
commit
c9fdf8fead
2937 files changed
+42233
-176793
No files matched your search
+2
-600
@@ -2,347 +2,20 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "alloca"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5a7d05ea6aea7e9e64d25b9156ba2fee3fdd659e34e41063cd2fc7cd020d7f4"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anes"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.20.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
|
||||
|
||||
[[package]]
|
||||
name = "cast"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3eb0f42d6c360dc3f8a821f6bf2fdea7f72bfd36b3076eb0e6d1e9e0752fff4"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
||||
|
||||
[[package]]
|
||||
name = "ciborium"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e"
|
||||
dependencies = [
|
||||
"ciborium-io",
|
||||
"ciborium-ll",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ciborium-io"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757"
|
||||
|
||||
[[package]]
|
||||
name = "ciborium-ll"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9"
|
||||
dependencies = [
|
||||
"ciborium-io",
|
||||
"half",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486"
|
||||
|
||||
[[package]]
|
||||
name = "criterion"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "950046b2aa2492f9a536f5f4f9a3de7b9e2476e575e05bd6c333371add4d98f3"
|
||||
dependencies = [
|
||||
"alloca",
|
||||
"anes",
|
||||
"cast",
|
||||
"ciborium",
|
||||
"clap",
|
||||
"criterion-plot",
|
||||
"itertools",
|
||||
"num-traits",
|
||||
"oorandom",
|
||||
"page_size",
|
||||
"plotters",
|
||||
"rayon",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tinytemplate",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "criterion-plot"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8d80a2f4f5b554395e47b5d8305bc3d27813bacb73493eb1001e8f76dae29ea"
|
||||
dependencies = [
|
||||
"cast",
|
||||
"itertools",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "622f3fc73690be383c7214310406f28a90e6edeadc3cea882f9d71e495b9711a"
|
||||
dependencies = [
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc74980687109a3b14c72fd458107bf0baa1da1a1a805e178d15501ba9b86d9d"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "252afb9ae5eaa683babdc6a068b3f5726eb19e05070c731f9b2a23a7c3e8ed34"
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d"
|
||||
|
||||
[[package]]
|
||||
name = "fluxer_rt_thread"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"criterion",
|
||||
"libc",
|
||||
"windows",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"pin-project-lite",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "half"
|
||||
version = "2.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crunchy",
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce57d20d1ea864ce2ac172ab472d409214f4fd359f0b2a2775abdf522e2af99e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.189"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||
|
||||
[[package]]
|
||||
name = "oorandom"
|
||||
version = "11.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e"
|
||||
|
||||
[[package]]
|
||||
name = "page_size"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30d5b2194ed13191c1999ae0704b7839fb18384fa22e49b57eeaa97d79ce40da"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
|
||||
|
||||
[[package]]
|
||||
name = "plotters"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
"plotters-backend",
|
||||
"plotters-svg",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "plotters-backend"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a"
|
||||
|
||||
[[package]]
|
||||
name = "plotters-svg"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670"
|
||||
dependencies = [
|
||||
"plotters-backend",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
@@ -361,125 +34,6 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon"
|
||||
version = "1.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d"
|
||||
dependencies = [
|
||||
"either",
|
||||
"rayon-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon-core"
|
||||
version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
|
||||
dependencies = [
|
||||
"crossbeam-deque",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.151"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
@@ -491,129 +45,12 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "3.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinytemplate"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
|
||||
dependencies = [
|
||||
"same-file",
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.128"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aecb87a33d3b0c5e3b7aa46336eaf486cffafbd281b195e4c8b80d50df2351bf"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.128"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a690d511e3c1a8b3a55e33511e3c2c00c78415cd23650f32b808627f5696b9ed"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.128"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "411e4887f0071ef2d2164a9d5fdf2d20efbef78fccd3a78b0c10a1dc5295e48a"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.6",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.128"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81941cd78d0c92026c33e5e01312845a4cb1e9af3407f9134b100dd03144103e"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9fbddc4a036f00ec4f18c83445bd3115cb306a91da554919a099d9222fe4a7f8"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.62.2"
|
||||
@@ -667,7 +104,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -678,7 +115,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -715,15 +152,6 @@ dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-threading"
|
||||
version = "0.2.1"
|
||||
@@ -732,29 +160,3 @@ checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d35102a9f36d089ccae9e4c6802bc118be4487b80aaffc0ab4e0cf5ce92d2873"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "146c01f5ab44258da43cf276c74a2763db2ff3969c9c652c3f2de07041d0b2bc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
||||
@@ -23,10 +23,3 @@ windows = {version = "0.62.2", features = [
|
||||
"Win32_Media",
|
||||
"Win32_Media_Multimedia",
|
||||
]}
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.8"
|
||||
|
||||
[[bench]]
|
||||
name = "tick"
|
||||
harness = false
|
||||
@@ -1,24 +0,0 @@
|
||||
{
|
||||
"measured_at": "85e057a273fd",
|
||||
"host": "darwin-arm64-apple-silicon",
|
||||
"regression_budget_percent": 5.0,
|
||||
"criterion_args": {
|
||||
"warm_up_time_sec": 2,
|
||||
"measurement_time_sec": 5
|
||||
},
|
||||
"benches": {
|
||||
"tick_driver/audio_21_33ms": {
|
||||
"median_ns": 21415000.0,
|
||||
"low_ns": 21395000.0,
|
||||
"high_ns": 21441000.0,
|
||||
"note": "Measures real-time sleep precision against AUDIO_TICK_PERIOD_NS=21333333; baseline reflects clock+scheduler delay on this host, not pure CPU work."
|
||||
},
|
||||
"system_clock_now_ns": {
|
||||
"median_ns": 22.931,
|
||||
"low_ns": 22.763,
|
||||
"high_ns": 23.099,
|
||||
"budget_percent_override": 15.0,
|
||||
"note": "23ns op; clock_gettime variance dominates over 5%. Wider budget reflects the floor of measurement noise."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use std::hint::black_box;
|
||||
use std::sync::Arc;
|
||||
|
||||
use criterion::{Criterion, criterion_group, criterion_main};
|
||||
use fluxer_rt_thread::{MonotonicClock, SystemMonotonicClock, TickDriver};
|
||||
|
||||
const AUDIO_TICK_PERIOD_NS: u64 = 21_333_333;
|
||||
|
||||
fn bench_audio_tick(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("tick_driver");
|
||||
group.sample_size(20);
|
||||
group.bench_function("audio_21_33ms", |b| {
|
||||
b.iter_custom(|iters| {
|
||||
let clock = Arc::new(SystemMonotonicClock::new());
|
||||
let mut driver = TickDriver::new(clock.clone(), AUDIO_TICK_PERIOD_NS).expect("driver");
|
||||
let _ = driver.wait_until_next_tick().expect("warmup");
|
||||
let start = std::time::Instant::now();
|
||||
for _ in 0..iters {
|
||||
let info = driver.wait_until_next_tick().expect("tick");
|
||||
black_box(info);
|
||||
}
|
||||
start.elapsed()
|
||||
})
|
||||
});
|
||||
group.finish();
|
||||
}
|
||||
|
||||
fn bench_now_ns(c: &mut Criterion) {
|
||||
let clock = SystemMonotonicClock::new();
|
||||
c.bench_function("system_clock_now_ns", |b| {
|
||||
b.iter(|| {
|
||||
let v = MonotonicClock::now_ns(&clock);
|
||||
black_box(v)
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench_audio_tick, bench_now_ns);
|
||||
criterion_main!(benches);
|
||||
@@ -6,7 +6,4 @@ pub mod priority;
|
||||
pub mod tick;
|
||||
|
||||
pub use priority::{PriorityProfile, RealtimePriorityGuard, RtError, RtOutcome};
|
||||
pub use tick::{MonotonicClock, SystemMonotonicClock, TickDriver, TickInfo};
|
||||
|
||||
pub const NS_PER_MS: u64 = 1_000_000;
|
||||
pub const NS_PER_SEC: u64 = 1_000_000_000;
|
||||
pub use tick::{MonotonicClock, SystemMonotonicClock};
|
||||
@@ -6,8 +6,6 @@ use core::fmt;
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum PriorityProfile {
|
||||
Audio,
|
||||
Video,
|
||||
Network,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
@@ -84,66 +82,6 @@ impl Drop for RealtimePriorityGuard {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
mod platform {
|
||||
use super::{PriorityProfile, RtError, RtOutcome};
|
||||
use libc::qos_class_t::{
|
||||
QOS_CLASS_DEFAULT, QOS_CLASS_USER_INITIATED, QOS_CLASS_USER_INTERACTIVE, QOS_CLASS_UTILITY,
|
||||
};
|
||||
|
||||
pub struct PlatformGuard {
|
||||
prior_qos: libc::qos_class_t,
|
||||
prior_relative: i32,
|
||||
}
|
||||
|
||||
impl PlatformGuard {
|
||||
pub fn acquire(profile: PriorityProfile) -> Result<(Self, RtOutcome), RtError> {
|
||||
assert!(matches!(
|
||||
profile,
|
||||
PriorityProfile::Audio | PriorityProfile::Video | PriorityProfile::Network
|
||||
));
|
||||
let mut prior_qos: libc::qos_class_t = QOS_CLASS_DEFAULT;
|
||||
let mut prior_relative: i32 = 0;
|
||||
let read_rc = unsafe {
|
||||
libc::pthread_get_qos_class_np(
|
||||
libc::pthread_self(),
|
||||
&mut prior_qos,
|
||||
&mut prior_relative,
|
||||
)
|
||||
};
|
||||
if read_rc != 0 {
|
||||
return Err(RtError::PlatformDenied(read_rc));
|
||||
}
|
||||
let target = map_profile(profile);
|
||||
let set_rc = unsafe { libc::pthread_set_qos_class_self_np(target, 0) };
|
||||
if set_rc != 0 {
|
||||
return Err(RtError::PlatformDenied(set_rc));
|
||||
}
|
||||
Ok((
|
||||
Self {
|
||||
prior_qos,
|
||||
prior_relative,
|
||||
},
|
||||
RtOutcome::Acquired,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn restore(&mut self) {
|
||||
unsafe {
|
||||
let _ = libc::pthread_set_qos_class_self_np(self.prior_qos, self.prior_relative);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn map_profile(profile: PriorityProfile) -> libc::qos_class_t {
|
||||
match profile {
|
||||
PriorityProfile::Audio => QOS_CLASS_USER_INTERACTIVE,
|
||||
PriorityProfile::Video => QOS_CLASS_USER_INITIATED,
|
||||
PriorityProfile::Network => QOS_CLASS_UTILITY,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
mod platform {
|
||||
use super::{PriorityProfile, RtError, RtOutcome};
|
||||
@@ -157,10 +95,7 @@ mod platform {
|
||||
|
||||
impl PlatformGuard {
|
||||
pub fn acquire(profile: PriorityProfile) -> Result<(Self, RtOutcome), RtError> {
|
||||
assert!(matches!(
|
||||
profile,
|
||||
PriorityProfile::Audio | PriorityProfile::Video | PriorityProfile::Network
|
||||
));
|
||||
assert!(matches!(profile, PriorityProfile::Audio));
|
||||
let mut prior_policy: i32 = 0;
|
||||
let mut prior_param: libc::sched_param = unsafe { core::mem::zeroed() };
|
||||
let read_rc = unsafe {
|
||||
@@ -195,8 +130,6 @@ mod platform {
|
||||
}
|
||||
let fallback_nice = match profile {
|
||||
PriorityProfile::Audio => -19,
|
||||
PriorityProfile::Video => -10,
|
||||
PriorityProfile::Network => -5,
|
||||
};
|
||||
let prior_nice = unsafe {
|
||||
*libc::__errno_location() = 0;
|
||||
@@ -239,13 +172,8 @@ mod platform {
|
||||
fn map_profile(profile: PriorityProfile) -> (i32, i32) {
|
||||
let policy = libc::SCHED_FIFO;
|
||||
let max = unsafe { libc::sched_get_priority_max(policy) };
|
||||
let min = unsafe { libc::sched_get_priority_min(policy) };
|
||||
assert!(max >= min);
|
||||
let span = (max - min).max(1);
|
||||
let prio = match profile {
|
||||
PriorityProfile::Audio => max,
|
||||
PriorityProfile::Video => min + (span * 2) / 3,
|
||||
PriorityProfile::Network => min + span / 3,
|
||||
};
|
||||
(policy, prio)
|
||||
}
|
||||
@@ -266,14 +194,9 @@ mod platform {
|
||||
|
||||
impl PlatformGuard {
|
||||
pub fn acquire(profile: PriorityProfile) -> Result<(Self, RtOutcome), RtError> {
|
||||
assert!(matches!(
|
||||
profile,
|
||||
PriorityProfile::Audio | PriorityProfile::Video | PriorityProfile::Network
|
||||
));
|
||||
assert!(matches!(profile, PriorityProfile::Audio));
|
||||
let task_name: &[u16] = match profile {
|
||||
PriorityProfile::Audio => &AUDIO_W,
|
||||
PriorityProfile::Video => &CAPTURE_W,
|
||||
PriorityProfile::Network => &PLAYBACK_W,
|
||||
};
|
||||
let mut task_index: u32 = 0;
|
||||
let handle = unsafe {
|
||||
@@ -303,30 +226,9 @@ mod platform {
|
||||
b'o' as u16,
|
||||
0,
|
||||
];
|
||||
const CAPTURE_W: [u16; 8] = [
|
||||
b'C' as u16,
|
||||
b'a' as u16,
|
||||
b'p' as u16,
|
||||
b't' as u16,
|
||||
b'u' as u16,
|
||||
b'r' as u16,
|
||||
b'e' as u16,
|
||||
0,
|
||||
];
|
||||
const PLAYBACK_W: [u16; 9] = [
|
||||
b'P' as u16,
|
||||
b'l' as u16,
|
||||
b'a' as u16,
|
||||
b'y' as u16,
|
||||
b'b' as u16,
|
||||
b'a' as u16,
|
||||
b'c' as u16,
|
||||
b'k' as u16,
|
||||
0,
|
||||
];
|
||||
}
|
||||
|
||||
#[cfg(not(any(unix, target_os = "windows")))]
|
||||
#[cfg(not(any(all(unix, not(target_os = "macos")), target_os = "windows")))]
|
||||
mod platform {
|
||||
use super::{PriorityProfile, RtError, RtOutcome};
|
||||
|
||||
@@ -342,58 +244,3 @@ mod platform {
|
||||
}
|
||||
|
||||
use platform::PlatformGuard;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn acquire_and_release_audio_does_not_panic() {
|
||||
let guard = RealtimePriorityGuard::acquire(PriorityProfile::Audio);
|
||||
match guard {
|
||||
Ok(g) => {
|
||||
assert!(matches!(
|
||||
*g.outcome(),
|
||||
RtOutcome::Acquired | RtOutcome::PartialFallback
|
||||
));
|
||||
drop(g);
|
||||
}
|
||||
Err(RtError::PlatformDenied(_)) => {}
|
||||
Err(other) => panic!("unexpected error: {other:?}"),
|
||||
}
|
||||
let again = RealtimePriorityGuard::acquire(PriorityProfile::Audio);
|
||||
if let Ok(g) = again {
|
||||
drop(g);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_acquire_on_same_thread_errors() {
|
||||
let first = RealtimePriorityGuard::acquire(PriorityProfile::Audio);
|
||||
if let Ok(first_guard) = first {
|
||||
let second = RealtimePriorityGuard::acquire(PriorityProfile::Audio);
|
||||
assert_eq!(second.err(), Some(RtError::AlreadyAcquired));
|
||||
drop(first_guard);
|
||||
let third = RealtimePriorityGuard::acquire(PriorityProfile::Network);
|
||||
if let Ok(t) = third {
|
||||
drop(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_profiles_round_trip() {
|
||||
for profile in [
|
||||
PriorityProfile::Audio,
|
||||
PriorityProfile::Video,
|
||||
PriorityProfile::Network,
|
||||
] {
|
||||
let g = RealtimePriorityGuard::acquire(profile);
|
||||
match g {
|
||||
Ok(g) => drop(g),
|
||||
Err(RtError::PlatformDenied(_)) => {}
|
||||
Err(other) => panic!("unexpected error for {profile:?}: {other:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use core::fmt;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use crate::NS_PER_MS;
|
||||
use std::time::Instant;
|
||||
|
||||
pub trait MonotonicClock: Send + Sync {
|
||||
fn now_ns(&self) -> u64;
|
||||
@@ -47,317 +42,3 @@ impl MonotonicClock for SystemMonotonicClock {
|
||||
observed
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct TickInfo {
|
||||
pub tick_index: u64,
|
||||
pub scheduled_ns: u64,
|
||||
pub actual_ns: u64,
|
||||
pub lag_ns: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum TickError {
|
||||
ZeroPeriod,
|
||||
PeriodTooLarge,
|
||||
NonMonotonicClock { prior_ns: u64, observed_ns: u64 },
|
||||
}
|
||||
|
||||
impl fmt::Display for TickError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
TickError::ZeroPeriod => write!(f, "tick period must be non-zero"),
|
||||
TickError::PeriodTooLarge => write!(f, "tick period exceeds u64 budget"),
|
||||
TickError::NonMonotonicClock {
|
||||
prior_ns,
|
||||
observed_ns,
|
||||
} => write!(
|
||||
f,
|
||||
"MonotonicClock returned non-monotonic reading: prior={prior_ns} observed={observed_ns}",
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for TickError {}
|
||||
|
||||
pub const TICK_PERIOD_NS_MAX: u64 = 60 * crate::NS_PER_SEC;
|
||||
|
||||
const SLEEP_SAFETY_MARGIN_NS: u64 = NS_PER_MS;
|
||||
|
||||
const SPIN_THRESHOLD_NS: u64 = 150_000;
|
||||
|
||||
pub struct TickDriver<C: MonotonicClock> {
|
||||
clock: Arc<C>,
|
||||
period_ns: u64,
|
||||
start_ns: u64,
|
||||
next_tick_index: u64,
|
||||
last_scheduled_ns: u64,
|
||||
last_actual_ns: u64,
|
||||
}
|
||||
|
||||
impl<C: MonotonicClock> TickDriver<C> {
|
||||
pub fn new(clock: Arc<C>, period_ns: u64) -> Result<Self, TickError> {
|
||||
if period_ns == 0 {
|
||||
return Err(TickError::ZeroPeriod);
|
||||
}
|
||||
if period_ns > TICK_PERIOD_NS_MAX {
|
||||
return Err(TickError::PeriodTooLarge);
|
||||
}
|
||||
let start_ns = clock.now_ns();
|
||||
assert!(period_ns > 0);
|
||||
assert!(period_ns <= TICK_PERIOD_NS_MAX);
|
||||
Ok(Self {
|
||||
clock,
|
||||
period_ns,
|
||||
start_ns,
|
||||
next_tick_index: 0,
|
||||
last_scheduled_ns: 0,
|
||||
last_actual_ns: start_ns,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn period_ns(&self) -> u64 {
|
||||
assert!(self.period_ns > 0);
|
||||
assert!(self.period_ns <= TICK_PERIOD_NS_MAX);
|
||||
self.period_ns
|
||||
}
|
||||
|
||||
pub fn start_ns(&self) -> u64 {
|
||||
assert!(self.start_ns <= self.clock.now_ns().saturating_add(self.period_ns));
|
||||
self.start_ns
|
||||
}
|
||||
|
||||
pub fn wait_until_next_tick(&mut self) -> Result<TickInfo, TickError> {
|
||||
assert!(self.period_ns > 0);
|
||||
let mut prior_actual = self.last_actual_ns;
|
||||
let mut tick_index = self.next_tick_index;
|
||||
let scheduled_ns = self
|
||||
.start_ns
|
||||
.saturating_add(tick_index.saturating_mul(self.period_ns));
|
||||
assert!(scheduled_ns >= self.last_scheduled_ns || tick_index == 0);
|
||||
loop {
|
||||
let now = self.clock.now_ns();
|
||||
if now < prior_actual {
|
||||
return Err(TickError::NonMonotonicClock {
|
||||
prior_ns: prior_actual,
|
||||
observed_ns: now,
|
||||
});
|
||||
}
|
||||
prior_actual = now;
|
||||
if now >= scheduled_ns {
|
||||
break;
|
||||
}
|
||||
let remaining = scheduled_ns - now;
|
||||
if remaining > SLEEP_SAFETY_MARGIN_NS {
|
||||
thread::park_timeout(Duration::from_nanos(remaining - SLEEP_SAFETY_MARGIN_NS));
|
||||
} else if remaining > SPIN_THRESHOLD_NS {
|
||||
thread::park_timeout(Duration::from_nanos(remaining - SPIN_THRESHOLD_NS));
|
||||
} else {
|
||||
core::hint::spin_loop();
|
||||
}
|
||||
}
|
||||
let actual_ns = self.clock.now_ns();
|
||||
if actual_ns < prior_actual {
|
||||
return Err(TickError::NonMonotonicClock {
|
||||
prior_ns: prior_actual,
|
||||
observed_ns: actual_ns,
|
||||
});
|
||||
}
|
||||
let lag_ns = (actual_ns as i128 - scheduled_ns as i128) as i64;
|
||||
let info = TickInfo {
|
||||
tick_index,
|
||||
scheduled_ns,
|
||||
actual_ns,
|
||||
lag_ns,
|
||||
};
|
||||
if actual_ns > scheduled_ns.saturating_add(self.period_ns) {
|
||||
let overshoot = (actual_ns - scheduled_ns) / self.period_ns;
|
||||
tick_index = tick_index.saturating_add(overshoot);
|
||||
}
|
||||
self.next_tick_index = tick_index.saturating_add(1);
|
||||
self.last_scheduled_ns = scheduled_ns;
|
||||
self.last_actual_ns = actual_ns;
|
||||
assert!(self.next_tick_index > tick_index);
|
||||
assert_eq!(
|
||||
info.lag_ns,
|
||||
info.actual_ns as i64 - info.scheduled_ns as i64
|
||||
);
|
||||
Ok(info)
|
||||
}
|
||||
|
||||
pub fn next_tick_index(&self) -> u64 {
|
||||
assert!(self.next_tick_index >= 1 || self.last_actual_ns == self.start_ns);
|
||||
self.next_tick_index
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ScriptedClock {
|
||||
readings: Mutex<Vec<u64>>,
|
||||
cursor: AtomicU64,
|
||||
}
|
||||
|
||||
impl ScriptedClock {
|
||||
pub fn new(readings: Vec<u64>) -> Self {
|
||||
assert!(!readings.is_empty());
|
||||
Self {
|
||||
readings: Mutex::new(readings),
|
||||
cursor: AtomicU64::new(0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MonotonicClock for ScriptedClock {
|
||||
fn now_ns(&self) -> u64 {
|
||||
let readings = self.readings.lock().expect("readings lock poisoned");
|
||||
assert!(!readings.is_empty());
|
||||
let idx = self.cursor.fetch_add(1, Ordering::AcqRel) as usize;
|
||||
let n = readings.len();
|
||||
let chosen = if idx < n {
|
||||
readings[idx]
|
||||
} else {
|
||||
*readings.last().unwrap()
|
||||
};
|
||||
assert!(n > 0);
|
||||
chosen
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
fn ci_mode() -> bool {
|
||||
std::env::var_os("CI").is_some()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_period_rejected() {
|
||||
let clock = Arc::new(SystemMonotonicClock::new());
|
||||
let err = TickDriver::new(clock, 0).err();
|
||||
assert_eq!(err, Some(TickError::ZeroPeriod));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn period_too_large_rejected() {
|
||||
let clock = Arc::new(SystemMonotonicClock::new());
|
||||
let err = TickDriver::new(clock, TICK_PERIOD_NS_MAX + 1).err();
|
||||
assert_eq!(err, Some(TickError::PeriodTooLarge));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn system_clock_is_monotonic_over_many_samples() {
|
||||
let clock = SystemMonotonicClock::new();
|
||||
let mut prev = clock.now_ns();
|
||||
let samples = 10_000;
|
||||
for _ in 0..samples {
|
||||
let now = clock.now_ns();
|
||||
assert!(now >= prev, "clock went backwards: prev={prev} now={now}");
|
||||
prev = now;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tick_driver_meets_jitter_budget_at_1ms_period() {
|
||||
let clock = Arc::new(SystemMonotonicClock::new());
|
||||
let period_ns = NS_PER_MS;
|
||||
let mut driver = TickDriver::new(clock, period_ns).expect("driver");
|
||||
let n: u64 = 100;
|
||||
let mut total_error_ns: i128 = 0;
|
||||
let mut max_error_ns: i64 = 0;
|
||||
for _ in 0..n {
|
||||
let info = driver.wait_until_next_tick().expect("tick ok");
|
||||
assert!(info.lag_ns >= -(period_ns as i64));
|
||||
let err = info.lag_ns.abs();
|
||||
total_error_ns += err as i128;
|
||||
if err > max_error_ns {
|
||||
max_error_ns = err;
|
||||
}
|
||||
}
|
||||
let mean_error_ns = (total_error_ns / n as i128) as i64;
|
||||
let max_budget_ns: i64 = if ci_mode() {
|
||||
25 * NS_PER_MS as i64
|
||||
} else {
|
||||
NS_PER_MS as i64
|
||||
};
|
||||
let mean_budget_ns: i64 = if ci_mode() {
|
||||
5 * NS_PER_MS as i64
|
||||
} else {
|
||||
200_000
|
||||
};
|
||||
assert!(
|
||||
mean_error_ns < mean_budget_ns,
|
||||
"mean error {mean_error_ns} ns exceeded budget {mean_budget_ns} ns (ci={})",
|
||||
ci_mode(),
|
||||
);
|
||||
assert!(
|
||||
max_error_ns < max_budget_ns,
|
||||
"max error {max_error_ns} ns exceeded budget {max_budget_ns} ns (ci={})",
|
||||
ci_mode(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lag_reported_when_caller_sleeps_over_a_tick_boundary() {
|
||||
let clock = Arc::new(SystemMonotonicClock::new());
|
||||
let period_ns = 5 * NS_PER_MS;
|
||||
let mut driver = TickDriver::new(clock, period_ns).expect("driver");
|
||||
let _first = driver.wait_until_next_tick().expect("first tick");
|
||||
thread::sleep(Duration::from_millis(20));
|
||||
let info = driver.wait_until_next_tick().expect("after sleep");
|
||||
assert!(
|
||||
info.lag_ns > 0,
|
||||
"expected positive lag, got {}",
|
||||
info.lag_ns
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tick_index_is_monotonic() {
|
||||
let clock = Arc::new(SystemMonotonicClock::new());
|
||||
let mut driver = TickDriver::new(clock, NS_PER_MS).expect("driver");
|
||||
let mut prior_index = None::<u64>;
|
||||
let mut prior_scheduled = None::<u64>;
|
||||
for _ in 0..16 {
|
||||
let info = driver.wait_until_next_tick().expect("tick");
|
||||
if let Some(prev) = prior_index {
|
||||
assert!(
|
||||
info.tick_index > prev,
|
||||
"tick_index not monotonic: prev={prev} cur={}",
|
||||
info.tick_index
|
||||
);
|
||||
}
|
||||
if let Some(prev) = prior_scheduled {
|
||||
assert!(info.scheduled_ns > prev, "scheduled_ns not monotonic");
|
||||
}
|
||||
prior_index = Some(info.tick_index);
|
||||
prior_scheduled = Some(info.scheduled_ns);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_monotonic_clock_is_detected() {
|
||||
let clock = Arc::new(ScriptedClock::new(vec![
|
||||
0, 10_000_000, 5_000_000, 5_000_000,
|
||||
]));
|
||||
let mut driver = TickDriver::new(clock, NS_PER_MS).expect("driver");
|
||||
let err = driver.wait_until_next_tick().err();
|
||||
assert!(
|
||||
matches!(err, Some(TickError::NonMonotonicClock { .. })),
|
||||
"got {err:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tick_info_lag_invariant_holds() {
|
||||
let clock = Arc::new(SystemMonotonicClock::new());
|
||||
let mut driver = TickDriver::new(clock, NS_PER_MS).expect("driver");
|
||||
for _ in 0..5 {
|
||||
let info = driver.wait_until_next_tick().expect("tick");
|
||||
let derived = info.actual_ns as i64 - info.scheduled_ns as i64;
|
||||
assert_eq!(info.lag_ns, derived);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user