Profiling timing shows that we can do interrupt checks with cost:

* about 2.0 secs per 1 billion checks if the counter is kept in memory
* about 0.5 secs per 1 billion checks if the counter is kept in register.
This commit is contained in:
Abdulaziz Ghuloum 2006-12-21 16:22:07 +03:00
parent 5615b03879
commit 67a850e712
7 changed files with 72 additions and 91 deletions

View File

@ -1,6 +1,4 @@
main: main.c
gcc -m64 -O3 -Wall main.c -o main
main: main.c int.s
gcc -Wall main.c int.s -o main
main.s: main.c
gcc -m64 -O3 -Wall -fomit-frame-pointer -fno-PIC -S main.c

34
lab/prof/int.s Normal file
View File

@ -0,0 +1,34 @@
.globl _interrupt_mem
_interrupt_mem:
movl 4(%esp), %eax
L_loop1:
subl $1, 0(%eax);
jz L_int1
jmp L_loop1
L_int1:
ret
.globl _interrupt_reg
_interrupt_reg:
movl 4(%esp), %eax
L_loop2:
subl $1, %eax;
jz L_int2
subl $1, %eax;
jz L_int2
subl $1, %eax;
jz L_int2
subl $1, %eax;
jz L_int2
subl $1, %eax;
jz L_int2
subl $1, %eax;
jz L_int2
subl $1, %eax;
jz L_int2
jmp L_loop2
L_int2:
ret

Binary file not shown.

View File

@ -1,14 +1,31 @@
#include <stdio.h>
long long foo(long long int x){
return x+1;
}
#include <stdlib.h>
int main(int argc, char** argv){
fprintf(stderr, "sizeof(long long int)=%ld\n",
sizeof(long long int));
long long int x = 57;
x = foo(x);
#include <string.h>
typedef struct pcb{
int counter;
} pcb;
extern void interrupt_mem(pcb*);
extern void interrupt_reg(int);
void usage(char* name){
fprintf(stderr, "Usage: %s [mem|reg]\n", name);
exit(-1);
}
int main(int argc, char** argv){
int most_positive_number = 0x7FFFFFFF;
if(argc != 2) usage(argv[0]);
if(strcmp(argv[1], "reg") == 0){
interrupt_reg(most_positive_number);
} else if(strcmp(argv[1], "mem") == 0){
pcb x;
x.counter = most_positive_number;
interrupt_mem(&x);
} else {
usage(argv[0]);
}
return 0;
}

View File

@ -1,77 +0,0 @@
.text
.globl _foo
_foo:
LFB3:
leaq 1(%rdi), %rax
ret
LFE3:
.cstring
LC0:
.ascii "sizeof(long long int)=%ld\12\0"
.text
.globl _main
_main:
LFB20:
subq $8, %rsp
LCFI0:
movl $8, %edx
leaq LC0(%rip), %rsi
movq ___stderrp@GOTPCREL(%rip), %rax
movq (%rax), %rdi
xorl %eax, %eax
call _fprintf
movl $-1, %edi
call _exit
LFE20:
.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
EH_frame1:
.set L$set$0,LECIE1-LSCIE1
.long L$set$0
LSCIE1:
.long 0x0
.byte 0x1
.ascii "zR\0"
.byte 0x1
.byte 0x78
.byte 0x10
.byte 0x1
.byte 0x10
.byte 0xc
.byte 0x7
.byte 0x8
.byte 0x90
.byte 0x1
.align 3
LECIE1:
.globl _foo.eh
_foo.eh:
LSFDE1:
.set L$set$1,LEFDE1-LASFDE1
.long L$set$1
LASFDE1:
.long LASFDE1-EH_frame1
.quad LFB3-.
.set L$set$2,LFE3-LFB3
.quad L$set$2
.byte 0x0
.align 3
LEFDE1:
.globl _main.eh
_main.eh:
LSFDE3:
.set L$set$3,LEFDE3-LASFDE3
.long L$set$3
LASFDE3:
.long LASFDE3-EH_frame1
.quad LFB20-.
.set L$set$4,LFE20-LFB20
.quad L$set$4
.byte 0x0
.byte 0x4
.set L$set$5,LCFI0-LFB20
.long L$set$5
.byte 0xe
.byte 0x10
.align 3
LEFDE3:
.subsections_via_symbols

BIN
lab/prof/plot.gcx Normal file

Binary file not shown.

9
lab/prof/times.txt Normal file
View File

@ -0,0 +1,9 @@
1 2.157
2 1.618
3 1.440
4 1.350
5 1.296
6 1.260
7 1.232