Changeset 11909ce3 in mainline
- Timestamp:
- 2024-01-21T15:48:43Z (11 months ago)
- Branches:
- master
- Children:
- 515f1b1
- Parents:
- 33e15a0
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2023-03-29 10:25:36)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-21 15:48:43)
- Location:
- kernel/generic
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/proc/thread.h
r33e15a0 r11909ce3 147 147 148 148 /** Thread accounting. */ 149 uint64_t ucycles;150 uint64_t kcycles;149 atomic_time_stat_t ucycles; 150 atomic_time_stat_t kcycles; 151 151 /** Last sampled cycle. */ 152 152 uint64_t last_cycle; -
kernel/generic/src/interrupt/interrupt.c
r33e15a0 r11909ce3 114 114 115 115 /* Account user cycles */ 116 if (THREAD) { 117 irq_spinlock_lock(&THREAD->lock, false); 116 if (THREAD) 118 117 thread_update_accounting(true); 119 irq_spinlock_unlock(&THREAD->lock, false);120 }121 118 122 119 /* Account CPU usage if it woke up from sleep */ … … 155 152 156 153 /* Do not charge THREAD for exception cycles */ 157 if (THREAD) { 158 irq_spinlock_lock(&THREAD->lock, false); 154 if (THREAD) 159 155 THREAD->last_cycle = end_cycle; 160 irq_spinlock_unlock(&THREAD->lock, false);161 }162 156 #else 163 157 panic("No space for any exception handler, yet we want to handle some exception."); -
kernel/generic/src/proc/scheduler.c
r33e15a0 r11909ce3 507 507 508 508 /* Update thread kernel accounting */ 509 THREAD->kcycles += get_cycle() - THREAD->last_cycle;509 atomic_time_increment(&THREAD->kcycles, get_cycle() - THREAD->last_cycle); 510 510 511 511 /* -
kernel/generic/src/proc/task.c
r33e15a0 r11909ce3 506 506 /* Current values of threads */ 507 507 list_foreach(task->threads, th_link, thread_t, thread) { 508 irq_spinlock_lock(&thread->lock, false);509 510 508 /* Process only counted threads */ 511 509 if (!thread->uncounted) { … … 515 513 } 516 514 517 uret += thread->ucycles;518 kret += thread->kcycles;515 uret += atomic_time_read(&thread->ucycles); 516 kret += atomic_time_read(&thread->kcycles); 519 517 } 520 521 irq_spinlock_unlock(&thread->lock, false);522 518 } 523 519 -
kernel/generic/src/proc/thread.c
r33e15a0 r11909ce3 258 258 thread->thread_code = func; 259 259 thread->thread_arg = arg; 260 thread->ucycles = 0;261 thread->kcycles = 0;260 thread->ucycles = ATOMIC_TIME_INITIALIZER(); 261 thread->kcycles = ATOMIC_TIME_INITIALIZER(); 262 262 thread->uncounted = 263 263 ((flags & THREAD_FLAG_UNCOUNTED) == THREAD_FLAG_UNCOUNTED); … … 333 333 334 334 if (!thread->uncounted) { 335 thread->task->ucycles += thread->ucycles;336 thread->task->kcycles += thread->kcycles;335 thread->task->ucycles += atomic_time_read(&thread->ucycles); 336 thread->task->kcycles += atomic_time_read(&thread->kcycles); 337 337 } 338 338 … … 682 682 uint64_t ucycles, kcycles; 683 683 char usuffix, ksuffix; 684 order_suffix( thread->ucycles, &ucycles, &usuffix);685 order_suffix( thread->kcycles, &kcycles, &ksuffix);684 order_suffix(atomic_time_read(&thread->ucycles), &ucycles, &usuffix); 685 order_suffix(atomic_time_read(&thread->kcycles), &kcycles, &ksuffix); 686 686 687 687 state_t state = atomic_get_unordered(&thread->state); … … 788 788 void thread_update_accounting(bool user) 789 789 { 790 assert(interrupts_disabled()); 791 790 792 uint64_t time = get_cycle(); 791 793 792 assert(interrupts_disabled());793 assert(irq_spinlock_locked(&THREAD->lock));794 795 794 if (user) 796 THREAD->ucycles += time - THREAD->last_cycle;795 atomic_time_increment(&THREAD->ucycles, time - THREAD->last_cycle); 797 796 else 798 THREAD->kcycles += time - THREAD->last_cycle;797 atomic_time_increment(&THREAD->kcycles, time - THREAD->last_cycle); 799 798 800 799 THREAD->last_cycle = time; -
kernel/generic/src/syscall/syscall.c
r33e15a0 r11909ce3 141 141 { 142 142 /* Do userpace accounting */ 143 i rq_spinlock_lock(&THREAD->lock, true);143 ipl_t ipl = interrupts_disable(); 144 144 thread_update_accounting(true); 145 i rq_spinlock_unlock(&THREAD->lock, true);145 interrupts_restore(ipl); 146 146 147 147 #ifdef CONFIG_UDEBUG … … 191 191 192 192 /* Do kernel accounting */ 193 i rq_spinlock_lock(&THREAD->lock, true);193 ipl = interrupts_disable(); 194 194 thread_update_accounting(false); 195 i rq_spinlock_unlock(&THREAD->lock, true);195 interrupts_restore(ipl); 196 196 197 197 return rc; -
kernel/generic/src/sysinfo/stats.c
r33e15a0 r11909ce3 299 299 { 300 300 assert(interrupts_disabled()); 301 assert(irq_spinlock_locked(&thread->lock));302 301 303 302 stats_thread->thread_id = thread->tid; … … 305 304 stats_thread->state = atomic_get_unordered(&thread->state); 306 305 stats_thread->priority = atomic_get_unordered(&thread->priority); 307 stats_thread->ucycles = thread->ucycles;308 stats_thread->kcycles = thread->kcycles;306 stats_thread->ucycles = atomic_time_read(&thread->ucycles); 307 stats_thread->kcycles = atomic_time_read(&thread->kcycles); 309 308 310 309 cpu_t *cpu = atomic_get_unordered(&thread->cpu);
Note:
See TracChangeset
for help on using the changeset viewer.