2 * Copyright (c) 2011 Joakim Johansson <jocke@tbricks.com>.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
21 #include "pthread_workqueue.h"
24 # include "../../src/windows/platform.h"
28 #define SECONDS_TO_RUN 10
29 #define WORKQUEUE_COUNT 3
30 #define GENERATOR_WORKQUEUE_COUNT 1
31 #define SLEEP_BEFORE_START 0
32 #define FORCE_BUSY_LOOP 0
33 #define LATENCY_RUN_GENERATOR_IN_MAIN_THREAD 0
36 #define EVENTS_GENERATED_PER_TICK 100 // simulate some small bursting
37 #define EVENT_GENERATION_FREQUENCY 100 // events/s base rate, need to use busy loop = 1 if > 100Hz due to nanosleep resolution
39 #define AGGREGATE_DATA_RATE_PER_SECOND (EVENT_GENERATION_FREQUENCY * EVENTS_GENERATED_PER_TICK)
40 #define EVENTS_TO_GENERATE (SECONDS_TO_RUN * AGGREGATE_DATA_RATE_PER_SECOND)
41 #define TOTAL_DATA_PER_SECOND (AGGREGATE_DATA_RATE_PER_SECOND*GENERATOR_WORKQUEUE_COUNT)
42 #define TOTAL_TICKS_TO_RUN (SECONDS_TO_RUN * EVENT_GENERATION_FREQUENCY)
44 #define NANOSECONDS_PER_SECOND 1000000000
45 #define DISTRIBUTION_BUCKETS 20 // 1us per bucket
46 #define EVENT_TIME_SLICE (NANOSECONDS_PER_SECOND / EVENT_GENERATION_FREQUENCY)
47 #define SYSTEM_CLOCK_RESOLUTION 100
50 typedef unsigned long long mytime_t;
52 typedef unsigned long mytime_t;
57 unsigned int queue_index;
68 unsigned int count_over_threshold;
69 unsigned int distribution[DISTRIBUTION_BUCKETS];
72 // We create our own separate workqueues for event generation
73 struct wq_event_generator
75 pthread_workqueue_t wq;
76 struct wq_event *wq_events;
81 # define atomic_inc atomic_inc_32
82 # define atomic_dec atomic_dec_32
83 # define atomic_inc_nv atomic_inc_32_nv
84 # define atomic_dec_nv atomic_dec_32_nv
86 # define atomic_inc(p) (void) InterlockedIncrement((p))
87 # define atomic_dec(p) (void) InterlockedDecrement((p))
88 # define atomic_inc_nv(p) InterlockedIncrement((p))
89 # define atomic_dec_nv(p) InterlockedDecrement((p))
91 # define atomic_inc(p) (void) __sync_add_and_fetch((p), 1)
92 # define atomic_dec(p) (void) __sync_sub_and_fetch((p), 1)
93 # define atomic_inc_nv(p) __sync_add_and_fetch((p), 1)
94 # define atomic_dec_nv(p) __sync_sub_and_fetch((p), 1)