@@ -92,8 +92,18 @@ unsigned int has_hwp_request_pkg; /* IA32_HWP_REQUEST_PKG */
9292
9393unsigned int bdx_highest_ratio ;
9494
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+
95102#define PATH_TO_CPU "/sys/devices/system/cpu/"
96103#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"
97107
98108static int use_android_msr_path ;
99109
@@ -106,6 +116,7 @@ void usage(void)
106116 fprintf (stderr , "scope: --cpu cpu-list [--hwp-use-pkg #] | --pkg pkg-list\n" );
107117 fprintf (stderr , "field: --all | --epb | --hwp-epp | --hwp-min | --hwp-max | --hwp-desired\n" );
108118 fprintf (stderr , "other: --hwp-enable | --turbo-enable (0 | 1) | --help | --force\n" );
119+ fprintf (stderr , "soc-slider: --soc-slider-balance # | --soc-slider-offset # | --platform-profile <name>\n" );
109120 fprintf (stderr ,
110121 "value: ( # | \"normal\" | \"performance\" | \"balance-performance\" | \"balance-power\"| \"power\")\n" );
111122 fprintf (stderr , "--hwp-window usec\n" );
@@ -518,6 +529,23 @@ void for_packages(unsigned long long pkg_set, int (func)(int))
518529 }
519530}
520531
532+ static int parse_cmdline_int (const char * s , int * out )
533+ {
534+ char * endp ;
535+ long val ;
536+
537+ val = strtol (s , & endp , 0 );
538+ if (endp == s || errno == ERANGE )
539+ return -1 ;
540+ if (* endp != '\0' )
541+ return -1 ;
542+ if (val < INT_MIN || val > INT_MAX )
543+ return -1 ;
544+
545+ * out = (int )val ;
546+ return 0 ;
547+ }
548+
521549void print_version (void )
522550{
523551 printf ("x86_energy_perf_policy 2025.11.22 Len Brown <lenb@kernel.org>\n" );
@@ -546,12 +574,15 @@ void cmdline(int argc, char **argv)
546574 {"hwp-use-pkg" , required_argument , 0 , 'u' },
547575 {"version" , no_argument , 0 , 'v' },
548576 {"hwp-window" , required_argument , 0 , 'w' },
577+ {"soc-slider-balance" , required_argument , 0 , 'S' },
578+ {"soc-slider-offset" , required_argument , 0 , 'O' },
579+ {"platform-profile" , required_argument , 0 , 'F' },
549580 {0 , 0 , 0 , 0 }
550581 };
551582
552583 progname = argv [0 ];
553584
554- while ((opt = getopt_long_only (argc , argv , "+a:c:dD:E:e:f:m:M:rt:u:vw:" ,
585+ while ((opt = getopt_long_only (argc , argv , "+a:c:dD:E:e:f:m:M:rt:u:vw::S:O:F: " ,
555586 long_options , & option_index )) != -1 ) {
556587 switch (opt ) {
557588 case 'a' :
@@ -579,12 +610,23 @@ void cmdline(int argc, char **argv)
579610 case 'D' :
580611 req_update .hwp_desired = parse_cmdline_hwp_desired (parse_optarg_string (optarg ));
581612 break ;
613+ case 'F' :
614+ if (strlen (optarg ) >= sizeof (platform_profile ))
615+ errx (1 , "--platform-profile: value too long" );
616+ strcpy (platform_profile , optarg );
617+ update_platform_profile = 1 ;
618+ break ;
582619 case 'm' :
583620 req_update .hwp_min = parse_cmdline_hwp_min (parse_optarg_string (optarg ));
584621 break ;
585622 case 'M' :
586623 req_update .hwp_max = parse_cmdline_hwp_max (parse_optarg_string (optarg ));
587624 break ;
625+ case 'O' :
626+ if (parse_cmdline_int (optarg , & soc_slider_offset ))
627+ errx (1 , "--soc-slider-offset: invalid value" );
628+ update_soc_slider_offset = 1 ;
629+ break ;
588630 case 'p' :
589631 parse_cmdline_pkg (optarg );
590632 break ;
@@ -594,6 +636,11 @@ void cmdline(int argc, char **argv)
594636 case 'r' :
595637 /* v1 used -r to specify read-only mode, now the default */
596638 break ;
639+ case 'S' :
640+ if (parse_cmdline_int (optarg , & soc_slider_balance ))
641+ errx (1 , "--soc-slider-balance: invalid value" );
642+ update_soc_slider_balance = 1 ;
643+ break ;
597644 case 't' :
598645 turbo_update_value = parse_cmdline_turbo (parse_optarg_string (optarg ));
599646 break ;
@@ -777,6 +824,31 @@ static unsigned int write_sysfs(const char *path, char *buf, size_t buflen)
777824 return (unsigned int ) numwritten ;
778825}
779826
827+ static int sysfs_read_string (const char * path , char * buf , size_t buflen )
828+ {
829+ unsigned int len ;
830+ size_t n ;
831+
832+ len = read_sysfs (path , buf , buflen );
833+ if (!len )
834+ return -1 ;
835+
836+ n = strcspn (buf , "\n" );
837+ buf [n ] = '\0' ;
838+ return 0 ;
839+ }
840+
841+ static int sysfs_write_string (const char * path , const char * buf )
842+ {
843+ char tmp [128 ];
844+ int len ;
845+
846+ len = snprintf (tmp , sizeof (tmp ), "%s\n" , buf );
847+ if (len < 0 || len >= (int )sizeof (tmp ))
848+ return -1 ;
849+ return write_sysfs (path , tmp , (size_t )len + 1 ) ? 0 : -1 ;
850+ }
851+
780852void print_hwp_cap (int cpu , struct msr_hwp_cap * cap , char * str )
781853{
782854 if (cpu != -1 )
@@ -900,6 +972,55 @@ static int set_epb_sysfs(int cpu, int val)
900972 return (int )val ;
901973}
902974
975+ static int soc_slider_available (void )
976+ {
977+ if (access (PATH_SOC_SLIDER_BALANCE , R_OK ) &&
978+ access (PATH_SOC_SLIDER_OFFSET , R_OK ) &&
979+ access (PATH_PLATFORM_PROFILE , R_OK ))
980+ return 0 ;
981+
982+ return 1 ;
983+ }
984+
985+ static void print_soc_slider (void )
986+ {
987+ char buf [64 ];
988+
989+ if (!soc_slider_available ())
990+ return ;
991+
992+ if (sysfs_read_string (PATH_SOC_SLIDER_BALANCE , buf , sizeof (buf )) == 0 )
993+ printf ("soc-slider-balance: %s\n" , buf );
994+ if (sysfs_read_string (PATH_SOC_SLIDER_OFFSET , buf , sizeof (buf )) == 0 )
995+ printf ("soc-slider-offset: %s\n" , buf );
996+ if (sysfs_read_string (PATH_PLATFORM_PROFILE , buf , sizeof (buf )) == 0 )
997+ printf ("platform-profile: %s\n" , buf );
998+ }
999+
1000+ static int update_soc_slider (void )
1001+ {
1002+ char tmp [32 ];
1003+
1004+ if (update_soc_slider_balance ) {
1005+ snprintf (tmp , sizeof (tmp ), "%d" , soc_slider_balance );
1006+ if (sysfs_write_string (PATH_SOC_SLIDER_BALANCE , tmp ))
1007+ err (1 , "soc-slider-balance write failed" );
1008+ }
1009+
1010+ if (update_soc_slider_offset ) {
1011+ snprintf (tmp , sizeof (tmp ), "%d" , soc_slider_offset );
1012+ if (sysfs_write_string (PATH_SOC_SLIDER_OFFSET , tmp ))
1013+ err (1 , "soc-slider-offset write failed" );
1014+ }
1015+
1016+ if (update_platform_profile ) {
1017+ if (sysfs_write_string (PATH_PLATFORM_PROFILE , platform_profile ))
1018+ err (1 , "platform-profile write failed" );
1019+ }
1020+
1021+ return 0 ;
1022+ }
1023+
9031024int print_cpu_msrs (int cpu )
9041025{
9051026 struct msr_hwp_request req ;
@@ -1604,10 +1725,14 @@ int main(int argc, char **argv)
16041725 return - EINVAL ;
16051726
16061727 /* display information only, no updates to settings */
1607- if (!update_epb && !update_turbo && !hwp_update_enabled ()) {
1728+ if (!update_epb && !update_turbo && !hwp_update_enabled () &&
1729+ !update_soc_slider_balance && !update_soc_slider_offset &&
1730+ !update_platform_profile ) {
16081731 if (cpu_selected_set )
16091732 for_all_cpus_in_set (cpu_setsize , cpu_selected_set , print_cpu_msrs );
16101733
1734+ print_soc_slider ();
1735+
16111736 if (has_hwp_request_pkg ) {
16121737 if (pkg_selected_set == 0 )
16131738 pkg_selected_set = pkg_present_set ;
@@ -1628,5 +1753,8 @@ int main(int argc, char **argv)
16281753 } else if (pkg_selected_set )
16291754 for_packages (pkg_selected_set , update_hwp_request_pkg_msr );
16301755
1756+ if (update_soc_slider_balance || update_soc_slider_offset || update_platform_profile )
1757+ update_soc_slider ();
1758+
16311759 return 0 ;
16321760}
0 commit comments