linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
  • * Re: [PATCH 1/2] cpupower: fix amd cpu (family < 0x17) active state issue
           [not found] <20210324082838.41462-1-xufuhai1992@gmail.com>
           [not found] ` <20210324082838.41462-2-xufuhai1992@gmail.com>
    @ 2021-03-29 11:10 ` Thomas Renninger
      2021-03-30  3:47   ` xufuhai
      1 sibling, 1 reply; 13+ messages in thread
    From: Thomas Renninger @ 2021-03-29 11:10 UTC (permalink / raw)
      To: linux, sherry.hurwitz, linux-pm, xufuhai; +Cc: lishujin, xufuhai
    
    Hi,
    
    Am Mittwoch, 24. März 2021, 09:28:37 CEST schrieb xufuhai:
    > From: xufuhai <xufuhai@kuaishou.com>
    > 
    > For the old  AMD processor (family < 0x17), cpupower will call the
    > amd_pci_get_num_boost_states function, but for the non-root user
    > pci_read_byte function (implementation comes from the psutil library),
    > val will be set to 0xff, indicating that there is no read function
    > callback. At this time, the original logic will set the cpupower turbo
    > active state to yes. This is an obvious issue~
    > 
    > Reproduce procedure:
    > 	cpupower frequency-info
    > 
    > Signed-off-by: xufuhai <xufuhai@kuaishou.com>
    > ---
    >  tools/power/cpupower/utils/helpers/amd.c | 7 +++++++
    >  1 file changed, 7 insertions(+)
    > 
    > diff --git a/tools/power/cpupower/utils/helpers/amd.c
    > b/tools/power/cpupower/utils/helpers/amd.c index 97f2c857048e..6f9504906afa
    > 100644
    > --- a/tools/power/cpupower/utils/helpers/amd.c
    > +++ b/tools/power/cpupower/utils/helpers/amd.c
    > @@ -137,6 +137,13 @@ int amd_pci_get_num_boost_states(int *active, int
    > *states) return -ENODEV;
    > 
    >  	val = pci_read_byte(device, 0x15c);
    > +
    > +	/* If val is 0xff, meaning has no permisson to
    > +	 * get the boost states, return -1
    > +	 */
    > +	if (val == 0xff)
    > +		return -1;
    > +
    There is certainly a cleaner way to do this.., theoretically
    pci_read_byte can return 0xff in other cases?
    
    But I guess this is a sufficient way to handle this for now.
    
    Reviewed-by: Thomas Renninger <trenn@suse.de>
    
    Thanks,
    
            Thomas
    
    
    
    ^ permalink raw reply	[flat|nested] 13+ messages in thread
  • * [PATCH 2/2] cpupower: fix amd cpu (family >= 0x17) active state issue
    @ 2021-03-24 10:28 xufuhai
      2021-03-26 20:13 ` Shuah Khan
      0 siblings, 1 reply; 13+ messages in thread
    From: xufuhai @ 2021-03-24 10:28 UTC (permalink / raw)
      To: linux, sherry.hurwitz, trenn, linux-pm; +Cc: lishujin
    
    From: xufuhai <xufuhai@kuaishou.com>
    
    If the read_msr function is executed by a non-root user, the function
    returns -1, which means that there is no permission to access /dev/cpu/%d/msr,
    but cpufreq_has_boost_support should also return -1 immediately, and should not
    follow the original logic to return 0, which will cause amd The cpupower tool
    returns the turbo active status as 0.
    
    Reproduce procedure:
            cpupower frequency-info
    
    Signed-off-by: xufuhai <xufuhai@kuaishou.com>
    Signed-off-by: chenguanqiao <chenguanqiao@kuaishou.com>
    Signed-off-by: lishujin <lishujin@kuaishou.com>
    ---
     tools/power/cpupower/utils/helpers/misc.c | 9 +++++++--
     1 file changed, 7 insertions(+), 2 deletions(-)
    
    diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c
    index fc6e34511721..be96f9ce18eb 100644
    --- a/tools/power/cpupower/utils/helpers/misc.c
    +++ b/tools/power/cpupower/utils/helpers/misc.c
    @@ -30,10 +30,15 @@ int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active,
     		 */
     
     		if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_CPB_MSR) {
    -			if (!read_msr(cpu, MSR_AMD_HWCR, &val)) {
    +			ret = read_msr(cpu, MSR_AMD_HWCR, &val);
    +			if (!ret) {
     				if (!(val & CPUPOWER_AMD_CPBDIS))
     					*active = 1;
    -			}
    +			} else
    +				/* no permission to access /dev/cpu/%d/msr, return -1 immediately,
    +				 * and should not follow the original logic to return 0
    +				 */
    +				return ret;
     		} else {
     			ret = amd_pci_get_num_boost_states(active, states);
     			if (ret)
    -- 
    2.24.3 (Apple Git-128)
    
    ^ permalink raw reply related	[flat|nested] 13+ messages in thread

    end of thread, other threads:[~2021-04-16 15:04 UTC | newest]
    
    Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
    -- links below jump to the message on this page --
         [not found] <20210324082838.41462-1-xufuhai1992@gmail.com>
         [not found] ` <20210324082838.41462-2-xufuhai1992@gmail.com>
    2021-03-29 10:58   ` [PATCH 2/2] cpupower: fix amd cpu (family >= 0x17) active state issue Thomas Renninger
    2021-03-30  2:46     ` xufuhai
    2021-04-08  2:21       ` xufuhai
    2021-04-15  7:02         ` [PATCH v2 " xufuhai
    2021-04-15 13:45           ` Huang Rui
    2021-04-15 23:07           ` Shuah Khan
         [not found]             ` <CAOkq_BcdvS1NtKJ9=peRWHc00kGjfvdE+Cyz7vqvH0+kermfhQ@mail.gmail.com>
    2021-04-16 15:04               ` Shuah Khan
    2021-03-29 11:10 ` [PATCH 1/2] cpupower: fix amd cpu (family < " Thomas Renninger
    2021-03-30  3:47   ` xufuhai
    2021-04-08  2:22     ` xufuhai
    2021-03-24 10:28 [PATCH 2/2] cpupower: fix amd cpu (family >= " xufuhai
    2021-03-26 20:13 ` Shuah Khan
    2021-03-29  4:11   ` xufuhai
    

    This is a public inbox, see mirroring instructions
    for how to clone and mirror all data and code used for this inbox;
    as well as URLs for NNTP newsgroup(s).