Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable agents to auto-select how many threads to use #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions agents/agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <strings.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/sysinfo.h>
#include <sys/types.h>

#include <lancet/agent.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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]();
Expand Down Expand Up @@ -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);
Expand Down