diff --git a/thirdparty/asic-rs/patches/0011-luxminer-set-power-limit-epic-psu-gating.patch b/thirdparty/asic-rs/patches/0011-luxminer-set-power-limit-epic-psu-gating.patch new file mode 100644 index 00000000..b58c84dc --- /dev/null +++ b/thirdparty/asic-rs/patches/0011-luxminer-set-power-limit-epic-psu-gating.patch @@ -0,0 +1,162 @@ +Subject: [PATCH 0011] luxminer: implement set_power_limit; epic: document PSU gating + +Round-15 follow-up. The toolkit reported supports_power_limit=false for LuxOS and +ePIC (UMC OS) miners. Investigated against the live corpus (S19j Pro on both). + +LuxOS: genuinely under-reported. LuxOS tunes by discrete named profiles, each +carrying a Watts rating (the `profiles` RPC returns Step + Watts), applied with +profileset -- pure frequency/voltage tuning, no special PSU needed. Implemented +SetPowerLimit by mapping the requested watts to the highest profile whose Watts +does not exceed it (or the lowest profile when the target is below all of them), +then profileset. supports_set_power_limit now returns true. The pure mapping is +factored into parse_profile_watts + select_profile_at_or_below with a unit test. +Verified live: set_power_limit(2500) on an S19j Pro selected step -4 (2385 W, the +highest <= 2500) and the miner's active profile became 445MHz/-4. + +ePIC: NOT under-reporting after all -- left at false, with a comment explaining +why. ePIC PowerPlay's only true power-limit path is the PowerTune perpetual-tune +algorithm, which the firmware gates on the PSU: on a fixed-voltage Bitmain PSU +(the APW12 on an S19j Pro) perpetualtune/algo rejects it with "Power optimization +is not supported by this PSU". That support is a per-PSU runtime property this +synchronous, no-I/O capability check cannot observe, so advertising true would +over-report on most reflashed Antminers. (Hashrate tuning stays available via +set_tuning_config.) + +diff --git a/vendor/asic-rs-firmwares-epic/src/backends/v1/mod.rs b/vendor/asic-rs-firmwares-epic/src/backends/v1/mod.rs +index a6f555f7..c21e05b1 100644 +--- a/vendor/asic-rs-firmwares-epic/src/backends/v1/mod.rs ++++ b/vendor/asic-rs-firmwares-epic/src/backends/v1/mod.rs +@@ -1369,6 +1369,14 @@ impl SetFaultLight for PowerPlayV1 { + #[async_trait] + impl SetPowerLimit for PowerPlayV1 { + fn supports_set_power_limit(&self) -> bool { ++ // ePIC PowerPlay's only true power-limit mechanism is the PowerTune ++ // perpetual-tune algorithm, which the firmware gates on the PSU: on a ++ // fixed-voltage Bitmain PSU (e.g. the APW12 on an S19j Pro) the ++ // perpetualtune/algo endpoint rejects it with "Power optimization is not ++ // supported by this PSU". Since that support is a per-PSU runtime property ++ // that this synchronous, no-I/O capability check cannot observe, report ++ // false rather than over-advertise a control that fails on most reflashed ++ // Antminers. (Hashrate tuning is exposed separately via set_tuning_config.) + false + } + } +diff --git a/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs b/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs +index af89167c..aac39eb6 100644 +--- a/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs ++++ b/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs +@@ -1052,10 +1052,66 @@ impl SetFaultLight for LuxMinerV1 { + } + } + ++/// Parse a LuxOS `profiles` RPC reply into (step name, watts) pairs, keeping only ++/// profiles that report both a `Step` and a `Watts` value. ++fn parse_profile_watts(profiles: &Value) -> Vec<(String, f64)> { ++ profiles ++ .get("PROFILES") ++ .and_then(Value::as_array) ++ .map(|arr| { ++ arr.iter() ++ .filter_map(|p| { ++ let step = p.get("Step").and_then(Value::as_str)?.to_string(); ++ let watts = p.get("Watts").and_then(Value::as_f64)?; ++ Some((step, watts)) ++ }) ++ .collect() ++ }) ++ .unwrap_or_default() ++} ++ ++/// Choose the LuxOS profile step to satisfy a watts power limit: the highest-watt ++/// profile that does not exceed `target_w`, or -- when the target is below every ++/// profile -- the lowest-watt profile. Returns None only when there are no ++/// profiles to choose from. ++fn select_profile_at_or_below(steps: &[(String, f64)], target_w: f64) -> Option { ++ if steps.is_empty() { ++ return None; ++ } ++ let mut sorted: Vec<&(String, f64)> = steps.iter().collect(); ++ sorted.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap_or(std::cmp::Ordering::Equal)); ++ sorted ++ .iter() ++ .rev() ++ .find(|(_, w)| *w <= target_w) ++ .or_else(|| sorted.first()) ++ .map(|(s, _)| s.clone()) ++} ++ + #[async_trait] + impl SetPowerLimit for LuxMinerV1 { + fn supports_set_power_limit(&self) -> bool { +- false ++ true ++ } ++ ++ async fn set_power_limit(&self, power: Power) -> anyhow::Result { ++ // LuxOS tunes by discrete named profiles (each carries a Watts rating), ++ // not a raw watts setpoint. Map the requested limit to the highest profile ++ // whose Watts does not exceed it (or the lowest profile when the target is ++ // below every profile), then apply it with profileset. ++ let profiles = self.rpc.profiles().await?; ++ let steps = parse_profile_watts(&profiles); ++ let Some(chosen) = select_profile_at_or_below(&steps, power.as_watts()) else { ++ anyhow::bail!("LuxOS reported no tunable profiles with a Step/Watts pair"); ++ }; ++ let resp = self.rpc.profileset(&chosen).await?; ++ // LuxOS answers with a STATUS array; "S"/"I" is success. A missing status ++ // after a non-error reply is treated as applied. ++ Ok(resp ++ .pointer("/STATUS/0/STATUS") ++ .and_then(Value::as_str) ++ .map(|s| matches!(s, "S" | "I")) ++ .unwrap_or(true)) + } + } + +@@ -1231,6 +1287,46 @@ mod tests { + POWER, PROFILES, STATS, SUMMARY, TEMPS, VERSION, VOLTAGEGET_0, VOLTAGEGET_1, VOLTAGEGET_2, + }; + ++ #[test] ++ fn power_limit_profile_selection() { ++ // LuxOS reports a ladder of profiles, each with a Step name and Watts. ++ let steps = vec![ ++ ("-16".to_string(), 865.0), ++ ("-4".to_string(), 2385.0), ++ ("-2".to_string(), 2790.0), ++ ("0".to_string(), 3100.0), ++ ]; ++ // The highest profile at or below the requested watts limit. ++ assert_eq!( ++ select_profile_at_or_below(&steps, 2500.0).as_deref(), ++ Some("-4") ++ ); ++ assert_eq!( ++ select_profile_at_or_below(&steps, 2790.0).as_deref(), ++ Some("-2") ++ ); ++ // Above every profile -> the maximum profile (a limit can't exceed the ++ // hardware's top profile). ++ assert_eq!( ++ select_profile_at_or_below(&steps, 9000.0).as_deref(), ++ Some("0") ++ ); ++ // Below every profile -> the minimum profile. ++ assert_eq!( ++ select_profile_at_or_below(&steps, 100.0).as_deref(), ++ Some("-16") ++ ); ++ // No profiles -> nothing to choose. ++ assert_eq!(select_profile_at_or_below(&[], 2500.0), None); ++ ++ // parse_profile_watts against the captured LuxOS `profiles` reply: it ++ // yields tunable profiles and selection finds a real step among them. ++ let profiles: Value = serde_json::from_str(PROFILES).unwrap(); ++ let parsed = parse_profile_watts(&profiles); ++ assert!(!parsed.is_empty(), "fixture should carry tunable profiles"); ++ assert!(select_profile_at_or_below(&parsed, 2500.0).is_some()); ++ } ++ + #[tokio::test] + + async fn test_luxminer_v1() -> anyhow::Result<()> { diff --git a/vendor/asic-rs-firmwares-epic/.cargo-checksum.json b/vendor/asic-rs-firmwares-epic/.cargo-checksum.json index a0401875..8398ae7c 100644 --- a/vendor/asic-rs-firmwares-epic/.cargo-checksum.json +++ b/vendor/asic-rs-firmwares-epic/.cargo-checksum.json @@ -1 +1 @@ -{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"4c9489c1f9b5f16e3fd8ab777da35bb120ccd0ca05f780cf94853c89fb5c8946","Cargo.lock":"69db8793725d6071e21b4353fb89537912096d7eccebd6ee597367330141f613","Cargo.toml":"df82261a9c3187bee15a7d6092d54ad2e9c7e4d1f127cd577c457d913f6881cf","Cargo.toml.orig":"e7c4ef90bc86763dad35d1a4da1c17c7e2f59eaac79e2f011647ae31c43d5e2b","src/backends/mod.rs":"1362c4d3805dccb7a78ef6b45d6a81b8f63b2be75fcf80329b6c2b0dd9e2d5c5","src/backends/v1/mod.rs":"360f173deb62c38bceb907774be6caaea5814b4f543d8d7f3c72828db31640b9","src/backends/v1/web.rs":"3a567a4f581baa5d9d2d4e59d8acc754eec51d49b0a4f5434d87614b037a4a55","src/firmware.rs":"fb88124a51089756cc3271f3d4a234d73add61ab919c4710ef26a52dc8b5ef80","src/lib.rs":"53f7acddeff8f7d82f80d09e0a9f91962011f9ccf2e441c4ca05cd7fc4eb292e","src/test/json/mod.rs":"24191681066d5cf6a3022ad59c1baa92b57e3ce7717bb78d6a682af9e19a38c4","src/test/json/v1/capabilities.json":"d2b3dae7aa2a1e2977e0ddf62cf2d730de64cf12bf62388c12fd23dc5278bbcb","src/test/json/v1/chip_clocks.json":"d1f46d3aad6ad55ec1c02d0b26aa4c5034c1ccaefb130d7b0e46efe48bb122a0","src/test/json/v1/chip_hashrates.json":"9601a1289f93fe4e27c722d51b3a31daa71aec71f2c29e71f6d1eefe01edf7f2","src/test/json/v1/chip_temps.json":"cb7390e424af57f55f0c974ddfe0c98c4d5b4dbcd85887e38ff8caf7b19f62fe","src/test/json/v1/chip_voltages.json":"cb7390e424af57f55f0c974ddfe0c98c4d5b4dbcd85887e38ff8caf7b19f62fe","src/test/json/v1/mod.rs":"5671105221b84b0b6edb2df34b25bfc9e33459da285d4316be0db23ddb630e8d","src/test/json/v1/network.json":"3374b419fa2f0bc19544c670e08118bbc45bd4d121a577c5a6403c8c8100f628","src/test/json/v1/summary.json":"ac8ac018da9d619b5884f283b730bad2bf0a7e8f2032a7119193c9e5d87d6a7c","src/test/json/v1/temps.json":"794edf870985ed4398ead96670b8f5d01deb4d825fb14a8325087a29cd939fa8","src/test/mod.rs":"ed52c3d613eabc4a0346bb38bcfdf7a94933d61e368d3c9094821edeab92f81b"},"package":"268dc7c8b3289fccd3230ff87f7bfc727a3e7e2f6f72ae56ab9d27c63eabc5cf"} \ No newline at end of file +{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"4c9489c1f9b5f16e3fd8ab777da35bb120ccd0ca05f780cf94853c89fb5c8946","Cargo.lock":"69db8793725d6071e21b4353fb89537912096d7eccebd6ee597367330141f613","Cargo.toml":"df82261a9c3187bee15a7d6092d54ad2e9c7e4d1f127cd577c457d913f6881cf","Cargo.toml.orig":"e7c4ef90bc86763dad35d1a4da1c17c7e2f59eaac79e2f011647ae31c43d5e2b","src/backends/mod.rs":"1362c4d3805dccb7a78ef6b45d6a81b8f63b2be75fcf80329b6c2b0dd9e2d5c5","src/backends/v1/mod.rs":"fff17902f8fa033d5b67c6131ea2ff01b80f9a9c8e02dd0511e1e87521d23e47","src/backends/v1/web.rs":"3a567a4f581baa5d9d2d4e59d8acc754eec51d49b0a4f5434d87614b037a4a55","src/firmware.rs":"fb88124a51089756cc3271f3d4a234d73add61ab919c4710ef26a52dc8b5ef80","src/lib.rs":"53f7acddeff8f7d82f80d09e0a9f91962011f9ccf2e441c4ca05cd7fc4eb292e","src/test/json/mod.rs":"24191681066d5cf6a3022ad59c1baa92b57e3ce7717bb78d6a682af9e19a38c4","src/test/json/v1/capabilities.json":"d2b3dae7aa2a1e2977e0ddf62cf2d730de64cf12bf62388c12fd23dc5278bbcb","src/test/json/v1/chip_clocks.json":"d1f46d3aad6ad55ec1c02d0b26aa4c5034c1ccaefb130d7b0e46efe48bb122a0","src/test/json/v1/chip_hashrates.json":"9601a1289f93fe4e27c722d51b3a31daa71aec71f2c29e71f6d1eefe01edf7f2","src/test/json/v1/chip_temps.json":"cb7390e424af57f55f0c974ddfe0c98c4d5b4dbcd85887e38ff8caf7b19f62fe","src/test/json/v1/chip_voltages.json":"cb7390e424af57f55f0c974ddfe0c98c4d5b4dbcd85887e38ff8caf7b19f62fe","src/test/json/v1/mod.rs":"5671105221b84b0b6edb2df34b25bfc9e33459da285d4316be0db23ddb630e8d","src/test/json/v1/network.json":"3374b419fa2f0bc19544c670e08118bbc45bd4d121a577c5a6403c8c8100f628","src/test/json/v1/summary.json":"ac8ac018da9d619b5884f283b730bad2bf0a7e8f2032a7119193c9e5d87d6a7c","src/test/json/v1/temps.json":"794edf870985ed4398ead96670b8f5d01deb4d825fb14a8325087a29cd939fa8","src/test/mod.rs":"ed52c3d613eabc4a0346bb38bcfdf7a94933d61e368d3c9094821edeab92f81b"},"package":"268dc7c8b3289fccd3230ff87f7bfc727a3e7e2f6f72ae56ab9d27c63eabc5cf"} \ No newline at end of file diff --git a/vendor/asic-rs-firmwares-epic/src/backends/v1/mod.rs b/vendor/asic-rs-firmwares-epic/src/backends/v1/mod.rs index a6f555f7..c21e05b1 100644 --- a/vendor/asic-rs-firmwares-epic/src/backends/v1/mod.rs +++ b/vendor/asic-rs-firmwares-epic/src/backends/v1/mod.rs @@ -1369,6 +1369,14 @@ impl SetFaultLight for PowerPlayV1 { #[async_trait] impl SetPowerLimit for PowerPlayV1 { fn supports_set_power_limit(&self) -> bool { + // ePIC PowerPlay's only true power-limit mechanism is the PowerTune + // perpetual-tune algorithm, which the firmware gates on the PSU: on a + // fixed-voltage Bitmain PSU (e.g. the APW12 on an S19j Pro) the + // perpetualtune/algo endpoint rejects it with "Power optimization is not + // supported by this PSU". Since that support is a per-PSU runtime property + // that this synchronous, no-I/O capability check cannot observe, report + // false rather than over-advertise a control that fails on most reflashed + // Antminers. (Hashrate tuning is exposed separately via set_tuning_config.) false } } diff --git a/vendor/asic-rs-firmwares-luxminer/.cargo-checksum.json b/vendor/asic-rs-firmwares-luxminer/.cargo-checksum.json index cfbc09a3..4a12d240 100644 --- a/vendor/asic-rs-firmwares-luxminer/.cargo-checksum.json +++ b/vendor/asic-rs-firmwares-luxminer/.cargo-checksum.json @@ -1 +1 @@ -{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"fe8effe2bfdda5d4c390656c016729f531a2b1c60033228557659c0befdde9f2","Cargo.lock":"a2b2cb45bb8b574e4f29ffdcdb5ebafd1dd87a0e6e11b47383973a99be367784","Cargo.toml":"503efa00123f8567f5fe40bf6a93e9e453d13094df0e0e1b7e98bdacdfbd2595","Cargo.toml.orig":"1c4ba0315fb491c086fc22a5c9bafaf7288c6b1fd48679c3d03dbd9df156a8b5","src/backends/mod.rs":"548d988b877410e330a55e275f64b2adad95ca5f1a0f085fe144957c96b8906f","src/backends/v1/mod.rs":"fc109beb7fa4713b5f7a6d717e225ff91baa6f8ef497bc770a435f92981c2879","src/backends/v1/rpc.rs":"9dea9c65629e1e9b833b96a4ae88014f7195a26036104f92daa264fbdf13feba","src/firmware.rs":"d95345295ae5043dfc357e69ae56c564b261fdb3b19b5c0ad1765267ff05ab3f","src/lib.rs":"53f7acddeff8f7d82f80d09e0a9f91962011f9ccf2e441c4ca05cd7fc4eb292e","src/test/json/mod.rs":"24191681066d5cf6a3022ad59c1baa92b57e3ce7717bb78d6a682af9e19a38c4","src/test/json/v1/config.json":"6ca9e6217d853d4bf1e75d69159630e9c9184ede96751706b88dfb699b5d59ad","src/test/json/v1/devs.json":"8f746dc6a02953eee5ee96dcf53be8dc7880a8ffc2c6e303f0284bcf6a97f42d","src/test/json/v1/events.json":"913683ff97af3333018807e1cc6e43467ea8a55925e5964dc402616615e2a5e3","src/test/json/v1/fans.json":"f8a9a1234d651055c80f4ebb1380bbb4e6d19eb33012902c55fff1385e592447","src/test/json/v1/healthchipget_0.json":"10619460049333ca016b2beec59ecc514ed9077fb19bdf7d0ed697201f8cb96c","src/test/json/v1/healthchipget_1.json":"80927fb1480c95be7f3a4e155d63f68f97720530ff7cf5d5ade06f2a3e810bf0","src/test/json/v1/healthchipget_2.json":"1e93ee2ab472ee7af58add08b4251e3ce0ad4f986d4325abbf43fd4c9b3dd28f","src/test/json/v1/mod.rs":"5a050f07455e622e35ad79ab1c8a6daf2ea38c4198472e49c6bbfe80538a9e48","src/test/json/v1/pools.json":"0068745327e31853fec051172abb7337f18a4cf9972c51967113d63f4f31f504","src/test/json/v1/power.json":"80534bb4581de7c8b747bf33b5d629b909c6e16a531d18ecb4afd7ffad3f014f","src/test/json/v1/profiles.json":"1f00429036e270daa08f12cd2d7357135070c57acd7a899a3c0af6167fe82abb","src/test/json/v1/stats.json":"2b105f0eb927046c9d2389bde978a43e3d54d12a420dfbe400786bb2f0ae31ca","src/test/json/v1/summary.json":"aaea3378eb7040952037e2f1ef7bd5f20a1b242bf93d4ba0501c46104b0b31a0","src/test/json/v1/temps.json":"1ee781cd2be3ed6a6a07e23be930248735fb51348c160453ba10f6ef71fcb7f1","src/test/json/v1/version.json":"4beb6ca5c0ebf359cee0434fdcc4d0a1a0607436634e46be3fd951e2256595df","src/test/json/v1/voltageget_0.json":"c445fa8674c2542b2d296fbafdd3166c53008dfbd9da8095327217989d37f1da","src/test/json/v1/voltageget_1.json":"96b91c3447dd66e7f1f575ed3b99611062e8b1d516d31422b74e425c46b2f49c","src/test/json/v1/voltageget_2.json":"7d40544021b2e32401135ae333067b770d2d736ada9e60deaca8fd8f5a79a1e3","src/test/mod.rs":"ed52c3d613eabc4a0346bb38bcfdf7a94933d61e368d3c9094821edeab92f81b"},"package":"513792d93a2a21d5258d9e6ac0e6dc9e0a6365118934514b4e656792add78066"} \ No newline at end of file +{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"fe8effe2bfdda5d4c390656c016729f531a2b1c60033228557659c0befdde9f2","Cargo.lock":"a2b2cb45bb8b574e4f29ffdcdb5ebafd1dd87a0e6e11b47383973a99be367784","Cargo.toml":"503efa00123f8567f5fe40bf6a93e9e453d13094df0e0e1b7e98bdacdfbd2595","Cargo.toml.orig":"1c4ba0315fb491c086fc22a5c9bafaf7288c6b1fd48679c3d03dbd9df156a8b5","src/backends/mod.rs":"548d988b877410e330a55e275f64b2adad95ca5f1a0f085fe144957c96b8906f","src/backends/v1/mod.rs":"06f28c59112bd40771db1c865d00402ae37f18146a3eaf9de905d3f4a0a6ba51","src/backends/v1/rpc.rs":"9dea9c65629e1e9b833b96a4ae88014f7195a26036104f92daa264fbdf13feba","src/firmware.rs":"d95345295ae5043dfc357e69ae56c564b261fdb3b19b5c0ad1765267ff05ab3f","src/lib.rs":"53f7acddeff8f7d82f80d09e0a9f91962011f9ccf2e441c4ca05cd7fc4eb292e","src/test/json/mod.rs":"24191681066d5cf6a3022ad59c1baa92b57e3ce7717bb78d6a682af9e19a38c4","src/test/json/v1/config.json":"6ca9e6217d853d4bf1e75d69159630e9c9184ede96751706b88dfb699b5d59ad","src/test/json/v1/devs.json":"8f746dc6a02953eee5ee96dcf53be8dc7880a8ffc2c6e303f0284bcf6a97f42d","src/test/json/v1/events.json":"913683ff97af3333018807e1cc6e43467ea8a55925e5964dc402616615e2a5e3","src/test/json/v1/fans.json":"f8a9a1234d651055c80f4ebb1380bbb4e6d19eb33012902c55fff1385e592447","src/test/json/v1/healthchipget_0.json":"10619460049333ca016b2beec59ecc514ed9077fb19bdf7d0ed697201f8cb96c","src/test/json/v1/healthchipget_1.json":"80927fb1480c95be7f3a4e155d63f68f97720530ff7cf5d5ade06f2a3e810bf0","src/test/json/v1/healthchipget_2.json":"1e93ee2ab472ee7af58add08b4251e3ce0ad4f986d4325abbf43fd4c9b3dd28f","src/test/json/v1/mod.rs":"5a050f07455e622e35ad79ab1c8a6daf2ea38c4198472e49c6bbfe80538a9e48","src/test/json/v1/pools.json":"0068745327e31853fec051172abb7337f18a4cf9972c51967113d63f4f31f504","src/test/json/v1/power.json":"80534bb4581de7c8b747bf33b5d629b909c6e16a531d18ecb4afd7ffad3f014f","src/test/json/v1/profiles.json":"1f00429036e270daa08f12cd2d7357135070c57acd7a899a3c0af6167fe82abb","src/test/json/v1/stats.json":"2b105f0eb927046c9d2389bde978a43e3d54d12a420dfbe400786bb2f0ae31ca","src/test/json/v1/summary.json":"aaea3378eb7040952037e2f1ef7bd5f20a1b242bf93d4ba0501c46104b0b31a0","src/test/json/v1/temps.json":"1ee781cd2be3ed6a6a07e23be930248735fb51348c160453ba10f6ef71fcb7f1","src/test/json/v1/version.json":"4beb6ca5c0ebf359cee0434fdcc4d0a1a0607436634e46be3fd951e2256595df","src/test/json/v1/voltageget_0.json":"c445fa8674c2542b2d296fbafdd3166c53008dfbd9da8095327217989d37f1da","src/test/json/v1/voltageget_1.json":"96b91c3447dd66e7f1f575ed3b99611062e8b1d516d31422b74e425c46b2f49c","src/test/json/v1/voltageget_2.json":"7d40544021b2e32401135ae333067b770d2d736ada9e60deaca8fd8f5a79a1e3","src/test/mod.rs":"ed52c3d613eabc4a0346bb38bcfdf7a94933d61e368d3c9094821edeab92f81b"},"package":"513792d93a2a21d5258d9e6ac0e6dc9e0a6365118934514b4e656792add78066"} \ No newline at end of file diff --git a/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs b/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs index af89167c..aac39eb6 100644 --- a/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs +++ b/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs @@ -1052,10 +1052,66 @@ impl SetFaultLight for LuxMinerV1 { } } +/// Parse a LuxOS `profiles` RPC reply into (step name, watts) pairs, keeping only +/// profiles that report both a `Step` and a `Watts` value. +fn parse_profile_watts(profiles: &Value) -> Vec<(String, f64)> { + profiles + .get("PROFILES") + .and_then(Value::as_array) + .map(|arr| { + arr.iter() + .filter_map(|p| { + let step = p.get("Step").and_then(Value::as_str)?.to_string(); + let watts = p.get("Watts").and_then(Value::as_f64)?; + Some((step, watts)) + }) + .collect() + }) + .unwrap_or_default() +} + +/// Choose the LuxOS profile step to satisfy a watts power limit: the highest-watt +/// profile that does not exceed `target_w`, or -- when the target is below every +/// profile -- the lowest-watt profile. Returns None only when there are no +/// profiles to choose from. +fn select_profile_at_or_below(steps: &[(String, f64)], target_w: f64) -> Option { + if steps.is_empty() { + return None; + } + let mut sorted: Vec<&(String, f64)> = steps.iter().collect(); + sorted.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap_or(std::cmp::Ordering::Equal)); + sorted + .iter() + .rev() + .find(|(_, w)| *w <= target_w) + .or_else(|| sorted.first()) + .map(|(s, _)| s.clone()) +} + #[async_trait] impl SetPowerLimit for LuxMinerV1 { fn supports_set_power_limit(&self) -> bool { - false + true + } + + async fn set_power_limit(&self, power: Power) -> anyhow::Result { + // LuxOS tunes by discrete named profiles (each carries a Watts rating), + // not a raw watts setpoint. Map the requested limit to the highest profile + // whose Watts does not exceed it (or the lowest profile when the target is + // below every profile), then apply it with profileset. + let profiles = self.rpc.profiles().await?; + let steps = parse_profile_watts(&profiles); + let Some(chosen) = select_profile_at_or_below(&steps, power.as_watts()) else { + anyhow::bail!("LuxOS reported no tunable profiles with a Step/Watts pair"); + }; + let resp = self.rpc.profileset(&chosen).await?; + // LuxOS answers with a STATUS array; "S"/"I" is success. A missing status + // after a non-error reply is treated as applied. + Ok(resp + .pointer("/STATUS/0/STATUS") + .and_then(Value::as_str) + .map(|s| matches!(s, "S" | "I")) + .unwrap_or(true)) } } @@ -1231,6 +1287,46 @@ mod tests { POWER, PROFILES, STATS, SUMMARY, TEMPS, VERSION, VOLTAGEGET_0, VOLTAGEGET_1, VOLTAGEGET_2, }; + #[test] + fn power_limit_profile_selection() { + // LuxOS reports a ladder of profiles, each with a Step name and Watts. + let steps = vec![ + ("-16".to_string(), 865.0), + ("-4".to_string(), 2385.0), + ("-2".to_string(), 2790.0), + ("0".to_string(), 3100.0), + ]; + // The highest profile at or below the requested watts limit. + assert_eq!( + select_profile_at_or_below(&steps, 2500.0).as_deref(), + Some("-4") + ); + assert_eq!( + select_profile_at_or_below(&steps, 2790.0).as_deref(), + Some("-2") + ); + // Above every profile -> the maximum profile (a limit can't exceed the + // hardware's top profile). + assert_eq!( + select_profile_at_or_below(&steps, 9000.0).as_deref(), + Some("0") + ); + // Below every profile -> the minimum profile. + assert_eq!( + select_profile_at_or_below(&steps, 100.0).as_deref(), + Some("-16") + ); + // No profiles -> nothing to choose. + assert_eq!(select_profile_at_or_below(&[], 2500.0), None); + + // parse_profile_watts against the captured LuxOS `profiles` reply: it + // yields tunable profiles and selection finds a real step among them. + let profiles: Value = serde_json::from_str(PROFILES).unwrap(); + let parsed = parse_profile_watts(&profiles); + assert!(!parsed.is_empty(), "fixture should carry tunable profiles"); + assert!(select_profile_at_or_below(&parsed, 2500.0).is_some()); + } + #[tokio::test] async fn test_luxminer_v1() -> anyhow::Result<()> {