Petri,

On 07.09.15 15:41, Petri Savolainen wrote:
Raw CPU cycle counts can be used to measure performance
in CPU cycles. These functions will replace some usage of
odp_time_cycles() of odp_time_diff_cycles().

Signed-off-by: Petri Savolainen <petri.savolai...@nokia.com>
---

Probably proposed API covers all existent cases.
Also we agreed that it can be 32-bits counter like for ARMv7.

Just imaged situation when we need to put some masg in N cycles.
Or complete some job when we spend some amount of cpu cycles.
In this case c1 + c2(range) should be avoided, as in 64-bits
it approximately will never be overflowed and in comparison will be more
then current cycle number forever.

But don't bother, I think that if you use this API for such case, your
program definitely is wrong and should be rewritten.

+ operation should be used only to integrate spent cycles, not more.


  include/odp/api/cpu.h | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 52 insertions(+)

diff --git a/include/odp/api/cpu.h b/include/odp/api/cpu.h
index c389093..50a7e3d 100644
--- a/include/odp/api/cpu.h
+++ b/include/odp/api/cpu.h
@@ -18,6 +18,8 @@
  extern "C" {
  #endif

+#include <odp/std_types.h>
+
  /** @defgroup odp_cpu ODP CPU
   *  @{
   */
@@ -44,6 +46,56 @@ int odp_cpu_id(void);
  int odp_cpu_count(void);

  /**
+ * Current CPU cycle count
+ *
+ * Return current CPU cycle count. Cycle count may not be reset at ODP init
+ * and thus may wrap back to zero between two calls. Use odp_cpu_cycles_max()
+ * to read the maximum count value after which it wraps. Cycle count frequency
+ * follows the CPU frequency and thus may change at any time. The count may
+ * advance in steps larger than one. Use odp_cpu_cycles_resolution() to read
+ * the step size.
+ *
+ * @note Do not use CPU count for time measurements since the frequency may
+ * vary.
+ *
+ * @return Current CPU cycle count
+ */
+uint64_t odp_cpu_cycles(void);
+
+/**
+ * CPU cycle count difference
+ *
+ * Calculate difference between cycle counts c1 and c2. Parameter c1 must be 
the
+ * first cycle count sample and c2 the second. The function handles correctly
+ * single cycle count wrap between c1 and c2.
+ *
+ * @param c1    First cycle count
+ * @param c2    Second cycle count
+ *
+ * @return CPU cycles from c1 to c2
+ */
+uint64_t odp_cpu_cycles_diff(uint64_t c1, uint64_t c2);
+
+/**
+ * Maximum CPU cycle count
+ *
+ * Maximum CPU cycle count value before it wraps back to zero.
+ *
+ * @return Maximum CPU cycle count value
+ */
+uint64_t odp_cpu_cycles_max(void);
+
+/**
+ * Resolution of CPU cycle count
+ *
+ * CPU cycle count may advance in steps larger than one. This function returns
+ * resolution of odp_cpu_cycles() in CPU cycles.
+ *
+ * @return CPU cycle count resolution in CPU cycles
+ */
+uint64_t odp_cpu_cycles_resolution(void);
+
+/**
   * @}
   */



--
Regards,
Ivan Khoronzhuk
_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to