diff --git a/libpandabase/BUILD.gn b/libpandabase/BUILD.gn index 6b378666c708a684d8832c66cd87249cacb1a3bc..afe52800a6f9ce1784f598ecce606c6bd816a1e4 100644 --- a/libpandabase/BUILD.gn +++ b/libpandabase/BUILD.gn @@ -18,6 +18,7 @@ config("arkbase_public_config") { include_dirs = [ "$ark_root/libpandabase", "$target_gen_dir/include", + "$target_gen_dir/generated", "$target_gen_dir", ] @@ -168,6 +169,18 @@ if (current_cpu == "arm64") { [ "$ark_root/libpandabase/arch/default/cpu_features.cpp" ] } +if (is_mob) { + copy("coherency_line_size_h") { + sources = [ "$ark_root/platforms/mobile/libpandabase/coherency_line_size.h" ] + outputs = [ "$target_gen_dir/generated/coherency_line_size.h" ] + } +} else { + copy("coherency_line_size_h") { + sources = [ "$ark_root/platforms/common/libpandabase/coherency_line_size.h" ] + outputs = [ "$target_gen_dir/generated/coherency_line_size.h" ] + } +} + libarkbase_configs = [ sdk_libc_secshared_config, ":arkbase_public_config", @@ -180,6 +193,7 @@ libarkbase_deps = [ ":generate_version_file", ":logger_enum_gen_h", ":logger_impl_gen_h", + ":coherency_line_size_h", sdk_libc_secshared_dep, ] diff --git a/libpandabase/CMakeLists.txt b/libpandabase/CMakeLists.txt index 88370419ca966f91d68e185c6be793e49776da9b..db8f9c7ad5a2f6c5d3efdebae3f335c0816957b7 100644 --- a/libpandabase/CMakeLists.txt +++ b/libpandabase/CMakeLists.txt @@ -184,11 +184,27 @@ else() message(FATAL_ERROR "Arch ${CMAKE_SYSTEM_PROCESSOR} is not supported") endif() -add_library(arkbase ${PANDA_DEFAULT_LIB_TYPE} ${SOURCES}) - set(GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated) file(MAKE_DIRECTORY ${GENERATED_DIR}) +if(PANDA_TARGET_MOBILE) + set(COHERENCY_LINE_SIZE_H_INPUT "${PANDA_ROOT}/platforms/mobile/libpandabase/coherency_line_size.h") +else() + set(COHERENCY_LINE_SIZE_H_INPUT "${PANDA_ROOT}/platforms/common/libpandabase/coherency_line_size.h") +endif() + +set(COHERENCY_LINE_SIZE_H_OUTPUT "${GENERATED_DIR}/coherency_line_size.h") + +add_custom_command(OUTPUT ${COHERENCY_LINE_SIZE_H_OUTPUT} + COMMAND cmake -E copy ${COHERENCY_LINE_SIZE_H_INPUT} ${COHERENCY_LINE_SIZE_H_OUTPUT} + DEPENDS ${COHERENCY_LINE_SIZE_H_INPUT}) + +add_custom_target(coherency_line_size_h DEPENDS ${COHERENCY_LINE_SIZE_H_OUTPUT}) + +add_library(arkbase ${PANDA_DEFAULT_LIB_TYPE} ${SOURCES}) + +add_dependencies(arkbase coherency_line_size_h) + # Version find_package(Git) if(Git_FOUND) diff --git a/libpandabase/mem/ringbuf/lock_free_ring_buffer.h b/libpandabase/mem/ringbuf/lock_free_ring_buffer.h index 522ed1ead1ca7d05ec1d8e6d333cecfee7514deb..251b1cc9f6a6b8fd0831d93790e983fca946401a 100644 --- a/libpandabase/mem/ringbuf/lock_free_ring_buffer.h +++ b/libpandabase/mem/ringbuf/lock_free_ring_buffer.h @@ -16,11 +16,11 @@ #ifndef PANDA_LIBPANDABASE_MEM_RING_BUF_LOCK_FREE_BUFFER #define PANDA_LIBPANDABASE_MEM_RING_BUF_LOCK_FREE_BUFFER -#include "libpandabase/utils/math_helpers.h" -#include "libpandabase/cpu_features.h" -#include #include #include +#include +#include "coherency_line_size.h" +#include "libpandabase/utils/math_helpers.h" namespace panda::mem { /** @@ -109,9 +109,9 @@ public: } private: - alignas(panda::CACHE_LINE_SIZE) std::atomic tail_index_; + alignas(panda::COHERENCY_LINE_SIZE) std::atomic tail_index_; std::atomic head_index_; - alignas(panda::CACHE_LINE_SIZE) std::array buffer_; + alignas(panda::COHERENCY_LINE_SIZE) std::array buffer_; size_t Increment(size_t n) { diff --git a/platforms/common/libpandabase/coherency_line_size.h b/platforms/common/libpandabase/coherency_line_size.h new file mode 100644 index 0000000000000000000000000000000000000000..c51fa4db16622835fc09d26a1dc619fe42f50069 --- /dev/null +++ b/platforms/common/libpandabase/coherency_line_size.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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. + */ +#ifndef PANDA_COHERENCY_LINE_SIZE_H_ +#define PANDA_COHERENCY_LINE_SIZE_H_ + +#include +#include "libpandabase/cpu_features.h" + +namespace panda { +inline constexpr size_t COHERENCY_LINE_SIZE = CACHE_LINE_SIZE; +} // namespace panda + +#endif // PANDA_COHERENCY_LINE_SIZE_H_ diff --git a/runtime/asm_defines/BUILD.gn b/runtime/asm_defines/BUILD.gn index ab441970a54f422cfc070c0d7eeb0ba19a6af5bb..c619615b5cbec4b51959ad2c4f7152b3630ce00c 100644 --- a/runtime/asm_defines/BUILD.gn +++ b/runtime/asm_defines/BUILD.gn @@ -37,6 +37,7 @@ ohos_static_library("asm_defines") { deps = [ "$ark_root/libpandafile:libarkfile", "$ark_root/runtime:arkruntime_header_deps", + "$ark_root/libpandabase:coherency_line_size_h", sdk_libc_secshared_dep, ] } diff --git a/runtime/asm_defines/CMakeLists.txt b/runtime/asm_defines/CMakeLists.txt index d3bbe2ded70d477b88fee1eaefb1b5b7befacb0e..642e33236933fd549b0c827ec4400ae5fb2d3aef 100644 --- a/runtime/asm_defines/CMakeLists.txt +++ b/runtime/asm_defines/CMakeLists.txt @@ -25,6 +25,7 @@ add_dependencies(asm_defines shorty_values_gen_arkruntime plugins_defines_h plugins_asm_defines_def + coherency_line_size_h ) set(GEN_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/../include")