From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18607 invoked by alias); 8 Oct 2013 18:32:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 18590 invoked by uid 89); 8 Oct 2013 18:32:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-4.3 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 08 Oct 2013 18:32:19 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r98IWIdK013589 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 8 Oct 2013 14:32:18 -0400 Received: from host2.jankratochvil.net (ovpn-116-31.ams2.redhat.com [10.36.116.31]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r98IWEl1032313 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Tue, 8 Oct 2013 14:32:17 -0400 Date: Tue, 08 Oct 2013 18:32:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] Minor O_CLOEXEC optimization, "regression" fix Message-ID: <20131008183214.GB27355@host2.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00233.txt.bz2 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 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);