Ignore:
Timestamp:
Mar 28, 2018, 2:40:29 PM (4 years ago)
Author:
alain
Message:

Fix various bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/scheduler.c

    r436 r437  
    9797    list_entry_t * current;
    9898    list_entry_t * last;
     99    list_entry_t * root;
     100    bool_t         done;
    99101
    100102    // take lock protecting sheduler lists
    101103    spinlock_lock( &sched->lock );
    102104
    103     // first loop : scan the kernel threads list if not empty
     105    // first : scan the kernel threads list if not empty
    104106    if( list_is_empty( &sched->k_root ) == false )
    105107    {
     108        root    = &sched->k_root;
    106109        last    = sched->k_last;
    107         current = sched->k_last;
    108         do
     110        current = last;
     111        done    = false;
     112
     113        while( done == false )
    109114        {
    110115            // get next entry in kernel list
    111             current = list_next( &sched->k_root , current );
     116            current = current->next;
     117
     118            // check exit condition
     119            if( current == last ) done = true;
    112120
    113121            // skip the root that does not contain a thread
    114             if( current == NULL ) current = sched->k_root.next;
     122            if( current == root ) continue;
    115123
    116124            // get thread pointer for this entry
     
    120128            switch( thread->type )
    121129            {
    122                 case THREAD_IDLE: // skip IDLE thread
    123                 break;
    124 
    125                 case THREAD_RPC:  // RPC thread if non blocked and FIFO non-empty
     130                case THREAD_RPC:  // if non blocked and RPC FIFO non-empty
    126131                if( (thread->blocked == 0) &&
    127132                    (local_fifo_is_empty( &LOCAL_CLUSTER->rpc_fifo ) == 0) )
     
    132137                break;
    133138
    134                 default:          // DEV thread if non blocked and waiting queue non empty
     139                case THREAD_DEV:  // if non blocked and waiting queue non empty
    135140                if( (thread->blocked == 0) &&
    136141                    (xlist_is_empty( XPTR( local_cxy , &thread->chdev->wait_root)) == 0) )
     
    140145                }
    141146                break;
    142             }  // end switch type
    143         }
    144         while( current != last );
    145     }
    146 
    147     // second loop : scan the user threads list if not empty
     147
     148                default:
     149                break;
     150            }
     151        } // end loop on kernel threads
     152    } // end if kernel threads
     153
     154    // second : scan the user threads list if not empty
    148155    if( list_is_empty( &sched->u_root ) == false )
    149156    {
     157        root    = &sched->u_root;
    150158        last    = sched->u_last;
    151         current = sched->u_last;
    152         do
     159        current = last;
     160        done    = false;
     161
     162        while( done == false )
    153163        {
    154164            // get next entry in user list
    155             current = list_next( &sched->u_root , current );
     165            current = current->next;
     166
     167            // check exit condition
     168            if( current == last ) done = true;
    156169
    157170            // skip the root that does not contain a thread
    158             if( current == NULL ) current = sched->u_root.next;
     171            if( current == root ) continue;
    159172
    160173            // get thread pointer for this entry
     
    167180                return thread;
    168181            }
    169         }
    170         while( current != last );
    171     }
    172 
    173     // third : return idle thread if no runnable thread
     182        } // end loop on user threads
     183    } // end if user threads
     184
     185    // third : return idle thread if no other runnable thread
    174186    spinlock_unlock( &sched->lock );
    175187    return sched->idle;
     
    180192void sched_handle_signals( core_t * core )
    181193{
     194
    182195    list_entry_t * iter;
    183196    thread_t     * thread;
     
    214227            process = thread->process;
    215228
     229#if CONFIG_DEBUG_SCHED_HANDLE_SIGNALS
     230uint32_t cycle = (uint32_t)hal_get_cycles();
     231if( CONFIG_DEBUG_SCHED_HANDLE_SIGNALS < cycle )
     232printk("\n[DBG] %s : thread %x in proces %x must be deleted / cycle %d\n",
     233__FUNCTION__ , thread , process->pid , cycle );
     234#endif
    216235                // release FPU if required
    217236                if( thread->core->fpu_owner == thread )  thread->core->fpu_owner = NULL;
     
    232251
    233252#if CONFIG_DEBUG_SCHED_HANDLE_SIGNALS
    234 uint32_t cycle = (uint32_t)hal_get_cycles();
     253cycle = (uint32_t)hal_get_cycles();
    235254if( CONFIG_DEBUG_SCHED_HANDLE_SIGNALS < cycle )
    236 printk("\n[DBG] %s : thread %x deleted thread %x / cycle %d\n",
    237 __FUNCTION__ , CURRENT_THREAD , thread , cycle );
     255printk("\n[DBG] %s : thread %x in process %x has been deleted / cycle %d\n",
     256__FUNCTION__ , thread , process->pid , cycle );
    238257#endif
    239258            // destroy process descriptor if no more threads
     
    246265cycle = (uint32_t)hal_get_cycles();
    247266if( CONFIG_DEBUG_SCHED_HANDLE_SIGNALS < cycle )
    248 printk("\n[DBG] %s : thread %x deleted process %x / cycle %d\n",
    249 __FUNCTION__ , CURRENT_THREAD , process , cycle );
     267printk("\n[DBG] %s : process %x has been deleted / cycle %d\n",
     268__FUNCTION__ , process->pid , cycle );
    250269#endif
    251270
     
    374393    remote_spinlock_lock_busy( lock_xp , &save_sr );
    375394
    376     nolock_printk("\n***** scheduler state for core[%x,%d] / cycle %d / current = (%x,%x)\n",
    377             local_cxy , core->lid, (uint32_t)hal_get_cycles(),
    378             sched->current->process->pid , sched->current->trdid );
     395    nolock_printk("\n***** threads on core[%x,%d] / current %x / cycle %d\n",
     396            local_cxy , core->lid, sched->current, (uint32_t)hal_get_cycles() );
    379397
    380398    // display kernel threads
     
    390408        else
    391409        {
    392             nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X \n",
     410            nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X\n",
    393411            thread_type_str( thread->type ), thread->process->pid, thread->trdid,
    394             thread, thread->blocked, thread->flags  );
     412            thread, thread->blocked, thread->flags );
    395413        }
    396414    }
Note: See TracChangeset for help on using the changeset viewer.