flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Performance of SYSENTER

Author
Thread Post new topic Reply to topic
l4m2



Joined: 15 Jan 2015
Posts: 674
l4m2 19 Nov 2021, 18:59
I'm testing SYSENTER performance and it turns out that each call takes 54.602287 cycles (1M calls).
0. Is this code correct?
1. Is this treated fast enough?
1.5. I test this due to interest to online judge of special problems with lots of interactives. Usual solutions compile the interactive lib together, making it easily attacked.
2. I run on virtualbox. Does that lead to difference to real computer?
2.5. I was searching for address of HPET but failed and fall back to RDTSC.
Code:
        org $7c00
        cli
        in al,0x92
        or al,0000_0010B
        out 0x92,al
        lgdt [gdt_ptr]
        mov eax, cr0
        inc eax
        mov cr0, eax
        mov ax, 16
        mov ds, ax
        mov ss, ax
        jmp 8:x32
        
        use32
x32:    mov ecx, $174
        xor edx, edx
        mov eax, 8
        wrmsr
        mov eax, 0x7c00
        inc ecx
        wrmsr
        mov eax, intx
        inc ecx
        wrmsr
        
        mov edx, run
        sysexit ; Yes I use SYSEXIT to go to ring3
        
intx:   sysexit

run:    rdtsc
        mov esi, eax
        mov edi, edx
        mov ebx, 1000000
        mov edx, .lp
.lp:    sub ebx, 1
        jz .ok
        sysenter
        
.ok:    rdtsc
        sub eax, esi
        sbb edx, edi
        mov ebx, $b8100
        call print
        mov eax, edx
        call print
        
        jmp $
        
print:  mov cl, al
        and cl, $F
        cmp cl, 10
        jb .ov
        add cl, 7
.ov:    add cl, 48
        mov [ebx], cl
        sub ebx, 2
        shr eax, 4
        jnz print
        sub ebx, 2
        ret
        
        align 8
GDT_BASE:
        dd 0, 0
        dd $FFFF, $00CF9A00
        dd $FFFF, $00CF9200
        dd $FFFF, $00CF9A00 ; No actual protection here
        dd $FFFF, $00CF9200
        GDT_LIMIT = $-GDT_BASE-1
        
        align 8
gdt_ptr:
        dw GDT_LIMIT
        dd GDT_BASE
        
        db $7dfe-$ dup $90
        dw $aa55    
Post 19 Nov 2021, 18:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 19 Nov 2021, 22:57
You won't get good timing results from a VM.
Post 19 Nov 2021, 22:57
View user's profile Send private message Visit poster's website Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 674
l4m2 20 Nov 2021, 04:06
revolution wrote:
You won't get good timing results from a VM.
[s]I went to another real machine and it restarts forever, seems triple fault[/s](work on an old computer, moved to another thread)
On an old one, sysenter/sysexit is 142.189327, int n(real mode) is 649.966513, call/ret(no ring switch) is 78.724625, no call is 2.000215
Post 20 Nov 2021, 04:06
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.