Ignore:
File:
1 edited

Legend:

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

    r8f80c77 r6e121b8  
    110110        }
    111111       
     112        /* Each CPU structure is locked separatelly */
     113        ipl_t ipl = interrupts_disable();
     114       
    112115        size_t i;
    113116        for (i = 0; i < config.cpu_count; i++) {
    114                 irq_spinlock_lock(&cpus[i].lock, true);
     117                spinlock_lock(&cpus[i].lock);
    115118               
    116119                stats_cpus[i].id = cpus[i].id;
     
    120123                stats_cpus[i].idle_ticks = cpus[i].idle_ticks;
    121124               
    122                 irq_spinlock_unlock(&cpus[i].lock, true);
    123         }
     125                spinlock_unlock(&cpus[i].lock);
     126        }
     127       
     128        interrupts_restore(ipl);
    124129       
    125130        return ((void *) stats_cpus);
     
    195200 *
    196201 * Summarize task information into task statistics.
     202 * Task lock should be held and interrupts disabled
     203 * before executing this function.
    197204 *
    198205 * @param task       Task.
     
    202209static void produce_stats_task(task_t *task, stats_task_t *stats_task)
    203210{
    204         ASSERT(interrupts_disabled());
    205         ASSERT(irq_spinlock_locked(&task->lock));
    206 
    207211        stats_task->task_id = task->taskid;
    208212        str_cpy(stats_task->name, TASK_NAME_BUFLEN, task->name);
     
    231235       
    232236        /* Interrupts are already disabled */
    233         irq_spinlock_lock(&(task->lock), false);
     237        spinlock_lock(&(task->lock));
    234238       
    235239        /* Record the statistics and increment the iterator */
     
    237241        (*iterator)++;
    238242       
    239         irq_spinlock_unlock(&(task->lock), false);
     243        spinlock_unlock(&(task->lock));
    240244       
    241245        return true;
     
    256260{
    257261        /* Messing with task structures, avoid deadlock */
    258         irq_spinlock_lock(&tasks_lock, true);
     262        ipl_t ipl = interrupts_disable();
     263        spinlock_lock(&tasks_lock);
    259264       
    260265        /* First walk the task tree to count the tasks */
     
    264269        if (count == 0) {
    265270                /* No tasks found (strange) */
    266                 irq_spinlock_unlock(&tasks_lock, true);
     271                spinlock_unlock(&tasks_lock);
     272                interrupts_restore(ipl);
     273               
    267274                *size = 0;
    268275                return NULL;
     
    271278        *size = sizeof(stats_task_t) * count;
    272279        if (dry_run) {
    273                 irq_spinlock_unlock(&tasks_lock, true);
     280                spinlock_unlock(&tasks_lock);
     281                interrupts_restore(ipl);
    274282                return NULL;
    275283        }
     
    278286        if (stats_tasks == NULL) {
    279287                /* No free space for allocation */
    280                 irq_spinlock_unlock(&tasks_lock, true);
     288                spinlock_unlock(&tasks_lock);
     289                interrupts_restore(ipl);
     290               
    281291                *size = 0;
    282292                return NULL;
     
    287297        avltree_walk(&tasks_tree, task_serialize_walker, (void *) &iterator);
    288298       
    289         irq_spinlock_unlock(&tasks_lock, true);
     299        spinlock_unlock(&tasks_lock);
     300        interrupts_restore(ipl);
    290301       
    291302        return ((void *) stats_tasks);
     
    295306 *
    296307 * Summarize thread information into thread statistics.
     308 * Thread lock should be held and interrupts disabled
     309 * before executing this function.
    297310 *
    298311 * @param thread       Thread.
     
    302315static void produce_stats_thread(thread_t *thread, stats_thread_t *stats_thread)
    303316{
    304         ASSERT(interrupts_disabled());
    305         ASSERT(irq_spinlock_locked(&thread->lock));
    306 
    307317        stats_thread->thread_id = thread->tid;
    308318        stats_thread->task_id = thread->task->taskid;
     
    336346       
    337347        /* Interrupts are already disabled */
    338         irq_spinlock_lock(&thread->lock, false);
     348        spinlock_lock(&thread->lock);
    339349       
    340350        /* Record the statistics and increment the iterator */
     
    342352        (*iterator)++;
    343353       
    344         irq_spinlock_unlock(&thread->lock, false);
     354        spinlock_unlock(&thread->lock);
    345355       
    346356        return true;
     
    361371{
    362372        /* Messing with threads structures, avoid deadlock */
    363         irq_spinlock_lock(&threads_lock, true);
     373        ipl_t ipl = interrupts_disable();
     374        spinlock_lock(&threads_lock);
    364375       
    365376        /* First walk the thread tree to count the threads */
     
    369380        if (count == 0) {
    370381                /* No threads found (strange) */
    371                 irq_spinlock_unlock(&threads_lock, true);
     382                spinlock_unlock(&threads_lock);
     383                interrupts_restore(ipl);
     384               
    372385                *size = 0;
    373386                return NULL;
     
    376389        *size = sizeof(stats_thread_t) * count;
    377390        if (dry_run) {
    378                 irq_spinlock_unlock(&threads_lock, true);
     391                spinlock_unlock(&threads_lock);
     392                interrupts_restore(ipl);
    379393                return NULL;
    380394        }
     
    383397        if (stats_threads == NULL) {
    384398                /* No free space for allocation */
    385                 irq_spinlock_unlock(&threads_lock, true);
     399                spinlock_unlock(&threads_lock);
     400                interrupts_restore(ipl);
     401               
    386402                *size = 0;
    387403                return NULL;
     
    392408        avltree_walk(&threads_tree, thread_serialize_walker, (void *) &iterator);
    393409       
    394         irq_spinlock_unlock(&threads_lock, true);
     410        spinlock_unlock(&threads_lock);
     411        interrupts_restore(ipl);
    395412       
    396413        return ((void *) stats_threads);
     
    426443       
    427444        /* Messing with task structures, avoid deadlock */
    428         irq_spinlock_lock(&tasks_lock, true);
     445        ipl_t ipl = interrupts_disable();
     446        spinlock_lock(&tasks_lock);
    429447       
    430448        task_t *task = task_find_by_id(task_id);
    431449        if (task == NULL) {
    432450                /* No task with this ID */
    433                 irq_spinlock_unlock(&tasks_lock, true);
     451                spinlock_unlock(&tasks_lock);
     452                interrupts_restore(ipl);
    434453                return ret;
    435454        }
     
    440459                ret.data.size = sizeof(stats_task_t);
    441460               
    442                 irq_spinlock_unlock(&tasks_lock, true);
     461                spinlock_unlock(&tasks_lock);
    443462        } else {
    444463                /* Allocate stats_task_t structure */
     
    446465                    (stats_task_t *) malloc(sizeof(stats_task_t), FRAME_ATOMIC);
    447466                if (stats_task == NULL) {
    448                         irq_spinlock_unlock(&tasks_lock, true);
     467                        spinlock_unlock(&tasks_lock);
     468                        interrupts_restore(ipl);
    449469                        return ret;
    450470                }
     
    454474                ret.data.data = (void *) stats_task;
    455475                ret.data.size = sizeof(stats_task_t);
    456                
     476       
    457477                /* Hand-over-hand locking */
    458                 irq_spinlock_exchange(&tasks_lock, &task->lock);
     478                spinlock_lock(&task->lock);
     479                spinlock_unlock(&tasks_lock);
    459480               
    460481                produce_stats_task(task, stats_task);
    461482               
    462                 irq_spinlock_unlock(&task->lock, true);
    463         }
     483                spinlock_unlock(&task->lock);
     484        }
     485       
     486        interrupts_restore(ipl);
    464487       
    465488        return ret;
     
    495518       
    496519        /* Messing with threads structures, avoid deadlock */
    497         irq_spinlock_lock(&threads_lock, true);
     520        ipl_t ipl = interrupts_disable();
     521        spinlock_lock(&threads_lock);
    498522       
    499523        thread_t *thread = thread_find_by_id(thread_id);
    500524        if (thread == NULL) {
    501525                /* No thread with this ID */
    502                 irq_spinlock_unlock(&threads_lock, true);
     526                spinlock_unlock(&threads_lock);
     527                interrupts_restore(ipl);
    503528                return ret;
    504529        }
     
    509534                ret.data.size = sizeof(stats_thread_t);
    510535               
    511                 irq_spinlock_unlock(&threads_lock, true);
     536                spinlock_unlock(&threads_lock);
    512537        } else {
    513538                /* Allocate stats_thread_t structure */
     
    515540                    (stats_thread_t *) malloc(sizeof(stats_thread_t), FRAME_ATOMIC);
    516541                if (stats_thread == NULL) {
    517                         irq_spinlock_unlock(&threads_lock, true);
     542                        spinlock_unlock(&threads_lock);
     543                        interrupts_restore(ipl);
    518544                        return ret;
    519545                }
     
    525551               
    526552                /* Hand-over-hand locking */
    527                 irq_spinlock_exchange(&threads_lock, &thread->lock);
     553                spinlock_lock(&thread->lock);
     554                spinlock_unlock(&threads_lock);
    528555               
    529556                produce_stats_thread(thread, stats_thread);
    530557               
    531                 irq_spinlock_unlock(&thread->lock, true);
    532         }
     558                spinlock_unlock(&thread->lock);
     559        }
     560       
     561        interrupts_restore(ipl);
    533562       
    534563        return ret;
     
    644673{
    645674        mutex_initialize(&load_lock, MUTEX_PASSIVE);
    646        
     675
    647676        sysinfo_set_item_fn_val("system.uptime", NULL, get_stats_uptime);
    648677        sysinfo_set_item_fn_data("system.cpus", NULL, get_stats_cpus);
Note: See TracChangeset for help on using the changeset viewer.