From 002c2c038e0b62638891da954bbf124b45d1a4f9 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Thu, 29 Jun 2023 10:10:52 +0800 Subject: [PATCH 1/6] bpftune: init at unstable-2023-05-30 --- pkgs/os-specific/linux/bpftune/default.nix | 64 ++++++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 2 files changed, 66 insertions(+) create mode 100644 pkgs/os-specific/linux/bpftune/default.nix diff --git a/pkgs/os-specific/linux/bpftune/default.nix b/pkgs/os-specific/linux/bpftune/default.nix new file mode 100644 index 000000000000..09d5f4756191 --- /dev/null +++ b/pkgs/os-specific/linux/bpftune/default.nix @@ -0,0 +1,64 @@ +{ lib +, stdenv +, fetchFromGitHub +, clang +, bpftools +, docutils +, libbpf +, libcap +, libnl +}: + +stdenv.mkDerivation rec { + pname = "bpftune"; + version = "unstable-2023-05-30"; + + src = fetchFromGitHub { + owner = "oracle-samples"; + repo = "bpftune"; + rev = "bfec6668db29ec83afe2b030440f4d8f1476c1a6"; + hash = "sha256-is7y53c9pBSyywVW8hO0iHsVPQlsCb4LU/cJMGf9ua4="; + }; + + postPatch = '' + # otherwise shrink rpath would drop $out/lib from rpath + substituteInPlace src/Makefile \ + --replace /lib64 /lib \ + --replace /sbin /bin + substituteInPlace src/bpftune.service \ + --replace /usr/sbin/bpftune "$out/bin/bpftune" + substituteInPlace include/bpftune/libbpftune.h \ + --replace /usr/lib64/bpftune/ "$out/lib/bpftune/" \ + --replace /usr/local/lib64/bpftune/ "$out/lib/bpftune/" + ''; + + nativeBuildInputs = [ + clang + bpftools + docutils # rst2man + ]; + + buildInputs = [ + libbpf + libcap + libnl + ]; + + makeFlags = [ + "prefix=${placeholder "out"}" + "BPFTUNE_VERSION=${version}" + "BPF_INCLUDE=${lib.getDev libbpf}/include" + "NL_INCLUDE=${lib.getDev libnl}/include/libnl3" + ]; + + hardeningDisable = [ + "stackprotector" + ]; + + meta = with lib; { + description = "BPF-based auto-tuning of Linux system parameters"; + homepage = "https://github.com/oracle-samples/bpftune"; + license = licenses.gpl2Only; + maintainers = with maintainers; [ nickcao ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6194bb7a42aa..41c5cf37130f 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -27219,6 +27219,8 @@ with pkgs; bpf-linker = callPackage ../development/tools/bpf-linker { }; + bpftune = callPackage ../os-specific/linux/bpftune { }; + bpfmon = callPackage ../os-specific/linux/bpfmon { }; bridge-utils = callPackage ../os-specific/linux/bridge-utils { }; From b47c483bf8860ac9dbcc7d72a80f98bfd2b1584a Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Thu, 29 Jun 2023 10:25:41 +0800 Subject: [PATCH 2/6] nixos/bpftune: init --- nixos/modules/module-list.nix | 1 + nixos/modules/services/system/bpftune.nix | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 nixos/modules/services/system/bpftune.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 97abbe219116..46561fef45a8 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -1142,6 +1142,7 @@ ./services/security/vaultwarden/default.nix ./services/security/yubikey-agent.nix ./services/system/automatic-timezoned.nix + ./services/system/bpftune.nix ./services/system/cachix-agent/default.nix ./services/system/cachix-watch-store.nix ./services/system/cloud-init.nix diff --git a/nixos/modules/services/system/bpftune.nix b/nixos/modules/services/system/bpftune.nix new file mode 100644 index 000000000000..d656a19c0ad1 --- /dev/null +++ b/nixos/modules/services/system/bpftune.nix @@ -0,0 +1,22 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.services.bpftune; +in +{ + meta = { + maintainers = with lib.maintainers; [ nickcao ]; + }; + + options = { + services.bpftune = { + enable = lib.mkEnableOption (lib.mdDoc "bpftune BPF driven auto-tuning"); + + package = lib.mkPackageOptionMD pkgs "bpftune" { }; + }; + }; + + config = lib.mkIf cfg.enable { + systemd.packages = [ cfg.package ]; + systemd.services.bpftune.wantedBy = [ "multi-user.target" ]; + }; +} From 4cd70e125d1baabb0846bdbfd4d87cf69e5fed8a Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Thu, 29 Jun 2023 10:43:06 +0800 Subject: [PATCH 3/6] nixos/bpftune: init basic test --- nixos/tests/all-tests.nix | 1 + nixos/tests/bpftune.nix | 37 ++++++++++++++++++++++ pkgs/os-specific/linux/bpftune/default.nix | 5 +++ 3 files changed, 43 insertions(+) create mode 100644 nixos/tests/bpftune.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 723b030072e1..5f4aefad890f 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -138,6 +138,7 @@ in { borgbackup = handleTest ./borgbackup.nix {}; botamusique = handleTest ./botamusique.nix {}; bpf = handleTestOn ["x86_64-linux" "aarch64-linux"] ./bpf.nix {}; + bpftune = handleTest ./bpftune.nix {}; breitbandmessung = handleTest ./breitbandmessung.nix {}; brscan5 = handleTest ./brscan5.nix {}; btrbk = handleTest ./btrbk.nix {}; diff --git a/nixos/tests/bpftune.nix b/nixos/tests/bpftune.nix new file mode 100644 index 000000000000..63fcfc8b8199 --- /dev/null +++ b/nixos/tests/bpftune.nix @@ -0,0 +1,37 @@ +import ./make-test-python.nix ({ lib, pkgs, ... }: { + + name = "bpftune"; + + meta = { + maintainers = with lib.maintainers; [ nickcao ]; + }; + + nodes = { + client = { pkgs, ... }: { + services.bpftune.enable = true; + + boot.kernel.sysctl."net.ipv4.tcp_rmem" = "4096 131072 1310720"; + + environment.systemPackages = [ pkgs.iperf3 ]; + }; + + server = { ... }: { + services.iperf3 = { + enable = true; + openFirewall = true; + }; + }; + }; + + testScript = '' + with subtest("bpftune startup"): + client.wait_for_unit("bpftune.service") + client.wait_for_console_text("bpftune works fully") + + with subtest("bpftune tcp buffer size"): + server.wait_for_unit("iperf3.service") + client.succeed("iperf3 --reverse -c server") + client.wait_for_console_text("need to increase TCP buffer size") + ''; + +}) diff --git a/pkgs/os-specific/linux/bpftune/default.nix b/pkgs/os-specific/linux/bpftune/default.nix index 09d5f4756191..089aee11fb3f 100644 --- a/pkgs/os-specific/linux/bpftune/default.nix +++ b/pkgs/os-specific/linux/bpftune/default.nix @@ -7,6 +7,7 @@ , libbpf , libcap , libnl +, nixosTests }: stdenv.mkDerivation rec { @@ -55,6 +56,10 @@ stdenv.mkDerivation rec { "stackprotector" ]; + passthru.tests = { + inherit (nixosTests) bpftune; + }; + meta = with lib; { description = "BPF-based auto-tuning of Linux system parameters"; homepage = "https://github.com/oracle-samples/bpftune"; From 975bd53d395a4fb674d02ce7ccff82045e9fcd67 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Tue, 11 Jul 2023 17:40:58 +0800 Subject: [PATCH 4/6] bpftune: unstable-2023-05-30 -> unstable-2023-07-11 Diff: https://github.com/oracle-samples/bpftune/compare/bfec6668db29ec83afe2b030440f4d8f1476c1a6...f2eb8e9c020261cc8c58b312841dec32d287a0cc --- pkgs/os-specific/linux/bpftune/default.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkgs/os-specific/linux/bpftune/default.nix b/pkgs/os-specific/linux/bpftune/default.nix index 089aee11fb3f..2cdbddc28593 100644 --- a/pkgs/os-specific/linux/bpftune/default.nix +++ b/pkgs/os-specific/linux/bpftune/default.nix @@ -12,20 +12,21 @@ stdenv.mkDerivation rec { pname = "bpftune"; - version = "unstable-2023-05-30"; + version = "unstable-2023-07-11"; src = fetchFromGitHub { owner = "oracle-samples"; repo = "bpftune"; - rev = "bfec6668db29ec83afe2b030440f4d8f1476c1a6"; - hash = "sha256-is7y53c9pBSyywVW8hO0iHsVPQlsCb4LU/cJMGf9ua4="; + rev = "f2eb8e9c020261cc8c58b312841dec32d287a0cc"; + hash = "sha256-M5Zl4TzifQ3TkmCEBgKtv/kwichUY0PXQaQQThkTn2Q="; }; postPatch = '' # otherwise shrink rpath would drop $out/lib from rpath substituteInPlace src/Makefile \ - --replace /lib64 /lib \ - --replace /sbin /bin + --replace /lib64 /lib \ + --replace /sbin /bin \ + --replace ldconfig true substituteInPlace src/bpftune.service \ --replace /usr/sbin/bpftune "$out/bin/bpftune" substituteInPlace include/bpftune/libbpftune.h \ @@ -47,6 +48,7 @@ stdenv.mkDerivation rec { makeFlags = [ "prefix=${placeholder "out"}" + "confprefix=${placeholder "out"}/etc" "BPFTUNE_VERSION=${version}" "BPF_INCLUDE=${lib.getDev libbpf}/include" "NL_INCLUDE=${lib.getDev libnl}/include/libnl3" From bc8224cab6eb57117193f3ac06fcc46d5775cd4c Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Mon, 17 Jul 2023 15:58:34 +0800 Subject: [PATCH 5/6] bpftune: unstable-2023-07-11 -> unstable-2023-07-14, enable parallel building Diff: https://github.com/oracle-samples/bpftune/compare/f2eb8e9c020261cc8c58b312841dec32d287a0cc...66620152bf8c37ab592e9273fe87e567126801c2 --- pkgs/os-specific/linux/bpftune/default.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/os-specific/linux/bpftune/default.nix b/pkgs/os-specific/linux/bpftune/default.nix index 2cdbddc28593..da1bd1b384bb 100644 --- a/pkgs/os-specific/linux/bpftune/default.nix +++ b/pkgs/os-specific/linux/bpftune/default.nix @@ -12,13 +12,13 @@ stdenv.mkDerivation rec { pname = "bpftune"; - version = "unstable-2023-07-11"; + version = "unstable-2023-07-14"; src = fetchFromGitHub { owner = "oracle-samples"; repo = "bpftune"; - rev = "f2eb8e9c020261cc8c58b312841dec32d287a0cc"; - hash = "sha256-M5Zl4TzifQ3TkmCEBgKtv/kwichUY0PXQaQQThkTn2Q="; + rev = "66620152bf8c37ab592e9273fe87e567126801c2"; + hash = "sha256-U0O+F1DBF1xiaUKklwpZORBwF1T9wHM0SPQKUNaxKZk="; }; postPatch = '' @@ -62,6 +62,8 @@ stdenv.mkDerivation rec { inherit (nixosTests) bpftune; }; + enableParallelBuilding = true; + meta = with lib; { description = "BPF-based auto-tuning of Linux system parameters"; homepage = "https://github.com/oracle-samples/bpftune"; From 3f751bfdf6d1086317d175b628a17690605cccd1 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Tue, 18 Jul 2023 08:48:43 +0800 Subject: [PATCH 6/6] nixos/bpftune: drop flaky tests --- nixos/tests/bpftune.nix | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/nixos/tests/bpftune.nix b/nixos/tests/bpftune.nix index 63fcfc8b8199..c17bbcd11092 100644 --- a/nixos/tests/bpftune.nix +++ b/nixos/tests/bpftune.nix @@ -7,31 +7,14 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: { }; nodes = { - client = { pkgs, ... }: { + machine = { pkgs, ... }: { services.bpftune.enable = true; - - boot.kernel.sysctl."net.ipv4.tcp_rmem" = "4096 131072 1310720"; - - environment.systemPackages = [ pkgs.iperf3 ]; - }; - - server = { ... }: { - services.iperf3 = { - enable = true; - openFirewall = true; - }; }; }; testScript = '' - with subtest("bpftune startup"): - client.wait_for_unit("bpftune.service") - client.wait_for_console_text("bpftune works fully") - - with subtest("bpftune tcp buffer size"): - server.wait_for_unit("iperf3.service") - client.succeed("iperf3 --reverse -c server") - client.wait_for_console_text("need to increase TCP buffer size") + machine.wait_for_unit("bpftune.service") + machine.wait_for_console_text("bpftune works") ''; })