[Fuchsia] Pass cached notification handle to inflight list
Optimization improves virtmagma perf.
Change-Id: If36ea53ba947bdd6bafafa7fbbb85a9a6f6c1327
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/mesa/+/480605
Reviewed-by: John Bauman <jbauman@google.com>
diff --git a/src/intel/vulkan/anv_magma_connection.cc b/src/intel/vulkan/anv_magma_connection.cc
index 98fdba8..1efbb8d 100644
--- a/src/intel/vulkan/anv_magma_connection.cc
+++ b/src/intel/vulkan/anv_magma_connection.cc
@@ -178,8 +178,8 @@
uint64_t timeout_ns)
{
return InflightList_WaitForBuffer(Connection::cast(connection)->inflight_list(),
- Connection::cast(connection)->magma_connection(), buffer_id,
- timeout_ns);
+ Connection::cast(connection)->magma_connection(),
+ connection->notification_channel, buffer_id, timeout_ns);
}
int AnvMagmaConnectionExec(anv_connection* connection, uint32_t context_id,
diff --git a/src/util/inflight_list.c b/src/util/inflight_list.c
index ed3d75e..a8b1d07 100644
--- a/src/util/inflight_list.c
+++ b/src/util/inflight_list.c
@@ -42,10 +42,10 @@
return abs_timeout - now;
}
-static magma_status_t wait_notification_channel(magma_connection_t connection, int64_t timeout_ns)
+static magma_status_t wait_notification_channel(magma_handle_t channel, int64_t timeout_ns)
{
magma_poll_item_t item = {
- .handle = magma_get_notification_channel_handle(connection),
+ .handle = channel,
.type = MAGMA_POLL_TYPE_HANDLE,
.condition = MAGMA_POLL_CONDITION_READABLE,
};
@@ -145,7 +145,8 @@
}
magma_status_t InflightList_WaitForBuffer(struct InflightList* list, magma_connection_t connection,
- uint64_t buffer_id, uint64_t timeout_ns)
+ magma_handle_t notification_channel, uint64_t buffer_id,
+ uint64_t timeout_ns)
{
int result = pthread_mutex_lock(&list->mutex_);
assert(result == 0);
@@ -156,7 +157,7 @@
magma_status_t status = MAGMA_STATUS_OK;
while (InflightList_is_inflight(list, buffer_id)) {
- status = list->wait_(connection, get_relative_timeout(deadline));
+ status = list->wait_(notification_channel, get_relative_timeout(deadline));
if (status != MAGMA_STATUS_OK) {
break;
diff --git a/src/util/inflight_list.h b/src/util/inflight_list.h
index 7ac68ff..bc60443 100644
--- a/src/util/inflight_list.h
+++ b/src/util/inflight_list.h
@@ -36,8 +36,7 @@
// by reading completed buffer ids from the magma notification channel.
// Not threadsafe.
-typedef magma_status_t (*wait_notification_channel_t)(magma_connection_t connection,
- int64_t timeout_ns);
+typedef magma_status_t (*wait_notification_channel_t)(magma_handle_t channel, int64_t timeout_ns);
typedef magma_status_t (*read_notification_channel_t)(magma_connection_t connection, void* buffer,
uint64_t buffer_size,
@@ -86,7 +85,8 @@
// Wait for the given |buffer_id| to be removed from the inflight list. Threadsafe.
magma_status_t InflightList_WaitForBuffer(struct InflightList* list, magma_connection_t connection,
- uint64_t buffer_id, uint64_t timeout_ns);
+ magma_handle_t notification_channel, uint64_t buffer_id,
+ uint64_t timeout_ns);
// Adds the give buffers to the inflight list and services the notification channel. Threadsafe.
void InflightList_AddAndUpdate(struct InflightList* list, magma_connection_t connection,
diff --git a/src/util/tests/inflight_list/test_inflight_list.cpp b/src/util/tests/inflight_list/test_inflight_list.cpp
index 1b4ad54..60a1b50 100644
--- a/src/util/tests/inflight_list/test_inflight_list.cpp
+++ b/src/util/tests/inflight_list/test_inflight_list.cpp
@@ -41,15 +41,18 @@
TestConnection() { zx::channel::create(0, &channel[0], &channel[1]); }
zx::channel channel[2];
+
+ zx_handle_t get_notification_channel() { return channel[0].get(); }
};
-static magma_status_t wait_notification_channel(magma_connection_t connection, int64_t timeout_ns)
+static magma_status_t wait_notification_channel(magma_handle_t channel, int64_t timeout_ns)
{
zx_signals_t pending;
- zx_status_t status =
- static_cast<TestConnection*>(connection)
- ->channel[0]
- .wait_one(ZX_CHANNEL_READABLE, zx::deadline_after(zx::nsec(timeout_ns)), &pending);
+ zx_handle_t zx_channel_handle = channel;
+
+ zx_status_t status = zx_object_wait_one(zx_channel_handle, ZX_CHANNEL_READABLE,
+ zx_deadline_after(ZX_NSEC(timeout_ns)), &pending);
+
switch (status) {
case ZX_ERR_TIMED_OUT:
return MAGMA_STATUS_TIMED_OUT;
@@ -174,6 +177,7 @@
EXPECT_FALSE(InflightList_is_inflight(list_, buffer_id));
TestConnection connection;
+ magma_handle_t channel = connection.get_notification_channel();
std::vector<magma_system_exec_resource> resource;
resource.push_back({.buffer_id = buffer_id});
@@ -186,7 +190,7 @@
EXPECT_TRUE(InflightList_is_inflight(list_, buffer_id + 2));
EXPECT_EQ(MAGMA_STATUS_TIMED_OUT,
- InflightList_WaitForBuffer(list_, &connection, buffer_id, 0 /*timeout_ns*/));
+ InflightList_WaitForBuffer(list_, &connection, channel, buffer_id, 0 /*timeout_ns*/));
EXPECT_TRUE(InflightList_is_inflight(list_, buffer_id));
EXPECT_TRUE(InflightList_is_inflight(list_, buffer_id + 1));
EXPECT_TRUE(InflightList_is_inflight(list_, buffer_id + 2));
@@ -197,22 +201,23 @@
constexpr uint64_t kTimeoutNs = ms_to_ns(100);
uint64_t start = gettime_ns();
EXPECT_EQ(MAGMA_STATUS_TIMED_OUT,
- InflightList_WaitForBuffer(list_, &connection, buffer_id + 1, kTimeoutNs));
+ InflightList_WaitForBuffer(list_, &connection, channel, buffer_id + 1, kTimeoutNs));
EXPECT_LE(kTimeoutNs - ms_to_ns(1), gettime_ns() - start); // TODO(fxb/49103) remove rounding
EXPECT_FALSE(InflightList_is_inflight(list_, buffer_id));
EXPECT_TRUE(InflightList_is_inflight(list_, buffer_id + 1));
EXPECT_TRUE(InflightList_is_inflight(list_, buffer_id + 2));
- EXPECT_EQ(MAGMA_STATUS_OK, InflightList_WaitForBuffer(list_, &connection, buffer_id, 0));
+ EXPECT_EQ(MAGMA_STATUS_OK,
+ InflightList_WaitForBuffer(list_, &connection, channel, buffer_id, 0));
value = buffer_id + 1;
connection.channel[1].write(0, &value, sizeof(value), nullptr, 0);
value = buffer_id + 2;
connection.channel[1].write(0, &value, sizeof(value), nullptr, 0);
- EXPECT_EQ(MAGMA_STATUS_OK,
- InflightList_WaitForBuffer(list_, &connection, buffer_id + 1, 0 /*timeout_ns*/));
+ EXPECT_EQ(MAGMA_STATUS_OK, InflightList_WaitForBuffer(list_, &connection, channel, buffer_id + 1,
+ 0 /*timeout_ns*/));
EXPECT_FALSE(InflightList_is_inflight(list_, buffer_id));
EXPECT_FALSE(InflightList_is_inflight(list_, buffer_id + 1));