x86/cpu: Strip leading and trailing spaces from the /proc/cpuinfo CPU model field
PATCH 1/1 x86/cpu: Strip leading and trailing spaces from the /proc/cpuinfo CPU model field
When comparing 'model name' fields in /proc/cpuinfo it was noticed that a simple test comparing the model name fields was failing. After some quick investigation it was noticed that the model name fields were actually different -- processor 0's model name field had trailing white space removed, while the other processors did not.
Another way of seeing this behaviour is to convert spaces into underscores in the output of /proc/cpuinfo,
[thetango@prarit ~]# grep "^model name" /proc/cpuinfo | uniq -c | sed 's/\ /_/g'______1_model_name :_AMD_Opteron(TM)_Processor_6272_____63_model_name :_AMD_Opteron(TM)_Processor_6272_________________
which shows two different model name fields even though they should be the same.
This occurs because the kernel calls strim() on cpu 0's x86_model_id field to output a pretty message to the console in print_cpu_info(), and as a result truncates the whitespace at the end of the x86_model_id field.
The x86_model_id field should be the same for the same processors. This patch uses string functions to remove both leading and trailing whitespace in the x86_model_id field. As a result the print_cpu_info() output looks like
smpboot: CPU0: AMD Opteron(TM) Processor 6272 (fam: 15, model: 01, stepping: 02)
and the x86_model_id field is correct on all processors on AMD platforms
[thetango@prarit ~]# grep "^model name" /proc/cpuinfo | uniq -c | sed 's/\ /_/g'_____64_model_name :_AMD_Opteron(TM)_Processor_6272
and the functionality is correct on an Intel box:
[thetango@prarit2]# grep "^model name" /proc/cpuinfo | uniq -c | sed 's/\ /_/g' ____144_model_name :_Intel(R)_Xeon(R)_CPU_E7-8890_v3_@_2.50GHz
[v2]: use memmove and update patch subject
--- arch/x86/kernel/cpu/common.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)
arch/x86/kernel/cpu/common.c +4 -13
@@ -419,7 +419,6 @@ static const struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {};static void get_model_name (struct cpuinfo_x86 *c) {unsigned int *v; -char *p, *q;if (c->extended_cpuid_level <0x80000004 )return ;
@@ -431,18 +430,10 @@ static void get_model_name(struct cpuinfo_x86 *c) c->x86_model_id[48 ] =0 ;/* -* Intel chips right-justify this string for some dumb reason; -* undo that brain damage: +* Remove leading whitespace on Intel processors and trailing +* whitespace on AMD processors. */ - p = q = &c->x86_model_id[0 ]; -while (*p ==' ' ) - p++; -if (p != q) { -while (*p) - *q++ = *p++; -while (q <= &c->x86_model_id[48 ]) - *q++ ='\0' ;/* Zero-pad the rest */ - } +memmove (c->x86_model_id,strim (c->x86_model_id),48 ); }void cpu_detect_cache_sizes (struct cpuinfo_x86 *c)
@@ -1122,7 +1113,7 @@ void print_cpu_info(struct cpuinfo_x86 *c)printk (KERN_CONT "%s " , vendor);if (c->x86_model_id[0 ]) -printk (KERN_CONT "%s" ,strim (c->x86_model_id)); +printk (KERN_CONT "%s" , c->x86_model_id);else printk (KERN_CONT "%d86" , c->x86);
Signature · 1 line
1.8.3.1
Quoted 51 lines · Prarit Bhargava
When comparing 'model name' fields in
/proc/cpuinfoit was noticed that a simple test comparing the model name fields was failing. After some quick investigation it was noticed that the model name fields were actually different -- processor 0's model name field had trailing white space removed, while the other processors did not.Another way of seeing this behaviour is to convert spaces into underscores in the output of
/proc/cpuinfo,[thetango@prarit ~]# grep "^model name"
/proc/cpuinfo| uniq -c | sed 's/\ /_/g'______1_model_name:_AMD_Opteron(TM)_Processor_6272_____63_model_name:_AMD_Opteron(TM)_Processor_6272_________________which shows two different model name fields even though they should be the same.
This occurs because the kernel calls
strim()on cpu 0'sx86_model_idfield to output a pretty message to the console inprint_cpu_info(), and as a result truncates the whitespace at the end of thex86_model_idfield.The
x86_model_idfield should be the same for the same processors. This patch uses string functions to remove both leading and trailing whitespace in thex86_model_idfield. As a result theprint_cpu_info()output looks likesmpboot: CPU0: AMD Opteron(TM) Processor 6272 (fam: 15, model: 01, stepping: 02)
and the
x86_model_idfield is correct on all processors on AMD platforms[thetango@prarit ~]# grep "^model name"
/proc/cpuinfo| uniq -c | sed 's/\ /_/g'_____64_model_name:_AMD_Opteron(TM)_Processor_6272and the functionality is correct on an Intel box:
[thetango@prarit2]# grep "^model name" /proc/cpuinfo | uniq -c | sed 's/\ /_/g' ____144_model_name :_Intel(R)_Xeon(R)_CPU_E7-8890_v3_@_2.50GHz[v2]: use memmove and update patch subject
Signed-off-by Prarit Bhargava <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc "H. Peter Anvin" <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Borislav Petkov <[email protected]>Cc Denys Vlasenko <[email protected]>Cc Dave Hansen <[email protected]>Cc Igor Mammedov <[email protected]>Cc Fenghua Yu <[email protected]>Cc Brian Gerst <[email protected]>
Quoted 3 lines
--- arch/x86/kernel/cpu/common.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)
Applied, thanks.
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--