trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From duke8...@apache.org
Subject [trafficserver] branch master updated: set thread affinity using type info
Date Fri, 22 Feb 2019 16:05:12 GMT
This is an automated email from the ASF dual-hosted git repository.

duke8253 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 4266403  set thread affinity using type info
4266403 is described below

commit 426640346798589dcd7d5b87c9f64e748208ceaf
Author: Fei Deng <duke8253@gmail.com>
AuthorDate: Thu Feb 21 15:18:47 2019 -0600

    set thread affinity using type info
---
 iocore/eventsystem/P_UnixEventProcessor.h          |  3 +++
 src/traffic_server/InkAPI.cc                       | 14 ++----------
 .../cont_schedule/gold/thread_affinity.gold        |  4 ++--
 tests/tools/plugins/cont_schedule.cc               | 26 +++++++++++++---------
 4 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/iocore/eventsystem/P_UnixEventProcessor.h b/iocore/eventsystem/P_UnixEventProcessor.h
index 90f08b9..003d425 100644
--- a/iocore/eventsystem/P_UnixEventProcessor.h
+++ b/iocore/eventsystem/P_UnixEventProcessor.h
@@ -71,6 +71,9 @@ EventProcessor::schedule(Event *e, EventType etype, bool fast_signal)
     e->ethread = ethread;
   } else {
     e->ethread = assign_thread(etype);
+    if (ethread == nullptr) {
+      e->continuation->setThreadAffinity(e->ethread);
+    }
   }
 
   if (e->continuation->mutex) {
diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc
index 5b63750..e7d1080 100644
--- a/src/traffic_server/InkAPI.cc
+++ b/src/traffic_server/InkAPI.cc
@@ -4409,8 +4409,7 @@ TSContSchedule(TSCont contp, TSHRTime timeout)
 
   EThread *eth = i->getThreadAffinity();
   if (eth == nullptr) {
-    eth = this_event_thread();
-    i->setThreadAffinity(eth);
+    return nullptr;
   }
 
   TSAction action;
@@ -4438,10 +4437,6 @@ TSContScheduleOnPool(TSCont contp, TSHRTime timeout, TSThreadPool tp)
     ink_assert(!"not reached");
   }
 
-  if (i->getThreadAffinity() == nullptr) {
-    i->setThreadAffinity(this_event_thread());
-  }
-
   EventType etype;
 
   switch (tp) {
@@ -4527,8 +4522,7 @@ TSContScheduleEvery(TSCont contp, TSHRTime every /* millisecs */)
 
   EThread *eth = i->getThreadAffinity();
   if (eth == nullptr) {
-    eth = this_event_thread();
-    i->setThreadAffinity(eth);
+    return nullptr;
   }
 
   TSAction action = reinterpret_cast<TSAction>(eth->schedule_every(i, HRTIME_MSECONDS(every)));
@@ -4551,10 +4545,6 @@ TSContScheduleEveryOnPool(TSCont contp, TSHRTime every, TSThreadPool
tp)
     ink_assert(!"not reached");
   }
 
-  if (i->getThreadAffinity() == nullptr) {
-    i->setThreadAffinity(this_event_thread());
-  }
-
   EventType etype;
 
   switch (tp) {
diff --git a/tests/gold_tests/cont_schedule/gold/thread_affinity.gold b/tests/gold_tests/cont_schedule/gold/thread_affinity.gold
index b81b4f5..09a79cf 100644
--- a/tests/gold_tests/cont_schedule/gold/thread_affinity.gold
+++ b/tests/gold_tests/cont_schedule/gold/thread_affinity.gold
@@ -1,5 +1,5 @@
 ``
-``pass [affinity thread is null]
-``pass [affinity thread is set]
+``pass [affinity thread is not null]
 ``pass [affinity thread is cleared]
+``pass [affinity thread is set]
 ``
diff --git a/tests/tools/plugins/cont_schedule.cc b/tests/tools/plugins/cont_schedule.cc
index accf3db..abc8066 100644
--- a/tests/tools/plugins/cont_schedule.cc
+++ b/tests/tools/plugins/cont_schedule.cc
@@ -175,22 +175,22 @@ TSContThreadAffinity_handler(TSCont contp, TSEvent event, void *edata)
 
   test_thread = TSEventThreadSelf();
 
-  if (TSContThreadAffinityGet(contp) == nullptr) {
-    TSDebug(DEBUG_TAG_CHK, "pass [affinity thread is null]");
-    TSContThreadAffinitySet(contp, TSEventThreadSelf());
-    if (TSContThreadAffinityGet(contp) == test_thread) {
-      TSDebug(DEBUG_TAG_CHK, "pass [affinity thread is set]");
-      TSContThreadAffinityClear(contp);
-      if (TSContThreadAffinityGet(contp) == nullptr) {
-        TSDebug(DEBUG_TAG_CHK, "pass [affinity thread is cleared]");
+  if (TSContThreadAffinityGet(contp) != nullptr) {
+    TSDebug(DEBUG_TAG_CHK, "pass [affinity thread is not null]");
+    TSContThreadAffinityClear(contp);
+    if (TSContThreadAffinityGet(contp) == nullptr) {
+      TSDebug(DEBUG_TAG_CHK, "pass [affinity thread is cleared]");
+      TSContThreadAffinitySet(contp, TSEventThreadSelf());
+      if (TSContThreadAffinityGet(contp) == test_thread) {
+        TSDebug(DEBUG_TAG_CHK, "pass [affinity thread is set]");
       } else {
-        TSDebug(DEBUG_TAG_CHK, "fail [affinity thread is not cleared]");
+        TSDebug(DEBUG_TAG_CHK, "fail [affinity thread is not set]");
       }
     } else {
-      TSDebug(DEBUG_TAG_CHK, "fail [affinity thread is not set]");
+      TSDebug(DEBUG_TAG_CHK, "fail [affinity thread is not cleared]");
     }
   } else {
-    TSDebug(DEBUG_TAG_CHK, "fail [affinity thread is not null]");
+    TSDebug(DEBUG_TAG_CHK, "fail [affinity thread is null]");
   }
 
   return 0;
@@ -207,6 +207,7 @@ TSContSchedule_test()
   } else {
     TSDebug(DEBUG_TAG_SCHD, "[%s] scheduling continuation", plugin_name);
     TSContScheduleOnPool(contp, 0, TS_THREAD_POOL_NET);
+    TSContThreadAffinityClear(contp);
     TSContScheduleOnPool(contp, 200, TS_THREAD_POOL_NET);
   }
 }
@@ -223,8 +224,10 @@ TSContScheduleOnPool_test()
   } else {
     TSDebug(DEBUG_TAG_SCHD, "[%s] scheduling continuation", plugin_name);
     TSContScheduleOnPool(contp_1, 0, TS_THREAD_POOL_NET);
+    TSContThreadAffinityClear(contp_1);
     TSContScheduleOnPool(contp_1, 100, TS_THREAD_POOL_NET);
     TSContScheduleOnPool(contp_2, 200, TS_THREAD_POOL_TASK);
+    TSContThreadAffinityClear(contp_2);
     TSContScheduleOnPool(contp_2, 300, TS_THREAD_POOL_TASK);
   }
 }
@@ -240,6 +243,7 @@ TSContScheduleOnThread_test()
   } else {
     TSDebug(DEBUG_TAG_SCHD, "[%s] scheduling continuation", plugin_name);
     TSContScheduleOnPool(contp, 0, TS_THREAD_POOL_NET);
+    TSContThreadAffinityClear(contp);
     TSContScheduleOnPool(contp, 200, TS_THREAD_POOL_NET);
   }
 }


Mime
View raw message