Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/tlb.c

    rda1bafb r98000fb  
    3333/**
    3434 * @file
    35  * @brief Generic TLB shootdown algorithm.
     35 * @brief       Generic TLB shootdown algorithm.
    3636 *
    3737 * The algorithm implemented here is based on the CMU TLB shootdown
     
    5353#include <cpu.h>
    5454
     55/**
     56 * This lock is used for synchronisation between sender and
     57 * recipients of TLB shootdown message. It must be acquired
     58 * before CPU structure lock.
     59 */
     60SPINLOCK_INITIALIZE(tlblock);
     61
    5562void tlb_init(void)
    5663{
     
    5966
    6067#ifdef CONFIG_SMP
    61 
    62 /**
    63  * This lock is used for synchronisation between sender and
    64  * recipients of TLB shootdown message. It must be acquired
    65  * before CPU structure lock.
    66  *
    67  */
    68 IRQ_SPINLOCK_STATIC_INITIALIZE(tlblock);
    6968
    7069/** Send TLB shootdown message.
     
    7978 * @param page Virtual page address, if required by type.
    8079 * @param count Number of pages, if required by type.
    81  *
    8280 */
    8381void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid,
    8482    uintptr_t page, size_t count)
    8583{
    86         CPU->tlb_active = false;
    87         irq_spinlock_lock(&tlblock, false);
     84        unsigned int i;
     85
     86        CPU->tlb_active = 0;
     87        spinlock_lock(&tlblock);
    8888       
    89         size_t i;
    9089        for (i = 0; i < config.cpu_count; i++) {
    9190                cpu_t *cpu;
     
    9392                if (i == CPU->id)
    9493                        continue;
    95                
     94
    9695                cpu = &cpus[i];
    97                 irq_spinlock_lock(&cpu->lock, false);
     96                spinlock_lock(&cpu->lock);
    9897                if (cpu->tlb_messages_count == TLB_MESSAGE_QUEUE_LEN) {
    9998                        /*
     
    116115                        cpu->tlb_messages[idx].count = count;
    117116                }
    118                 irq_spinlock_unlock(&cpu->lock, false);
     117                spinlock_unlock(&cpu->lock);
    119118        }
    120119       
    121120        tlb_shootdown_ipi_send();
    122        
    123 busy_wait:
     121
     122busy_wait:     
    124123        for (i = 0; i < config.cpu_count; i++)
    125124                if (cpus[i].tlb_active)
     
    127126}
    128127
    129 /** Finish TLB shootdown sequence.
    130  *
    131  */
     128/** Finish TLB shootdown sequence. */
    132129void tlb_shootdown_finalize(void)
    133130{
    134         irq_spinlock_unlock(&tlblock, false);
    135         CPU->tlb_active = true;
     131        spinlock_unlock(&tlblock);
     132        CPU->tlb_active = 1;
    136133}
    137134
     
    141138}
    142139
    143 /** Receive TLB shootdown message.
    144  *
    145  */
     140/** Receive TLB shootdown message. */
    146141void tlb_shootdown_ipi_recv(void)
    147142{
     143        tlb_invalidate_type_t type;
     144        asid_t asid;
     145        uintptr_t page;
     146        size_t count;
     147        unsigned int i;
     148       
    148149        ASSERT(CPU);
    149150       
    150         CPU->tlb_active = false;
    151         irq_spinlock_lock(&tlblock, false);
    152         irq_spinlock_unlock(&tlblock, false);
     151        CPU->tlb_active = 0;
     152        spinlock_lock(&tlblock);
     153        spinlock_unlock(&tlblock);
    153154       
    154         irq_spinlock_lock(&CPU->lock, false);
     155        spinlock_lock(&CPU->lock);
    155156        ASSERT(CPU->tlb_messages_count <= TLB_MESSAGE_QUEUE_LEN);
    156        
    157         size_t i;
     157
    158158        for (i = 0; i < CPU->tlb_messages_count; CPU->tlb_messages_count--) {
    159                 tlb_invalidate_type_t type = CPU->tlb_messages[i].type;
    160                 asid_t asid = CPU->tlb_messages[i].asid;
    161                 uintptr_t page = CPU->tlb_messages[i].page;
    162                 size_t count = CPU->tlb_messages[i].count;
    163                
     159                type = CPU->tlb_messages[i].type;
     160                asid = CPU->tlb_messages[i].asid;
     161                page = CPU->tlb_messages[i].page;
     162                count = CPU->tlb_messages[i].count;
     163
    164164                switch (type) {
    165165                case TLB_INVL_ALL:
     
    170170                        break;
    171171                case TLB_INVL_PAGES:
    172                         ASSERT(count);
     172                        ASSERT(count);
    173173                        tlb_invalidate_pages(asid, page, count);
    174174                        break;
     
    177177                        break;
    178178                }
    179                
    180179                if (type == TLB_INVL_ALL)
    181180                        break;
    182181        }
    183182       
    184         irq_spinlock_unlock(&CPU->lock, false);
    185         CPU->tlb_active = true;
     183        spinlock_unlock(&CPU->lock);
     184        CPU->tlb_active = 1;
    186185}
    187186
Note: See TracChangeset for help on using the changeset viewer.