Changeset 1068f6a in mainline


Ignore:
Timestamp:
2006-05-20T19:32:06Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c1982e45
Parents:
9ea6cc5
Message:

Turn address space lock, address space area lock and
page_ht_lock into mutexes.

Files:
10 edited

Legend:

Unmodified
Added
Removed
  • genarch/include/mm/page_ht.h

    r9ea6cc5 r1068f6a  
    7171
    7272extern page_mapping_operations_t ht_mapping_operations;
    73 extern spinlock_t page_ht_lock;
     73extern mutex_t page_ht_lock;
    7474extern hash_table_t page_ht;
    7575extern hash_table_operations_t ht_operations;
  • genarch/src/mm/as_ht.c

    r9ea6cc5 r1068f6a  
    4040#include <memstr.h>
    4141#include <adt/hash_table.h>
    42 #include <synch/spinlock.h>
     42#include <synch/mutex.h>
    4343
    4444static pte_t *ht_create(int flags);
     
    6767        if (flags & FLAG_AS_KERNEL) {
    6868                hash_table_create(&page_ht, PAGE_HT_ENTRIES, 2, &ht_operations);
     69                mutex_initialize(&page_ht_lock);
    6970        }
    7071        return NULL;
     
    8283{
    8384        if (lock)
    84                 spinlock_lock(&as->lock);
    85         spinlock_lock(&page_ht_lock);
     85                mutex_lock(&as->lock);
     86        mutex_lock(&page_ht_lock);
    8687}
    8788
     
    9697void ht_unlock(as_t *as, bool unlock)
    9798{
    98         spinlock_unlock(&page_ht_lock);
     99        mutex_unlock(&page_ht_lock);
    99100        if (unlock)
    100                 spinlock_unlock(&as->lock);
     101                mutex_unlock(&as->lock);
    101102}
  • genarch/src/mm/as_pt.c

    r9ea6cc5 r1068f6a  
    3636#include <mm/frame.h>
    3737#include <mm/as.h>
     38#include <synch/mutex.h>
    3839#include <arch/mm/page.h>
    3940#include <arch/mm/as.h>
     
    7980                 
    8081                ipl = interrupts_disable();
    81                 spinlock_lock(&AS_KERNEL->lock);               
     82                mutex_lock(&AS_KERNEL->lock);           
    8283                src_ptl0 = (pte_t *) PA2KA((__address) AS_KERNEL->page_table);
    8384
     
    8788                memsetb((__address) dst_ptl0, PAGE_SIZE, 0);
    8889                memcpy((void *) dst, (void *) src, PAGE_SIZE - (src - (__address) src_ptl0));
    89                 spinlock_unlock(&AS_KERNEL->lock);
     90                mutex_unlock(&AS_KERNEL->lock);
    9091                interrupts_restore(ipl);
    9192        }
     
    105106{
    106107        if (lock)
    107                 spinlock_lock(&as->lock);
     108                mutex_lock(&as->lock);
    108109}
    109110
     
    119120{
    120121        if (unlock)
    121                 spinlock_unlock(&as->lock);
     122                mutex_unlock(&as->lock);
    122123}
  • genarch/src/mm/asid.c

    r9ea6cc5 r1068f6a  
    5858#include <arch/mm/asid.h>
    5959#include <synch/spinlock.h>
     60#include <synch/mutex.h>
    6061#include <arch.h>
    6162#include <adt/list.h>
     
    104105               
    105106                as = list_get_instance(tmp, as_t, inactive_as_with_asid_link);
    106                 spinlock_lock(&as->lock);
     107                mutex_lock_active(&as->lock);
    107108
    108109                /*
     
    118119                 */
    119120                as->asid = ASID_INVALID;
    120                 spinlock_unlock(&as->lock);
     121                mutex_unlock(&as->lock);
    121122
    122123                /*
  • genarch/src/mm/page_ht.c

    r9ea6cc5 r1068f6a  
    6262 * locks.
    6363 */
    64 SPINLOCK_INITIALIZE(page_ht_lock);
     64mutex_t page_ht_lock;
    6565
    6666/**
  • generic/include/mm/as.h

    r9ea6cc5 r1068f6a  
    4545#include <typedefs.h>
    4646#include <synch/spinlock.h>
     47#include <synch/mutex.h>
    4748#include <adt/list.h>
    4849#include <adt/btree.h>
     
    6768#define AS_AREA_ATTR_PARTIAL    1       /* Not fully initialized area. */
    6869
    69 #define AS_PF_FAULT             0       /**< The page fault was not resolved by asp_page_fault(). */
     70#define AS_PF_FAULT             0       /**< The page fault was not resolved by as_page_fault(). */
    7071#define AS_PF_OK                1       /**< The page fault was resolved by as_page_fault(). */
    71 #define AS_PF_DEFER             2       /**< The page fault was caused by memcpy_from_uspace(). */
     72#define AS_PF_DEFER             2       /**< The page fault was caused by memcpy_from_uspace()
     73                                             or memcpy_to_uspace(). */
    7274
    7375/** Address space area structure.
     
    7779 */
    7880struct as_area {
    79         SPINLOCK_DECLARE(lock);
     81        mutex_t lock;
    8082        int flags;              /**< Flags related to the memory represented by the address space area. */
    8183        int attributes;         /**< Attributes related to the address space area itself. */
     
    9294 */
    9395struct as {
    94         /** Protected by asidlock. Must be acquired before as->lock. */
     96        /** Protected by asidlock. */
    9597        link_t inactive_as_with_asid_link;
    9698
    97         SPINLOCK_DECLARE(lock);
     99        mutex_t lock;
    98100
    99101        /** Number of processors on wich is this address space active. */
  • generic/include/synch/mutex.h

    r9ea6cc5 r1068f6a  
    4545#define mutex_lock_timeout(mtx,usec) \
    4646        _mutex_lock_timeout((mtx),(usec),SYNCH_NON_BLOCKING)
    47        
     47#define mutex_lock_active(mtx) \
     48        while (mutex_trylock((mtx)) != ESYNCH_OK_ATOMIC)
     49
    4850extern void mutex_initialize(mutex_t *mtx);
    4951extern int _mutex_lock_timeout(mutex_t *mtx, __u32 usec, int trylock);
  • generic/include/typedefs.h

    r9ea6cc5 r1068f6a  
    6464typedef struct futex futex_t;
    6565
    66 typedef struct chunk chunk_t;
    67 
    6866typedef struct buddy_system buddy_system_t;
    6967typedef struct buddy_system_operations buddy_system_operations_t;
    7068
    71 typedef enum as_area_type as_area_type_t;
    7269typedef struct as_area as_area_t;
    7370typedef struct as as_t;
    7471
    7572typedef struct link link_t;
    76 
    77 typedef char *char_ptr;
    7873
    7974typedef struct the the_t;
  • generic/src/mm/as.c

    r9ea6cc5 r1068f6a  
    5555#include <arch/mm/asid.h>
    5656#include <synch/spinlock.h>
     57#include <synch/mutex.h>
    5758#include <adt/list.h>
    5859#include <adt/btree.h>
     
    7576as_operations_t *as_operations = NULL;
    7677
    77 /** Address space lock. It protects inactive_as_with_asid_head. */
     78/** Address space lock. It protects inactive_as_with_asid_head. Must be acquired before as_t mutex. */
    7879SPINLOCK_INITIALIZE(as_lock);
    7980
     
    111112        as = (as_t *) malloc(sizeof(as_t), 0);
    112113        link_initialize(&as->inactive_as_with_asid_link);
    113         spinlock_initialize(&as->lock, "as_lock");
     114        mutex_initialize(&as->lock);
    114115        btree_create(&as->as_area_btree);
    115116       
     
    163164       
    164165        ipl = interrupts_disable();
    165         spinlock_lock(&as->lock);
     166        mutex_lock(&as->lock);
    166167       
    167168        if (!check_area_conflicts(as, base, size, NULL)) {
    168                 spinlock_unlock(&as->lock);
     169                mutex_unlock(&as->lock);
    169170                interrupts_restore(ipl);
    170171                return NULL;
     
    173174        a = (as_area_t *) malloc(sizeof(as_area_t), 0);
    174175
    175         spinlock_initialize(&a->lock, "as_area_lock");
     176        mutex_initialize(&a->lock);
    176177       
    177178        a->flags = flags;
     
    182183        btree_insert(&as->as_area_btree, base, (void *) a, NULL);
    183184
    184         spinlock_unlock(&as->lock);
     185        mutex_unlock(&as->lock);
    185186        interrupts_restore(ipl);
    186187
     
    204205       
    205206        ipl = interrupts_disable();
    206         spinlock_lock(&as->lock);
     207        mutex_lock(&as->lock);
    207208       
    208209        /*
     
    211212        area = find_area_and_lock(as, address);
    212213        if (!area) {
    213                 spinlock_unlock(&as->lock);
     214                mutex_unlock(&as->lock);
    214215                interrupts_restore(ipl);
    215216                return ENOENT;
     
    221222                 * with memory mapped devices is not supported.
    222223                 */
    223                 spinlock_unlock(&area->lock);
    224                 spinlock_unlock(&as->lock);
     224                mutex_unlock(&area->lock);
     225                mutex_unlock(&as->lock);
    225226                interrupts_restore(ipl);
    226227                return ENOTSUP;
     
    232233                 * Zero size address space areas are not allowed.
    233234                 */
    234                 spinlock_unlock(&area->lock);
    235                 spinlock_unlock(&as->lock);
     235                mutex_unlock(&area->lock);
     236                mutex_unlock(&as->lock);
    236237                interrupts_restore(ipl);
    237238                return EPERM;
     
    279280                 */
    280281                if (!check_area_conflicts(as, address, pages * PAGE_SIZE, area)) {
    281                         spinlock_unlock(&area->lock);
    282                         spinlock_unlock(&as->lock);             
     282                        mutex_unlock(&area->lock);
     283                        mutex_unlock(&as->lock);               
    283284                        interrupts_restore(ipl);
    284285                        return EADDRNOTAVAIL;
     
    288289        area->pages = pages;
    289290       
    290         spinlock_unlock(&area->lock);
    291         spinlock_unlock(&as->lock);
     291        mutex_unlock(&area->lock);
     292        mutex_unlock(&as->lock);
    292293        interrupts_restore(ipl);
    293294
     
    310311
    311312        ipl = interrupts_disable();
    312         spinlock_lock(&as->lock);
     313        mutex_lock(&as->lock);
    313314
    314315        area = find_area_and_lock(as, address);
    315316        if (!area) {
    316                 spinlock_unlock(&as->lock);
     317                mutex_unlock(&as->lock);
    317318                interrupts_restore(ipl);
    318319                return ENOENT;
     
    351352
    352353        area->attributes |= AS_AREA_ATTR_PARTIAL;
    353         spinlock_unlock(&area->lock);
     354        mutex_unlock(&area->lock);
    354355
    355356        /*
     
    360361        free(area);
    361362       
    362         spinlock_unlock(&AS->lock);
     363        mutex_unlock(&AS->lock);
    363364        interrupts_restore(ipl);
    364365        return 0;
     
    398399        src_as = src_task->as;
    399400       
    400         spinlock_lock(&src_as->lock);
     401        mutex_lock(&src_as->lock);
    401402        src_area = find_area_and_lock(src_as, src_base);
    402403        if (!src_area) {
     
    405406                 */
    406407                spinlock_unlock(&src_task->lock);
    407                 spinlock_unlock(&src_as->lock);
     408                mutex_unlock(&src_as->lock);
    408409                interrupts_restore(ipl);
    409410                return ENOENT;
     
    411412        src_size = src_area->pages * PAGE_SIZE;
    412413        src_flags = src_area->flags;
    413         spinlock_unlock(&src_area->lock);
    414         spinlock_unlock(&src_as->lock);
     414        mutex_unlock(&src_area->lock);
     415        mutex_unlock(&src_as->lock);
    415416
    416417
     
    442443         */
    443444        if (AS < src_as) {
    444                 spinlock_lock(&AS->lock);
    445                 spinlock_lock(&src_as->lock);
     445                mutex_lock(&AS->lock);
     446                mutex_lock(&src_as->lock);
    446447        } else {
    447                 spinlock_lock(&AS->lock);
    448                 spinlock_lock(&src_as->lock);
     448                mutex_lock(&AS->lock);
     449                mutex_lock(&src_as->lock);
    449450        }
    450451       
     
    476477         * attribute.
    477478         */     
    478         spinlock_lock(&dst_area->lock);
     479        mutex_lock(&dst_area->lock);
    479480        dst_area->attributes &= ~AS_AREA_ATTR_PARTIAL;
    480         spinlock_unlock(&dst_area->lock);
    481        
    482         spinlock_unlock(&AS->lock);
    483         spinlock_unlock(&src_as->lock);
     481        mutex_unlock(&dst_area->lock);
     482       
     483        mutex_unlock(&AS->lock);
     484        mutex_unlock(&src_as->lock);
    484485        interrupts_restore(ipl);
    485486       
     
    512513        page_mapping_insert(as, page, frame, get_area_flags(area));
    513514       
    514         spinlock_unlock(&area->lock);
     515        mutex_unlock(&area->lock);
    515516        page_table_unlock(as, true);
    516517        interrupts_restore(ipl);
     
    533534        __address frame;
    534535       
     536        if (!THREAD)
     537                return 0;
     538               
    535539        ASSERT(AS);
    536540
    537         spinlock_lock(&AS->lock);
     541        mutex_lock(&AS->lock);
    538542        area = find_area_and_lock(AS, page);   
    539543        if (!area) {
     
    542546                 * Signal page fault to low-level handler.
    543547                 */
    544                 spinlock_unlock(&AS->lock);
     548                mutex_unlock(&AS->lock);
    545549                goto page_fault;
    546550        }
     
    551555                 * Avoid possible race by returning error.
    552556                 */
    553                 spinlock_unlock(&area->lock);
    554                 spinlock_unlock(&AS->lock);
     557                mutex_unlock(&area->lock);
     558                mutex_unlock(&AS->lock);
    555559                goto page_fault;               
    556560        }
     
    568572                if (PTE_PRESENT(pte)) {
    569573                        page_table_unlock(AS, false);
    570                         spinlock_unlock(&area->lock);
    571                         spinlock_unlock(&AS->lock);
     574                        mutex_unlock(&area->lock);
     575                        mutex_unlock(&AS->lock);
    572576                        return 1;
    573577                }
     
    599603        page_table_unlock(AS, false);
    600604       
    601         spinlock_unlock(&area->lock);
    602         spinlock_unlock(&AS->lock);
     605        mutex_unlock(&area->lock);
     606        mutex_unlock(&AS->lock);
    603607        return AS_PF_OK;
    604608
     
    622626/** Switch address spaces.
    623627 *
     628 * Note that this function cannot sleep as it is essentially a part of
     629 * the scheduling. Sleeping here would lead to deadlock on wakeup.
     630 *
    624631 * @param old Old address space or NULL.
    625632 * @param new New address space.
     
    637644         */     
    638645        if (old) {
    639                 spinlock_lock(&old->lock);
     646                mutex_lock_active(&old->lock);
    640647                ASSERT(old->refcount);
    641648                if((--old->refcount == 0) && (old != AS_KERNEL)) {
     
    649656                         list_append(&old->inactive_as_with_asid_link, &inactive_as_with_asid_head);
    650657                }
    651                 spinlock_unlock(&old->lock);
     658                mutex_unlock(&old->lock);
    652659        }
    653660
     
    655662         * Second, prepare the new address space.
    656663         */
    657         spinlock_lock(&new->lock);
     664        mutex_lock_active(&new->lock);
    658665        if ((new->refcount++ == 0) && (new != AS_KERNEL)) {
    659666                if (new->asid != ASID_INVALID)
     
    663670        }
    664671        SET_PTL0_ADDRESS(new->page_table);
    665         spinlock_unlock(&new->lock);
     672        mutex_unlock(&new->lock);
    666673
    667674        if (needs_asid) {
     
    673680               
    674681                asid = asid_get();
    675                 spinlock_lock(&new->lock);
     682                mutex_lock_active(&new->lock);
    676683                new->asid = asid;
    677                 spinlock_unlock(&new->lock);
     684                mutex_unlock(&new->lock);
    678685        }
    679686        spinlock_unlock(&as_lock);
     
    799806        if (a) {
    800807                /* va is the base address of an address space area */
    801                 spinlock_lock(&a->lock);
     808                mutex_lock(&a->lock);
    802809                return a;
    803810        }
     
    812819        for (i = 0; i < leaf->keys; i++) {
    813820                a = (as_area_t *) leaf->value[i];
    814                 spinlock_lock(&a->lock);
     821                mutex_lock(&a->lock);
    815822                if ((a->base <= va) && (va < a->base + a->pages * PAGE_SIZE)) {
    816823                        return a;
    817824                }
    818                 spinlock_unlock(&a->lock);
     825                mutex_unlock(&a->lock);
    819826        }
    820827
     
    825832        if ((lnode = btree_leaf_node_left_neighbour(&as->as_area_btree, leaf))) {
    826833                a = (as_area_t *) lnode->value[lnode->keys - 1];
    827                 spinlock_lock(&a->lock);
     834                mutex_lock(&a->lock);
    828835                if (va < a->base + a->pages * PAGE_SIZE) {
    829836                        return a;
    830837                }
    831                 spinlock_unlock(&a->lock);
     838                mutex_unlock(&a->lock);
    832839        }
    833840
     
    874881        if ((node = btree_leaf_node_left_neighbour(&as->as_area_btree, leaf))) {
    875882                a = (as_area_t *) node->value[node->keys - 1];
    876                 spinlock_lock(&a->lock);
     883                mutex_lock(&a->lock);
    877884                if (overlaps(va, size, a->base, a->pages * PAGE_SIZE)) {
    878                         spinlock_unlock(&a->lock);
     885                        mutex_unlock(&a->lock);
    879886                        return false;
    880887                }
    881                 spinlock_unlock(&a->lock);
     888                mutex_unlock(&a->lock);
    882889        }
    883890        if ((node = btree_leaf_node_right_neighbour(&as->as_area_btree, leaf))) {
    884891                a = (as_area_t *) node->value[0];
    885                 spinlock_lock(&a->lock);
     892                mutex_lock(&a->lock);
    886893                if (overlaps(va, size, a->base, a->pages * PAGE_SIZE)) {
    887                         spinlock_unlock(&a->lock);
     894                        mutex_unlock(&a->lock);
    888895                        return false;
    889896                }
    890                 spinlock_unlock(&a->lock);
     897                mutex_unlock(&a->lock);
    891898        }
    892899       
     
    898905                        continue;
    899906       
    900                 spinlock_lock(&a->lock);
     907                mutex_lock(&a->lock);
    901908                if (overlaps(va, size, a->base, a->pages * PAGE_SIZE)) {
    902                         spinlock_unlock(&a->lock);
     909                        mutex_unlock(&a->lock);
    903910                        return false;
    904911                }
    905                 spinlock_unlock(&a->lock);
     912                mutex_unlock(&a->lock);
    906913        }
    907914
     
    918925}
    919926
    920 /** Return size of address space of current task pointed to by base */
     927/** Return size of the address space area with given base. */
    921928size_t as_get_size(__address base)
    922929{
     
    929936        if (src_area){
    930937                size = src_area->pages * PAGE_SIZE;
    931                 spinlock_unlock(&src_area->lock);
     938                mutex_unlock(&src_area->lock);
    932939        } else {
    933940                size = 0;
  • generic/src/proc/scheduler.c

    r9ea6cc5 r1068f6a  
    422422        relink_rq(priority);           
    423423
    424         spinlock_lock(&THREAD->lock);   
    425 
    426424        /*
    427425         * If both the old and the new task are the same, lots of work is avoided.
     
    455453        }
    456454
     455        spinlock_lock(&THREAD->lock);   
    457456        THREAD->state = Running;
    458457
Note: See TracChangeset for help on using the changeset viewer.