summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Ho <willho@google.com>2022-10-12 16:52:52 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2022-10-12 16:52:52 +0000
commit6107be7528bd258130b5340be2eee1532c7f692c (patch)
tree514ac18f80bfb9015783cc580a57c06da416710b
parent0b142bd8a567a2a03cbbfc39cf939ee2def27cee (diff)
parent74cdd86272d2207c2ae06247d7a733b387f8096c (diff)
downloadgfxstream-protocols-6107be7528bd258130b5340be2eee1532c7f692c.tar.gz
Merge "Add HealthWatchdogs to VkEncoder and AddressSpaceStream"
-rw-r--r--registry/vulkan/scripts/cereal/encoder.py42
-rw-r--r--registry/vulkan/scripts/cerealgenerator.py5
2 files changed, 40 insertions, 7 deletions
diff --git a/registry/vulkan/scripts/cereal/encoder.py b/registry/vulkan/scripts/cereal/encoder.py
index 4547723a..e5fc4a45 100644
--- a/registry/vulkan/scripts/cereal/encoder.py
+++ b/registry/vulkan/scripts/cereal/encoder.py
@@ -18,9 +18,11 @@ from .wrapperdefs import ROOT_TYPE_DEFAULT_VALUE
from .wrapperdefs import VULKAN_STREAM_TYPE_GUEST
encoder_decl_preamble = """
+using android::base::guest::HealthMonitor;
+
class VkEncoder {
public:
- VkEncoder(IOStream* stream);
+ VkEncoder(IOStream* stream, HealthMonitor<>* healthMonitor = nullptr);
~VkEncoder();
#include "VkEncoder.h.inl"
@@ -30,6 +32,7 @@ encoder_decl_postamble = """
private:
class Impl;
std::unique_ptr<Impl> mImpl;
+ HealthMonitor<>* mHealthMonitor;
};
"""
@@ -364,6 +367,7 @@ def emit_parameter_encode_write_packet_info(typeInfo, api, cgen):
cgen.stmt("uint32_t packetSize_%s = 4 + 4 + (queueSubmitWithCommandsEnabled ? 4 : 0) + count" % (api.name))
else:
cgen.stmt("uint32_t packetSize_%s = 4 + 4 + count" % (api.name))
+ cgen.stmt("healthMonitorAnnotation_packetSize = std::make_optional(packetSize_%s)" % (api.name))
if not doDispatchSerialize:
cgen.stmt("if (queueSubmitWithCommandsEnabled) packetSize_%s -= 8" % api.name)
@@ -374,6 +378,7 @@ def emit_parameter_encode_write_packet_info(typeInfo, api, cgen):
if doSeqno:
cgen.stmt("uint32_t seqno; if (queueSubmitWithCommandsEnabled) seqno = ResourceTracker::nextSeqno()")
+ cgen.stmt("healthMonitorAnnotation_seqno = std::make_optional(seqno)")
cgen.stmt("memcpy(streamPtr, &opcode_%s, sizeof(uint32_t)); streamPtr += sizeof(uint32_t)" % api.name)
cgen.stmt("memcpy(streamPtr, &packetSize_%s, sizeof(uint32_t)); streamPtr += sizeof(uint32_t)" % api.name)
@@ -487,6 +492,27 @@ def emit_debug_log(typeInfo, api, cgen):
cgen.stmt("ENCODER_DEBUG_LOG(\"%s(%s)\", %s)" % (api.name, logFormatStr, logVargsStr))
+def emit_health_watchdog(api, cgen):
+ cgen.stmt("std::optional<uint32_t> healthMonitorAnnotation_seqno = std::nullopt")
+ cgen.stmt("std::optional<uint32_t> healthMonitorAnnotation_packetSize = std::nullopt")
+ cgen.line("""
+ auto watchdog = mHealthMonitor ?
+ WATCHDOG_BUILDER(*mHealthMonitor, \"%s in VkEncoder\")
+ .setOnHangCallback([&]() {
+ auto annotations = std::make_unique<EventHangMetadata::HangAnnotations>();
+ if (healthMonitorAnnotation_seqno) {
+ annotations->insert({{"seqno", std::to_string(healthMonitorAnnotation_seqno.value())}});
+ }
+ if (healthMonitorAnnotation_packetSize) {
+ annotations->insert({{"packetSize", std::to_string(healthMonitorAnnotation_packetSize.value())}});
+ }
+ return std::move(annotations);
+ })
+ .build() :
+ nullptr;
+ """% (api.name)
+ )
+
def emit_default_encoding(typeInfo, api, cgen):
emit_debug_log(typeInfo, api, cgen)
emit_lock(cgen)
@@ -669,12 +695,14 @@ class VulkanEncoder(VulkanWrapperGenerator):
self.module.appendHeader(self.cgenHeader.swapCode())
- if api.name in custom_encodes.keys():
- self.module.appendImpl(self.cgenImpl.makeFuncImpl(
- apiImpl, lambda cgen: custom_encodes[api.name](self.typeInfo, api, cgen)))
- else:
- self.module.appendImpl(self.cgenImpl.makeFuncImpl(apiImpl,
- lambda cgen: emit_default_encoding(self.typeInfo, api, cgen)))
+ def emit_function_impl(cgen):
+ emit_health_watchdog(api, cgen)
+ if api.name in custom_encodes.keys():
+ custom_encodes[api.name](self.typeInfo, api, cgen)
+ else:
+ emit_default_encoding(self.typeInfo, api, cgen)
+
+ self.module.appendImpl(self.cgenImpl.makeFuncImpl(apiImpl, emit_function_impl))
def onEnd(self,):
self.module.appendHeader(encoder_decl_postamble)
diff --git a/registry/vulkan/scripts/cerealgenerator.py b/registry/vulkan/scripts/cerealgenerator.py
index 783401e5..a34148ae 100644
--- a/registry/vulkan/scripts/cerealgenerator.py
+++ b/registry/vulkan/scripts/cerealgenerator.py
@@ -167,6 +167,7 @@ target_include_directories(OpenglRender_vulkan_cereal
"""
encoderInclude = """
+#include "android/base/AndroidHealthMonitor.h"
#include "goldfish_vk_private_defs.h"
#include <memory>
class IOStream;
@@ -193,7 +194,11 @@ class IOStream;
#include "goldfish_vk_private_defs.h"
#include "goldfish_vk_transform_guest.h"
+#include <memory>
+#include <optional>
#include <unordered_map>
+#include <string>
+#include <vector>
""" % VULKAN_STREAM_TYPE_GUEST