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

[amdgpu_linux] Add widget type #115

Merged
merged 4 commits into from Jan 3, 2023
Merged

Conversation

shikamaru
Copy link
Contributor

Hi guys,

I’ve had this vicious widget I made about 2 years ago, I use both of the metrics in my config, one with a progressbar and the other with a graph, it works quite well for me. It’s been a long time since I last contributed to vicious (12 years!), hope you guys like this one !

Merry Christmas,

Regards,

Copy link
Member

@McSinyx McSinyx left a comment

Choose a reason for hiding this comment

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

Thank you for the Christmas present! Since I don't have an AMD GPU and it's already working for you, I only left comments on the possible edge cases. Does AMD provide any specification on the presence and format of sysfs files?

_data["{gpu_usage}"] = "N/A"
end

if _mem == nil then
Copy link
Member

Choose a reason for hiding this comment

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

My Lua is rusty now but I suppose _mem == nil should always be true here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I wanted to put that variable in a closure based on the assumption that the max vram wouldn’t change on subsequent calls, but atm it’s a local variable which means it’s called every time, so it could be optimized there, I admit I’m not a lua expert either, how would you do that, define that variable outside of the function ? In practice I don’t notice a negative performance effect but I don’t update the associated widget as often as the performance graph.

Copy link
Member

Choose a reason for hiding this comment

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

I wanted to put that variable in a closure based on the assumption that the max vram wouldn’t change on subsequent calls, [...], how would you do that, define that variable outside of the function ?

Yes, some other widgets also do it.

f = io.open(amdgpu .. "/mem_info_vram_used", "r")
if f then
for line in f:lines() do
_data["{mem_usage}"] = line/_mem*100
Copy link
Member

Choose a reason for hiding this comment

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

I have a feeling line and _mem should be checked to be numbers instead of propagating an attempt to div error to naughtification.

Copy link
Member

Choose a reason for hiding this comment

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

Looking at the specs, it seems mem_info_vram_total and mem_info_vram_used should exist together, but at least one should be checked with tonumber. They should also consist of only one line, thus f:read'*l' can be preferred for better communicating the intention.

@shikamaru
Copy link
Contributor Author

Thanks for the review, I didn’t use everything that the open source amdgpu driver provides, but yeah, a comment pointing to this documentation would probably be helpful : https://www.kernel.org/doc/html/v5.9/gpu/amdgpu.html

@shikamaru
Copy link
Contributor Author

@McSinyx here is what I came up with, I checked with strace now mem_info_vram_total is only read once, I checked for numbers and prevent division by zero and added a link to the documentation. I missed your comment about using f:read, just modified that as well.

Copy link
Member

@McSinyx McSinyx left a comment

Choose a reason for hiding this comment

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

LGTM. _data's fields could be initialized as N/A for better concision but it's a matter of taste. I will be merging this around new year's eve, just in case there's something we missed and for other maintainers to chime in their opinions, if any.

- declare _mem outside of function so that total ram is checked only
  once (performance improvement)
- use string.match and tonumber and check for division by zero
- add link to kernel doc
@McSinyx McSinyx merged commit 47ae72e into vicious-widgets:master Jan 3, 2023
@McSinyx
Copy link
Member

McSinyx commented Jan 3, 2023

😅 I failed my own deadline but happy new year nevertheless 🎆

@shikamaru
Copy link
Contributor Author

thank you man, happy new year!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants