You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by du...@apache.org on 2019/06/18 15:13:51 UTC
[trafficserver] branch master updated: use type info to assign an
affinity thread
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 e209bb1 use type info to assign an affinity thread
e209bb1 is described below
commit e209bb1802f6ee1681e858f39985c3affa04d903
Author: Fei Deng <du...@gmail.com>
AuthorDate: Thu Apr 25 01:35:54 2019 -0500
use type info to assign an affinity thread
---
iocore/eventsystem/I_EventProcessor.h | 1 +
iocore/eventsystem/P_UnixEventProcessor.h | 25 +++++++++++++++++++++++
iocore/net/UnixNetProcessor.cc | 33 +++++++++++++------------------
3 files changed, 40 insertions(+), 19 deletions(-)
diff --git a/iocore/eventsystem/I_EventProcessor.h b/iocore/eventsystem/I_EventProcessor.h
index a15d406..761f9ca 100644
--- a/iocore/eventsystem/I_EventProcessor.h
+++ b/iocore/eventsystem/I_EventProcessor.h
@@ -331,6 +331,7 @@ public:
Event *schedule(Event *e, EventType etype, bool fast_signal = false);
EThread *assign_thread(EventType etype);
+ EThread *assign_affinity_by_type(Continuation *cont, EventType etype);
EThread *all_dthreads[MAX_EVENT_THREADS];
int n_dthreads = 0; // No. of dedicated threads
diff --git a/iocore/eventsystem/P_UnixEventProcessor.h b/iocore/eventsystem/P_UnixEventProcessor.h
index b4dea2e..8ebf1f9 100644
--- a/iocore/eventsystem/P_UnixEventProcessor.h
+++ b/iocore/eventsystem/P_UnixEventProcessor.h
@@ -61,6 +61,31 @@ EventProcessor::assign_thread(EventType etype)
return tg->_thread[next];
}
+// If thread_holding is the correct type, return it.
+//
+// Otherwise check if there is already an affinity associated with the continuation,
+// return it if the type is the same, return the next available thread of "etype" if
+// the type is different.
+//
+// Only assign new affinity when there is currently none.
+TS_INLINE EThread *
+EventProcessor::assign_affinity_by_type(Continuation *cont, EventType etype)
+{
+ EThread *ethread = cont->mutex->thread_holding;
+ if (!ethread->is_event_type(etype)) {
+ ethread = cont->getThreadAffinity();
+ if (ethread == nullptr || !ethread->is_event_type(etype)) {
+ ethread = assign_thread(etype);
+ }
+ }
+
+ if (cont->getThreadAffinity() == nullptr) {
+ cont->setThreadAffinity(ethread);
+ }
+
+ return ethread;
+}
+
TS_INLINE Event *
EventProcessor::schedule(Event *e, EventType etype, bool fast_signal)
{
diff --git a/iocore/net/UnixNetProcessor.cc b/iocore/net/UnixNetProcessor.cc
index fd3b368..3902658 100644
--- a/iocore/net/UnixNetProcessor.cc
+++ b/iocore/net/UnixNetProcessor.cc
@@ -178,7 +178,7 @@ UnixNetProcessor::connect_re_internal(Continuation *cont, sockaddr const *target
if (TSSystemState::is_event_system_shut_down()) {
return ACTION_RESULT_NONE;
}
- EThread *t = cont->mutex->thread_holding;
+ EThread *t = eventProcessor.assign_affinity_by_type(cont, opt->etype);
UnixNetVConnection *vc = (UnixNetVConnection *)this->allocate_vc(t);
if (opt) {
@@ -232,27 +232,22 @@ UnixNetProcessor::connect_re_internal(Continuation *cont, sockaddr const *target
vc->action_ = cont;
}
- if (t->is_event_type(opt->etype)) {
- MUTEX_TRY_LOCK(lock, cont->mutex, t);
- if (lock.is_locked()) {
- MUTEX_TRY_LOCK(lock2, get_NetHandler(t)->mutex, t);
- if (lock2.is_locked()) {
- int ret;
- ret = vc->connectUp(t, NO_FD);
- if ((using_socks) && (ret == CONNECT_SUCCESS)) {
- return &socksEntry->action_;
- } else {
- return ACTION_RESULT_DONE;
- }
+ MUTEX_TRY_LOCK(lock, cont->mutex, t);
+ if (lock.is_locked()) {
+ MUTEX_TRY_LOCK(lock2, get_NetHandler(t)->mutex, t);
+ if (lock2.is_locked()) {
+ int ret;
+ ret = vc->connectUp(t, NO_FD);
+ if ((using_socks) && (ret == CONNECT_SUCCESS)) {
+ return &socksEntry->action_;
+ } else {
+ return ACTION_RESULT_DONE;
}
}
}
- // Try to stay on the current thread if it is the right type
- if (t->is_event_type(opt->etype)) {
- t->schedule_imm(vc);
- } else { // Otherwise, pass along to another thread of the right type
- eventProcessor.schedule_imm(vc, opt->etype);
- }
+
+ t->schedule_imm(vc);
+
if (using_socks) {
return &socksEntry->action_;
} else {