Skip to content

Commit

Permalink
cache uname syscall invocation (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrDet authored Jun 19, 2024
1 parent 7fb4547 commit a481534
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 1 addition & 3 deletions common/kernel-version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

#include "common/kernel-version.h"

#include <sys/utsname.h>

#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) {
Expand Down
3 changes: 2 additions & 1 deletion common/kernel-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#pragma once

#include <sys/cdefs.h>
#include <sys/utsname.h>

utsname* cached_uname();
int epoll_exclusive_supported();
int madvise_madv_free_supported();

9 changes: 4 additions & 5 deletions runtime/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#undef basename

#include "common/kernel-version.h"
#include "common/macos-ports.h"
#include "common/wrappers/mkdir_recursive.h"

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions server/php-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a481534

Please sign in to comment.