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