init: v1.0.0
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
# In linux
|
||||
```
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static long long GetThreadCpuTimeNs() {
|
||||
struct timespec t;
|
||||
if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t)) {
|
||||
perror("clock_gettime");
|
||||
return 0;
|
||||
}
|
||||
return t.tv_nsec;
|
||||
}
|
||||
```
|
||||
Makov测试熵估计0.5-0.6
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "textflag.h"
|
||||
|
||||
|
||||
TEXT ·GetCPUTimeStamp(SB), NOSPLIT, $0
|
||||
RDTSCP // save time stamp counter in DX:AX
|
||||
SHLQ $32, DX
|
||||
ORQ DX, AX
|
||||
MOVQ AX, res+0(FP)
|
||||
RET
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "textflag.h"
|
||||
|
||||
|
||||
TEXT ·GetCPUTimeStamp(SB), NOSPLIT, $0
|
||||
MRS CNTVCT_EL0, R0
|
||||
MOVD R0, res+0(FP)
|
||||
RET
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
//go:build amd64 || arm64
|
||||
// +build amd64 arm64
|
||||
|
||||
package rdtsc
|
||||
|
||||
const SupportRDTSC = true
|
||||
|
||||
//go:noescape
|
||||
func GetCPUTimeStamp() uint64
|
||||
@@ -0,0 +1,9 @@
|
||||
//go:build !amd64 && !arm64
|
||||
|
||||
package rdtsc
|
||||
|
||||
const SupportRDTSC = false
|
||||
|
||||
func GetCPUTimeStamp() uint64 {
|
||||
panic("unsupported")
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package rdtsc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRDTSC(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
fmt.Printf("%x\n", GetCPUTimeStamp())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user