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


Ignore:
Timestamp:
2024-01-20T17:09:00Z (4 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
3d84734
Parents:
286da52
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-20 16:12:46)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-20 17:09:00)
Message:

Make thread→cpu weakly atomic, to avoid need for thread lock

File:
1 edited

Legend:

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

    r286da52 refed95a3  
    311311
    312312        irq_spinlock_lock(&THREAD->lock, false);
    313         assert(THREAD->cpu == CPU);
     313        assert(atomic_get_unordered(&THREAD->cpu) == CPU);
    314314
    315315        THREAD->state = Running;
     
    387387
    388388        assert(thread->state == Running);
    389         assert(thread->cpu == CPU);
     389        assert(atomic_get_unordered(&thread->cpu) == CPU);
    390390
    391391        int i = (thread->priority < RQ_COUNT - 1) ?
     
    411411
    412412        /* Prefer the CPU on which the thread ran last */
    413         if (!thread->cpu)
    414                 thread->cpu = CPU;
    415 
    416         cpu_t *cpu = thread->cpu;
     413        cpu_t *cpu = atomic_get_unordered(&thread->cpu);
     414
     415        if (!cpu) {
     416                cpu = CPU;
     417                atomic_set_unordered(&thread->cpu, CPU);
     418        }
    417419
    418420        irq_spinlock_unlock(&thread->lock, false);
     
    656658
    657659                thread->stolen = true;
    658                 thread->cpu = CPU;
     660                atomic_set_unordered(&thread->cpu, CPU);
    659661
    660662                irq_spinlock_unlock(&thread->lock, false);
Note: See TracChangeset for help on using the changeset viewer.