source: mainline/kernel/test/mm/slab1.c@ a35b458

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a35b458 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 4.4 KB
RevLine 
[4e147a6]1/*
[df4ed85]2 * Copyright (c) 2006 Ondrej Palkovsky
[4e147a6]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 */
28
29#include <test.h>
30#include <mm/slab.h>
[a294ad0]31#include <print.h>
[14e5d88]32#include <proc/thread.h>
33#include <arch.h>
[44a7ee5]34#include <mem.h>
[a294ad0]35
[cb01e1e]36#define VAL_COUNT 1024
[a294ad0]37
[cb01e1e]38static void *data[VAL_COUNT];
[4e147a6]39
[cb01e1e]40static void testit(int size, int count)
[4e147a6]41{
[a294ad0]42 slab_cache_t *cache;
43 int i;
[a35b458]44
[cb01e1e]45 TPRINTF("Creating cache, object size: %d.\n", size);
[a35b458]46
[deada67]47 cache = slab_cache_create("test_cache", size, 0, NULL, NULL,
[cb01e1e]48 SLAB_CACHE_NOMAGAZINE);
[a35b458]49
[cb01e1e]50 TPRINTF("Allocating %d items...", count);
[a35b458]51
[96348adc]52 for (i = 0; i < count; i++) {
[a294ad0]53 data[i] = slab_alloc(cache, 0);
[e32e092]54 memsetb(data[i], size, 0);
[a294ad0]55 }
[a35b458]56
[cb01e1e]57 TPRINTF("done.\n");
[a35b458]58
[cb01e1e]59 TPRINTF("Freeing %d items...", count);
[a35b458]60
[deada67]61 for (i = 0; i < count; i++)
[a294ad0]62 slab_free(cache, data[i]);
[a35b458]63
[cb01e1e]64 TPRINTF("done.\n");
[a35b458]65
[cb01e1e]66 TPRINTF("Allocating %d items...", count);
[a35b458]67
[96348adc]68 for (i = 0; i < count; i++) {
[bc504ef2]69 data[i] = slab_alloc(cache, 0);
[e32e092]70 memsetb(data[i], size, 0);
[bc504ef2]71 }
[a35b458]72
[cb01e1e]73 TPRINTF("done.\n");
[a35b458]74
[cb01e1e]75 TPRINTF("Freeing %d items...", count / 2);
[a35b458]76
[deada67]77 for (i = count - 1; i >= count / 2; i--)
[bc504ef2]78 slab_free(cache, data[i]);
[a35b458]79
[cb01e1e]80 TPRINTF("done.\n");
[a35b458]81
[cb01e1e]82 TPRINTF("Allocating %d items...", count / 2);
[a35b458]83
[96348adc]84 for (i = count / 2; i < count; i++) {
[bc504ef2]85 data[i] = slab_alloc(cache, 0);
[e32e092]86 memsetb(data[i], size, 0);
[bc504ef2]87 }
[a35b458]88
[cb01e1e]89 TPRINTF("done.\n");
[a35b458]90
[cb01e1e]91 TPRINTF("Freeing %d items...", count);
[a35b458]92
[deada67]93 for (i = 0; i < count; i++)
94 slab_free(cache, data[i]);
[a35b458]95
[cb01e1e]96 TPRINTF("done.\n");
[a35b458]97
[bc504ef2]98 slab_cache_destroy(cache);
[a35b458]99
[cb01e1e]100 TPRINTF("Test complete.\n");
[4e147a6]101}
[14e5d88]102
[cb01e1e]103static void testsimple(void)
[14e5d88]104{
[cb01e1e]105 testit(100, VAL_COUNT);
106 testit(200, VAL_COUNT);
107 testit(1024, VAL_COUNT);
108 testit(2048, 512);
109 testit(4000, 128);
110 testit(8192, 128);
111 testit(16384, 128);
112 testit(16385, 128);
[14e5d88]113}
114
[cb01e1e]115#define THREADS 6
116#define THR_MEM_COUNT 1024
117#define THR_MEM_SIZE 128
[14e5d88]118
[cb01e1e]119static void *thr_data[THREADS][THR_MEM_COUNT];
[96348adc]120static slab_cache_t *thr_cache;
121static semaphore_t thr_sem;
[14e5d88]122
[ff14c520]123static void slabtest(void *data)
[14e5d88]124{
[96b02eb9]125 int offs = (int) (sysarg_t) data;
[96348adc]126 int i, j;
[a35b458]127
[8d6d76a]128 thread_detach(THREAD);
[a35b458]129
[cb01e1e]130 TPRINTF("Starting thread #%" PRIu64 "...\n", THREAD->tid);
[a35b458]131
[96348adc]132 for (j = 0; j < 10; j++) {
133 for (i = 0; i < THR_MEM_COUNT; i++)
[14e5d88]134 thr_data[offs][i] = slab_alloc(thr_cache,0);
[96348adc]135 for (i = 0; i < THR_MEM_COUNT / 2; i++)
[14e5d88]136 slab_free(thr_cache, thr_data[offs][i]);
[96348adc]137 for (i = 0; i < THR_MEM_COUNT / 2; i++)
[14e5d88]138 thr_data[offs][i] = slab_alloc(thr_cache, 0);
[96348adc]139 for (i = 0; i < THR_MEM_COUNT; i++)
[14e5d88]140 slab_free(thr_cache, thr_data[offs][i]);
141 }
[a35b458]142
[cb01e1e]143 TPRINTF("Thread #%" PRIu64 " finished\n", THREAD->tid);
[a35b458]144
[14e5d88]145 semaphore_up(&thr_sem);
146}
147
[cb01e1e]148static void testthreads(void)
[14e5d88]149{
150 thread_t *t;
151 int i;
[a35b458]152
[deada67]153 thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, NULL, NULL,
[cb01e1e]154 SLAB_CACHE_NOMAGAZINE);
[a35b458]155
[96348adc]156 semaphore_initialize(&thr_sem, 0);
[6eef3c4]157 for (i = 0; i < THREADS; i++) {
158 if (!(t = thread_create(slabtest, (void *) (sysarg_t) i, TASK, THREAD_FLAG_NONE, "slabtest"))) {
[cb01e1e]159 TPRINTF("Could not create thread %d\n", i);
[deada67]160 } else
[96348adc]161 thread_ready(t);
[14e5d88]162 }
163
[96348adc]164 for (i = 0; i < THREADS; i++)
[14e5d88]165 semaphore_down(&thr_sem);
[a35b458]166
[14e5d88]167 slab_cache_destroy(thr_cache);
[a35b458]168
[cb01e1e]169 TPRINTF("Test complete.\n");
[14e5d88]170}
171
[a000878c]172const char *test_slab1(void)
[14e5d88]173{
[cb01e1e]174 testsimple();
175 testthreads();
[a35b458]176
[96348adc]177 return NULL;
[14e5d88]178}
Note: See TracBrowser for help on using the repository browser.