Changeset 3d84734 in mainline


Ignore:
Timestamp:
2024-01-20T17:19:52Z (4 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

Location:
kernel/generic
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/proc/thread.h

    refed95a3 r3d84734  
    155155
    156156        /** Thread's priority. Implemented as index to CPU->rq */
    157         int priority;
     157        atomic_int_fast32_t priority;
    158158        /** Thread ID. */
    159159        thread_id_t tid;
  • 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
  • kernel/generic/src/proc/thread.c

    refed95a3 r3d84734  
    262262        thread->uncounted =
    263263            ((flags & THREAD_FLAG_UNCOUNTED) == THREAD_FLAG_UNCOUNTED);
    264         thread->priority = -1;          /* Start in rq[0] */
     264        atomic_init(&thread->priority, -1);          /* Start in rq[0] */
    265265        atomic_init(&thread->cpu, NULL);
    266266        thread->stolen = false;
  • kernel/generic/src/sysinfo/stats.c

    refed95a3 r3d84734  
    304304        stats_thread->task_id = thread->task->taskid;
    305305        stats_thread->state = thread->state;
    306         stats_thread->priority = thread->priority;
     306        stats_thread->priority = atomic_get_unordered(&thread->priority);
    307307        stats_thread->ucycles = thread->ucycles;
    308308        stats_thread->kcycles = thread->kcycles;
Note: See TracChangeset for help on using the changeset viewer.