From 238fc24684ffba3fc0ae542fa752d475d06648e3 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 4 Feb 2013 21:21:55 -0500 Subject: [PATCH] Remove slow sync() call for NFS flushing. --- src/V3File.cpp | 4 +--- src/V3Options.cpp | 12 ++++++++++++ src/V3Options.h | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/V3File.cpp b/src/V3File.cpp index 3621e6739..11cdeb914 100644 --- a/src/V3File.cpp +++ b/src/V3File.cpp @@ -162,13 +162,11 @@ inline void V3FileDependImp::writeTimes(const string& filename, const string& cm *ofp<<"# DESCR"<<"IPTION: Verilator output: Timestamp data for --skip-identical. Delete at will."<::iterator iter=m_filenameList.begin(); iter!=m_filenameList.end(); ++iter) { // Read stats of files we create after we're done making them (execpt for this file, of course) DependFile* dfp = (DependFile*)&(*iter); + V3Options::fileNfsFlush(dfp->filename()); dfp->loadStats(); off_t showSize = iter->size(); if (dfp->filename() == filename) showSize=0; // We're writing it, so need to ignore it diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 6710f1c5e..225cada90 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -277,6 +278,17 @@ bool V3Options::fileStatNormal(const string& filename) { return true; } +void V3Options::fileNfsFlush(const string& filename) { + // NFS caches stat() calls so to get up-to-date information must + // do a open or opendir on the filename. + // Faster to just try both rather than check if a file is a dir. + if (DIR* dirp = opendir(filename.c_str())) { + closedir(dirp); + } else if (int fd = ::open(filename.c_str(), O_RDONLY)) { + if (fd>0) ::close(fd); + } +} + string V3Options::fileExists (const string& filename) { // Surprisingly, for VCS and other simulators, this process // is quite slow; presumably because of re-reading each directory diff --git a/src/V3Options.h b/src/V3Options.h index 2f1a262c9..637c55ad9 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -36,6 +36,7 @@ class V3OptionsImp; class FileLine; +struct stat; typedef vector V3StringList; typedef set V3StringSet; @@ -321,6 +322,7 @@ class V3Options { V3LangCode fileLanguage(const string &filename); static bool fileStatDir (const string& filename); static bool fileStatNormal (const string& filename); + static void fileNfsFlush(const string& filename); // METHODS (other OS) static void throwSigsegv();