diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h
index 73fa2e69b029..7df20976f36f 100644
--- a/src/libcamera/include/utils.h
+++ b/src/libcamera/include/utils.h
@@ -8,6 +8,7 @@
 #define __LIBCAMERA_UTILS_H__
 
 #include <memory>
+#include <time.h>
 
 #define ARRAY_SIZE(a)	(sizeof(a) / sizeof(a[0]))
 
@@ -24,6 +25,11 @@ std::unique_ptr<T> make_unique(Args&&... args)
 
 } /* namespace utils */
 
+struct timespec &operator+=(struct timespec &lhs, const struct timespec &rhs);
+struct timespec operator+(struct timespec lhs, const struct timespec &rhs);
+struct timespec &operator-=(struct timespec &lhs, const struct timespec &rhs);
+struct timespec operator-(struct timespec lhs, const struct timespec &rhs);
+
 } /* namespace libcamera */
 
 #endif /* __LIBCAMERA_UTILS_H__ */
diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
index f9f25c0ecf15..72d4a194e19a 100644
--- a/src/libcamera/meson.build
+++ b/src/libcamera/meson.build
@@ -11,6 +11,7 @@ libcamera_sources = files([
     'pipeline_handler.cpp',
     'signal.cpp',
     'timer.cpp',
+    'utils.cpp',
     'v4l2_device.cpp',
 ])
 
diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
new file mode 100644
index 000000000000..5014b27d8c7d
--- /dev/null
+++ b/src/libcamera/utils.cpp
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2018, Google Inc.
+ *
+ * utils.cpp - Miscellaneous utility functions
+ */
+
+#include "utils.h"
+
+namespace libcamera {
+
+struct timespec &operator+=(struct timespec &lhs, const struct timespec &rhs)
+{
+	lhs.tv_sec += rhs.tv_sec;
+	lhs.tv_nsec += rhs.tv_nsec;
+	if (lhs.tv_nsec >= 1000000000) {
+		lhs.tv_sec++;
+		lhs.tv_nsec -= 1000000000;
+	}
+
+	return lhs;
+}
+
+struct timespec operator+(struct timespec lhs, const struct timespec &rhs)
+{
+	return lhs += rhs;
+}
+
+struct timespec &operator-=(struct timespec &lhs, const struct timespec &rhs)
+{
+	lhs.tv_sec -= rhs.tv_sec;
+	lhs.tv_nsec -= rhs.tv_nsec;
+	if (lhs.tv_nsec < 0) {
+		lhs.tv_sec--;
+		lhs.tv_nsec += 1000000000;
+	}
+
+	return lhs;
+}
+
+struct timespec operator-(struct timespec lhs, const struct timespec &rhs)
+{
+	return lhs - rhs;
+}
+
+} /* namespace libcamera */
