Changeset 11909ce3 in mainline for kernel/generic/src/proc/thread.c


Ignore:
Timestamp:
2024-01-21T15:48:43Z (4 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
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)
Message:

Make thread cycle statistics atomic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/thread.c

    r33e15a0 r11909ce3  
    258258        thread->thread_code = func;
    259259        thread->thread_arg = arg;
    260         thread->ucycles = 0;
    261         thread->kcycles = 0;
     260        thread->ucycles = ATOMIC_TIME_INITIALIZER();
     261        thread->kcycles = ATOMIC_TIME_INITIALIZER();
    262262        thread->uncounted =
    263263            ((flags & THREAD_FLAG_UNCOUNTED) == THREAD_FLAG_UNCOUNTED);
     
    333333
    334334        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);
    337337        }
    338338
     
    682682        uint64_t ucycles, kcycles;
    683683        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);
    686686
    687687        state_t state = atomic_get_unordered(&thread->state);
     
    788788void thread_update_accounting(bool user)
    789789{
     790        assert(interrupts_disabled());
     791
    790792        uint64_t time = get_cycle();
    791793
    792         assert(interrupts_disabled());
    793         assert(irq_spinlock_locked(&THREAD->lock));
    794 
    795794        if (user)
    796                 THREAD->ucycles += time - THREAD->last_cycle;
     795                atomic_time_increment(&THREAD->ucycles, time - THREAD->last_cycle);
    797796        else
    798                 THREAD->kcycles += time - THREAD->last_cycle;
     797                atomic_time_increment(&THREAD->kcycles, time - THREAD->last_cycle);
    799798
    800799        THREAD->last_cycle = time;
Note: See TracChangeset for help on using the changeset viewer.