Debian Codegraph @

regressions/ck_hp/benchmark/fifo_latency.c

raw
1 /*
2 * Copyright 2011-2015 Samy Al Bahra.
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 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27 #include <ck_hp.h>
28 #include <ck_hp_fifo.h>
29 #include <inttypes.h>
30 #include <stdint.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33
34 #include "../../common.h"
35
36 #ifndef ENTRIES
37 #define ENTRIES 4096
38 #endif
39
40 #ifndef STEPS
41 #define STEPS 40000
42 #endif
43
44 static ck_hp_fifo_t fifo;
45 static ck_hp_t fifo_hp;
46
47 int
48 main(void)
49 {
50 void *r;
51 uint64_t s, e, a;
52 unsigned int i;
53 unsigned int j;
54 ck_hp_fifo_entry_t hp_entry[ENTRIES];
55 ck_hp_fifo_entry_t hp_stub;
56 ck_hp_record_t record;
57
58 ck_hp_init(&fifo_hp, CK_HP_FIFO_SLOTS_COUNT, 1000000, NULL);
59
60 r = malloc(CK_HP_FIFO_SLOTS_SIZE);
61 if (r == NULL) {
62 ck_error("ERROR: Failed to allocate slots.\n");
63 }
64 ck_hp_register(&fifo_hp, &record, r);
65
66 a = 0;
67 for (i = 0; i < STEPS; i++) {
68 ck_hp_fifo_init(&fifo, &hp_stub);
69
70 s = rdtsc();
71 for (j = 0; j < ENTRIES; j++)
72 ck_hp_fifo_enqueue_mpmc(&record, &fifo, hp_entry + j, NULL);
73 e = rdtsc();
74
75 a += e - s;
76 }
77 printf("ck_hp_fifo_enqueue_mpmc: %16" PRIu64 "\n", a / STEPS / ENTRIES);
78
79 a = 0;
80 for (i = 0; i < STEPS; i++) {
81 ck_hp_fifo_init(&fifo, &hp_stub);
82 for (j = 0; j < ENTRIES; j++)
83 ck_hp_fifo_enqueue_mpmc(&record, &fifo, hp_entry + j, NULL);
84
85 s = rdtsc();
86 for (j = 0; j < ENTRIES; j++)
87 ck_hp_fifo_dequeue_mpmc(&record, &fifo, &r);
88 e = rdtsc();
89 a += e - s;
90 }
91 printf("ck_hp_fifo_dequeue_mpmc: %16" PRIu64 "\n", a / STEPS / ENTRIES);
92
93 return 0;
94 }