[RESTRICT AUTOMERGE] Remove libsync usages
libsync depends on <debugfs>/sync/sw_sync to create the sync timeline.
However, because debugfs is not available on the production build,
libsync must be used only for a debugging.
This change therefore removes libsync usages from EVS manager's frame
delivery mechanism and rewrites the synchronization with a mutex and a
conditional variable.
Bug: 174580577
Test: vts-tradefed run commandAndExit vts-hal-auto
--skip-all-system-status-check
--primary-abi-only
--skip-preconditions
-m VtsHalEvsV1_1Target --test EvsHidlTest#CameraOpenClean
Change-Id: If51d5367f8e834106612e591f644d3804fe6ea87
diff --git a/evs/manager/1.1/Android.bp b/evs/manager/1.1/Android.bp
index d9c7d33..8fc47a4 100644
--- a/evs/manager/1.1/Android.bp
+++ b/evs/manager/1.1/Android.bp
@@ -25,9 +25,6 @@
"stats/CameraUsageStats.cpp",
"stats/LooperWrapper.cpp",
"stats/StatsCollector.cpp",
- "sync/unique_fd.cpp",
- "sync/unique_fence.cpp",
- "sync/unique_timeline.cpp",
],
shared_libs: [
@@ -40,7 +37,6 @@
"libhidlbase",
"libprocessgroup",
"libstatslog",
- "libsync",
"libui",
"libutils",
],
@@ -54,14 +50,9 @@
"-Wthread-safety",
],
- include_dirs: [
- "system/core/libsync",
- ],
-
export_include_dirs: [
"./",
"stats/",
- "sync/",
],
product_variables: {
@@ -87,9 +78,6 @@
"stats/CameraUsageStats.cpp",
"stats/LooperWrapper.cpp",
"stats/StatsCollector.cpp",
- "sync/unique_fd.cpp",
- "sync/unique_fence.cpp",
- "sync/unique_timeline.cpp",
],
shared_libs: [
@@ -102,7 +90,6 @@
"libhidlbase",
"libprocessgroup",
"libstatslog",
- "libsync",
"libui",
"libutils",
],
@@ -110,8 +97,6 @@
init_rc: ["android.automotive.evs.manager@1.1.rc"],
cflags: ["-DLOG_TAG=\"EvsManagerV1_1\""] + [
- "-DGL_GLEXT_PROTOTYPES",
- "-DEGL_EGLEXT_PROTOTYPES",
"-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
"-Wall",
"-Werror",
@@ -120,10 +105,6 @@
"-Wthread-safety",
],
- include_dirs: [
- "system/core/libsync",
- ],
-
product_variables: {
debuggable: {
cflags: [
diff --git a/evs/manager/1.1/Enumerator.cpp b/evs/manager/1.1/Enumerator.cpp
index 61cfec9..f733803 100644
--- a/evs/manager/1.1/Enumerator.cpp
+++ b/evs/manager/1.1/Enumerator.cpp
@@ -343,13 +343,6 @@
mHwEnumerator->closeCamera(device);
success = false;
break;
- } else if (!hwCamera->isSyncSupported()) {
- LOG(INFO) << id << " does not support a sw_sync.";
- if (physicalCameras.size() > 1) {
- LOG(ERROR) << "sw_sync is required for logical camera devices.";
- success = false;
- break;
- }
}
}
diff --git a/evs/manager/1.1/HalCamera.cpp b/evs/manager/1.1/HalCamera.cpp
index f4d2c49..e08599f 100644
--- a/evs/manager/1.1/HalCamera.cpp
+++ b/evs/manager/1.1/HalCamera.cpp
@@ -77,19 +77,6 @@
return false;
}
- if (mSyncSupported) {
- // Create a timeline
- std::lock_guard<std::mutex> lock(mFrameMutex);
- auto timeline = make_unique<UniqueTimeline>(0);
- if (timeline != nullptr) {
- mTimelines[(uint64_t)virtualCamera.get()] = std::move(timeline);
- } else {
- LOG(WARNING) << "Failed to create a timeline. "
- << "Client " << std::hex << virtualCamera.get()
- << " will use v1.0 frame delivery mechanism.";
- }
- }
-
// Add this virtualCamera to our ownership list via weak pointer
mClients.emplace_back(virtualCamera);
@@ -220,34 +207,14 @@
}
-UniqueFence HalCamera::requestNewFrame(sp<VirtualCamera> client,
- const int64_t lastTimestamp) {
- if (!mSyncSupported) {
- LOG(ERROR) << "This HalCamera does not support a fence-based "
- << "frame delivery.";
- return {};
- }
-
+void HalCamera::requestNewFrame(sp<VirtualCamera> client,
+ const int64_t lastTimestamp) {
FrameRequest req;
req.client = client;
req.timestamp = lastTimestamp;
- const uint64_t id = (uint64_t)client.get();
-
std::lock_guard<std::mutex> lock(mFrameMutex);
-
- if (mTimelines.find(id) == mTimelines.end()) {
- // Timeline for this client either does not exist or is deleted.
- LOG(ERROR) << "Timeline for this client does not exist.";
- return {};
- }
-
- mTimelines[id]->BumpFenceEventCounter();
- UniqueFence fence = mTimelines[id]->CreateFence("FrameFence");
-
mNextRequests->push_back(req);
-
- return fence.Dup();
}
@@ -275,15 +242,8 @@
}
}
- const uint64_t clientId = reinterpret_cast<const uint64_t>(client);
if (itReq != mNextRequests->end()) {
mNextRequests->erase(itReq);
-
- // Signal a pending fence and delete associated timeline.
- if (mTimelines.find(clientId) != mTimelines.end()) {
- mTimelines[clientId]->BumpTimelineEventCounter();
- mTimelines.erase(clientId);
- }
}
auto itCam = mClients.begin();
@@ -399,7 +359,8 @@
// but this must be derived from current framerate.
constexpr int64_t kThreshold = 16 * 1e+3; // ms
unsigned frameDeliveriesV1 = 0;
- if (mSyncSupported) {
+ {
+ // Handle frame requests from v1.1 clients
std::lock_guard<std::mutex> lock(mFrameMutex);
std::swap(mCurrentRequests, mNextRequests);
while (!mCurrentRequests->empty()) {
@@ -418,7 +379,6 @@
} else if (vCam != nullptr && vCam->deliverFrame(buffer[0])) {
// Forward a frame and move a timeline.
LOG(DEBUG) << getId() << " forwarded the buffer #" << buffer[0].bufferId;
- mTimelines[(uint64_t)vCam.get()]->BumpTimelineEventCounter();
++frameDeliveriesV1;
}
}
@@ -432,7 +392,7 @@
unsigned frameDeliveries = 0;
for (auto&& client : mClients) {
sp<VirtualCamera> vCam = client.promote();
- if (vCam == nullptr || (mSyncSupported && vCam->getVersion() > 0)) {
+ if (vCam == nullptr || vCam->getVersion() > 0) {
continue;
}
@@ -630,10 +590,8 @@
buffer += handle->toString(double_indent.c_str());
}
- StringAppendF(&buffer, "%sMaster client: %p\n"
- "%sSynchronization support: %s\n",
- indent, mMaster.promote().get(),
- indent, mSyncSupported ? "T":"F");
+ StringAppendF(&buffer, "%sMaster client: %p\n",
+ indent, mMaster.promote().get());
buffer += HalCamera::toString(mStreamConfig, indent);
diff --git a/evs/manager/1.1/HalCamera.h b/evs/manager/1.1/HalCamera.h
index efc5c25..2f707ff 100644
--- a/evs/manager/1.1/HalCamera.h
+++ b/evs/manager/1.1/HalCamera.h
@@ -18,9 +18,6 @@
#define ANDROID_AUTOMOTIVE_EVS_V1_1_HALCAMERA_H
#include "stats/CameraUsageStats.h"
-#include "sync/unique_fd.h"
-#include "sync/unique_fence.h"
-#include "sync/unique_timeline.h"
#include <deque>
#include <list>
@@ -68,7 +65,6 @@
: mHwCamera(hwCamera),
mId(deviceId),
mStreamConfig(cfg),
- mSyncSupported(UniqueTimeline::Supported()),
mTimeCreatedMs(android::uptimeMillis()),
mUsageStats(new CameraUsageStats(recordId)) {
mCurrentRequests = &mFrameRequests[0];
@@ -90,7 +86,7 @@
bool changeFramesInFlight(int delta);
bool changeFramesInFlight(const hardware::hidl_vec<BufferDesc_1_1>& buffers,
int* delta);
- UniqueFence requestNewFrame(sp<VirtualCamera> virtualCamera,
+ void requestNewFrame(sp<VirtualCamera> virtualCamera,
const int64_t timestamp);
Return<EvsResult> clientStreamStarting();
@@ -103,7 +99,6 @@
Return<EvsResult> setParameter(sp<VirtualCamera> virtualCamera,
CameraParam id, int32_t& value);
Return<EvsResult> getParameter(CameraParam id, int32_t& value);
- bool isSyncSupported() const { return mSyncSupported; }
// Returns a snapshot of collected usage statistics
CameraUsageStatsRecord getStats() const;
@@ -154,9 +149,6 @@
std::deque<FrameRequest> mFrameRequests[2] GUARDED_BY(mFrameMutex);
std::deque<FrameRequest>* mCurrentRequests PT_GUARDED_BY(mFrameMutex);
std::deque<FrameRequest>* mNextRequests PT_GUARDED_BY(mFrameMutex);
- std::unordered_map<uint64_t,
- std::unique_ptr<UniqueTimeline>> mTimelines GUARDED_BY(mFrameMutex);
- bool mSyncSupported;
// Time this object was created
int64_t mTimeCreatedMs;
diff --git a/evs/manager/1.1/VirtualCamera.cpp b/evs/manager/1.1/VirtualCamera.cpp
index fda58d1..34530d8 100644
--- a/evs/manager/1.1/VirtualCamera.cpp
+++ b/evs/manager/1.1/VirtualCamera.cpp
@@ -152,9 +152,8 @@
frame_1_0.bufferId = bufDesc.bufferId;
mStream->deliverFrame(frame_1_0);
- } else if (!mCaptureThread.joinable()) {
- // A capture thread does not run only it failed to create a
- // timeline.
+ } else if (mCaptureThread.joinable()) {
+ // Keep forwarding frames as long as a capture thread is alive
if (mFramesHeld.size() > 0 && mStream_1_1 != nullptr) {
// Pass this buffer through to our client
hardware::hidl_vec<BufferDesc_1_1> frames;
@@ -164,7 +163,12 @@
frames[0] = mFramesHeld[mHalCamera.begin()->first].back();
}
- mStream_1_1->deliverFrame_1_1(frames);
+ // Notify a new frame receipt
+ {
+ std::lock_guard<std::mutex> lock(mFrameDeliveryMutex);
+ mSourceCameras.erase(bufDesc.deviceId);
+ }
+ mFramesReadySignal.notify_all();
}
}
@@ -342,18 +346,14 @@
// Start a thread that waits on the fence and forwards collected frames
// to the v1.1 client.
- // If the system does not support a sw sync, EVS does not support a logical
- // camera device and, therefore, VirtualCamera will subscribe only to a
- // single hw camera.
auto pHwCamera = mHalCamera.begin()->second.promote();
- if (mStream_1_1 != nullptr && pHwCamera != nullptr && pHwCamera->isSyncSupported()) {
+ if (mStream_1_1 != nullptr && pHwCamera != nullptr) {
mCaptureThread = std::thread([this]() {
// TODO(b/145466570): With a proper camera hang handler, we may want
// to reduce an amount of timeout.
- constexpr int kFrameTimeoutMs = 5000; // timeout in ms.
+ constexpr auto kFrameTimeout = 5s; // timeout in seconds.
int64_t lastFrameTimestamp = -1;
while (mStreamState == RUNNING) {
- UniqueFence fence;
unsigned count = 0;
for (auto&& [key, hwCamera] : mHalCamera) {
auto pHwCamera = hwCamera.promote();
@@ -362,21 +362,20 @@
continue;
}
- UniqueFence another = pHwCamera->requestNewFrame(this, lastFrameTimestamp);
- if (!another) {
- LOG(WARNING) << key << " returned an invalid fence.";
- continue;
+ pHwCamera->requestNewFrame(this, lastFrameTimestamp);
+ {
+ std::lock_guard<std::mutex> lock(mFrameDeliveryMutex);
+ mSourceCameras.emplace(pHwCamera->getId());
}
-
- fence = UniqueFence::Merge("MergedFrameFence",
- fence,
- another);
++count;
}
- if (fence.Wait(kFrameTimeoutMs) < 0) {
- // TODO(b/145466570): Replace this temporarily camera hang
- // handler.
+ std::unique_lock<std::mutex> lock(mFrameDeliveryMutex);
+ if (!mFramesReadySignal.wait_for(lock,
+ kFrameTimeout,
+ [this]() REQUIRES(mFrameDeliveryMutex) {
+ return mSourceCameras.empty();
+ })) {
PLOG(ERROR) << this << ": Camera hangs?";
break;
} else if (mStreamState == RUNNING) {
@@ -398,7 +397,11 @@
}
frames[i++] = frame;
}
- mStream_1_1->deliverFrame_1_1(frames);
+
+ auto ret = mStream_1_1->deliverFrame_1_1(frames);
+ if (!ret.isOk()) {
+ LOG(WARNING) << "Failed to forward frames";
+ }
}
}
}
diff --git a/evs/manager/1.1/VirtualCamera.h b/evs/manager/1.1/VirtualCamera.h
index 76a8648..0dbd97d 100644
--- a/evs/manager/1.1/VirtualCamera.h
+++ b/evs/manager/1.1/VirtualCamera.h
@@ -22,10 +22,13 @@
#include <android/hardware/automotive/evs/1.1/IEvsCameraStream.h>
#include <android/hardware/automotive/evs/1.1/IEvsDisplay.h>
-#include <thread>
#include <deque>
+#include <set>
+#include <thread>
#include <unordered_map>
+#include <utils/Mutex.h>
+
using namespace std;
using namespace ::android::hardware::automotive::evs::V1_1;
@@ -132,6 +135,11 @@
deque<BufferDesc_1_1>> mFramesHeld;
thread mCaptureThread;
CameraDesc* mDesc;
+
+ mutable std::mutex mFrameDeliveryMutex;
+ std::condition_variable mFramesReadySignal;
+ std::set<std::string> mSourceCameras GUARDED_BY(mFrameDeliveryMutex);
+
};
} // namespace implementation
diff --git a/evs/manager/1.1/sync/unique_fd.cpp b/evs/manager/1.1/sync/unique_fd.cpp
deleted file mode 100644
index eb5bb63..0000000
--- a/evs/manager/1.1/sync/unique_fd.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2016 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 "unique_fd.h"
-
-#include <errno.h>
-#include <string.h>
-
-#include <android-base/logging.h>
-
-namespace android {
-namespace automotive {
-namespace evs {
-namespace V1_1 {
-namespace implementation {
-
-UniqueFd::UniqueFd() : fd_(-1) {}
-
-UniqueFd::UniqueFd(int fd) : fd_(fd) {
-}
-
-UniqueFd::~UniqueFd() {
- InternalClose();
-}
-
-UniqueFd::UniqueFd(UniqueFd&& other) : fd_(other.fd_) {
- other.fd_ = -1;
-}
-
-UniqueFd& UniqueFd::operator=(UniqueFd&& other) {
- InternalClose();
- fd_ = other.fd_;
- other.fd_ = -1;
- return *this;
-}
-
-void UniqueFd::Reset(int new_fd) {
- InternalClose();
- fd_ = new_fd;
-}
-
-UniqueFd UniqueFd::Dup() const {
- return (fd_ >= 0) ? UniqueFd(InternalDup()) : UniqueFd(fd_);
-}
-
-UniqueFd::operator bool() const {
- return fd_ >= 0;
-}
-
-int UniqueFd::Get() const {
- return fd_;
-}
-
-int UniqueFd::GetUnowned() const {
- return InternalDup();
-}
-
-int UniqueFd::Release() {
- int ret = fd_;
- fd_ = -1;
- return ret;
-}
-
-void UniqueFd::InternalClose() {
- if (fd_ >= 0) {
- int err = close(fd_);
- if (err < 0) {
- PLOG(FATAL) << "Error closing UniqueFd";
- }
- }
- fd_ = -1;
-}
-
-int UniqueFd::InternalDup() const {
- int new_fd = fd_ >= 0 ? dup(fd_) : fd_;
- if (new_fd < 0 && fd_ >= 0) {
- PLOG(FATAL) << "Error duplicating UniqueFd";
- }
- return new_fd;
-}
-
-} // namespace implementation
-} // namespace V1_1
-} // namespace evs
-} // namespace automotive
-} // namespace android
diff --git a/evs/manager/1.1/sync/unique_fd.h b/evs/manager/1.1/sync/unique_fd.h
deleted file mode 100644
index 204a5fc..0000000
--- a/evs/manager/1.1/sync/unique_fd.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2016 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.
- */
-
-#pragma once
-
-namespace android {
-namespace automotive {
-namespace evs {
-namespace V1_1 {
-namespace implementation {
-
-// This is a simple C++ wrapper around a POSIX file descriptor. It is meant to
-// enforce ownership just like unique_ptr<T>
-//
-// Instances of this type cannot be copied, but they can be moved.
-class UniqueFd {
-public:
- UniqueFd();
- explicit UniqueFd(int fd);
- ~UniqueFd();
- UniqueFd(UniqueFd&&);
- UniqueFd& operator=(UniqueFd&&);
-
- // Destroy the current descriptor, and take ownership of a new one.
- void Reset(int new_fd = -1);
-
- // Duplicate the current descriptor.
- UniqueFd Dup() const;
-
- // Returns true if the descriptor is valid. False otherwise.
- explicit operator bool() const;
-
- // Gets the descriptor
- int Get() const;
-
- // Gets a unowned duplicate of the descriptor. The caller is responsible for
- // closing it.
- int GetUnowned() const;
-
- // Gets the descriptor and releases ownership. The caller is responsible for
- // closing it.
- int Release();
-
-private:
- UniqueFd(const UniqueFd&) = delete;
- UniqueFd& operator=(const UniqueFd&) = delete;
-
- void InternalClose();
- int InternalDup() const;
-
- int fd_;
-};
-
-} // namespace implementation
-} // namespace V1_1
-} // namespace evs
-} // namespace automotive
-} // namespace android
-
diff --git a/evs/manager/1.1/sync/unique_fence.cpp b/evs/manager/1.1/sync/unique_fence.cpp
deleted file mode 100644
index 7aaa9f4..0000000
--- a/evs/manager/1.1/sync/unique_fence.cpp
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright (C) 2016 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 "unique_fence.h"
-
-#include <errno.h>
-#include <cinttypes>
-#include <cstring>
-#include <memory>
-#include <string>
-
-#include <android-base/logging.h>
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wzero-length-array"
-#endif // __clang__
-#include <sync/sync.h>
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif // __clang__
-#include <utils/String8.h>
-
-
-constexpr int kWarningTimeout = 2000;
-
-namespace android {
-namespace automotive {
-namespace evs {
-namespace V1_1 {
-namespace implementation {
-
-namespace {
-
-const char* GetStatusString(int status) {
- if (status == 0) {
- return "active";
- } else if (status == 1) {
- return "signaled";
- } else {
- return "error";
- }
-}
-
-} // namespace
-
-UniqueFence::UniqueFence() {}
-
-UniqueFence::UniqueFence(int fd) : fd_(fd) {}
-
-UniqueFence::UniqueFence(UniqueFence&& other) = default;
-UniqueFence& UniqueFence::operator=(UniqueFence&& other) = default;
-
-void UniqueFence::Reset() {
- fd_.Reset();
-}
-
-UniqueFence UniqueFence::Dup() const {
- return UniqueFence(fd_.GetUnowned());
-}
-
-int UniqueFence::Get() const {
- return fd_.Get();
-}
-
-int UniqueFence::GetUnowned() const {
- return fd_.GetUnowned();
-}
-
-UniqueFence::operator bool() const {
- return static_cast<bool>(fd_);
-}
-
-void UniqueFence::GetDebugStateDump(String8& result) const {
- constexpr int INDENT = 8;
- struct sync_file_info* finfo = sync_file_info(fd_.Get());
- if (finfo == nullptr) {
- result.append("no debug info available");
- return;
- }
- result.appendFormat("name: %s status: %d (%s)", finfo->name, finfo->status,
- GetStatusString(finfo->status));
-
- struct sync_fence_info* pinfo = sync_get_fence_info(finfo);
- for (uint32_t i = 0; i < finfo->num_fences; i++) {
- result.appendFormat("\n%*spt %u driver: %s obj: %s: status: %d(%s) timestamp: %llu", INDENT,
- "", i, pinfo[i].driver_name, pinfo[i].obj_name, pinfo[i].status,
- GetStatusString(pinfo[i].status), pinfo[i].timestamp_ns);
- }
- sync_file_info_free(finfo);
-}
-
-int UniqueFence::Wait(int wait_time_ms) {
- if (wait_time_ms == -1) {
- int err = sync_wait(fd_.Get(), kWarningTimeout);
- if (err >= 0 || errno != ETIME) return err;
-
- String8 dump;
- GetDebugStateDump(dump);
- LOG(WARNING) << "Waited on fence " << fd_.Get()
- << " for " << kWarningTimeout << " ms. " << dump.string();
- }
- return sync_wait(fd_.Get(), wait_time_ms);
-}
-
-UniqueFence UniqueFence::Merge(const char* name, const UniqueFence& fence1,
- const UniqueFence& fence2) {
- UniqueFence merged_fence;
- if (fence1.fd_ || fence2.fd_) {
- if (fence1.fd_ && fence2.fd_) {
- merged_fence.fd_.Reset(sync_merge(name, fence1.fd_.Get(), fence2.fd_.Get()));
- } else if (fence1.fd_) {
- // We merge the fence with itself so that we always generate a fence with
- // a new name.
- merged_fence.fd_.Reset(sync_merge(name, fence1.fd_.Get(), fence1.fd_.Get()));
- } else if (fence2.fd_) {
- // We merge the fence with itself so that we always generate a fence with
- // a new name.
- merged_fence.fd_.Reset(sync_merge(name, fence2.fd_.Get(), fence2.fd_.Get()));
- }
-
- if (!merged_fence.fd_) {
- PLOG(ERROR) << "Failed to merge fences";
- }
- }
- return merged_fence;
-}
-
-} // namespace implementation
-} // namespace V1_1
-} // namespace evs
-} // namespace automotive
-} // namespace android
diff --git a/evs/manager/1.1/sync/unique_fence.h b/evs/manager/1.1/sync/unique_fence.h
deleted file mode 100644
index 7dd9f91..0000000
--- a/evs/manager/1.1/sync/unique_fence.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (C) 2016 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.
- */
-
-#pragma once
-
-#include <utils/String8.h>
-
-#include "unique_fd.h"
-
-namespace android {
-namespace automotive {
-namespace evs {
-namespace V1_1 {
-namespace implementation {
-
-// This is a simple C++ wrapper around the sw_sync interface. It is used to
-// create and maintain sync fences created from a timeline.
-class UniqueFence {
-public:
- UniqueFence();
- explicit UniqueFence(int fd);
-
- UniqueFence(UniqueFence&&);
- UniqueFence& operator=(UniqueFence&&);
-
- // Destroy the current fence.
- void Reset();
-
- // Duplicate the fence.
- UniqueFence Dup() const;
-
- // Gets the descriptor
- int Get() const;
-
- // Gets an unowned duplicate of the fence descriptor.
- int GetUnowned() const;
-
- // Returns true if the fence is set to a valid descriptor. False otherwise.
- explicit operator bool() const;
-
- // Waits on the fence for the indicated amount of time in milliseconds. The
- // default value of -1 means to wait forever.
- int Wait(int wait_time_ms = -1);
-
- // Gets a string containing debug information for the fence.
- void GetDebugStateDump(String8& result) const;
-
- // Creates a new fence that signals when both input fences are signaled. Note
- // that it is possible to merge multiple fences this way.
- static UniqueFence Merge(const char* name, const UniqueFence& fence1,
- const UniqueFence& fence2);
-
-private:
- // The fence file descriptor
- UniqueFd fd_;
-};
-
-} // namespace implementation
-} // namespace V1_1
-} // namespace evs
-} // namespace automotive
-} // namespace android
-
diff --git a/evs/manager/1.1/sync/unique_timeline.cpp b/evs/manager/1.1/sync/unique_timeline.cpp
deleted file mode 100644
index b9556b8..0000000
--- a/evs/manager/1.1/sync/unique_timeline.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2016 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 "unique_timeline.h"
-
-#include <errno.h>
-#include <limits>
-#include <string.h>
-#include <sw_sync.h>
-
-#include <android-base/logging.h>
-
-namespace android {
-namespace automotive {
-namespace evs {
-namespace V1_1 {
-namespace implementation {
-
-UniqueTimeline::UniqueTimeline(unsigned offset)
- : fd_(sw_sync_timeline_create()), fence_counter_(offset) {
- if (!fd_) {
- LOG(FATAL) << "Failed to create a timeline.";
- }
-}
-
-UniqueTimeline::~UniqueTimeline() {
- // Force any fences waiting on the timeline to be released by incrementing
- // by the difference between the two counters. The sw_sync driver has
- // changed behavior several times, and no longer releases fences when the
- // timeline fd is closed. While at one point adding MAX_UINT worked (by
- // adding MAX_INT with two separate calls), even that stopped working.
- // (See b/35115489 for background)
- BumpTimelineEventCounter(fence_counter_ - timeline_counter_);
-}
-
-bool UniqueTimeline::Supported() {
- UniqueFd fd{sw_sync_timeline_create()};
- return !!fd;
-}
-
-UniqueFence UniqueTimeline::CreateFence(const char* name) {
- UniqueFence fence(sw_sync_fence_create(fd_.Get(), name, fence_counter_));
- if (!fence) {
- PLOG(FATAL) << "Cannot create fence";
- }
- return fence;
-}
-
-void UniqueTimeline::BumpTimelineEventCounter() {
- BumpTimelineEventCounter(1);
-}
-
-void UniqueTimeline::BumpTimelineEventCounter(unsigned count) {
- timeline_counter_ += count;
- int err = sw_sync_timeline_inc(fd_.Get(), count);
- if (err < 0) {
- PLOG(FATAL) << "Cannot bump timeline counter";
- }
-}
-
-} // namespace implementation
-} // namespace V1_1
-} // namespace evs
-} // namespace automotive
-} // namespace android
diff --git a/evs/manager/1.1/sync/unique_timeline.h b/evs/manager/1.1/sync/unique_timeline.h
deleted file mode 100644
index 17c2703..0000000
--- a/evs/manager/1.1/sync/unique_timeline.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2016 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.
- */
-
-#pragma once
-
-#include "unique_fd.h"
-#include "unique_fence.h"
-
-namespace android {
-namespace automotive {
-namespace evs {
-namespace V1_1 {
-namespace implementation {
-
-// This is a simple C++ wrapper around the sw_sync interface. It is used to
-// create sync fences using timeline semantics.
-//
-// The timeline has two counters, a fence event counter maintained here in this
-// class, and the timeline counter hidden in the driver. The one in the driver
-// is initialized to zero when creating the timeline, and the one here is
-// initialized to one. The counters are meant to be independently incremented.
-//
-// When the driver counter is incremented, all fences that were created with
-// counts after the previous value of the timeline counter, and before (and
-// including) the new value are signaled by the driver.
-//
-// All fences are signaled if the timeline is also destroyed.
-//
-// The typical uses of these fences is to acquire a fence for some future point
-// on the timeline, and incrementing the local fence event counter to
-// distinguish between separate events. Then later when the event actually
-// occurs you increment the drivers count.
-//
-// Since the fences are file descriptors, they can be easily sent to another
-// process, which can wait for them to signal without needing to define some
-// other IPC mechanism to communicate the event. If the fence is sent well in
-// advance, there should be minimal latency too.
-//
-// Instances of this class cannot be copied, but can be moved.
-class UniqueTimeline {
-public:
- // Initializes the timeline, using the given initial_fence_couter value.
- explicit UniqueTimeline(unsigned initial_fence_counter);
-
- ~UniqueTimeline();
-
- // Returns true if it is possible to create timelines.
- static bool Supported();
-
- // Creates a fence fd using the current value of the fence counter.
- // A negative value is returned on error.
- UniqueFence CreateFence(const char* name);
-
- // Increments the counter used when creating fences
- void BumpFenceEventCounter() { fence_counter_ += 1; }
-
- // Increments the drivers version of the counter, signaling any fences in the
- // range.
- void BumpTimelineEventCounter();
-
-private:
- void BumpTimelineEventCounter(unsigned);
-
- // The timeline file descriptor.
- UniqueFd fd_{-1};
-
- // The counter used when creating fences on the timeline.
- unsigned fence_counter_{0};
-
- // The effective count for the timeline. The kernel driver has the actual
- // value, we just track what it should be. If it ever becomes out of sync,
- // it could be a problem for releasing fences on destruction.
- unsigned timeline_counter_{0};
-};
-
-} // namespace implementation
-} // namespace V1_1
-} // namespace evs
-} // namespace automotive
-} // namespace android
-