Subversion Repositories HelenOS

Rev

Rev 3343 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
692 bondari 1
/*
2071 jermar 2
 * Copyright (c) 2006 Sergey Bondari
692 bondari 3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
2028 decky 28
 
692 bondari 29
#include <print.h>
30
#include <test.h>
31
#include <mm/page.h>
32
#include <mm/frame.h>
814 palkovsky 33
#include <mm/slab.h>
692 bondari 34
#include <arch/mm/page.h>
3862 rimsky 35
#include <arch/asm.h>
692 bondari 36
#include <arch/types.h>
1104 jermar 37
#include <atomic.h>
692 bondari 38
#include <debug.h>
39
#include <proc/thread.h>
40
#include <memstr.h>
745 jermar 41
#include <arch.h>
692 bondari 42
 
735 bondari 43
#define MAX_FRAMES 256
44
#define MAX_ORDER 8
692 bondari 45
 
733 bondari 46
#define THREAD_RUNS 1
735 bondari 47
#define THREADS 8
692 bondari 48
 
49
static atomic_t thread_count;
2028 decky 50
static atomic_t thread_fail;
2053 decky 51
static bool sh_quiet;
692 bondari 52
 
2028 decky 53
static void falloc(void * arg)
745 jermar 54
{
1767 palkovsky 55
    int order, run, allocated, i;
1780 jermar 56
    uint8_t val = THREAD->tid % THREADS;
733 bondari 57
    index_t k;
692 bondari 58
 
3104 svoboda 59
    void **frames =  (void **) malloc(MAX_FRAMES * sizeof(void *), FRAME_ATOMIC);
2028 decky 60
    if (frames == NULL) {
2053 decky 61
        if (!sh_quiet)
3069 decky 62
            printf("Thread #%" PRIu64 " (cpu%u): Unable to allocate frames\n", THREAD->tid, CPU->id);
2028 decky 63
        atomic_inc(&thread_fail);
64
        atomic_dec(&thread_count);
65
        return;
66
    }
1658 vana 67
 
68
    thread_detach(THREAD);
692 bondari 69
 
745 jermar 70
    for (run = 0; run < THREAD_RUNS; run++) {
71
        for (order = 0; order <= MAX_ORDER; order++) {
2053 decky 72
            if (!sh_quiet)
3069 decky 73
                printf("Thread #%" PRIu64 " (cpu%u): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order);
2053 decky 74
 
692 bondari 75
            allocated = 0;
745 jermar 76
            for (i = 0; i < (MAX_FRAMES >> order); i++) {
3104 svoboda 77
                frames[allocated] = frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
1767 palkovsky 78
                if (frames[allocated]) {
745 jermar 79
                    memsetb(frames[allocated], FRAME_SIZE << order, val);
692 bondari 80
                    allocated++;
2028 decky 81
                } else
692 bondari 82
                    break;
83
            }
2053 decky 84
 
85
            if (!sh_quiet)
3069 decky 86
                printf("Thread #%" PRIu64 " (cpu%u): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated);
2053 decky 87
 
88
            if (!sh_quiet)
3069 decky 89
                printf("Thread #%" PRIu64 " (cpu%u): Deallocating ... \n", THREAD->tid, CPU->id);
2053 decky 90
 
745 jermar 91
            for (i = 0; i < allocated; i++) {
2745 decky 92
                for (k = 0; k <= (((index_t) FRAME_SIZE << order) - 1); k++) {
1780 jermar 93
                    if (((uint8_t *) frames[i])[k] != val) {
2053 decky 94
                        if (!sh_quiet)
3069 decky 95
                            printf("Thread #%" PRIu64 " (cpu%u): Unexpected data (%c) in block %p offset %#" PRIi "\n", THREAD->tid, CPU->id, ((char *) frames[i])[k], frames[i], k);
2028 decky 96
                        atomic_inc(&thread_fail);
97
                        goto cleanup;
733 bondari 98
                    }
99
                }
1760 palkovsky 100
                frame_free(KA2PA(frames[i]));
692 bondari 101
            }
2053 decky 102
 
103
            if (!sh_quiet)
3069 decky 104
                printf("Thread #%" PRIu64 " (cpu%u): Finished run.\n", THREAD->tid, CPU->id);
692 bondari 105
        }
106
    }
2028 decky 107
 
108
cleanup:   
745 jermar 109
    free(frames);
2053 decky 110
 
111
    if (!sh_quiet)
3069 decky 112
        printf("Thread #%" PRIu64 " (cpu%u): Exiting\n", THREAD->tid, CPU->id);
692 bondari 113
    atomic_dec(&thread_count);
114
}
115
 
2050 decky 116
char * test_falloc2(bool quiet)
745 jermar 117
{
2028 decky 118
    unsigned int i;
2053 decky 119
    sh_quiet = quiet;
692 bondari 120
 
121
    atomic_set(&thread_count, THREADS);
2028 decky 122
    atomic_set(&thread_fail, 0);
692 bondari 123
 
745 jermar 124
    for (i = 0; i < THREADS; i++) {
2042 decky 125
        thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc", false);
2028 decky 126
        if (!thrd) {
2053 decky 127
            if (!quiet)
3069 decky 128
                printf("Could not create thread %u\n", i);
2028 decky 129
            break;
130
        }
131
        thread_ready(thrd);
692 bondari 132
    }
133
 
2028 decky 134
    while (atomic_get(&thread_count) > 0) {
2053 decky 135
        if (!quiet)
3069 decky 136
            printf("Threads left: %ld\n", atomic_get(&thread_count));
2028 decky 137
        thread_sleep(1);
138
    }
139
 
140
    if (atomic_get(&thread_fail) == 0)
141
        return NULL;
142
 
143
    return "Test failed";
692 bondari 144
}