hitagi: Fully support Intel Arc #70

Open
opened 2023-02-12 00:04:23 +01:00 by simon · 2 comments
Owner

The following works/doesn’t work:

  • Basic video output (requires Linux 6.2 to work OOTB)
  • Audio output
  • OpenGL/Vulkan (requires Mesa 22.3 to work OOTB)
  • Hardware decoding (VAAPI) (tested with mpv)
  • OpenCL (tested with waifu2x-converter-cpp)
  • oneAPI (tested with nix-warezblender-bin)
  • hwmon (partial)
    • energy monitoring (not fully; sensors shows the voltage, maximum power, and energy (cumulative, so in joules!), but the current power draw is not available)
    • fan control/monitoring
    • temperature monitoring
  • usage monitoring (basic; with intel_gpu_top)
  • nice usage monitoring
    • mangohud (only has workaround of calling intel_gpu_top, which has limitations)
    • nvtop (does not yet support much of anything)
  • pytorch (upstream does not support any of the GPU’s APIs yet; there is intel_extension_for_pytorch, which however is far from a drop-in-replacement)

Not having hwmon for temperature means that it is not possible to control the case fans conditionally on max(cpu,gpu,nvme).

The following works/doesn’t work: - [X] Basic video output (requires Linux 6.2 to work OOTB) - [X] Audio output - [X] OpenGL/Vulkan (requires Mesa 22.3 to work OOTB) - [X] Hardware decoding (VAAPI) (tested with mpv) - [X] OpenCL (tested with `waifu2x-converter-cpp`) - [X] oneAPI (tested with `nix-warez`’ `blender-bin`) - [ ] hwmon (partial) - [X] energy monitoring (not fully; sensors shows the voltage, maximum power, and energy (cumulative, so in joules!), but the current power draw is not available) - [ ] fan control/monitoring - [ ] temperature monitoring - [X] usage monitoring (basic; with `intel_gpu_top`) - [ ] nice usage monitoring - [ ] mangohud (only has workaround of calling `intel_gpu_top`, which has limitations) - [ ] nvtop (does not yet support much of anything) - [ ] pytorch (upstream does not support any of the GPU’s APIs yet; there is `intel_extension_for_pytorch`, which however is far from a drop-in-replacement) Not having hwmon for temperature means that it is not possible to control the case fans conditionally on `max(cpu,gpu,nvme)`.
simon added the
blocked by/upstream
type
feature
affects/usability
affects/hardware
labels 2023-02-12 00:04:23 +01:00
Author
Owner

Incomplete/very WIP patch for trying to get mangohud to work inside the steam container:

diff --git a/users/simon/modules/games.nix b/users/simon/modules/games.nix
index 915afe0..cba258c 100644
--- a/users/simon/modules/games.nix
+++ b/users/simon/modules/games.nix
@@ -3,6 +3,29 @@ let
   cfg = nixosConfig.sbruder.games;
   inherit (nixosConfig.sbruder) unfree;
 
+  # part of making mangohud’s makeshift intel arc stats work in bubblewrap
+  capdrop =
+    let
+      source = pkgs.writeText "capdrop.c" ''
+        #include <stdio.h>
+        #include <sys/capability.h>
+        #include <unistd.h>
+
+        int main (int argc, char *argv[]) {
+            if (argc < 2) {
+                fprintf(stderr, "USAGE: capdrop /path/to/executable [args]\n");
+                return 1;
+            }
+            cap_set_proc(0);
+            return execv(argv[1], &argv[1]);
+        }
+      '';
+    in
+    pkgs.runCommandCC "capdrop" { nativeBuildInputs = [ pkgs.libcap ]; } ''
+      mkdir -p $out/bin
+      $CC -lcap ${source} -o $out/bin/capdrop
+    '';
+
   steam-sandbox = pkgs.writeShellScriptBin "steam-sandbox" /* bash */ ''
     set -euo pipefail
     shopt -s nullglob # make for loop work for glob if files do not exist
@@ -67,6 +90,12 @@ let
         --dev-bind /dev/input /dev/input
         --dev-bind-try /dev/uinput /dev/uinput
         --ro-bind /sys /sys # required for discovery
+
+        # hack for intel arc metrics
+        --ro-bind /run/wrappers/bin/intel_gpu_top /run/wrappers/bin/intel_gpu_top
+        --ro-bind /run/wrappers/bin/intel_gpu_top.real /run/wrappers/bin/intel_gpu_top.real
+        --cap-add CAP_SETPCAP
+        --cap-add CAP_PERFMON
       )
 
     for hidraw in /dev/hidraw*; do
@@ -79,7 +108,10 @@ let
 
     ${pkgs.bubblewrap}/bin/bwrap \
         "''${bubblewrap_args[@]}" \
-        ''${SANDBOX_COMMAND:-${pkgs.unstable.steam}/bin/steam} \
+        "${pkgs.libcap}/bin/capsh" \
+        "--caps=cap_setpcap" \
+        "--shell=''${SANDBOX_COMMAND:-${pkgs.unstable.steam}/bin/steam}" \
+        "--" \
         "$@"
   '';
 

The problem is getting the capabilities to propagate through both sandboxing layers. Bubblewrap only allows either setting all capabilities (Permitted, Inherited, Effective, Bounding, Ambient) or none. However, I only want to set Bounding capabilities. Because bwrap actually checks for set capabilities, it actually fails (because of legacy things that once required it but it no longer supports) when run with permitted capabilities. Therefore, it is required to drop the capabilities again. However, I could not get this to work inside the second layer (which is added deep inside nixpkgs).

Incomplete/very WIP patch for trying to get mangohud to work inside the steam container: ```diff diff --git a/users/simon/modules/games.nix b/users/simon/modules/games.nix index 915afe0..cba258c 100644 --- a/users/simon/modules/games.nix +++ b/users/simon/modules/games.nix @@ -3,6 +3,29 @@ let cfg = nixosConfig.sbruder.games; inherit (nixosConfig.sbruder) unfree; + # part of making mangohud’s makeshift intel arc stats work in bubblewrap + capdrop = + let + source = pkgs.writeText "capdrop.c" '' + #include <stdio.h> + #include <sys/capability.h> + #include <unistd.h> + + int main (int argc, char *argv[]) { + if (argc < 2) { + fprintf(stderr, "USAGE: capdrop /path/to/executable [args]\n"); + return 1; + } + cap_set_proc(0); + return execv(argv[1], &argv[1]); + } + ''; + in + pkgs.runCommandCC "capdrop" { nativeBuildInputs = [ pkgs.libcap ]; } '' + mkdir -p $out/bin + $CC -lcap ${source} -o $out/bin/capdrop + ''; + steam-sandbox = pkgs.writeShellScriptBin "steam-sandbox" /* bash */ '' set -euo pipefail shopt -s nullglob # make for loop work for glob if files do not exist @@ -67,6 +90,12 @@ let --dev-bind /dev/input /dev/input --dev-bind-try /dev/uinput /dev/uinput --ro-bind /sys /sys # required for discovery + + # hack for intel arc metrics + --ro-bind /run/wrappers/bin/intel_gpu_top /run/wrappers/bin/intel_gpu_top + --ro-bind /run/wrappers/bin/intel_gpu_top.real /run/wrappers/bin/intel_gpu_top.real + --cap-add CAP_SETPCAP + --cap-add CAP_PERFMON ) for hidraw in /dev/hidraw*; do @@ -79,7 +108,10 @@ let ${pkgs.bubblewrap}/bin/bwrap \ "''${bubblewrap_args[@]}" \ - ''${SANDBOX_COMMAND:-${pkgs.unstable.steam}/bin/steam} \ + "${pkgs.libcap}/bin/capsh" \ + "--caps=cap_setpcap" \ + "--shell=''${SANDBOX_COMMAND:-${pkgs.unstable.steam}/bin/steam}" \ + "--" \ "$@" ''; ``` The problem is getting the capabilities to propagate through both sandboxing layers. Bubblewrap only allows either setting all capabilities (Permitted, Inherited, Effective, Bounding, Ambient) or none. However, I only want to set Bounding capabilities. Because bwrap actually checks for set capabilities, it actually fails (because of legacy things that once required it but it no longer supports) when run with permitted capabilities. Therefore, it is required to drop the capabilities again. However, I could not get this to work inside the second layer (which is added deep inside nixpkgs).
Author
Owner

Right now, using mesa from unstable does not work due to inompatible libc/libstdc++ versions of clients and mesa.

Right now, using mesa from unstable does not work due to inompatible libc/libstdc++ versions of clients and mesa.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: simon/nixos-config#70
No description provided.