diff --git a/include/records/I_RecDefs.h b/include/records/I_RecDefs.h index 5362e5e00f6..24851a44027 100644 --- a/include/records/I_RecDefs.h +++ b/include/records/I_RecDefs.h @@ -151,6 +151,19 @@ struct RecRawStat { uint32_t version; }; +struct RecRawStatBlock; + +// This defines the interface to the low level stat block operations +// The implementation of this was moved out of the records library due to a circular dependency this produced. +// look for the implementation of RecRawStatBlockOps in iocore/eventsystem +struct RecRawStatBlockOps { + virtual int raw_stat_clear_sum(RecRawStatBlock *rsb, int id) = 0; + virtual int raw_stat_clear_count(RecRawStatBlock *rsb, int id) = 0; + virtual int raw_stat_get_total(RecRawStatBlock *rsb, int id, RecRawStat *total) = 0; + virtual int raw_stat_sync_to_global(RecRawStatBlock *rsb, int id) = 0; + virtual int raw_stat_clear(RecRawStatBlock *rsb, int id) = 0; +}; + // WARNING! It's advised that developers do not modify the contents of // the RecRawStatBlock. ^_^ struct RecRawStatBlock { @@ -159,6 +172,7 @@ struct RecRawStatBlock { int num_stats; // number of stats in this block int max_stats; // maximum number of stats for this block ink_mutex mutex; + RecRawStatBlockOps *ops; }; //------------------------------------------------------------------------- diff --git a/include/records/I_RecProcess.h b/include/records/I_RecProcess.h index 1d510b12fb8..15a51117fb2 100644 --- a/include/records/I_RecProcess.h +++ b/include/records/I_RecProcess.h @@ -27,22 +27,12 @@ #include "I_EventSystem.h" //------------------------------------------------------------------------- -// Initialization/Starting +// RawStat Registration //------------------------------------------------------------------------- -int RecProcessInit(Diags *diags = nullptr); -int RecProcessInitMessage(); -int RecProcessStart(); -//------------------------------------------------------------------------- -// Setters for manipulating internal sleep intervals -//------------------------------------------------------------------------- -void RecProcess_set_raw_stat_sync_interval_ms(int ms); -void RecProcess_set_config_update_interval_ms(int ms); -void RecProcess_set_remote_sync_interval_ms(int ms); +using RecRawStatBlockAllocator = RecRawStatBlock *(*)(int num_stats); -//------------------------------------------------------------------------- -// RawStat Registration -//------------------------------------------------------------------------- +void SetRecAllocateRawStatBlockAllocator(RecRawStatBlockAllocator); RecRawStatBlock *RecAllocateRawStatBlock(int num_stats); int _RecRegisterRawStat(RecRawStatBlock *rsb, RecT rec_type, const char *name, RecDataT data_type, RecPersistT persist_type, int id, diff --git a/iocore/eventsystem/CMakeLists.txt b/iocore/eventsystem/CMakeLists.txt index 14615544445..c9dd0550006 100644 --- a/iocore/eventsystem/CMakeLists.txt +++ b/iocore/eventsystem/CMakeLists.txt @@ -33,5 +33,6 @@ add_library(inkevent SHARED UnixEvent.cc UnixEventProcessor.cc ConfigProcessor.cc -) -target_include_directories(inkevent PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file + RecRawStatsImpl.cc) +target_include_directories(inkevent PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(inkevent ${PCRE_LIBRARIES} ${OPENSSL_LIBRARIES} yaml-cpp::yaml-cpp tscpputil resolv libswoc tscore records_p) \ No newline at end of file diff --git a/iocore/eventsystem/I_EventSystem.h b/iocore/eventsystem/I_EventSystem.h index a062b5c31a8..8064be7fe1b 100644 --- a/iocore/eventsystem/I_EventSystem.h +++ b/iocore/eventsystem/I_EventSystem.h @@ -44,6 +44,7 @@ #include "I_VConnection.h" #include "records/I_RecProcess.h" #include "I_SocketManager.h" +#include "RecProcess.h" static constexpr ts::ModuleVersion EVENT_SYSTEM_MODULE_PUBLIC_VERSION(1, 0, ts::ModuleVersion::PUBLIC); diff --git a/iocore/eventsystem/Makefile.am b/iocore/eventsystem/Makefile.am index a18ee043f20..3b642e9104e 100644 --- a/iocore/eventsystem/Makefile.am +++ b/iocore/eventsystem/Makefile.am @@ -63,6 +63,8 @@ libinkevent_a_SOURCES = \ Processor.cc \ ProtectedQueue.cc \ ProxyAllocator.cc \ + RecProcess.cc \ + RecRawStatsImpl.cc \ SocketManager.cc \ Tasks.cc \ Thread.cc \ diff --git a/src/records/RecProcess.cc b/iocore/eventsystem/RecProcess.cc similarity index 85% rename from src/records/RecProcess.cc rename to iocore/eventsystem/RecProcess.cc index 884120a817b..fff53ca6acc 100644 --- a/src/records/RecProcess.cc +++ b/iocore/eventsystem/RecProcess.cc @@ -34,8 +34,7 @@ #include "records/P_RecFile.h" // Marks whether the message handler has been initialized. -static bool message_initialized_p = false; -static bool g_started = false; +static bool g_started = false; static EventNotify g_force_req_notify; static int g_rec_raw_stat_sync_interval_ms = REC_RAW_STAT_SYNC_INTERVAL_MS; static int g_rec_config_update_interval_ms = REC_CONFIG_UPDATE_INTERVAL_MS; @@ -44,27 +43,6 @@ static Event *raw_stat_sync_cont_event; static Event *config_update_cont_event; static Event *sync_cont_event; -//------------------------------------------------------------------------- -// i_am_the_record_owner, only used for librecords_p.a -//------------------------------------------------------------------------- -bool -i_am_the_record_owner(RecT rec_type) -{ - switch (rec_type) { - case RECT_CONFIG: - case RECT_PROCESS: - case RECT_NODE: - case RECT_LOCAL: - case RECT_PLUGIN: - return true; - default: - ink_assert(!"Unexpected RecT type"); - return false; - } - - return false; -} - //------------------------------------------------------------------------- // Simple setters for the intervals to decouple this from the proxy //------------------------------------------------------------------------- @@ -160,6 +138,8 @@ struct sync_cont : public Continuation { } }; +void SetupRecRawStatBlockAllocator(); + //------------------------------------------------------------------------- // RecProcessInit //------------------------------------------------------------------------- @@ -168,6 +148,8 @@ RecProcessInit(Diags *_diags) { static bool initialized_p = false; + SetupRecRawStatBlockAllocator(); + if (initialized_p) { return REC_ERR_OKAY; } @@ -181,29 +163,6 @@ RecProcessInit(Diags *_diags) return REC_ERR_OKAY; } -void -RecMessageInit() -{ - message_initialized_p = true; -} -//------------------------------------------------------------------------- -// RecProcessInitMessage -//------------------------------------------------------------------------- -int -RecProcessInitMessage() -{ - static bool initialized_p = false; - - if (initialized_p) { - return REC_ERR_OKAY; - } - - RecMessageInit(); - initialized_p = true; - - return REC_ERR_OKAY; -} - //------------------------------------------------------------------------- // RecProcessStart //------------------------------------------------------------------------- diff --git a/iocore/eventsystem/RecProcess.h b/iocore/eventsystem/RecProcess.h new file mode 100644 index 00000000000..f34d6f9621c --- /dev/null +++ b/iocore/eventsystem/RecProcess.h @@ -0,0 +1,40 @@ +/** @file + +Public RecProcess declarations + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#pragma once + +#include "records/I_RecDefs.h" +#include "tscore/Diags.h" + +//------------------------------------------------------------------------- +// Initialization/Starting +//------------------------------------------------------------------------- +int RecProcessInit(Diags *diags = nullptr); +int RecProcessStart(); + +//------------------------------------------------------------------------- +// Setters for manipulating internal sleep intervals +//------------------------------------------------------------------------- +void RecProcess_set_raw_stat_sync_interval_ms(int ms); +void RecProcess_set_config_update_interval_ms(int ms); +void RecProcess_set_remote_sync_interval_ms(int ms); diff --git a/iocore/eventsystem/RecRawStatsImpl.cc b/iocore/eventsystem/RecRawStatsImpl.cc new file mode 100644 index 00000000000..cd66e819c5c --- /dev/null +++ b/iocore/eventsystem/RecRawStatsImpl.cc @@ -0,0 +1,254 @@ +/** @file + +Record statistics support (EThread implementation). + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "records/I_RecDefs.h" +#include "records/P_RecCore.h" +#include "records/P_RecProcess.h" +#include + +//------------------------------------------------------------------------- +// raw_stat_get_total +//------------------------------------------------------------------------- + +struct RecRawStatBlockOpsImpl : RecRawStatBlockOps { + int raw_stat_clear(RecRawStatBlock *rsb, int id) override; + int raw_stat_clear_count(RecRawStatBlock *rsb, int id) override; + int raw_stat_clear_sum(RecRawStatBlock *rsb, int id) override; + int raw_stat_get_total(RecRawStatBlock *rsb, int id, RecRawStat *total) override; + int raw_stat_sync_to_global(RecRawStatBlock *rsb, int id) override; +}; + +RecRawStatBlock * +RecAllocateRawStatBlockImpl(int num_stats) +{ + static RecRawStatBlockOpsImpl ops; + + off_t ethr_stat_offset; + RecRawStatBlock *rsb; + + // allocate thread-local raw-stat memory + if ((ethr_stat_offset = eventProcessor.allocate(num_stats * sizeof(RecRawStat))) == -1) { + return nullptr; + } + + // create the raw-stat-block structure + rsb = static_cast(ats_malloc(sizeof(RecRawStatBlock))); + memset(rsb, 0, sizeof(RecRawStatBlock)); + + rsb->global = static_cast(ats_malloc(num_stats * sizeof(RecRawStat *))); + memset(rsb->global, 0, num_stats * sizeof(RecRawStat *)); + + rsb->num_stats = 0; + rsb->max_stats = num_stats; + rsb->ethr_stat_offset = ethr_stat_offset; + + ink_mutex_init(&(rsb->mutex)); + + rsb->ops = &ops; + return rsb; +} + +void +SetupRecRawStatBlockAllocator() +{ + SetRecAllocateRawStatBlockAllocator(RecAllocateRawStatBlockImpl); +} + +// Commonly used access to a raw stat, avoid typos. +static RecRawStat * +thread_stat(EThread *et, RecRawStatBlock *rsb, int id) +{ + return (reinterpret_cast(reinterpret_cast(et) + rsb->ethr_stat_offset)) + id; +} + +int +RecRawStatBlockOpsImpl::raw_stat_get_total(RecRawStatBlock *rsb, int id, RecRawStat *total) +{ + total->sum = 0; + total->count = 0; + + // get global values + total->sum = rsb->global[id]->sum; + total->count = rsb->global[id]->count; + + // get thread local values + for (EThread *et : eventProcessor.active_ethreads()) { + RecRawStat *tlp = thread_stat(et, rsb, id); + total->sum += tlp->sum; + total->count += tlp->count; + } + + for (EThread *et : eventProcessor.active_dthreads()) { + RecRawStat *tlp = thread_stat(et, rsb, id); + total->sum += tlp->sum; + total->count += tlp->count; + } + + if (total->sum < 0) { // Assure that we stay positive + total->sum = 0; + } + + return REC_ERR_OKAY; +} + +//------------------------------------------------------------------------- +// raw_stat_sync_to_global +//------------------------------------------------------------------------- +int +RecRawStatBlockOpsImpl::raw_stat_sync_to_global(RecRawStatBlock *rsb, int id) +{ + RecRawStat total; + + total.sum = 0; + total.count = 0; + + // sum the thread local values + for (EThread *et : eventProcessor.active_ethreads()) { + RecRawStat *tlp = thread_stat(et, rsb, id); + total.sum += tlp->sum; + total.count += tlp->count; + } + + for (EThread *et : eventProcessor.active_dthreads()) { + RecRawStat *tlp = thread_stat(et, rsb, id); + total.sum += tlp->sum; + total.count += tlp->count; + } + + if (total.sum < 0) { // Assure that we stay positive + total.sum = 0; + } + + // lock so the setting of the globals and last values are atomic + { + ink_scoped_mutex_lock lock(rsb->mutex); + + // get the delta from the last sync + RecRawStat delta; + delta.sum = total.sum - rsb->global[id]->last_sum; + delta.count = total.count - rsb->global[id]->last_count; + + // increment the global values by the delta + ink_atomic_increment(&(rsb->global[id]->sum), delta.sum); + ink_atomic_increment(&(rsb->global[id]->count), delta.count); + + // set the new totals as the last values seen + ink_atomic_swap(&(rsb->global[id]->last_sum), total.sum); + ink_atomic_swap(&(rsb->global[id]->last_count), total.count); + } + + return REC_ERR_OKAY; +} + +//------------------------------------------------------------------------- +// raw_stat_clear +//------------------------------------------------------------------------- +int +RecRawStatBlockOpsImpl::raw_stat_clear(RecRawStatBlock *rsb, int id) +{ + Debug("stats", "raw_stat_clear(): rsb pointer:%p id:%d", rsb, id); + + // the globals need to be reset too + // lock so the setting of the globals and last values are atomic + { + ink_scoped_mutex_lock lock(rsb->mutex); + ink_atomic_swap(&(rsb->global[id]->sum), static_cast(0)); + ink_atomic_swap(&(rsb->global[id]->last_sum), static_cast(0)); + ink_atomic_swap(&(rsb->global[id]->count), static_cast(0)); + ink_atomic_swap(&(rsb->global[id]->last_count), static_cast(0)); + } + // reset the local stats + for (EThread *et : eventProcessor.active_ethreads()) { + RecRawStat *tlp = thread_stat(et, rsb, id); + ink_atomic_swap(&(tlp->sum), static_cast(0)); + ink_atomic_swap(&(tlp->count), static_cast(0)); + } + + for (EThread *et : eventProcessor.active_dthreads()) { + RecRawStat *tlp = thread_stat(et, rsb, id); + ink_atomic_swap(&(tlp->sum), static_cast(0)); + ink_atomic_swap(&(tlp->count), static_cast(0)); + } + + return REC_ERR_OKAY; +} + +//------------------------------------------------------------------------- +// raw_stat_clear_sum +//------------------------------------------------------------------------- +int +RecRawStatBlockOpsImpl::raw_stat_clear_sum(RecRawStatBlock *rsb, int id) +{ + Debug("stats", "raw_stat_clear_sum(): rsb pointer:%p id:%d", rsb, id); + + // the globals need to be reset too + // lock so the setting of the globals and last values are atomic + { + ink_scoped_mutex_lock lock(rsb->mutex); + ink_atomic_swap(&(rsb->global[id]->sum), static_cast(0)); + ink_atomic_swap(&(rsb->global[id]->last_sum), static_cast(0)); + } + + // reset the local stats + for (EThread *et : eventProcessor.active_ethreads()) { + RecRawStat *tlp = thread_stat(et, rsb, id); + ink_atomic_swap(&(tlp->sum), static_cast(0)); + } + + for (EThread *et : eventProcessor.active_dthreads()) { + RecRawStat *tlp = thread_stat(et, rsb, id); + ink_atomic_swap(&(tlp->sum), static_cast(0)); + } + + return REC_ERR_OKAY; +} + +//------------------------------------------------------------------------- +// raw_stat_clear_count +//------------------------------------------------------------------------- +int +RecRawStatBlockOpsImpl::raw_stat_clear_count(RecRawStatBlock *rsb, int id) +{ + Debug("stats", "raw_stat_clear_count(): rsb pointer:%p id:%d", rsb, id); + + // the globals need to be reset too + // lock so the setting of the globals and last values are atomic + { + ink_scoped_mutex_lock lock(rsb->mutex); + ink_atomic_swap(&(rsb->global[id]->count), static_cast(0)); + ink_atomic_swap(&(rsb->global[id]->last_count), static_cast(0)); + } + + // reset the local stats + for (EThread *et : eventProcessor.active_ethreads()) { + RecRawStat *tlp = thread_stat(et, rsb, id); + ink_atomic_swap(&(tlp->count), static_cast(0)); + } + + for (EThread *et : eventProcessor.active_dthreads()) { + RecRawStat *tlp = thread_stat(et, rsb, id); + ink_atomic_swap(&(tlp->count), static_cast(0)); + } + + return REC_ERR_OKAY; +} diff --git a/mgmt/rpc/Makefile.am b/mgmt/rpc/Makefile.am index 415ad089c12..04c4145d609 100644 --- a/mgmt/rpc/Makefile.am +++ b/mgmt/rpc/Makefile.am @@ -66,11 +66,9 @@ test_jsonrpc_SOURCES = \ test_jsonrpc_LDADD = \ libjsonrpc_protocol.la \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ - $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ - $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/tscore/libtscore.la \ $(top_builddir)/mgmt/utils/libutils_p.la \ @YAMLCPP_LIBS@ @HWLOC_LIBS@ @@ -109,11 +107,9 @@ test_jsonrpcserver_SOURCES = \ test_jsonrpcserver_LDADD = \ libjsonrpc_protocol.la \ libjsonrpc_server.la \ - $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ - $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/src/tscore/libtscore.la \ $(top_builddir)/mgmt/utils/libutils_p.la \ diff --git a/proxy/logging/LogStandalone.cc b/proxy/logging/LogStandalone.cc index 58e80d7ec4e..9565afb0260 100644 --- a/proxy/logging/LogStandalone.cc +++ b/proxy/logging/LogStandalone.cc @@ -40,6 +40,7 @@ // Needs LibRecordsConfigInit() #include "records/I_RecordsConfig.h" #include "I_Machine.h" +#include "RecProcess.h" #define LOG_FILENAME_SIZE 255 @@ -103,8 +104,6 @@ initialize_process_manager() RecProcessInit(diags()); LibRecordsConfigInit(); - RecProcessInitMessage(); - // // Define version info records // diff --git a/src/records/CMakeLists.txt b/src/records/CMakeLists.txt index 20897ed6ada..c3a9953fb32 100644 --- a/src/records/CMakeLists.txt +++ b/src/records/CMakeLists.txt @@ -15,8 +15,7 @@ # ####################### - -add_library(records_lm STATIC +add_library(records_p SHARED P_RecCore.cc RecConfigParse.cc RecCore.cc @@ -25,36 +24,13 @@ add_library(records_lm STATIC RecHttp.cc RecMessage.cc RecMutex.cc - RecRawStats.cc RecUtils.cc RecYAMLDecoder.cc RecordsConfig.cc RecordsConfigUtils.cc -) -target_include_directories(records_lm PRIVATE - ${CMAKE_SOURCE_DIR}/mgmt - ${CMAKE_SOURCE_DIR}/mgmt/api/include - ${CMAKE_SOURCE_DIR}/mgmt/utils - ${CMAKE_SOURCE_DIR}/iocore/eventsystem - ${CMAKE_SOURCE_DIR}/iocore/utils -) - -add_library(records_p STATIC - P_RecCore.cc - RecConfigParse.cc - RecCore.cc - RecDebug.cc - RecFile.cc - RecHttp.cc - RecMessage.cc - RecMutex.cc RecRawStats.cc - RecUtils.cc - RecProcess.cc - RecYAMLDecoder.cc - RecordsConfig.cc - RecordsConfigUtils.cc ) + target_include_directories(records_p PRIVATE ${CMAKE_SOURCE_DIR}/mgmt ${CMAKE_SOURCE_DIR}/mgmt/api/include @@ -62,3 +38,4 @@ target_include_directories(records_p PRIVATE ${CMAKE_SOURCE_DIR}/iocore/eventsystem ${CMAKE_SOURCE_DIR}/iocore/utils ) +target_link_libraries(records_p tscore libswoc) \ No newline at end of file diff --git a/src/records/Makefile.am b/src/records/Makefile.am index 2bdb5e0527d..15c64dce4fb 100644 --- a/src/records/Makefile.am +++ b/src/records/Makefile.am @@ -56,11 +56,7 @@ librecords_COMMON = \ RecordsConfig.cc \ RecordsConfigUtils.cc -librecords_p_a_SOURCES = \ - $(librecords_COMMON) \ - I_RecProcess.h \ - P_RecProcess.h \ - RecProcess.cc +librecords_p_a_SOURCES = $(librecords_COMMON) TESTS = $(check_PROGRAMS) diff --git a/src/records/RecCore.cc b/src/records/RecCore.cc index 7f9212ed883..20daab92f69 100644 --- a/src/records/RecCore.cc +++ b/src/records/RecCore.cc @@ -1294,3 +1294,24 @@ RecConfigWarnIfUnregistered() }, nullptr); } + +//------------------------------------------------------------------------- +// i_am_the_record_owner, only used for librecords_p.a +//------------------------------------------------------------------------- +bool +i_am_the_record_owner(RecT rec_type) +{ + switch (rec_type) { + case RECT_CONFIG: + case RECT_PROCESS: + case RECT_NODE: + case RECT_LOCAL: + case RECT_PLUGIN: + return true; + default: + ink_assert(!"Unexpected RecT type"); + return false; + } + + return false; +} diff --git a/src/records/RecRawStats.cc b/src/records/RecRawStats.cc index 1760a0a746b..deaf8398250 100644 --- a/src/records/RecRawStats.cc +++ b/src/records/RecRawStats.cc @@ -1,6 +1,6 @@ /** @file - Record statistics support. +Record statistics support @section license License @@ -26,218 +26,19 @@ #include //------------------------------------------------------------------------- -// raw_stat_get_total -//------------------------------------------------------------------------- - -namespace -{ -// Commonly used access to a raw stat, avoid typos. -inline RecRawStat * -thread_stat(EThread *et, RecRawStatBlock *rsb, int id) -{ - return (reinterpret_cast(reinterpret_cast(et) + rsb->ethr_stat_offset)) + id; -} -} // namespace - -static int -raw_stat_get_total(RecRawStatBlock *rsb, int id, RecRawStat *total) -{ - total->sum = 0; - total->count = 0; - - // get global values - total->sum = rsb->global[id]->sum; - total->count = rsb->global[id]->count; - - // get thread local values - for (EThread *et : eventProcessor.active_ethreads()) { - RecRawStat *tlp = thread_stat(et, rsb, id); - total->sum += tlp->sum; - total->count += tlp->count; - } - - for (EThread *et : eventProcessor.active_dthreads()) { - RecRawStat *tlp = thread_stat(et, rsb, id); - total->sum += tlp->sum; - total->count += tlp->count; - } - - if (total->sum < 0) { // Assure that we stay positive - total->sum = 0; - } - - return REC_ERR_OKAY; -} - -//------------------------------------------------------------------------- -// raw_stat_sync_to_global -//------------------------------------------------------------------------- -static int -raw_stat_sync_to_global(RecRawStatBlock *rsb, int id) -{ - RecRawStat total; - - total.sum = 0; - total.count = 0; - - // sum the thread local values - for (EThread *et : eventProcessor.active_ethreads()) { - RecRawStat *tlp = thread_stat(et, rsb, id); - total.sum += tlp->sum; - total.count += tlp->count; - } - - for (EThread *et : eventProcessor.active_dthreads()) { - RecRawStat *tlp = thread_stat(et, rsb, id); - total.sum += tlp->sum; - total.count += tlp->count; - } - - if (total.sum < 0) { // Assure that we stay positive - total.sum = 0; - } - - // lock so the setting of the globals and last values are atomic - { - ink_scoped_mutex_lock lock(rsb->mutex); - - // get the delta from the last sync - RecRawStat delta; - delta.sum = total.sum - rsb->global[id]->last_sum; - delta.count = total.count - rsb->global[id]->last_count; - - // increment the global values by the delta - ink_atomic_increment(&(rsb->global[id]->sum), delta.sum); - ink_atomic_increment(&(rsb->global[id]->count), delta.count); - - // set the new totals as the last values seen - ink_atomic_swap(&(rsb->global[id]->last_sum), total.sum); - ink_atomic_swap(&(rsb->global[id]->last_count), total.count); - } - - return REC_ERR_OKAY; -} - -//------------------------------------------------------------------------- -// raw_stat_clear -//------------------------------------------------------------------------- -static int -raw_stat_clear(RecRawStatBlock *rsb, int id) -{ - Debug("stats", "raw_stat_clear(): rsb pointer:%p id:%d", rsb, id); - - // the globals need to be reset too - // lock so the setting of the globals and last values are atomic - { - ink_scoped_mutex_lock lock(rsb->mutex); - ink_atomic_swap(&(rsb->global[id]->sum), static_cast(0)); - ink_atomic_swap(&(rsb->global[id]->last_sum), static_cast(0)); - ink_atomic_swap(&(rsb->global[id]->count), static_cast(0)); - ink_atomic_swap(&(rsb->global[id]->last_count), static_cast(0)); - } - // reset the local stats - for (EThread *et : eventProcessor.active_ethreads()) { - RecRawStat *tlp = thread_stat(et, rsb, id); - ink_atomic_swap(&(tlp->sum), static_cast(0)); - ink_atomic_swap(&(tlp->count), static_cast(0)); - } - - for (EThread *et : eventProcessor.active_dthreads()) { - RecRawStat *tlp = thread_stat(et, rsb, id); - ink_atomic_swap(&(tlp->sum), static_cast(0)); - ink_atomic_swap(&(tlp->count), static_cast(0)); - } - - return REC_ERR_OKAY; -} - -//------------------------------------------------------------------------- -// raw_stat_clear_sum -//------------------------------------------------------------------------- -static int -raw_stat_clear_sum(RecRawStatBlock *rsb, int id) -{ - Debug("stats", "raw_stat_clear_sum(): rsb pointer:%p id:%d", rsb, id); - - // the globals need to be reset too - // lock so the setting of the globals and last values are atomic - { - ink_scoped_mutex_lock lock(rsb->mutex); - ink_atomic_swap(&(rsb->global[id]->sum), static_cast(0)); - ink_atomic_swap(&(rsb->global[id]->last_sum), static_cast(0)); - } - - // reset the local stats - for (EThread *et : eventProcessor.active_ethreads()) { - RecRawStat *tlp = thread_stat(et, rsb, id); - ink_atomic_swap(&(tlp->sum), static_cast(0)); - } - - for (EThread *et : eventProcessor.active_dthreads()) { - RecRawStat *tlp = thread_stat(et, rsb, id); - ink_atomic_swap(&(tlp->sum), static_cast(0)); - } - - return REC_ERR_OKAY; -} - -//------------------------------------------------------------------------- -// raw_stat_clear_count +// RecAllocateRawStatBlock //------------------------------------------------------------------------- -static int -raw_stat_clear_count(RecRawStatBlock *rsb, int id) +static RecRawStatBlockAllocator raw_stat_block_allocator = nullptr; +void +SetRecAllocateRawStatBlockAllocator(RecRawStatBlockAllocator f) { - Debug("stats", "raw_stat_clear_count(): rsb pointer:%p id:%d", rsb, id); - - // the globals need to be reset too - // lock so the setting of the globals and last values are atomic - { - ink_scoped_mutex_lock lock(rsb->mutex); - ink_atomic_swap(&(rsb->global[id]->count), static_cast(0)); - ink_atomic_swap(&(rsb->global[id]->last_count), static_cast(0)); - } - - // reset the local stats - for (EThread *et : eventProcessor.active_ethreads()) { - RecRawStat *tlp = thread_stat(et, rsb, id); - ink_atomic_swap(&(tlp->count), static_cast(0)); - } - - for (EThread *et : eventProcessor.active_dthreads()) { - RecRawStat *tlp = thread_stat(et, rsb, id); - ink_atomic_swap(&(tlp->count), static_cast(0)); - } - - return REC_ERR_OKAY; + raw_stat_block_allocator = f; } -//------------------------------------------------------------------------- -// RecAllocateRawStatBlock -//------------------------------------------------------------------------- RecRawStatBlock * RecAllocateRawStatBlock(int num_stats) { - off_t ethr_stat_offset; - RecRawStatBlock *rsb; - - // allocate thread-local raw-stat memory - if ((ethr_stat_offset = eventProcessor.allocate(num_stats * sizeof(RecRawStat))) == -1) { - return nullptr; - } - - // create the raw-stat-block structure - rsb = static_cast(ats_malloc(sizeof(RecRawStatBlock))); - memset(rsb, 0, sizeof(RecRawStatBlock)); - - rsb->global = static_cast(ats_malloc(num_stats * sizeof(RecRawStat *))); - memset(rsb->global, 0, num_stats * sizeof(RecRawStat *)); - - rsb->num_stats = 0; - rsb->max_stats = num_stats; - rsb->ethr_stat_offset = ethr_stat_offset; - - ink_mutex_init(&(rsb->mutex)); - return rsb; + return raw_stat_block_allocator(num_stats); } //------------------------------------------------------------------------- @@ -295,7 +96,7 @@ RecRawStatSyncSum(const char *name, RecDataT data_type, RecData *data, RecRawSta RecRawStat total; Debug("stats", "raw sync:sum for %s", name); - raw_stat_sync_to_global(rsb, id); + rsb->ops->raw_stat_sync_to_global(rsb, id); total.sum = rsb->global[id]->sum; total.count = rsb->global[id]->count; RecDataSetFromInt64(data_type, data, total.sum); @@ -309,7 +110,7 @@ RecRawStatSyncCount(const char *name, RecDataT data_type, RecData *data, RecRawS RecRawStat total; Debug("stats", "raw sync:count for %s", name); - raw_stat_sync_to_global(rsb, id); + rsb->ops->raw_stat_sync_to_global(rsb, id); total.sum = rsb->global[id]->sum; total.count = rsb->global[id]->count; RecDataSetFromInt64(data_type, data, total.count); @@ -324,7 +125,7 @@ RecRawStatSyncAvg(const char *name, RecDataT data_type, RecData *data, RecRawSta RecFloat avg = 0.0f; Debug("stats", "raw sync:avg for %s", name); - raw_stat_sync_to_global(rsb, id); + rsb->ops->raw_stat_sync_to_global(rsb, id); total.sum = rsb->global[id]->sum; total.count = rsb->global[id]->count; if (total.count != 0) { @@ -341,7 +142,7 @@ RecRawStatSyncHrTimeAvg(const char *name, RecDataT data_type, RecData *data, Rec RecFloat r; Debug("stats", "raw sync:hr-timeavg for %s", name); - raw_stat_sync_to_global(rsb, id); + rsb->ops->raw_stat_sync_to_global(rsb, id); total.sum = rsb->global[id]->sum; total.count = rsb->global[id]->count; @@ -363,7 +164,7 @@ RecRawStatSyncIntMsecsToFloatSeconds(const char *name, RecDataT data_type, RecDa RecFloat r; Debug("stats", "raw sync:seconds for %s", name); - raw_stat_sync_to_global(rsb, id); + rsb->ops->raw_stat_sync_to_global(rsb, id); total.sum = rsb->global[id]->sum; total.count = rsb->global[id]->count; @@ -383,7 +184,7 @@ RecRawStatSyncIntMsecsToFloatSeconds(const char *name, RecDataT data_type, RecDa int RecSetRawStatSum(RecRawStatBlock *rsb, int id, int64_t data) { - raw_stat_clear_sum(rsb, id); + rsb->ops->raw_stat_clear_sum(rsb, id); ink_atomic_swap(&(rsb->global[id]->sum), data); return REC_ERR_OKAY; } @@ -391,7 +192,7 @@ RecSetRawStatSum(RecRawStatBlock *rsb, int id, int64_t data) int RecSetRawStatCount(RecRawStatBlock *rsb, int id, int64_t data) { - raw_stat_clear_count(rsb, id); + rsb->ops->raw_stat_clear_count(rsb, id); ink_atomic_swap(&(rsb->global[id]->count), data); return REC_ERR_OKAY; } @@ -405,7 +206,7 @@ RecGetRawStatSum(RecRawStatBlock *rsb, int id, int64_t *data) { RecRawStat total; - raw_stat_get_total(rsb, id, &total); + rsb->ops->raw_stat_get_total(rsb, id, &total); *data = total.sum; return REC_ERR_OKAY; } @@ -415,7 +216,7 @@ RecGetRawStatCount(RecRawStatBlock *rsb, int id, int64_t *data) { RecRawStat total; - raw_stat_get_total(rsb, id, &total); + rsb->ops->raw_stat_get_total(rsb, id, &total); *data = total.count; return REC_ERR_OKAY; } @@ -555,7 +356,7 @@ RecExecRawStatSyncCbs() if (REC_TYPE_IS_STAT(r->rec_type)) { if (r->stat_meta.sync_cb) { if (r->version && r->version != r->stat_meta.sync_rsb->global[r->stat_meta.sync_id]->version) { - raw_stat_clear(r->stat_meta.sync_rsb, r->stat_meta.sync_id); + r->stat_meta.sync_rsb->ops->raw_stat_clear(r->stat_meta.sync_rsb, r->stat_meta.sync_id); r->stat_meta.sync_rsb->global[r->stat_meta.sync_id]->version = r->version; } else { (*(r->stat_meta.sync_cb))(r->name, r->data_type, &(r->data), r->stat_meta.sync_rsb, r->stat_meta.sync_id); diff --git a/src/traffic_crashlog/Makefile.inc b/src/traffic_crashlog/Makefile.inc index 1d88fe10ca7..ceee194fc63 100644 --- a/src/traffic_crashlog/Makefile.inc +++ b/src/traffic_crashlog/Makefile.inc @@ -38,8 +38,8 @@ traffic_crashlog_traffic_crashlog_SOURCES = \ traffic_crashlog/traffic_crashlog.h traffic_crashlog_traffic_crashlog_LDADD = \ - $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ + $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/iocore/net/libinknet.a \ $(top_builddir)/src/tscore/libtscore.la \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ diff --git a/src/traffic_crashlog/traffic_crashlog.cc b/src/traffic_crashlog/traffic_crashlog.cc index 47b67dd5902..f7bee21a624 100644 --- a/src/traffic_crashlog/traffic_crashlog.cc +++ b/src/traffic_crashlog/traffic_crashlog.cc @@ -31,6 +31,7 @@ #include "records/I_RecordsConfig.h" #include "tscore/BaseLogFile.h" #include "tscore/runroot.h" +#include "RecProcess.h" static int syslog_mode = false; static int debug_mode = false; diff --git a/src/traffic_layout/Makefile.inc b/src/traffic_layout/Makefile.inc index ccc10d033a8..0bdde7f6a06 100644 --- a/src/traffic_layout/Makefile.inc +++ b/src/traffic_layout/Makefile.inc @@ -42,8 +42,8 @@ traffic_layout_traffic_layout_SOURCES = \ traffic_layout/info.h traffic_layout_traffic_layout_LDADD = \ - $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ + $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.la \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ @SWOC_LIBS@ @HWLOC_LIBS@ @YAMLCPP_LIBS@ @LIBLZMA@ diff --git a/src/traffic_layout/engine.cc b/src/traffic_layout/engine.cc index 7ba0e120efb..c6a2eba40a3 100644 --- a/src/traffic_layout/engine.cc +++ b/src/traffic_layout/engine.cc @@ -41,6 +41,8 @@ #include #include +#include "RecProcess.h" + static const long MAX_LOGIN = ink_login_name_max(); static constexpr int MAX_GROUP_NUM = 32; diff --git a/src/traffic_layout/info.cc b/src/traffic_layout/info.cc index e9ed63a1392..1de8cfe40f0 100644 --- a/src/traffic_layout/info.cc +++ b/src/traffic_layout/info.cc @@ -29,6 +29,7 @@ #include "records/I_RecProcess.h" #include "records/I_RecordsConfig.h" #include "info.h" +#include "RecProcess.h" #if TS_USE_HWLOC #include diff --git a/src/traffic_quic/traffic_quic.cc b/src/traffic_quic/traffic_quic.cc index f61db271e90..5e1212b340c 100644 --- a/src/traffic_quic/traffic_quic.cc +++ b/src/traffic_quic/traffic_quic.cc @@ -39,6 +39,8 @@ #include "P_SSLUtils.h" #include "P_SSLConfig.h" +#include "RecProcess.h" + #define THREADS 1 constexpr size_t stacksize = 1048576; diff --git a/src/traffic_server/CMakeLists.txt b/src/traffic_server/CMakeLists.txt index 97955731cbf..e0ed574ad84 100644 --- a/src/traffic_server/CMakeLists.txt +++ b/src/traffic_server/CMakeLists.txt @@ -26,7 +26,7 @@ add_executable(traffic_server traffic_server.cc RpcAdminPubHandlers.cc ${CMAKE_SOURCE_DIR}/src/shared/overridable_txn_vars.cc -) + RecProcess.h) target_include_directories(traffic_server PRIVATE ${IOCORE_INCLUDE_DIRS} ${PROXY_INCLUDE_DIRS} diff --git a/src/traffic_server/traffic_server.cc b/src/traffic_server/traffic_server.cc index 46acf960cbb..c728a67bae0 100644 --- a/src/traffic_server/traffic_server.cc +++ b/src/traffic_server/traffic_server.cc @@ -77,7 +77,7 @@ extern "C" int plock(int); #include "tscore/I_Layout.h" #include "I_Machine.h" #include "records/I_RecordsConfig.h" -#include "records/I_RecProcess.h" +#include "RecProcess.h" #include "Transform.h" #include "ConfigProcessor.h" #include "HttpProxyServerMain.h" @@ -672,7 +672,6 @@ initialize_process_manager() RecProcessInit(diags()); LibRecordsConfigInit(); - RecProcessInitMessage(); check_config_directories(); // diff --git a/src/tscore/CMakeLists.txt b/src/tscore/CMakeLists.txt index 8ab2f393f6b..8a288ed1469 100644 --- a/src/tscore/CMakeLists.txt +++ b/src/tscore/CMakeLists.txt @@ -109,7 +109,7 @@ target_include_directories(tscore PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${YAML_INCLUDE_DIRS} ) -target_link_libraries(tscore ${PCRE_LIBRARIES} ${OPENSSL_LIBRARIES} yaml-cpp::yaml-cpp tscpputil resolv) +target_link_libraries(tscore ${PCRE_LIBRARIES} ${OPENSSL_LIBRARIES} yaml-cpp::yaml-cpp tscpputil resolv libswoc) add_executable(test_tscore unit_tests/test_AcidPtr.cc