From de6bf577fafabb2930ecc6b7a98eb8ad461bd49d Mon Sep 17 00:00:00 2001 From: Bob Chen Date: Wed, 25 Sep 2024 13:34:22 +0800 Subject: [PATCH] Fix getpagesize() when first used --- include/photon/thread/arch.h | 1 + thread/arch.cpp | 23 +++++++++++++++++++++++ thread/arch.h | 26 ++++++++++++++++++++++++++ thread/stack-allocator.cpp | 3 +-- thread/thread.cpp | 11 +++++++---- 5 files changed, 58 insertions(+), 6 deletions(-) create mode 120000 include/photon/thread/arch.h create mode 100644 thread/arch.cpp create mode 100644 thread/arch.h diff --git a/include/photon/thread/arch.h b/include/photon/thread/arch.h new file mode 120000 index 00000000..657ef9aa --- /dev/null +++ b/include/photon/thread/arch.h @@ -0,0 +1 @@ +../../../thread/arch.h \ No newline at end of file diff --git a/thread/arch.cpp b/thread/arch.cpp new file mode 100644 index 00000000..10c4faaf --- /dev/null +++ b/thread/arch.cpp @@ -0,0 +1,23 @@ +/* +Copyright 2022 The Photon Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include "arch.h" + +namespace photon { + +uint32_t PAGE_SIZE = 0; + +} \ No newline at end of file diff --git a/thread/arch.h b/thread/arch.h new file mode 100644 index 00000000..67a8bb0d --- /dev/null +++ b/thread/arch.h @@ -0,0 +1,26 @@ +/* +Copyright 2022 The Photon Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +#include + +namespace photon { + +// Only available after photon::init() or photon::vcpu_init() +extern uint32_t PAGE_SIZE; + +} \ No newline at end of file diff --git a/thread/stack-allocator.cpp b/thread/stack-allocator.cpp index ccc07d5a..6992e97f 100644 --- a/thread/stack-allocator.cpp +++ b/thread/stack-allocator.cpp @@ -20,6 +20,7 @@ limitations under the License. #include #include #include +#include #include #include #include @@ -28,8 +29,6 @@ limitations under the License. namespace photon { -const static size_t PAGE_SIZE = getpagesize(); - template class PooledStackAllocator { diff --git a/thread/thread.cpp b/thread/thread.cpp index 67fd3e53..5541e496 100644 --- a/thread/thread.cpp +++ b/thread/thread.cpp @@ -51,6 +51,7 @@ inline int posix_memalign(void** memptr, size_t alignment, size_t size) { #include #include #include +#include /* notes on the scheduler: @@ -86,8 +87,6 @@ inline int posix_memalign(void** memptr, size_t alignment, size_t size) { #name": " #endif -static const size_t PAGE_SIZE = getpagesize(); - namespace photon { inline uint64_t min(uint64_t a, uint64_t b) { return (a