From owner-dev-commits-src-all@freebsd.org Wed Feb 3 06:58:33 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D81A452D6A8; Wed, 3 Feb 2021 06:58:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DVsw95nJdz3hhJ; Wed, 3 Feb 2021 06:58:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AF0441C6D2; Wed, 3 Feb 2021 06:58:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1136wX2g001394; Wed, 3 Feb 2021 06:58:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1136wXVJ001393; Wed, 3 Feb 2021 06:58:33 GMT (envelope-from git) Date: Wed, 3 Feb 2021 06:58:33 GMT Message-Id: <202102030658.1136wXVJ001393@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 32b391d4a99c - stable/12 - stand: lua: enhance lfs.dir() to speed up kernels_autodetect MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 32b391d4a99c8c3a52ea1d2c0c82ee3208b77a19 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Feb 2021 06:58:33 -0000 The branch stable/12 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=32b391d4a99c8c3a52ea1d2c0c82ee3208b77a19 commit 32b391d4a99c8c3a52ea1d2c0c82ee3208b77a19 Author: Kyle Evans AuthorDate: 2021-01-24 01:32:38 +0000 Commit: Kyle Evans CommitDate: 2021-02-03 06:58:18 +0000 stand: lua: enhance lfs.dir() to speed up kernels_autodetect This eliminates a lot of stat() calls that happen when lualoader renders the menu with the default settings, and greatly speeds up rendering on my laptop. ftype is nil if loader/loader.efi hasn't been updated yet, falling back to lfs.attributes() to test. This is technically incompatible with lfs, but not in a particularly terrible way. (cherry picked from commit e25ee296c919d6567aa76058a7049eac974797fb) --- libexec/flua/modules/lfs.c | 28 +++++++++++++++++++++++++++- stand/lua/core.lua | 8 ++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/libexec/flua/modules/lfs.c b/libexec/flua/modules/lfs.c index 52a30c1515a9..e36c78d3b35b 100644 --- a/libexec/flua/modules/lfs.c +++ b/libexec/flua/modules/lfs.c @@ -122,6 +122,27 @@ __FBSDID("$FreeBSD$"); #define DIR_METATABLE "directory iterator metatable" +static int +lua_dir_iter_pushtype(lua_State *L __unused, const struct dirent *ent __unused) +{ + + /* + * This is a non-standard extension to luafilesystem for loader's + * benefit. The extra stat() calls to determine the entry type can + * be quite expensive on some systems, so this speeds up enumeration of + * /boot greatly by providing the type up front. + * + * This extension is compatible enough with luafilesystem, in that we're + * just using an extra return value for the iterator. + */ +#ifdef _STANDALONE + lua_pushinteger(L, ent->d_type); + return 1; +#else + return 0; +#endif +} + static int lua_dir_iter_next(lua_State *L) { @@ -144,7 +165,7 @@ lua_dir_iter_next(lua_State *L) } lua_pushstring(L, entry->d_name); - return 1; + return 1 + lua_dir_iter_pushtype(L, entry); } static int @@ -420,5 +441,10 @@ luaopen_lfs(lua_State *L) { register_metatable(L); luaL_newlib(L, fslib); +#ifdef _STANDALONE + /* Non-standard extension for loader, used with lfs.dir(). */ + lua_pushinteger(L, DT_DIR); + lua_setfield(L, -2, "DT_DIR"); +#endif return 1; } diff --git a/stand/lua/core.lua b/stand/lua/core.lua index ad9a3e353fd1..7f6b809761c4 100644 --- a/stand/lua/core.lua +++ b/stand/lua/core.lua @@ -238,14 +238,18 @@ function core.kernelList() -- Automatically detect other bootable kernel directories using a -- heuristic. Any directory in /boot that contains an ordinary file -- named "kernel" is considered eligible. - for file in lfs.dir("/boot") do + for file, ftype in lfs.dir("/boot") do local fname = "/boot/" .. file if file == "." or file == ".." then goto continue end - if lfs.attributes(fname, "mode") ~= "directory" then + if ftype then + if ftype ~= lfs.DT_DIR then + goto continue + end + elseif lfs.attributes(fname, "mode") ~= "directory" then goto continue end