ce426f
commit a3d9ab5070b56b49aa91be2887fa5b118012b2cd
ce426f
Author: H.J. Lu <hjl.tools@gmail.com>
ce426f
Date:   Tue Mar 31 13:17:51 2015 -0700
ce426f
ce426f
    Limit threads sharing L2 cache to 2 for SLM/KNL
ce426f
    
ce426f
    Silvermont and Knights Landing have a modular system design with two cores
ce426f
    sharing an L2 cache.  If more than 2 cores are detected to shared L2 cache,
ce426f
    it should be adjusted for Silvermont and Knights Landing.
ce426f
    
ce426f
        [BZ #18185]
ce426f
        * sysdeps/x86_64/cacheinfo.c (init_cacheinfo): Limit threads
ce426f
        sharing L2 cache to 2 for Silvermont/Knights Landing.
ce426f
ce426f
diff --git a/sysdeps/x86_64/cacheinfo.c b/sysdeps/x86_64/cacheinfo.c
ce426f
index f1cbf50..b99fb9a 100644
ce426f
--- a/sysdeps/x86_64/cacheinfo.c
ce426f
+++ b/sysdeps/x86_64/cacheinfo.c
ce426f
@@ -585,6 +585,10 @@ init_cacheinfo (void)
ce426f
       __cpuid (1, eax, ebx_1, ecx, edx);
ce426f
 #endif
ce426f
 
ce426f
+      unsigned int family = (eax >> 8) & 0x0f;
ce426f
+      unsigned int model = (eax >> 4) & 0x0f;
ce426f
+      unsigned int extended_model = (eax >> 12) & 0xf0;
ce426f
+
ce426f
 #ifndef DISABLE_PREFERRED_MEMORY_INSTRUCTION
ce426f
       /* Intel prefers SSSE3 instructions for memory/string routines
ce426f
 	 if they are available.  */
ce426f
@@ -647,6 +651,25 @@ init_cacheinfo (void)
ce426f
 		}
ce426f
 	    }
ce426f
 	  threads += 1;
ce426f
+	  if (threads > 2 && level == 2 && family == 6)
ce426f
+	    {
ce426f
+	      model += extended_model;
ce426f
+	      switch (model)
ce426f
+		{
ce426f
+		case 0x57:
ce426f
+		  /* Knights Landing has L2 cache shared by 2 cores.  */
ce426f
+		case 0x37:
ce426f
+		case 0x4a:
ce426f
+		case 0x4d:
ce426f
+		case 0x5a:
ce426f
+		case 0x5d:
ce426f
+		  /* Silvermont has L2 cache shared by 2 cores.  */
ce426f
+		  threads = 2;
ce426f
+		  break;
ce426f
+		default:
ce426f
+		  break;
ce426f
+		}
ce426f
+	    }
ce426f
 	}
ce426f
       else
ce426f
 	{