From 84b0a624cd8b6678c4a7f6bae0c0b8c1609ae952 Mon Sep 17 00:00:00 2001 From: kat witch Date: Mon, 10 Jan 2022 17:06:26 +0000 Subject: [PATCH] TSC tolerance patch, CPU-line fixes, ... --- config/hosts/goliath.nix | 4 ++++ config/profiles/vfio/profile.nix | 10 +++++++-- config/profiles/vfio/tsc-tolerance.patch | 26 ++++++++++++++++++++++++ config/tf | 2 +- overlays/local/vm-pinning.nix | 8 +++++++- overlays/local/vm.nix | 3 ++- 6 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 config/profiles/vfio/tsc-tolerance.patch diff --git a/config/hosts/goliath.nix b/config/hosts/goliath.nix index 742abd38..bec94c73 100644 --- a/config/hosts/goliath.nix +++ b/config/hosts/goliath.nix @@ -185,6 +185,10 @@ mkIf (vfio-pci-ids != [ ]) { options.ids = concatStringsSep "," vfio-pci-ids; }; + kvm_amd.options = { + avic = true; + npt = true; + }; }; services.udev.extraRules = '' diff --git a/config/profiles/vfio/profile.nix b/config/profiles/vfio/profile.nix index 47f2e3ca..a5e5e8d6 100644 --- a/config/profiles/vfio/profile.nix +++ b/config/profiles/vfio/profile.nix @@ -129,11 +129,11 @@ in { (hugepages { where = "/dev/hugepages1G"; options = "pagesize=1GB,mode=0775"; }) ]; - fileSystems."/sys/fs/cgroup/cpuset" = { + /* fileSystems."/sys/fs/cgroup/cpuset" = { device = "cpuset"; fsType = "cgroup"; noCheck = true; - }; + }; */ systemd.services.preallocate-huggies = { wantedBy = singleton "multi-user.target"; @@ -149,9 +149,15 @@ in { boot = lib.mkMerge [{ initrd.kernelModules = mkBefore [ "vfio" "vfio_iommu_type1" "vfio_pci" "vfio_virqfd" ]; + kernelParams = [ + ]; kernelModules = [ "i2c-dev" ]; # i2c-dev is required for DDC/CI for screenstub kernelPatches = with pkgs.kernelPatches; [ (mkIf config.deploy.profile.hardware.acs-override acs-override) + { + name = "clocksource-reduce-tsc-tolerance"; + patch = ./tsc-tolerance.patch; + } ]; } (mkIf (config.deploy.profile.hardware.amdgpu) { diff --git a/config/profiles/vfio/tsc-tolerance.patch b/config/profiles/vfio/tsc-tolerance.patch new file mode 100644 index 00000000..e100b221 --- /dev/null +++ b/config/profiles/vfio/tsc-tolerance.patch @@ -0,0 +1,26 @@ +From 5cac0c3c4383010f0579028de8decd6ede4bd460 Mon Sep 17 00:00:00 2001 +From: Stefan Springer +Date: Sun, 3 Oct 2021 23:26:40 +0200 +Subject: [PATCH] clocksource: set WATCHDOG_MAX_SKEW to 60 + +in order to find a more relaxed middleground between the old default (100) and the new one(50) +--- + kernel/time/clocksource.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c +index b8a14d2fb..f8f848d13 100644 +--- a/kernel/time/clocksource.c ++++ b/kernel/time/clocksource.c +@@ -107,7 +107,7 @@ static u64 suspend_start; + * This delay could be due to SMIs, NMIs, or to VCPU preemptions. Used as + * a lower bound for cs->uncertainty_margin values when registering clocks. + */ +-#define WATCHDOG_MAX_SKEW (50 * NSEC_PER_USEC) ++#define WATCHDOG_MAX_SKEW (60 * NSEC_PER_USEC) + + #ifdef CONFIG_CLOCKSOURCE_WATCHDOG + static void clocksource_watchdog_work(struct work_struct *work); +-- +2.32.0 + diff --git a/config/tf b/config/tf index 5ebe5539..82aa63da 160000 --- a/config/tf +++ b/config/tf @@ -1 +1 @@ -Subproject commit 5ebe55390f615f537be4eda6adaae6656d96655b +Subproject commit 82aa63dafe2fc353ab90475c2cc48069c32738c5 diff --git a/overlays/local/vm-pinning.nix b/overlays/local/vm-pinning.nix index 1cc89b9e..b2340857 100644 --- a/overlays/local/vm-pinning.nix +++ b/overlays/local/vm-pinning.nix @@ -59,7 +59,13 @@ for task in /proc/$QEMU_PID/task/*; do case $TASKNAME in worker | qemu-system-*) echo worker is $TASKNAME - ;; + ;; + IO*) + regex="IO iothread([0-9]*)" + if [[ $TASKNAME =~ $regex ]]; then + chrt -f -p 1 $TASK + fi + ;; CPU*) regex="CPU ([0-9]*)/KVM" if [[ $TASKNAME =~ $regex ]]; then diff --git a/overlays/local/vm.nix b/overlays/local/vm.nix index 97a170f6..bed43611 100644 --- a/overlays/local/vm.nix +++ b/overlays/local/vm.nix @@ -9,7 +9,8 @@ writeShellScriptBin "win10-vm" '' -blockdev '{"node-name":"libvirt-pflash1-format","read-only":false,"driver":"raw","file":"libvirt-pflash1-storage"}' \ -machine pc-q35-5.1,accel=kvm,usb=off,vmport=off,dump-guest-core=off,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format \ -monitor stdio \ - -cpu host,migratable=no,+invtsc,topoext=on,hv-time,hv-vpindex,hv-relaxed,hv-vapic,-amd-stibp,hv-synic,hv-spinlocks=0x1fff,host-cache-info=on,l3-cache=off -m 12288 \ + -cpu host,migratable=no,topoext=on,host-cache-info=on,+invtsc,hv_time,hv_relaxed,hv_vpindex,hv_synic,hv_spinlocks=0x1fff,hv_vendor_id=ab12341234ab$,hv_vapic,-amd-stibp \ + -m 12288 \ -mem-path /dev/hugepages1G/qemu-win10-vm -mem-prealloc \ -smp 8,sockets=1,dies=1,cores=4,threads=2 \ -object iothread,id=iothread1 \