~samhsmith/AstraOS

42bebda867513dc9fb068eff46827f6017d4ed35 — Sam H Smith 2 years ago 64c99f2
changed time syscall
M dave_terminal/dave.c => dave_terminal/dave.c +1 -1
@@ 389,7 389,7 @@ void _start()
            u64 practical_column_count = 1;
            if(column_count > practical_column_count) { practical_column_count = column_count; }

            f64 time_frame_start = AOS_time_get_seconds();
            f64 time_frame_start = AOS_H_time_get_seconds();
            f64 when_in_second_frame_start = modulo(time_frame_start, 1.0);

            u8 draw_text_buffer[row_count * practical_column_count];

M ray2d/ray2d.c => ray2d/ray2d.c +5 -5
@@ 64,7 64,7 @@ else

}

    f64 start_time = AOS_time_get_seconds();
    f64 start_time = AOS_H_time_get_seconds();

    f64 square_x_control = 0.0;
    f64 square_y_control = 0.0;


@@ 78,9 78,9 @@ while(1)
    u16 surface_count = 1;
    if(is_running_as_ega)
    {
        f64 sec_before_call = AOS_time_get_seconds();
        f64 sec_before_call = AOS_H_time_get_seconds();
        surface_count = AOS_IPFC_call(ega_session_id, 0, 0, surfaces);
        f64 sec_after_call = AOS_time_get_seconds();
        f64 sec_after_call = AOS_H_time_get_seconds();
        AOS_H_printf("time to get surfaces via ipfc : %5.5lf ms\n", (sec_after_call - sec_before_call) * 1000.0);
    }



@@ 107,7 107,7 @@ while(1)
    if(surface_count) { fb_page_count = AOS_surface_acquire(surfaces[0], 0, 0); }
    if(surface_count && AOS_surface_acquire(surfaces[0], fb, fb_page_count))
    {
        f64 frame_start = AOS_time_get_seconds();
        f64 frame_start = AOS_H_time_get_seconds();
        f64 delta_time = frame_start - last_frame_time;
        last_frame_time = frame_start;



@@ 245,7 245,7 @@ while(1)
        pfy += dpfy;
        }
        AOS_surface_commit(surfaces[0]);
        f64 frame_end = AOS_time_get_seconds();
        f64 frame_end = AOS_H_time_get_seconds();
        AOS_H_printf("elf time : %10.10lf ms\n", (frame_end - frame_start) * 1000.0);
    }
}

M square_src/elf.c => square_src/elf.c +5 -5
@@ 64,7 64,7 @@ else

}

    f64 start_time = AOS_time_get_seconds();
    f64 start_time = AOS_H_time_get_seconds();

    f64 square_x_control = 0.0;
    f64 square_y_control = 0.0;


@@ 78,9 78,9 @@ while(1)
    u16 surface_count = 1;
    if(is_running_as_ega)
    {
        f64 sec_before_call = AOS_time_get_seconds();
        f64 sec_before_call = AOS_H_time_get_seconds();
        surface_count = AOS_IPFC_call(ega_session_id, 0, 0, surfaces);
        f64 sec_after_call = AOS_time_get_seconds();
        f64 sec_after_call = AOS_H_time_get_seconds();
        AOS_H_printf("time to get surfaces via ipfc : %5.5lf ms\n", (sec_after_call - sec_before_call) * 1000.0);
    }



@@ 107,7 107,7 @@ while(1)
    if(surface_count) { fb_page_count = AOS_surface_acquire(surfaces[0], 0, 0); }
    if(surface_count && AOS_surface_acquire(surfaces[0], fb, fb_page_count))
    {
        f64 frame_start = AOS_time_get_seconds();
        f64 frame_start = AOS_H_time_get_seconds();
        f64 delta_time = frame_start - last_frame_time;
        last_frame_time = frame_start;



@@ 245,7 245,7 @@ while(1)
        pfy += dpfy;
        }
        AOS_surface_commit(surfaces[0]);
        f64 frame_end = AOS_time_get_seconds();
        f64 frame_end = AOS_H_time_get_seconds();
        AOS_H_printf("elf time : %10.10lf ms\n", (frame_end - frame_start) * 1000.0);
    }
}

M src/syscall.c => src/syscall.c +37 -3
@@ 712,14 712,46 @@ void syscall_surface_consumer_fetch(u64 hart)
    rwlock_release_read(&KERNEL_PROCESS_ARRAY_RWLOCK);
}

void syscall_time_get_seconds(u64 hart, u64 mtime)
void syscall_get_cpu_time(u64 hart, u64 mtime)
{
    {
        volatile u64* mtimecmp = ((u64*)0x02004000) + hart;
        volatile u64* mtime = (u64*)0x0200bff8;
        u64 start_wait = *mtime;
        rwlock_acquire_read(&KERNEL_PROCESS_ARRAY_RWLOCK);
        u64 end_wait = *mtime;

        wait_time_acc[hart] += end_wait - start_wait;
        wait_time_times[hart] += 1;
    }
    Process* process = KERNEL_PROCESS_ARRAY[kernel_current_threads[hart].process_pid];
    Thread* current_thread = &process->threads[kernel_current_thread_tid[hart]];
    TrapFrame* frame = &current_thread->frame;

    frame->regs[10] = mtime;
    current_thread->program_counter += 4;
    rwlock_release_read(&KERNEL_PROCESS_ARRAY_RWLOCK);
}

void syscall_get_cpu_timer_frequency(u64 hart, u64 mtime)
{
    {
        volatile u64* mtimecmp = ((u64*)0x02004000) + hart;
        volatile u64* mtime = (u64*)0x0200bff8;
        u64 start_wait = *mtime;
        rwlock_acquire_read(&KERNEL_PROCESS_ARRAY_RWLOCK);
        u64 end_wait = *mtime;

        wait_time_acc[hart] += end_wait - start_wait;
        wait_time_times[hart] += 1;
    }
    Process* process = KERNEL_PROCESS_ARRAY[kernel_current_threads[hart].process_pid];
    Thread* current_thread = &process->threads[kernel_current_thread_tid[hart]];
    TrapFrame* frame = &current_thread->frame;

    *((f64*)&frame->regs[10]) = ((f64)mtime) / 10000000.0;
    frame->regs[10] = MACHINE_TIMER_SECOND;
    current_thread->program_counter += 4;
    rwlock_release_read(&KERNEL_PROCESS_ARRAY_RWLOCK);
}

void syscall_file_get_name(u64 hart)


@@ 2249,7 2281,7 @@ void do_syscall(TrapFrame* frame, u64 mtime, u64 hart)
    else if(call_num == 13)
    { syscall_surface_consumer_fetch(hart); }
    else if(call_num == 14)
    { syscall_time_get_seconds(hart, mtime); }
    { syscall_get_cpu_time(hart, mtime); }
    else if(call_num == 15)
    { syscall_file_get_name(hart); }
    else if(call_num == 23)


@@ 2310,6 2342,8 @@ void do_syscall(TrapFrame* frame, u64 mtime, u64 hart)
    { syscall_IPFC_call(hart, mtime); }
    else if(call_num == 53)
    { syscall_IPFC_return(hart, mtime); }
    else if(call_num == 54)
    { syscall_get_cpu_timer_frequency(hart, mtime); }
    else
    { printf("invalid syscall, we should handle this case but we don't\n"); while(1) {} }
}

M src/tempuser.c => src/tempuser.c +7 -7
@@ 687,20 687,20 @@ while(1) {
//            AOS_H_printf("kbd event: %u, scancode: %u\n", kbd_events[i].event, kbd_events[i].scancode);
        }
    }
//f64 pre_sleep = AOS_time_get_seconds();
//f64 pre_sleep = AOS_H_time_get_seconds();
    u64 AOS_wait_surface = 0;
    AOS_thread_awake_on_surface(&AOS_wait_surface, 1);
    AOS_thread_awake_on_mouse();
    AOS_thread_awake_on_keyboard();
    AOS_thread_awake_after_time(1000000);
    AOS_thread_sleep();
//AOS_H_printf("temp slept for %lf seconds\n", AOS_time_get_seconds() - pre_sleep);
//AOS_H_printf("temp slept for %lf seconds\n", AOS_H_time_get_seconds() - pre_sleep);

    Framebuffer* fb = 0x54000;
    u64 fb_page_count = AOS_surface_acquire(0, 0, 0);
    if(AOS_surface_acquire(0, fb, fb_page_count))
    {
        double time_frame_start = AOS_time_get_seconds();
        double time_frame_start = AOS_H_time_get_seconds();

        // Fetch from consumers and setup
        {


@@ 777,7 777,7 @@ while(1) {
        bottom_banner_y = 0;
        if(fb->height > 16) { bottom_banner_y = fb->height - 16; }

        f64 time_render_start = AOS_time_get_seconds();
        f64 time_render_start = AOS_H_time_get_seconds();
#if 1
        render_buffer = fb;
        atomic_s64_set(&render_work_done, 0);


@@ 922,7 922,7 @@ while(1) {
            }
        }
#endif
        f64 time_render_end = AOS_time_get_seconds();
        f64 time_render_end = AOS_H_time_get_seconds();
        //printf("it took %lf ms to render\n", (time_render_end - time_render_start)*1000.0);

        { // draw cursor


@@ 949,7 949,7 @@ while(1) {
        }

        // frame time, bottom right
        f64 time_frame_end = AOS_time_get_seconds();
        f64 time_frame_end = AOS_H_time_get_seconds();
        f64 frame_time = (time_frame_end-time_frame_start) *1000.0;
        rolling_frame_time = rolling_frame_time * 0.9 + frame_time * 0.1;
        frame_time = rolling_frame_time;


@@ 972,7 972,7 @@ while(1) {
        }

        // time since last frame, bottom right, above frametime
        f64 time_right_now = AOS_time_get_seconds();
        f64 time_right_now = AOS_H_time_get_seconds();
        f64 time_passed = (time_right_now-last_frame_time) *1000.0;
        rolling_time_passed = rolling_time_passed *0.9 + time_passed *0.1;
        time_passed = rolling_time_passed;

M userland/aos_helper.h => userland/aos_helper.h +4 -2
@@ 6,7 6,6 @@
#include "../common/types.h"
#include "aos_syscalls.h"


#ifdef __cplusplus
extern "C" {
#endif


@@ 980,6 979,9 @@ s32 AOS_H_fctprintf(void (*out)(char character, void* arg), void* arg, const cha
  return ret;
}


f64 AOS_H_time_get_seconds()
{
    return (f64)AOS_get_cpu_time() / (f64)AOS_get_cpu_timer_frequency();
}

#endif // _AOS_HELPER

M userland/aos_syscalls.h => userland/aos_syscalls.h +2 -1
@@ 57,7 57,8 @@ u64 AOS_surface_consumer_get_size(u64 consumer_slot, volatile u32* width, volati
u64 AOS_surface_consumer_set_size(u64 consumer_slot, u32 width, u32 height);
u64 AOS_surface_consumer_fetch(u64 consumer_slot, volatile AOS_Framebuffer* fb, u64 page_count);
 
f64 AOS_time_get_seconds();
u64 AOS_get_cpu_time();
u64 AOS_get_cpu_timer_frequency();
 
u64 AOS_is_valid_file_id(u64 file_id);
u64 AOS_is_valid_dir_id(u64 directory_id);

M userland/aos_syscalls.s => userland/aos_syscalls.s +8 -2
@@ 111,8 111,8 @@ AOS_surface_consumer_fetch:
    ecall
    ret

.global AOS_time_get_seconds
AOS_time_get_seconds:
.global AOS_get_cpu_time
AOS_get_cpu_time:
    addi a0, x0, 14
    ecall
    ret


@@ 376,3 376,9 @@ AOS_IPFC_return:
    ecall
    ret

.global AOS_get_cpu_timer_frequency
AOS_get_cpu_timer_frequency:
    addi a0, x0, 54
    ecall
    ret