public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: Michal Jires <mjires@suse.cz>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 4/7] lto: Implement ltrans cache
Date: Tue, 14 May 2024 13:51:08 +0200	[thread overview]
Message-ID: <ZkNQLD4gEFE6Smxb@kam.mff.cuni.cz> (raw)
In-Reply-To: <788aa123a8fd4bbfa8a80eda37fbacf38ec78c9b.1700222403.git.mjires@suse.cz>

> This patch implements Incremental LTO as ltrans cache.
> 
> The cache is active when directory $GCC_LTRANS_CACHE is specified and exists.
> Stored are pairs of ltrans input/output files and input file hash.
> File locking is used to allow multiple GCC instances to use to same cache.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu
> 
> gcc/ChangeLog:
> 
> 	* Makefile.in: Add lto-ltrans-cache.o.
> 	* lto-wrapper.cc: Use ltrans cache.
> 	* lto-ltrans-cache.cc: New file.
> 	* lto-ltrans-cache.h: New file.
> diff --git a/gcc/lto-ltrans-cache.cc b/gcc/lto-ltrans-cache.cc
> new file mode 100644
> index 00000000000..0d43e548fb3
> --- /dev/null
> +++ b/gcc/lto-ltrans-cache.cc
> @@ -0,0 +1,407 @@
> +/* File caching.
> +   Copyright (C) 2009-2023 Free Software Foundation, Inc.

Probably copyright should be 2023-2024
> +const md5_checksum_t INVALID_CHECKSUM = {
Maybe static here? Officially there should be comment before the
function.
> +  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> +};
> +
> +/* Computes checksum for given file, returns INVALID_CHECKSUM if not possible.
> + */
comment would look more regular if linebreak is made before possible :)
> +
> +/* Checks identity of two files byte by byte.  */
> +static bool
> +files_identical (char const *first_filename, char const *second_filename)
> +{
> +  FILE *f_first = fopen (first_filename, "rb");
> +  if (!f_first)
> +    return false;
> +
> +  FILE *f_second = fopen (second_filename, "rb");
> +  if (!f_second)
> +    {
> +      fclose (f_first);
> +      return false;
> +    }
> +
> +  bool ret = true;
> +
> +  for (;;)
> +    {
> +      int c1, c2;
> +      c1 = fgetc (f_first);
> +      c2 = fgetc (f_second);

I guess reading by fgetc may get quite ineffecient here.  Comparing
bigger blocks is probably going to be faster.  We could also
(incrementally) use mmap where supported.
> +
> +/* Contructor of cache item.  */
> +ltrans_file_cache::item::item (std::string input, std::string output,
> +  md5_checksum_t input_checksum, uint32_t last_used):
Here should be enough whitespace so md5_checksum appears just after ( in
line above
                                  md5_checksum_t input_checksum, uint32_t last_used):
> +  input (std::move (input)), output (std::move (output)),
> +  input_checksum (input_checksum), last_used (last_used)
> +{
> +  lock = lockfile (this->input + ".lock");
> +}
> +/* Destructor of cache item.  */
> +ltrans_file_cache::item::~item ()
> +{
> +  lock.unlock ();
> +}
> +
> +/* Reads next cache item from cachedata file.
> +   Adds `dir/` prefix to filenames.  */
> +static ltrans_file_cache::item*
> +read_cache_item (FILE* f, const char* dir)
> +{
> +  md5_checksum_t checksum;
> +  uint32_t last_used;
> +
> +  if (fread (&checksum, 1, checksum.size (), f) != checksum.size ())
> +    return NULL;
> +  if (fread (&last_used, sizeof (last_used), 1, f) != 1)
> +    return NULL;
> +
> +  std::vector<char> input (strlen (dir));
> +  memcpy (&input[0], dir, input.size ());
> +  input.push_back ('/');
Why this is not std::string?
> +  /* Loads data about previously cached items from cachedata file.
> +
> +     Must be called with creation_lock or deletion_lock held to
> +     prevent data race.  */
> +  void
> +  load_cache ();
There should be no newline between type and name.  It is there only when
defining function (so it is easy to use old-school grep to find where
function is defined.)

Looks good to me otherwise.
Honza

  reply	other threads:[~2024-05-14 11:51 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-17 20:16 [PATCH 0/7] lto: Incremental LTO Michal Jires
2023-11-17 20:16 ` [PATCH 1/7] lto: Skip flag OPT_fltrans_output_list_ Michal Jires
2023-12-29 21:16   ` Jan Hubicka
2023-11-17 20:16 ` [PATCH 2/7] lto: Remove random_seed from section name Michal Jires
2023-12-29 21:17   ` Jan Hubicka
2024-01-09 16:49     ` [PATCH 2/7 v2] " Michal Jires
     [not found]       ` <c480760c-f167-4e60-a27e-52bebdd1351b@suse.cz>
2024-05-14 11:28         ` Fwd: " Jan Hubicka
2023-11-17 20:17 ` [PATCH 3/7] Lockfile Michal Jires
2023-12-29 21:23   ` Jan Hubicka
2024-01-09 17:10     ` Michal Jires
2024-06-20 11:24   ` [PATCH 3/7 v2] Lockfile Michal Jires
2024-06-20 12:36     ` Richard Biener
2023-11-17 20:17 ` [PATCH 4/7] lto: Implement ltrans cache Michal Jires
2024-05-14 11:51   ` Jan Hubicka [this message]
2024-06-20 11:31   ` [PATCH 4/7 v2] " Michal Jires
2024-06-20 17:45     ` Andi Kleen
2024-06-21 11:12       ` Jan Hubicka
2024-06-21 19:07         ` Andi Kleen
2024-06-21 19:16           ` Sam James
2024-06-21 16:59       ` Michal Jireš
2024-06-21 19:09         ` Andi Kleen
2023-11-17 20:17 ` [PATCH 5/7] lto: Implement cache partitioning Michal Jires
2024-05-14 12:10   ` Jan Hubicka
2023-11-17 20:17 ` [PATCH 6/7] lto: squash order of symbols in partitions Michal Jires
2024-05-14 12:20   ` Jan Hubicka
2023-11-17 20:17 ` [PATCH 7/7] lto: partition specific lto_clone_numbers Michal Jires
2024-05-14 12:11   ` Jan Hubicka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZkNQLD4gEFE6Smxb@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mjires@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).