mirror of
https://sourceware.org/git/glibc.git
synced 2025-01-13 04:30:07 +00:00
67385a01d2
This patch adds a new feature for powerpc. In order to get faster access to the HWCAP/HWCAP2 bits and platform number (i.e. for implementing __builtin_cpu_is () / __builtin_cpu_supports () in GCC) without the overhead of reading from the auxiliary vector, we now reserve space for them in the TCB. This is an ABI change for GLIBC 2.23. A new versioned symbol '__parse_hwcap_and_convert_at_platform' is available to get the data from the auxiliary vector and parse it, and store it for later use in the TLS initialization code. This function is called very early (in _dl_sysdep_start () via DL_PLATFORM_INFO for the dynamic linking case, and in __libc_start_main () for the static linking case) to make sure the data is available at the time of TLS initialization. * sysdeps/powerpc/Makefile (sysdep-dl-routines): Add hwcapinfo. (sysdep_routines): Likewise. (sysdep-rtld-routines): Likewise. [$(subdir) = nptl](tests): Add test-get_hwcap and test-get_hwcap-static [$(subdir) = nptl](tests-static): test-get_hwcap-static * sysdeps/powerpc/Versions: Added new __parse_hwcap_and_convert_at_platform symbol to GLIBC-2.23. * sysdeps/powerpc/hwcapinfo.c: New file. (__tcb_parse_hwcap_and_convert_at_platform): New function to initialize and parse hwcap, hwcap2 and platform number information. * sysdeps/powerpc/hwcapinfo.h: New file. Creates global variables to store HWCAP+HWCAP2 and platform number. * sysdeps/powerpc/nptl/tcb-offsets.sym: Added new offsets for HWCAP+HWCAP2 and platform number in the TCB. * sysdeps/powerpc/nptl/tls.h: New functionality. Stores the HWCAP, HWCAP2 and platform number in the TCB. (dtv): Added new fields for HWCAP+HWCAP2 and platform number. (TLS_INIT_TP): Included calls to add the hwcap and at_platform values in the TCB in TP initialization. (TLS_DEFINE_INIT_TP): Likewise. (THREAD_GET_HWCAP): New macro. (THREAD_SET_HWCAP): Likewise. (THREAD_GET_AT_PLATFORM): Likewise. (THREAD_SET_AT_PLATFORM): Likewise. * sysdeps/powerpc/powerpc32/dl-machine.h: (dl_platform_init): New function that calls __parse_hwcap_and_convert_at_platform for the dymanic linking case for powerpc32. * sysdeps/powerpc/powerpc64/dl-machine.h: Likewise, for powerpc64. * sysdeps/powerpc/test-get_hwcap-static.c: New file. Testcase for this functionality, static linking case. * sysdeps/powerpc/test-get_hwcap.c: New file. Likewise, dynamic linking case. * sysdeps/unix/sysv/linux/powerpc/libc-start.c: Added call to __parse_hwcap_and_convert_at_platform for the static linking case. * sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist: Included the new __parse_hwcap_and_convert_at_platform symbol in the ABI list for GLIBC 2.23. * sysdeps/unix/sysv/linux/powerpc/powerpc64/ld-le.abilist: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/ld.abilist: Likewise.
189 lines
4.6 KiB
C
189 lines
4.6 KiB
C
/* Check __ppc_get_hwcap() and __ppc_get_at_plaftorm() functionality.
|
|
Copyright (C) 2015 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
/* Tests if the hwcap, hwcap2 and platform data are stored in the TCB. */
|
|
|
|
#include <inttypes.h>
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <pthread.h>
|
|
|
|
#include <sys/auxv.h>
|
|
|
|
#include <dl-procinfo.h>
|
|
|
|
#ifndef STATIC_TST_HWCAP
|
|
#undef PROCINFO_DECL
|
|
#include <dl-procinfo.c>
|
|
#endif
|
|
|
|
/* Offsets copied from tcb-offsets.h. */
|
|
|
|
#ifdef __powerpc64__
|
|
# define __TPREG "r13"
|
|
# define __HWCAPOFF -28776
|
|
# define __ATPLATOFF -28764
|
|
#else
|
|
# define __TPREG "r2"
|
|
# define __HWCAPOFF -28736
|
|
# define __HWCAP2OFF -28732
|
|
# define __ATPLATOFF -28724
|
|
#endif
|
|
|
|
uint64_t check_tcbhwcap (long tid)
|
|
{
|
|
|
|
uint32_t tcb_at_platform, at_platform;
|
|
uint64_t hwcap, hwcap2, tcb_hwcap;
|
|
const char *at_platform_string;
|
|
|
|
/* Testing if the hwcap/hwcap2 data is correctly initialized by
|
|
TLS_TP_INIT. */
|
|
|
|
register unsigned long __tp __asm__ (__TPREG);
|
|
|
|
#ifdef __powerpc64__
|
|
__asm__ ("ld %0,%1(%2)\n"
|
|
: "=r" (tcb_hwcap)
|
|
: "i" (__HWCAPOFF), "b" (__tp));
|
|
#else
|
|
uint64_t h1, h2;
|
|
|
|
__asm__ ("lwz %0,%1(%2)\n"
|
|
: "=r" (h1)
|
|
: "i" (__HWCAPOFF), "b" (__tp));
|
|
__asm__ ("lwz %0,%1(%2)\n"
|
|
: "=r" (h2)
|
|
: "i" (__HWCAP2OFF), "b" (__tp));
|
|
tcb_hwcap = (h1 >> 32) << 32 | (h2 >> 32);
|
|
#endif
|
|
|
|
hwcap = getauxval (AT_HWCAP);
|
|
hwcap2 = getauxval (AT_HWCAP2);
|
|
|
|
/* hwcap contains only the latest supported ISA, the code checks which is
|
|
and fills the previous supported ones. This is necessary because the
|
|
same is done in hwcapinfo.c when setting the values that are copied to
|
|
the TCB. */
|
|
|
|
if (hwcap2 & PPC_FEATURE2_ARCH_2_07)
|
|
hwcap |= PPC_FEATURE_ARCH_2_06
|
|
| PPC_FEATURE_ARCH_2_05
|
|
| PPC_FEATURE_POWER5_PLUS
|
|
| PPC_FEATURE_POWER5
|
|
| PPC_FEATURE_POWER4;
|
|
else if (hwcap & PPC_FEATURE_ARCH_2_06)
|
|
hwcap |= PPC_FEATURE_ARCH_2_05
|
|
| PPC_FEATURE_POWER5_PLUS
|
|
| PPC_FEATURE_POWER5
|
|
| PPC_FEATURE_POWER4;
|
|
else if (hwcap & PPC_FEATURE_ARCH_2_05)
|
|
hwcap |= PPC_FEATURE_POWER5_PLUS
|
|
| PPC_FEATURE_POWER5
|
|
| PPC_FEATURE_POWER4;
|
|
else if (hwcap & PPC_FEATURE_POWER5_PLUS)
|
|
hwcap |= PPC_FEATURE_POWER5
|
|
| PPC_FEATURE_POWER4;
|
|
else if (hwcap & PPC_FEATURE_POWER5)
|
|
hwcap |= PPC_FEATURE_POWER4;
|
|
|
|
hwcap = (hwcap << 32) + hwcap2;
|
|
|
|
if ( tcb_hwcap != hwcap )
|
|
{
|
|
printf ("FAIL: __ppc_get_hwcap() - HWCAP is %" PRIx64 ". Should be %"
|
|
PRIx64 " for thread %ld.\n", tcb_hwcap, hwcap, tid);
|
|
return 1;
|
|
}
|
|
|
|
/* Same test for the platform number. */
|
|
__asm__ ("lwz %0,%1(%2)\n"
|
|
: "=r" (tcb_at_platform)
|
|
: "i" (__ATPLATOFF), "b" (__tp));
|
|
|
|
at_platform_string = (const char *) getauxval (AT_PLATFORM);
|
|
at_platform = _dl_string_platform (at_platform_string);
|
|
|
|
if ( tcb_at_platform != at_platform )
|
|
{
|
|
printf ("FAIL: __ppc_get_at_platform() - AT_PLATFORM is %x. Should be %x"
|
|
" for thread %ld\n", tcb_at_platform, at_platform, tid);
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void *t1 (void *tid)
|
|
{
|
|
if (check_tcbhwcap ((long) tid))
|
|
{
|
|
pthread_exit (tid);
|
|
}
|
|
|
|
pthread_exit (NULL);
|
|
|
|
}
|
|
|
|
static int
|
|
do_test (void)
|
|
{
|
|
|
|
pthread_t threads[2];
|
|
pthread_attr_t attr;
|
|
pthread_attr_init (&attr);
|
|
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_JOINABLE);
|
|
void *status;
|
|
|
|
long i = 0;
|
|
|
|
/* Check for main. */
|
|
if (check_tcbhwcap (i))
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
/* Check for other thread. */
|
|
i++;
|
|
if (pthread_create (&threads[i], &attr, t1, (void *)i))
|
|
{
|
|
printf ("FAIL: error creating thread %ld.\n", i);
|
|
return 1;
|
|
}
|
|
|
|
pthread_attr_destroy (&attr);
|
|
if (pthread_join (threads[i], &status))
|
|
{
|
|
printf ("FAIL: error joining thread %ld.\n", i);
|
|
return 1;
|
|
}
|
|
if (status)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
printf("PASS: HWCAP, HWCAP2 and AT_PLATFORM are correctly set in the TCB for"
|
|
" all threads.\n");
|
|
|
|
pthread_exit (NULL);
|
|
|
|
}
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
#include "../test-skeleton.c"
|