Skip to content

Commit

Permalink
Merge branch 'tools-ynl-fixes-for-the-page-pool-sample-and-the-genera…
Browse files Browse the repository at this point in the history
…tion-process'

Jakub Kicinski says:

====================
tools: ynl: fixes for the page-pool sample and the generation process

Minor fixes to the new sample and the Makefiles.
====================

Link: https://lore.kernel.org/r/20231129193622.2912353-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Nov 30, 2023
2 parents 987b71f + a115b92 commit 6afb936
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions tools/net/ynl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ SUBDIRS = lib generated samples

all: $(SUBDIRS)

samples: | lib generated

$(SUBDIRS):
@if [ -f "$@/Makefile" ] ; then \
$(MAKE) -C $@ ; \
Expand Down
2 changes: 2 additions & 0 deletions tools/net/ynl/samples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ include $(wildcard *.d)

all: $(BINS)

CFLAGS_page-pool=$(CFLAGS_netdev)

$(BINS): ../lib/ynl.a ../generated/protos.a $(SRCS)
@echo -e '\tCC sample $@'
@$(COMPILE.c) $(CFLAGS_$@) $@.c -o $@.o
Expand Down
2 changes: 1 addition & 1 deletion tools/net/ynl/samples/page-pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int main(int argc, char **argv)
struct stat *s = find_ifc(&a, pp->ifindex);

count(s, 1, pp);
if (pp->_present.destroyed)
if (pp->_present.detach_time)
count(s, 0, pp);
}
netdev_page_pool_get_list_free(pools);
Expand Down
12 changes: 8 additions & 4 deletions tools/net/ynl/ynl-gen-c.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,8 +1164,9 @@ def __init__(self, cw, family, ku_space, op, op_mode, attr_set=None):


class CodeWriter:
def __init__(self, nlib, out_file=None):
def __init__(self, nlib, out_file=None, overwrite=True):
self.nlib = nlib
self._overwrite = overwrite

self._nl = False
self._block_end = False
Expand All @@ -1186,8 +1187,9 @@ def close_out_file(self):
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
if not self._overwrite and os.path.isfile(self._out_file):
if 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)
Expand Down Expand Up @@ -2516,6 +2518,8 @@ def main():
parser.add_argument('--header', dest='header', action='store_true', default=None)
parser.add_argument('--source', dest='header', action='store_false')
parser.add_argument('--user-header', nargs='+', default=[])
parser.add_argument('--cmp-out', action='store_true', default=None,
help='Do not overwrite the output file if the new output is identical to the old')
parser.add_argument('--exclude-op', action='append', default=[])
parser.add_argument('-o', dest='out_file', type=str, default=None)
args = parser.parse_args()
Expand Down Expand Up @@ -2543,7 +2547,7 @@ def main():
print(f'Message enum-model {parsed.msg_id_model} not supported for {args.mode} generation')
os.sys.exit(1)

cw = CodeWriter(BaseNlLib(), args.out_file)
cw = CodeWriter(BaseNlLib(), args.out_file, overwrite=(not args.cmp_out))

_, spec_kernel = find_kernel_root(args.spec)
if args.mode == 'uapi' or args.header:
Expand Down
4 changes: 2 additions & 2 deletions tools/net/ynl/ynl-regen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ for f in $files; do
fi

echo -e "\tGEN ${params[2]}\t$f"
$TOOL --mode ${params[2]} --${params[3]} --spec $KDIR/${params[0]} \
$args -o $f
$TOOL --cmp-out --mode ${params[2]} --${params[3]} \
--spec $KDIR/${params[0]} $args -o $f
done

popd >>/dev/null

0 comments on commit 6afb936

Please sign in to comment.