Rev 2022 | Rev 2029 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2022 | Rev 2028 | ||
---|---|---|---|
Line 32... | Line 32... | ||
32 | #include <proc/thread.h> |
32 | #include <proc/thread.h> |
33 | #include <arch.h> |
33 | #include <arch.h> |
34 | #include <panic.h> |
34 | #include <panic.h> |
35 | #include <memstr.h> |
35 | #include <memstr.h> |
36 | 36 | ||
37 | #ifdef CONFIG_BENCH |
- | |
38 | #include <arch/cycle.h> |
- | |
39 | #endif |
- | |
40 | - | ||
41 | #define VAL_COUNT 1024 |
37 | #define VAL_COUNT 1024 |
42 | 38 | ||
43 | static void * data[VAL_COUNT]; |
39 | static void * data[VAL_COUNT]; |
44 | 40 | ||
45 | static void testit(int size, int count) |
41 | static void testit(int size, int count) |
Line 49... | Line 45... | ||
49 | 45 | ||
50 | printf("Creating cache, object size: %d.\n", size); |
46 | printf("Creating cache, object size: %d.\n", size); |
51 | cache = slab_cache_create("test_cache", size, 0, NULL, NULL, |
47 | cache = slab_cache_create("test_cache", size, 0, NULL, NULL, |
52 | SLAB_CACHE_NOMAGAZINE); |
48 | SLAB_CACHE_NOMAGAZINE); |
53 | printf("Allocating %d items...", count); |
49 | printf("Allocating %d items...", count); |
54 | for (i=0; i < count; i++) { |
50 | for (i = 0; i < count; i++) { |
55 | data[i] = slab_alloc(cache, 0); |
51 | data[i] = slab_alloc(cache, 0); |
56 | memsetb((uintptr_t)data[i], size, 0); |
52 | memsetb((uintptr_t) data[i], size, 0); |
57 | } |
53 | } |
58 | printf("done.\n"); |
54 | printf("done.\n"); |
59 | printf("Freeing %d items...", count); |
55 | printf("Freeing %d items...", count); |
60 | for (i=0; i < count; i++) { |
56 | for (i = 0; i < count; i++) { |
61 | slab_free(cache, data[i]); |
57 | slab_free(cache, data[i]); |
62 | } |
58 | } |
63 | printf("done.\n"); |
59 | printf("done.\n"); |
64 | 60 | ||
65 | printf("Allocating %d items...", count); |
61 | printf("Allocating %d items...", count); |
66 | for (i=0; i < count; i++) { |
62 | for (i = 0; i < count; i++) { |
67 | data[i] = slab_alloc(cache, 0); |
63 | data[i] = slab_alloc(cache, 0); |
68 | memsetb((uintptr_t)data[i], size, 0); |
64 | memsetb((uintptr_t) data[i], size, 0); |
69 | } |
65 | } |
70 | printf("done.\n"); |
66 | printf("done.\n"); |
71 | 67 | ||
72 | printf("Freeing %d items...", count/2); |
68 | printf("Freeing %d items...", count / 2); |
73 | for (i=count-1; i >= count/2; i--) { |
69 | for (i = count - 1; i >= count / 2; i--) { |
74 | slab_free(cache, data[i]); |
70 | slab_free(cache, data[i]); |
75 | } |
71 | } |
76 | printf("done.\n"); |
72 | printf("done.\n"); |
77 | 73 | ||
78 | printf("Allocating %d items...", count/2); |
74 | printf("Allocating %d items...", count / 2); |
79 | for (i=count/2; i < count; i++) { |
75 | for (i = count / 2; i < count; i++) { |
80 | data[i] = slab_alloc(cache, 0); |
76 | data[i] = slab_alloc(cache, 0); |
81 | memsetb((uintptr_t)data[i], size, 0); |
77 | memsetb((uintptr_t) data[i], size, 0); |
82 | } |
78 | } |
83 | printf("done.\n"); |
79 | printf("done.\n"); |
84 | printf("Freeing %d items...", count); |
80 | printf("Freeing %d items...", count); |
85 | for (i=0; i < count; i++) { |
81 | for (i = 0; i < count; i++) { |
86 | slab_free(cache, data[i]); |
82 | slab_free(cache, data[i]); |
87 | } |
83 | } |
88 | printf("done.\n"); |
84 | printf("done.\n"); |
89 | slab_cache_destroy(cache); |
85 | slab_cache_destroy(cache); |
90 | 86 | ||
Line 101... | Line 97... | ||
101 | testit(8192, 128); |
97 | testit(8192, 128); |
102 | testit(16384, 128); |
98 | testit(16384, 128); |
103 | testit(16385, 128); |
99 | testit(16385, 128); |
104 | } |
100 | } |
105 | 101 | ||
106 | - | ||
107 | #define THREADS 6 |
102 | #define THREADS 6 |
108 | #define THR_MEM_COUNT 1024 |
103 | #define THR_MEM_COUNT 1024 |
109 | #define THR_MEM_SIZE 128 |
104 | #define THR_MEM_SIZE 128 |
110 | 105 | ||
111 | void * thr_data[THREADS][THR_MEM_COUNT]; |
106 | static void * thr_data[THREADS][THR_MEM_COUNT]; |
112 | slab_cache_t *thr_cache; |
107 | static slab_cache_t *thr_cache; |
113 | semaphore_t thr_sem; |
108 | static semaphore_t thr_sem; |
114 | 109 | ||
115 | static void slabtest(void *data) |
110 | static void slabtest(void *data) |
116 | { |
111 | { |
117 | int offs = (int)(unative_t) data; |
112 | int offs = (int) (unative_t) data; |
118 | int i,j; |
113 | int i, j; |
119 | 114 | ||
120 | thread_detach(THREAD); |
115 | thread_detach(THREAD); |
121 | 116 | ||
122 | printf("Starting thread #%d...\n",THREAD->tid); |
117 | printf("Starting thread #%d...\n",THREAD->tid); |
123 | for (j=0; j<10; j++) { |
118 | for (j = 0; j < 10; j++) { |
124 | for (i=0; i<THR_MEM_COUNT; i++) |
119 | for (i = 0; i < THR_MEM_COUNT; i++) |
125 | thr_data[offs][i] = slab_alloc(thr_cache,0); |
120 | thr_data[offs][i] = slab_alloc(thr_cache,0); |
126 | for (i=0; i<THR_MEM_COUNT/2; i++) |
121 | for (i = 0; i < THR_MEM_COUNT / 2; i++) |
127 | slab_free(thr_cache, thr_data[offs][i]); |
122 | slab_free(thr_cache, thr_data[offs][i]); |
128 | for (i=0; i< THR_MEM_COUNT/2; i++) |
123 | for (i = 0; i < THR_MEM_COUNT / 2; i++) |
129 | thr_data[offs][i] = slab_alloc(thr_cache, 0); |
124 | thr_data[offs][i] = slab_alloc(thr_cache, 0); |
130 | for (i=0; i<THR_MEM_COUNT;i++) |
125 | for (i = 0; i < THR_MEM_COUNT; i++) |
131 | slab_free(thr_cache, thr_data[offs][i]); |
126 | slab_free(thr_cache, thr_data[offs][i]); |
132 | } |
127 | } |
133 | printf("Thread #%d finished\n", THREAD->tid); |
128 | printf("Thread #%d finished\n", THREAD->tid); |
134 | semaphore_up(&thr_sem); |
129 | semaphore_up(&thr_sem); |
135 | } |
130 | } |
Line 140... | Line 135... | ||
140 | int i; |
135 | int i; |
141 | 136 | ||
142 | thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, |
137 | thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, |
143 | NULL, NULL, |
138 | NULL, NULL, |
144 | SLAB_CACHE_NOMAGAZINE); |
139 | SLAB_CACHE_NOMAGAZINE); |
145 | semaphore_initialize(&thr_sem,0); |
140 | semaphore_initialize(&thr_sem, 0); |
146 | for (i=0; i<THREADS; i++) { |
141 | for (i = 0; i < THREADS; i++) { |
147 | if (!(t = thread_create(slabtest, (void *)(unative_t)i, TASK, 0, "slabtest"))) |
142 | if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest"))) |
148 | panic("could not create thread\n"); |
143 | printf("Could not create thread %d\n", i); |
- | 144 | else |
|
149 | thread_ready(t); |
145 | thread_ready(t); |
150 | } |
146 | } |
151 | 147 | ||
152 | for (i=0; i<THREADS; i++) |
148 | for (i = 0; i < THREADS; i++) |
153 | semaphore_down(&thr_sem); |
149 | semaphore_down(&thr_sem); |
154 | 150 | ||
155 | slab_cache_destroy(thr_cache); |
151 | slab_cache_destroy(thr_cache); |
156 | printf("Test complete.\n"); |
152 | printf("Test complete.\n"); |
157 | 153 | ||
158 | } |
154 | } |
159 | 155 | ||
160 | void test_slab1(void) |
156 | char * test_slab1(void) |
161 | { |
157 | { |
162 | #ifdef CONFIG_BENCH |
- | |
163 | uint64_t t0 = get_cycle(); |
- | |
164 | #endif |
- | |
165 | testsimple(); |
158 | testsimple(); |
166 | testthreads(); |
159 | testthreads(); |
167 | #ifdef CONFIG_BENCH |
160 | |
168 | uint64_t dt = get_cycle() - t0; |
- | |
169 | printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt); |
- | |
170 | #endif |
161 | return NULL; |
171 | } |
162 | } |