/kernel/trunk/test/mm/falloc1/test.c |
---|
0,0 → 1,84 |
/* |
* Copyright (C) 2006 Sergey Bondari |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <print.h> |
#include <test.h> |
#include <mm/page.h> |
#include <mm/frame.h> |
#include <arch/mm/page.h> |
#include <arch/types.h> |
#include <debug.h> |
#define MAX_FRAMES 1024 |
#define MAX_ORDER 8 |
#define TEST_RUNS 4 |
void test(void) { |
__address frames[MAX_FRAMES]; |
int results[MAX_ORDER+1]; |
int i, order, run; |
int allocated; |
int status; |
ASSERT(TEST_RUNS > 1); |
for (run=0;run<=TEST_RUNS;run++) { |
for (order=0;order<=MAX_ORDER;order++) { |
printf("Allocating %d frames blocks ... ", 1<<order); |
allocated = 0; |
for (i=0;i<MAX_FRAMES>>order;i++) { |
frames[allocated] = frame_alloc(FRAME_NON_BLOCKING,order, &status); |
if (status == 0) { |
allocated++; |
} else { |
printf("done. "); |
break; |
} |
} |
printf("%d blocks alocated.\n", allocated); |
if (run) { |
if (results[order] != allocated) { |
panic("Test failed. Frame leak possible.\n"); |
} |
} else results[order] = allocated; |
printf("Deallocating ... "); |
for (i=0;i<allocated;i++) { |
frame_free(frames[i]); |
} |
printf("done.\n"); |
} |
} |
printf("Test passed\n"); |
} |
/kernel/trunk/test/mm/mapping1/test.c |
---|
47,8 → 47,8 |
printf("Memory management test mapping #1\n"); |
frame0 = frame_alloc(FRAME_KA, ONE_FRAME); |
frame1 = frame_alloc(FRAME_KA, ONE_FRAME); |
frame0 = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
frame1 = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
printf("Writing %L to physical address %P.\n", VALUE0, KA2PA(frame0)); |
*((__u32 *) frame0) = VALUE0; |
/kernel/trunk/kernel.config |
---|
81,5 → 81,6 |
@ "print/print1" Printf test 1 |
@ "thread/thread1" Thread test 1 |
@ "mm/mapping1" Mapping test 1 |
@ "mm/falloc1" Frame Allocation test 1 |
@ [ARCH=mips32] "debug/mips1" Mips breakpoint-debug test |
! CONFIG_TEST (choice) |
/kernel/trunk/genarch/src/mm/page_pt.c |
---|
63,7 → 63,7 |
ptl0 = (pte_t *) PA2KA(root ? root : (__address) GET_PTL0_ADDRESS()); |
if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) { |
newpt = frame_alloc(FRAME_KA, ONE_FRAME); |
newpt = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
memsetb(newpt, PAGE_SIZE, 0); |
SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt)); |
SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE); |
72,7 → 72,7 |
ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page))); |
if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) { |
newpt = frame_alloc(FRAME_KA, ONE_FRAME); |
newpt = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
memsetb(newpt, PAGE_SIZE, 0); |
SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt)); |
SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE); |
81,7 → 81,7 |
ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page))); |
if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) { |
newpt = frame_alloc(FRAME_KA, ONE_FRAME); |
newpt = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
memsetb(newpt, PAGE_SIZE, 0); |
SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt)); |
SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE); |
/kernel/trunk/generic/include/mm/frame.h |
---|
38,9 → 38,14 |
#define ONE_FRAME 0 |
#define FRAME_KA 1 /* skip frames conflicting with user address space */ |
#define FRAME_PANIC 2 /* panic on failure */ |
#define FRAME_KA 1 /* skip frames conflicting with user address space */ |
#define FRAME_PANIC 2 /* panic on failure */ |
#define FRAME_NON_BLOCKING 4 /* do not panic and do not sleep on failure */ |
#define FRAME_OK 0 /* frame_alloc return status */ |
#define FRAME_NO_MEMORY 1 /* frame_alloc return status */ |
#define FRAME_ERROR 2 /* frame_alloc return status */ |
#define FRAME2ADDR(zone, frame) ((zone)->base + ((frame) - (zone)->frames) * FRAME_SIZE) |
#define ADDR2FRAME(zone, addr) (&((zone)->frames[((addr) - (zone)->base) / FRAME_SIZE])) |
#define FRAME_INDEX(zone, frame) ((index_t)((frame) - (zone)->frames)) |
88,8 → 93,10 |
extern void frame_init(void); |
extern void frame_initialize(frame_t *frame, zone_t *zone); |
__address frame_alloc(int flags, __u8 order); |
__address frame_alloc(int flags, __u8 order, int * status); |
extern void frame_free(__address addr); |
zone_t * get_zone_by_frame(frame_t * frame); |
/* |
/kernel/trunk/generic/src/proc/thread.c |
---|
173,9 → 173,9 |
spinlock_initialize(&t->lock, "thread_t_lock"); |
frame_ks = frame_alloc(FRAME_KA, ONE_FRAME); |
frame_ks = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
if (THREAD_USER_STACK & flags) { |
frame_us = frame_alloc(FRAME_KA, ONE_FRAME); |
frame_us = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
} |
ipl = interrupts_disable(); |
/kernel/trunk/generic/src/cpu/cpu.c |
---|
61,7 → 61,7 |
memsetb((__address) cpus, sizeof(cpu_t) * config.cpu_count, 0); |
for (i=0; i < config.cpu_count; i++) { |
cpus[i].stack = (__u8 *) frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME); |
cpus[i].stack = (__u8 *) frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME, NULL); |
cpus[i].id = i; |
/kernel/trunk/generic/src/mm/vm.c |
---|
70,7 → 70,7 |
pte_t *src_ptl0, *dst_ptl0; |
src_ptl0 = (pte_t *) PA2KA((__address) GET_PTL0_ADDRESS()); |
dst_ptl0 = (pte_t *) frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME); |
dst_ptl0 = (pte_t *) frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME, NULL); |
// memsetb((__address) dst_ptl0, PAGE_SIZE, 0); |
// memcpy((void *) &dst_ptl0[KAS_START_INDEX], (void *) &src_ptl0[KAS_START_INDEX], KAS_INDICES); |
116,7 → 116,7 |
} |
for (i=0; i<size; i++) |
a->mapping[i] = frame_alloc(0, ONE_FRAME); |
a->mapping[i] = frame_alloc(0, ONE_FRAME, NULL); |
spinlock_initialize(&a->lock, "vm_area_lock"); |
/kernel/trunk/generic/src/mm/frame.c |
---|
83,7 → 83,7 |
* |
* @return Allocated frame. |
*/ |
__address frame_alloc(int flags, __u8 order) |
__address frame_alloc(int flags, __u8 order, int * status) |
{ |
ipl_t ipl; |
link_t *cur, *tmp; |
117,6 → 117,8 |
if (flags & FRAME_PANIC) |
panic("Can't allocate frame.\n"); |
/* |
* TODO: Sleep until frames are available again. |
*/ |
123,6 → 125,12 |
spinlock_unlock(&zone_head_lock); |
interrupts_restore(ipl); |
if (flags & FRAME_NON_BLOCKING) { |
ASSERT(status != NULL); |
*status = FRAME_NO_MEMORY; |
return NULL; |
} |
panic("Sleep not implemented.\n"); |
goto loop; |
} |
151,6 → 159,11 |
if (flags & FRAME_KA) |
v = PA2KA(v); |
if (flags & FRAME_NON_BLOCKING) { |
ASSERT(status != NULL); |
*status = FRAME_OK; |
} |
return v; |
} |
/kernel/trunk/arch/mips32/src/mm/page.c |
---|
42,7 → 42,7 |
page_operations = &page_pt_operations; |
ptl0 = frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME); |
ptl0 = frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME, NULL); |
memsetb(ptl0, FRAME_SIZE, 0); |
SET_PTL0_ADDRESS(KA2PA(ptl0)); |