Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solve ratio problem #12

Merged
merged 4 commits into from
Oct 10, 2023
Merged

solve ratio problem #12

merged 4 commits into from
Oct 10, 2023

Conversation

bktech2021
Copy link
Contributor

solves the ratio problem for laptops and fanless cards.

solves the ratio problem for laptops and fanless cards.
changed the message when there is no fans, no fan to no fans
src/app.rs Outdated
@@ -154,7 +154,9 @@ pub fn run(
selected_gpu = usize::from(n - 1)
}
KeyCode::Char('p') => {
// re-scan pci tree to let driver discover new devices (only works as sudo)
//commented out because discover_gpus not implemented
Copy link
Owner

@alphastrata alphastrata Oct 9, 2023

Choose a reason for hiding this comment

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

It is implemented https://docs.rs/nvml-wrapper/latest/nvml_wrapper/struct.Nvml.html#method.discover_gpus, it's probably not available on the platform (laptop gpus).

We need a better way to conditionally show/not-show this for sure.

You can actually see it working on a multi-gpu system here #6 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i was not able to compile, i will look again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/* snip

# Platform Support

    Only supports Linux.
    */
    // TODO: constructor for default pci_infos ^
    // Checked against local
    // Tested
    #[cfg(target_os = "linux")]
    #[doc(alias = "nvmlDeviceDiscoverGpus")]
    pub fn discover_gpus(&self, pci_info: PciInfo) -> Result<(), NvmlError> {
        let sym = nvml_sym(self.lib.nvmlDeviceDiscoverGpus.as_ref())?;

        unsafe { nvml_try(sym(&mut pci_info.try_into()?)) }
    }

/* snip */

as it writes, this function is only for linux, im testing it on windows. so i will try to not show "p to rescan" on windows

Copy link
Owner

Choose a reason for hiding this comment

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

Good call, I too should've gone deeper in the docs before snarking, soz.

src/app.rs Outdated

let percentage = (avg / 100.).clamp(0., 1.0);
let label = format!("{:.1}%", avg);
let percentage = match avg.is_nan() {
Copy link
Owner

Choose a reason for hiding this comment

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

There is defnitely no issue with the code -- I'm thinking that maybe we should just not run the call to draw_fan-speed at all if we're on a fan-less system, because we're checking this every time the loop runs.

Wanna hoist something out side the loop to where we can check if we get values then just never run this code if we don't have to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i will convert it to something like Result<Gauge, Error>, if error is no fans, it will get there is no fans. and, you can implement other errors in future.

@alphastrata
Copy link
Owner

Hey bktexh -- thanks for your contribution:

After thinking more about it I think we'll do something like this:

pub fn run(
    nvml: nvml_wrapper::Nvml,

   /* Snip */

    let mut gpu_list = crate::gpu::try_init_gpus(&nvml, lh)?; //Line 32, in `src/app.rs

    // Let's work out if there's any GPUs we can get a fan off.
    let has_fans = gpu_list
        .iter()
        .any(|gpu| gpu.inner.num_fans().map_or(0, |fc| fc) != 0);
   /* Snip */
    // Then later (in the endless loop:
    // Fanspeed:
    if has_fans {
        let fan_gauge = draw_fan_speed(gpu);
        f.render_widget(fan_gauge, chunks[2]);
    }

(apologies for not writing more code to exemplify what I'm after here, on mobile & on the move atm.

src/app.rs Outdated Show resolved Hide resolved
src/app.rs Outdated Show resolved Hide resolved
src/app.rs Show resolved Hide resolved
src/app.rs Show resolved Hide resolved
@alphastrata alphastrata merged commit 1e36af8 into alphastrata:main Oct 10, 2023
1 check passed
@alphastrata
Copy link
Owner

Thank you :)

@bktech2021
Copy link
Contributor Author

i forgot something, we are only checking at program start, not when rescanning

@alphastrata
Copy link
Owner

I'll fix it in an hour or so -- don't think it'll tick anyone off too badly till then 😉

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.

2 participants