Changeset ef1eab7 in mainline for kernel/generic/src/sysinfo/stats.c


Ignore:
Timestamp:
2018-11-03T21:36:39Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
aab5e46
Parents:
ad2cf04
Message:

Replace AVL trees in kernel with ordered dictionary.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/sysinfo/stats.c

    rad2cf04 ref1eab7  
    22 * Copyright (c) 2010 Stanislav Kozina
    33 * Copyright (c) 2010 Martin Decky
     4 * Copyright (c) 2018 Jiri Svoboda
    45 * All rights reserved.
    56 *
     
    123124}
    124125
    125 /** Count number of nodes in an AVL tree
    126  *
    127  * AVL tree walker for counting nodes.
    128  *
    129  * @param node AVL tree node (unused).
    130  * @param arg  Pointer to the counter (size_t).
    131  *
    132  * @param Always true (continue the walk).
    133  *
    134  */
    135 static bool avl_count_walker(avltree_node_t *node, void *arg)
    136 {
    137         size_t *count = (size_t *) arg;
    138         (*count)++;
    139 
    140         return true;
    141 }
    142 
    143126/** Get the size of a virtual address space
    144127 *
     
    245228}
    246229
    247 /** Gather statistics of all tasks
    248  *
    249  * AVL task tree walker for gathering task statistics. Interrupts should
    250  * be already disabled while walking the tree.
    251  *
    252  * @param node AVL task tree node.
    253  * @param arg  Pointer to the iterator into the array of stats_task_t.
    254  *
    255  * @param Always true (continue the walk).
    256  *
    257  */
    258 static bool task_serialize_walker(avltree_node_t *node, void *arg)
    259 {
    260         stats_task_t **iterator = (stats_task_t **) arg;
    261         task_t *task = avltree_get_instance(node, task_t, tasks_tree_node);
    262 
    263         /* Interrupts are already disabled */
    264         irq_spinlock_lock(&(task->lock), false);
    265 
    266         /* Record the statistics and increment the iterator */
    267         produce_stats_task(task, *iterator);
    268         (*iterator)++;
    269 
    270         irq_spinlock_unlock(&(task->lock), false);
    271 
    272         return true;
    273 }
    274 
    275230/** Get task statistics
    276231 *
     
    290245        irq_spinlock_lock(&tasks_lock, true);
    291246
    292         /* First walk the task tree to count the tasks */
    293         size_t count = 0;
    294         avltree_walk(&tasks_tree, avl_count_walker, (void *) &count);
     247        /* Count the tasks */
     248        size_t count = odict_count(&tasks);
    295249
    296250        if (count == 0) {
     
    315269        }
    316270
    317         /* Walk tha task tree again to gather the statistics */
    318         stats_task_t *iterator = stats_tasks;
    319         avltree_walk(&tasks_tree, task_serialize_walker, (void *) &iterator);
     271        /* Gather the statistics for each task */
     272        size_t i = 0;
     273        odlink_t *odlink = odict_first(&tasks);
     274        while (odlink != NULL) {
     275                task_t *task = odict_get_instance(odlink, task_t, ltasks);
     276
     277                /* Interrupts are already disabled */
     278                irq_spinlock_lock(&(task->lock), false);
     279
     280                /* Record the statistics and increment the index */
     281                produce_stats_task(task, &stats_tasks[i]);
     282                i++;
     283
     284                irq_spinlock_unlock(&(task->lock), false);
     285                odlink = odict_next(odlink, &tasks);
     286        }
    320287
    321288        irq_spinlock_unlock(&tasks_lock, true);
     
    351318}
    352319
    353 /** Gather statistics of all threads
    354  *
    355  * AVL three tree walker for gathering thread statistics. Interrupts should
    356  * be already disabled while walking the tree.
    357  *
    358  * @param node AVL thread tree node.
    359  * @param arg  Pointer to the iterator into the array of thread statistics.
    360  *
    361  * @param Always true (continue the walk).
    362  *
    363  */
    364 static bool thread_serialize_walker(avltree_node_t *node, void *arg)
    365 {
    366         stats_thread_t **iterator = (stats_thread_t **) arg;
    367         thread_t *thread = avltree_get_instance(node, thread_t, threads_tree_node);
    368 
    369         /* Interrupts are already disabled */
    370         irq_spinlock_lock(&thread->lock, false);
    371 
    372         /* Record the statistics and increment the iterator */
    373         produce_stats_thread(thread, *iterator);
    374         (*iterator)++;
    375 
    376         irq_spinlock_unlock(&thread->lock, false);
    377 
    378         return true;
    379 }
    380 
    381320/** Get thread statistics
    382321 *
     
    396335        irq_spinlock_lock(&threads_lock, true);
    397336
    398         /* First walk the thread tree to count the threads */
    399         size_t count = 0;
    400         avltree_walk(&threads_tree, avl_count_walker, (void *) &count);
     337        /* Count the threads */
     338        size_t count = odict_count(&threads);
    401339
    402340        if (count == 0) {
     
    422360
    423361        /* Walk tha thread tree again to gather the statistics */
    424         stats_thread_t *iterator = stats_threads;
    425         avltree_walk(&threads_tree, thread_serialize_walker, (void *) &iterator);
     362        size_t i = 0;
     363
     364        odlink_t *odlink = odict_first(&threads);
     365        while (odlink != NULL) {
     366                thread_t *thread = odict_get_instance(odlink, thread_t,
     367                    lthreads);
     368
     369                /* Interrupts are already disabled */
     370                irq_spinlock_lock(&thread->lock, false);
     371
     372                /* Record the statistics and increment the index */
     373                produce_stats_thread(thread, &stats_threads[i]);
     374                i++;
     375
     376                irq_spinlock_unlock(&thread->lock, false);
     377
     378                odlink = odict_next(odlink, &threads);
     379        }
    426380
    427381        irq_spinlock_unlock(&threads_lock, true);
Note: See TracChangeset for help on using the changeset viewer.