Changeset 482826d in mainline


Ignore:
Timestamp:
2006-05-31T16:23:19Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
39031cc
Parents:
343fc179
Message:

Function for destroying address space for which there is no other reference in the kernel.

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • arch/ia32/include/mm/asid.h

    r343fc179 r482826d  
    4141
    4242#define asid_get()              (ASID_START+1)
     43#define asid_put(asid)
    4344
    4445#endif
  • genarch/src/mm/as_ht.c

    r343fc179 r482826d  
    4343
    4444static pte_t *ht_create(int flags);
     45static void ht_destroy(pte_t *page_table);
    4546
    4647static void ht_lock(as_t *as, bool lock);
     
    4950as_operations_t as_ht_operations = {
    5051        .page_table_create = ht_create,
     52        .page_table_destroy = ht_destroy,
    5153        .page_table_lock = ht_lock,
    5254        .page_table_unlock = ht_unlock,
     
    7072        }
    7173        return NULL;
     74}
     75
     76/** Destroy page table.
     77 *
     78 * Actually do nothing as the global page hash table is used.
     79 *
     80 * @param page_table This parameter is ignored.
     81 */
     82void ht_destroy(pte_t *page_table)
     83{
     84        /* No-op. */
    7285}
    7386
  • genarch/src/mm/as_pt.c

    r343fc179 r482826d  
    4545
    4646static pte_t *ptl0_create(int flags);
     47static void ptl0_destroy(pte_t *page_table);
    4748
    4849static void pt_lock(as_t *as, bool lock);
     
    5152as_operations_t as_pt_operations = {
    5253        .page_table_create = ptl0_create,
     54        .page_table_destroy = ptl0_destroy,
    5355        .page_table_lock = pt_lock,
    5456        .page_table_unlock = pt_unlock
     
    9597}
    9698
     99/** Destroy page table.
     100 *
     101 * Destroy PTL0, other levels are expected to be already deallocated.
     102 *
     103 * @param page_table Physical address of PTL0.
     104 */
     105void ptl0_destroy(pte_t *page_table)
     106{
     107        frame_free(ADDR2PFN((__address) page_table));
     108}
     109
    97110/** Lock page tables.
    98111 *
  • generic/include/mm/as.h

    r343fc179 r482826d  
    7676        mutex_t lock;
    7777
     78        /** Number of references (i.e tasks that reference this as). */
     79        count_t refcount;
     80
    7881        /** Number of processors on wich is this address space active. */
    7982        count_t cpu_refcount;
     
    9194struct as_operations {
    9295        pte_t *(* page_table_create)(int flags);
     96        void (* page_table_destroy)(pte_t *page_table);
    9397        void (* page_table_lock)(as_t *as, bool lock);
    9498        void (* page_table_unlock)(as_t *as, bool unlock);
     
    159163
    160164extern void as_init(void);
     165
    161166extern as_t *as_create(int flags);
     167extern void as_destroy(as_t *as);
     168extern void as_switch(as_t *old, as_t *new);
     169extern int as_page_fault(__address page, pf_access_t access, istate_t *istate);
     170
    162171extern as_area_t *as_area_create(as_t *as, int flags, size_t size, __address base, int attrs,
    163172        mem_backend_t *backend, mem_backend_data_t *backend_data);
     173extern int as_area_destroy(as_t *as, __address address);       
    164174extern int as_area_resize(as_t *as, __address address, size_t size, int flags);
    165 extern int as_area_destroy(as_t *as, __address address);
     175int as_area_share(as_t *src_as, __address src_base, size_t acc_size,
     176                  as_t *dst_as, __address dst_base, int dst_flags_mask);
     177
    166178extern int as_area_get_flags(as_area_t *area);
    167179extern bool as_area_check_access(as_area_t *area, pf_access_t access);
    168 extern int as_page_fault(__address page, pf_access_t access, istate_t *istate);
    169 extern void as_switch(as_t *old, as_t *new);
    170 extern void as_free(as_t *as);
    171 int as_area_share(as_t *src_as, __address src_base, size_t acc_size,
    172                   as_t *dst_as, __address dst_base, int dst_flags_mask);
    173180extern size_t as_get_size(__address base);
    174181extern int used_space_insert(as_area_t *a, __address page, count_t count);
  • generic/include/mm/page.h

    r343fc179 r482826d  
    8686extern pte_t *page_mapping_find(as_t *as, __address page);
    8787extern pte_t *page_table_create(int flags);
     88extern void page_table_destroy(pte_t *page_table);
    8889extern void map_structure(__address s, size_t size);
    8990extern __address hw_map(__address physaddr, size_t size);
  • generic/include/proc/task.h

    r343fc179 r482826d  
    5757       
    5858        /**
    59           * Serializes access to the B+tree of task's futexes. This mutex is
    60           * independent on the task spinlock.
    61           */
     59         * Serializes access to the B+tree of task's futexes. This mutex is
     60         * independent on the task spinlock.
     61         */
    6262        mutex_t futexes_lock;
    6363        btree_t futexes;        /**< B+tree of futexes referenced by this task. */
  • generic/src/mm/as.c

    r343fc179 r482826d  
    122122                as->asid = ASID_INVALID;
    123123       
     124        as->refcount = 0;
    124125        as->cpu_refcount = 0;
    125126        as->page_table = page_table_create(flags);
     
    128129}
    129130
    130 /** Free Adress space */
    131 void as_free(as_t *as)
    132 {
    133         ASSERT(as->cpu_refcount == 0);
    134 
    135         /* TODO: free as_areas and other resources held by as */
    136         /* TODO: free page table */
     131/** Destroy adress space.
     132 *
     133 * When there are no tasks referencing this address space (i.e. its refcount is zero),
     134 * the address space can be destroyed.
     135 */
     136void as_destroy(as_t *as)
     137{
     138        ipl_t ipl;
     139        bool cond;
     140
     141        ASSERT(as->refcount == 0);
     142       
     143        /*
     144         * Since there is no reference to this area,
     145         * it is safe not to lock its mutex.
     146         */
     147         
     148        ipl = interrupts_disable();
     149        spinlock_lock(&inactive_as_with_asid_lock);
     150        if (as->asid != ASID_INVALID && as->asid != ASID_KERNEL) {
     151                list_remove(&as->inactive_as_with_asid_link);
     152                asid_put(as->asid);
     153        }
     154        spinlock_unlock(&inactive_as_with_asid_lock);
     155
     156        /*
     157         * Destroy address space areas of the address space.
     158         */     
     159        for (cond = true; cond; ) {
     160                btree_node_t *node;
     161               
     162                ASSERT(!list_empty(&as->as_area_btree.leaf_head));
     163                node = list_get_instance(&as->as_area_btree.leaf_head.next, btree_node_t, leaf_link);
     164                if ((cond = node->keys)) {
     165                        as_area_destroy(as, node->key[0]);
     166                        btree_remove(&as->as_area_btree, node->key[0], node);
     167                }
     168        }
     169       
     170        page_table_destroy(as->page_table);
     171
     172        interrupts_restore(ipl);
     173       
    137174        free(as);
    138175}
     
    841878}
    842879
     880/** Destroy page table.
     881 *
     882 * Destroy page table in architecture specific way.
     883 *
     884 * @param page_table Physical address of PTL0.
     885 */
     886void page_table_destroy(pte_t *page_table)
     887{
     888        ASSERT(as_operations);
     889        ASSERT(as_operations->page_table_destroy);
     890
     891        as_operations->page_table_destroy(page_table);
     892}
     893
    843894/** Lock page table.
    844895 *
  • generic/src/proc/task.c

    r343fc179 r482826d  
    108108       
    109109        ipl = interrupts_disable();
     110
     111        /*
     112         * Increment address space reference count.
     113         * TODO: Reconsider the locking scheme.
     114         */
     115        mutex_lock(&as->lock);
     116        as->refcount++;
     117        mutex_unlock(&as->lock);
     118
    110119        spinlock_lock(&tasks_lock);
    111120
     
    140149        rc = elf_load((elf_header_t *) program_addr, as);
    141150        if (rc != EE_OK) {
    142                 as_free(as);
     151                as_destroy(as);
    143152                return NULL;
    144153        }
Note: See TracChangeset for help on using the changeset viewer.