History

use proper serialization; use RDTSCP if possible

Sigrid Solveig Haflínudóttir committed 6 years ago

Commit bbdcad51 parent cce6dfb3 files · +55 −5Browse files

Unified · Split

3 files
  1. b.c +26 −0
  2. b.h +4 −4
  3. b_amd64.s +25 −1
b.c+26−0
@@ -13,6 +13,19 @@ enum { · 12 unmodified lines
1313
1414 static uvlong adj;
1515
16+typedef struct Res {
17+ ulong ax, bx, cx, dx;
18+}Res;
19+
20+Res cpuid(ulong ax, ulong cx);
21+
22+void _tstart(uvlong *c);
23+void _tend(uvlong *c);
24+void _tstartp(uvlong *c);
25+void _tendp(uvlong *c);
26+void (*tstart)(uvlong *c);
27+void (*tend)(uvlong *c);
28+
1629 uvlong
1730 cycles2ns(uvlong x)
1831 {
@@ -47,10 +60,23 @@ static int · 28 unmodified lines
4760 void
4861 benchinit(B *b, char *name)
4962 {
63+ Res r;
5064 int i;
5165
5266 fmtinstall(L'σ', σfmt);
5367 fmtinstall(L'τ', τfmt);
68+
69+ if(tstart == nil){
70+ r = cpuid(0x80000001, 2);
71+ if((r.dx & (1<<27)) != 0){
72+ tstart = _tstartp;
73+ tend = _tendp;
74+ }else{
75+ tstart = _tstart;
76+ tend = _tend;
77+ }
78+ }
79+
5480 memset(b, 0, sizeof(*b));
5581 b->name = name;
5682 b->n = b->nc = Bstepmin;
b.h+4−4
@@ -24,11 +24,11 @@ struct B { · 23 unmodified lines
2424
2525 /* private */
2626 void benchstep(B *b);
27−void _tstart(uvlong *c);
28−void _tend(uvlong *c);
27+extern void (*tstart)(uvlong *c);
28+extern void (*tend)(uvlong *c);
2929
3030 /* public */
3131 void benchinit(B *b, char *name);
3232 void benchprint(B *b, int nb, int fd);
33−#define benchin(b) do{ _tstart(&(b)->tin); }while(0)
34−#define benchout(b) do{ _tend(&(b)->tout); benchstep(b); }while(0)
33+#define benchin(b) do{ tstart(&(b)->tin); }while(0)
34+#define benchout(b) do{ tend(&(b)->tout); benchstep(b); }while(0)
b_amd64.s+25−1
@@ -1,13 +1,37 @@
11 TEXT _tstart(SB), 1, $0
2− LFENCE
2+ CPUID
33 RDTSC
44 MOVL AX, 0(RARG)
55 MOVL DX, 4(RARG)
66 RET
77
88 TEXT _tend(SB), 1, $0
9+ CPUID
910 RDTSC
1011 MOVL AX, 0(RARG)
1112 MOVL DX, 4(RARG)
13+ RET
14+
15+TEXT _tstartp(SB), 1, $0
16+ CPUID
17+ WORD $0x010f; BYTE $0xf9 // RDTSCP
18+ MOVL AX, 0(RARG)
19+ MOVL DX, 4(RARG)
20+ RET
21+
22+TEXT _tendp(SB), 1, $0
23+ WORD $0x010f; BYTE $0xf9 // RDTSCP
24+ MOVL AX, 0(RARG)
25+ MOVL DX, 4(RARG)
26+ CPUID
27+ RET
28+
29+TEXT cpuid(SB), 1, $0
30+ MOVL ax+8(FP), AX
31+ MOVL cx+16(FP), CX
1232 CPUID
33+ MOVL AX, 0(BP)
34+ MOVL BX, 4(BP)
35+ MOVL CX, 8(BP)
36+ MOVL DX, 12(BP)
1337 RET

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t