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


Ignore:
Timestamp:
2023-02-25T11:51:04Z (12 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4f84ee42
Parents:
4777e02
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-22 12:09:47)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-25 11:51:04)
Message:

Move some oddly placed accounting code

Thread ucycles and kcycles should be transferred to the task
accounting when a thread is destroyed, regardless of the
circumstances of its exit. The original code seems to only
do so when a thread returns from its implementing function.

File:
1 edited

Legend:

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

    r4777e02 rc7326f21  
    135135        f(arg);
    136136
    137         /* Accumulate accounting to the task */
    138         irq_spinlock_lock(&THREAD->lock, true);
    139         if (!THREAD->uncounted) {
    140                 thread_update_accounting(true);
    141                 uint64_t ucycles = THREAD->ucycles;
    142                 THREAD->ucycles = 0;
    143                 uint64_t kcycles = THREAD->kcycles;
    144                 THREAD->kcycles = 0;
    145 
    146                 irq_spinlock_pass(&THREAD->lock, &TASK->lock);
    147                 TASK->ucycles += ucycles;
    148                 TASK->kcycles += kcycles;
    149                 irq_spinlock_unlock(&TASK->lock, true);
    150         } else
    151                 irq_spinlock_unlock(&THREAD->lock, true);
    152 
    153137        thread_exit();
    154138
     
    419403        ipl_t ipl = interrupts_disable();
    420404
    421         /* Remove thread from task's list. */
    422         irq_spinlock_lock(&thread->task->lock, false);
    423         list_remove(&thread->th_link);
    424         irq_spinlock_unlock(&thread->task->lock, false);
    425 
    426405        /* Remove thread from global list. */
    427406        irq_spinlock_lock(&threads_lock, false);
     
    429408        irq_spinlock_unlock(&threads_lock, false);
    430409
    431         /* Clear cpu->fpu_owner if set to this thread. */
    432         irq_spinlock_lock(&thread->lock, false);
     410        /* Remove thread from task's list and accumulate accounting. */
     411        irq_spinlock_lock(&thread->task->lock, false);
     412
     413        list_remove(&thread->th_link);
     414
     415        /*
     416         * No other CPU has access to this thread anymore, so we don't need
     417         * thread->lock for accessing thread's fields after this point.
     418         */
     419
     420        if (!thread->uncounted) {
     421                thread->task->ucycles += thread->ucycles;
     422                thread->task->kcycles += thread->kcycles;
     423        }
     424
     425        irq_spinlock_unlock(&thread->task->lock, false);
    433426
    434427        assert((thread->state == Exiting) || (thread->state == Lingering));
    435428        assert(thread->cpu);
    436429
     430        /* Clear cpu->fpu_owner if set to this thread. */
    437431        irq_spinlock_lock(&thread->cpu->lock, false);
    438432        if (thread->cpu->fpu_owner == thread)
    439433                thread->cpu->fpu_owner = NULL;
    440434        irq_spinlock_unlock(&thread->cpu->lock, false);
    441 
    442         irq_spinlock_unlock(&thread->lock, false);
    443435
    444436        interrupts_restore(ipl);
Note: See TracChangeset for help on using the changeset viewer.