diff mbox

[API-NEXT] api: odp_time_sub

Message ID 1473873284-15148-1-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Sept. 14, 2016, 5:14 p.m. UTC
Previously we had odp_time_sum but missing call to subtract
some value from odp_time_t. Because on different platforms it
can be implemented differently we need this call.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>

---
 include/odp/api/spec/time.h                 | 10 ++++++++++
 platform/linux-generic/odp_time.c           | 17 +++++++++++++++++
 test/common_plat/validation/api/time/time.c |  2 +-
 3 files changed, 28 insertions(+), 1 deletion(-)

-- 
2.7.1.250.gff4ea60
diff mbox

Patch

diff --git a/include/odp/api/spec/time.h b/include/odp/api/spec/time.h
index fcc94c9..5e94b70 100644
--- a/include/odp/api/spec/time.h
+++ b/include/odp/api/spec/time.h
@@ -87,6 +87,16 @@  odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1);
 odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2);
 
 /**
+ * Time subtract
+ *
+ * @param t1    Time stamp to subtract from
+ * @param t2    Value to subtract
+ *
+ * @return Time stamp t1 - t2
+ */
+odp_time_t odp_time_sub(odp_time_t t1, odp_time_t t2);
+
+/**
  * Convert time to nanoseconds
  *
  * @param time  Time
diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c
index 81e0522..7fef46f 100644
--- a/platform/linux-generic/odp_time.c
+++ b/platform/linux-generic/odp_time.c
@@ -81,6 +81,18 @@  static inline odp_time_t time_sum(odp_time_t t1, odp_time_t t2)
 	return time;
 }
 
+static inline odp_time_t time_sub(odp_time_t t1, odp_time_t t2)
+{
+	uint64_t ns;
+	odp_time_t time;
+
+	ns = time_to_ns(t1) - time_to_ns(t2);
+	time.tv_sec = ns / ODP_TIME_SEC_IN_NS;
+	time.tv_nsec = ns - time.tv_sec * ODP_TIME_SEC_IN_NS;
+
+	return time;
+}
+
 static inline odp_time_t time_local_from_ns(uint64_t ns)
 {
 	odp_time_t time;
@@ -152,6 +164,11 @@  odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2)
 	return time_sum(t1, t2);
 }
 
+odp_time_t odp_time_sub(odp_time_t t1, odp_time_t t2)
+{
+	return time_sub(t1, t2);
+}
+
 uint64_t odp_time_local_res(void)
 {
 	return time_local_res();
diff --git a/test/common_plat/validation/api/time/time.c b/test/common_plat/validation/api/time/time.c
index 530d5c0..3885b65 100644
--- a/test/common_plat/validation/api/time/time.c
+++ b/test/common_plat/validation/api/time/time.c
@@ -1,4 +1,4 @@ 
-/* Copyright (c) 2015, Linaro Limited
+b/* Copyright (c) 2015, Linaro Limited
  * All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause