From 565d6e838121b412c7310ffc3162b030f2e4aace Mon Sep 17 00:00:00 2001
From: Jason Volk <jason@zemos.net>
Date: Wed, 10 Apr 2019 14:49:39 -0700
Subject: [PATCH] ircd::prof: Add a syscall_timer device.

---
 include/ircd/prof.h | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/include/ircd/prof.h b/include/ircd/prof.h
index d4d9e8df4..acc1f4353 100644
--- a/include/ircd/prof.h
+++ b/include/ircd/prof.h
@@ -19,6 +19,7 @@ namespace ircd::prof
 	struct times;
 	struct system;
 	struct resource;
+	struct syscall_timer;
 	enum dpl :uint8_t;
 	enum counter :uint8_t;
 	enum cacheop :uint8_t;
@@ -74,6 +75,35 @@ struct ircd::prof::times
 	times() = default;
 };
 
+/// This device intends to figure out when a system call is really slow
+/// or "blocking." The original use-case is for io_submit() in fs::aio.
+/// The sample is conducted with times(2) which is itself a system call,
+/// and the result has poor resolution meaning the result of at() is
+/// generally 0 unless the system call was actually slow.
+struct ircd::prof::syscall_timer
+{
+	uint64_t started
+	{
+		time_kern()
+	};
+
+	uint64_t stopped
+	{
+		0
+	};
+
+	uint64_t at() const
+	{
+		return stopped - started;
+	}
+
+	uint64_t stop()
+	{
+		stopped = time_kern();
+		return at();
+	}
+};
+
 struct ircd::prof::resource
 :std::array<uint64_t, 9>
 {