Ignore:
File:
1 edited

Legend:

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

    rc626117 r6188fee  
    6363#include <proc/thread.h> /* THREAD */
    6464
    65 zones_t zones = {
    66         .count = 0,
    67         .lock = IRQ_SPINLOCK_INITIALIZER("frame.zones.lock"),
    68 };
     65zones_t zones;
    6966
    7067/*
     
    7269 * available.
    7370 */
    74 static IRQ_SPINLOCK_INITIALIZE(mem_avail_lock);
    75 static CONDVAR_INITIALIZE(mem_avail_cv);
     71static mutex_t mem_avail_mtx;
     72static condvar_t mem_avail_cv;
    7673static size_t mem_avail_req = 0;  /**< Number of frames requested. */
    7774static size_t mem_avail_gen = 0;  /**< Generation counter. */
     
    951948#endif
    952949
    953                 /* Disabled interrupts needed to prevent deadlock with TLB shootdown. */
    954                 irq_spinlock_lock(&mem_avail_lock, true);
     950                /*
     951                 * Since the mem_avail_mtx is an active mutex, we need to
     952                 * disable interrupts to prevent deadlock with TLB shootdown.
     953                 */
     954                ipl_t ipl = interrupts_disable();
     955                mutex_lock(&mem_avail_mtx);
    955956
    956957                if (mem_avail_req > 0)
     
    962963
    963964                while (gen == mem_avail_gen)
    964                         condvar_wait(&mem_avail_cv, &mem_avail_lock);
    965 
    966                 irq_spinlock_unlock(&mem_avail_lock, true);
     965                        condvar_wait(&mem_avail_cv, &mem_avail_mtx);
     966
     967                mutex_unlock(&mem_avail_mtx);
     968                interrupts_restore(ipl);
    967969
    968970#ifdef CONFIG_DEBUG
     
    10221024        irq_spinlock_unlock(&zones.lock, true);
    10231025
    1024         /* Signal that some memory has been freed. */
    1025 
    1026         /* Disabled interrupts needed to prevent deadlock with TLB shootdown. */
    1027         irq_spinlock_lock(&mem_avail_lock, true);
     1026        /*
     1027         * Signal that some memory has been freed.
     1028         * Since the mem_avail_mtx is an active mutex,
     1029         * we need to disable interruptsto prevent deadlock
     1030         * with TLB shootdown.
     1031         */
     1032
     1033        ipl_t ipl = interrupts_disable();
     1034        mutex_lock(&mem_avail_mtx);
    10281035
    10291036        if (mem_avail_req > 0)
     
    10351042        }
    10361043
    1037         irq_spinlock_unlock(&mem_avail_lock, true);
     1044        mutex_unlock(&mem_avail_mtx);
     1045        interrupts_restore(ipl);
    10381046
    10391047        if (!(flags & FRAME_NO_RESERVE))
     
    11001108void frame_init(void)
    11011109{
     1110        if (config.cpu_active == 1) {
     1111                zones.count = 0;
     1112                irq_spinlock_initialize(&zones.lock, "frame.zones.lock");
     1113                mutex_initialize(&mem_avail_mtx, MUTEX_ACTIVE);
     1114                condvar_initialize(&mem_avail_cv);
     1115        }
     1116
    11021117        /* Tell the architecture to create some memory */
    11031118        frame_low_arch_init();
Note: See TracChangeset for help on using the changeset viewer.