Subversion Repositories HelenOS-historic

Rev

Rev 768 | Rev 780 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 768 Rev 773
Line 71... Line 71...
71
        *((void **)data2) = olddata2;
71
        *((void **)data2) = olddata2;
72
        olddata1 = data1;
72
        olddata1 = data1;
73
        olddata2 = data2;
73
        olddata2 = data2;
74
    }while(1);
74
    }while(1);
75
    printf("done.\n");
75
    printf("done.\n");
76
    slab_print_list();
-
 
77
    /* We do not have memory - now deallocate cache2 */
76
    /* We do not have memory - now deallocate cache2 */
78
    printf("Deallocating cache2...");
77
    printf("Deallocating cache2...");
79
    while (olddata2) {
78
    while (olddata2) {
80
        data2 = *((void **)olddata2);
79
        data2 = *((void **)olddata2);
81
        slab_free(cache2, olddata2);
80
        slab_free(cache2, olddata2);
82
        olddata2 = data2;
81
        olddata2 = data2;
83
    }
82
    }
84
    printf("done.\n");
83
    printf("done.\n");
85
 
84
 
86
    slab_print_list();
-
 
87
    printf("Allocating to cache1...\n");
85
    printf("Allocating to cache1...\n");
88
    for (i=0; i<30; i++) {
86
    for (i=0; i<30; i++) {
89
        data1 = slab_alloc(cache1, FRAME_ATOMIC);
87
        data1 = slab_alloc(cache1, FRAME_ATOMIC);
90
        if (!data1) {
88
        if (!data1) {
91
            panic("Incorrect memory size - use another test.");
89
            panic("Incorrect memory size - use another test.");
92
        }
90
        }
93
        memsetb((__address)data1, ITEM_SIZE, 0);
91
        memsetb((__address)data1, ITEM_SIZE, 0);
94
        *((void **)data1) = olddata1;
92
        *((void **)data1) = olddata1;
95
        olddata1 = data1;
93
        olddata1 = data1;
96
    }
94
    }
97
    slab_print_list();
-
 
98
    while (1) {
95
    while (1) {
99
        data1 = slab_alloc(cache1, FRAME_ATOMIC);
96
        data1 = slab_alloc(cache1, FRAME_ATOMIC);
100
        if (!data1) {
97
        if (!data1) {
101
            break;
98
            break;
102
        }
99
        }
103
        memsetb((__address)data1, ITEM_SIZE, 0);
100
        memsetb((__address)data1, ITEM_SIZE, 0);
104
        *((void **)data1) = olddata1;
101
        *((void **)data1) = olddata1;
105
        olddata1 = data1;
102
        olddata1 = data1;
106
    }
103
    }
107
    slab_print_list();
-
 
108
    printf("Deallocating cache1...");
104
    printf("Deallocating cache1...");
109
    while (olddata1) {
105
    while (olddata1) {
110
        data1 = *((void **)olddata1);
106
        data1 = *((void **)olddata1);
111
        slab_free(cache1, olddata1);
107
        slab_free(cache1, olddata1);
112
        olddata1 = data1;
108
        olddata1 = data1;
Line 115... Line 111...
115
    slab_print_list();
111
    slab_print_list();
116
    slab_cache_destroy(cache1);
112
    slab_cache_destroy(cache1);
117
    slab_cache_destroy(cache2);
113
    slab_cache_destroy(cache2);
118
}
114
}
119
 
115
 
-
 
116
slab_cache_t *thr_cache;
-
 
117
semaphore_t thr_sem;
-
 
118
 
-
 
119
#define THREADS 8
-
 
120
 
-
 
121
static void thread(void *priv)
-
 
122
{
-
 
123
    void *data=NULL, *new;
-
 
124
 
-
 
125
    printf("Starting thread #%d...\n",THREAD->tid);
-
 
126
 
-
 
127
    /* Alloc all */
-
 
128
    printf("Thread #%d allocating...\n", THREAD->tid);
-
 
129
    while (1) {
-
 
130
        /* Call with atomic to detect end of memory */
-
 
131
        new = slab_alloc(thr_cache, FRAME_ATOMIC);
-
 
132
        if (!new)
-
 
133
            break;
-
 
134
        *((void **)new) = data;
-
 
135
        data = new;
-
 
136
    }
-
 
137
    printf("Thread #%d releasing...\n", THREAD->tid);
-
 
138
    while (data) {
-
 
139
        new = *((void **)data);
-
 
140
        slab_free(thr_cache, data);
-
 
141
        data = new;
-
 
142
    }
-
 
143
    printf("Thread #%d allocating...\n", THREAD->tid);
-
 
144
    while (1) {
-
 
145
        /* Call with atomic to detect end of memory */
-
 
146
        new = slab_alloc(thr_cache, FRAME_ATOMIC);
-
 
147
        if (!new)
-
 
148
            break;
-
 
149
        *((void **)new) = data;
-
 
150
        data = new;
-
 
151
    }
-
 
152
    printf("Thread #%d releasing...\n", THREAD->tid);
-
 
153
    while (data) {
-
 
154
        new = *((void **)data);
-
 
155
        slab_free(thr_cache, data);
-
 
156
        data = new;
-
 
157
    }
-
 
158
 
-
 
159
 
-
 
160
    printf("Thread #%d finished\n", THREAD->tid);
-
 
161
    slab_print_list();
-
 
162
    semaphore_up(&thr_sem);
-
 
163
}
-
 
164
 
-
 
165
 
-
 
166
static void multitest(int size)
-
 
167
{
-
 
168
    /* Start 8 threads that just allocate as much as possible,
-
 
169
     * then release everything, then again allocate, then release
-
 
170
     */
-
 
171
    thread_t *t;
-
 
172
    int i;
-
 
173
 
-
 
174
    printf("Running stress test with size %d\n", size);
-
 
175
    thr_cache = slab_cache_create("thread_cache", size, 0,
-
 
176
                      NULL, NULL,
-
 
177
                      0);
-
 
178
    semaphore_initialize(&thr_sem,0);
-
 
179
    for (i=0; i<THREADS; i++) {  
-
 
180
        if (!(t = thread_create(thread, NULL, TASK, 0)))
-
 
181
            panic("could not create thread\n");
-
 
182
        thread_ready(t);
-
 
183
    }
-
 
184
 
-
 
185
    for (i=0; i<THREADS; i++)
-
 
186
        semaphore_down(&thr_sem);
-
 
187
   
-
 
188
    slab_cache_destroy(thr_cache);
-
 
189
    printf("Stress test complete.\n");
-
 
190
}
-
 
191
 
120
void test(void)
192
void test(void)
121
{
193
{
122
    printf("Running reclaim test .. pass1\n");
194
    printf("Running reclaim single-thread test .. pass1\n");
123
    totalmemtest();
195
    totalmemtest();
124
    printf("Running reclaim test .. pass2\n");
196
    printf("Running reclaim single-thread test .. pass2\n");
125
    totalmemtest();
197
    totalmemtest();
126
    printf("Reclaim test OK.\n");
198
    printf("Reclaim test OK.\n");
-
 
199
 
-
 
200
    multitest(128);
-
 
201
    multitest(2048);
-
 
202
    printf("All done.\n");
127
}
203
}