HASH da2b6802dd8b
DATE 2025-05-13
SUBJECT hardware: add cpu options
FILES 3 CHANGED
HASH da2b6802dd8b
DATE 2025-05-13
SUBJECT hardware: add cpu options
FILES 3 CHANGED
┌─ modules/nixos/hardware/cpu/micro-architectures.nix ───────────────────────┐
│ diff --git a/modules/nixos/hardware/cpu/micro-architectures.nix b/modules/nixos/ha │
│ rdware/cpu/micro-architectures.nix │
│ new file mode 100644 │
│ index 0000000..1525fdd │
│ --- /dev/null │
│ +++ b/modules/nixos/hardware/cpu/micro-architectures.nix │
│ @@ -0,0 +1,83 @@ │
│ +{ │
│ + # <type>.<family>.<model> │
│ + │
│ + # TODO: account for stepping <type>.<family>.<stepping>.<model> │
│ + intel = { │
│ + # only do big core client cpu now │
│ + "6" = { │
│ + "191" = {name = "raptor-lake";}; │
│ + "190" = {name = "raptor-lake";}; │
│ + "186" = {name = "raptor-lake";}; │
│ + "183" = {name = "raptor-lake";}; │
│ + │
│ + "189" = {name = "lunar-lake";}; │
│ + "188" = {name = "lunar-lake";}; │
│ + │
│ + "198" = {name = "arrow-lake";}; │
│ + "197" = {name = "arrow-lake";}; │
│ + "181" = {name = "arrow-lake";}; │
│ + │
│ + "172" = {name = "meteor-lake";}; │
│ + "171" = {name = "meteor-lake";}; │
│ + "170" = {name = "meteor-lake";}; │
│ + │
│ + "154" = {name = "alder-lake";}; │
│ + "151" = {name = "alder-lake";}; │
│ + │
│ + "167" = {name = "rocket-lake";}; │
│ + │
│ + "166" = {name = "comet-lake";}; │
│ + "165" = {name = "comet-lake";}; │
│ + │
│ + "141" = {name = "tiger-lake";}; │
│ + "140" = {name = "tiger-lake";}; │
│ + │
│ + "126" = {name = "ice-lake";}; │
│ + "125" = {name = "ice-lake";}; │
│ + │
│ + "102" = {name = "cannon-lake";}; │
│ + │
│ + "158" = {name = "coffee-lake";}; │
│ + "142" = {name = "coffee-lake";}; │
│ + │
│ + "94" = {name = "skylake";}; │
│ + "78" = {name = "skylake";}; │
│ + │
│ + "71" = {name = "broadwell";}; │
│ + "61" = {name = "broadwell";}; │
│ + │
│ + "70" = {name = "haswell";}; │
│ + "69" = {name = "haswell";}; │
│ + "60" = {name = "haswell";}; │
│ + │
│ + "58" = {name = "ivy-bridge";}; │
│ + │
│ + "42" = {name = "sandy-bridge";}; │
│ + │
│ + "37" = {name = "westmere";}; │
│ + │
│ + "31" = {name = "nehalem";}; │
│ + "30" = {name = "nehalem";}; │
│ + │
│ + "23" = {name = "penryn";}; │
│ + │
│ + "22" = {name = "core";}; │
│ + "15" = {name = "core";}; │
│ + │
│ + "14" = {name = "modified-pentium-m";}; │
│ + │
│ + "21" = {name = "pentium-m";}; │
│ + }; │
│ + }; │
│ + amd = { │
│ + # TODO: zen 5 │
│ + "25" = { │
│ + "96" = {name = "zen4";}; │
│ + "112" = {name = "zen4";}; │
│ + "120" = {name = "zen4c";}; │
│ + "33" = {name = "zen3";}; │
│ + "80" = {name = "zen3";}; │
│ + "1" = {name = "zen3";}; │
│ + }; │
│ + }; │
│ +} │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ ...e/cpu/micro-architectures.nix ───┐
│ diff --git a/modules/nixos/hardware/cpu/micr │
│ o-architectures.nix b/modules/nixos/hardware │
│ /cpu/micro-architectures.nix │
│ new file mode 100644 │
│ index 0000000..1525fdd │
│ --- /dev/null │
│ +++ b/modules/nixos/hardware/cpu/micro-archi │
│ tectures.nix │
│ @@ -0,0 +1,83 @@ │
│ +{ │
│ + # <type>.<family>.<model> │
│ + │
│ + # TODO: account for stepping <type>.<fami │
│ ly>.<stepping>.<model> │
│ + intel = { │
│ + # only do big core client cpu now │
│ + "6" = { │
│ + "191" = {name = "raptor-lake";}; │
│ + "190" = {name = "raptor-lake";}; │
│ + "186" = {name = "raptor-lake";}; │
│ + "183" = {name = "raptor-lake";}; │
│ + │
│ + "189" = {name = "lunar-lake";}; │
│ + "188" = {name = "lunar-lake";}; │
│ + │
│ + "198" = {name = "arrow-lake";}; │
│ + "197" = {name = "arrow-lake";}; │
│ + "181" = {name = "arrow-lake";}; │
│ + │
│ + "172" = {name = "meteor-lake";}; │
│ + "171" = {name = "meteor-lake";}; │
│ + "170" = {name = "meteor-lake";}; │
│ + │
│ + "154" = {name = "alder-lake";}; │
│ + "151" = {name = "alder-lake";}; │
│ + │
│ + "167" = {name = "rocket-lake";}; │
│ + │
│ + "166" = {name = "comet-lake";}; │
│ + "165" = {name = "comet-lake";}; │
│ + │
│ + "141" = {name = "tiger-lake";}; │
│ + "140" = {name = "tiger-lake";}; │
│ + │
│ + "126" = {name = "ice-lake";}; │
│ + "125" = {name = "ice-lake";}; │
│ + │
│ + "102" = {name = "cannon-lake";}; │
│ + │
│ + "158" = {name = "coffee-lake";}; │
│ + "142" = {name = "coffee-lake";}; │
│ + │
│ + "94" = {name = "skylake";}; │
│ + "78" = {name = "skylake";}; │
│ + │
│ + "71" = {name = "broadwell";}; │
│ + "61" = {name = "broadwell";}; │
│ + │
│ + "70" = {name = "haswell";}; │
│ + "69" = {name = "haswell";}; │
│ + "60" = {name = "haswell";}; │
│ + │
│ + "58" = {name = "ivy-bridge";}; │
│ + │
│ + "42" = {name = "sandy-bridge";}; │
│ + │
│ + "37" = {name = "westmere";}; │
│ + │
│ + "31" = {name = "nehalem";}; │
│ + "30" = {name = "nehalem";}; │
│ + │
│ + "23" = {name = "penryn";}; │
│ + │
│ + "22" = {name = "core";}; │
│ + "15" = {name = "core";}; │
│ + │
│ + "14" = {name = "modified-pentium-m";} │
│ ; │
│ + │
│ + "21" = {name = "pentium-m";}; │
│ + }; │
│ + }; │
│ + amd = { │
│ + # TODO: zen 5 │
│ + "25" = { │
│ + "96" = {name = "zen4";}; │
│ + "112" = {name = "zen4";}; │
│ + "120" = {name = "zen4c";}; │
│ + "33" = {name = "zen3";}; │
│ + "80" = {name = "zen3";}; │
│ + "1" = {name = "zen3";}; │
│ + }; │
│ + }; │
│ +} │
└──────────────────────────────────────────────┘
┌─ modules/nixos/hardware/cpu/options.nix ───────────────────────────────────┐
│ diff --git a/modules/nixos/hardware/cpu/options.nix b/modules/nixos/hardware/cpu/o │
│ ptions.nix │
│ new file mode 100644 │
│ index 0000000..9cb5f44 │
│ --- /dev/null │
│ +++ b/modules/nixos/hardware/cpu/options.nix │
│ @@ -0,0 +1,103 @@ │
│ +{ │
│ + lib, │
│ + config, │
│ + ... │
│ +}: let │
│ + inherit (lib) mkOption mkEnableOption; │
│ + inherit (lib.types) enum int str nullOr float; │
│ + cfg = config.ooknet.hardware.cpu; │
│ + microArchMapping = import ./micro-architectures; │
│ + │
│ + lookupMicroArch = cpu: let │
│ + vendor = cpu.type; │
│ + family = toString cpu.model.family; │
│ + model = toString cpu.model.id; │
│ + in │
│ + microArchMapping.${vendor}.${family}.${model} or null; │
│ +in { │
│ + cpu = { │
│ + type = mkOption { │
│ + type = nullOr (enum ["intel" "amd"]); │
│ + default = null; │
│ + }; │
│ + │
│ + model = { │
│ + id = mkOption { │
│ + type = nullOr int; │
│ + default = null; │
│ + description = "CPU model from CPUID"; │
│ + }; │
│ + family = mkOption { │
│ + type = nullOr int; │
│ + default = null; │
│ + description = "CPU family from CPUID"; │
│ + }; │
│ + stepping = mkOption { │
│ + type = nullOr int; │
│ + default = null; │
│ + description = "CPU stepping from CPUID"; │
│ + }; │
│ + }; │
│ + │
│ + name = mkOption { │
│ + type = nullOr str; │
│ + default = null; │
│ + description = "CPU Model Name"; │
│ + example = "Intel(R) Core(TM) i3-10100 CPU @ 3.60GHz"; │
│ + }; │
│ + │
│ + tdp = mkOption { │
│ + type = nullOr int; │
│ + default = null; │
│ + description = '' │
│ + Thermal Design Power in watts. │
│ + Must be manually specified based on CPU model. │
│ + Refer to manufacturer specifications: │
│ + - Intel: https://ark.intel.com │
│ + - AMD: https://www.amd.com/en/products/specifications.html │
│ + ''; │
│ + example = 65; │
│ + }; │
│ + │
│ + baseClock = mkOption { │
│ + type = nullOr float; │
│ + default = null; │
│ + description = "Base clock frequency in GHz"; │
│ + example = 3.8; │
│ + }; │
│ + │
│ + boostClock = mkOption { │
│ + type = nullOr float; │
│ + default = null; │
│ + description = "Boost clock frequency in GHz"; │
│ + example = 4.7; │
│ + }; │
│ + │
│ + cores = mkOption { │
│ + type = int; │
│ + description = "Number of Physical CPU cores the system has"; │
│ + }; │
│ + │
│ + threadsPerCore = mkOption { │
│ + type = int; │
│ + default = 1; │
│ + descrpition = "Number of threads per physical core (hyperthreading)"; │
│ + }; │
│ + │
│ + totalThreads = mkOption { │
│ + type = int; │
│ + default = cfg.cpu.cores * cfg.cpu.threadsPerCore; │
│ + description = "Number of cpu threads the cpu has"; │
│ + readOnly = true; │
│ + }; │
│ + │
│ + microArchitecture = mkOption { │
│ + type = str; │
│ + default = lookupMicroArch cfg; │
│ + description = "CPU microarchitecture (e.g, skylake, zen4)"; │
│ + readOnly = true; │
│ + }; │
│ + │
│ + amd.pstate.enable = mkEnableOption ""; │
│ + }; │
│ +} │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ ...ixos/hardware/cpu/options.nix ───┐
│ diff --git a/modules/nixos/hardware/cpu/opti │
│ ons.nix b/modules/nixos/hardware/cpu/options │
│ .nix │
│ new file mode 100644 │
│ index 0000000..9cb5f44 │
│ --- /dev/null │
│ +++ b/modules/nixos/hardware/cpu/options.nix │
│ @@ -0,0 +1,103 @@ │
│ +{ │
│ + lib, │
│ + config, │
│ + ... │
│ +}: let │
│ + inherit (lib) mkOption mkEnableOption; │
│ + inherit (lib.types) enum int str nullOr f │
│ loat; │
│ + cfg = config.ooknet.hardware.cpu; │
│ + microArchMapping = import ./micro-archite │
│ ctures; │
│ + │
│ + lookupMicroArch = cpu: let │
│ + vendor = cpu.type; │
│ + family = toString cpu.model.family; │
│ + model = toString cpu.model.id; │
│ + in │
│ + microArchMapping.${vendor}.${family}.${ │
│ model} or null; │
│ +in { │
│ + cpu = { │
│ + type = mkOption { │
│ + type = nullOr (enum ["intel" "amd"]); │
│ + default = null; │
│ + }; │
│ + │
│ + model = { │
│ + id = mkOption { │
│ + type = nullOr int; │
│ + default = null; │
│ + description = "CPU model from CPUID │
│ "; │
│ + }; │
│ + family = mkOption { │
│ + type = nullOr int; │
│ + default = null; │
│ + description = "CPU family from CPUI │
│ D"; │
│ + }; │
│ + stepping = mkOption { │
│ + type = nullOr int; │
│ + default = null; │
│ + description = "CPU stepping from CP │
│ UID"; │
│ + }; │
│ + }; │
│ + │
│ + name = mkOption { │
│ + type = nullOr str; │
│ + default = null; │
│ + description = "CPU Model Name"; │
│ + example = "Intel(R) Core(TM) i3-10100 │
│ CPU @ 3.60GHz"; │
│ + }; │
│ + │
│ + tdp = mkOption { │
│ + type = nullOr int; │
│ + default = null; │
│ + description = '' │
│ + Thermal Design Power in watts. │
│ + Must be manually specified based on │
│ CPU model. │
│ + Refer to manufacturer specification │
│ s: │
│ + - Intel: https://ark.intel.com │
│ + - AMD: https://www.amd.com/en/produ │
│ cts/specifications.html │
│ + ''; │
│ + example = 65; │
│ + }; │
│ + │
│ + baseClock = mkOption { │
│ + type = nullOr float; │
│ + default = null; │
│ + description = "Base clock frequency i │
│ n GHz"; │
│ + example = 3.8; │
│ + }; │
│ + │
│ + boostClock = mkOption { │
│ + type = nullOr float; │
│ + default = null; │
│ + description = "Boost clock frequency │
│ in GHz"; │
│ + example = 4.7; │
│ + }; │
│ + │
│ + cores = mkOption { │
│ + type = int; │
│ + description = "Number of Physical CPU │
│ cores the system has"; │
│ + }; │
│ + │
│ + threadsPerCore = mkOption { │
│ + type = int; │
│ + default = 1; │
│ + descrpition = "Number of threads per │
│ physical core (hyperthreading)"; │
│ + }; │
│ + │
│ + totalThreads = mkOption { │
│ + type = int; │
│ + default = cfg.cpu.cores * cfg.cpu.thr │
│ eadsPerCore; │
│ + description = "Number of cpu threads │
│ the cpu has"; │
│ + readOnly = true; │
│ + }; │
│ + │
│ + microArchitecture = mkOption { │
│ + type = str; │
│ + default = lookupMicroArch cfg; │
│ + description = "CPU microarchitecture │
│ (e.g, skylake, zen4)"; │
│ + readOnly = true; │
│ + }; │
│ + │
│ + amd.pstate.enable = mkEnableOption ""; │
│ + }; │
│ +} │
└──────────────────────────────────────────────┘
┌─ modules/nixos/hardware/options.nix ───────────────────────────────────────┐
│ diff --git a/modules/nixos/hardware/options.nix b/modules/nixos/hardware/options.n │
│ ix │
│ index 1e85597..ad240f6 100644 │
│ --- a/modules/nixos/hardware/options.nix │
│ +++ b/modules/nixos/hardware/options.nix │
│ @@ -21,22 +21,6 @@ in { │
│ lact.enable = mkEnableOption "Enable amd tuning software lact"; │
│ }; │
│ │
│ - cpu = { │
│ - type = mkOption { │
│ - type = nullOr (enum ["intel" "amd"]); │
│ - default = null; │
│ - }; │
│ - amd.pstate.enable = mkEnableOption ""; │
│ - cores = mkOption { │
│ - type = int; │
│ - description = "Number of Physical CPU cores the system has"; │
│ - }; │
│ - threads = mkOption { │
│ - type = int; │
│ - description = "Number of cpu threads the cpu has"; │
│ - }; │
│ - }; │
│ - │
│ features = mkOption { │
│ type = listOf (enum [ │
│ "audio" │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ ...es/nixos/hardware/options.nix ───┐
│ diff --git a/modules/nixos/hardware/options. │
│ nix b/modules/nixos/hardware/options.nix │
│ index 1e85597..ad240f6 100644 │
│ --- a/modules/nixos/hardware/options.nix │
│ +++ b/modules/nixos/hardware/options.nix │
│ @@ -21,22 +21,6 @@ in { │
│ lact.enable = mkEnableOption "Enable │
│ amd tuning software lact"; │
│ }; │
│ │
│ - cpu = { │
│ - type = mkOption { │
│ - type = nullOr (enum ["intel" "amd"] │
│ ); │
│ - default = null; │
│ - }; │
│ - amd.pstate.enable = mkEnableOption "" │
│ ; │
│ - cores = mkOption { │
│ - type = int; │
│ - description = "Number of Physical C │
│ PU cores the system has"; │
│ - }; │
│ - threads = mkOption { │
│ - type = int; │
│ - description = "Number of cpu thread │
│ s the cpu has"; │
│ - }; │
│ - }; │
│ - │
│ features = mkOption { │
│ type = listOf (enum [ │
│ "audio" │
└──────────────────────────────────────────────┘
[ BACK TO LOG ]
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET