Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools/power/x86: Add SOC slider and platform profile support

Add support for reading and writing SOC slider parameters and
platform profile via sysfs in x86_energy_perf_policy.

New command-line options:
--soc-slider-balance <value>
--soc-slider-offset <value>
--platform-profile <name>

These options allow control of the processor thermal SOC
slider balance and offset through the
processor_thermal_soc_slider module, as well as the
platform profile class interface.

When no update flags are set, the tool now also prints
the current SOC slider and platform profile values
alongside existing MSR output.

Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>

authored by

Kaushlendra Kumar and committed by
Len Brown
feffac18 028ef9c9

+130 -2
+130 -2
tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
··· 92 92 93 93 unsigned int bdx_highest_ratio; 94 94 95 + unsigned char update_soc_slider_balance; 96 + unsigned char update_soc_slider_offset; 97 + unsigned char update_platform_profile; 98 + int soc_slider_balance; 99 + int soc_slider_offset; 100 + char platform_profile[64]; 101 + 95 102 #define PATH_TO_CPU "/sys/devices/system/cpu/" 96 103 #define SYSFS_PATH_MAX 255 104 + #define PATH_SOC_SLIDER_BALANCE "/sys/module/processor_thermal_soc_slider/parameters/slider_balance" 105 + #define PATH_SOC_SLIDER_OFFSET "/sys/module/processor_thermal_soc_slider/parameters/slider_offset" 106 + #define PATH_PLATFORM_PROFILE "/sys/class/platform-profile/platform-profile-0/profile" 97 107 98 108 static int use_android_msr_path; 99 109 ··· 116 106 fprintf(stderr, "scope: --cpu cpu-list [--hwp-use-pkg #] | --pkg pkg-list\n"); 117 107 fprintf(stderr, "field: --all | --epb | --hwp-epp | --hwp-min | --hwp-max | --hwp-desired\n"); 118 108 fprintf(stderr, "other: --hwp-enable | --turbo-enable (0 | 1) | --help | --force\n"); 109 + fprintf(stderr, "soc-slider: --soc-slider-balance # | --soc-slider-offset # | --platform-profile <name>\n"); 119 110 fprintf(stderr, 120 111 "value: ( # | \"normal\" | \"performance\" | \"balance-performance\" | \"balance-power\"| \"power\")\n"); 121 112 fprintf(stderr, "--hwp-window usec\n"); ··· 529 518 } 530 519 } 531 520 521 + static int parse_cmdline_int(const char *s, int *out) 522 + { 523 + char *endp; 524 + long val; 525 + 526 + val = strtol(s, &endp, 0); 527 + if (endp == s || errno == ERANGE) 528 + return -1; 529 + if (*endp != '\0') 530 + return -1; 531 + if (val < INT_MIN || val > INT_MAX) 532 + return -1; 533 + 534 + *out = (int)val; 535 + return 0; 536 + } 537 + 532 538 void print_version(void) 533 539 { 534 540 printf("x86_energy_perf_policy 2025.11.22 Len Brown <lenb@kernel.org>\n"); ··· 574 546 {"hwp-use-pkg", required_argument, 0, 'u'}, 575 547 {"version", no_argument, 0, 'v'}, 576 548 {"hwp-window", required_argument, 0, 'w'}, 549 + {"soc-slider-balance", required_argument, 0, 'S'}, 550 + {"soc-slider-offset", required_argument, 0, 'O'}, 551 + {"platform-profile", required_argument, 0, 'F'}, 577 552 {0, 0, 0, 0 } 578 553 }; 579 554 580 555 progname = argv[0]; 581 556 582 - while ((opt = getopt_long_only(argc, argv, "+a:c:dD:E:e:f:m:M:rt:u:vw:", 557 + while ((opt = getopt_long_only(argc, argv, "+a:c:dD:E:e:f:m:M:rt:u:vw::S:O:F:", 583 558 long_options, &option_index)) != -1) { 584 559 switch (opt) { 585 560 case 'a': ··· 610 579 case 'D': 611 580 req_update.hwp_desired = parse_cmdline_hwp_desired(parse_optarg_string(optarg)); 612 581 break; 582 + case 'F': 583 + if (strlen(optarg) >= sizeof(platform_profile)) 584 + errx(1, "--platform-profile: value too long"); 585 + strcpy(platform_profile, optarg); 586 + update_platform_profile = 1; 587 + break; 613 588 case 'm': 614 589 req_update.hwp_min = parse_cmdline_hwp_min(parse_optarg_string(optarg)); 615 590 break; 616 591 case 'M': 617 592 req_update.hwp_max = parse_cmdline_hwp_max(parse_optarg_string(optarg)); 593 + break; 594 + case 'O': 595 + if (parse_cmdline_int(optarg, &soc_slider_offset)) 596 + errx(1, "--soc-slider-offset: invalid value"); 597 + update_soc_slider_offset = 1; 618 598 break; 619 599 case 'p': 620 600 parse_cmdline_pkg(optarg); ··· 635 593 break; 636 594 case 'r': 637 595 /* v1 used -r to specify read-only mode, now the default */ 596 + break; 597 + case 'S': 598 + if (parse_cmdline_int(optarg, &soc_slider_balance)) 599 + errx(1, "--soc-slider-balance: invalid value"); 600 + update_soc_slider_balance = 1; 638 601 break; 639 602 case 't': 640 603 turbo_update_value = parse_cmdline_turbo(parse_optarg_string(optarg)); ··· 824 777 return (unsigned int) numwritten; 825 778 } 826 779 780 + static int sysfs_read_string(const char *path, char *buf, size_t buflen) 781 + { 782 + unsigned int len; 783 + size_t n; 784 + 785 + len = read_sysfs(path, buf, buflen); 786 + if (!len) 787 + return -1; 788 + 789 + n = strcspn(buf, "\n"); 790 + buf[n] = '\0'; 791 + return 0; 792 + } 793 + 794 + static int sysfs_write_string(const char *path, const char *buf) 795 + { 796 + char tmp[128]; 797 + int len; 798 + 799 + len = snprintf(tmp, sizeof(tmp), "%s\n", buf); 800 + if (len < 0 || len >= (int)sizeof(tmp)) 801 + return -1; 802 + return write_sysfs(path, tmp, (size_t)len + 1) ? 0 : -1; 803 + } 804 + 827 805 void print_hwp_cap(int cpu, struct msr_hwp_cap *cap, char *str) 828 806 { 829 807 if (cpu != -1) ··· 970 898 return -1; 971 899 972 900 return (int)val; 901 + } 902 + 903 + static int soc_slider_available(void) 904 + { 905 + if (access(PATH_SOC_SLIDER_BALANCE, R_OK) && 906 + access(PATH_SOC_SLIDER_OFFSET, R_OK) && 907 + access(PATH_PLATFORM_PROFILE, R_OK)) 908 + return 0; 909 + 910 + return 1; 911 + } 912 + 913 + static void print_soc_slider(void) 914 + { 915 + char buf[64]; 916 + 917 + if (!soc_slider_available()) 918 + return; 919 + 920 + if (sysfs_read_string(PATH_SOC_SLIDER_BALANCE, buf, sizeof(buf)) == 0) 921 + printf("soc-slider-balance: %s\n", buf); 922 + if (sysfs_read_string(PATH_SOC_SLIDER_OFFSET, buf, sizeof(buf)) == 0) 923 + printf("soc-slider-offset: %s\n", buf); 924 + if (sysfs_read_string(PATH_PLATFORM_PROFILE, buf, sizeof(buf)) == 0) 925 + printf("platform-profile: %s\n", buf); 926 + } 927 + 928 + static int update_soc_slider(void) 929 + { 930 + char tmp[32]; 931 + 932 + if (update_soc_slider_balance) { 933 + snprintf(tmp, sizeof(tmp), "%d", soc_slider_balance); 934 + if (sysfs_write_string(PATH_SOC_SLIDER_BALANCE, tmp)) 935 + err(1, "soc-slider-balance write failed"); 936 + } 937 + 938 + if (update_soc_slider_offset) { 939 + snprintf(tmp, sizeof(tmp), "%d", soc_slider_offset); 940 + if (sysfs_write_string(PATH_SOC_SLIDER_OFFSET, tmp)) 941 + err(1, "soc-slider-offset write failed"); 942 + } 943 + 944 + if (update_platform_profile) { 945 + if (sysfs_write_string(PATH_PLATFORM_PROFILE, platform_profile)) 946 + err(1, "platform-profile write failed"); 947 + } 948 + 949 + return 0; 973 950 } 974 951 975 952 int print_cpu_msrs(int cpu) ··· 1725 1604 return -EINVAL; 1726 1605 1727 1606 /* display information only, no updates to settings */ 1728 - if (!update_epb && !update_turbo && !hwp_update_enabled()) { 1607 + if (!update_epb && !update_turbo && !hwp_update_enabled() && 1608 + !update_soc_slider_balance && !update_soc_slider_offset && 1609 + !update_platform_profile) { 1729 1610 if (cpu_selected_set) 1730 1611 for_all_cpus_in_set(cpu_setsize, cpu_selected_set, print_cpu_msrs); 1612 + 1613 + print_soc_slider(); 1731 1614 1732 1615 if (has_hwp_request_pkg) { 1733 1616 if (pkg_selected_set == 0) ··· 1752 1627 1753 1628 } else if (pkg_selected_set) 1754 1629 for_packages(pkg_selected_set, update_hwp_request_pkg_msr); 1630 + 1631 + if (update_soc_slider_balance || update_soc_slider_offset || update_platform_profile) 1632 + update_soc_slider(); 1755 1633 1756 1634 return 0; 1757 1635 }