Ignore:
File:
1 edited

Legend:

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

    rfe7bcf1 r07d4271  
    119119        size_t i;
    120120        for (i = 0; i < config.cpu_count; i++) {
    121                 irq_spinlock_lock(&cpus[i].lock, true);
    122 
    123121                stats_cpus[i].id = cpus[i].id;
    124122                stats_cpus[i].active = cpus[i].active;
    125123                stats_cpus[i].frequency_mhz = cpus[i].frequency_mhz;
    126                 stats_cpus[i].busy_cycles = cpus[i].busy_cycles;
    127                 stats_cpus[i].idle_cycles = cpus[i].idle_cycles;
    128 
    129                 irq_spinlock_unlock(&cpus[i].lock, true);
     124
     125                stats_cpus[i].busy_cycles = atomic_time_read(&cpus[i].busy_cycles);
     126                stats_cpus[i].idle_cycles = atomic_time_read(&cpus[i].idle_cycles);
    130127        }
    131128
     
    224221        stats_task->virtmem = get_task_virtmem(task->as);
    225222        stats_task->resmem = get_task_resmem(task->as);
    226         stats_task->threads = atomic_load(&task->refcount);
     223        stats_task->threads = atomic_load(&task->lifecount);
    227224        task_get_accounting(task, &(stats_task->ucycles),
    228225            &(stats_task->kcycles));
     
    302299{
    303300        assert(interrupts_disabled());
    304         assert(irq_spinlock_locked(&thread->lock));
    305301
    306302        stats_thread->thread_id = thread->tid;
    307303        stats_thread->task_id = thread->task->taskid;
    308         stats_thread->state = thread->state;
    309         stats_thread->priority = thread->priority;
    310         stats_thread->ucycles = thread->ucycles;
    311         stats_thread->kcycles = thread->kcycles;
    312 
    313         if (thread->cpu != NULL) {
     304        stats_thread->state = atomic_get_unordered(&thread->state);
     305        stats_thread->priority = atomic_get_unordered(&thread->priority);
     306        stats_thread->ucycles = atomic_time_read(&thread->ucycles);
     307        stats_thread->kcycles = atomic_time_read(&thread->kcycles);
     308
     309        cpu_t *cpu = atomic_get_unordered(&thread->cpu);
     310
     311        if (cpu != NULL) {
    314312                stats_thread->on_cpu = true;
    315                 stats_thread->cpu = thread->cpu->id;
     313                stats_thread->cpu = cpu->id;
    316314        } else
    317315                stats_thread->on_cpu = false;
     
    332330    bool dry_run, void *data)
    333331{
    334         /* Messing with threads structures, avoid deadlock */
     332        /* Messing with threads structures */
    335333        irq_spinlock_lock(&threads_lock, true);
    336334
     
    364362        thread_t *thread = thread_first();
    365363        while (thread != NULL) {
    366                 /* Interrupts are already disabled */
    367                 irq_spinlock_lock(&thread->lock, false);
    368 
    369364                /* Record the statistics and increment the index */
    370365                produce_stats_thread(thread, &stats_threads[i]);
    371366                i++;
    372 
    373                 irq_spinlock_unlock(&thread->lock, false);
    374367
    375368                thread = thread_next(thread);
     
    518511{
    519512        /* Initially no return value */
    520         sysinfo_return_t ret;
    521         ret.tag = SYSINFO_VAL_UNDEFINED;
     513        sysinfo_return_t ret = {
     514                .tag = SYSINFO_VAL_UNDEFINED,
     515        };
    522516
    523517        /* Parse the task ID */
     
    526520                return ret;
    527521
    528         /* Messing with task structures, avoid deadlock */
    529         irq_spinlock_lock(&tasks_lock, true);
    530 
    531522        task_t *task = task_find_by_id(task_id);
    532         if (task == NULL) {
    533                 /* No task with this ID */
    534                 irq_spinlock_unlock(&tasks_lock, true);
     523        if (!task)
    535524                return ret;
    536         }
    537525
    538526        if (dry_run) {
     
    540528                ret.data.data = NULL;
    541529                ret.data.size = sizeof(stats_task_t);
    542 
    543                 irq_spinlock_unlock(&tasks_lock, true);
    544530        } else {
    545531                /* Allocate stats_task_t structure */
    546                 stats_task_t *stats_task =
    547                     (stats_task_t *) malloc(sizeof(stats_task_t));
    548                 if (stats_task == NULL) {
    549                         irq_spinlock_unlock(&tasks_lock, true);
    550                         return ret;
     532                stats_task_t *stats_task = malloc(sizeof(stats_task_t));
     533
     534                if (stats_task != NULL) {
     535                        /* Correct return value */
     536                        ret.tag = SYSINFO_VAL_FUNCTION_DATA;
     537                        ret.data.data = stats_task;
     538                        ret.data.size = sizeof(stats_task_t);
     539
     540                        irq_spinlock_lock(&task->lock, true);
     541                        produce_stats_task(task, stats_task);
     542                        irq_spinlock_unlock(&task->lock, true);
    551543                }
    552 
    553                 /* Correct return value */
    554                 ret.tag = SYSINFO_VAL_FUNCTION_DATA;
    555                 ret.data.data = (void *) stats_task;
    556                 ret.data.size = sizeof(stats_task_t);
    557 
    558                 /* Hand-over-hand locking */
    559                 irq_spinlock_exchange(&tasks_lock, &task->lock);
    560 
    561                 produce_stats_task(task, stats_task);
    562 
    563                 irq_spinlock_unlock(&task->lock, true);
    564         }
    565 
     544        }
     545
     546        task_release(task);
    566547        return ret;
    567548}
     
    597578                return ret;
    598579
    599         /* Messing with threads structures, avoid deadlock */
     580        /* Messing with threads structures */
    600581        irq_spinlock_lock(&threads_lock, true);
    601582
     
    627608                ret.data.size = sizeof(stats_thread_t);
    628609
    629                 /* Hand-over-hand locking */
    630                 irq_spinlock_exchange(&threads_lock, &thread->lock);
    631 
    632610                produce_stats_thread(thread, stats_thread);
    633611
    634                 irq_spinlock_unlock(&thread->lock, true);
     612                irq_spinlock_unlock(&threads_lock, true);
    635613        }
    636614
     
    847825void kload(void *arg)
    848826{
    849         thread_detach(THREAD);
    850 
    851827        while (true) {
    852828                size_t ready = atomic_load(&nrdy);
Note: See TracChangeset for help on using the changeset viewer.