diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-04-11 18:15:04 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-04-11 18:15:04 +0000 |
commit | f8f0e2a3793d76e9c6798edf2f6768e750655211 (patch) | |
tree | d2614232e1771745d8911c0d27e3a64f8af63c96 | |
parent | 6625b8d7b825960f3cbadfdc712385552d824458 (diff) | |
parent | 5b466f8d01b2d1d91885e1be2e2c621cce4d358e (diff) | |
download | aemu-emu-34-2-release.tar.gz |
Snap for 11702928 from 5b466f8d01b2d1d91885e1be2e2c621cce4d358e to emu-34-2-releaseemu-34-2-release
Change-Id: I4c9a0a08f835d88ca85589c49113aac7c4ef5afe
-rw-r--r-- | base/CMakeLists.txt | 3 | ||||
-rw-r--r-- | base/HybridEntityManager_unittest.cpp | 45 | ||||
-rw-r--r-- | base/include/aemu/base/containers/HybridEntityManager.h | 19 | ||||
-rw-r--r-- | base/include/aemu/base/synchronization/Lock.h | 4 | ||||
-rw-r--r-- | host-common/include/host-common/misc.h | 2 | ||||
-rw-r--r-- | host-common/misc.cpp | 11 |
6 files changed, 64 insertions, 20 deletions
diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index 1c97220..5af7d98 100644 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -150,7 +150,8 @@ if (ENABLE_VKCEREAL_TESTS) StringFormat_unittest.cpp SubAllocator_unittest.cpp TypeTraits_unittest.cpp - WorkerThread_unittest.cpp) + WorkerThread_unittest.cpp + HybridEntityManager_unittest.cpp) endif() add_executable(aemu-base_unittests ${aemu-base-test-srcs}) target_link_libraries( diff --git a/base/HybridEntityManager_unittest.cpp b/base/HybridEntityManager_unittest.cpp new file mode 100644 index 0000000..cc67dc7 --- /dev/null +++ b/base/HybridEntityManager_unittest.cpp @@ -0,0 +1,45 @@ +// Copyright (C) 2024 The Android Open Source Project +// +// 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 "aemu/base/containers/HybridEntityManager.h" + +#include <gtest/gtest.h> + +namespace android { +namespace base { + +static constexpr uint32_t kTestMaxIndex = 16; +using TestHCM = HybridEntityManager<kTestMaxIndex, uint64_t, int>; + +TEST(HybridEntityManager, UpdateIndex) { + TestHCM m; + // Occupy all linear entries. + for (uint32_t i = 0; i < kTestMaxIndex; i++) { + m.add(i, 1); + } + int indices[4]; + indices[0] = m.addFixed(kTestMaxIndex, 0, 1); + indices[1] = m.add(100, 1); + indices[2] = m.add(2, 1); + m.remove(indices[1]); + m.addFixed(indices[1], 1, 1); + // Verify it doesn't overwrite old entries. + indices[3] = m.add(3, 1); + EXPECT_EQ(0, *m.get_const(indices[0])); + EXPECT_EQ(1, *m.get_const(indices[1])); + EXPECT_EQ(2, *m.get_const(indices[2])); + EXPECT_EQ(3, *m.get_const(indices[3])); +} + +} +}
\ No newline at end of file diff --git a/base/include/aemu/base/containers/HybridEntityManager.h b/base/include/aemu/base/containers/HybridEntityManager.h index dab8914..c5a0c5a 100644 --- a/base/include/aemu/base/containers/HybridEntityManager.h +++ b/base/include/aemu/base/containers/HybridEntityManager.h @@ -57,7 +57,12 @@ public: mIndexForMap = maxIndex; } nextIndex = mIndexForMap; - mMap[nextIndex] = data; + auto emplaced = mMap.emplace(nextIndex, data); + if (!emplaced.second) { + fprintf(stderr, "%s: fatal: trying to insert duplicated entry 0x%llx\n", __func__, + (unsigned long long)nextIndex); + abort(); + } ++mIndexForMap; return EM::makeHandle(nextIndex, 1, type); } @@ -70,11 +75,13 @@ public: } else { AutoLock lock(mMapLock); // Fixed allocations require us to update mIndexForMap to catch up with it. - // We assume that addFixed/add for the map case do not interleave badly - // (addFixed at i, add at i+1, addFixed at i+1) - mIndexForMap = index_u64; - mMap[index_u64] = data; - ++mIndexForMap; + mIndexForMap = std::max(index_u64 + 1, mIndexForMap); + auto emplaced = mMap.emplace(index_u64, data); + if (!emplaced.second) { + fprintf(stderr, "%s: fatal: trying to insert duplicated entry 0x%llx\n", __func__, + (unsigned long long)index_u64); + abort(); + } return index; } } diff --git a/base/include/aemu/base/synchronization/Lock.h b/base/include/aemu/base/synchronization/Lock.h index 2b88f05..281a970 100644 --- a/base/include/aemu/base/synchronization/Lock.h +++ b/base/include/aemu/base/synchronization/Lock.h @@ -237,6 +237,8 @@ static inline __attribute__((always_inline)) void SmpWmb() { asm volatile("dmb ishst" ::: "memory"); #elif defined(__x86_64__) std::atomic_thread_fence(std::memory_order_release); +#elif defined(__riscv) && (__riscv_xlen == 64) + std::atomic_thread_fence(std::memory_order_release); #else #error "Unimplemented SmpWmb for current CPU architecture" #endif @@ -247,6 +249,8 @@ static inline __attribute__((always_inline)) void SmpRmb() { asm volatile("dmb ishld" ::: "memory"); #elif defined(__x86_64__) std::atomic_thread_fence(std::memory_order_acquire); +#elif defined(__riscv) && (__riscv_xlen == 64) + std::atomic_thread_fence(std::memory_order_acquire); #else #error "Unimplemented SmpRmb for current CPU architecture" #endif diff --git a/host-common/include/host-common/misc.h b/host-common/include/host-common/misc.h index 17e3c05..eaa41f5 100644 --- a/host-common/include/host-common/misc.h +++ b/host-common/include/host-common/misc.h @@ -52,8 +52,6 @@ namespace emugl { EMUGL_COMMON_API void setAvdInfo(bool isPhone, int apiLevel); EMUGL_COMMON_API void getAvdInfo(bool* isPhone, int* apiLevel); - EMUGL_COMMON_API void setShouldSkipDraw(bool skip); - EMUGL_COMMON_API bool shouldSkipDraw(); // CPU usage get/set. EMUGL_COMMON_API void setCpuUsage(android::base::CpuUsage* usage); EMUGL_COMMON_API android::base::CpuUsage* getCpuUsage(); diff --git a/host-common/misc.cpp b/host-common/misc.cpp index ecd3294..ec7a085 100644 --- a/host-common/misc.cpp +++ b/host-common/misc.cpp @@ -21,8 +21,6 @@ static int s_apiLevel = -1; static bool s_isPhone = false; -static bool s_shouldSkipDrawing = false; - android::base::CpuUsage* s_cpu_usage = nullptr; android::base::MemoryTracker* s_mem_usage = nullptr; @@ -31,15 +29,6 @@ void emugl::setAvdInfo(bool phone, int apiLevel) { s_apiLevel = apiLevel; } -bool emugl::shouldSkipDraw() { - return s_shouldSkipDrawing; -} - - -void emugl::setShouldSkipDraw(bool skip) { - s_shouldSkipDrawing = skip; -} - void emugl::getAvdInfo(bool* phone, int* apiLevel) { if (phone) *phone = s_isPhone; if (apiLevel) *apiLevel = s_apiLevel; |