Updated Branches: refs/heads/master 1686269fb -> 025cd2796
TS-1356 Simple way of assigning threads to a CPU. It just loops over the net threads an assigns them to a CPU. Better version to come later. Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/025cd279 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/025cd279 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/025cd279 Branch: refs/heads/master Commit: 025cd2796b331b022c255f2cb531aedd95786757 Parents: 1686269 Author: Bryan Call <[email protected]> Authored: Wed Aug 15 13:37:09 2012 -0700 Committer: Bryan Call <[email protected]> Committed: Wed Aug 15 13:37:09 2012 -0700 ---------------------------------------------------------------------- iocore/eventsystem/UnixEventProcessor.cc | 31 +++++++++++++++++++++--- mgmt/RecordsConfig.cc | 2 + 2 files changed, 29 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/025cd279/iocore/eventsystem/UnixEventProcessor.cc ---------------------------------------------------------------------- diff --git a/iocore/eventsystem/UnixEventProcessor.cc b/iocore/eventsystem/UnixEventProcessor.cc index a3b5a7b..7030d15 100644 --- a/iocore/eventsystem/UnixEventProcessor.cc +++ b/iocore/eventsystem/UnixEventProcessor.cc @@ -22,8 +22,9 @@ */ #include "P_EventSystem.h" /* MAGIC_EDITING_TAG */ - - +#include <sched.h> +#include <hwloc.h> +#include "ink_defs.h" EventType EventProcessor::spawn_event_threads(int n_threads, const char* et_name) @@ -93,11 +94,33 @@ EventProcessor::start(int n_event_threads) t->set_event_type((EventType) ET_CALL); } n_threads_for_type[ET_CALL] = n_event_threads; + +#if TS_USE_HWLOC + int affinity = 0; + REC_ReadConfigInteger(affinity, "proxy.config.exec_thread.affinity"); + cpu_set_t cpuset; + const hwloc_topology_t *topology = ink_get_topology(); + int cu = hwloc_get_nbobjs_by_type(*topology, HWLOC_OBJ_CORE); + int pu = hwloc_get_nbobjs_by_type(*topology, HWLOC_OBJ_PU); + int num_cpus = cu; + Debug("iocore_thread", "cu: %d pu: %d affinity: %d", cu, pu, affinity); +#endif + for (i = first_thread; i < n_ethreads; i++) { snprintf(thr_name, MAX_THREAD_NAME_LENGTH, "[ET_NET %d]", i); - all_ethreads[i]->start(thr_name); + ink_thread tid = all_ethreads[i]->start(thr_name); + (void)tid; + +#if TS_USE_HWLOC + if (affinity == 1) { + CPU_ZERO(&cpuset); + int cpu = (i - 1) % num_cpus; + CPU_SET(cpu, &cpuset); + Debug("iocore_thread", "setaffinity tid: %lu, net thread: %d, cpu: %d", tid, i, cpu); + assert(pthread_setaffinity_np(tid, sizeof(cpu_set_t), &cpuset) == 0); + } +#endif } - Debug("iocore_thread", "Created event thread group id %d with %d threads", ET_CALL, n_event_threads); return 0; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/025cd279/mgmt/RecordsConfig.cc ---------------------------------------------------------------------- diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc index e9e7ba3..41212da 100644 --- a/mgmt/RecordsConfig.cc +++ b/mgmt/RecordsConfig.cc @@ -130,6 +130,8 @@ RecordElement RecordsConfig[] = { , {RECT_CONFIG, "proxy.config.exec_thread.limit", RECD_INT, "2", RECU_RESTART_TS, RR_NULL, RECC_INT, "[1-1024]", RECA_READ_ONLY} , + {RECT_CONFIG, "proxy.config.exec_thread.affinity", RECD_INT, "0", RECU_RESTART_TS, RR_NULL, RECC_INT, "[0-1]", RECA_READ_ONLY} + , {RECT_CONFIG, "proxy.config.accept_threads", RECD_INT, "1", RECU_RESTART_TS, RR_NULL, RECC_INT, "[0-1]", RECA_READ_ONLY} , {RECT_CONFIG, "proxy.config.task_threads", RECD_INT, "2", RECU_RESTART_TS, RR_NULL, RECC_INT, "[0-99999]", RECA_READ_ONLY}
