[PATCH 1/1] x86: Optimizing memcpy for AMD Zen architecture.
Florian Weimer
fweimer@redhat.com
Tue Oct 27 10:38:04 GMT 2020
* sajan karumanchi:
> diff --git a/sysdeps/x86/cacheinfo.h b/sysdeps/x86/cacheinfo.h
> index 7f342fdc23..d6d6877702 100644
> --- a/sysdeps/x86/cacheinfo.h
> +++ b/sysdeps/x86/cacheinfo.h
> @@ -303,6 +303,8 @@ init_cacheinfo (void)
> data = handle_amd (_SC_LEVEL1_DCACHE_SIZE);
> long int core = handle_amd (_SC_LEVEL2_CACHE_SIZE);
> shared = handle_amd (_SC_LEVEL3_CACHE_SIZE);
> + unsigned int eax;
> + unsigned int threads_per_ccx = 0;
>
> /* Get maximum extended function. */
> __cpuid (0x80000000, max_cpuid_ex, ebx, ecx, edx);
> @@ -320,7 +322,7 @@ init_cacheinfo (void)
> threads = 1 << ((ecx >> 12) & 0x0f);
> }
>
> - if (threads == 0)
> + if (threads == 0 || cpu_features->basic.family >= 0x17)
> {
> /* If APIC ID width is not available, use logical
> processor count. */
> @@ -335,13 +337,27 @@ init_cacheinfo (void)
> if (threads > 0)
> shared /= threads;
>
> - /* Account for exclusive L2 and L3 caches. */
> - shared += core;
> - }
> + /* Get shared cache per ccx for Zen architectures */
> + if (cpu_features->basic.family >= 0x17)
> + {
> + /* Get number of threads share the L3 cache in CCX */
> + __cpuid_count(0x8000001D, 0x3, eax, ebx, ecx, edx);
> + threads_per_ccx = ((eax >> 14) & 0xfff) + 1;
> + shared = shared * threads_per_ccx;
> + }
> + else
> + {
> + /* Account for exclusive L2 and L3 caches. */
> + shared += core;
> + }
> + }
> }
Although not visible in the patch, these changes a properly guarded by
an arch_kind_amd check, as expected.
Beyond that, I can't comment on the substance of the patch, but I'd like
to request the follow style changes:
* Move the definitions of eax and threads_per_ccx closer
to their usage site. Initialize threads_per_ccx directly with its
final variable. (The separate variable is nice for documentation
purposes.)
* Add a space after __cpuid_count (to follow GNU style).
* Add ". " (period and two spaces) at the end of all new comments.
* Remove Signed-off-by. glibc does not use DCO
<https://developercertificate.org/>. I assume this patch is covered
by AMD's copyright assignment instead.
I can make these changes for you and push this, or you can post a new
patch.
Thanks,
Florian
--
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
More information about the Libc-alpha
mailing list