cpu_speed.s 1.62 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

	.global	has_time_stamp_counter
has_time_stamp_counter:
	push	%ebx
	push	%ecx
	push	%edx

	pushfl
	mov	$0x200000,%eax
	pop	%ebx
	xor	%ebx,%eax
	push	%eax
	popfl
	pushfl
	pop	%eax
	
	xor	%ebx,%eax
	jz	no_cpuid_instruction

	mov	$1,%eax

	.byte	0x0f,0xa2 # cpuid
	
	shr	$4,%edx
	mov	$1,%eax
	and	%edx,%eax

no_cpuid_instruction:
	pop	%edx
	pop	%ecx
	pop	%ebx
	ret

	.global	read_time_stamp_counter
read_time_stamp_counter:
	push	%ecx
	push	%edx
	movl	12(%esp),%ecx

	.byte	0x0f,0x31 # rdtsc

	movl	%eax,0(%ecx)
	movl	%edx,4(%ecx)
	pop	%edx
	pop	%ecx
	ret

	.global	compute_profile_overhead
compute_profile_overhead:
	jmp	compute_profile_overhead_

profile_:
	push	%eax
	push	%edx

	.byte	0x0f,0x31 # rdtsc

	sub	g_time_lo,%eax
	sbb	g_time_hi,%edx
	add	%eax,p_time_lo
	adc	%edx,p_time_hi

	.byte	0x0f,0x31 # rdtsc

	mov	%edx,g_time_hi
	pop	%edx
	mov	%eax,g_time_lo
	pop	%eax
	ret

compute_profile_overhead_:
	mov	4(%esp),%eax
	push	%ebx
	push	%ecx
	push	%edx
	push	%ebp
	
	xor	%ecx,%ecx
	xor	%edx,%edx
	mov	$100000,%ebx
	
	call	profile_
	mov	%ecx,p_time_lo
	mov	%edx,p_time_hi

compute_profile_overhead_lp1:
	lea	p_time_lo,%ebp
	call	profile_

	add	%ecx,%ecx
	add	%edx,%edx
	
	sub	$1,%ebx
	jne	compute_profile_overhead_lp1

	mov	p_time_lo,%ecx
	mov	p_time_hi,%edx
	mov	%ecx,0(%eax)
	mov	%edx,4(%eax)

	xor	%ecx,%ecx
	xor	%edx,%edx
	mov	$100000,%ebx
	
	call	profile_
	mov	%ecx,p_time_lo
	mov	%edx,p_time_hi

compute_profile_overhead_lp2:
	add	%ecx,%ecx
	add	%edx,%edx
	
	sub	$1,%ebx
	jne	compute_profile_overhead_lp2

	call	profile_

	mov	p_time_lo,%ecx
	mov	p_time_hi,%edx
	mov	%ecx,8(%eax)
	mov	%edx,12(%eax)

	pop	%ebp
	pop	%edx
	pop	%ecx
	pop	%ebx
	ret