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

Intel GPU support #903

Merged
merged 9 commits into from
Sep 21, 2024
Merged

Intel GPU support #903

merged 9 commits into from
Sep 21, 2024

Conversation

bjia56
Copy link
Contributor

@bjia56 bjia56 commented Jul 31, 2024

This is a possible implementation for #644. It uses stripped down code from igt-gpu-tools to handle requests to the Linux perf framework and access metrics from the Intel PMU in the same way that intel_gpu_top works. Tested on an Intel Gemini Lake processor's iGPU.
image

Much of the line count comes from sources pulled (and modified) from igt-gpu-tools, including a database of Intel chipsets and their corresponding pretty-print names. Extra dependencies that would have been pulled in by igt-gpu-tools were removed to keep btop standalone.

@ingenarel
Copy link

oh my god i was searching how to have a gpu graph. currently using igpu-tools. would love to see this merged!

@bjia56
Copy link
Contributor Author

bjia56 commented Aug 1, 2024

If folks are interested in testing out this change, I'm building downloadable btop zips (with the Intel support) here: https://github.com/bjia56/btop-builder

My use case is to run btop as part of a Docker or LXC container as part of the Scrypted home video platform. Using the Intel PMU requires privileged/root permissions, so the above builds also contain a workaround for pulling GPU metrics from an http server running on the host.

@aristocratos
Copy link
Owner

@bjia56
Nice work!
Let me now when you think it's ready to go from a draft to a "sharp" PR and I'll start going trough it.

I'm assuming there aren't any conflicting licensing from the code you pulled from igt-gpu-tools?

@bjia56
Copy link
Contributor Author

bjia56 commented Aug 1, 2024

I can clean things up a bit and fix the Makefile (have only been using the CMake builds myself).

Is the http-based metrics endpoint (as a fallback data source) of interest for upstreaming, or would you like to keep only the Intel PMU collection method? The tradeoff is the http endpoint is non-standard, while the PMU requires sudo (or at least CAP_PERFMON permissions). For something like Scrypted, which can be internet-facing, we'd like to minimize the permissions required to run containers.

Regarding licensing, to my understanding igt-gpu-tools is MIT-licensed: https://gitlab.freedesktop.org/drm/igt-gpu-tools
The part that I'm unsure of is the DRM headers, as those appear to be pulled from the Linux kernel repo. I am not a lawyer, but since these sources retain their licensing headers, perhaps that's ok?

@aristocratos
Copy link
Owner

@bjia56

Is the http-based metrics endpoint (as a fallback data source) of interest for upstreaming [...]

I rather avoid pulling in an entire http library for a single use case. As long as we make sure the CAP_PERFMON permission/sudo requirement is well documented. Could maybe add a make setcap to the Makefile that runs setcap on the binary with the correct arguments to make it even easier. Could also be a good idea to log a WARNING when starting up if permissions is missing.

Regarding licensing, to my understanding igt-gpu-tools is MIT-licensed [...]
The part that I'm unsure of is the DRM headers [...]

Looks like there is a MIT notice on the DRM headers also, so if that is the case from the origin it shouldn't be any issue.

It's only a problem if it was GPL, since GPL don't mix with Apache.

@aristocratos aristocratos marked this pull request as ready for review September 21, 2024 11:53
@aristocratos
Copy link
Owner

Nice work @bjia56 :)

Merging in to main.

@aristocratos aristocratos merged commit 24fc97c into aristocratos:main Sep 21, 2024
54 checks passed
@bjia56
Copy link
Contributor Author

bjia56 commented Sep 21, 2024

Thanks for finishing up this PR!

@RudolphSedlin
Copy link

RudolphSedlin commented Sep 22, 2024

Are we certain that this works for Alchemist GPUs using the i915 KMD? I would assume so given the KMD is the same, and yet my A770 is unrecognized. Running in debug mode suggests no GPU collect occurs at all.

@bjia56
Copy link
Contributor Author

bjia56 commented Sep 22, 2024

Does the A770 show up in intel_gpu_top?

@bjia56 bjia56 deleted the intel branch September 22, 2024 23:59
@RudolphSedlin
Copy link

RudolphSedlin commented Sep 23, 2024

Yeah, its shown as just "Intel Dg2 (Gen 12)". Hardware device is also as expected, just /dev/dri/card1. This is rather bizarre, given the codebase should be the same between the two, though it should be worth noting I cleanbuilt igt-gpu-tools, perhaps btop is out-of-date somehow?

@bjia56
Copy link
Contributor Author

bjia56 commented Sep 23, 2024

The reference igt code that was pulled into btop was commit 0f02dc176959e6296866b1bafd3982e277a5e44b from https://gitlab.freedesktop.org/drm/igt-gpu-tools.git. btop uses the PMU to access metrics, so it requires sudo permissions same as igt. If the device itself is unknown by the built-in Intel chip database, then it should show as a Generic device, if I recall correctly.

@andras-tim
Copy link

andras-tim commented Sep 23, 2024

I compiled btop recently with GPU_SUPPORT=true, and then with sudo I saw my Intel GPU. Thanks!

Edit: I have an old, integrated GPU:

$ intel_gpu_top -L
card0                    Intel Kabylake (Gen9)             pci:vendor=8086,device=591B,card=0
└─renderD128

@RudolphSedlin
Copy link

RudolphSedlin commented Sep 23, 2024

How odd, then the device is not generic. Tried to compile with GPU_SUPPORT=true, no dice. May try with Xe, maybe there is something there. @andras-tim, do you get metrics on your Alchemist card?

Edit: No luck, I assumed perhaps a different KMD would expose the PMU differently if the fault was somehow localized to my machine.

@luyu-wu
Copy link

luyu-wu commented Sep 23, 2024

Is there anyway to do this without root? I believe nvtop (and missioncenter) gets basic usage stats without root permissions!
I'll try and find some time to look into it if it's possible (and applicable here).

@lichrot
Copy link

lichrot commented Nov 16, 2024

Is there anyway to do this without root? I believe nvtop (and missioncenter) gets basic usage stats without root permissions! I'll try and find some time to look into it if it's possible (and applicable here).

For those who are still looking for a solution, there's one mentioned in the Intel kernel driver issue

To allow btop (or similar programs that require access to Intel iGPU sysfs) to run without elevating privileges: setcap cap_perfmon=+ep /path/to/btop/executable

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.

7 participants