aboutsummaryrefslogtreecommitdiff
path: root/host-common
diff options
context:
space:
mode:
authorJoshua Duong <joshuaduong@google.com>2023-08-18 14:01:25 -0700
committerJoshua Duong <joshuaduong@google.com>2023-08-22 09:17:58 -0700
commit7d90df6fd73d2ab0513fc3f726f5b43be75c6651 (patch)
tree061f6728cf0a64c11f9fbff4c591c8e093c12743 /host-common
parent5611439c6c24082a9f2f7795275f6c650e901bd2 (diff)
downloadaemu-7d90df6fd73d2ab0513fc3f726f5b43be75c6651.tar.gz
Add GoldfishPipeServiceOps APIs to wait for guest data.
We need to separate the waiting part out from guest_recv/guest_send because those calls in qemu are protected by the global qemu mutex. But when we wait, we need to release the mutex. Bug: 294378605 Test: CtsGraphicsTestCases Change-Id: Ic47960d9bd714e5c5a593afd851daa59ce05a7ab
Diffstat (limited to 'host-common')
-rw-r--r--host-common/AndroidPipe.cpp20
-rw-r--r--host-common/include/host-common/AndroidPipe.h8
-rw-r--r--host-common/include/host-common/android_pipe_device.h6
-rw-r--r--host-common/include/host-common/goldfish_pipe.h6
4 files changed, 40 insertions, 0 deletions
diff --git a/host-common/AndroidPipe.cpp b/host-common/AndroidPipe.cpp
index a61fc6e..8a8b592 100644
--- a/host-common/AndroidPipe.cpp
+++ b/host-common/AndroidPipe.cpp
@@ -74,6 +74,10 @@ static BaseStream* asBaseStream(CStream* stream) {
}
#define CHECK_VM_STATE_LOCK() (void)0
+// b/294378605: Need to implement VM_STATE_LOCK and VM_STATE_UNLOCK for qemu. We leave this empty
+// for now since qemu provides its own implementation of AndroidPipe.cpp.
+#define VM_STATE_LOCK() (void)0
+#define VM_STATE_UNLOCK() (void)0
namespace android {
@@ -773,6 +777,14 @@ int android_pipe_guest_recv(void* internalPipe,
return pipe->onGuestRecv(buffers, numBuffers);
}
+void android_pipe_wait_guest_recv(void* internalPipe) {
+ CHECK_VM_STATE_LOCK();
+ auto pipe = static_cast<AndroidPipe*>(internalPipe);
+ VM_STATE_UNLOCK();
+ pipe->waitGuestRecv();
+ VM_STATE_LOCK();
+}
+
int android_pipe_guest_send(void** internalPipe,
const AndroidPipeBuffer* buffers,
int numBuffers) {
@@ -783,6 +795,14 @@ int android_pipe_guest_send(void** internalPipe,
return pipe->onGuestSend(buffers, numBuffers, internalPipe);
}
+void android_pipe_wait_guest_send(void* internalPipe) {
+ CHECK_VM_STATE_LOCK();
+ auto pipe = static_cast<AndroidPipe*>(internalPipe);
+ VM_STATE_UNLOCK();
+ pipe->waitGuestSend();
+ VM_STATE_LOCK();
+}
+
void android_pipe_guest_wake_on(void* internalPipe, unsigned wakes) {
CHECK_VM_STATE_LOCK();
auto pipe = static_cast<AndroidPipe*>(internalPipe);
diff --git a/host-common/include/host-common/AndroidPipe.h b/host-common/include/host-common/AndroidPipe.h
index 628c34e..ab39dd9 100644
--- a/host-common/include/host-common/AndroidPipe.h
+++ b/host-common/include/host-common/AndroidPipe.h
@@ -166,6 +166,10 @@ public:
// is no data yet to read.
virtual int onGuestRecv(AndroidPipeBuffer* buffers, int numBuffers) = 0;
+ // A blocking call that waits until guest is able to receive data from the pipe.
+ // This can be used if a previous call to |onGuestRecv| returns PIPE_ERROR_AGAIN.
+ virtual void waitGuestRecv() const {};
+
// Called from the device thread when the guest wants to send data to
// the pipe. |buffers| points to an array of |numBuffers| descriptors that
// specify where to copy the data from. Return the number of bytes that
@@ -176,6 +180,10 @@ public:
int numBuffers,
void** newPipePtr) = 0;
+ // A blocking call that waits until guest is able to send data to the pipe.
+ // This can be used if a previous call to |onGuestSend| returns PIPE_ERROR_AGAIN.
+ virtual void waitGuestSend() const {}
+
// Called from the device thread when the guest wants to indicate it
// wants to be woken up when the set of PIPE_WAKE_XXX event bits in |flags|
// will occur. The pipe implementation should call the wake() method to
diff --git a/host-common/include/host-common/android_pipe_device.h b/host-common/include/host-common/android_pipe_device.h
index 06802f7..3b12247 100644
--- a/host-common/include/host-common/android_pipe_device.h
+++ b/host-common/include/host-common/android_pipe_device.h
@@ -166,10 +166,16 @@ ANDROID_PIPE_DEVICE_EXPORT unsigned android_pipe_guest_poll(void* internal_pipe)
ANDROID_PIPE_DEVICE_EXPORT int android_pipe_guest_recv(
void* internal_pipe, AndroidPipeBuffer* buffers, int numBuffers);
+// Blocking call that waits until guest is able to receive data.
+ANDROID_PIPE_DEVICE_EXPORT void android_pipe_wait_guest_recv(void* internal_pipe);
+
// Call the sendBuffers() callback of the client associated with |pipe|.
ANDROID_PIPE_DEVICE_EXPORT int android_pipe_guest_send(
void** internal_pipe, const AndroidPipeBuffer* buffer, int numBuffer);
+// Blocking call that waits until guest is able to send data.
+ANDROID_PIPE_DEVICE_EXPORT void android_pipe_wait_guest_send(void* internal_pipe);
+
// Call the wakeOn() callback of the client associated with |pipe|.
ANDROID_PIPE_DEVICE_EXPORT void android_pipe_guest_wake_on(
void* internal_pipe, unsigned wakes);
diff --git a/host-common/include/host-common/goldfish_pipe.h b/host-common/include/host-common/goldfish_pipe.h
index f387dcf..b78f493 100644
--- a/host-common/include/host-common/goldfish_pipe.h
+++ b/host-common/include/host-common/goldfish_pipe.h
@@ -123,6 +123,9 @@ typedef struct GoldfishPipeServiceOps {
GoldfishPipeBuffer *buffers,
int num_buffers);
+ // Blocking call that waits until guest is able to receive data through |host_pipe|.
+ void (*wait_guest_recv)(GoldfishHostPipe* host_pipe);
+
// Called when the guest tries to send data to the host through
// |host_pipe|. This will try to copy data from the memory ranges
// decribed by the array |buffers| or |num_buffers| items.
@@ -132,6 +135,9 @@ typedef struct GoldfishPipeServiceOps {
const GoldfishPipeBuffer *buffers,
int num_buffers);
+ // Blocking call that waits until guest is able to send data through |host_pipe|.
+ void (*wait_guest_send)(GoldfishHostPipe* host_pipe);
+
// Called when the guest wants to be waked on specific events.
// identified by the |wake_flags| bitmask. The host should call
// goldfish_pipe_signal_wake() with the appropriate bitmask when