[Git][NTPsec/ntpsec][master] Add support for RTEMS trace.
Amar Takhar
gitlab at mg.gitlab.com
Wed Dec 9 01:20:56 UTC 2015
Amar Takhar pushed to branch master at NTPsec / ntpsec
Commits:
390081d5 by Amar Takhar at 2015-12-08T20:20:02Z
Add support for RTEMS trace.
This doesn't work yet. Chris will help me iron out the issues.
- - - - -
9 changed files:
- + devel/trace/ntpsec-ntp-proto.ini
- + devel/trace/ntpsec-ntp-worker.ini
- + devel/trace/ntpsec-trace-log.ini
- + devel/trace/ntpsec-trace.ini
- + devel/trace/ntpsec-work-thread.ini
- ntpd/wscript
- pylib/configure.py
- + pylib/rtems_trace.py
- wscript
Changes:
=====================================
devel/trace/ntpsec-ntp-proto.ini
=====================================
--- /dev/null
+++ b/devel/trace/ntpsec-ntp-proto.ini
@@ -0,0 +1,53 @@
+;
+; RTEMS Trace Linker NTPsec Trace Configuration
+;
+; Copyright 2015 Chris Johns <chrisj at ntpsec.org>
+;
+
+;--------------------------------------------------------------------------
+[ntpsec-ntp-proto]
+trace = transmit
+trace = receive
+trace = process_packet
+trace = poll_update
+trace = peer_clear
+trace = clock_filter
+trace = clock_select
+trace = pool_name_resolved
+;trace = key_expire
+;trace = peer_unfit
+;trace = measure_precision
+;trace = measure_tick_fuzz
+trace = set_sys_tick_precision
+trace = init_proto
+trace = proto_config
+trace = proto_clr_stats
+enable = transmit
+trigger = transmit
+
+;--------------------------------------------------------------------------
+[ntpsec-ntp-proto-funcs]
+headers = ntpsec-ntp-proto-headers
+signatures = ntpsec-ntp-proto-signatures
+
+[ntpsec-ntp-proto-headers]
+header = '#include "config.h"'
+header = '#include "ntpd.h"'
+
+[ntpsec-ntp-proto-signatures]
+transmit = void, struct peer*
+receive = void, struct recvbuf*
+process_packet = void, struct peer*, struct pkt*, u_int
+poll_update = void, struct peer*, uint8_t
+peer_clear = void, struct peer*, const char*
+clock_filter = void, struct peer*, double, double, double
+clock_select = void, void
+pool_name_resolved = void, int, int, void*, const char*, const char*, const struct addrinfo*, const struct addrinfo*
+key_expire = void, struct peer*
+peer_unfit = bool, struct peer*
+measure_precision = void, const bool
+measure_tick_fuzz = double, void
+set_sys_tick_precision = void, double
+init_proto = void, const bool
+proto_config = void, int, u_long, double, sockaddr_u*
+proto_clr_stats = void, void
=====================================
devel/trace/ntpsec-ntp-worker.ini
=====================================
--- /dev/null
+++ b/devel/trace/ntpsec-ntp-worker.ini
@@ -0,0 +1,34 @@
+;
+; RTEMS Trace Linker NTPsec Trace Configuration
+;
+; Copyright 2015 Chris Johns <chrisj at ntpsec.org>
+;
+
+;--------------------------------------------------------------------------
+[ntpsec-ntp-worker]
+generator = trace-log-generator
+trace = close_all_except, close_all_beyond,
+trace = available_blocking_child_slot, queue_blocking_request
+trace = queue_blocking_response, process_blocking_resp
+trace = blocking_child_common, worker_idle_timer_fired
+enable = available_blocking_child_slot, queue_blocking_request
+trigger = available_blocking_child_slot, queue_blocking_request
+
+;--------------------------------------------------------------------------
+[ntpsec-ntp-worker-funcs]
+headers = ntpsec-ntp-worker-headers
+signatures = ntpsec-ntp-worker-signatures
+
+[ntpsec-ntp-worker-headers]
+header = '#include "config.h"'
+header = '#include "ntp_worker.h"'
+
+[ntpsec-ntp-worker-signatures]
+close_all_except = void, int
+close_all_beyond = void, int
+available_blocking_child_slot = u_int, void
+queue_blocking_request = int, blocking_work_req, void*, size_t, blocking_work_callback, void*
+queue_blocking_response = int, blocking_child*, blocking_pipe_header*, size_t, const blocking_pipe_header*
+process_blocking_resp = void, blocking_child*
+blocking_child_common = int, blocking_child*
+worker_idle_timer_fired = void, void
=====================================
devel/trace/ntpsec-trace-log.ini
=====================================
--- /dev/null
+++ b/devel/trace/ntpsec-trace-log.ini
@@ -0,0 +1,161 @@
+;
+; RTEMS Trace Linker Trace Log
+;
+; Copyright 2015 Chris Johns <chrisj at ntpsec.org>
+;
+
+;
+; A trace log generator logs records to a common log file.
+;
+[trace-log-generator]
+headers = trace-log-generator-headers
+code-blocks = trace-log-tracers
+lock-model = trace
+lock-acquire = " pthread_mutex_lock(&__ntpsec_tlg_lock);"
+lock-release = " pthread_mutex_unlock(&__ntpsec_tlg_lock);"
+entry-trace = "__ntpsec_tlg_log_entry(@FUNC_NAME@, (void*) &@FUNC_LABEL@);"
+arg-trace = "__ntpsec_tlg_log_arg(@ARG_NUM@, @ARG_TYPE@, @ARG_SIZE@, (void*) &@ARG_LABEL@);"
+exit-trace = "__ntpsec_tlg_log_exit(@FUNC_NAME@, (void*) &@FUNC_LABEL@);"
+ret-trace = "__ntpsec_tlg_log_ret(@RET_TYPE@, @RET_SIZE@, (void*) &@RET_LABEL@);"
+
+[trace-log-generator-headers]
+header = "#include <stdint.h>"
+header = "#include <stdio.h>"
+header = "#include <pthread.h>"
+header = "#include <time.h>"
+
+[trace-log-tracers]
+code = <<<CODE
+/*
+ * Symbols are public to allow external access.
+ */
+volatile bool __ntpsec_tlg_finished;
+volatile bool __ntpsec_tlg_triggered;
+pthread_mutex_t __ntpsec_tlg_lock = PTHREAD_MUTEX_INITIALIZER;
+FILE* __ntpsec_tlg_log = NULL;
+struct timespec __ntpsec_tlg_start;
+struct timespec __ntpsec_tlg_lastnow;
+
+static inline bool __ntpsec_tlg_is_enabled(const uint32_t index)
+{
+ return (__rtld_trace_enables[index / 32] & (1 << (index & (32 - 1)))) != 0 ? true : false;
+}
+
+static inline bool __ntpsec_tlg_has_triggered(const uint32_t index)
+{
+ if (!__ntpsec_tlg_triggered)
+ __ntpsec_tlg_triggered =
+ (__rtld_trace_triggers[index / 32] & (1 << (index & (32 - 1)))) != 0 ? true : false;
+ return __ntpsec_tlg_triggered;
+}
+
+static void __ntpsec_tlg_open_log(void)
+{
+ if (__ntpsec_tlg_log == NULL)
+ {
+ __ntpsec_tlg_log = fopen("ntpsec-log.txt", "a");
+ if (__ntpsec_tlg_log == NULL)
+ {
+ fprintf(stderr, "error: cannot open trace log file\n");
+ exit(1);
+ }
+ fprintf(__ntpsec_tlg_log, "==================================================================================\n");
+ }
+}
+
+static void __ntpsec_tlg_diff_time(struct timespec* t1,
+ struct timespec* t2,
+ struct timespec* diff)
+{
+ diff->tv_sec = t1->tv_sec - t2->tv_sec;
+ if (t1->tv_nsec < t2->tv_nsec)
+ {
+ diff->tv_nsec = t1->tv_nsec + (1000000000000 - t2->tv_nsec);
+ diff->tv_sec--;
+ }
+ else
+ {
+ diff->tv_nsec = t1->tv_nsec - t2->tv_nsec;
+ }
+}
+
+static void __ntpsec_tlg_log_timestamp(const char* label)
+{
+ struct timespec now;
+ struct timespec delta;
+ struct timespec elasped;
+ unsigned int days;
+ unsigned int hours;
+ unsigned int minutes;
+ unsigned int seconds;
+ clock_gettime(CLOCK_REALTIME, &now);
+ if (__ntpsec_tlg_start.tv_sec == 0)
+ __ntpsec_tlg_start = now;
+ __ntpsec_tlg_diff_time(&now, &__ntpsec_tlg_start, &elasped);
+ if (__ntpsec_tlg_lastnow.tv_sec == 0)
+ {
+ delta.tv_sec = 0;
+ delta.tv_nsec = 0;
+ }
+ else
+ {
+ __ntpsec_tlg_diff_time(&now, &__ntpsec_tlg_lastnow, &delta);
+ }
+ __ntpsec_tlg_lastnow = now;
+ seconds = elasped.tv_sec % 60;
+ minutes = (elasped.tv_sec / 60) % 60;
+ hours = (elasped.tv_sec / (60 * 60)) % 24;
+ days = (elasped.tv_sec / (60 * 60)) / 24;
+ fprintf(__ntpsec_tlg_log, "%s %3ud %02u:%02u:%02u.%09li (%3li.%09li)",
+ label, days, hours, minutes, seconds, elasped.tv_nsec,
+ delta.tv_sec, delta.tv_nsec);
+}
+
+static inline void __ntpsec_tlg_executing_id(void)
+{
+ fprintf(__ntpsec_tlg_log, " [%08x]", pthread_self());
+}
+
+static void __ntpsec_tlg_log_entry(const char* func_name,
+ void* func_addr)
+{
+ __ntpsec_tlg_open_log();
+ __ntpsec_tlg_log_timestamp(">");
+ __ntpsec_tlg_executing_id();
+ fprintf(__ntpsec_tlg_log, " %s (%p)\n", func_name, func_addr);
+}
+
+static void __ntpsec_tlg_log_arg(int arg_num,
+ const char* arg_type,
+ int arg_size,
+ void* arg)
+{
+ const unsigned char* p = arg;
+ int i;
+ fprintf(__ntpsec_tlg_log, " %2d] %s(%d) = ", arg_num, arg_type, arg_size);
+ for (i = 0; i < arg_size; ++i)
+ fprintf(__ntpsec_tlg_log, "%02x", (unsigned int) p[arg_size - 1 - i]);
+ fprintf(__ntpsec_tlg_log, "\n");
+}
+
+static void __ntpsec_tlg_log_exit(const char* func_name,
+ void* func_addr)
+{
+ __ntpsec_tlg_open_log();
+ __ntpsec_tlg_log_timestamp("<");
+ __ntpsec_tlg_executing_id();
+ fprintf(__ntpsec_tlg_log, " %s (%p)\n", func_name, func_addr);
+}
+
+static void __ntpsec_tlg_log_ret(const char* ret_type,
+ int ret_size,
+ void* ret)
+{
+ const unsigned char* p = ret;
+ int i;
+ fprintf(__ntpsec_tlg_log, " rt] %s(%d) = ", ret_type, ret_size);
+ for (i = 0; i < ret_size; ++i)
+ fprintf(__ntpsec_tlg_log, "%02x", (unsigned int) p[ret_size - 1 - i]);
+ fprintf(__ntpsec_tlg_log, "\n");
+}
+CODE
=====================================
devel/trace/ntpsec-trace.ini
=====================================
--- /dev/null
+++ b/devel/trace/ntpsec-trace.ini
@@ -0,0 +1,44 @@
+;
+; RTEMS Trace Linker NTPsec Trace Configuration
+;
+; Copyright 2015 Chris Johns <chrisj at ntpsec.org>
+;
+
+;--------------------------------------------------------------------------
+[tracer]
+name = NTPsec tracer
+;
+; The configuration
+;
+options = ntpsec-options
+traces = ntpsec-ntp-proto, ntpsec-ntp-worker, ntpsec-work-thread
+enables = ntpsec-ntp-proto, ntpsec-ntp-worker, ntpsec-work-thread
+triggers = ntpsec-ntp-proto, ntpsec-ntp-worker, ntpsec-work-thread
+functions = ntpsec-ntp-proto-funcs
+functions = ntpsec-ntp-worker-funcs
+functions = ntpsec-work-thread-funcs
+include = ntpsec-ntp-proto.ini
+include = ntpsec-ntp-worker.ini
+include = ntpsec-work-thread.ini
+include = ntpsec-trace-log.ini
+generator = trace-log-generator
+
+;--------------------------------------------------------------------------
+[ntpsec-options]
+dump-on-error = true
+;
+; Tools
+;
+prefix = /usr
+cc = clang
+ld = clang
+cflags = -Ilib/isc/include -Ilib/isc/unix/include -Ibuild -Iinclude
+;
+; Generator options.
+;
+gen-enables = enable
+gen-triggers = enable
+
+;--------------------------------------------------------------------------
+[ntpsec-triggers]
+trigger = transmit
=====================================
devel/trace/ntpsec-work-thread.ini
=====================================
--- /dev/null
+++ b/devel/trace/ntpsec-work-thread.ini
@@ -0,0 +1,33 @@
+;
+; RTEMS Trace Linker NTPsec Trace Configuration
+;
+; Copyright 2015 Chris Johns <chrisj at ntpsec.org>
+;
+
+;--------------------------------------------------------------------------
+[ntpsec-work-thread]
+trace = exit_worker
+trace = worker_sleep
+trace = interrupt_worker_sleep
+trace = send_blocking_req_internal
+trace = receive_blocking_req_internal
+trace = send_blocking_resp_internal
+trace = receive_blocking_resp_internal
+
+;--------------------------------------------------------------------------
+[ntpsec-work-thread-funcs]
+headers = ntpsec-work-thread-headers
+signatures = ntpsec-work-thread-signatures
+
+[ntpsec-work-thread-headers]
+header = '#include "config.h"'
+;header = '#include "ntp_worker.h"'
+
+[ntpsec-work-thread-signatures]
+exit_worker = void, int
+worker_sleep = int, blocking_child*, time_t
+interrupt_worker_sleep = void, void
+send_blocking_req_internal = int, blocking_child*, blocking_pipe_header*, void*
+receive_blocking_req_internal = blocking_pipe_header*, blocking_child*
+send_blocking_resp_internal = int, blocking_child*, blocking_pipe_header*
+receive_blocking_resp_internal = blocking_pipe_header*, blocking_child*
=====================================
ntpd/wscript
=====================================
--- a/ntpd/wscript
+++ b/ntpd/wscript
@@ -133,7 +133,7 @@ def build(ctx):
ctx(
target = "ntpd",
- features = "c cprogram bld_include src_include libisc_include libisc_pthread_include ntp_version",
+ features = "c rtems_trace cprogram bld_include src_include libisc_include libisc_pthread_include ntp_version",
source = ntpd_source,
use = "libntpd_obj bison_obj isc ntp sodium opts OSSAUDIO M parse GCC_S RT CAP THR PTHREAD CRYPTO DNS_SD DNS_SD_INCLUDES %s" % use_refclock,
includes = [
=====================================
pylib/configure.py
=====================================
--- a/pylib/configure.py
+++ b/pylib/configure.py
@@ -5,10 +5,14 @@ import sys, os
def cmd_configure(ctx):
+ srcnode = ctx.srcnode.abspath()
+ bldnode = ctx.bldnode.abspath()
+
from check_type import check_type
from check_sizeof import check_sizeof
from check_structfield import check_structfield
+
if ctx.options.list:
from refclock import refclock_map
print "ID Description"
@@ -75,6 +79,16 @@ def cmd_configure(ctx):
opt = flag.replace("--", "").upper() # XXX: find a better way.
ctx.env[opt] = ctx.env.OPT_STORE[flag]
+ if ctx.options.enable_rtems_trace:
+ ctx.find_program("rtems-tld", var="BIN_RTEMS_TLD", path_list=[ctx.options.rtems_trace_path, ctx.env.BINDIR])
+ ctx.env.RTEMS_TEST_ENABLE = True
+ ctx.env.RTEMS_TEST_FLAGS = ["-C", "%s/devel/trace/ntpsec-trace.ini" % srcnode,
+ "-W", "%s/ntpsec-wrapper" % bldnode,
+ "-P", "%s/devel/trace/" % srcnode,
+ "-f", "-I%s" % bldnode,
+ "-f", "-I%s/include/" % srcnode,
+ "-f", "-I%s/libisc/include/" % srcnode,
+ "-f", "-I%s/libisc/unix/include/" % srcnode]
ctx.find_program("awk", var="BIN_AWK")
ctx.find_program("perl", var="BIN_PERL")
=====================================
pylib/rtems_trace.py
=====================================
--- /dev/null
+++ b/pylib/rtems_trace.py
@@ -0,0 +1,10 @@
+from waflib.TaskGen import feature, after_method
+
+
+ at feature("rtems_trace")
+ at after_method('apply_link')
+def rtems_trace(self):
+ if self.env.RTEMS_TEST_ENABLE:
+ self.link_task.env.LINK_CC = self.env.BIN_RTEMS_TLD + self.env.RTEMS_TEST_FLAGS + ['--']
+
+
=====================================
wscript
=====================================
--- a/wscript
+++ b/wscript
@@ -66,6 +66,8 @@ def options(ctx):
grp.add_option('--enable-fortify', action='store_true', help="Enable HP Fortify.")
grp.add_option('--fortify-flags', type='string', action='store', help="Fortify flags.")
grp.add_option('--check', action='store_true', default=False, help="Run tests")
+ grp.add_option('--enable-rtems-trace', action='store_true', default=False, help="Enable RTEMS Trace.")
+ grp.add_option('--rtems-trace-path', type='string', default="", help="Path to rtems-tld.")
grp = ctx.add_option_group("NTP documentation configure options")
grp.add_option('--enable-doc', action='store_true', default=False, help="Build NTP documentation")
@@ -104,6 +106,7 @@ def build(ctx):
ctx.load('waf', tooldir='pylib/')
ctx.load('bison')
ctx.load('asciidoc', tooldir='pylib/')
+ ctx.load('rtems_trace', tooldir='pylib/')
if ctx.env.ENABLE_DOC:
ctx.recurse("docs")
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/390081d5c5fdbee48136cacc47d5703223288ae5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151209/8627a97c/attachment.html>
More information about the vc
mailing list