static bool compare_uds = false; /* unix-socket comparison? */
static bool attach_none = false; /* clear attach-flags? */
static bool is_bandwidth = false; /* is this a bandwidth test? */
+static bool measure_latency_with_fork = false; /* are we measuring latency with separate or same thread? */
static char *stress_payload;
struct stats {
struct bandwidth_worker_data {
int i;
struct kdbus_test_env *env;
+ struct kdbus_conn *conn;
};
-void *bandwidth_receiver_thread(void *conn)
+// only used in the latency test -> always just 1 sender/receiver pair
+_Atomic uint64_t start_timestamp_mt;
+_Atomic bool pending;
+
+void *bandwidth_receiver_thread(void *_data)
{
+ struct bandwidth_worker_data *data = _data;
+
+ uint64_t start = now(CLOCK_REALTIME);
while (1) {
- if (handle_echo_reply((struct kdbus_conn *) conn, 0)) {
+ while (measure_latency_with_fork && !pending);
+
+ if (handle_echo_reply(data->conn, start_timestamp_mt)) {
// no can do
}
+ if (measure_latency_with_fork) {
+ const uint64_t current = now(CLOCK_REALTIME);
+ if (current - start > 1000000000ULL) {
+ dump_stats(false);
+ reset_stats();
+ start = current;
+ }
+ pending = false;
+ }
}
return NULL;
ASSERT_ZERO(setup_simple_kdbus_msg(conn_b, conn_a->id, data->env->payload, &kdbus_msg));
ASSERT_NO_PENDING(conn_a);
+ data->conn = conn_a;
+
pthread_t p;
- pthread_create(&p, NULL, bandwidth_receiver_thread, conn_a);
+ pthread_create(&p, NULL, bandwidth_receiver_thread, data);
while (1) {
+ if (measure_latency_with_fork) {
+ while (pending);
+
+ start_timestamp_mt = now(CLOCK_REALTIME);
+ }
if (send_echo_request(conn_b, kdbus_msg, 0)) {
// no can do
}
+ if (measure_latency_with_fork)
+ pending = true;
}
return TEST_OK;
return TEST_OK;
}
+
+static wur int benchmark_latency_mt(struct kdbus_test_env *env)
+{
+ setlocale(LC_ALL, "");
+
+ stress_payload = malloc(env->payload);
+ ASSERT_NONZERO(stress_payload);
+ for (int i = 0; i < env->payload; i++)
+ stress_payload[i] = i;
+
+ bandwidth_sender_thread(&(struct bandwidth_worker_data){ .i = 0, .env = env });
+
+ return TEST_OK;
+}
+
+
wur int kdbus_test_benchmark(struct kdbus_test_env *env)
{
use_memfd = true;
return benchmark_bandwidth(env);
}
+wur int kdbus_test_benchmark_mt(struct kdbus_test_env *env)
+{
+ use_memfd = false;
+ attach_none = false;
+ compare_uds = false;
+ is_bandwidth = false;
+ measure_latency_with_fork = true;
+ return benchmark_latency_mt(env);
+}
+
wur int kdbus_test_benchmark_nomemfds(struct kdbus_test_env *env)
{
use_memfd = false;