Skip to content

Commit 5c3bc58

Browse files
committed
[riscv64] Get the TSC from rdtime instruction
1 parent 04364b8 commit 5c3bc58

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

riscv64/bitasm.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,21 @@ __asm__ volatile \
8585
)
8686

8787
#define RDTSC64(_mem64) \
88-
/*TODO __asm__ volatile \
88+
__asm__ volatile \
8989
( \
90-
"csrr %0 , mcycle" \
90+
"rdtime %0" \
9191
: "=r" (_mem64) \
9292
: \
9393
: "cc", "memory" \
94-
)*/ \
95-
_mem64 = 0;
94+
)
9695

9796
#define ASM_RDTSC(_reg) \
98-
"# Read variant TSC." /*TODO "\n\t" \
99-
"csrr " #_reg ", mcycle" "\n\t"*/
97+
"# Read variant TSC." "\n\t" \
98+
"rdtime " #_reg "\n\t"
10099

101100
#define ASM_CODE_RDPMC(_ctr, _reg) \
102101
"# Read PMU counter." "\n\t" \
103-
"csrr " #_reg ", " #_ctr "\n\t" \
102+
/*TODO "csrr " #_reg ", " #_ctr "\n\t" */ \
104103

105104
#define ASM_RDPMC(_ctr, _reg) ASM_CODE_RDPMC(_ctr, _reg)
106105

riscv64/corefreqd.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -2033,16 +2033,16 @@ REASON_CODE Child_Manager(REF *Ref)
20332033
Arg[cpu].TID = 0;
20342034
}
20352035
} else {
2036-
unsigned int seed32 = time(0);
2037-
/*TODO(Cycles) __asm__ volatile
2036+
volatile unsigned long seed;
2037+
__asm__ volatile
20382038
(
2039-
"csrr %0, mcycle"
2040-
: "=r" (seed32)
2039+
"rdtime %0"
2040+
: "=r" (seed)
20412041
:
20422042
:
2043-
);*/
2043+
);
20442044
#ifdef __GLIBC__
2045-
initstate_r( seed32,
2045+
initstate_r( (unsigned int) seed,
20462046
RO(Shm)->Cpu[cpu].Slice.Random.state,
20472047
sizeof(RO(Shm)->Cpu[cpu].Slice.Random.state),
20482048
&RO(Shm)->Cpu[cpu].Slice.Random.data );

riscv64/corefreqk.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static signed int ArchID = -1;
8080
module_param(ArchID, int, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
8181
MODULE_PARM_DESC(ArchID, "Force an architecture (ID)");
8282

83-
static signed int AutoClock = /*TODO: 0b11*/ 0b00;
83+
static signed int AutoClock = 0b11;
8484
module_param(AutoClock, int, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
8585
MODULE_PARM_DESC(AutoClock, "Estimate Clock Frequency 0:Spec; 1:Once; 2:Auto");
8686

@@ -506,11 +506,13 @@ static signed int SearchArchitectureID(void)
506506
static void Query_Features(void *pArg)
507507
{
508508
INIT_ARG *iArg = (INIT_ARG *) pArg;
509-
/* volatile unsigned long long cntfrq; TODO*/
509+
volatile unsigned long long cntfrq;
510510

511511
iArg->Features->Info.Vendor.CRC = CRC_RESERVED;
512512
iArg->SMT_Count = 1;
513513
iArg->HypervisorID = HYPERV_NONE;
514+
515+
RDTSC64(cntfrq);
514516
/*TODO(Cycles)
515517
__asm__ __volatile__(
516518
"csrr %[cntfrq], mcycle" "\n\t"
@@ -539,14 +541,9 @@ static void Query_Features(void *pArg)
539541
#else
540542
iArg->Features->ACPI = 0;
541543
#endif
542-
/*
543544
iArg->Features->TSC = \
544545
iArg->Features->Inv_TSC = \
545546
iArg->Features->RDTSCP = cntfrq != 0;
546-
*/
547-
iArg->Features->TSC = \
548-
iArg->Features->Inv_TSC = \
549-
iArg->Features->RDTSCP = 0;
550547

551548
iArg->Features->PerfMon.FixCtrs = \
552549
iArg->Features->PerfMon.MonCtrs = \
@@ -1716,6 +1713,7 @@ static void Generic_Core_Counters_Clear(union SAVE_AREA_CORE *Save,
17161713

17171714
#define Counters_Generic(Core, T) \
17181715
({ \
1716+
RDTSC64(Core->Counter[T].TSC); \
17191717
/*TODO(Cycles) \
17201718
RDTSC_COUNTERx3(Core->Counter[T].TSC, \
17211719
pmevcntr2_el0:mcycle, Core->Counter[T].C0.UCC,\
@@ -1818,7 +1816,8 @@ static void Generic_Core_Counters_Clear(union SAVE_AREA_CORE *Save,
18181816

18191817
#define PKG_Counters_Generic(Core, T) \
18201818
({ \
1821-
/*TODO(Cycles) \
1819+
RDTSC64(PUBLIC(RO(Proc))->Counter[T].PCLK); \
1820+
/*TODO(CleanUp) \
18221821
volatile unsigned long long cntpct; \
18231822
__asm__ volatile \
18241823
( \

riscv64/corefreqm.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ void CallWith_RDTSC_RDPMC( RO(SHM_STRUCT) *RO(Shm),
5050
unsigned long arg )
5151
{
5252
struct SLICE_STRUCT *pSlice = &RO(Shm)->Cpu[cpu].Slice;
53+
54+
RDTSC64(pSlice->Counter[0].TSC);
5355
/*TODO(Cycles)
5456
RDTSC_PMCx1( pSlice->Counter[0].TSC,
5557
pmevcntr3_el0:mcycle,
5658
pSlice->Counter[0].INST );
5759
*/
5860
pSlice->Counter[0].INST &= INST_COUNTER_OVERFLOW;
61+
62+
RDTSC64(pSlice->Counter[1].TSC);
5963
/*TODO(Cycles)
6064
RDTSC_PMCx1( pSlice->Counter[1].TSC,
6165
pmevcntr3_el0:mcycle,
@@ -64,6 +68,8 @@ void CallWith_RDTSC_RDPMC( RO(SHM_STRUCT) *RO(Shm),
6468
pSlice->Counter[1].INST &= INST_COUNTER_OVERFLOW;
6569

6670
SliceFunc(RO(Shm), RW(Shm), cpu, arg);
71+
72+
RDTSC64(pSlice->Counter[2].TSC);
6773
/*TODO(Cycles)
6874
RDTSC_PMCx1( pSlice->Counter[2].TSC,
6975
pmevcntr3_el0:mcycle,
@@ -122,7 +128,8 @@ void Slice_Atomic(RO(SHM_STRUCT) *RO(Shm), RW(SHM_STRUCT) *RW(Shm),
122128
UNUSED(RW(Shm));
123129
register unsigned long loop = arg;
124130
do {
125-
/* __asm__ volatile
131+
__asm__ volatile("nop");
132+
/*TODO __asm__ volatile
126133
(
127134
"ldr x10, %[_err]" "\n\t"
128135
"1:" "\n\t"

0 commit comments

Comments
 (0)