Changes in kernel/generic/src/sysinfo/stats.c [fe7bcf1:07d4271] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/sysinfo/stats.c
rfe7bcf1 r07d4271 119 119 size_t i; 120 120 for (i = 0; i < config.cpu_count; i++) { 121 irq_spinlock_lock(&cpus[i].lock, true);122 123 121 stats_cpus[i].id = cpus[i].id; 124 122 stats_cpus[i].active = cpus[i].active; 125 123 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); 130 127 } 131 128 … … 224 221 stats_task->virtmem = get_task_virtmem(task->as); 225 222 stats_task->resmem = get_task_resmem(task->as); 226 stats_task->threads = atomic_load(&task-> refcount);223 stats_task->threads = atomic_load(&task->lifecount); 227 224 task_get_accounting(task, &(stats_task->ucycles), 228 225 &(stats_task->kcycles)); … … 302 299 { 303 300 assert(interrupts_disabled()); 304 assert(irq_spinlock_locked(&thread->lock));305 301 306 302 stats_thread->thread_id = thread->tid; 307 303 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) { 314 312 stats_thread->on_cpu = true; 315 stats_thread->cpu = thread->cpu->id;313 stats_thread->cpu = cpu->id; 316 314 } else 317 315 stats_thread->on_cpu = false; … … 332 330 bool dry_run, void *data) 333 331 { 334 /* Messing with threads structures , avoid deadlock*/332 /* Messing with threads structures */ 335 333 irq_spinlock_lock(&threads_lock, true); 336 334 … … 364 362 thread_t *thread = thread_first(); 365 363 while (thread != NULL) { 366 /* Interrupts are already disabled */367 irq_spinlock_lock(&thread->lock, false);368 369 364 /* Record the statistics and increment the index */ 370 365 produce_stats_thread(thread, &stats_threads[i]); 371 366 i++; 372 373 irq_spinlock_unlock(&thread->lock, false);374 367 375 368 thread = thread_next(thread); … … 518 511 { 519 512 /* 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 }; 522 516 523 517 /* Parse the task ID */ … … 526 520 return ret; 527 521 528 /* Messing with task structures, avoid deadlock */529 irq_spinlock_lock(&tasks_lock, true);530 531 522 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) 535 524 return ret; 536 }537 525 538 526 if (dry_run) { … … 540 528 ret.data.data = NULL; 541 529 ret.data.size = sizeof(stats_task_t); 542 543 irq_spinlock_unlock(&tasks_lock, true);544 530 } else { 545 531 /* 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); 551 543 } 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); 566 547 return ret; 567 548 } … … 597 578 return ret; 598 579 599 /* Messing with threads structures , avoid deadlock*/580 /* Messing with threads structures */ 600 581 irq_spinlock_lock(&threads_lock, true); 601 582 … … 627 608 ret.data.size = sizeof(stats_thread_t); 628 609 629 /* Hand-over-hand locking */630 irq_spinlock_exchange(&threads_lock, &thread->lock);631 632 610 produce_stats_thread(thread, stats_thread); 633 611 634 irq_spinlock_unlock(&thread ->lock, true);612 irq_spinlock_unlock(&threads_lock, true); 635 613 } 636 614 … … 847 825 void kload(void *arg) 848 826 { 849 thread_detach(THREAD);850 851 827 while (true) { 852 828 size_t ready = atomic_load(&nrdy);
Note:
See TracChangeset
for help on using the changeset viewer.