Skip to content

Commit

Permalink
scx_loader: fix recursion of type convertion
Browse files Browse the repository at this point in the history
Into trait was calling the Into<&SupportedSched> which was calling
Into<SupportedSched> and so on.

```
    #0 0x622450e96149 in scx_loader::_$LT$impl$u20$core..convert..From$LT$scx_loader..SupportedSched$GT$$u20$for$u20$$RF$str$GT$::from::h13ba9d4271e33441 /tmp/scx/rust/scx_loader/src/lib.rs:60:9
    #1 0x622450e91af3 in _$LT$T$u20$as$u20$core..convert..Into$LT$U$GT$$GT$::into::h9481856c4f80c765 /home/vl/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:759:9
    #2 0x622450e9614a in scx_loader::_$LT$impl$u20$core..convert..From$LT$scx_loader..SupportedSched$GT$$u20$for$u20$$RF$str$GT$::from::h13ba9d4271e33441 /tmp/scx/rust/scx_loader/src/lib.rs:60:9
    #3 0x622450e91af3 in _$LT$T$u20$as$u20$core..convert..Into$LT$U$GT$$GT$::into::h9481856c4f80c765 /home/vl/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:759:9
    #4 0x622450e9614a in scx_loader::_$LT$impl$u20$core..convert..From$LT$scx_loader..SupportedSched$GT$$u20$for$u20$$RF$str$GT$::from::h13ba9d4271e33441 /tmp/scx/rust/scx_loader/src/lib.rs:60:9
    #5 0x622450e91af3 in _$LT$T$u20$as$u20$core..convert..Into$LT$U$GT$$GT$::into::h9481856c4f80c765 /home/vl/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:759:9
    #6 0x622450e9614a in scx_loader::_$LT$impl$u20$core..convert..From$LT$scx_loader..SupportedSched$GT$$u20$for$u20$$RF$str$GT$::from::h13ba9d4271e33441 /tmp/scx/rust/scx_loader/src/lib.rs:60:9
    #7 0x622450e91af3 in _$LT$T$u20$as$u20$core..convert..Into$LT$U$GT$$GT$::into::h9481856c4f80c765 /home/vl/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:759:9
    #8 0x622450e9614a in scx_loader::_$LT$impl$u20$core..convert..From$LT$scx_loader..SupportedSched$GT$$u20$for$u20$$RF$str$GT$::from::h13ba9d4271e33441 /tmp/scx/rust/scx_loader/src/lib.rs:60:9
    #9 0x622450e91af3 in _$LT$T$u20$as$u20$core..convert..Into$LT$U$GT$$GT$::into::h9481856c4f80c765 /home/vl/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:759:9
    #10 0x622450e9614a in scx_loader::_$LT$impl$u20$core..convert..From$LT$scx_loader..SupportedSched$GT$$u20$for$u20$$RF$str$GT$::from::h13ba9d4271e33441 /tmp/scx/rust/scx_loader/src/lib.rs:60:9
    #11 0x622450e91af3 in _$LT$T$u20$as$u20$core..convert..Into$LT$U$GT$$GT$::into::h9481856c4f80c765 /home/vl/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:759:9
    #12 0x622450e9614a in scx_loader::_$LT$impl$u20$core..convert..From$LT$scx_loader..SupportedSched$GT$$u20$for$u20$$RF$str$GT$::from::h13ba9d4271e33441 /tmp/scx/rust/scx_loader/src/lib.rs:60:9
    #13 0x622450e91af3 in _$LT$T$u20$as$u20$core..convert..Into$LT$U$GT$$GT$::into::h9481856c4f80c765 /home/vl/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:759:9
    #14 0x622450e9614a in scx_loader::_$LT$impl$u20$core..convert..From$LT$scx_loader..SupportedSched$GT$$u20$for$u20$$RF$str$GT$::from::h13ba9d4271e33441 /tmp/scx/rust/scx_loader/src/lib.rs:60:9
```
  • Loading branch information
vnepogodin committed Dec 12, 2024
1 parent aa7b375 commit 74fd6e0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion rust/scx_loader/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub fn get_scx_flags_for_mode(
scx_sched: &SupportedSched,
sched_mode: SchedMode,
) -> Vec<String> {
let scx_name: &str = scx_sched.into();
let scx_name: &str = scx_sched.clone().into();
if let Some(sched_config) = config.scheds.get(scx_name) {
let scx_flags = extract_scx_flags_from_config(sched_config, &sched_mode);

Expand Down
35 changes: 18 additions & 17 deletions rust/scx_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,6 @@ pub enum SchedMode {
Server = 4,
}

impl From<&SupportedSched> for &str {
fn from(scx_name: &SupportedSched) -> &'static str {
match scx_name {
SupportedSched::Bpfland => "scx_bpfland",
SupportedSched::Rusty => "scx_rusty",
SupportedSched::Lavd => "scx_lavd",
SupportedSched::Flash => "scx_flash",
}
}
}

impl From<SupportedSched> for &str {
fn from(scx_name: SupportedSched) -> &'static str {
scx_name.into()
}
}

impl FromStr for SupportedSched {
type Err = anyhow::Error;

Expand All @@ -74,3 +57,21 @@ impl FromStr for SupportedSched {
}
}
}

impl TryFrom<&str> for SupportedSched {
type Error = <SupportedSched as FromStr>::Err;
fn try_from(s: &str) -> Result<SupportedSched, Self::Error> {
<SupportedSched as FromStr>::from_str(s)
}
}

impl From<SupportedSched> for &str {
fn from(scx_name: SupportedSched) -> Self {
match scx_name {
SupportedSched::Bpfland => "scx_bpfland",
SupportedSched::Rusty => "scx_rusty",
SupportedSched::Lavd => "scx_lavd",
SupportedSched::Flash => "scx_flash",
}
}
}
4 changes: 2 additions & 2 deletions rust/scx_loader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl ScxLoader {
#[zbus(property)]
async fn current_scheduler(&self) -> String {
if let Some(current_scx) = &self.current_scx {
let current_scx: &str = current_scx.into();
let current_scx: &str = current_scx.clone().into();
log::info!("called {current_scx:?}");
return current_scx.to_owned();
}
Expand Down Expand Up @@ -162,7 +162,7 @@ impl ScxLoader {

async fn stop_scheduler(&mut self) -> zbus::fdo::Result<()> {
if let Some(current_scx) = &self.current_scx {
let scx_name: &str = current_scx.into();
let scx_name: &str = current_scx.clone().into();

log::info!("stopping {scx_name:?}..");
let _ = self.channel.send(ScxMessage::StopSched);
Expand Down

0 comments on commit 74fd6e0

Please sign in to comment.