#include <chrono>
#include <iostream>
+#include <optional>
#include <thread>
using namespace std::chrono_literals;
* and will just take however many tries it managed to receive. */
size_t try_count = 120'000;
+ /* Pins the client to a specific CPU. If the server lives on the
+ * same CPU as the client, it will be able to process the message
+ * as soon as the client goes to sleep (trading off parallelism
+ * for better "timings" on the process scheduler). */
+ std::optional <int> cpu_pin = std::nullopt;
+
/* Matches the server's default for convenience. */
std::string sock_path = "/tmp/test";
};
run_opts ret;
int opt;
- while ((opt = getopt(argc, argv, "d:m:t:p:h")) != -1)
+ while ((opt = getopt(argc, argv, "c:d:m:t:p:h")) != -1)
switch (opt) {
+ case 'c':
+ ret.cpu_pin = std::stoi(optarg);
+ break;
case 'm':
ret.payload = std::stoi(optarg);
break;
<< " [-t try_count] "
<< " [-d delay_usec] "
<< " [-p sock_path] "
+ << " [-c cpu_pin] "
<< std::endl
;
}
return EXIT_FAILURE;
}
+ if (opt.cpu_pin) {
+ cpu_set_t set;
+ CPU_ZERO (&set);
+ CPU_SET (opt.cpu_pin.value(), & set);
+ sched_setaffinity (getpid(), sizeof set, & set);
+ }
+
auto sock_path = "unix:path=" + opt.sock_path;
auto conn = dbus_connection_open_private (sock_path.c_str(), nullptr);
* Good for %-based comparisons, but avoid for time measurements. */
bool busy_wait = false;
+ /* Pins the server to a specific CPU. If the server lives on the
+ * same CPU as the client, it will be able to process the message
+ * as soon as the client goes to sleep (trading off parallelism
+ * for better "timings" on the process scheduler). */
+ std::optional <int> cpu_pin = std::nullopt;
+
/* When enabled, the server collects all method call times and
* writes them out to a CSV file under the specified path. Useful
* for distribution charts. */
run_opts ret;
int opt;
- while ((opt = getopt(argc, argv, ":ihp:r:t:w")) != -1)
+ while ((opt = getopt(argc, argv, ":c:ihp:r:t:w")) != -1)
switch (opt) {
+ case 'c':
+ ret.cpu_pin = std::stoi(optarg);
+ break;
case 'i':
ret.infinite_listening = true;
break;
" [-i (infinite listening)]"
" [-w (busy wait)]"
" [-r [dump_csv_file_path]]"
+ " [-c cpu_pin]"
<< std::endl
;
}
return EXIT_FAILURE;
}
+ if (opt.cpu_pin) {
+ cpu_set_t set;
+ CPU_ZERO (&set);
+ CPU_SET (opt.cpu_pin.value(), & set);
+ sched_setaffinity (getpid(), sizeof set, & set);
+ }
+
DBusError derror;
dbus_error_init (& derror);