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_energy_perf_policy: Enhances SoC Slider related checks

When processor_thermal_soc_slider is loaded, its slider
and offset modparams are visible. Check that the driver
actually registered the profile named "SoC Slider" before
reading or writing these modparams.

n.b. This utility allows writing the Slider and Offset modparams
even if the driver policy is not "balanced". Currently the
processor_thermal_soc_slider consults those modparams
only in "balanced" mode.

Signed-off-by: Len Brown <len.brown@intel.com>

+104 -38
+104 -38
tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
··· 104 104 #define PATH_SOC_SLIDER_BALANCE "/sys/module/processor_thermal_soc_slider/parameters/slider_balance" 105 105 #define PATH_SOC_SLIDER_OFFSET "/sys/module/processor_thermal_soc_slider/parameters/slider_offset" 106 106 #define PATH_PLATFORM_PROFILE "/sys/class/platform-profile/platform-profile-0/profile" 107 + #define PATH_PLATFORM_PROFILE_NAME "/sys/class/platform-profile/platform-profile-0/name" 108 + #define POWER_SLIDER_NAME "SoC Power Slider" 107 109 108 110 static int use_android_msr_path; 111 + 112 + static unsigned int read_sysfs(const char *, char *, size_t); 113 + static int sysfs_read_string(const char *, char *, size_t); 109 114 110 115 /* 111 116 * maintain compatibility with original implementation, but don't document it: ··· 556 551 printf("x86_energy_perf_policy 2025.11.22 Len Brown <lenb@kernel.org>\n"); 557 552 } 558 553 554 + static int platform_profile_access(int mode) 555 + { 556 + if (access(PATH_PLATFORM_PROFILE, mode)) { 557 + if (debug) 558 + fprintf(stderr, "Can not access %s\n", PATH_PLATFORM_PROFILE); 559 + return 0; 560 + } 561 + 562 + return 1; 563 + } 564 + 565 + static int platform_profile_name_is(char *name) 566 + { 567 + char buf[64]; 568 + 569 + if (sysfs_read_string(PATH_PLATFORM_PROFILE_NAME, buf, sizeof(buf)) != 0) { 570 + if (debug) 571 + fprintf(stderr, "Can not read %s\n", PATH_PLATFORM_PROFILE_NAME); 572 + return 0; 573 + } 574 + 575 + if (strncmp(buf, name, 16)) { 576 + if (debug) 577 + fprintf(stderr, "%s does not match '%s'\n", PATH_PLATFORM_PROFILE_NAME, name); 578 + return 0; 579 + } 580 + 581 + return 1; 582 + } 583 + 584 + static int soc_slider_access(int mode) 585 + { 586 + if (!platform_profile_access(R_OK)) 587 + return 0; 588 + 589 + if (!platform_profile_name_is(POWER_SLIDER_NAME)) 590 + return 0; 591 + 592 + if (access(PATH_SOC_SLIDER_BALANCE, mode)) { 593 + if (debug) 594 + fprintf(stderr, "Can not access %s\n", PATH_SOC_SLIDER_BALANCE); 595 + return 0; 596 + } 597 + 598 + if (access(PATH_SOC_SLIDER_OFFSET, mode)) { 599 + if (debug) 600 + fprintf(stderr, "Can not access %s\n", PATH_SOC_SLIDER_OFFSET); 601 + return 0; 602 + } 603 + 604 + return 1; 605 + } 606 + 559 607 void cmdline(int argc, char **argv) 560 608 { 561 609 int opt; 562 610 int option_index = 0; 563 611 564 612 static struct option long_options[] = { 565 - {"all", required_argument, 0, 'a'}, 566 - {"cpu", required_argument, 0, 'c'}, 567 - {"pkg", required_argument, 0, 'p'}, 568 - {"debug", no_argument, 0, 'd'}, 569 - {"hwp-desired", required_argument, 0, 'D'}, 570 - {"epb", required_argument, 0, 'B'}, 571 - {"force", no_argument, 0, 'f'}, 572 - {"hwp-enable", no_argument, 0, 'e'}, 573 - {"help", no_argument, 0, 'h'}, 574 - {"hwp-epp", required_argument, 0, 'P'}, 575 - {"hwp-min", required_argument, 0, 'm'}, 576 - {"hwp-max", required_argument, 0, 'M'}, 577 - {"read", no_argument, 0, 'r'}, 578 - {"turbo-enable", required_argument, 0, 't'}, 579 - {"hwp-use-pkg", required_argument, 0, 'u'}, 580 - {"version", no_argument, 0, 'v'}, 581 - {"hwp-window", required_argument, 0, 'w'}, 582 - {"soc-slider-balance", required_argument, 0, 'S'}, 583 - {"soc-slider-offset", required_argument, 0, 'O'}, 584 - {"platform-profile", required_argument, 0, 'F'}, 585 - {0, 0, 0, 0 } 613 + { "all", required_argument, 0, 'a' }, 614 + { "cpu", required_argument, 0, 'c' }, 615 + { "pkg", required_argument, 0, 'p' }, 616 + { "debug", no_argument, 0, 'd' }, 617 + { "hwp-desired", required_argument, 0, 'D' }, 618 + { "epb", required_argument, 0, 'B' }, 619 + { "force", no_argument, 0, 'f' }, 620 + { "hwp-enable", no_argument, 0, 'e' }, 621 + { "help", no_argument, 0, 'h' }, 622 + { "hwp-epp", required_argument, 0, 'P' }, 623 + { "hwp-min", required_argument, 0, 'm' }, 624 + { "hwp-max", required_argument, 0, 'M' }, 625 + { "read", no_argument, 0, 'r' }, 626 + { "turbo-enable", required_argument, 0, 't' }, 627 + { "hwp-use-pkg", required_argument, 0, 'u' }, 628 + { "version", no_argument, 0, 'v' }, 629 + { "hwp-window", required_argument, 0, 'w' }, 630 + { "soc-slider-balance", required_argument, 0, 'S' }, 631 + { "soc-slider-offset", required_argument, 0, 'O' }, 632 + { "platform-profile", required_argument, 0, 'F' }, 633 + { 0, 0, 0, 0 } 586 634 }; 587 635 588 636 progname = argv[0]; 589 637 590 - while ((opt = getopt_long_only(argc, argv, "+a:c:dD:E:e:f:m:M:rt:u:vw::S:O:F:", 591 - long_options, &option_index)) != -1) { 638 + while ((opt = getopt_long_only(argc, argv, "+a:c:dD:E:e:f:m:M:rt:u:vw::S:O:F:", long_options, &option_index)) != -1) { 592 639 switch (opt) { 593 640 case 'a': 594 641 parse_cmdline_all(optarg); ··· 670 613 case 'F': 671 614 if (strlen(optarg) >= sizeof(platform_profile)) 672 615 errx(1, "--platform-profile: value too long"); 616 + if (!platform_profile_access(W_OK)) 617 + errx(1, "Can not update platform-profile in '%s'", PATH_PLATFORM_PROFILE); 673 618 strcpy(platform_profile, optarg); 674 619 update_platform_profile = 1; 675 620 break; ··· 684 625 case 'O': 685 626 if (parse_cmdline_int(optarg, &soc_slider_offset)) 686 627 errx(1, "--soc-slider-offset: invalid value"); 628 + if (!soc_slider_access(W_OK)) 629 + errx(1, "Unable to write SOC Slider Offset"); 687 630 update_soc_slider_offset = 1; 688 631 break; 689 632 case 'p': ··· 700 639 case 'S': 701 640 if (parse_cmdline_int(optarg, &soc_slider_balance)) 702 641 errx(1, "--soc-slider-balance: invalid value"); 642 + if (!soc_slider_access(W_OK)) 643 + errx(1, "Unable to write SOC Slider-Balance in '%s'", PATH_SOC_SLIDER_BALANCE); 703 644 update_soc_slider_balance = 1; 704 645 break; 705 646 case 't': ··· 877 814 878 815 numwritten = write(fd, buf, buflen - 1); 879 816 if (numwritten < 1) { 880 - perror("write failed\n"); 817 + buf[strcspn(buf, "\n")] = '\0'; 818 + warn("Write '%s' to '%s' failed", buf, path); 881 819 close(fd); 882 820 return -1; 883 821 } ··· 1036 972 return (int)val; 1037 973 } 1038 974 1039 - static int soc_slider_available(void) 1040 - { 1041 - if (access(PATH_SOC_SLIDER_BALANCE, R_OK) && 1042 - access(PATH_SOC_SLIDER_OFFSET, R_OK) && 1043 - access(PATH_PLATFORM_PROFILE, R_OK)) 1044 - return 0; 1045 - 1046 - return 1; 1047 - } 1048 - 1049 975 static void print_soc_slider(void) 1050 976 { 1051 977 char buf[64]; 1052 978 1053 - if (!soc_slider_available()) 979 + if (!soc_slider_access(R_OK)) 1054 980 return; 1055 981 1056 982 if (sysfs_read_string(PATH_SOC_SLIDER_BALANCE, buf, sizeof(buf)) == 0) 1057 983 printf("soc-slider-balance: %s\n", buf); 984 + 1058 985 if (sysfs_read_string(PATH_SOC_SLIDER_OFFSET, buf, sizeof(buf)) == 0) 1059 986 printf("soc-slider-offset: %s\n", buf); 987 + } 988 + 989 + static void print_platform_profile(void) 990 + { 991 + char buf[64]; 992 + 993 + if (!platform_profile_access(R_OK)) 994 + return; 995 + 996 + if (sysfs_read_string(PATH_PLATFORM_PROFILE_NAME, buf, sizeof(buf)) == 0) 997 + printf("platform-profile-name: %s\n", buf); 998 + 1060 999 if (sysfs_read_string(PATH_PLATFORM_PROFILE, buf, sizeof(buf)) == 0) 1061 1000 printf("platform-profile: %s\n", buf); 1062 1001 } ··· 1792 1725 return -EINVAL; 1793 1726 1794 1727 /* display information only, no updates to settings */ 1795 - if (!update_epb && !update_turbo && !hwp_update_enabled() && 1796 - !update_soc_slider_balance && !update_soc_slider_offset && 1797 - !update_platform_profile) { 1728 + if (!update_epb && !update_turbo && !hwp_update_enabled() && !update_soc_slider_balance && !update_soc_slider_offset && !update_platform_profile) { 1798 1729 if (cpu_selected_set) 1799 1730 for_all_cpus_in_set(cpu_setsize, cpu_selected_set, print_cpu_msrs); 1800 1731 1801 1732 print_soc_slider(); 1733 + print_platform_profile(); 1802 1734 1803 1735 if (has_hwp_request_pkg) { 1804 1736 if (pkg_selected_set == 0)