From e6a71efe8c471aba642e407e1436eb81c4e345d6 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 15 Oct 2021 14:57:31 -0700 Subject: [PATCH] ircd::cl: Sample tsc for work item submission for blocking interface mitigations. --- include/ircd/cl.h | 1 + ircd/cl.cc | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/ircd/cl.h b/include/ircd/cl.h index 95e9002eb..d900069bb 100644 --- a/include/ircd/cl.h +++ b/include/ircd/cl.h @@ -58,6 +58,7 @@ struct ircd::cl::work void *handle {nullptr}; ctx::ctx *context {ctx::current}; void *object {nullptr}; + uint64_t ts {ircd::cycles()}; static void init(), fini() noexcept; diff --git a/ircd/cl.cc b/ircd/cl.cc index 7d9149b66..37ff6e43e 100644 --- a/ircd/cl.cc +++ b/ircd/cl.cc @@ -655,6 +655,7 @@ namespace ircd::cl static const size_t _deps_list_max {32}; static thread_local cl_event _deps_list[_deps_list_max]; + static void check_submit_blocking(cl::exec *const &, const exec::opts &); static void handle_submitted(cl::exec *const &, const exec::opts &); static vector_view make_deps_default(cl::work *const &, const exec::opts &); static vector_view make_deps(cl::work *const &, const exec::opts &); @@ -1057,6 +1058,7 @@ try assert(this->handle); call(clReleaseEvent, cl_event(this->handle)); this->handle = nullptr; + this->work::ts = ircd::cycles(); }}; // Wait for the mapping to complete before presenting the buffer. @@ -1171,6 +1173,7 @@ try assert(this->handle); call(clReleaseEvent, cl_event(this->handle)); this->handle = nullptr; + this->work::ts = ircd::cycles(); }}; wait(); @@ -1202,6 +1205,9 @@ ircd::cl::handle_submitted(cl::exec *const &exec, if(opts.sync) cl::sync(); + if(likely(!opts.blocking)) + check_submit_blocking(exec, opts); + if(opts.nice == 0) ctx::yield(); @@ -1209,6 +1215,38 @@ ircd::cl::handle_submitted(cl::exec *const &exec, ctx::sleep(opts.nice * milliseconds(nice_rate)); } +void +ircd::cl::check_submit_blocking(cl::exec *const &exec, + const exec::opts &opts) +{ + const auto threshold + { + 268'435'456 + }; + + const auto submit_cycles + { + prof::cycles() - exec->ts + }; + + if(likely(submit_cycles < threshold)) + return; + + char nbuf[64]; + const auto name + { + exec->name(nbuf) + }; + + char pbuf[32]; + log::dwarning + { + log, "clEnqueue() kernel '%s' blocking the host for %s cycles on submit.", + name?: ""_sv, + pretty(pbuf, si(submit_cycles), 1), + }; +} + ircd::vector_view ircd::cl::make_deps(cl::work *const &work, const exec::opts &opts)