Changeset 3d84734 in mainline for kernel/generic/src/proc/scheduler.c


Ignore:
Timestamp:
2024-01-20T17:19:52Z (15 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
41bfc64
Parents:
efed95a3
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-20 17:18:35)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-20 17:19:52)
Message:

Make thread→priority weakly atomic to avoid need for locking

File:
1 edited

Legend:

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

    refed95a3 r3d84734  
    314314
    315315        THREAD->state = Running;
    316         THREAD->priority = rq_index;  /* Correct rq index */
     316        atomic_set_unordered(&THREAD->priority, rq_index);  /* Correct rq index */
    317317
    318318        /*
     
    325325        log(LF_OTHER, LVL_DEBUG,
    326326            "cpu%u: tid %" PRIu64 " (priority=%d, ticks=%" PRIu64
    327             ", nrdy=%zu)", CPU->id, THREAD->tid, THREAD->priority,
     327            ", nrdy=%zu)", CPU->id, THREAD->tid, rq_index,
    328328            THREAD->ticks, atomic_load(&CPU->nrdy));
    329329#endif
     
    389389        assert(atomic_get_unordered(&thread->cpu) == CPU);
    390390
    391         int i = (thread->priority < RQ_COUNT - 1) ?
    392             ++thread->priority : thread->priority;
     391        int prio = atomic_get_unordered(&thread->priority);
     392
     393        if (prio < RQ_COUNT - 1) {
     394                prio++;
     395                atomic_set_unordered(&thread->priority, prio);
     396        }
    393397
    394398        thread->state = Ready;
     
    396400        irq_spinlock_unlock(&thread->lock, false);
    397401
    398         add_to_rq(thread, CPU, i);
     402        add_to_rq(thread, CPU, prio);
    399403}
    400404
     
    407411        assert(thread->state == Sleeping || thread->state == Entering);
    408412
    409         thread->priority = 0;
     413        atomic_set_unordered(&thread->priority, 0);
    410414        thread->state = Ready;
    411415
Note: See TracChangeset for help on using the changeset viewer.