Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcozecchini 0:9fca2b23d0ba 1 /*
marcozecchini 0:9fca2b23d0ba 2 * Profiling framework for the events library
marcozecchini 0:9fca2b23d0ba 3 *
marcozecchini 0:9fca2b23d0ba 4 * Copyright (c) 2016 Christopher Haster
marcozecchini 0:9fca2b23d0ba 5 *
marcozecchini 0:9fca2b23d0ba 6 * Licensed under the Apache License, Version 2.0 (the "License");
marcozecchini 0:9fca2b23d0ba 7 * you may not use this file except in compliance with the License.
marcozecchini 0:9fca2b23d0ba 8 * You may obtain a copy of the License at
marcozecchini 0:9fca2b23d0ba 9 *
marcozecchini 0:9fca2b23d0ba 10 * http://www.apache.org/licenses/LICENSE-2.0
marcozecchini 0:9fca2b23d0ba 11 *
marcozecchini 0:9fca2b23d0ba 12 * Unless required by applicable law or agreed to in writing, software
marcozecchini 0:9fca2b23d0ba 13 * distributed under the License is distributed on an "AS IS" BASIS,
marcozecchini 0:9fca2b23d0ba 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
marcozecchini 0:9fca2b23d0ba 15 * See the License for the specific language governing permissions and
marcozecchini 0:9fca2b23d0ba 16 * limitations under the License.
marcozecchini 0:9fca2b23d0ba 17 */
marcozecchini 0:9fca2b23d0ba 18 #include "equeue.h"
marcozecchini 0:9fca2b23d0ba 19 #include <unistd.h>
marcozecchini 0:9fca2b23d0ba 20 #include <stdio.h>
marcozecchini 0:9fca2b23d0ba 21 #include <setjmp.h>
marcozecchini 0:9fca2b23d0ba 22 #include <stdint.h>
marcozecchini 0:9fca2b23d0ba 23 #include <stdlib.h>
marcozecchini 0:9fca2b23d0ba 24 #include <inttypes.h>
marcozecchini 0:9fca2b23d0ba 25 #include <sys/time.h>
marcozecchini 0:9fca2b23d0ba 26
marcozecchini 0:9fca2b23d0ba 27
marcozecchini 0:9fca2b23d0ba 28 // Performance measurement utils
marcozecchini 0:9fca2b23d0ba 29 #define PROF_RUNS 5
marcozecchini 0:9fca2b23d0ba 30 #define PROF_INTERVAL 100000000
marcozecchini 0:9fca2b23d0ba 31
marcozecchini 0:9fca2b23d0ba 32 #define prof_volatile(t) __attribute__((unused)) volatile t
marcozecchini 0:9fca2b23d0ba 33
marcozecchini 0:9fca2b23d0ba 34 typedef uint64_t prof_cycle_t;
marcozecchini 0:9fca2b23d0ba 35
marcozecchini 0:9fca2b23d0ba 36 static volatile prof_cycle_t prof_start_cycle;
marcozecchini 0:9fca2b23d0ba 37 static volatile prof_cycle_t prof_stop_cycle;
marcozecchini 0:9fca2b23d0ba 38 static prof_cycle_t prof_accum_cycle;
marcozecchini 0:9fca2b23d0ba 39 static prof_cycle_t prof_baseline_cycle;
marcozecchini 0:9fca2b23d0ba 40 static prof_cycle_t prof_iterations;
marcozecchini 0:9fca2b23d0ba 41 static const char *prof_units;
marcozecchini 0:9fca2b23d0ba 42
marcozecchini 0:9fca2b23d0ba 43 #define prof_cycle() ({ \
marcozecchini 0:9fca2b23d0ba 44 uint32_t a, b; \
marcozecchini 0:9fca2b23d0ba 45 __asm__ volatile ("rdtsc" : "=a" (a), "=d" (b)); \
marcozecchini 0:9fca2b23d0ba 46 ((uint64_t)b << 32) | (uint64_t)a; \
marcozecchini 0:9fca2b23d0ba 47 })
marcozecchini 0:9fca2b23d0ba 48
marcozecchini 0:9fca2b23d0ba 49 #define prof_loop() \
marcozecchini 0:9fca2b23d0ba 50 for (prof_iterations = 0; \
marcozecchini 0:9fca2b23d0ba 51 prof_accum_cycle < PROF_INTERVAL; \
marcozecchini 0:9fca2b23d0ba 52 prof_iterations++)
marcozecchini 0:9fca2b23d0ba 53
marcozecchini 0:9fca2b23d0ba 54 #define prof_start() ({ \
marcozecchini 0:9fca2b23d0ba 55 prof_start_cycle = prof_cycle(); \
marcozecchini 0:9fca2b23d0ba 56 })
marcozecchini 0:9fca2b23d0ba 57
marcozecchini 0:9fca2b23d0ba 58 #define prof_stop() ({ \
marcozecchini 0:9fca2b23d0ba 59 prof_stop_cycle = prof_cycle(); \
marcozecchini 0:9fca2b23d0ba 60 prof_accum_cycle += prof_stop_cycle - prof_start_cycle; \
marcozecchini 0:9fca2b23d0ba 61 })
marcozecchini 0:9fca2b23d0ba 62
marcozecchini 0:9fca2b23d0ba 63 #define prof_result(value, units) ({ \
marcozecchini 0:9fca2b23d0ba 64 prof_accum_cycle = value+prof_baseline_cycle; \
marcozecchini 0:9fca2b23d0ba 65 prof_iterations = 1; \
marcozecchini 0:9fca2b23d0ba 66 prof_units = units; \
marcozecchini 0:9fca2b23d0ba 67 })
marcozecchini 0:9fca2b23d0ba 68
marcozecchini 0:9fca2b23d0ba 69 #define prof_measure(func, ...) ({ \
marcozecchini 0:9fca2b23d0ba 70 printf("%s: ...", #func); \
marcozecchini 0:9fca2b23d0ba 71 fflush(stdout); \
marcozecchini 0:9fca2b23d0ba 72 \
marcozecchini 0:9fca2b23d0ba 73 prof_units = "cycles"; \
marcozecchini 0:9fca2b23d0ba 74 prof_cycle_t runs[PROF_RUNS]; \
marcozecchini 0:9fca2b23d0ba 75 for (int i = 0; i < PROF_RUNS; i++) { \
marcozecchini 0:9fca2b23d0ba 76 prof_accum_cycle = 0; \
marcozecchini 0:9fca2b23d0ba 77 prof_iterations = 0; \
marcozecchini 0:9fca2b23d0ba 78 func(__VA_ARGS__); \
marcozecchini 0:9fca2b23d0ba 79 runs[i] = prof_accum_cycle / prof_iterations; \
marcozecchini 0:9fca2b23d0ba 80 } \
marcozecchini 0:9fca2b23d0ba 81 \
marcozecchini 0:9fca2b23d0ba 82 prof_cycle_t res = runs[0]; \
marcozecchini 0:9fca2b23d0ba 83 for (int i = 0; i < PROF_RUNS; i++) { \
marcozecchini 0:9fca2b23d0ba 84 if (runs[i] < res) { \
marcozecchini 0:9fca2b23d0ba 85 res = runs[i]; \
marcozecchini 0:9fca2b23d0ba 86 } \
marcozecchini 0:9fca2b23d0ba 87 } \
marcozecchini 0:9fca2b23d0ba 88 res -= prof_baseline_cycle; \
marcozecchini 0:9fca2b23d0ba 89 printf("\r%s: %"PRIu64" %s", #func, res, prof_units); \
marcozecchini 0:9fca2b23d0ba 90 \
marcozecchini 0:9fca2b23d0ba 91 if (!isatty(0)) { \
marcozecchini 0:9fca2b23d0ba 92 prof_cycle_t prev; \
marcozecchini 0:9fca2b23d0ba 93 while (scanf("%*[^0-9]%"PRIu64, &prev) == 0); \
marcozecchini 0:9fca2b23d0ba 94 int64_t perc = 100*((int64_t)prev - (int64_t)res) / (int64_t)prev; \
marcozecchini 0:9fca2b23d0ba 95 \
marcozecchini 0:9fca2b23d0ba 96 if (perc > 10) { \
marcozecchini 0:9fca2b23d0ba 97 printf(" (\e[32m%+"PRId64"%%\e[0m)", perc); \
marcozecchini 0:9fca2b23d0ba 98 } else if (perc < -10) { \
marcozecchini 0:9fca2b23d0ba 99 printf(" (\e[31m%+"PRId64"%%\e[0m)", perc); \
marcozecchini 0:9fca2b23d0ba 100 } else { \
marcozecchini 0:9fca2b23d0ba 101 printf(" (%+"PRId64"%%)", perc); \
marcozecchini 0:9fca2b23d0ba 102 } \
marcozecchini 0:9fca2b23d0ba 103 } \
marcozecchini 0:9fca2b23d0ba 104 \
marcozecchini 0:9fca2b23d0ba 105 printf("\n"); \
marcozecchini 0:9fca2b23d0ba 106 res; \
marcozecchini 0:9fca2b23d0ba 107 })
marcozecchini 0:9fca2b23d0ba 108
marcozecchini 0:9fca2b23d0ba 109 #define prof_baseline(func, ...) ({ \
marcozecchini 0:9fca2b23d0ba 110 prof_baseline_cycle = 0; \
marcozecchini 0:9fca2b23d0ba 111 prof_baseline_cycle = prof_measure(func, __VA_ARGS__); \
marcozecchini 0:9fca2b23d0ba 112 })
marcozecchini 0:9fca2b23d0ba 113
marcozecchini 0:9fca2b23d0ba 114
marcozecchini 0:9fca2b23d0ba 115 // Various test functions
marcozecchini 0:9fca2b23d0ba 116 void no_func(void *eh) {
marcozecchini 0:9fca2b23d0ba 117 }
marcozecchini 0:9fca2b23d0ba 118
marcozecchini 0:9fca2b23d0ba 119
marcozecchini 0:9fca2b23d0ba 120 // Actual performance tests
marcozecchini 0:9fca2b23d0ba 121 void baseline_prof(void) {
marcozecchini 0:9fca2b23d0ba 122 prof_loop() {
marcozecchini 0:9fca2b23d0ba 123 prof_start();
marcozecchini 0:9fca2b23d0ba 124 __asm__ volatile ("");
marcozecchini 0:9fca2b23d0ba 125 prof_stop();
marcozecchini 0:9fca2b23d0ba 126 }
marcozecchini 0:9fca2b23d0ba 127 }
marcozecchini 0:9fca2b23d0ba 128
marcozecchini 0:9fca2b23d0ba 129 void equeue_tick_prof(void) {
marcozecchini 0:9fca2b23d0ba 130 prof_volatile(unsigned) res;
marcozecchini 0:9fca2b23d0ba 131 prof_loop() {
marcozecchini 0:9fca2b23d0ba 132 prof_start();
marcozecchini 0:9fca2b23d0ba 133 res = equeue_tick();
marcozecchini 0:9fca2b23d0ba 134 prof_stop();
marcozecchini 0:9fca2b23d0ba 135 }
marcozecchini 0:9fca2b23d0ba 136 }
marcozecchini 0:9fca2b23d0ba 137
marcozecchini 0:9fca2b23d0ba 138 void equeue_alloc_prof(void) {
marcozecchini 0:9fca2b23d0ba 139 struct equeue q;
marcozecchini 0:9fca2b23d0ba 140 equeue_create(&q, 32*EQUEUE_EVENT_SIZE);
marcozecchini 0:9fca2b23d0ba 141
marcozecchini 0:9fca2b23d0ba 142 prof_loop() {
marcozecchini 0:9fca2b23d0ba 143 prof_start();
marcozecchini 0:9fca2b23d0ba 144 void *e = equeue_alloc(&q, 8 * sizeof(int));
marcozecchini 0:9fca2b23d0ba 145 prof_stop();
marcozecchini 0:9fca2b23d0ba 146
marcozecchini 0:9fca2b23d0ba 147 equeue_dealloc(&q, e);
marcozecchini 0:9fca2b23d0ba 148 }
marcozecchini 0:9fca2b23d0ba 149
marcozecchini 0:9fca2b23d0ba 150 equeue_destroy(&q);
marcozecchini 0:9fca2b23d0ba 151 }
marcozecchini 0:9fca2b23d0ba 152
marcozecchini 0:9fca2b23d0ba 153 void equeue_alloc_many_prof(int count) {
marcozecchini 0:9fca2b23d0ba 154 struct equeue q;
marcozecchini 0:9fca2b23d0ba 155 equeue_create(&q, count*EQUEUE_EVENT_SIZE);
marcozecchini 0:9fca2b23d0ba 156
marcozecchini 0:9fca2b23d0ba 157 void *es[count];
marcozecchini 0:9fca2b23d0ba 158
marcozecchini 0:9fca2b23d0ba 159 for (int i = 0; i < count; i++) {
marcozecchini 0:9fca2b23d0ba 160 es[i] = equeue_alloc(&q, (i % 4) * sizeof(int));
marcozecchini 0:9fca2b23d0ba 161 }
marcozecchini 0:9fca2b23d0ba 162
marcozecchini 0:9fca2b23d0ba 163 for (int i = 0; i < count; i++) {
marcozecchini 0:9fca2b23d0ba 164 equeue_dealloc(&q, es[i]);
marcozecchini 0:9fca2b23d0ba 165 }
marcozecchini 0:9fca2b23d0ba 166
marcozecchini 0:9fca2b23d0ba 167 prof_loop() {
marcozecchini 0:9fca2b23d0ba 168 prof_start();
marcozecchini 0:9fca2b23d0ba 169 void *e = equeue_alloc(&q, 8 * sizeof(int));
marcozecchini 0:9fca2b23d0ba 170 prof_stop();
marcozecchini 0:9fca2b23d0ba 171
marcozecchini 0:9fca2b23d0ba 172 equeue_dealloc(&q, e);
marcozecchini 0:9fca2b23d0ba 173 }
marcozecchini 0:9fca2b23d0ba 174
marcozecchini 0:9fca2b23d0ba 175 equeue_destroy(&q);
marcozecchini 0:9fca2b23d0ba 176 }
marcozecchini 0:9fca2b23d0ba 177
marcozecchini 0:9fca2b23d0ba 178 void equeue_post_prof(void) {
marcozecchini 0:9fca2b23d0ba 179 struct equeue q;
marcozecchini 0:9fca2b23d0ba 180 equeue_create(&q, EQUEUE_EVENT_SIZE);
marcozecchini 0:9fca2b23d0ba 181
marcozecchini 0:9fca2b23d0ba 182 prof_loop() {
marcozecchini 0:9fca2b23d0ba 183 void *e = equeue_alloc(&q, 0);
marcozecchini 0:9fca2b23d0ba 184
marcozecchini 0:9fca2b23d0ba 185 prof_start();
marcozecchini 0:9fca2b23d0ba 186 int id = equeue_post(&q, no_func, e);
marcozecchini 0:9fca2b23d0ba 187 prof_stop();
marcozecchini 0:9fca2b23d0ba 188
marcozecchini 0:9fca2b23d0ba 189 equeue_cancel(&q, id);
marcozecchini 0:9fca2b23d0ba 190 }
marcozecchini 0:9fca2b23d0ba 191
marcozecchini 0:9fca2b23d0ba 192 equeue_destroy(&q);
marcozecchini 0:9fca2b23d0ba 193 }
marcozecchini 0:9fca2b23d0ba 194
marcozecchini 0:9fca2b23d0ba 195 void equeue_post_many_prof(int count) {
marcozecchini 0:9fca2b23d0ba 196 struct equeue q;
marcozecchini 0:9fca2b23d0ba 197 equeue_create(&q, count*EQUEUE_EVENT_SIZE);
marcozecchini 0:9fca2b23d0ba 198
marcozecchini 0:9fca2b23d0ba 199 for (int i = 0; i < count-1; i++) {
marcozecchini 0:9fca2b23d0ba 200 equeue_call(&q, no_func, 0);
marcozecchini 0:9fca2b23d0ba 201 }
marcozecchini 0:9fca2b23d0ba 202
marcozecchini 0:9fca2b23d0ba 203 prof_loop() {
marcozecchini 0:9fca2b23d0ba 204 void *e = equeue_alloc(&q, 0);
marcozecchini 0:9fca2b23d0ba 205
marcozecchini 0:9fca2b23d0ba 206 prof_start();
marcozecchini 0:9fca2b23d0ba 207 int id = equeue_post(&q, no_func, e);
marcozecchini 0:9fca2b23d0ba 208 prof_stop();
marcozecchini 0:9fca2b23d0ba 209
marcozecchini 0:9fca2b23d0ba 210 equeue_cancel(&q, id);
marcozecchini 0:9fca2b23d0ba 211 }
marcozecchini 0:9fca2b23d0ba 212
marcozecchini 0:9fca2b23d0ba 213 equeue_destroy(&q);
marcozecchini 0:9fca2b23d0ba 214 }
marcozecchini 0:9fca2b23d0ba 215
marcozecchini 0:9fca2b23d0ba 216 void equeue_post_future_prof(void) {
marcozecchini 0:9fca2b23d0ba 217 struct equeue q;
marcozecchini 0:9fca2b23d0ba 218 equeue_create(&q, EQUEUE_EVENT_SIZE);
marcozecchini 0:9fca2b23d0ba 219
marcozecchini 0:9fca2b23d0ba 220 prof_loop() {
marcozecchini 0:9fca2b23d0ba 221 void *e = equeue_alloc(&q, 0);
marcozecchini 0:9fca2b23d0ba 222 equeue_event_delay(e, 1000);
marcozecchini 0:9fca2b23d0ba 223
marcozecchini 0:9fca2b23d0ba 224 prof_start();
marcozecchini 0:9fca2b23d0ba 225 int id = equeue_post(&q, no_func, e);
marcozecchini 0:9fca2b23d0ba 226 prof_stop();
marcozecchini 0:9fca2b23d0ba 227
marcozecchini 0:9fca2b23d0ba 228 equeue_cancel(&q, id);
marcozecchini 0:9fca2b23d0ba 229 }
marcozecchini 0:9fca2b23d0ba 230
marcozecchini 0:9fca2b23d0ba 231 equeue_destroy(&q);
marcozecchini 0:9fca2b23d0ba 232 }
marcozecchini 0:9fca2b23d0ba 233
marcozecchini 0:9fca2b23d0ba 234 void equeue_post_future_many_prof(int count) {
marcozecchini 0:9fca2b23d0ba 235 struct equeue q;
marcozecchini 0:9fca2b23d0ba 236 equeue_create(&q, count*EQUEUE_EVENT_SIZE);
marcozecchini 0:9fca2b23d0ba 237
marcozecchini 0:9fca2b23d0ba 238 for (int i = 0; i < count-1; i++) {
marcozecchini 0:9fca2b23d0ba 239 equeue_call(&q, no_func, 0);
marcozecchini 0:9fca2b23d0ba 240 }
marcozecchini 0:9fca2b23d0ba 241
marcozecchini 0:9fca2b23d0ba 242 prof_loop() {
marcozecchini 0:9fca2b23d0ba 243 void *e = equeue_alloc(&q, 0);
marcozecchini 0:9fca2b23d0ba 244 equeue_event_delay(e, 1000);
marcozecchini 0:9fca2b23d0ba 245
marcozecchini 0:9fca2b23d0ba 246 prof_start();
marcozecchini 0:9fca2b23d0ba 247 int id = equeue_post(&q, no_func, e);
marcozecchini 0:9fca2b23d0ba 248 prof_stop();
marcozecchini 0:9fca2b23d0ba 249
marcozecchini 0:9fca2b23d0ba 250 equeue_cancel(&q, id);
marcozecchini 0:9fca2b23d0ba 251 }
marcozecchini 0:9fca2b23d0ba 252
marcozecchini 0:9fca2b23d0ba 253 equeue_destroy(&q);
marcozecchini 0:9fca2b23d0ba 254 }
marcozecchini 0:9fca2b23d0ba 255
marcozecchini 0:9fca2b23d0ba 256 void equeue_dispatch_prof(void) {
marcozecchini 0:9fca2b23d0ba 257 struct equeue q;
marcozecchini 0:9fca2b23d0ba 258 equeue_create(&q, EQUEUE_EVENT_SIZE);
marcozecchini 0:9fca2b23d0ba 259
marcozecchini 0:9fca2b23d0ba 260 prof_loop() {
marcozecchini 0:9fca2b23d0ba 261 equeue_call(&q, no_func, 0);
marcozecchini 0:9fca2b23d0ba 262
marcozecchini 0:9fca2b23d0ba 263 prof_start();
marcozecchini 0:9fca2b23d0ba 264 equeue_dispatch(&q, 0);
marcozecchini 0:9fca2b23d0ba 265 prof_stop();
marcozecchini 0:9fca2b23d0ba 266 }
marcozecchini 0:9fca2b23d0ba 267
marcozecchini 0:9fca2b23d0ba 268 equeue_destroy(&q);
marcozecchini 0:9fca2b23d0ba 269 }
marcozecchini 0:9fca2b23d0ba 270
marcozecchini 0:9fca2b23d0ba 271 void equeue_dispatch_many_prof(int count) {
marcozecchini 0:9fca2b23d0ba 272 struct equeue q;
marcozecchini 0:9fca2b23d0ba 273 equeue_create(&q, count*EQUEUE_EVENT_SIZE);
marcozecchini 0:9fca2b23d0ba 274
marcozecchini 0:9fca2b23d0ba 275 prof_loop() {
marcozecchini 0:9fca2b23d0ba 276 for (int i = 0; i < count; i++) {
marcozecchini 0:9fca2b23d0ba 277 equeue_call(&q, no_func, 0);
marcozecchini 0:9fca2b23d0ba 278 }
marcozecchini 0:9fca2b23d0ba 279
marcozecchini 0:9fca2b23d0ba 280 prof_start();
marcozecchini 0:9fca2b23d0ba 281 equeue_dispatch(&q, 0);
marcozecchini 0:9fca2b23d0ba 282 prof_stop();
marcozecchini 0:9fca2b23d0ba 283 }
marcozecchini 0:9fca2b23d0ba 284
marcozecchini 0:9fca2b23d0ba 285 equeue_destroy(&q);
marcozecchini 0:9fca2b23d0ba 286 }
marcozecchini 0:9fca2b23d0ba 287
marcozecchini 0:9fca2b23d0ba 288 void equeue_cancel_prof(void) {
marcozecchini 0:9fca2b23d0ba 289 struct equeue q;
marcozecchini 0:9fca2b23d0ba 290 equeue_create(&q, EQUEUE_EVENT_SIZE);
marcozecchini 0:9fca2b23d0ba 291
marcozecchini 0:9fca2b23d0ba 292 prof_loop() {
marcozecchini 0:9fca2b23d0ba 293 int id = equeue_call(&q, no_func, 0);
marcozecchini 0:9fca2b23d0ba 294
marcozecchini 0:9fca2b23d0ba 295 prof_start();
marcozecchini 0:9fca2b23d0ba 296 equeue_cancel(&q, id);
marcozecchini 0:9fca2b23d0ba 297 prof_stop();
marcozecchini 0:9fca2b23d0ba 298 }
marcozecchini 0:9fca2b23d0ba 299
marcozecchini 0:9fca2b23d0ba 300 equeue_destroy(&q);
marcozecchini 0:9fca2b23d0ba 301 }
marcozecchini 0:9fca2b23d0ba 302
marcozecchini 0:9fca2b23d0ba 303 void equeue_cancel_many_prof(int count) {
marcozecchini 0:9fca2b23d0ba 304 struct equeue q;
marcozecchini 0:9fca2b23d0ba 305 equeue_create(&q, count*EQUEUE_EVENT_SIZE);
marcozecchini 0:9fca2b23d0ba 306
marcozecchini 0:9fca2b23d0ba 307 for (int i = 0; i < count-1; i++) {
marcozecchini 0:9fca2b23d0ba 308 equeue_call(&q, no_func, 0);
marcozecchini 0:9fca2b23d0ba 309 }
marcozecchini 0:9fca2b23d0ba 310
marcozecchini 0:9fca2b23d0ba 311 prof_loop() {
marcozecchini 0:9fca2b23d0ba 312 int id = equeue_call(&q, no_func, 0);
marcozecchini 0:9fca2b23d0ba 313
marcozecchini 0:9fca2b23d0ba 314 prof_start();
marcozecchini 0:9fca2b23d0ba 315 equeue_cancel(&q, id);
marcozecchini 0:9fca2b23d0ba 316 prof_stop();
marcozecchini 0:9fca2b23d0ba 317 }
marcozecchini 0:9fca2b23d0ba 318
marcozecchini 0:9fca2b23d0ba 319 equeue_destroy(&q);
marcozecchini 0:9fca2b23d0ba 320 }
marcozecchini 0:9fca2b23d0ba 321
marcozecchini 0:9fca2b23d0ba 322 void equeue_alloc_size_prof(void) {
marcozecchini 0:9fca2b23d0ba 323 size_t size = 32*EQUEUE_EVENT_SIZE;
marcozecchini 0:9fca2b23d0ba 324
marcozecchini 0:9fca2b23d0ba 325 struct equeue q;
marcozecchini 0:9fca2b23d0ba 326 equeue_create(&q, size);
marcozecchini 0:9fca2b23d0ba 327 equeue_alloc(&q, 0);
marcozecchini 0:9fca2b23d0ba 328
marcozecchini 0:9fca2b23d0ba 329 prof_result(size - q.slab.size, "bytes");
marcozecchini 0:9fca2b23d0ba 330
marcozecchini 0:9fca2b23d0ba 331 equeue_destroy(&q);
marcozecchini 0:9fca2b23d0ba 332 }
marcozecchini 0:9fca2b23d0ba 333
marcozecchini 0:9fca2b23d0ba 334 void equeue_alloc_many_size_prof(int count) {
marcozecchini 0:9fca2b23d0ba 335 size_t size = count*EQUEUE_EVENT_SIZE;
marcozecchini 0:9fca2b23d0ba 336
marcozecchini 0:9fca2b23d0ba 337 struct equeue q;
marcozecchini 0:9fca2b23d0ba 338 equeue_create(&q, size);
marcozecchini 0:9fca2b23d0ba 339
marcozecchini 0:9fca2b23d0ba 340 for (int i = 0; i < count; i++) {
marcozecchini 0:9fca2b23d0ba 341 equeue_alloc(&q, (i % 4) * sizeof(int));
marcozecchini 0:9fca2b23d0ba 342 }
marcozecchini 0:9fca2b23d0ba 343
marcozecchini 0:9fca2b23d0ba 344 prof_result(size - q.slab.size, "bytes");
marcozecchini 0:9fca2b23d0ba 345
marcozecchini 0:9fca2b23d0ba 346 equeue_destroy(&q);
marcozecchini 0:9fca2b23d0ba 347 }
marcozecchini 0:9fca2b23d0ba 348
marcozecchini 0:9fca2b23d0ba 349 void equeue_alloc_fragmented_size_prof(int count) {
marcozecchini 0:9fca2b23d0ba 350 size_t size = count*EQUEUE_EVENT_SIZE;
marcozecchini 0:9fca2b23d0ba 351
marcozecchini 0:9fca2b23d0ba 352 struct equeue q;
marcozecchini 0:9fca2b23d0ba 353 equeue_create(&q, size);
marcozecchini 0:9fca2b23d0ba 354
marcozecchini 0:9fca2b23d0ba 355 void *es[count];
marcozecchini 0:9fca2b23d0ba 356
marcozecchini 0:9fca2b23d0ba 357 for (int i = 0; i < count; i++) {
marcozecchini 0:9fca2b23d0ba 358 es[i] = equeue_alloc(&q, (i % 4) * sizeof(int));
marcozecchini 0:9fca2b23d0ba 359 }
marcozecchini 0:9fca2b23d0ba 360
marcozecchini 0:9fca2b23d0ba 361 for (int i = 0; i < count; i++) {
marcozecchini 0:9fca2b23d0ba 362 equeue_dealloc(&q, es[i]);
marcozecchini 0:9fca2b23d0ba 363 }
marcozecchini 0:9fca2b23d0ba 364
marcozecchini 0:9fca2b23d0ba 365 for (int i = count-1; i >= 0; i--) {
marcozecchini 0:9fca2b23d0ba 366 es[i] = equeue_alloc(&q, (i % 4) * sizeof(int));
marcozecchini 0:9fca2b23d0ba 367 }
marcozecchini 0:9fca2b23d0ba 368
marcozecchini 0:9fca2b23d0ba 369 for (int i = count-1; i >= 0; i--) {
marcozecchini 0:9fca2b23d0ba 370 equeue_dealloc(&q, es[i]);
marcozecchini 0:9fca2b23d0ba 371 }
marcozecchini 0:9fca2b23d0ba 372
marcozecchini 0:9fca2b23d0ba 373 for (int i = 0; i < count; i++) {
marcozecchini 0:9fca2b23d0ba 374 equeue_alloc(&q, (i % 4) * sizeof(int));
marcozecchini 0:9fca2b23d0ba 375 }
marcozecchini 0:9fca2b23d0ba 376
marcozecchini 0:9fca2b23d0ba 377 prof_result(size - q.slab.size, "bytes");
marcozecchini 0:9fca2b23d0ba 378
marcozecchini 0:9fca2b23d0ba 379 equeue_destroy(&q);
marcozecchini 0:9fca2b23d0ba 380 }
marcozecchini 0:9fca2b23d0ba 381
marcozecchini 0:9fca2b23d0ba 382
marcozecchini 0:9fca2b23d0ba 383 // Entry point
marcozecchini 0:9fca2b23d0ba 384 int main() {
marcozecchini 0:9fca2b23d0ba 385 printf("beginning profiling...\n");
marcozecchini 0:9fca2b23d0ba 386
marcozecchini 0:9fca2b23d0ba 387 prof_baseline(baseline_prof);
marcozecchini 0:9fca2b23d0ba 388
marcozecchini 0:9fca2b23d0ba 389 prof_measure(equeue_tick_prof);
marcozecchini 0:9fca2b23d0ba 390 prof_measure(equeue_alloc_prof);
marcozecchini 0:9fca2b23d0ba 391 prof_measure(equeue_post_prof);
marcozecchini 0:9fca2b23d0ba 392 prof_measure(equeue_post_future_prof);
marcozecchini 0:9fca2b23d0ba 393 prof_measure(equeue_dispatch_prof);
marcozecchini 0:9fca2b23d0ba 394 prof_measure(equeue_cancel_prof);
marcozecchini 0:9fca2b23d0ba 395
marcozecchini 0:9fca2b23d0ba 396 prof_measure(equeue_alloc_many_prof, 1000);
marcozecchini 0:9fca2b23d0ba 397 prof_measure(equeue_post_many_prof, 1000);
marcozecchini 0:9fca2b23d0ba 398 prof_measure(equeue_post_future_many_prof, 1000);
marcozecchini 0:9fca2b23d0ba 399 prof_measure(equeue_dispatch_many_prof, 100);
marcozecchini 0:9fca2b23d0ba 400 prof_measure(equeue_cancel_many_prof, 100);
marcozecchini 0:9fca2b23d0ba 401
marcozecchini 0:9fca2b23d0ba 402 prof_measure(equeue_alloc_size_prof);
marcozecchini 0:9fca2b23d0ba 403 prof_measure(equeue_alloc_many_size_prof, 1000);
marcozecchini 0:9fca2b23d0ba 404 prof_measure(equeue_alloc_fragmented_size_prof, 1000);
marcozecchini 0:9fca2b23d0ba 405
marcozecchini 0:9fca2b23d0ba 406 printf("done!\n");
marcozecchini 0:9fca2b23d0ba 407 }