netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] tools: ynl-gen: don't touch the output file if content is the same
@ 2023-10-27 22:34 Jakub Kicinski
  2023-10-28  8:26 ` Jiri Pirko
  2023-11-02  5:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Jakub Kicinski @ 2023-10-27 22:34 UTC (permalink / raw)
  To: davem; +Cc: netdev, edumazet, pabeni, jiri, Jakub Kicinski

I often regenerate all YNL files in the tree to make sure they
are in sync with the codegen and specs. Generator rewrites
the files unconditionally, so since make looks at file modification
time to decide what to rebuild - my next build takes longer.

We already generate the code to a tempfile most of the time,
only overwrite the target when we have to.

Before:

  $ stat include/uapi/linux/netdev.h
    File: include/uapi/linux/netdev.h
    Size: 2307      	Blocks: 8          IO Block: 4096   regular file
  Access: 2023-10-27 15:19:56.347071940 -0700
  Modify: 2023-10-27 15:19:45.089000900 -0700
  Change: 2023-10-27 15:19:45.089000900 -0700
   Birth: 2023-10-27 15:19:45.088000894 -0700

  $ ./tools/net/ynl/ynl-regen.sh -f
  [...]

  $ stat include/uapi/linux/netdev.h
    File: include/uapi/linux/netdev.h
    Size: 2307      	Blocks: 8          IO Block: 4096   regular file
  Access: 2023-10-27 15:19:56.347071940 -0700
  Modify: 2023-10-27 15:22:18.417968446 -0700
  Change: 2023-10-27 15:22:18.417968446 -0700
   Birth: 2023-10-27 15:19:45.088000894 -0700

After:

  $ stat include/uapi/linux/netdev.h
    File: include/uapi/linux/netdev.h
    Size: 2307      	Blocks: 8          IO Block: 4096   regular file
  Access: 2023-10-27 15:22:41.520114221 -0700
  Modify: 2023-10-27 15:22:18.417968446 -0700
  Change: 2023-10-27 15:22:18.417968446 -0700
   Birth: 2023-10-27 15:19:45.088000894 -0700

  $ ./tools/net/ynl/ynl-regen.sh -f
  [...]

  $ stat include/uapi/linux/netdev.h
    File: include/uapi/linux/netdev.h
    Size: 2307      	Blocks: 8          IO Block: 4096   regular file
  Access: 2023-10-27 15:22:41.520114221 -0700
  Modify: 2023-10-27 15:22:18.417968446 -0700
  Change: 2023-10-27 15:22:18.417968446 -0700
   Birth: 2023-10-27 15:19:45.088000894 -0700

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/net/ynl/ynl-gen-c.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 13427436bfb7..c4003a83cd5d 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -3,6 +3,7 @@
 
 import argparse
 import collections
+import filecmp
 import os
 import re
 import shutil
@@ -1168,7 +1169,7 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
         if out_file is None:
             self._out = os.sys.stdout
         else:
-            self._out = tempfile.TemporaryFile('w+')
+            self._out = tempfile.NamedTemporaryFile('w+')
             self._out_file = out_file
 
     def __del__(self):
@@ -1177,6 +1178,10 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
     def close_out_file(self):
         if self._out == os.sys.stdout:
             return
+        # Avoid modifying the file if contents didn't change
+        self._out.flush()
+        if os.path.isfile(self._out_file) and filecmp.cmp(self._out.name, self._out_file, shallow=False):
+            return
         with open(self._out_file, 'w+') as out_file:
             self._out.seek(0)
             shutil.copyfileobj(self._out, out_file)
-- 
2.41.0


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

* Re: [PATCH net-next] tools: ynl-gen: don't touch the output file if content is the same
  2023-10-27 22:34 [PATCH net-next] tools: ynl-gen: don't touch the output file if content is the same Jakub Kicinski
@ 2023-10-28  8:26 ` Jiri Pirko
  2023-11-02  5:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Pirko @ 2023-10-28  8:26 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni

Sat, Oct 28, 2023 at 12:34:08AM CEST, kuba@kernel.org wrote:
>I often regenerate all YNL files in the tree to make sure they
>are in sync with the codegen and specs. Generator rewrites
>the files unconditionally, so since make looks at file modification
>time to decide what to rebuild - my next build takes longer.
>
>We already generate the code to a tempfile most of the time,
>only overwrite the target when we have to.
>
>Before:
>
>  $ stat include/uapi/linux/netdev.h
>    File: include/uapi/linux/netdev.h
>    Size: 2307      	Blocks: 8          IO Block: 4096   regular file
>  Access: 2023-10-27 15:19:56.347071940 -0700
>  Modify: 2023-10-27 15:19:45.089000900 -0700
>  Change: 2023-10-27 15:19:45.089000900 -0700
>   Birth: 2023-10-27 15:19:45.088000894 -0700
>
>  $ ./tools/net/ynl/ynl-regen.sh -f
>  [...]
>
>  $ stat include/uapi/linux/netdev.h
>    File: include/uapi/linux/netdev.h
>    Size: 2307      	Blocks: 8          IO Block: 4096   regular file
>  Access: 2023-10-27 15:19:56.347071940 -0700
>  Modify: 2023-10-27 15:22:18.417968446 -0700
>  Change: 2023-10-27 15:22:18.417968446 -0700
>   Birth: 2023-10-27 15:19:45.088000894 -0700
>
>After:
>
>  $ stat include/uapi/linux/netdev.h
>    File: include/uapi/linux/netdev.h
>    Size: 2307      	Blocks: 8          IO Block: 4096   regular file
>  Access: 2023-10-27 15:22:41.520114221 -0700
>  Modify: 2023-10-27 15:22:18.417968446 -0700
>  Change: 2023-10-27 15:22:18.417968446 -0700
>   Birth: 2023-10-27 15:19:45.088000894 -0700
>
>  $ ./tools/net/ynl/ynl-regen.sh -f
>  [...]
>
>  $ stat include/uapi/linux/netdev.h
>    File: include/uapi/linux/netdev.h
>    Size: 2307      	Blocks: 8          IO Block: 4096   regular file
>  Access: 2023-10-27 15:22:41.520114221 -0700
>  Modify: 2023-10-27 15:22:18.417968446 -0700
>  Change: 2023-10-27 15:22:18.417968446 -0700
>   Birth: 2023-10-27 15:19:45.088000894 -0700
>
>Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>

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

* Re: [PATCH net-next] tools: ynl-gen: don't touch the output file if content is the same
  2023-10-27 22:34 [PATCH net-next] tools: ynl-gen: don't touch the output file if content is the same Jakub Kicinski
  2023-10-28  8:26 ` Jiri Pirko
@ 2023-11-02  5:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-11-02  5:20 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni, jiri

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 27 Oct 2023 15:34:08 -0700 you wrote:
> I often regenerate all YNL files in the tree to make sure they
> are in sync with the codegen and specs. Generator rewrites
> the files unconditionally, so since make looks at file modification
> time to decide what to rebuild - my next build takes longer.
> 
> We already generate the code to a tempfile most of the time,
> only overwrite the target when we have to.
> 
> [...]

Here is the summary with links:
  - [net-next] tools: ynl-gen: don't touch the output file if content is the same
    https://git.kernel.org/netdev/net/c/2b7ac0c87d98

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-11-02  5:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-27 22:34 [PATCH net-next] tools: ynl-gen: don't touch the output file if content is the same Jakub Kicinski
2023-10-28  8:26 ` Jiri Pirko
2023-11-02  5:20 ` patchwork-bot+netdevbpf

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 NNTP newsgroup(s).