From a48153485dc5e29c1d646d2167d85f6953acc718 Mon Sep 17 00:00:00 2001 From: Denis Vaksman Date: Wed, 19 Jun 2024 17:48:04 +0300 Subject: [PATCH] cache uname syscall invocation (#1020) --- common/kernel-version.cpp | 4 +--- common/kernel-version.h | 3 ++- runtime/files.cpp | 9 ++++----- server/php-engine.cpp | 2 ++ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/common/kernel-version.cpp b/common/kernel-version.cpp index a9aa1accaa..c6173c7034 100644 --- a/common/kernel-version.cpp +++ b/common/kernel-version.cpp @@ -4,12 +4,10 @@ #include "common/kernel-version.h" -#include - #include "common/kprintf.h" #include "common/stats/provider.h" -static struct utsname* cached_uname() { +utsname* cached_uname() { static struct utsname kernel_version; static int got_kernel_version = 0; if (got_kernel_version == 0) { diff --git a/common/kernel-version.h b/common/kernel-version.h index 48012169b8..754c60f68c 100644 --- a/common/kernel-version.h +++ b/common/kernel-version.h @@ -5,7 +5,8 @@ #pragma once #include +#include +utsname* cached_uname(); int epoll_exclusive_supported(); int madvise_madv_free_supported(); - diff --git a/runtime/files.cpp b/runtime/files.cpp index e695734553..01f38ffa83 100644 --- a/runtime/files.cpp +++ b/runtime/files.cpp @@ -13,6 +13,7 @@ #undef basename +#include "common/kernel-version.h" #include "common/macos-ports.h" #include "common/wrappers/mkdir_recursive.h" @@ -361,13 +362,11 @@ bool f$mkdir(const string &name, int64_t mode, bool recursive) { } string f$php_uname(const string &name) { - utsname res; - dl::enter_critical_section();//OK - if (uname(&res)) { - dl::leave_critical_section(); + const auto *uname = cached_uname(); + if (uname == nullptr) { return {}; } - dl::leave_critical_section(); + const auto &res = *uname; char mode = name[0]; switch (mode) { diff --git a/server/php-engine.cpp b/server/php-engine.cpp index 3c2a1da794..61d1ce3bf1 100644 --- a/server/php-engine.cpp +++ b/server/php-engine.cpp @@ -26,6 +26,7 @@ #include "common/crc32c.h" #include "common/cycleclock.h" #include "common/dl-utils-lite.h" +#include "common/kernel-version.h" #include "common/kprintf.h" #include "common/macos-ports.h" #include "common/options.h" @@ -1667,6 +1668,7 @@ void init_all() { log_server_warning(deprecation_warning); } StatsHouseManager::get().set_common_tags(); + cached_uname(); // invoke uname syscall only once on master start global_init_runtime_libs(); init_php_scripts_once_in_master();