Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] Minor O_CLOEXEC optimization, "regression" fix
@ 2013-10-08 18:32 Jan Kratochvil
  2013-10-08 19:44 ` Tom Tromey
  0 siblings, 1 reply; 15+ messages in thread
From: Jan Kratochvil @ 2013-10-08 18:32 UTC (permalink / raw)
  To: gdb-patches

Hi Tom,

I just noticed GDB does many needless double-opens with ENOENT like:

open("/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY) = -1 ENOENT (No such file or directory)

The fix is simple, it saved 30 syscalls on a small example (3076->3046) like:

 open("/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
-open("/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY) = -1 ENOENT (No such file or directory)
 open("/usr/lib/debug/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
-open("/usr/lib/debug/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY) = -1 ENOENT (No such file or directory)
 open("/usr/share/gdb/auto-load/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
-open("/usr/share/gdb/auto-load/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY) = -1 ENOENT (No such file or directory)

No regressions on {x86_64,x86_64-m32,i686}-fedora21pre-linux-gnu.


Jan


gdb/
2013-10-08  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Minor performance optimization of opening non-existing files.
	* common/filestuff.c (gdb_fopen_cloexec): New variable
	fopen_e_ever_succeeded, use it.

diff --git a/gdb/common/filestuff.c b/gdb/common/filestuff.c
index d3b13e8..e10a013 100644
--- a/gdb/common/filestuff.c
+++ b/gdb/common/filestuff.c
@@ -319,6 +319,10 @@ gdb_fopen_cloexec (const char *filename, const char *opentype)
      supported.  */
   static int fopen_e_ever_failed = O_CLOEXEC == 0;
 
+  /* If we know the operating system supports "e" do not retry the open
+     without "e".  The file for example just does not exist.  */
+  static int fopen_e_ever_succeeded;
+
   if (!fopen_e_ever_failed)
     {
       char *copy;
@@ -331,7 +335,9 @@ gdb_fopen_cloexec (const char *filename, const char *opentype)
       result = fopen (filename, copy);
     }
 
-  if (result == NULL)
+  if (result != NULL)
+    fopen_e_ever_succeeded = 1;
+  else if (!fopen_e_ever_succeeded)
     {
       /* Fallback.  */
       result = fopen (filename, opentype);


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2013-10-09 19:08 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-08 18:32 [patch] Minor O_CLOEXEC optimization, "regression" fix Jan Kratochvil
2013-10-08 19:44 ` Tom Tromey
2013-10-09 13:10   ` Jan Kratochvil
2013-10-09 13:34     ` Kai Tietz
2013-10-09 14:41       ` [patchv2] " Jan Kratochvil
2013-10-09 15:48         ` Tom Tromey
2013-10-09 16:01           ` [commit] " Jan Kratochvil
2013-10-09 17:07       ` [patch] " Eli Zaretskii
2013-10-09 17:02     ` Eli Zaretskii
2013-10-09 17:08       ` Tom Tromey
2013-10-09 17:29         ` Eli Zaretskii
2013-10-09 17:41           ` Jan Kratochvil
2013-10-09 17:58             ` Eli Zaretskii
2013-10-09 18:37               ` Jan Kratochvil
2013-10-09 19:08                 ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox