Changeset f8ddd17 in mainline for uspace/libc/generic/as.c


Ignore:
Timestamp:
2006-12-09T20:20:50Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b82a13c
Parents:
9ab9c2ec
Message:

Rework support for virtually indexed cache.
Instead of repeatedly flushing the data cache, which was a huge overkill, refuse to create an illegal address alias
in the kernel (again) and allocate appropriate page color in userspace instead. Extend the detection also to
SYS_PHYSMEM_MAP syscall.

Add support for tracking physical memory areas mappable by SYS_PHYSMEM_MAP.

Lots of coding style changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/libc/generic/as.c

    r9ab9c2ec rf8ddd17  
    3838#include <align.h>
    3939#include <types.h>
     40#include <bitops.h>
    4041
    4142/**
     
    5455void *as_area_create(void *address, size_t size, int flags)
    5556{
    56         return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t ) address, (sysarg_t) size, (sysarg_t) flags);
     57        return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t ) address,
     58                (sysarg_t) size, (sysarg_t) flags);
    5759}
    5860
    5961/** Resize address space area.
    6062 *
    61  * @param address Virtual address pointing into already existing address space area.
     63 * @param address Virtual address pointing into already existing address space
     64 *      area.
    6265 * @param size New requested size of the area.
    6366 * @param flags Currently unused.
     
    6770int as_area_resize(void *address, size_t size, int flags)
    6871{
    69         return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t ) address, (sysarg_t) size, (sysarg_t) flags);
     72        return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t ) address, (sysarg_t)
     73                size, (sysarg_t) flags);
    7074}
    7175
    7276/** Destroy address space area.
    7377 *
    74  * @param address Virtual address pointing into the address space area being destroyed.
     78 * @param address Virtual address pointing into the address space area being
     79 *      destroyed.
    7580 *
    7681 * @return Zero on success or a code from @ref errno.h on failure.
     
    134139        /* Return pointer to area not managed by sbrk */
    135140        return ((void *) &_heap + maxheapsize);
    136 
    137141}
    138142
    139143/** Return pointer to some unmapped area, where fits new as_area
    140144 *
     145 * @param sz Requested size of the allocation.
     146 * @param color Requested virtual color of the allocation.
     147 *
     148 * @return Pointer to the beginning
     149 *
    141150 * TODO: make some first_fit/... algorithm, we are now just incrementing
    142151 *       the pointer to last area
    143152 */
    144 void * as_get_mappable_page(size_t sz)
     153#include <stdio.h>
     154void *as_get_mappable_page(size_t sz, int color)
    145155{
    146156        void *res;
     157        uint64_t asz;
     158        int i;
     159       
     160        if (!sz)
     161                return NULL;   
     162
     163        asz = 1 << (fnzb64(sz - 1) + 1);
    147164
    148165        /* Set heapsize to some meaningful value */
     
    150167                set_maxheapsize(MAX_HEAP_SIZE);
    151168       
    152         if (!last_allocated)
    153                 last_allocated = (void *) ALIGN_UP((void *) &_heap + maxheapsize, PAGE_SIZE);
    154        
    155         sz = ALIGN_UP(sz, PAGE_SIZE);
     169        /*
     170         * Make sure we allocate from naturally aligned address and a page of
     171         * appropriate color.
     172         */
     173        i = 0;
     174        do {
     175                if (!last_allocated) {
     176                        last_allocated = (void *) ALIGN_UP((void *) &_heap +
     177                                maxheapsize, asz);
     178                } else {
     179                        last_allocated = (void *) ALIGN_UP(((uintptr_t)
     180                                last_allocated) + (int) (i > 0), asz);
     181                }
     182        } while ((asz < (1 << (PAGE_COLOR_BITS + PAGE_WIDTH))) &&
     183                (PAGE_COLOR((uintptr_t) last_allocated) != color) &&
     184                (++i < (1 << PAGE_COLOR_BITS)));
     185
    156186        res = last_allocated;
    157         last_allocated += sz;
     187        last_allocated += ALIGN_UP(sz, PAGE_SIZE);
    158188
    159189        return res;
Note: See TracChangeset for help on using the changeset viewer.