Changeset 5dcee525 in mainline


Ignore:
Timestamp:
2007-07-29T13:50:20Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
83a5cba
Parents:
d1e9321
Message:

Replace the threads_btree B+tree with an AVL tree. The new variable is called
threads_tree. For printing list of threads, use the new AVL tree walker
mechanism.

This solves half of ticket #48.

Location:
kernel/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/proc/thread.h

    rd1e9321 r5dcee525  
    4242#include <synch/rwlock.h>
    4343#include <synch/spinlock.h>
    44 #include <adt/btree.h>
     44#include <adt/avl.h>
    4545#include <mm/slab.h>
    4646#include <arch/cpu.h>
     
    9191        link_t wq_link;         /**< Wait queue link. */
    9292        link_t th_link;         /**< Links to threads within containing task. */
     93
     94        /** Threads linkage to the threads_tree. */
     95        avltree_node_t threads_tree_node;
    9396       
    9497        /** Lock protecting thread structure.
     
    205208/** Thread list lock.
    206209 *
    207  * This lock protects all link_t structures chained in threads_head.
     210 * This lock protects the threads_tree.
    208211 * Must be acquired before T.lock for each T of type thread_t.
    209212 *
     
    211214SPINLOCK_EXTERN(threads_lock);
    212215
    213 /** B+tree containing all threads. */
    214 extern btree_t threads_btree;
     216/** AVL tree containing all threads. */
     217extern avltree_t threads_tree;
    215218
    216219extern void thread_init(void);
  • kernel/generic/src/proc/thread.c

    rd1e9321 r5dcee525  
    5252#include <func.h>
    5353#include <context.h>
    54 #include <adt/btree.h>
     54#include <adt/avl.h>
    5555#include <adt/list.h>
    5656#include <time/clock.h>
     
    8282};
    8383
    84 /** Lock protecting the threads_btree B+tree.
     84/** Lock protecting the threads_tree AVL tree.
    8585 *
    8686 * For locking rules, see declaration thereof.
     
    8888SPINLOCK_INITIALIZE(threads_lock);
    8989
    90 /** B+tree of all threads.
    91  *
    92  * When a thread is found in the threads_btree B+tree, it is guaranteed to
     90/** ALV tree of all threads.
     91 *
     92 * When a thread is found in the threads_tree AVL tree, it is guaranteed to
    9393 * exist as long as the threads_lock is held.
    9494 */
    95 btree_t threads_btree;         
     95avltree_t threads_tree;         
    9696
    9797SPINLOCK_INITIALIZE(tidlock);
     
    213213#endif
    214214
    215         btree_create(&threads_btree);
     215        avltree_create(&threads_tree);
    216216}
    217217
     
    340340        t->fpu_context_engaged = 0;
    341341
     342        avltree_node_initialize(&t->threads_tree_node);
     343        t->threads_tree_node.key = (uintptr_t) t;
     344
    342345        /* might depend on previous initialization */
    343346        thread_create_arch(t); 
     
    369372
    370373        spinlock_lock(&threads_lock);
    371         btree_remove(&threads_btree, (btree_key_t) ((uintptr_t ) t), NULL);
     374        avltree_delete(&threads_tree, &t->threads_tree_node);
    372375        spinlock_unlock(&threads_lock);
    373376
     
    392395 *
    393396 * Attach the thread structure to the current task and make it visible in the
    394  * threads_btree.
     397 * threads_tree.
    395398 *
    396399 * @param t     Thread to be attached to the task.
     
    415418         */
    416419        spinlock_lock(&threads_lock);
    417         btree_insert(&threads_btree, (btree_key_t) ((uintptr_t) t), (void *) t,
    418             NULL);
     420        avltree_insert(&threads_tree, &t->threads_tree_node);
    419421        spinlock_unlock(&threads_lock);
    420422       
     
    576578}
    577579
     580static void thread_walker(avltree_node_t *node)
     581{
     582        thread_t *t;
     583               
     584        t = avltree_get_instance(node, thread_t, threads_tree_node);
     585
     586        uint64_t cycles;
     587        char suffix;
     588        order(t->cycles, &cycles, &suffix);
     589                       
     590        printf("%-6llu %-10s %#10zx %-8s %#10zx %-3ld %#10zx %#10zx %9llu%c ",
     591            t->tid, t->name, t, thread_states[t->state], t->task,
     592            t->task->context, t->thread_code, t->kstack, cycles, suffix);
     593                       
     594        if (t->cpu)
     595                printf("%-4zd", t->cpu->id);
     596        else
     597                printf("none");
     598                       
     599        if (t->state == Sleeping)
     600                printf(" %#10zx", t->sleep_queue);
     601                       
     602        printf("\n");
     603}
     604
    578605/** Print list of threads debug info */
    579606void thread_print_list(void)
    580607{
    581         link_t *cur;
    582608        ipl_t ipl;
    583609       
     
    591617            "-- ---------- ---------- ---- ---------\n");
    592618
    593         for (cur = threads_btree.leaf_head.next;
    594             cur != &threads_btree.leaf_head; cur = cur->next) {
    595                 btree_node_t *node;
    596                 unsigned int i;
    597 
    598                 node = list_get_instance(cur, btree_node_t, leaf_link);
    599                 for (i = 0; i < node->keys; i++) {
    600                         thread_t *t;
    601                
    602                         t = (thread_t *) node->value[i];
    603                        
    604                         uint64_t cycles;
    605                         char suffix;
    606                         order(t->cycles, &cycles, &suffix);
    607                        
    608                         printf("%-6llu %-10s %#10zx %-8s %#10zx %-3ld %#10zx "
    609                             "%#10zx %9llu%c ", t->tid, t->name, t,
    610                             thread_states[t->state], t->task, t->task->context,
    611                             t->thread_code, t->kstack, cycles, suffix);
    612                        
    613                         if (t->cpu)
    614                                 printf("%-4zd", t->cpu->id);
    615                         else
    616                                 printf("none");
    617                        
    618                         if (t->state == Sleeping)
    619                                 printf(" %#10zx", t->sleep_queue);
    620                        
    621                         printf("\n");
    622                 }
    623         }
     619        avltree_walk(&threads_tree, thread_walker);
    624620
    625621        spinlock_unlock(&threads_lock);
     
    638634bool thread_exists(thread_t *t)
    639635{
    640         btree_node_t *leaf;
    641        
    642         return btree_search(&threads_btree, (btree_key_t) ((uintptr_t) t),
    643             &leaf) != NULL;
     636        avltree_node_t *node;
     637
     638        node = avltree_search(&threads_tree, (avltree_key_t) ((uintptr_t) t));
     639       
     640        return node != NULL;
    644641}
    645642
Note: See TracChangeset for help on using the changeset viewer.