public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Support non-inclusive caches on Intel processors
@ 2016-05-11 20:00 H.J. Lu
  2016-05-13 13:36 ` H.J. Lu
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2016-05-11 20:00 UTC (permalink / raw)
  To: GNU C Library

Tested on Intel processors with inclusive cache and non-inclusive cache.
OK for master?


H.J.
--
	* sysdeps/x86/cacheinfo.c (init_cacheinfo): Check and support
	non-inclusive caches on Intel processors.
---
 sysdeps/x86/cacheinfo.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/sysdeps/x86/cacheinfo.c b/sysdeps/x86/cacheinfo.c
index 143b333..8408624 100644
--- a/sysdeps/x86/cacheinfo.c
+++ b/sysdeps/x86/cacheinfo.c
@@ -492,6 +492,9 @@ init_cacheinfo (void)
     {
       data = handle_intel (_SC_LEVEL1_DCACHE_SIZE, max_cpuid);
 
+      long int core = handle_intel (_SC_LEVEL2_CACHE_SIZE, max_cpuid);
+      bool inclusive_cache = true;
+
       /* Try L3 first.  */
       level  = 3;
       shared = handle_intel (_SC_LEVEL3_CACHE_SIZE, max_cpuid);
@@ -500,7 +503,7 @@ init_cacheinfo (void)
 	{
 	  /* Try L2 otherwise.  */
 	  level  = 2;
-	  shared = handle_intel (_SC_LEVEL2_CACHE_SIZE, max_cpuid);
+	  shared = core;
 	}
 
       /* Figure out the number of logical threads that share the
@@ -526,6 +529,9 @@ init_cacheinfo (void)
 	    }
 	  while (((eax >> 5) & 0x7) != level);
 
+	  /* Check if cache is inclusive of lower cache levels.  */
+	  inclusive_cache = (edx & 0x2) != 0;
+
 	  threads = (eax >> 14) & 0x3ff;
 
 	  /* If max_cpuid >= 11, THREADS is the maximum number of
@@ -592,6 +598,10 @@ init_cacheinfo (void)
 	 threads.  */
       if (shared > 0 && threads > 0)
 	shared /= threads;
+
+      /* Account for non-inclusive L2 and L3 caches.  */
+      if (level == 3 && !inclusive_cache)
+	shared += core;
     }
   /* This spells out "AuthenticAMD".  */
   else if (is_amd)
-- 
2.5.5

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Support non-inclusive caches on Intel processors
  2016-05-11 20:00 [PATCH] Support non-inclusive caches on Intel processors H.J. Lu
@ 2016-05-13 13:36 ` H.J. Lu
  0 siblings, 0 replies; 2+ messages in thread
From: H.J. Lu @ 2016-05-13 13:36 UTC (permalink / raw)
  To: GNU C Library

On Wed, May 11, 2016 at 1:00 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> Tested on Intel processors with inclusive cache and non-inclusive cache.
> OK for master?
>
>
> H.J.
> --
>         * sysdeps/x86/cacheinfo.c (init_cacheinfo): Check and support
>         non-inclusive caches on Intel processors.
> ---
>  sysdeps/x86/cacheinfo.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/sysdeps/x86/cacheinfo.c b/sysdeps/x86/cacheinfo.c
> index 143b333..8408624 100644
> --- a/sysdeps/x86/cacheinfo.c
> +++ b/sysdeps/x86/cacheinfo.c
> @@ -492,6 +492,9 @@ init_cacheinfo (void)
>      {
>        data = handle_intel (_SC_LEVEL1_DCACHE_SIZE, max_cpuid);
>
> +      long int core = handle_intel (_SC_LEVEL2_CACHE_SIZE, max_cpuid);
> +      bool inclusive_cache = true;
> +
>        /* Try L3 first.  */
>        level  = 3;
>        shared = handle_intel (_SC_LEVEL3_CACHE_SIZE, max_cpuid);
> @@ -500,7 +503,7 @@ init_cacheinfo (void)
>         {
>           /* Try L2 otherwise.  */
>           level  = 2;
> -         shared = handle_intel (_SC_LEVEL2_CACHE_SIZE, max_cpuid);
> +         shared = core;
>         }
>
>        /* Figure out the number of logical threads that share the
> @@ -526,6 +529,9 @@ init_cacheinfo (void)
>             }
>           while (((eax >> 5) & 0x7) != level);
>
> +         /* Check if cache is inclusive of lower cache levels.  */
> +         inclusive_cache = (edx & 0x2) != 0;
> +
>           threads = (eax >> 14) & 0x3ff;
>
>           /* If max_cpuid >= 11, THREADS is the maximum number of
> @@ -592,6 +598,10 @@ init_cacheinfo (void)
>          threads.  */
>        if (shared > 0 && threads > 0)
>         shared /= threads;
> +
> +      /* Account for non-inclusive L2 and L3 caches.  */
> +      if (level == 3 && !inclusive_cache)
> +       shared += core;
>      }
>    /* This spells out "AuthenticAMD".  */
>    else if (is_amd)
> --
> 2.5.5
>

I will check it in today.


-- 
H.J.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-05-13 13:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-11 20:00 [PATCH] Support non-inclusive caches on Intel processors H.J. Lu
2016-05-13 13:36 ` H.J. Lu

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 read-only IMAP folder(s) and NNTP newsgroup(s).