@@ -104,9 +104,14 @@ char platform_profile[64];
104104#define PATH_SOC_SLIDER_BALANCE "/sys/module/processor_thermal_soc_slider/parameters/slider_balance"
105105#define PATH_SOC_SLIDER_OFFSET "/sys/module/processor_thermal_soc_slider/parameters/slider_offset"
106106#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"
107109
108110static int use_android_msr_path ;
109111
112+ static unsigned int read_sysfs (const char * , char * , size_t );
113+ static int sysfs_read_string (const char * , char * , size_t );
114+
110115/*
111116 * maintain compatibility with original implementation, but don't document it:
112117 */
@@ -551,39 +556,91 @@ void print_version(void)
551556 printf ("x86_energy_perf_policy 2025.11.22 Len Brown <lenb@kernel.org>\n" );
552557}
553558
559+ static int platform_profile_access (int mode )
560+ {
561+ if (access (PATH_PLATFORM_PROFILE , mode )) {
562+ if (debug )
563+ fprintf (stderr , "Can not access %s\n" , PATH_PLATFORM_PROFILE );
564+ return 0 ;
565+ }
566+
567+ return 1 ;
568+ }
569+
570+ static int platform_profile_name_is (char * name )
571+ {
572+ char buf [64 ];
573+
574+ if (sysfs_read_string (PATH_PLATFORM_PROFILE_NAME , buf , sizeof (buf )) != 0 ) {
575+ if (debug )
576+ fprintf (stderr , "Can not read %s\n" , PATH_PLATFORM_PROFILE_NAME );
577+ return 0 ;
578+ }
579+
580+ if (strncmp (buf , name , 16 )) {
581+ if (debug )
582+ fprintf (stderr , "%s does not match '%s'\n" , PATH_PLATFORM_PROFILE_NAME , name );
583+ return 0 ;
584+ }
585+
586+ return 1 ;
587+ }
588+
589+ static int soc_slider_access (int mode )
590+ {
591+ if (!platform_profile_access (R_OK ))
592+ return 0 ;
593+
594+ if (!platform_profile_name_is (POWER_SLIDER_NAME ))
595+ return 0 ;
596+
597+ if (access (PATH_SOC_SLIDER_BALANCE , mode )) {
598+ if (debug )
599+ fprintf (stderr , "Can not access %s\n" , PATH_SOC_SLIDER_BALANCE );
600+ return 0 ;
601+ }
602+
603+ if (access (PATH_SOC_SLIDER_OFFSET , mode )) {
604+ if (debug )
605+ fprintf (stderr , "Can not access %s\n" , PATH_SOC_SLIDER_OFFSET );
606+ return 0 ;
607+ }
608+
609+ return 1 ;
610+ }
611+
554612void cmdline (int argc , char * * argv )
555613{
556614 int opt ;
557615 int option_index = 0 ;
558616
559617 static struct option long_options [] = {
560- {"all" , required_argument , 0 , 'a' },
561- {"cpu" , required_argument , 0 , 'c' },
562- {"pkg" , required_argument , 0 , 'p' },
563- {"debug" , no_argument , 0 , 'd' },
564- {"hwp-desired" , required_argument , 0 , 'D' },
565- {"epb" , required_argument , 0 , 'B' },
566- {"force" , no_argument , 0 , 'f' },
567- {"hwp-enable" , no_argument , 0 , 'e' },
568- {"help" , no_argument , 0 , 'h' },
569- {"hwp-epp" , required_argument , 0 , 'P' },
570- {"hwp-min" , required_argument , 0 , 'm' },
571- {"hwp-max" , required_argument , 0 , 'M' },
572- {"read" , no_argument , 0 , 'r' },
573- {"turbo-enable" , required_argument , 0 , 't' },
574- {"hwp-use-pkg" , required_argument , 0 , 'u' },
575- {"version" , no_argument , 0 , 'v' },
576- {"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' },
580- {0 , 0 , 0 , 0 }
618+ { "all" , required_argument , 0 , 'a' },
619+ { "cpu" , required_argument , 0 , 'c' },
620+ { "pkg" , required_argument , 0 , 'p' },
621+ { "debug" , no_argument , 0 , 'd' },
622+ { "hwp-desired" , required_argument , 0 , 'D' },
623+ { "epb" , required_argument , 0 , 'B' },
624+ { "force" , no_argument , 0 , 'f' },
625+ { "hwp-enable" , no_argument , 0 , 'e' },
626+ { "help" , no_argument , 0 , 'h' },
627+ { "hwp-epp" , required_argument , 0 , 'P' },
628+ { "hwp-min" , required_argument , 0 , 'm' },
629+ { "hwp-max" , required_argument , 0 , 'M' },
630+ { "read" , no_argument , 0 , 'r' },
631+ { "turbo-enable" , required_argument , 0 , 't' },
632+ { "hwp-use-pkg" , required_argument , 0 , 'u' },
633+ { "version" , no_argument , 0 , 'v' },
634+ { "hwp-window" , required_argument , 0 , 'w' },
635+ { "soc-slider-balance" , required_argument , 0 , 'S' },
636+ { "soc-slider-offset" , required_argument , 0 , 'O' },
637+ { "platform-profile" , required_argument , 0 , 'F' },
638+ { 0 , 0 , 0 , 0 }
581639 };
582640
583641 progname = argv [0 ];
584642
585- while ((opt = getopt_long_only (argc , argv , "+a:c:dD:E:e:f:m:M:rt:u:vw::S:O:F:" ,
586- long_options , & option_index )) != -1 ) {
643+ 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 ) {
587644 switch (opt ) {
588645 case 'a' :
589646 parse_cmdline_all (optarg );
@@ -613,6 +670,8 @@ void cmdline(int argc, char **argv)
613670 case 'F' :
614671 if (strlen (optarg ) >= sizeof (platform_profile ))
615672 errx (1 , "--platform-profile: value too long" );
673+ if (!platform_profile_access (W_OK ))
674+ errx (1 , "Can not update platform-profile in '%s'" , PATH_PLATFORM_PROFILE );
616675 strcpy (platform_profile , optarg );
617676 update_platform_profile = 1 ;
618677 break ;
@@ -625,6 +684,8 @@ void cmdline(int argc, char **argv)
625684 case 'O' :
626685 if (parse_cmdline_int (optarg , & soc_slider_offset ))
627686 errx (1 , "--soc-slider-offset: invalid value" );
687+ if (!soc_slider_access (W_OK ))
688+ errx (1 , "Unable to write SOC Slider Offset" );
628689 update_soc_slider_offset = 1 ;
629690 break ;
630691 case 'p' :
@@ -639,6 +700,8 @@ void cmdline(int argc, char **argv)
639700 case 'S' :
640701 if (parse_cmdline_int (optarg , & soc_slider_balance ))
641702 errx (1 , "--soc-slider-balance: invalid value" );
703+ if (!soc_slider_access (W_OK ))
704+ errx (1 , "Unable to write SOC Slider-Balance in '%s'" , PATH_SOC_SLIDER_BALANCE );
642705 update_soc_slider_balance = 1 ;
643706 break ;
644707 case 't' :
@@ -814,7 +877,8 @@ static unsigned int write_sysfs(const char *path, char *buf, size_t buflen)
814877
815878 numwritten = write (fd , buf , buflen - 1 );
816879 if (numwritten < 1 ) {
817- perror ("write failed\n" );
880+ buf [strcspn (buf , "\n" )] = '\0' ;
881+ warn ("Write '%s' to '%s' failed" , buf , path );
818882 close (fd );
819883 return -1 ;
820884 }
@@ -972,27 +1036,30 @@ static int set_epb_sysfs(int cpu, int val)
9721036 return (int )val ;
9731037}
9741038
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-
9851039static void print_soc_slider (void )
9861040{
9871041 char buf [64 ];
9881042
989- if (!soc_slider_available ( ))
1043+ if (!soc_slider_access ( R_OK ))
9901044 return ;
9911045
9921046 if (sysfs_read_string (PATH_SOC_SLIDER_BALANCE , buf , sizeof (buf )) == 0 )
9931047 printf ("soc-slider-balance: %s\n" , buf );
1048+
9941049 if (sysfs_read_string (PATH_SOC_SLIDER_OFFSET , buf , sizeof (buf )) == 0 )
9951050 printf ("soc-slider-offset: %s\n" , buf );
1051+ }
1052+
1053+ static void print_platform_profile (void )
1054+ {
1055+ char buf [64 ];
1056+
1057+ if (!platform_profile_access (R_OK ))
1058+ return ;
1059+
1060+ if (sysfs_read_string (PATH_PLATFORM_PROFILE_NAME , buf , sizeof (buf )) == 0 )
1061+ printf ("platform-profile-name: %s\n" , buf );
1062+
9961063 if (sysfs_read_string (PATH_PLATFORM_PROFILE , buf , sizeof (buf )) == 0 )
9971064 printf ("platform-profile: %s\n" , buf );
9981065}
@@ -1725,13 +1792,12 @@ int main(int argc, char **argv)
17251792 return - EINVAL ;
17261793
17271794 /* display information only, no updates to settings */
1728- if (!update_epb && !update_turbo && !hwp_update_enabled () &&
1729- !update_soc_slider_balance && !update_soc_slider_offset &&
1730- !update_platform_profile ) {
1795+ if (!update_epb && !update_turbo && !hwp_update_enabled () && !update_soc_slider_balance && !update_soc_slider_offset && !update_platform_profile ) {
17311796 if (cpu_selected_set )
17321797 for_all_cpus_in_set (cpu_setsize , cpu_selected_set , print_cpu_msrs );
17331798
17341799 print_soc_slider ();
1800+ print_platform_profile ();
17351801
17361802 if (has_hwp_request_pkg ) {
17371803 if (pkg_selected_set == 0 )
0 commit comments