From 24cfb7998c27feb4f9bc9631dcf4601ce3a86e3a Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Tue, 20 Sep 2022 19:05:38 +0200 Subject: [PATCH] feat: Use subsecond timestamps for include file check To avoid a race condition, ccache disables the direct mode if an include file has a too new mtime or ctime. Previously this check used one second resolution timestamps, which meant that a generated include file often would disable direct mode hits for up to one second. Now ccache uses timestamps with subsecond resolution (nanoseconds on Linux), so the direct mode will in practice no longer have to be disabled for generated include files. --- doc/MANUAL.adoc | 12 ++++++------ src/ccache.cpp | 8 ++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index 290d3cf30..8011e0d9f 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -962,13 +962,13 @@ Examples: directory in the `.gcno` file. *gcno_cwd* also disables hashing of the current working directory if `-fprofile-abs-path` is used. *include_file_ctime*:: - By default, ccache will not cache a file if it includes a header whose ctime - is too new. This sloppiness disables that check. See also - _<>_. + By default, ccache will disable the direct mode if an include file has too + new ctime. This sloppiness disables that check. See also _<>_. *include_file_mtime*:: - By default, ccache will not cache a file if it includes a header whose mtime - is too new. This sloppiness disables that check. See also - _<>_. + By default, ccache will disable the direct mode if an include file has too + new mtime. This sloppiness disables that check. See also _<>_. *ivfsoverlay*:: Ignore the Clang compiler option `-ivfsoverlay` and its argument. This is useful if you use Xcode, which uses a virtual file system (VFS) for things diff --git a/src/ccache.cpp b/src/ccache.cpp index 94d4a561a..c127c6d22 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -262,14 +262,14 @@ include_file_too_new(const Context& ctx, // starting compilation and writing the include file. See also the notes under // "Performance" in doc/MANUAL.adoc. if (!(ctx.config.sloppiness().is_enabled(core::Sloppy::include_file_mtime)) - && path_stat.mtime().sec() >= ctx.time_of_compilation.sec()) { + && path_stat.mtime() >= ctx.time_of_compilation) { LOG("Include file {} too new", path); return true; } // The same >= logic as above applies to the change time of the file. if (!(ctx.config.sloppiness().is_enabled(core::Sloppy::include_file_ctime)) - && path_stat.ctime().sec() >= ctx.time_of_compilation.sec()) { + && path_stat.ctime() >= ctx.time_of_compilation) { LOG("Include file {} ctime too new", path); return true; } @@ -774,10 +774,6 @@ update_manifest(Context& ctx, MTR_SCOPE("manifest", "manifest_put"); - // {m,c}time() have a resolution of 1 second, so we can cache the file's mtime - // and ctime only if they're at least one second older than - // time_of_compilation. - // // ctime() may be 0, so we have to check time_of_compilation against // MAX(mtime, ctime). // -- 2.47.2