benchmarks/riscv-splash2/utils/clone.c
/**
 * NOTE: the clone function has different signatures than
 * the linux system call
 */
the clone function has different signatures than
the linux system call
the clone function has different signatures than the linux system call
unsigned long __clone_rt(
    int   flags,
    void* child_stack,
    void* parent_tidptr,
    void* tls,
    void* child_tidptr
) {
    unsigned long idle_core = __get_idle_core();
    while(idle_core == -1);
    unsigned long current_core = __getmhartid();
    for(int i = 0; i < 32; i++) {
        context[idle_core].x[i] = context[current_core].x[i];
    }
    context[idle_core].x[2] = (unsigned long)child_stack;
    context[idle_core].x[4] = (unsigned long)tls;
    context[idle_core].epc  = __getmepc();
    context[idle_core].clear_child_tid = 0;
    if((flags & CLONE_CHILD_SETTID) != 0) {
        context[idle_core].set_child_tid = (unsigned long)child_tidptr;
        *(pid_t*)child_tidptr = idle_core + 1;
    }
    if((flags & CLONE_PARENT_SETTID) != 0) {
        *(pid_t*)parent_tidptr = idle_core + 1;
    }
    if((flags & CLONE_CHILD_CLEARTID) != 0) {
        context[idle_core].clear_child_tid = (unsigned long)child_tidptr;
    } else {
        context[idle_core].clear_child_tid = 0;
    }
    __atomic_exchange_n(&start_task[idle_core], 1, __ATOMIC_ACQ_REL);
    return idle_core + 1;
}
unsigned long __clone_rt ( int flags , void * child_stack , void * parent_tidptr , void * tls , void * child_tidptr ) { unsigned long idle_core = __get_idle_core ( ) ; while ( idle_core == -1 ) ; unsigned long current_core = __getmhartid ( ) ; for ( int i = 0 ; i < 32 ; i ++ ) { context [ idle_core ] . x [ i ] = context [ current_core ] . x [ i ] ; } context [ idle_core ] . x [ 2 ] = ( unsigned long ) child_stack ; context [ idle_core ] . x [ 4 ] = ( unsigned long ) tls ; context [ idle_core ] . epc = __getmepc ( ) ; context [ idle_core ] . clear_child_tid = 0 ; if ( ( flags & CLONE_CHILD_SETTID ) != 0 ) { context [ idle_core ] . set_child_tid = ( unsigned long ) child_tidptr ; * ( pid_t * ) child_tidptr = idle_core + 1 ; } if ( ( flags & CLONE_PARENT_SETTID ) != 0 ) { * ( pid_t * ) parent_tidptr = idle_core + 1 ; } if ( ( flags & CLONE_CHILD_CLEARTID ) != 0 ) { context [ idle_core ] . clear_child_tid = ( unsigned long ) child_tidptr ; } else { context [ idle_core ] . clear_child_tid = 0 ; } __atomic_exchange_n ( & start_task [ idle_core ] , 1 , __ATOMIC_ACQ_REL ) ; return idle_core + 1 ; }
NOTE: the clone function has different signatures than
 the linux system call
NOTE : the clone function has different signatures than the linux system call
// busy loop if no idle core found /* copy registers */