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 92ab7ef task threads ready lifecycle hook
92ab7ef is described below
commit 92ab7ef135e890380eb270fcc20ee27c57061e93
Author: Fei Deng <[email protected]>
AuthorDate: Mon Dec 17 16:41:53 2018 -0600
task threads ready lifecycle hook
---
doc/developer-guide/api/functions/TSLifecycleHookAdd.en.rst | 7 +++++++
include/ts/apidefs.h.in | 10 +++++++++-
iocore/eventsystem/I_EventProcessor.h | 1 +
iocore/eventsystem/I_Tasks.h | 1 +
iocore/eventsystem/Tasks.cc | 9 ++++++++-
iocore/eventsystem/UnixEventProcessor.cc | 3 +++
proxy/http/HttpDebugNames.cc | 2 ++
src/traffic_server/traffic_server.cc | 13 +++++++++++++
8 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/doc/developer-guide/api/functions/TSLifecycleHookAdd.en.rst
b/doc/developer-guide/api/functions/TSLifecycleHookAdd.en.rst
index efdcee1..bac552b 100644
--- a/doc/developer-guide/api/functions/TSLifecycleHookAdd.en.rst
+++ b/doc/developer-guide/api/functions/TSLifecycleHookAdd.en.rst
@@ -98,6 +98,13 @@ Types
Called after every SSL context initialization used by |TS| for inbound
connections (|TS| as the server).
+ .. cpp:enumerator:: TS_LIFECYCLE_TASK_THREADS_READY_HOOK
+
+ Called after |TS| task threads have been started.
+
+ Invoked with the event :c:data:`TS_EVENT_LIFECYCLE_TASK_THREADS_READY`
and ``NULL``
+ data.
+
.. c:type:: TSPluginMsg
The format of the data for the plugin message event
:c:data:`TS_EVENT_LIFECYCLE_MSG`.
diff --git a/include/ts/apidefs.h.in b/include/ts/apidefs.h.in
index 6c04265..8b74969 100644
--- a/include/ts/apidefs.h.in
+++ b/include/ts/apidefs.h.in
@@ -324,7 +324,7 @@ typedef enum {
accept connections. This is *not* guaranteed to be called
before the first connection is accepted.
- Event: TS_EVENT_LIFECYCLE_PORTS_READY_HOOK
+ Event: TS_EVENT_LIFECYCLE_PORTS_READY
TS_LIFECYCLE_CACHE_READY_HOOK
@@ -354,6 +354,12 @@ typedef enum {
Event: TS_EVENT_LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED
+ TS_LIFECYCLE_TASK_THREADS_READY_HOOK
+
+ called once, after the task threads have been started.
+
+ Event: TS_EVENT_LIFECYCLE_TASK_THREADS_READY
+
Ordering guarantees:
- TS_LIFECYCLE_PORTS_INITIALIZED_HOOK before TS_LIFECYCLE_PORTS_READY_HOOK.
@@ -368,6 +374,7 @@ typedef enum {
TS_LIFECYCLE_SERVER_SSL_CTX_INITIALIZED_HOOK,
TS_LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED_HOOK,
TS_LIFECYCLE_MSG_HOOK,
+ TS_LIFECYCLE_TASK_THREADS_READY_HOOK,
TS_LIFECYCLE_LAST_HOOK
} TSLifecycleHookID;
@@ -453,6 +460,7 @@ typedef enum {
TS_EVENT_LIFECYCLE_CACHE_READY = 60020,
TS_EVENT_LIFECYCLE_SERVER_SSL_CTX_INITIALIZED = 60021,
TS_EVENT_LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED = 60022,
+ TS_EVENT_LIFECYCLE_TASK_THREADS_READY = 60027,
TS_EVENT_VCONN_START = 60023,
TS_EVENT_VCONN_PRE_ACCEPT = TS_EVENT_VCONN_START, //
Deprecated but still compatible
TS_EVENT_VCONN_CLOSE = 60026,
diff --git a/iocore/eventsystem/I_EventProcessor.h
b/iocore/eventsystem/I_EventProcessor.h
index 28dbd01..3730b49 100644
--- a/iocore/eventsystem/I_EventProcessor.h
+++ b/iocore/eventsystem/I_EventProcessor.h
@@ -308,6 +308,7 @@ public:
int _next_round_robin = 0; ///< Index of thread to
use for events assigned to this group.
Que(Event, link) _spawnQueue; ///< Events to dispatch
when thread is spawned.
EThread *_thread[MAX_THREADS_IN_EACH_TYPE] = {}; ///< The actual threads
in this group.
+ std::function<void()> _afterStartCallback = nullptr;
};
/// Storage for per group data.
diff --git a/iocore/eventsystem/I_Tasks.h b/iocore/eventsystem/I_Tasks.h
index 0484f36..160ffe8 100644
--- a/iocore/eventsystem/I_Tasks.h
+++ b/iocore/eventsystem/I_Tasks.h
@@ -31,6 +31,7 @@ extern EventType ET_TASK;
class TasksProcessor : public Processor
{
public:
+ EventType register_event_type();
int start(int task_threads, size_t stacksize = DEFAULT_STACKSIZE) override;
};
diff --git a/iocore/eventsystem/Tasks.cc b/iocore/eventsystem/Tasks.cc
index 91a5942..7de34e2 100644
--- a/iocore/eventsystem/Tasks.cc
+++ b/iocore/eventsystem/Tasks.cc
@@ -27,11 +27,18 @@
EventType ET_TASK = ET_CALL;
TasksProcessor tasksProcessor;
+EventType
+TasksProcessor::register_event_type()
+{
+ ET_TASK = eventProcessor.register_event_type("ET_TASK");
+ return ET_TASK;
+}
+
// Note that if the number of task_threads is 0, all continuations scheduled
for
// ET_TASK ends up running on ET_CALL (which is the net-threads).
int
TasksProcessor::start(int task_threads, size_t stacksize)
{
- ET_TASK = eventProcessor.spawn_event_threads("ET_TASK", std::max(1,
task_threads), stacksize);
+ eventProcessor.spawn_event_threads(ET_TASK, std::max(1, task_threads),
stacksize);
return 0;
}
diff --git a/iocore/eventsystem/UnixEventProcessor.cc
b/iocore/eventsystem/UnixEventProcessor.cc
index 32b9ed6..f2bcf4e 100644
--- a/iocore/eventsystem/UnixEventProcessor.cc
+++ b/iocore/eventsystem/UnixEventProcessor.cc
@@ -396,6 +396,9 @@ EventProcessor::initThreadState(EThread *t)
for (int i = 0; i < MAX_EVENT_TYPES; ++i) {
if (t->is_event_type(i)) { // that event type done here, roll thread start
events of that type.
++thread_group[i]._started;
+ if (thread_group[i]._started == thread_group[i]._count &&
thread_group[i]._afterStartCallback != nullptr) {
+ thread_group[i]._afterStartCallback();
+ }
// To avoid race conditions on the event in the spawn queue, create a
local one to actually send.
// Use the spawn queue event as a read only model.
Event *nev = eventAllocator.alloc();
diff --git a/proxy/http/HttpDebugNames.cc b/proxy/http/HttpDebugNames.cc
index 59beb01..576e75a 100644
--- a/proxy/http/HttpDebugNames.cc
+++ b/proxy/http/HttpDebugNames.cc
@@ -345,6 +345,8 @@ HttpDebugNames::get_event_name(int event)
return "TS_EVENT_LIFECYCLE_SERVER_SSL_CTX_INITIALIZED";
case TS_EVENT_LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED:
return "TS_EVENT_LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED";
+ case TS_EVENT_LIFECYCLE_TASK_THREADS_READY:
+ return "TS_EVENT_LIFECYCLE_TASK_THREADS_READY";
case TS_EVENT_VCONN_START:
return "TS_EVENT_VCONN_START";
case TS_EVENT_VCONN_CLOSE:
diff --git a/src/traffic_server/traffic_server.cc
b/src/traffic_server/traffic_server.cc
index a69aeec..2d5f337 100644
--- a/src/traffic_server/traffic_server.cc
+++ b/src/traffic_server/traffic_server.cc
@@ -121,6 +121,7 @@ static void *mgmt_lifecycle_msg_callback(void *x, char
*data, int len);
static void init_ssl_ctx_callback(void *ctx, bool server);
static void load_ssl_file_callback(const char *ssl_file, unsigned int options);
static void load_remap_file_callback(const char *remap_file);
+static void task_threads_started_callback();
// We need these two to be accessible somewhere else now
int num_of_net_threads = ink_number_of_processors();
@@ -1957,6 +1958,8 @@ main(int /* argc ATS_UNUSED */, const char **argv)
RecConfigWarnIfUnregistered();
// "Task" processor, possibly with its own set of task threads
+ tasksProcessor.register_event_type();
+ eventProcessor.thread_group[ET_TASK]._afterStartCallback =
task_threads_started_callback;
tasksProcessor.start(num_task_threads, stacksize);
if (netProcessor.socks_conf_stuff->accept_enabled) {
@@ -2100,3 +2103,13 @@ load_remap_file_callback(const char *remap_file)
{
pmgmt->signalConfigFileChild("remap.config", remap_file,
CONFIG_FLAG_UNVERSIONED);
}
+
+static void
+task_threads_started_callback()
+{
+ APIHook *hook = lifecycle_hooks->get(TS_LIFECYCLE_TASK_THREADS_READY_HOOK);
+ while (hook) {
+ hook->invoke(TS_EVENT_LIFECYCLE_TASK_THREADS_READY, nullptr);
+ hook = hook->next();
+ }
+}