Skip to content

Commit ae15a26

Browse files
cjordan44Anas Nashif
authored andcommitted
arc: add _tsc_read for 64-bit timestamp
This implementation of _tsc_read returns a 64-bit value that is derived from the 64-bit tick count multiplied by hwcycles per tick, and then it adds the current value from the 32-bit timer. This produces a 64-bit time. There is a bunch of math here, which could be avoided if the CPU is built with Real-Time-Clock option. EM Starter Kit SOCs don't have this. I don't think Arduino 101 does either. See ZEP-1559 Change-Id: I9f846d170246556ac40fe2f45809e457c6375d8c Signed-off-by: Chuck Jordan <[email protected]>
1 parent 35fcb27 commit ae15a26

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

arch/arc/core/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ccflags-y +=-I$(srctree)/arch/$(ARCH)/include
33

44
obj-y += thread.o thread_entry_wrapper.o \
55
cpu_idle.o fast_irq.o fatal.o fault.o \
6-
fault_s.o irq_manage.o cache.o \
6+
fault_s.o irq_manage.o cache.o timestamp.o \
77
isr_wrapper.o regular_irq.o swap.o \
88
sys_fatal_error_handler.o
99

arch/arc/core/timestamp.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2017 Synopsys, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file
9+
* @brief Time Stamp API for ARCv2
10+
*
11+
* Provide 64-bit time stamp API
12+
*/
13+
14+
#include <kernel.h>
15+
#include <toolchain.h>
16+
#include <kernel_structs.h>
17+
18+
extern int64_t _sys_clock_tick_count;
19+
extern int sys_clock_hw_cycles_per_tick;
20+
21+
/*
22+
* @brief Read 64-bit timestamp value
23+
*
24+
* This function returns a 64-bit bit time stamp value that is clocked
25+
* at the same frequency as the CPU.
26+
*
27+
* @return 64-bit time stamp value
28+
*/
29+
uint64_t _tsc_read(void)
30+
{
31+
unsigned int key;
32+
uint64_t t;
33+
uint32_t count;
34+
35+
key = irq_lock();
36+
t = (uint64_t)_sys_clock_tick_count;
37+
count = _arc_v2_aux_reg_read(_ARC_V2_TMR0_COUNT);
38+
irq_unlock(key);
39+
t *= (uint64_t)sys_clock_hw_cycles_per_tick;
40+
t += (uint64_t)count;
41+
return t;
42+
}

include/arch/arc/v2/asm_inline_gcc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ extern "C" {
2121
#include <stdint.h>
2222
#include <stddef.h>
2323

24+
/**
25+
* @brief read timestamp register (CPU frequency)
26+
*/
27+
extern uint64_t _tsc_read(void);
28+
29+
2430
/* Implementation of sys_io.h's documented functions */
2531

2632
static ALWAYS_INLINE

0 commit comments

Comments
 (0)