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


Ignore:
Timestamp:
2010-05-24T18:57:31Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0095368
Parents:
666f492
Message:

major code revision

  • replace spinlocks taken with interrupts disabled with irq_spinlocks
  • change spacing (not indendation) to be tab-size independent
  • use unsigned integer types where appropriate (especially bit flags)
  • visual separation
  • remove argument names in function prototypes
  • string changes
  • correct some formating directives
  • replace various cryptic single-character variables (t, a, m, c, b, etc.) with proper identifiers (thread, task, timeout, as, itm, itc, etc.)
  • unify some assembler constructs
  • unused page table levels are now optimized out in compile time
  • replace several ints (with boolean semantics) with bools
  • use specifically sized types instead of generic types where appropriate (size_t, uint32_t, btree_key_t)
  • improve comments
  • split asserts with conjuction into multiple independent asserts
File:
1 edited

Legend:

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

    r666f492 rda1bafb  
    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);
     
    235230       
    236231        /* Interrupts are already disabled */
    237         spinlock_lock(&(task->lock));
     232        irq_spinlock_lock(&(task->lock), false);
    238233       
    239234        /* Record the statistics and increment the iterator */
     
    241236        (*iterator)++;
    242237       
    243         spinlock_unlock(&(task->lock));
     238        irq_spinlock_unlock(&(task->lock), false);
    244239       
    245240        return true;
     
    260255{
    261256        /* Messing with task structures, avoid deadlock */
    262         ipl_t ipl = interrupts_disable();
    263         spinlock_lock(&tasks_lock);
     257        irq_spinlock_lock(&tasks_lock, true);
    264258       
    265259        /* First walk the task tree to count the tasks */
     
    269263        if (count == 0) {
    270264                /* No tasks found (strange) */
    271                 spinlock_unlock(&tasks_lock);
    272                 interrupts_restore(ipl);
    273                
     265                irq_spinlock_unlock(&tasks_lock, true);
    274266                *size = 0;
    275267                return NULL;
     
    278270        *size = sizeof(stats_task_t) * count;
    279271        if (dry_run) {
    280                 spinlock_unlock(&tasks_lock);
    281                 interrupts_restore(ipl);
     272                irq_spinlock_unlock(&tasks_lock, true);
    282273                return NULL;
    283274        }
     
    286277        if (stats_tasks == NULL) {
    287278                /* No free space for allocation */
    288                 spinlock_unlock(&tasks_lock);
    289                 interrupts_restore(ipl);
    290                
     279                irq_spinlock_unlock(&tasks_lock, true);
    291280                *size = 0;
    292281                return NULL;
     
    297286        avltree_walk(&tasks_tree, task_serialize_walker, (void *) &iterator);
    298287       
    299         spinlock_unlock(&tasks_lock);
    300         interrupts_restore(ipl);
     288        irq_spinlock_unlock(&tasks_lock, true);
    301289       
    302290        return ((void *) stats_tasks);
     
    346334       
    347335        /* Interrupts are already disabled */
    348         spinlock_lock(&thread->lock);
     336        irq_spinlock_lock(&thread->lock, false);
    349337       
    350338        /* Record the statistics and increment the iterator */
     
    352340        (*iterator)++;
    353341       
    354         spinlock_unlock(&thread->lock);
     342        irq_spinlock_unlock(&thread->lock, false);
    355343       
    356344        return true;
     
    371359{
    372360        /* Messing with threads structures, avoid deadlock */
    373         ipl_t ipl = interrupts_disable();
    374         spinlock_lock(&threads_lock);
     361        irq_spinlock_lock(&threads_lock, true);
    375362       
    376363        /* First walk the thread tree to count the threads */
     
    380367        if (count == 0) {
    381368                /* No threads found (strange) */
    382                 spinlock_unlock(&threads_lock);
    383                 interrupts_restore(ipl);
    384                
     369                irq_spinlock_unlock(&threads_lock, true);
    385370                *size = 0;
    386371                return NULL;
     
    389374        *size = sizeof(stats_thread_t) * count;
    390375        if (dry_run) {
    391                 spinlock_unlock(&threads_lock);
    392                 interrupts_restore(ipl);
     376                irq_spinlock_unlock(&threads_lock, true);
    393377                return NULL;
    394378        }
     
    397381        if (stats_threads == NULL) {
    398382                /* No free space for allocation */
    399                 spinlock_unlock(&threads_lock);
    400                 interrupts_restore(ipl);
    401                
     383                irq_spinlock_unlock(&threads_lock, true);
    402384                *size = 0;
    403385                return NULL;
     
    408390        avltree_walk(&threads_tree, thread_serialize_walker, (void *) &iterator);
    409391       
    410         spinlock_unlock(&threads_lock);
    411         interrupts_restore(ipl);
     392        irq_spinlock_unlock(&threads_lock, true);
    412393       
    413394        return ((void *) stats_threads);
     
    443424       
    444425        /* Messing with task structures, avoid deadlock */
    445         ipl_t ipl = interrupts_disable();
    446         spinlock_lock(&tasks_lock);
     426        irq_spinlock_lock(&tasks_lock, true);
    447427       
    448428        task_t *task = task_find_by_id(task_id);
    449429        if (task == NULL) {
    450430                /* No task with this ID */
    451                 spinlock_unlock(&tasks_lock);
    452                 interrupts_restore(ipl);
     431                irq_spinlock_unlock(&tasks_lock, true);
    453432                return ret;
    454433        }
     
    459438                ret.data.size = sizeof(stats_task_t);
    460439               
    461                 spinlock_unlock(&tasks_lock);
     440                irq_spinlock_unlock(&tasks_lock, true);
    462441        } else {
    463442                /* Allocate stats_task_t structure */
     
    465444                    (stats_task_t *) malloc(sizeof(stats_task_t), FRAME_ATOMIC);
    466445                if (stats_task == NULL) {
    467                         spinlock_unlock(&tasks_lock);
    468                         interrupts_restore(ipl);
     446                        irq_spinlock_unlock(&tasks_lock, true);
    469447                        return ret;
    470448                }
     
    474452                ret.data.data = (void *) stats_task;
    475453                ret.data.size = sizeof(stats_task_t);
    476        
     454               
    477455                /* Hand-over-hand locking */
    478                 spinlock_lock(&task->lock);
    479                 spinlock_unlock(&tasks_lock);
     456                irq_spinlock_exchange(&tasks_lock, &task->lock);
    480457               
    481458                produce_stats_task(task, stats_task);
    482459               
    483                 spinlock_unlock(&task->lock);
    484         }
    485        
    486         interrupts_restore(ipl);
     460                irq_spinlock_unlock(&task->lock, true);
     461        }
    487462       
    488463        return ret;
     
    518493       
    519494        /* Messing with threads structures, avoid deadlock */
    520         ipl_t ipl = interrupts_disable();
    521         spinlock_lock(&threads_lock);
     495        irq_spinlock_lock(&threads_lock, true);
    522496       
    523497        thread_t *thread = thread_find_by_id(thread_id);
    524498        if (thread == NULL) {
    525499                /* No thread with this ID */
    526                 spinlock_unlock(&threads_lock);
    527                 interrupts_restore(ipl);
     500                irq_spinlock_unlock(&threads_lock, true);
    528501                return ret;
    529502        }
     
    534507                ret.data.size = sizeof(stats_thread_t);
    535508               
    536                 spinlock_unlock(&threads_lock);
     509                irq_spinlock_unlock(&threads_lock, true);
    537510        } else {
    538511                /* Allocate stats_thread_t structure */
     
    540513                    (stats_thread_t *) malloc(sizeof(stats_thread_t), FRAME_ATOMIC);
    541514                if (stats_thread == NULL) {
    542                         spinlock_unlock(&threads_lock);
    543                         interrupts_restore(ipl);
     515                        irq_spinlock_unlock(&threads_lock, true);
    544516                        return ret;
    545517                }
     
    551523               
    552524                /* Hand-over-hand locking */
    553                 spinlock_lock(&thread->lock);
    554                 spinlock_unlock(&threads_lock);
     525                irq_spinlock_exchange(&threads_lock, &thread->lock);
    555526               
    556527                produce_stats_thread(thread, stats_thread);
    557528               
    558                 spinlock_unlock(&thread->lock);
    559         }
    560        
    561         interrupts_restore(ipl);
     529                irq_spinlock_unlock(&thread->lock, true);
     530        }
    562531       
    563532        return ret;
     
    673642{
    674643        mutex_initialize(&load_lock, MUTEX_PASSIVE);
    675 
     644       
    676645        sysinfo_set_item_fn_val("system.uptime", NULL, get_stats_uptime);
    677646        sysinfo_set_item_fn_data("system.cpus", NULL, get_stats_cpus);
Note: See TracChangeset for help on using the changeset viewer.