Changeset 1a1744e in mainline


Ignore:
Timestamp:
2008-06-23T18:49:45Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1bb3766
Parents:
08a19ba
Message:

Get rid of the infamous "Sleep not implemented" panic during low memory
condition. Use a condition variable to implement the sleep. As of now, the
condition is rather coarse and can cause that threads may sleep unnecessarily.
Needs to be fine tuned and based on the amount of memory available.

File:
1 edited

Legend:

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

    r08a19ba r1a1744e  
    5959#include <adt/list.h>
    6060#include <synch/spinlock.h>
     61#include <synch/mutex.h>
     62#include <synch/condvar.h>
    6163#include <arch/asm.h>
    6264#include <arch.h>
     
    104106static zones_t zones;
    105107
     108/*
     109 * Synchronization primitives used to sleep when there is no memory
     110 * available.
     111 */
     112mutex_t zones_mtx;
     113condvar_t zones_cv;
     114int new_freed_mem = false;
    106115
    107116/********************/
     
    9921001        if (!zone) {
    9931002                /*
    994                  * TODO: Sleep until frames are available again.
     1003                 * Sleep until some frames are available again.
    9951004                 */
     1005                if (flags & FRAME_ATOMIC) {
     1006                        interrupts_restore(ipl);
     1007                        return 0;
     1008                }
     1009               
     1010#ifdef CONFIG_DEBUG
     1011                printf("Thread %" PRIu64 " falling asleep, low memory.\n", THREAD->tid);
     1012#endif
     1013
     1014                mutex_lock(&zones_mtx);
     1015                if (!new_freed_mem)
     1016                        condvar_wait(&zones_cv, &zones_mtx);
     1017                new_freed_mem = false;
     1018                mutex_unlock(&zones_mtx);
     1019
     1020#ifdef CONFIG_DEBUG
     1021                printf("Thread %" PRIu64 " woken up, memory available.\n", THREAD->tid);
     1022#endif
     1023
    9961024                interrupts_restore(ipl);
    997 
    998                 if (flags & FRAME_ATOMIC)
    999                         return 0;
    1000                
    1001                 panic("Sleep not implemented.\n");
    10021025                goto loop;
    10031026        }
     
    10291052
    10301053        ipl = interrupts_disable();
    1031        
     1054
    10321055        /*
    10331056         * First, find host frame zone for addr.
    10341057         */
    1035         zone = find_zone_and_lock(pfn,NULL);
     1058        zone = find_zone_and_lock(pfn, NULL);
    10361059        ASSERT(zone);
    10371060       
    1038         zone_frame_free(zone, pfn-zone->base);
     1061        zone_frame_free(zone, pfn - zone->base);
    10391062       
    10401063        spinlock_unlock(&zone->lock);
     1064       
     1065        /*
     1066         * Signal that some memory has been freed.
     1067         */
     1068        mutex_lock(&zones_mtx);
     1069        new_freed_mem = true;
     1070        condvar_broadcast(&zones_cv);
     1071        mutex_unlock(&zones_mtx);
     1072
    10411073        interrupts_restore(ipl);
    10421074}
     
    11171149                frame_mark_unavailable(0, 1);
    11181150        }
     1151
     1152        mutex_initialize(&zones_mtx, MUTEX_ACTIVE);     /* mimic spinlock */
     1153        condvar_initialize(&zones_cv);
    11191154}
    11201155
Note: See TracChangeset for help on using the changeset viewer.