Ignore:
File:
1 edited

Legend:

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

    ra35b458 r897fd8f1  
    9999        if (dry_run)
    100100                return NULL;
    101 
     101       
    102102        /* Assumption: config.cpu_count is constant */
    103103        stats_cpu_t *stats_cpus = (stats_cpu_t *) malloc(*size, FRAME_ATOMIC);
     
    106106                return NULL;
    107107        }
    108 
     108       
    109109        size_t i;
    110110        for (i = 0; i < config.cpu_count; i++) {
    111111                irq_spinlock_lock(&cpus[i].lock, true);
    112 
     112               
    113113                stats_cpus[i].id = cpus[i].id;
    114114                stats_cpus[i].active = cpus[i].active;
     
    116116                stats_cpus[i].busy_cycles = cpus[i].busy_cycles;
    117117                stats_cpus[i].idle_cycles = cpus[i].idle_cycles;
    118 
     118               
    119119                irq_spinlock_unlock(&cpus[i].lock, true);
    120120        }
    121 
     121       
    122122        return ((void *) stats_cpus);
    123123}
     
    137137        size_t *count = (size_t *) arg;
    138138        (*count)++;
    139 
     139       
    140140        return true;
    141141}
     
    156156         * object, return inexact statistics by skipping the respective object.
    157157         */
    158 
     158       
    159159        if (mutex_trylock(&as->lock) != EOK)
    160160                return 0;
    161 
     161       
    162162        size_t pages = 0;
    163 
     163       
    164164        /* Walk the B+ tree and count pages */
    165165        list_foreach(as->as_area_btree.leaf_list, leaf_link, btree_node_t,
     
    168168                for (i = 0; i < node->keys; i++) {
    169169                        as_area_t *area = node->value[i];
    170 
     170                       
    171171                        if (mutex_trylock(&area->lock) != EOK)
    172172                                continue;
    173 
     173                       
    174174                        pages += area->pages;
    175175                        mutex_unlock(&area->lock);
    176176                }
    177177        }
    178 
     178       
    179179        mutex_unlock(&as->lock);
    180 
     180       
    181181        return (pages << PAGE_WIDTH);
    182182}
     
    197197         * object, return inexact statistics by skipping the respective object.
    198198         */
    199 
     199       
    200200        if (mutex_trylock(&as->lock) != EOK)
    201201                return 0;
    202 
     202       
    203203        size_t pages = 0;
    204 
     204       
    205205        /* Walk the B+ tree and count pages */
    206206        list_foreach(as->as_area_btree.leaf_list, leaf_link, btree_node_t, node) {
     
    208208                for (i = 0; i < node->keys; i++) {
    209209                        as_area_t *area = node->value[i];
    210 
     210                       
    211211                        if (mutex_trylock(&area->lock) != EOK)
    212212                                continue;
    213 
     213                       
    214214                        pages += area->resident;
    215215                        mutex_unlock(&area->lock);
    216216                }
    217217        }
    218 
     218       
    219219        mutex_unlock(&as->lock);
    220 
     220       
    221221        return (pages << PAGE_WIDTH);
    222222}
     
    234234        assert(interrupts_disabled());
    235235        assert(irq_spinlock_locked(&task->lock));
    236 
     236       
    237237        stats_task->task_id = task->taskid;
    238238        str_cpy(stats_task->name, TASK_NAME_BUFLEN, task->name);
     
    260260        stats_task_t **iterator = (stats_task_t **) arg;
    261261        task_t *task = avltree_get_instance(node, task_t, tasks_tree_node);
    262 
     262       
    263263        /* Interrupts are already disabled */
    264264        irq_spinlock_lock(&(task->lock), false);
    265 
     265       
    266266        /* Record the statistics and increment the iterator */
    267267        produce_stats_task(task, *iterator);
    268268        (*iterator)++;
    269 
     269       
    270270        irq_spinlock_unlock(&(task->lock), false);
    271 
     271       
    272272        return true;
    273273}
     
    289289        /* Messing with task structures, avoid deadlock */
    290290        irq_spinlock_lock(&tasks_lock, true);
    291 
     291       
    292292        /* First walk the task tree to count the tasks */
    293293        size_t count = 0;
    294294        avltree_walk(&tasks_tree, avl_count_walker, (void *) &count);
    295 
     295       
    296296        if (count == 0) {
    297297                /* No tasks found (strange) */
     
    300300                return NULL;
    301301        }
    302 
     302       
    303303        *size = sizeof(stats_task_t) * count;
    304304        if (dry_run) {
     
    306306                return NULL;
    307307        }
    308 
     308       
    309309        stats_task_t *stats_tasks = (stats_task_t *) malloc(*size, FRAME_ATOMIC);
    310310        if (stats_tasks == NULL) {
     
    314314                return NULL;
    315315        }
    316 
     316       
    317317        /* Walk tha task tree again to gather the statistics */
    318318        stats_task_t *iterator = stats_tasks;
    319319        avltree_walk(&tasks_tree, task_serialize_walker, (void *) &iterator);
    320 
     320       
    321321        irq_spinlock_unlock(&tasks_lock, true);
    322 
     322       
    323323        return ((void *) stats_tasks);
    324324}
     
    336336        assert(interrupts_disabled());
    337337        assert(irq_spinlock_locked(&thread->lock));
    338 
     338       
    339339        stats_thread->thread_id = thread->tid;
    340340        stats_thread->task_id = thread->task->taskid;
     
    343343        stats_thread->ucycles = thread->ucycles;
    344344        stats_thread->kcycles = thread->kcycles;
    345 
     345       
    346346        if (thread->cpu != NULL) {
    347347                stats_thread->on_cpu = true;
     
    366366        stats_thread_t **iterator = (stats_thread_t **) arg;
    367367        thread_t *thread = avltree_get_instance(node, thread_t, threads_tree_node);
    368 
     368       
    369369        /* Interrupts are already disabled */
    370370        irq_spinlock_lock(&thread->lock, false);
    371 
     371       
    372372        /* Record the statistics and increment the iterator */
    373373        produce_stats_thread(thread, *iterator);
    374374        (*iterator)++;
    375 
     375       
    376376        irq_spinlock_unlock(&thread->lock, false);
    377 
     377       
    378378        return true;
    379379}
     
    395395        /* Messing with threads structures, avoid deadlock */
    396396        irq_spinlock_lock(&threads_lock, true);
    397 
     397       
    398398        /* First walk the thread tree to count the threads */
    399399        size_t count = 0;
    400400        avltree_walk(&threads_tree, avl_count_walker, (void *) &count);
    401 
     401       
    402402        if (count == 0) {
    403403                /* No threads found (strange) */
     
    406406                return NULL;
    407407        }
    408 
     408       
    409409        *size = sizeof(stats_thread_t) * count;
    410410        if (dry_run) {
     
    412412                return NULL;
    413413        }
    414 
     414       
    415415        stats_thread_t *stats_threads = (stats_thread_t *) malloc(*size, FRAME_ATOMIC);
    416416        if (stats_threads == NULL) {
     
    420420                return NULL;
    421421        }
    422 
     422       
    423423        /* Walk tha thread tree again to gather the statistics */
    424424        stats_thread_t *iterator = stats_threads;
    425425        avltree_walk(&threads_tree, thread_serialize_walker, (void *) &iterator);
    426 
     426       
    427427        irq_spinlock_unlock(&threads_lock, true);
    428 
     428       
    429429        return ((void *) stats_threads);
    430430}
     
    454454        sysinfo_return_t ret;
    455455        ret.tag = SYSINFO_VAL_UNDEFINED;
    456 
     456       
    457457        /* Parse the task ID */
    458458        task_id_t task_id;
    459459        if (str_uint64_t(name, NULL, 0, true, &task_id) != EOK)
    460460                return ret;
    461 
     461       
    462462        /* Messing with task structures, avoid deadlock */
    463463        irq_spinlock_lock(&tasks_lock, true);
    464 
     464       
    465465        task_t *task = task_find_by_id(task_id);
    466466        if (task == NULL) {
     
    469469                return ret;
    470470        }
    471 
     471       
    472472        if (dry_run) {
    473473                ret.tag = SYSINFO_VAL_FUNCTION_DATA;
    474474                ret.data.data = NULL;
    475475                ret.data.size = sizeof(stats_task_t);
    476 
     476               
    477477                irq_spinlock_unlock(&tasks_lock, true);
    478478        } else {
     
    484484                        return ret;
    485485                }
    486 
     486               
    487487                /* Correct return value */
    488488                ret.tag = SYSINFO_VAL_FUNCTION_DATA;
    489489                ret.data.data = (void *) stats_task;
    490490                ret.data.size = sizeof(stats_task_t);
    491 
     491               
    492492                /* Hand-over-hand locking */
    493493                irq_spinlock_exchange(&tasks_lock, &task->lock);
    494 
     494               
    495495                produce_stats_task(task, stats_task);
    496 
     496               
    497497                irq_spinlock_unlock(&task->lock, true);
    498498        }
    499 
     499       
    500500        return ret;
    501501}
     
    525525        sysinfo_return_t ret;
    526526        ret.tag = SYSINFO_VAL_UNDEFINED;
    527 
     527       
    528528        /* Parse the thread ID */
    529529        thread_id_t thread_id;
    530530        if (str_uint64_t(name, NULL, 0, true, &thread_id) != EOK)
    531531                return ret;
    532 
     532       
    533533        /* Messing with threads structures, avoid deadlock */
    534534        irq_spinlock_lock(&threads_lock, true);
    535 
     535       
    536536        thread_t *thread = thread_find_by_id(thread_id);
    537537        if (thread == NULL) {
     
    540540                return ret;
    541541        }
    542 
     542       
    543543        if (dry_run) {
    544544                ret.tag = SYSINFO_VAL_FUNCTION_DATA;
    545545                ret.data.data = NULL;
    546546                ret.data.size = sizeof(stats_thread_t);
    547 
     547               
    548548                irq_spinlock_unlock(&threads_lock, true);
    549549        } else {
     
    555555                        return ret;
    556556                }
    557 
     557               
    558558                /* Correct return value */
    559559                ret.tag = SYSINFO_VAL_FUNCTION_DATA;
    560560                ret.data.data = (void *) stats_thread;
    561561                ret.data.size = sizeof(stats_thread_t);
    562 
     562               
    563563                /* Hand-over-hand locking */
    564564                irq_spinlock_exchange(&threads_lock, &thread->lock);
    565 
     565               
    566566                produce_stats_thread(thread, stats_thread);
    567 
     567               
    568568                irq_spinlock_unlock(&thread->lock, true);
    569569        }
    570 
     570       
    571571        return ret;
    572572}
     
    587587{
    588588        *size = sizeof(stats_exc_t) * IVT_ITEMS;
    589 
     589       
    590590        if ((dry_run) || (IVT_ITEMS == 0))
    591591                return NULL;
    592 
     592       
    593593        stats_exc_t *stats_exceptions =
    594594            (stats_exc_t *) malloc(*size, FRAME_ATOMIC);
     
    598598                return NULL;
    599599        }
    600 
     600       
    601601#if (IVT_ITEMS > 0)
    602602        /* Messing with exception table, avoid deadlock */
    603603        irq_spinlock_lock(&exctbl_lock, true);
    604 
     604       
    605605        unsigned int i;
    606606        for (i = 0; i < IVT_ITEMS; i++) {
     
    611611                stats_exceptions[i].count = exc_table[i].count;
    612612        }
    613 
     613       
    614614        irq_spinlock_unlock(&exctbl_lock, true);
    615615#endif
    616 
     616       
    617617        return ((void *) stats_exceptions);
    618618}
     
    642642        sysinfo_return_t ret;
    643643        ret.tag = SYSINFO_VAL_UNDEFINED;
    644 
     644       
    645645        /* Parse the exception number */
    646646        uint64_t excn;
    647647        if (str_uint64_t(name, NULL, 0, true, &excn) != EOK)
    648648                return ret;
    649 
     649       
    650650#if (IVT_FIRST > 0)
    651651        if (excn < IVT_FIRST)
    652652                return ret;
    653653#endif
    654 
     654       
    655655#if (IVT_ITEMS + IVT_FIRST == 0)
    656656        return ret;
     
    659659                return ret;
    660660#endif
    661 
     661       
    662662        if (dry_run) {
    663663                ret.tag = SYSINFO_VAL_FUNCTION_DATA;
     
    667667                /* Update excn index for accessing exc_table */
    668668                excn -= IVT_FIRST;
    669 
     669               
    670670                /* Allocate stats_exc_t structure */
    671671                stats_exc_t *stats_exception =
     
    673673                if (stats_exception == NULL)
    674674                        return ret;
    675 
     675               
    676676                /* Messing with exception table, avoid deadlock */
    677677                irq_spinlock_lock(&exctbl_lock, true);
    678 
     678               
    679679                /* Correct return value */
    680680                ret.tag = SYSINFO_VAL_FUNCTION_DATA;
    681681                ret.data.data = (void *) stats_exception;
    682682                ret.data.size = sizeof(stats_exc_t);
    683 
     683               
    684684                stats_exception->id = excn;
    685685                str_cpy(stats_exception->desc, EXC_NAME_BUFLEN, exc_table[excn].name);
     
    687687                stats_exception->cycles = exc_table[excn].cycles;
    688688                stats_exception->count = exc_table[excn].count;
    689 
     689               
    690690                irq_spinlock_unlock(&exctbl_lock, true);
    691691        }
    692 
     692       
    693693        return ret;
    694694}
     
    711711        if (dry_run)
    712712                return NULL;
    713 
     713       
    714714        stats_physmem_t *stats_physmem =
    715715            (stats_physmem_t *) malloc(*size, FRAME_ATOMIC);
     
    718718                return NULL;
    719719        }
    720 
     720       
    721721        zones_stats(&(stats_physmem->total), &(stats_physmem->unavail),
    722722            &(stats_physmem->used), &(stats_physmem->free));
    723 
     723       
    724724        return ((void *) stats_physmem);
    725725}
     
    742742        if (dry_run)
    743743                return NULL;
    744 
     744       
    745745        load_t *stats_load = (load_t *) malloc(*size, FRAME_ATOMIC);
    746746        if (stats_load == NULL) {
     
    748748                return NULL;
    749749        }
    750 
     750       
    751751        /* To always get consistent values acquire the mutex */
    752752        mutex_lock(&load_lock);
    753 
     753       
    754754        unsigned int i;
    755755        for (i = 0; i < LOAD_STEPS; i++)
    756756                stats_load[i] = avenrdy[i] << LOAD_KERNEL_SHIFT;
    757 
     757       
    758758        mutex_unlock(&load_lock);
    759 
     759       
    760760        return ((void *) stats_load);
    761761}
     
    768768        load *= exp;
    769769        load += (ready << LOAD_FIXED_SHIFT) * (LOAD_FIXED_1 - exp);
    770 
     770       
    771771        return (load >> LOAD_FIXED_SHIFT);
    772772}
     
    782782{
    783783        thread_detach(THREAD);
    784 
     784       
    785785        while (true) {
    786786                atomic_count_t ready = atomic_get(&nrdy);
    787 
     787               
    788788                /* Mutually exclude with get_stats_load() */
    789789                mutex_lock(&load_lock);
    790 
     790               
    791791                unsigned int i;
    792792                for (i = 0; i < LOAD_STEPS; i++)
    793793                        avenrdy[i] = load_calc(avenrdy[i], load_exp[i], ready);
    794 
     794               
    795795                mutex_unlock(&load_lock);
    796 
     796               
    797797                thread_sleep(LOAD_INTERVAL);
    798798        }
     
    805805{
    806806        mutex_initialize(&load_lock, MUTEX_PASSIVE);
    807 
     807       
    808808        sysinfo_set_item_gen_data("system.cpus", NULL, get_stats_cpus, NULL);
    809809        sysinfo_set_item_gen_data("system.physmem", NULL, get_stats_physmem, NULL);
Note: See TracChangeset for help on using the changeset viewer.