From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16757 invoked by alias); 4 Nov 2004 23:41:43 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 16736 invoked from network); 4 Nov 2004 23:41:42 -0000 Received: from unknown (HELO palrel12.hp.com) (156.153.255.237) by sourceware.org with SMTP; 4 Nov 2004 23:41:42 -0000 Received: from hplms2.hpl.hp.com (hplms2.hpl.hp.com [15.0.152.33]) by palrel12.hp.com (Postfix) with ESMTP id 3C9A540FD29; Thu, 4 Nov 2004 15:41:42 -0800 (PST) Received: from napali.hpl.hp.com (napali.hpl.hp.com [15.4.89.123]) by hplms2.hpl.hp.com (8.13.1/8.13.1/HPL-PA Hub) with ESMTP id iA4NfejN028345; Thu, 4 Nov 2004 15:41:40 -0800 (PST) Received: from napali.hpl.hp.com (napali [127.0.0.1]) by napali.hpl.hp.com (8.13.1/8.13.1/Debian-16) with ESMTP id iA4NfeCJ008588; Thu, 4 Nov 2004 15:41:40 -0800 Received: (from davidm@localhost) by napali.hpl.hp.com (8.13.1/8.13.1/Submit) id iA4NfdWm008585; Thu, 4 Nov 2004 15:41:39 -0800 From: David Mosberger MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16778.48691.899903.792304@napali.hpl.hp.com> Date: Thu, 04 Nov 2004 23:41:00 -0000 To: Roland McGrath , libc-hacker@sources.redhat.com Cc: davidm@hpl.hp.com Subject: Re: second thoughts on using dl_iterate_phdr() for cache-validation In-Reply-To: <16491.32601.193260.288217@napali.hpl.hp.com> References: <16490.8972.453326.222897@napali.hpl.hp.com> <200403310804.i2V84PP6007330@magilla.sf.frob.com> <16491.32601.193260.288217@napali.hpl.hp.com> Reply-To: davidm@hpl.hp.com X-URL: http://www.hpl.hp.com/personal/David_Mosberger/ X-SW-Source: 2004-11/txt/msg00006.txt.bz2 This is a follow-up on a discussion that went dead around March 31. There were no objections to the patch I presented then and if that's still the case, I'd appreciate if this patch could be checked in. It speeds up dynamic-object cache-validition a great deal (~ a factor of 2, mainly because dl_iterate_phdr() requires taking an expensive lock). BTW: i assume an interface along the lines of: enum dl_counter { DL_PHDR_ADDITIONS, DL_PHDR_REMOVALS }; unsigned long long *dl_get_counter_address (enum dl_counter which_counter); is out of the question. If not, this would be even better, since the cache-validation overhead would drop to a simple load & compare. Thanks, --david --- ChangeLog 2004-11-04 David Mosberger * elf/Versions (dl_phdr_additions_count): New export (dl_phdr_removals_count): Likewise. * elf/dl-close.c (_dl_close): Increment dl_load_subs; * elf/dl-iteratephdr.c (dl_phdr_additions_count): New function. (dl_phdr_removals_count): Likewise. * elf/dl-support.c: New variable. * elf/tst-dlmodcount.c: New file. * include/link.h (dl_phdr_additions_count): Declare. (dl_phdr_removals_count): Likewise. * sysdeps/generic/ldsodefs.h (struct rtld_global): Add member "_dl_load_subs". Index: elf/Versions =================================================================== RCS file: /cvs/glibc/libc/elf/Versions,v retrieving revision 1.52 diff -u -r1.52 Versions --- elf/Versions 19 Oct 2004 22:20:33 -0000 1.52 +++ elf/Versions 4 Nov 2004 23:38:29 -0000 @@ -11,6 +11,10 @@ GLIBC_2.2.4 { dl_iterate_phdr; } + GLIBC_2.3.2 { + dl_phdr_additions_count; + dl_phdr_removals_count; + } %ifdef EXPORT_UNWIND_FIND_FDE GCC_3.0 { __register_frame_info_bases; __deregister_frame_info_bases; Index: elf/dl-close.c =================================================================== RCS file: /cvs/glibc/libc/elf/dl-close.c,v retrieving revision 1.107 diff -u -r1.107 dl-close.c --- elf/dl-close.c 14 Oct 2004 09:20:57 -0000 1.107 +++ elf/dl-close.c 4 Nov 2004 23:38:29 -0000 @@ -368,6 +368,7 @@ /* Notify the debugger we are about to remove some loaded objects. */ _r_debug.r_state = RT_DELETE; GLRO(dl_debug_state) (); + ++GL(dl_load_subs); #ifdef USE_TLS size_t tls_free_start; Index: elf/dl-iteratephdr.c =================================================================== RCS file: /cvs/glibc/libc/elf/dl-iteratephdr.c,v retrieving revision 1.12 diff -u -r1.12 dl-iteratephdr.c --- elf/dl-iteratephdr.c 14 Oct 2004 02:02:06 -0000 1.12 +++ elf/dl-iteratephdr.c 4 Nov 2004 23:38:29 -0000 @@ -23,6 +23,19 @@ #include #include + +unsigned long long +dl_phdr_additions_count (void) +{ + return GL(dl_load_adds); +} + +unsigned long long +dl_phdr_removals_count (void) +{ + return GL(dl_load_subs); +} + static void cancel_handler (void *arg __attribute__((unused))) { Index: elf/dl-support.c =================================================================== RCS file: /cvs/glibc/libc/elf/dl-support.c,v retrieving revision 1.86 diff -u -r1.86 dl-support.c --- elf/dl-support.c 14 Oct 2004 02:06:18 -0000 1.86 +++ elf/dl-support.c 4 Nov 2004 23:38:29 -0000 @@ -73,6 +73,9 @@ /* Incremented whenever something may have been added to dl_loaded. */ unsigned long long _dl_load_adds; +/* Incremented whenever something may have been removed from dl_loaded. */ +unsigned long long _dl_load_subs; + /* Fake scope. In dynamically linked binaries this is the scope of the main application but here we don't have something like this. So create a fake scope containing nothing. */ Index: elf/tst-dlmodcount.c =================================================================== RCS file: /cvs/glibc/libc/elf/tst-dlmodcount.c,v retrieving revision 1.3 diff -u -r1.3 tst-dlmodcount.c --- elf/tst-dlmodcount.c 26 Mar 2004 09:48:53 -0000 1.3 +++ elf/tst-dlmodcount.c 4 Nov 2004 23:38:29 -0000 @@ -71,6 +71,39 @@ return -1; } +static void +check (int cmd) +{ + static int last_adds = 0, last_subs = 0; + + printf (" additions = %Lu removals = %Lu\n", + dl_phdr_additions_count (), dl_phdr_removals_count ()); + + switch (cmd) + { + case SET: + break; + + case ADD: + if (leq (dl_phdr_additions_count (), last_adds)) + { + fprintf (stderr, "dlpi_adds failed to get incremented!\n"); + exit (3); + } + break; + + case REMOVE: + if (leq (dl_phdr_removals_count (), last_subs)) + { + fprintf (stderr, "dlpi_subs failed to get incremented!\n"); + exit (4); + } + break; + } + last_adds = dl_phdr_additions_count (); + last_subs = dl_phdr_removals_count (); +} + static void * load (const char *path) { @@ -81,6 +114,7 @@ if (!handle) exit (1); dl_iterate_phdr (callback, (void *)(intptr_t) ADD); + check (ADD); return handle; } @@ -91,6 +125,7 @@ if (dlclose (handle) < 0) exit (2); dl_iterate_phdr (callback, (void *)(intptr_t) REMOVE); + check (REMOVE); } int @@ -99,6 +134,7 @@ void *handle1, *handle2; dl_iterate_phdr (callback, (void *)(intptr_t) SET); + check (SET); handle1 = load ("firstobj.so"); handle2 = load ("globalmod1.so"); unload ("firstobj.so", handle1); Index: include/link.h =================================================================== RCS file: /cvs/glibc/libc/include/link.h,v retrieving revision 1.33 diff -u -r1.33 link.h --- include/link.h 14 Oct 2004 01:57:54 -0000 1.33 +++ include/link.h 4 Nov 2004 23:38:30 -0000 @@ -317,4 +317,18 @@ size_t size, void *data), void *data); +/* The value returned by this function increments by at least 1 when + objects are added to the list visited by dl_iterate_phdr(). This + function is not serialized with respect to dl_iterate_phdr(). If + serialization is needed, this function should be called from within + a dl_itereate_phdr() callback. */ +extern unsigned long long dl_phdr_additions_count (void); + +/* The vaue returned by this function increments by at least 1 when + objects are removed from the list visited by dl_iterate_phdr(). + This function is not serialized with respect to dl_iterate_phdr(). + If serialization is needed, this function should be called from + within a dl_itereate_phdr() callback. */ +extern unsigned long long dl_phdr_removals_count (void); + #endif /* link.h */ Index: sysdeps/generic/ldsodefs.h =================================================================== RCS file: /cvs/glibc/libc/sysdeps/generic/ldsodefs.h,v retrieving revision 1.105 diff -u -r1.105 ldsodefs.h --- sysdeps/generic/ldsodefs.h 19 Oct 2004 22:19:17 -0000 1.105 +++ sysdeps/generic/ldsodefs.h 4 Nov 2004 23:38:31 -0000 @@ -250,6 +250,9 @@ /* Incremented whenever something may have been added to dl_loaded. */ EXTERN unsigned long long _dl_load_adds; + /* Incremented whenever something may have been removed from dl_loaded. */ + EXTERN unsigned long long _dl_load_subs; + #ifndef MAP_ANON /* File descriptor referring to the zero-fill device. */ EXTERN int _dl_zerofd;