Ignore:
File:
1 edited

Legend:

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

    r6e121b8 r8f80c77  
    110110        }
    111111       
    112         /* Each CPU structure is locked separatelly */
    113         ipl_t ipl = interrupts_disable();
    114        
    115112        size_t i;
    116113        for (i = 0; i < config.cpu_count; i++) {
    117                 spinlock_lock(&cpus[i].lock);
     114                irq_spinlock_lock(&cpus[i].lock, true);
    118115               
    119116                stats_cpus[i].id = cpus[i].id;
     
    123120                stats_cpus[i].idle_ticks = cpus[i].idle_ticks;
    124121               
    125                 spinlock_unlock(&cpus[i].lock);
    126         }
    127        
    128         interrupts_restore(ipl);
     122                irq_spinlock_unlock(&cpus[i].lock, true);
     123        }
    129124       
    130125        return ((void *) stats_cpus);
     
    200195 *
    201196 * Summarize task information into task statistics.
    202  * Task lock should be held and interrupts disabled
    203  * before executing this function.
    204197 *
    205198 * @param task       Task.
     
    209202static void produce_stats_task(task_t *task, stats_task_t *stats_task)
    210203{
     204        ASSERT(interrupts_disabled());
     205        ASSERT(irq_spinlock_locked(&task->lock));
     206
    211207        stats_task->task_id = task->taskid;
    212208        str_cpy(stats_task->name, TASK_NAME_BUFLEN, task->name);
     
    235231       
    236232        /* Interrupts are already disabled */
    237         spinlock_lock(&(task->lock));
     233        irq_spinlock_lock(&(task->lock), false);
    238234       
    239235        /* Record the statistics and increment the iterator */
     
    241237        (*iterator)++;
    242238       
    243         spinlock_unlock(&(task->lock));
     239        irq_spinlock_unlock(&(task->lock), false);
    244240       
    245241        return true;
     
    260256{
    261257        /* Messing with task structures, avoid deadlock */
    262         ipl_t ipl = interrupts_disable();
    263         spinlock_lock(&tasks_lock);
     258        irq_spinlock_lock(&tasks_lock, true);
    264259       
    265260        /* First walk the task tree to count the tasks */
     
    269264        if (count == 0) {
    270265                /* No tasks found (strange) */
    271                 spinlock_unlock(&tasks_lock);
    272                 interrupts_restore(ipl);
    273                
     266                irq_spinlock_unlock(&tasks_lock, true);
    274267                *size = 0;
    275268                return NULL;
     
    278271        *size = sizeof(stats_task_t) * count;
    279272        if (dry_run) {
    280                 spinlock_unlock(&tasks_lock);
    281                 interrupts_restore(ipl);
     273                irq_spinlock_unlock(&tasks_lock, true);
    282274                return NULL;
    283275        }
     
    286278        if (stats_tasks == NULL) {
    287279                /* No free space for allocation */
    288                 spinlock_unlock(&tasks_lock);
    289                 interrupts_restore(ipl);
    290                
     280                irq_spinlock_unlock(&tasks_lock, true);
    291281                *size = 0;
    292282                return NULL;
     
    297287        avltree_walk(&tasks_tree, task_serialize_walker, (void *) &iterator);
    298288       
    299         spinlock_unlock(&tasks_lock);
    300         interrupts_restore(ipl);
     289        irq_spinlock_unlock(&tasks_lock, true);
    301290       
    302291        return ((void *) stats_tasks);
     
    306295 *
    307296 * Summarize thread information into thread statistics.
    308  * Thread lock should be held and interrupts disabled
    309  * before executing this function.
    310297 *
    311298 * @param thread       Thread.
     
    315302static void produce_stats_thread(thread_t *thread, stats_thread_t *stats_thread)
    316303{
     304        ASSERT(interrupts_disabled());
     305        ASSERT(irq_spinlock_locked(&thread->lock));
     306
    317307        stats_thread->thread_id = thread->tid;
    318308        stats_thread->task_id = thread->task->taskid;
     
    346336       
    347337        /* Interrupts are already disabled */
    348         spinlock_lock(&thread->lock);
     338        irq_spinlock_lock(&thread->lock, false);
    349339       
    350340        /* Record the statistics and increment the iterator */
     
    352342        (*iterator)++;
    353343       
    354         spinlock_unlock(&thread->lock);
     344        irq_spinlock_unlock(&thread->lock, false);
    355345       
    356346        return true;
     
    371361{
    372362        /* Messing with threads structures, avoid deadlock */
    373         ipl_t ipl = interrupts_disable();
    374         spinlock_lock(&threads_lock);
     363        irq_spinlock_lock(&threads_lock, true);
    375364       
    376365        /* First walk the thread tree to count the threads */
     
    380369        if (count == 0) {
    381370                /* No threads found (strange) */
    382                 spinlock_unlock(&threads_lock);
    383                 interrupts_restore(ipl);
    384                
     371                irq_spinlock_unlock(&threads_lock, true);
    385372                *size = 0;
    386373                return NULL;
     
    389376        *size = sizeof(stats_thread_t) * count;
    390377        if (dry_run) {
    391                 spinlock_unlock(&threads_lock);
    392                 interrupts_restore(ipl);
     378                irq_spinlock_unlock(&threads_lock, true);
    393379                return NULL;
    394380        }
     
    397383        if (stats_threads == NULL) {
    398384                /* No free space for allocation */
    399                 spinlock_unlock(&threads_lock);
    400                 interrupts_restore(ipl);
    401                
     385                irq_spinlock_unlock(&threads_lock, true);
    402386                *size = 0;
    403387                return NULL;
     
    408392        avltree_walk(&threads_tree, thread_serialize_walker, (void *) &iterator);
    409393       
    410         spinlock_unlock(&threads_lock);
    411         interrupts_restore(ipl);
     394        irq_spinlock_unlock(&threads_lock, true);
    412395       
    413396        return ((void *) stats_threads);
     
    443426       
    444427        /* Messing with task structures, avoid deadlock */
    445         ipl_t ipl = interrupts_disable();
    446         spinlock_lock(&tasks_lock);
     428        irq_spinlock_lock(&tasks_lock, true);
    447429       
    448430        task_t *task = task_find_by_id(task_id);
    449431        if (task == NULL) {
    450432                /* No task with this ID */
    451                 spinlock_unlock(&tasks_lock);
    452                 interrupts_restore(ipl);
     433                irq_spinlock_unlock(&tasks_lock, true);
    453434                return ret;
    454435        }
     
    459440                ret.data.size = sizeof(stats_task_t);
    460441               
    461                 spinlock_unlock(&tasks_lock);
     442                irq_spinlock_unlock(&tasks_lock, true);
    462443        } else {
    463444                /* Allocate stats_task_t structure */
     
    465446                    (stats_task_t *) malloc(sizeof(stats_task_t), FRAME_ATOMIC);
    466447                if (stats_task == NULL) {
    467                         spinlock_unlock(&tasks_lock);
    468                         interrupts_restore(ipl);
     448                        irq_spinlock_unlock(&tasks_lock, true);
    469449                        return ret;
    470450                }
     
    474454                ret.data.data = (void *) stats_task;
    475455                ret.data.size = sizeof(stats_task_t);
    476        
     456               
    477457                /* Hand-over-hand locking */
    478                 spinlock_lock(&task->lock);
    479                 spinlock_unlock(&tasks_lock);
     458                irq_spinlock_exchange(&tasks_lock, &task->lock);
    480459               
    481460                produce_stats_task(task, stats_task);
    482461               
    483                 spinlock_unlock(&task->lock);
    484         }
    485        
    486         interrupts_restore(ipl);
     462                irq_spinlock_unlock(&task->lock, true);
     463        }
    487464       
    488465        return ret;
     
    518495       
    519496        /* Messing with threads structures, avoid deadlock */
    520         ipl_t ipl = interrupts_disable();
    521         spinlock_lock(&threads_lock);
     497        irq_spinlock_lock(&threads_lock, true);
    522498       
    523499        thread_t *thread = thread_find_by_id(thread_id);
    524500        if (thread == NULL) {
    525501                /* No thread with this ID */
    526                 spinlock_unlock(&threads_lock);
    527                 interrupts_restore(ipl);
     502                irq_spinlock_unlock(&threads_lock, true);
    528503                return ret;
    529504        }
     
    534509                ret.data.size = sizeof(stats_thread_t);
    535510               
    536                 spinlock_unlock(&threads_lock);
     511                irq_spinlock_unlock(&threads_lock, true);
    537512        } else {
    538513                /* Allocate stats_thread_t structure */
     
    540515                    (stats_thread_t *) malloc(sizeof(stats_thread_t), FRAME_ATOMIC);
    541516                if (stats_thread == NULL) {
    542                         spinlock_unlock(&threads_lock);
    543                         interrupts_restore(ipl);
     517                        irq_spinlock_unlock(&threads_lock, true);
    544518                        return ret;
    545519                }
     
    551525               
    552526                /* Hand-over-hand locking */
    553                 spinlock_lock(&thread->lock);
    554                 spinlock_unlock(&threads_lock);
     527                irq_spinlock_exchange(&threads_lock, &thread->lock);
    555528               
    556529                produce_stats_thread(thread, stats_thread);
    557530               
    558                 spinlock_unlock(&thread->lock);
    559         }
    560        
    561         interrupts_restore(ipl);
     531                irq_spinlock_unlock(&thread->lock, true);
     532        }
    562533       
    563534        return ret;
     
    673644{
    674645        mutex_initialize(&load_lock, MUTEX_PASSIVE);
    675 
     646       
    676647        sysinfo_set_item_fn_val("system.uptime", NULL, get_stats_uptime);
    677648        sysinfo_set_item_fn_data("system.cpus", NULL, get_stats_cpus);
Note: See TracChangeset for help on using the changeset viewer.