Changeset 169815e in mainline


Ignore:
Timestamp:
2023-04-16T12:22:00Z (18 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fbaf6ac
Parents:
b2ec5cf
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-04-16 12:14:09)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-04-16 12:22:00)
Message:

Split cpu_t::lock into fpu_lock and tlb_lock

For all other purposes, locking is unnecessary, since the fields
in question are only accessed locally from the CPU they belong to.

Location:
kernel/generic
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/cpu.h

    rb2ec5cf r169815e  
    5151 */
    5252typedef struct cpu {
    53         IRQ_SPINLOCK_DECLARE(lock);
     53        IRQ_SPINLOCK_DECLARE(tlb_lock);
    5454
    5555        tlb_shootdown_msg_t tlb_messages[TLB_MESSAGE_QUEUE_LEN];
     
    9797        cpu_arch_t arch;
    9898
     99        IRQ_SPINLOCK_DECLARE(fpu_lock);
    99100        struct thread *fpu_owner;
    100101
  • kernel/generic/src/cpu/cpu.c

    rb2ec5cf r169815e  
    8484                        cpus[i].id = i;
    8585
    86                         irq_spinlock_initialize(&cpus[i].lock, "cpus[].lock");
     86                        irq_spinlock_initialize(&cpus[i].fpu_lock, "cpus[].fpu_lock");
     87                        irq_spinlock_initialize(&cpus[i].tlb_lock, "cpus[].tlb_lock");
    8788
    8889                        for (unsigned int j = 0; j < RQ_COUNT; j++) {
  • kernel/generic/src/interrupt/interrupt.c

    rb2ec5cf r169815e  
    114114        /* Account CPU usage if it woke up from sleep */
    115115        if (CPU && CPU->idle) {
    116                 irq_spinlock_lock(&CPU->lock, false);
    117116                uint64_t now = get_cycle();
    118117                atomic_time_increment(&CPU->idle_cycles, now - CPU->last_cycle);
    119118                CPU->last_cycle = now;
    120119                CPU->idle = false;
    121                 irq_spinlock_unlock(&CPU->lock, false);
    122120        }
    123121
  • kernel/generic/src/mm/tlb.c

    rb2ec5cf r169815e  
    9595                cpu_t *cpu = &cpus[i];
    9696
    97                 irq_spinlock_lock(&cpu->lock, false);
     97                irq_spinlock_lock(&cpu->tlb_lock, false);
    9898                if (cpu->tlb_messages_count == TLB_MESSAGE_QUEUE_LEN) {
    9999                        /*
     
    116116                        cpu->tlb_messages[idx].count = count;
    117117                }
    118                 irq_spinlock_unlock(&cpu->lock, false);
     118                irq_spinlock_unlock(&cpu->tlb_lock, false);
    119119        }
    120120
     
    158158        irq_spinlock_unlock(&tlblock, false);
    159159
    160         irq_spinlock_lock(&CPU->lock, false);
     160        irq_spinlock_lock(&CPU->tlb_lock, false);
    161161        assert(CPU->tlb_messages_count <= TLB_MESSAGE_QUEUE_LEN);
    162162
     
    189189
    190190        CPU->tlb_messages_count = 0;
    191         irq_spinlock_unlock(&CPU->lock, false);
     191        irq_spinlock_unlock(&CPU->tlb_lock, false);
    192192        CPU->tlb_active = true;
    193193}
  • kernel/generic/src/proc/scheduler.c

    rb2ec5cf r169815e  
    129129{
    130130        fpu_enable();
    131         irq_spinlock_lock(&CPU->lock, false);
     131        irq_spinlock_lock(&CPU->fpu_lock, false);
    132132
    133133        /* Save old context */
     
    154154        irq_spinlock_unlock(&THREAD->lock, false);
    155155
    156         irq_spinlock_unlock(&CPU->lock, false);
     156        irq_spinlock_unlock(&CPU->fpu_lock, false);
    157157}
    158158#endif /* CONFIG_FPU_LAZY */
     
    187187                 * This improves energy saving and hyperthreading.
    188188                 */
    189                 irq_spinlock_lock(&CPU->lock, false);
    190189                CPU->idle = true;
    191                 irq_spinlock_unlock(&CPU->lock, false);
    192190
    193191                /*
     
    298296        size_t n = 0;
    299297
    300         irq_spinlock_lock(&CPU->lock, false);
    301 
    302298        /* Move every list (except the one with highest priority) one level up. */
    303299        for (int i = RQ_COUNT - 1; i > start; i--) {
     
    322318                irq_spinlock_unlock(&CPU->rq[start].lock, false);
    323319        }
    324 
    325         irq_spinlock_unlock(&CPU->lock, false);
    326320}
    327321
     
    684678                        continue;
    685679
    686                 irq_spinlock_lock(&cpus[cpu].lock, true);
    687 
    688680                /* Technically a data race, but we don't really care in this case. */
    689681                int needs_relink = cpus[cpu].relink_deadline - cpus[cpu].current_clock_tick;
     
    711703                        irq_spinlock_unlock(&(cpus[cpu].rq[i].lock), false);
    712704                }
    713 
    714                 irq_spinlock_unlock(&cpus[cpu].lock, true);
    715705        }
    716706}
  • kernel/generic/src/proc/thread.c

    rb2ec5cf r169815e  
    425425
    426426        assert((thread->state == Exiting) || (thread->state == Lingering));
    427         assert(thread->cpu);
    428427
    429428        /* Clear cpu->fpu_owner if set to this thread. */
    430         irq_spinlock_lock(&thread->cpu->lock, false);
    431         if (thread->cpu->fpu_owner == thread)
    432                 thread->cpu->fpu_owner = NULL;
    433         irq_spinlock_unlock(&thread->cpu->lock, false);
     429#ifdef CONFIG_FPU_LAZY
     430        if (thread->cpu) {
     431                irq_spinlock_lock(&thread->cpu->fpu_lock, false);
     432                if (thread->cpu->fpu_owner == thread)
     433                        thread->cpu->fpu_owner = NULL;
     434                irq_spinlock_unlock(&thread->cpu->fpu_lock, false);
     435        }
     436#endif
    434437
    435438        interrupts_restore(ipl);
  • kernel/generic/src/sysinfo/stats.c

    rb2ec5cf r169815e  
    119119        size_t i;
    120120        for (i = 0; i < config.cpu_count; i++) {
    121                 irq_spinlock_lock(&cpus[i].lock, true);
    122 
    123121                stats_cpus[i].id = cpus[i].id;
    124122                stats_cpus[i].active = cpus[i].active;
     
    127125                stats_cpus[i].busy_cycles = atomic_time_read(&cpus[i].busy_cycles);
    128126                stats_cpus[i].idle_cycles = atomic_time_read(&cpus[i].idle_cycles);
    129 
    130                 irq_spinlock_unlock(&cpus[i].lock, true);
    131127        }
    132128
  • kernel/generic/src/time/clock.c

    rb2ec5cf r169815e  
    123123static void cpu_update_accounting(void)
    124124{
    125         irq_spinlock_lock(&CPU->lock, false);
    126125        uint64_t now = get_cycle();
    127126        atomic_time_increment(&CPU->busy_cycles, now - CPU->last_cycle);
    128127        CPU->last_cycle = now;
    129         irq_spinlock_unlock(&CPU->lock, false);
    130128}
    131129
Note: See TracChangeset for help on using the changeset viewer.