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.16.90-97bc38d7/elf/rtld.c.orig 2012-09-26 15:04:35.933146909 -0300 +++ glibc-2.16.90-97bc38d7/elf/rtld.c 2012-09-26 15:17:00.030170722 -0300 @@ -16,6 +16,9 @@ License along with the GNU C Library; if not, see . */ +/* Early statistics require high-precision timing. */ +#define NEED_HP_TIMING_HWCAP_AVAIL 1 + #include #include #include @@ -193,6 +196,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 @@ -324,9 +333,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.16.90-97bc38d7/sysdeps/generic/ldsodefs.h.orig 2012-09-14 17:31:29.000000000 -0300 +++ glibc-2.16.90-97bc38d7/sysdeps/generic/ldsodefs.h 2012-09-26 15:17:00.030170722 -0300 @@ -309,7 +309,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 @@ -522,7 +522,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.16.90-97bc38d7/sysdeps/i386/i586/hp-timing.c.orig 2012-09-26 15:16:32.425169831 -0300 +++ glibc-2.16.90-97bc38d7/sysdeps/i386/i586/hp-timing.c 2012-09-26 15:17:00.030170722 -0300 @@ -0,0 +1,2 @@ +/* We can use the i686 implementation without changes. */ +#include --- glibc-2.16.90-97bc38d7/sysdeps/i386/i586/hp-timing.h.orig 2012-09-26 15:16:45.313170250 -0300 +++ glibc-2.16.90-97bc38d7/sysdeps/i386/i586/hp-timing.h 2012-09-26 15:17:00.030170722 -0300 @@ -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 */ --- glibc-2.16.90-97bc38d7/sysdeps/i386/i586/Makefile.orig 2012-09-26 15:16:17.042169354 -0300 +++ glibc-2.16.90-97bc38d7/sysdeps/i386/i586/Makefile 2012-09-26 15:17:00.030170722 -0300 @@ -0,0 +1,4 @@ +ifeq ($(subdir),csu) +sysdep_routines += hp-timing +static-only-routines += hp-timing +endif