ACK: [PATCH 3/3] lib: fwts_cpu: query info from the first online CPU

Colin Ian King colin.king at canonical.com
Sun Jul 10 18:24:37 UTC 2016


On 09/07/16 00:42, Ricardo Neri wrote:
> All calls to fwts_cpu_get_info request the info of CPU0. However, this CPU
> may be offline if the Linux kernel was built with
> CONFIG_BOOTPARAM_HOTPLUG_CPU0. In such a case, fwts_cpu_get_info would
> return an empty (and useless) structure.
> 
> Assuming that all the CPUs yield the same information, we could use the
> first online CPU to query its information. We already operate under this
> assumption by always querying the CPU0 info.
> 
> Functionality to query a specific CPU is preserved but now it is possible
> to use -1 to query the first available CPU.
> 
> Signed-off-by: Ricardo Neri <ricardo.neri-calderon at linux.intel.com>
> ---
>  src/bios/mtrr/mtrr.c   |  2 +-
>  src/cpu/msr/msr.c      |  2 +-
>  src/cpu/nx/nx.c        |  6 +++---
>  src/cpu/virt/virt.c    |  2 +-
>  src/lib/src/fwts_cpu.c | 11 +++++++----
>  5 files changed, 13 insertions(+), 10 deletions(-)
> 
> diff --git a/src/bios/mtrr/mtrr.c b/src/bios/mtrr/mtrr.c
> index 9861fe0..18e1a29 100644
> --- a/src/bios/mtrr/mtrr.c
> +++ b/src/bios/mtrr/mtrr.c
> @@ -457,7 +457,7 @@ static int mtrr_init(fwts_framework *fw)
>  		return FWTS_ERROR;
>  	}
>  
> -	if ((fwts_cpuinfo = fwts_cpu_get_info(0)) == NULL) {
> +	if ((fwts_cpuinfo = fwts_cpu_get_info(-1)) == NULL) {
>  		fwts_log_error(fw, "Cannot get CPU info");
>  		return FWTS_ERROR;
>  	}
> diff --git a/src/cpu/msr/msr.c b/src/cpu/msr/msr.c
> index db6059c..54ed5a5 100644
> --- a/src/cpu/msr/msr.c
> +++ b/src/cpu/msr/msr.c
> @@ -33,7 +33,7 @@ static int msr_init(fwts_framework *fw)
>  {
>  	char *bios_vendor;
>  
> -	if ((cpuinfo = fwts_cpu_get_info(0)) == NULL) {
> +	if ((cpuinfo = fwts_cpu_get_info(-1)) == NULL) {
>  		fwts_log_error(fw, "Cannot get CPU info");
>  		return FWTS_ERROR;
>  	}
> diff --git a/src/cpu/nx/nx.c b/src/cpu/nx/nx.c
> index f5d74b3..6e183d5 100644
> --- a/src/cpu/nx/nx.c
> +++ b/src/cpu/nx/nx.c
> @@ -29,7 +29,7 @@ static int nx_test1(fwts_framework *fw)
>  {
>  	fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
>  
> -	if ((fwts_nx_cpuinfo = fwts_cpu_get_info(0)) == NULL) {
> +	if ((fwts_nx_cpuinfo = fwts_cpu_get_info(-1)) == NULL) {
>  		fwts_log_error(fw, "Cannot get CPU info");
>  		return FWTS_ERROR;
>  	}
> @@ -106,7 +106,7 @@ static int nx_test2(fwts_framework *fw)
>  	for (i = 0; i < n; i++) {
>  		fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
>  
> -		if ((fwts_nx_cpuinfo = fwts_cpu_get_info(0)) == NULL) {
> +		if ((fwts_nx_cpuinfo = fwts_cpu_get_info(-1)) == NULL) {
>  			fwts_failed(fw, LOG_LEVEL_MEDIUM, "NXCPUInfoRead", "Cannot get CPU%d info", i);
>  			fwts_cpu_free_info(fwts_nx_cpuinfo);
>  			return FWTS_ERROR;
> @@ -155,7 +155,7 @@ static int nx_test3(fwts_framework *fw)
>  		fwts_cpuinfo_x86 *fwts_nx_cpuinfo;
>  		uint64_t val;
>  
> -		if ((fwts_nx_cpuinfo = fwts_cpu_get_info(0)) == NULL) {
> +		if ((fwts_nx_cpuinfo = fwts_cpu_get_info(-1)) == NULL) {
>  			fwts_log_error(fw, "Cannot get CPU info");
>  			return FWTS_ERROR;
>  		}
> diff --git a/src/cpu/virt/virt.c b/src/cpu/virt/virt.c
> index ecc84d0..24b68f4 100644
> --- a/src/cpu/virt/virt.c
> +++ b/src/cpu/virt/virt.c
> @@ -43,7 +43,7 @@ fwts_cpuinfo_x86 *fwts_virt_cpuinfo;
>  
>  static int virt_init(fwts_framework *fw)
>  {
> -	if ((fwts_virt_cpuinfo = fwts_cpu_get_info(0)) == NULL) {
> +	if ((fwts_virt_cpuinfo = fwts_cpu_get_info(-1)) == NULL) {
>  		fwts_log_error(fw, "Cannot get CPU info");
>  		return FWTS_ERROR;
>  	}
> diff --git a/src/lib/src/fwts_cpu.c b/src/lib/src/fwts_cpu.c
> index 2e0834d..c0b1ec2 100644
> --- a/src/lib/src/fwts_cpu.c
> +++ b/src/lib/src/fwts_cpu.c
> @@ -99,9 +99,10 @@ void fwts_cpu_free_info(fwts_cpuinfo_x86 *cpu)
>  
>  /*
>   *  fwts_cpu_get_info()
> - *	get CPU information for specified CPU
> + *	get CPU information for specified CPU.
> + *	Specify the CPU as -1 to query the first online CPU.
>   */
> -fwts_cpuinfo_x86 *fwts_cpu_get_info(const int which_cpu)
> +fwts_cpuinfo_x86 *fwts_cpu_get_info(int which_cpu)
>  {
>  	FILE *fp;
>  	char buffer[1024];
> @@ -127,6 +128,8 @@ fwts_cpuinfo_x86 *fwts_cpu_get_info(const int which_cpu)
>  
>  		if (!strncmp(buffer, "processor", 9)) {
>  			sscanf(ptr, "%d", &cpu_num);
> +			if (which_cpu == -1)
> +				which_cpu = cpu_num;
>  			if (cpu_num > which_cpu)
>  				break;
>  			continue;
> @@ -176,7 +179,7 @@ static int fwts_cpu_matches_vendor_id(const char *vendor_id, bool *matches)
>  {
>  	fwts_cpuinfo_x86 *cpu;
>  
> -	if ((cpu = fwts_cpu_get_info(0)) == NULL)
> +	if ((cpu = fwts_cpu_get_info(-1)) == NULL)
>  		return FWTS_ERROR;
>  	if (cpu->vendor_id == NULL) {
>  		fwts_cpu_free_info(cpu);
> @@ -212,7 +215,7 @@ fwts_bool fwts_cpu_has_c1e(void)
>  
>  	fwts_cpuinfo_x86 *cpu;
>  
> -	if ((cpu = fwts_cpu_get_info(0)) == NULL)
> +	if ((cpu = fwts_cpu_get_info(-1)) == NULL)
>  		return FWTS_BOOL_ERROR;
>  	if (cpu->flags == NULL) {
>  		rc FWTS_BOOL_ERROR;
> 
Acked-by: Colin Ian King <colin.king at canonical.com>



More information about the fwts-devel mailing list