~samhsmith/AstraOS

a223aff754364ea494a7eb1b0c4a030b6b6f6de6 — Sam H Smith 2 years ago 8ff107e
fixed locking perf in tempuser
5 files changed, 45 insertions(+), 14 deletions(-)

M square_src/elf.c
M src/kernel.c
M src/log.c
M src/syscall.c
M src/tempuser.c
M square_src/elf.c => square_src/elf.c +2 -0
@@ 88,6 88,7 @@ while(1)
        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);
    }
#if 1
    else if(is_running_as_twa)
    {
        f64 sec_before_call = AOS_H_time_get_seconds();


@@ 95,6 96,7 @@ while(1)
        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);
    }
#endif

    AOS_thread_awake_on_surface(&surfaces, surface_count);
    AOS_thread_sleep();

M src/kernel.c => src/kernel.c +2 -2
@@ 576,7 576,7 @@ u64 m_trap(
                            KernelLogEntry entry = KERNEL_LOG[(log_index - i) % KERNEL_LOG_SIZE];
                            if(entry.is_kernel)
                            {
                                printf("%3.3llu) H:%llu - T:%llu | %s:%llu - %s\n",
                                printf("%3.3llu) H:%llu - T: %llu | %s:%llu - %s\n",
                                       log_entry_counter++,
                                       entry.hart,
                                       entry.time,


@@ 586,7 586,7 @@ u64 m_trap(
                            }
                            else
                            {
                                printf("%3.3llu) H:%llu - T:%llu - PID:%llu - TID:%llu | %s:%llu - %s\n",
                                printf("%3.3llu) H:%llu - T: %llu - PID:%llu - TID:%llu | %s:%llu - %s\n",
                                       log_entry_counter++,
                                       entry.hart,
                                       entry.time,

M src/log.c => src/log.c +1 -1
@@ 11,7 11,7 @@ typedef struct
    u8 is_kernel;
} KernelLogEntry;

#define KERNEL_LOG_SIZE 400
#define KERNEL_LOG_SIZE 800

KernelLogEntry KERNEL_LOG[KERNEL_LOG_SIZE];
atomic_s64 KERNEL_LOG_INDEX;

M src/syscall.c => src/syscall.c +10 -0
@@ 2163,6 2163,11 @@ void syscall_IPFC_call(u64 hart, u64 mtime)
    current_thread->IPFC_handler_index = handler_index;
    current_thread->is_running = 0;

    kernel_log_user(hart,
                    kernel_current_threads[hart].process_pid,
                    kernel_current_thread_tid[hart],
                    "thread called ipfc");

    rwlock_release_write(&KERNEL_PROCESS_ARRAY_RWLOCK);
    rwlock_acquire_read(&KERNEL_PROCESS_ARRAY_RWLOCK);
    kernel_choose_new_thread(mtime, hart);


@@ 2248,6 2253,11 @@ void syscall_IPFC_return(u64 hart, u64 mtime)
    else
    { rwlock_release_write(&process->process_lock); }

    kernel_log_user(hart,
                    kernel_current_threads[hart].process_pid,
                    kernel_current_thread_tid[hart],
                    "thread returned ipfc");

    kernel_choose_new_thread(mtime, hart);
    rwlock_release_read(&KERNEL_PROCESS_ARRAY_RWLOCK);
}

M src/tempuser.c => src/tempuser.c +30 -11
@@ 9,6 9,7 @@

typedef struct
{
    Spinlock lock;
    u16 other_surface_slot;
    u64 window_handle;
    s64 x;


@@ 380,7 381,7 @@ void render_thread_entry(u64 thread_number)
    }
}

Spinlock thunder_lock;
RWLock thunder_lock;
const char* TWA_IPFC_API_NAME = "thunder_windowed_application_ipfc_api_v1";
// f0 is create window
// f1 is destroy window


@@ 391,10 392,13 @@ void thunder_windowed_application_ipfc_api_entry(u64 source_pid, u16 function_in
    __asm__(".option norelax");
    __asm__("la gp, _global_pointer");
    __asm__(".option relax");
    spinlock_acquire(&thunder_lock);

    rwlock_acquire_read(&thunder_lock);

    if(function_index == 0)
    {
        rwlock_release_read(&thunder_lock);
        rwlock_acquire_write(&thunder_lock);
        AOS_H_printf("new window! from pid %llu\n", source_pid);
        if(window_count + 1 < 84) // can allocate new window
        {


@@ 432,12 436,12 @@ void thunder_windowed_application_ipfc_api_entry(u64 source_pid, u16 function_in
                }
                else { AOS_H_printf("Failed to create consumer for PID: %llu\n", source_pid); }
            }
            spinlock_release(&thunder_lock);
            rwlock_release_write(&thunder_lock);
            AOS_IPFC_return(1);
        }
        else
        {
            spinlock_release(&thunder_lock);
            rwlock_release_write(&thunder_lock);
            AOS_IPFC_return(0);
        }
    }


@@ 448,6 452,9 @@ void thunder_windowed_application_ipfc_api_entry(u64 source_pid, u16 function_in
        AOS_H_printf("destroy window with handle=%llu! from pid %llu\n", window_handle, source_pid);
        // destroy thingy

        rwlock_release_read(&thunder_lock);
        rwlock_acquire_write(&thunder_lock);

        u64 destroyed = 0;

        for(u64 i = 0; i < window_count; i++)


@@ 471,7 478,7 @@ void thunder_windowed_application_ipfc_api_entry(u64 source_pid, u16 function_in
            window_count--;
        }

        spinlock_release(&thunder_lock);
        rwlock_release_write(&thunder_lock);
        AOS_IPFC_return(destroyed);
    }
    else if(function_index == 2)


@@ 491,14 498,14 @@ void thunder_windowed_application_ipfc_api_entry(u64 source_pid, u16 function_in
            { continue; }

            copy_to[0] = windows[i].other_surface_slot;
            spinlock_release(&thunder_lock);
            rwlock_release_read(&thunder_lock);
            AOS_IPFC_return(1);
        }
        spinlock_release(&thunder_lock);
        rwlock_release_read(&thunder_lock);
        AOS_IPFC_return(0);
    }

    spinlock_release(&thunder_lock);
    rwlock_release_read(&thunder_lock);
    AOS_IPFC_return(0);
}



@@ 515,7 522,7 @@ void program_loader_program(u64 drive1_partitions_directory)

    spinlock_create(&tempuser_printout_lock);
    spinlock_create(&thunder_lock);
    spinlock_acquire(&thunder_lock);
    rwlock_acquire_read(&thunder_lock);
    render_work_semaphore = AOS_semaphore_create(0, THREAD_COUNT * JOBS_PER_THREAD);
    render_work_done_semaphore = AOS_semaphore_create(0, 1);
    {


@@ 561,6 568,8 @@ void program_loader_program(u64 drive1_partitions_directory)
while(1) {

    { // Check for program not alive's
        rwlock_release_read(&thunder_lock);
        rwlock_acquire_write(&thunder_lock);
        for(u64 i = 0; i < window_count; i++)
        {
            if(AOS_process_is_alive(windows[i].pid))


@@ 579,6 588,8 @@ while(1) {
            }
            window_count--;
        }
        rwlock_release_write(&thunder_lock);
        rwlock_acquire_read(&thunder_lock);
    }

#if 0


@@ 624,6 635,8 @@ while(1) {
    }

    { // Mouse events
        rwlock_release_read(&thunder_lock);
        rwlock_acquire_write(&thunder_lock);
        u64 mouse_event_count = AOS_get_rawmouse_events(0, 0);
        AOS_RawMouseEvent mouse_events[mouse_event_count];
        mouse_event_count = AOS_get_rawmouse_events(mouse_events, mouse_event_count);


@@ 703,6 716,8 @@ while(1) {
                is_resizing_window = 0;
            }
        }
        rwlock_release_write(&thunder_lock);
        rwlock_acquire_read(&thunder_lock);
    }

    { // Keyboard events


@@ 811,9 826,9 @@ while(1) {
    AOS_thread_awake_on_mouse();
    AOS_thread_awake_on_keyboard();
    AOS_thread_awake_after_time(1000000);
    spinlock_release(&thunder_lock);
    rwlock_release_read(&thunder_lock);
    AOS_thread_sleep();
    spinlock_acquire(&thunder_lock);
    rwlock_acquire_read(&thunder_lock);
//AOS_H_printf("temp slept for %lf seconds\n", AOS_H_time_get_seconds() - pre_sleep);

    Framebuffer* fb = 0x54000;


@@ 1121,6 1136,8 @@ while(1) {

        // move windows and resize them
        {
            rwlock_release_read(&thunder_lock);
            rwlock_acquire_write(&thunder_lock);
            for(u64 i = 0; i < window_count; i++)
            {
                windows[i].x = windows[i].new_x;


@@ 1128,6 1145,8 @@ while(1) {
                windows[i].width = windows[i].new_width;
                windows[i].height = windows[i].new_height;
            }
            rwlock_release_write(&thunder_lock);
            rwlock_acquire_read(&thunder_lock);
        }

        cursor_x = new_cursor_x;