2006-05-17 Gwenole Beauchesne * Update and simplify for glibc 2.4.90. 2002-12-07 Gwenole Beauchesne Let an i586 rtld load i686 libraries (especially libpthread) * elf/rtld.c (HP_TIMING_AVAIL): Redefine to HP_TIMING_HWCAP_AVAIL since early statistics require high-precision timers. * sysdeps/generic/ldsodefs.h (rtld_global): Declare _dl_cpuclock_offset if HP_TIMING_HWCAP_AVAIL is defined too. * sysdeps/unix/sysv/linux/i386/i586/Makefile: New file. * sysdeps/unix/sysv/linux/i386/i586/hp-timing.c: New file. * sysdeps/unix/sysv/linux/i386/i586/hp-timing.h: New file. --- glibc-2.4.90/elf/rtld.c.i586-hptiming 2006-04-27 14:54:33.000000000 +0200 +++ glibc-2.4.90/elf/rtld.c 2006-05-17 08:31:50.000000000 +0200 @@ -17,6 +17,9 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +/* Early statistics require high-precision timing. */ +#define NEED_HP_TIMING_HWCAP_AVAIL 1 + #include #include #include @@ -178,6 +181,12 @@ static void dl_main (const ElfW(Phdr) *p static struct libname_list _dl_rtld_libname; static struct libname_list _dl_rtld_libname2; +/* Run-time detect availability of high-precision timer? */ +#ifdef HP_TIMING_HWCAP_AVAIL +# undef HP_TIMING_AVAIL +# define HP_TIMING_AVAIL HP_TIMING_HWCAP_AVAIL +#endif + /* We expect less than a second for relocation. */ #ifdef HP_SMALL_TIMING_AVAIL # undef HP_TIMING_AVAIL @@ -311,9 +320,8 @@ _dl_start_final (void *arg, struct dl_st #endif -#if HP_TIMING_AVAIL - HP_TIMING_NOW (GL(dl_cpuclock_offset)); -#endif + if (HP_TIMING_AVAIL) + HP_TIMING_NOW (GL(dl_cpuclock_offset)); /* Initialize the stack end variable. */ __libc_stack_end = __builtin_frame_address (0); --- glibc-2.4.90/sysdeps/generic/ldsodefs.h.i586-hptiming 2006-05-10 15:42:19.000000000 +0200 +++ glibc-2.4.90/sysdeps/generic/ldsodefs.h 2006-05-17 08:13:21.000000000 +0200 @@ -408,7 +408,7 @@ struct rtld_global /* The object to be initialized first. */ EXTERN struct link_map *_dl_initfirst; -#if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL +#if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL || defined HP_TIMING_HWCAP_AVAIL /* Start time on CPU clock. */ EXTERN hp_timing_t _dl_cpuclock_offset; #endif @@ -619,7 +619,7 @@ struct rtld_global_ro /* All search directories defined at startup. */ EXTERN struct r_search_path_elem *_dl_init_all_dirs; -#if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL +#if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL || defined HP_TIMING_HWCAP_AVAIL /* Overhead of a high-precision timing measurement. */ EXTERN hp_timing_t _dl_hp_timing_overhead; #endif --- glibc-2.4.90/sysdeps/i386/i586/Makefile.i586-hptiming 2006-05-17 06:35:29.000000000 +0200 +++ glibc-2.4.90/sysdeps/i386/i586/Makefile 2006-05-17 06:35:41.000000000 +0200 @@ -0,0 +1,4 @@ +ifeq ($(subdir),csu) +sysdep_routines += hp-timing +static-only-routines += hp-timing +endif --- glibc-2.4.90/sysdeps/i386/i586/hp-timing.c.i586-hptiming 2006-05-17 06:36:28.000000000 +0200 +++ glibc-2.4.90/sysdeps/i386/i586/hp-timing.c 2006-05-17 08:17:51.000000000 +0200 @@ -0,0 +1,2 @@ +/* We can use the i686 implementation without changes. */ +#include --- glibc-2.4.90/sysdeps/i386/i586/hp-timing.h.i586-hptiming 2006-05-17 06:37:28.000000000 +0200 +++ glibc-2.4.90/sysdeps/i386/i586/hp-timing.h 2006-05-17 08:30:06.000000000 +0200 @@ -0,0 +1,43 @@ +#ifndef _HP_HWCAP_TIMING_H +#define _HP_HWCAP_TIMING_H 1 + +/* We can use the i686 implementation with slight changes. */ +#include + +/* We need the definition of HWCAP_I386_TSC. */ +#include + +/* We need to perform a runtime check for the timestamp register. */ +#undef HP_TIMING_AVAIL +#define HP_TIMING_AVAIL (0) + +/* HP_TIMING_HWCAP_AVAIL: this macro performs a run-time check for the + capability. */ +#define HP_TIMING_HWCAP_AVAIL (_dl_hp_timing_avail()) + +/* Perform the TSC check. */ +#ifdef NEED_HP_TIMING_HWCAP_AVAIL +static inline +unsigned int +_dl_cpuid_edx (unsigned int op) +{ + unsigned int edx; + __asm__ __volatile__("push %%ebx ; cpuid ; pop %%ebx" + : "=d" (edx) : "a" (op) : "ecx"); + return edx; +} + +static int +internal_function +_dl_hp_timing_avail (void) +{ + static int has_tsc = -1; + + if (__builtin_expect (has_tsc == -1, 0)) + has_tsc = (_dl_cpuid_edx(1) & HWCAP_I386_TSC) == HWCAP_I386_TSC; + + return has_tsc; +} +#endif + +#endif /* hp-timing.h */