From 719dfd95413316ce6635078f91ec9f156cb70cba Mon Sep 17 00:00:00 2001 From: Geoff Blake Date: Fri, 16 Aug 2024 09:59:35 -0500 Subject: [PATCH] Since the load and latency agents are polling based, we don't want more threads than available cores to avoid errorneous measurements. Allow -ltThreads and -loadThreads (-t at the agent command line) to take a -1 option and have the agents determine the number of threads to use. Also, make sure at least one connection per thread exists, by checking if avalaible threads > connections and settings threads = connections. --- Makefile | 2 +- agents/agent.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c500ef3..865aaf3 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -.PHONY: coordinator agents style manager manager_r2p2 all clean +.PHONY: coordinator agents style manager all clean .DEFAULT_GOAL := all all: agents diff --git a/agents/agent.c b/agents/agent.c index 943daa4..2b2f6bf 100644 --- a/agents/agent.c +++ b/agents/agent.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -136,7 +137,7 @@ struct byte_req_pair process_response(char *buf, int size) return consume_response(cfg->app_proto, &received); } -static void *agent_main(void *arg) +static void* agent_main(void *arg) { cpu_set_t cpuset; pthread_t thread; @@ -153,7 +154,9 @@ static void *agent_main(void *arg) s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset); if (s != 0) { - lancet_perror("pthread_setaffinity_np"); + char buf[256]; + snprintf(buf, sizeof(buf), "ERROR: pthread_setaffinity_np failed for thread %d", thread_idx); + lancet_perror(buf); return NULL; } cfg->tp->tp_main[cfg->atype](); @@ -203,6 +206,15 @@ int main(int argc, char **argv) if (cfg->atype == SYMMETRIC_NIC_TIMESTAMP_AGENT) enable_nic_timestamping(cfg->if_name); + /* Auto-select number of threads to use */ + if (cfg->thread_count == -1) { + cfg->thread_count = get_nprocs(); + if (cfg->conn_count < cfg->thread_count) { + cfg->thread_count = cfg->conn_count; + lancet_fprintf(stderr, "Limiting number of threads to %d\n", cfg->thread_count); + } + } + if (configure_control_block()) { lancet_fprintf(stderr, "failed to init the control block\n"); exit(-1);