You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2013/03/10 00:01:58 UTC

git commit: [TS-1356] Ability to set thread affinity with multiple modes

Updated Branches:
  refs/heads/master 8f6cbad67 -> c08d8d264


[TS-1356] Ability to set thread affinity with multiple modes


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/c08d8d26
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/c08d8d26
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/c08d8d26

Branch: refs/heads/master
Commit: c08d8d264b3394c1c8005dfc767bd887a8a78b73
Parents: 8f6cbad
Author: Bryan Call <bc...@apache.org>
Authored: Sat Mar 9 15:00:54 2013 -0800
Committer: Bryan Call <bc...@apache.org>
Committed: Sat Mar 9 15:00:54 2013 -0800

----------------------------------------------------------------------
 CHANGES                                  |    6 ++++-
 example/app-template/records.config.in   |    1 +
 iocore/eventsystem/UnixEventProcessor.cc |   32 +++++++++++++++++++-----
 3 files changed, 31 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c08d8d26/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index cb926b5..9f24b6b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,10 @@
                                                          -*- coding: utf-8 -*-
-Changes with Apache Traffic Server 3.3.1
+  Changes with Apache Traffic Server 3.3.2
 
+  *) [TS-1356] Ability to set thread affinity with multiple modes
+
+  
+  Changes with Apache Traffic Server 3.3.1
 
   *) [TS-1743] Implement our own hash mechanism for traffic_logstats, since
    C++11 does not provide a sensical hash<const char*>.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c08d8d26/example/app-template/records.config.in
----------------------------------------------------------------------
diff --git a/example/app-template/records.config.in b/example/app-template/records.config.in
index e17b0b6..148ed5e 100644
--- a/example/app-template/records.config.in
+++ b/example/app-template/records.config.in
@@ -28,6 +28,7 @@ CONFIG proxy.config.system.memalign_heap INT 0
 CONFIG proxy.config.exec_thread.autoconfig INT 1
 CONFIG proxy.config.exec_thread.autoconfig.scale FLOAT 3.0
 CONFIG proxy.config.exec_thread.limit INT 2
+CONFIG proxy.config.exec_thread.affinity INT 0
 CONFIG proxy.config.accept_threads INT 1
 
 ##############################################################################

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c08d8d26/iocore/eventsystem/UnixEventProcessor.cc
----------------------------------------------------------------------
diff --git a/iocore/eventsystem/UnixEventProcessor.cc b/iocore/eventsystem/UnixEventProcessor.cc
index 8a57195..1efdf0b 100644
--- a/iocore/eventsystem/UnixEventProcessor.cc
+++ b/iocore/eventsystem/UnixEventProcessor.cc
@@ -168,10 +168,10 @@ EventProcessor::start(int n_event_threads)
   REC_ReadConfigInteger(affinity, "proxy.config.exec_thread.affinity");
   ink_cpuset_t cpuset;
   const hwloc_topology_t *topology = ink_get_topology();
+  int socket = hwloc_get_nbobjs_by_type(*topology, HWLOC_OBJ_SOCKET);
   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);
+  Debug("iocore_thread", "socket: %d core: %d logical processor: %d affinity: %d", socket, cu, pu, affinity);
 #endif
 
   for (i = first_thread; i < n_ethreads; i++) {
@@ -180,12 +180,30 @@ EventProcessor::start(int n_event_threads)
     (void)tid;
 
 #if TS_USE_HWLOC
-    if (affinity == 1) {
-      int cpu = (i - 1) % num_cpus;
-      set_cpu(&cpuset, cpu);
-      Debug("iocore_thread", "setaffinity tid: %" PTR_FMT ", net thread: %u, cpu: %d", tid, i, cpu);
+    if (affinity != 0) {
+      int logical_ratio;
+      switch(affinity) {
+      case 3:           // assgin threads to logical cores
+        logical_ratio = 1;
+        break;
+      case 2:           // assign threads to real cores
+        logical_ratio = pu / cu;
+        break;
+      case 1:           // assgin threads to sockets
+      default:
+        logical_ratio = pu / socket;
+      }
+
+      char debug_message[256];
+      int len = snprintf(debug_message, sizeof(debug_message), "setaffinity tid: %" PTR_FMT ", net thread: %u cpu:", tid, i);
+      for (int cpu_count = 0; cpu_count < logical_ratio; cpu_count++) {
+        int cpu = ((i - 1) * logical_ratio + cpu_count) % pu;
+        set_cpu(&cpuset, cpu);
+        len += snprintf(debug_message + len, sizeof(debug_message) - len, " %d", cpu);
+      }
+      Debug("iocore_thread", debug_message);
       if (!bind_cpu(&cpuset, tid)){
-        Debug("iocore_thread", "setaffinity for tid: %" PTR_FMT ", net thread: %u, cpu: %d failed with: %d", tid, i, cpu, errno);
+        Error("%s, failed with errno: %d", debug_message, errno);
       }
     }
 #endif