summaryrefslogtreecommitdiffstats
path: root/src/ssx/trace
diff options
context:
space:
mode:
authorWilliam Bryan <wilbryan@us.ibm.com>2015-08-03 12:38:58 -0500
committerWilliam A. Bryan <wilbryan@us.ibm.com>2015-08-03 15:32:27 -0500
commit420e6d248cc6d2b3c39bc3970e3bb6747b3bddc3 (patch)
treec9f6691eddba39193e39aa769367e1267fb9fc86 /src/ssx/trace
parentadade8c8ef30ed519322674c762d95663009c5d4 (diff)
downloadtalos-occ-420e6d248cc6d2b3c39bc3970e3bb6747b3bddc3.tar.gz
talos-occ-420e6d248cc6d2b3c39bc3970e3bb6747b3bddc3.zip
new ssx and lib files
Change-Id: I2328b1e86d59e3788910687d762fb70ec680058f Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/19503 Reviewed-by: William A. Bryan <wilbryan@us.ibm.com> Tested-by: William A. Bryan <wilbryan@us.ibm.com>
Diffstat (limited to 'src/ssx/trace')
-rw-r--r--src/ssx/trace/Makefile50
-rw-r--r--src/ssx/trace/ssx_trace.h303
-rw-r--r--src/ssx/trace/ssx_trace_big.c116
-rw-r--r--src/ssx/trace/ssx_trace_binary.c115
-rw-r--r--src/ssx/trace/ssx_trace_core.c165
-rw-r--r--src/ssx/trace/ssxtracefiles.mk63
6 files changed, 812 insertions, 0 deletions
diff --git a/src/ssx/trace/Makefile b/src/ssx/trace/Makefile
new file mode 100644
index 0000000..5506b32
--- /dev/null
+++ b/src/ssx/trace/Makefile
@@ -0,0 +1,50 @@
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: src/ssx/trace/Makefile $
+#
+# OpenPOWER OnChipController Project
+#
+# Contributors Listed Below - COPYRIGHT 2015
+# [+] International Business Machines Corp.
+#
+#
+# Licensed 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.
+#
+# IBM_PROLOG_END_TAG
+# This Makefile is designed to be invoked with the -I argument set to
+# the location of the "ssx.mk" for the build
+
+include img_defs.mk
+include ssxtracefiles.mk
+
+ifeq "$(SSX_TIMER_SUPPORT)" "1"
+SSXTRACE_OBJECTS += ${SSXTRACE-TIMER-C-SOURCES:.c=.o} ${SSXTRACE-TIMER-S-SOURCES:.S=.o}
+endif
+
+ifeq "$(SSX_THREAD_SUPPORT)" "1"
+SSXTRACE_OBJECTS += ${SSXTRACE-THREAD-C-SOURCES:.c=.o} ${SSXTRACE-THREAD-S-SOURCES:.S=.o}
+endif
+
+OBJS := $(addprefix $(OBJDIR)/, $(SSXTRACE_OBJECTS))
+
+all: $(OBJS)
+
+$(OBJS) $(OBJS:.o=.d): | $(OBJDIR)
+
+$(OBJDIR):
+ mkdir -p $(OBJDIR)
+
+ifneq ($(MAKECMDGOALS),clean)
+include $(OBJS:.o=.d)
+endif
diff --git a/src/ssx/trace/ssx_trace.h b/src/ssx/trace/ssx_trace.h
new file mode 100644
index 0000000..c79452b
--- /dev/null
+++ b/src/ssx/trace/ssx_trace.h
@@ -0,0 +1,303 @@
+/* IBM_PROLOG_BEGIN_TAG */
+/* This is an automatically generated prolog. */
+/* */
+/* $Source: src/ssx/trace/ssx_trace.h $ */
+/* */
+/* OpenPOWER OnChipController Project */
+/* */
+/* Contributors Listed Below - COPYRIGHT 2015 */
+/* [+] International Business Machines Corp. */
+/* */
+/* */
+/* Licensed 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. */
+/* */
+/* IBM_PROLOG_END_TAG */
+#ifndef __SSX_TRACE_H__
+#define __SSX_TRACE_H__
+//-----------------------------------------------------------------------------
+// *! (C) Copyright International Business Machines Corp. 2014
+// *! All Rights Reserved -- Property of IBM
+// *! *** IBM Confidential ***
+//-----------------------------------------------------------------------------
+
+/// \file ssx_trace.h
+/// \brief Macros and declarations for the SSX Firmware Tracing Facility.
+///
+
+#include <stdint.h>
+
+#define SSX_TRACE_VERSION 2
+
+#ifndef SSX_TRACE_SZ
+#define SSX_TRACE_SZ 256
+#endif
+
+//Fail compilation if size is not a power of 2
+#if ((SSX_TRACE_SZ - 1) & SSX_TRACE_SZ)
+#error "SSX_TRACE_SZ is not a power of two!!!"
+#endif
+
+//Fail compilation if size is smaller than 64 bytes
+#if (SSX_TRACE_SZ < 64)
+#error "SSX_TRACE_SZ must be at least 64 bytes!!!"
+#endif
+
+//Mask for calculating offsets into the trace circular buffer
+#define SSX_TRACE_CB_MASK (SSX_TRACE_SZ - 1)
+
+#define STRINGIFY_HELPER(x) #x
+#define STRINGIFY(x) STRINGIFY_HELPER(x)
+
+#define PPC_IMG_STRING STRINGIFY(IMAGE_NAME)
+
+#ifdef SSX_TRACE_HASH_PREFIX
+#if (SSX_TRACE_HASH_PREFIX > 0xffff)
+#error SSX_TRACE_HASH_PREFIX must be defined as a 16 bit constant value
+#endif
+#endif //SSX_TRACE_HASH_PREFIX
+
+//This provides a 128ns tick (assuming a 32ns clock period)
+//and 4 different format values
+#define SSX_TRACE_TS_BITS 30
+
+#define SSX_TRACE_FORMAT_BITS (32 - SSX_TRACE_TS_BITS)
+
+#define SSX_TRACE_TS_MASK (0xfffffffful << SSX_TRACE_FORMAT_BITS)
+#define SSX_TRACE_FORMAT_MASK (~SSX_TRACE_TS_MASK)
+
+#define SSX_GET_TRACE_FORMAT(w32) (SSX_TRACE_FORMAT_MASK & w32)
+#define SSX_GET_TRACE_TIME(w32) (SSX_TRACE_TS_MASK & w32)
+
+//Set the trace timer period to be the maximum
+//32 bit time minus 2 seconds (assuming a 32ns tick)
+//This allows for up to 1 second of interrupt latency +
+//1 second for SSX_TRACE_MTBT while only requiring a trace
+//every 135 seconds in order to maintain the 64bit timebase.
+#define SSX_TRACE_TIMER_PERIOD (0xfffffffful - 62500000)
+
+//The Maximum Time Between Traces. In order to reduce the time that interrupts
+//are disabled for tracing, reading of the time stamp is not done atomically
+//with alocating an entry in the circular buffer. This means that the
+//timestamps might not appear in order in the trace buffer. This is a
+//problem because our calculation of the 64 bit timebase uses the unsigned
+//difference of the current 32bit timestamp and the previous one and if they
+//are out of order it will result in a very large difference. To solve this
+//problem, any time that the parser code sees a very large difference (larger
+//than SSX_TRACE_MTBT) it will treat it as a negative number.
+#define SSX_TRACE_MTBT (0xfffffffful - 31250000)
+
+#define SSX_TRACE_MAX_PARMS 4
+
+//This is the maximum number of bytes allowed to be traced in a binary trace
+//entry.
+//The trace version needs to change if this changes.
+#define SSX_TRACE_MAX_BINARY 256
+
+//clip the largest binary trace according to the trace buffer size.
+//(The trace version does not need to change if this changes as long
+// as it remains less than SSX_TRACE_MAX_BINARY)
+#if (SSX_TRACE_SZ <= 256)
+#define SSX_TRACE_CLIPPED_BINARY_SZ SSX_TRACE_SZ / 2
+#else
+#define SSX_TRACE_CLIPPED_BINARY_SZ SSX_TRACE_MAX_BINARY
+#endif
+
+//Trace formats that are supported
+typedef enum
+{
+ SSX_TRACE_FORMAT_EMPTY,
+ SSX_TRACE_FORMAT_TINY,
+ SSX_TRACE_FORMAT_BIG,
+ SSX_TRACE_FORMAT_BINARY,
+}SsxTraceFormat;
+
+//This combines the timestamp and the format bits into a
+//single 32 bit word.
+typedef union
+{
+ struct
+ {
+ uint32_t timestamp : SSX_TRACE_TS_BITS;
+ uint32_t format : SSX_TRACE_FORMAT_BITS;
+ };
+ uint32_t word32;
+}SsxTraceTime;
+
+//SSX trace uses a 16 bit string format hash value
+typedef uint16_t SsxTraceHash;
+
+//The constant 16 bit hash value is combined with a
+//16 bit parameter value when doing a tiny trace
+typedef union
+{
+ struct
+ {
+ SsxTraceHash string_id;
+ uint16_t parm;
+ };
+ uint32_t word32;
+}SsxTraceTinyParms;
+
+//A tiny trace fits within a single 8 byte word. This includes
+//the timestamp, format bits, hash id, and a 16 bit parameter.
+typedef union
+{
+ struct
+ {
+ SsxTraceTinyParms parms;
+ SsxTraceTime time_format;
+ };
+ uint64_t word64;
+}SsxTraceTiny;
+
+//Larger traces that require a 32 bit parameter or more than one
+//parameter use the big trace format. The number of parms and
+//the 'complete' flag are combined with the hash id. 'complete'
+//is set to 0 initially and set to one only after all of the trace
+//data has been written.
+typedef union
+{
+ struct
+ {
+ SsxTraceHash string_id;
+ uint8_t complete;
+ uint8_t num_parms;
+ };
+ uint32_t word32;
+}SsxTraceBigParms;
+
+typedef union
+{
+ struct
+ {
+ SsxTraceBigParms parms;
+ SsxTraceTime time_format;
+ };
+ uint64_t word64;
+}SsxTraceBig;
+
+//Binary traces are handled in a similar fashion to big traces, except
+//that instead of having a number of parameters, we have number of bytes.
+typedef union
+{
+ struct
+ {
+ SsxTraceHash string_id;
+ uint8_t complete;
+ uint8_t num_bytes;
+ };
+ uint32_t word32;
+}SsxTraceBinaryParms;
+
+typedef union
+{
+ struct
+ {
+ SsxTraceBinaryParms parms;
+ SsxTraceTime time_format;
+ };
+ uint64_t word64;
+}SsxTraceBinary;
+
+//This is a generic structure that can be used to retrieve data
+//for tiny, big, and binary formatted entries.
+typedef union
+{
+ struct
+ {
+ SsxTraceHash string_id;
+ union
+ {
+ uint16_t parm16;
+ struct
+ {
+ uint8_t complete;
+ uint8_t bytes_or_parms_count;
+ };
+ };
+ SsxTraceTime time_format;
+ };
+ uint64_t word64;
+}SsxTraceGeneric;
+
+//This is a format that might be used in the future for tracing
+//a 64 bit timestamp so that we don't fill up the buffer with periodic
+//timer traces. It is not currently used.
+#if 0
+typedef union
+{
+ struct
+ {
+ uint32_t upper32;
+ SsxTraceTime time_format;
+ };
+ uint64_t word64;
+}SsxTraceTime64;
+#endif
+
+//It would probably be more accurate to call this a footer since it
+//actually resides at the highest address of each trace entry. These eight
+//bytes contain information that allow us to walk the trace buffer from the
+//most recent entry to the oldest entry.
+typedef union
+{
+ SsxTraceGeneric generic;
+ SsxTraceBinary binary;
+ SsxTraceBig big;
+ SsxTraceTiny small;
+}SsxTraceEntryFooter;
+
+
+//This is the data that is updated (in the buffer header) every time we add
+//a new entry to the buffer.
+typedef union
+{
+ struct
+ {
+ uint32_t tbu32;
+ uint32_t offset;
+ };
+ uint64_t word64;
+}SsxTraceState;
+
+#define SSX_TRACE_IMG_STR_SZ 16
+
+//Header data for the trace buffer that is used for parsing the data.
+//Note: SsxTraceState contains a uint64_t which is required to be
+//placed on an 8-byte boundary according to the EABI Spec. This also
+//causes cb to start on an 8-byte boundary.
+typedef struct
+{
+ //these values are needed by the parser
+ uint16_t version;
+ uint16_t rsvd;
+ char image_str[SSX_TRACE_IMG_STR_SZ];
+ uint16_t instance_id;
+ uint16_t partial_trace_hash;
+ uint16_t hash_prefix;
+ uint16_t size;
+ uint32_t max_time_change;
+ uint32_t hz;
+ uint32_t pad;
+ uint64_t time_adj64;
+
+ //updated with each new trace entry
+ SsxTraceState state;
+
+ //circular trace buffer
+ uint8_t cb[SSX_TRACE_SZ];
+}SsxTraceBuffer;
+
+extern SsxTraceBuffer g_ssx_trace_buf;
+
+#endif /* __SSX_TRACE_H__ */
diff --git a/src/ssx/trace/ssx_trace_big.c b/src/ssx/trace/ssx_trace_big.c
new file mode 100644
index 0000000..4a9bdb5
--- /dev/null
+++ b/src/ssx/trace/ssx_trace_big.c
@@ -0,0 +1,116 @@
+/* IBM_PROLOG_BEGIN_TAG */
+/* This is an automatically generated prolog. */
+/* */
+/* $Source: src/ssx/trace/ssx_trace_big.c $ */
+/* */
+/* OpenPOWER OnChipController Project */
+/* */
+/* Contributors Listed Below - COPYRIGHT 2015 */
+/* [+] International Business Machines Corp. */
+/* */
+/* */
+/* Licensed 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. */
+/* */
+/* IBM_PROLOG_END_TAG */
+//-----------------------------------------------------------------------------
+// *! (C) Copyright International Business Machines Corp. 2014
+// *! All Rights Reserved -- Property of IBM
+// *! *** IBM Confidential ***
+//-----------------------------------------------------------------------------
+
+/// \file ssx_trace_big.c
+/// \brief SSX Trace function that supports up to four 32-bit parameters
+///
+/// The ssx_trace_big function is only called (via some macro magic) if the
+/// caller passes in a single parameter (not including the format string)
+/// that is larger than 16 bits to the SSX_TRACE(...) macro.
+///
+
+#include "ssx.h"
+#include "ssx_trace.h"
+
+#if (SSX_TRACE_SUPPORT && SSX_TIMER_SUPPORT)
+void ssx_trace_big(uint32_t i_hash_and_count,
+ uint64_t i_parm1, uint64_t i_parm2)
+{
+ SsxTraceBig footer;
+ SsxTraceBig* footer_ptr;
+ SsxTraceState state;
+ uint64_t* ptr64;
+ uint64_t tb64;
+ SsxMachineContext ctx;
+ uint32_t parm_size;
+ uint32_t cur_offset;
+ uint32_t footer_offset;
+
+ //fill in the footer data
+ tb64 = ssx_ext_timebase_get();
+ footer.parms.word32 = i_hash_and_count; //this has the parm count and hash
+ state.tbu32 = tb64 >> 32;
+ footer.time_format.word32 = tb64 & 0x00000000ffffffffull;
+ footer.time_format.format = SSX_TRACE_FORMAT_BIG;
+
+ //round up to 8 byte boundary
+ if(footer.parms.num_parms <= 2)
+ {
+ parm_size = 8;
+ }
+ else
+ {
+ parm_size = 16;
+ }
+
+ //*****The following operations must be done atomically*****
+ ssx_critical_section_enter(SSX_NONCRITICAL, &ctx);
+
+ //load in the offset in the cb for the entry we are adding
+ cur_offset = g_ssx_trace_buf.state.offset;
+
+ //Find the offset for the footer (at the end of the entry)
+ footer_offset = cur_offset + parm_size;
+
+ //calculate the address of the footer
+ ptr64 = (uint64_t*)&g_ssx_trace_buf.cb[footer_offset & SSX_TRACE_CB_MASK];
+
+ //calculate the offset for the next entry in the cb
+ state.offset = footer_offset + sizeof(SsxTraceBig);
+
+ //update the cb state (tbu and offset)
+ g_ssx_trace_buf.state.word64 = state.word64;
+
+ //write the data to the circular buffer including the
+ //timesamp, string hash, and 16bit parameter
+ *ptr64 = footer.word64;
+
+ //*******************exit the critical section***************
+ ssx_critical_section_exit(&ctx);
+
+
+ //write parm values to the circular buffer
+ footer_ptr = (SsxTraceBig*)ptr64;
+ ptr64 = (uint64_t*)&g_ssx_trace_buf.cb[cur_offset & SSX_TRACE_CB_MASK];
+ *ptr64 = i_parm1;
+ if(parm_size > 8)
+ {
+ ptr64 = (uint64_t*)&g_ssx_trace_buf.cb[(cur_offset + 8) & SSX_TRACE_CB_MASK];
+ *ptr64 = i_parm2;
+ }
+
+ //Mark the trace entry update as being completed
+ footer_ptr->parms.complete = 1;
+
+}
+
+#endif
+
+
diff --git a/src/ssx/trace/ssx_trace_binary.c b/src/ssx/trace/ssx_trace_binary.c
new file mode 100644
index 0000000..f1d1db6
--- /dev/null
+++ b/src/ssx/trace/ssx_trace_binary.c
@@ -0,0 +1,115 @@
+/* IBM_PROLOG_BEGIN_TAG */
+/* This is an automatically generated prolog. */
+/* */
+/* $Source: src/ssx/trace/ssx_trace_binary.c $ */
+/* */
+/* OpenPOWER OnChipController Project */
+/* */
+/* Contributors Listed Below - COPYRIGHT 2015 */
+/* [+] International Business Machines Corp. */
+/* */
+/* */
+/* Licensed 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. */
+/* */
+/* IBM_PROLOG_END_TAG */
+//-----------------------------------------------------------------------------
+// *! (C) Copyright International Business Machines Corp. 2014
+// *! All Rights Reserved -- Property of IBM
+// *! *** IBM Confidential ***
+//-----------------------------------------------------------------------------
+
+/// \file ssx_trace_binary.c
+/// \brief SSX Trace function for dumping memory contents
+///
+/// The ssx_trace_binary function is called by the SSX_TRACE_BINARY() macro.
+///
+
+
+#include "ssx.h"
+#include "ssx_trace.h"
+
+#if (SSX_TRACE_SUPPORT && SSX_TIMER_SUPPORT)
+void ssx_trace_binary(uint32_t i_hash_and_size, void* bufp)
+{
+ SsxTraceBinary footer;
+ SsxTraceBinary* footer_ptr;
+ SsxTraceState state;
+ uint64_t* ptr64;
+ uint64_t tb64;
+ SsxMachineContext ctx;
+ uint32_t data_size;
+ uint32_t cb_offset;
+ uint32_t footer_offset;
+ uint8_t* dest;
+ uint8_t* src;
+ uint32_t index;
+
+ //fill in the footer data
+ tb64 = ssx_ext_timebase_get();
+ footer.parms.word32 = i_hash_and_size; //this has the size and hash
+ state.tbu32 = tb64 >> 32;
+ footer.time_format.word32 = tb64 & 0x00000000ffffffffull;
+ footer.time_format.format = SSX_TRACE_FORMAT_BINARY;
+
+ //round up to 8 byte boundary
+ data_size = (footer.parms.num_bytes + 7) & ~0x00000007ul;
+
+ //limit data size
+ if(data_size > SSX_TRACE_CLIPPED_BINARY_SZ)
+ {
+ data_size = SSX_TRACE_CLIPPED_BINARY_SZ;
+ }
+
+ //*****The following operations must be done atomically*****
+ ssx_critical_section_enter(SSX_NONCRITICAL, &ctx);
+
+ //load in the offset in the cb for the entry we are adding
+ cb_offset = g_ssx_trace_buf.state.offset;
+
+ //Find the offset for the footer (at the end of the entry)
+ footer_offset = cb_offset + data_size;
+
+ //calculate the address of the footer
+ ptr64 = (uint64_t*)&g_ssx_trace_buf.cb[footer_offset & SSX_TRACE_CB_MASK];
+
+ //calculate the offset for the next entry in the cb
+ state.offset = footer_offset + sizeof(SsxTraceBinary);
+
+ //update the cb state (tbu and offset)
+ g_ssx_trace_buf.state.word64 = state.word64;
+
+ //write the footer data to the circular buffer including the
+ //timesamp, string hash and data size
+ *ptr64 = footer.word64;
+
+ //*******************exit the critical section***************
+ ssx_critical_section_exit(&ctx);
+
+ //write data to the circular buffer
+ for(src = bufp, index = 0;
+ index < data_size;
+ index++)
+ {
+ dest = &g_ssx_trace_buf.cb[(cb_offset + index) & SSX_TRACE_CB_MASK];
+ *dest = *(src++);
+ }
+
+ //Mark the trace entry update as being completed
+ footer_ptr = (SsxTraceBinary*)ptr64;
+ footer_ptr->parms.complete = 1;
+
+}
+
+#endif
+
+
diff --git a/src/ssx/trace/ssx_trace_core.c b/src/ssx/trace/ssx_trace_core.c
new file mode 100644
index 0000000..a2db4b8
--- /dev/null
+++ b/src/ssx/trace/ssx_trace_core.c
@@ -0,0 +1,165 @@
+/* IBM_PROLOG_BEGIN_TAG */
+/* This is an automatically generated prolog. */
+/* */
+/* $Source: src/ssx/trace/ssx_trace_core.c $ */
+/* */
+/* OpenPOWER OnChipController Project */
+/* */
+/* Contributors Listed Below - COPYRIGHT 2015 */
+/* [+] International Business Machines Corp. */
+/* */
+/* */
+/* Licensed 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. */
+/* */
+/* IBM_PROLOG_END_TAG */
+//-----------------------------------------------------------------------------
+// *! (C) Copyright International Business Machines Corp. 2014
+// *! All Rights Reserved -- Property of IBM
+// *! *** IBM Confidential ***
+//-----------------------------------------------------------------------------
+
+/// \file ssx_trace_core.c
+/// \brief SSX Trace core data and code.
+///
+/// This file includes the minimal code/data required to do minimal tracing.
+/// This includes the periodic timer initialization and the ssx_trace_tiny
+/// function. The ssx_trace_tiny function is called by the SSX_TRACE() macro
+/// when there is one or less parameters (not including the format string)
+/// and the parameter size is 16 bits or smaller.
+///
+
+#include "ssx.h"
+#include "ssx_trace.h"
+
+void ssx_trace_timer_callback(void* arg);
+
+#if (SSX_TRACE_SUPPORT && SSX_TIMER_SUPPORT)
+
+//Static initialization of the trace timer
+SsxTimer g_ssx_trace_timer = {
+ .deque = SSX_DEQUE_ELEMENT_INIT(),
+ .timeout = 0,
+ .callback = ssx_trace_timer_callback,
+ .arg = 0,
+ .options = SSX_TIMER_CALLBACK_PREEMPTIBLE,
+};
+
+//Static initialization of the ssx trace buffer
+SsxTraceBuffer g_ssx_trace_buf =
+{
+ .version = SSX_TRACE_VERSION,
+ .image_str = PPC_IMG_STRING,
+ .hash_prefix = SSX_TRACE_HASH_PREFIX,
+ .partial_trace_hash = trace_ppe_hash("PARTIAL TRACE ENTRY. HASH_ID = %d", SSX_TRACE_HASH_PREFIX),
+ .size = SSX_TRACE_SZ,
+ .max_time_change = SSX_TRACE_MTBT,
+ .hz = 500000000, //default value. Actual value is set in ssx_init.c
+ .time_adj64 = 0,
+ .state.word64 = 0,
+ .cb = {0}
+};
+
+//Needed for buffer extraction in simics for now
+SsxTraceBuffer* g_ssx_trace_buf_ptr = &g_ssx_trace_buf;
+
+// Creates an 8 byte entry in the trace buffer that includes a timestamp,
+// a format string hash value and a 16 bit parameter.
+//
+// i_parm has the hash value combined with the 16 bit parameter
+void ssx_trace_tiny(uint32_t i_parm)
+{
+ SsxTraceTiny footer;
+ SsxTraceState state;
+ uint64_t* ptr64;
+ uint64_t tb64;
+ SsxMachineContext ctx;
+
+ //fill in the footer data
+ footer.parms.word32 = i_parm;
+ tb64 = ssx_ext_timebase_get();
+ state.tbu32 = tb64 >> 32;
+ footer.time_format.word32 = tb64 & 0x00000000ffffffffull;
+
+ footer.time_format.format = SSX_TRACE_FORMAT_TINY;
+
+ //The following operations must be done atomically
+ ssx_critical_section_enter(SSX_NONCRITICAL, &ctx);
+
+ //load the current byte count and calculate the address for this
+ //entry in the cb
+ ptr64 = (uint64_t*)&g_ssx_trace_buf.cb[g_ssx_trace_buf.state.offset & SSX_TRACE_CB_MASK];
+
+ //calculate the offset for the next entry in the cb
+ state.offset = g_ssx_trace_buf.state.offset + sizeof(SsxTraceTiny);
+
+ //update the cb state (tbu and offset)
+ g_ssx_trace_buf.state.word64 = state.word64;
+
+ //write the data to the circular buffer including the
+ //timesamp, string hash, and 16bit parameter
+ *ptr64 = footer.word64;
+
+ //exit the critical section
+ ssx_critical_section_exit(&ctx);
+}
+
+
+// This function is called periodically in order to ensure that the max ticks
+// between trace entries is no more than what will fit inside a 32bit value.
+void ssx_trace_timer_callback(void* arg)
+{
+
+ // guarantee at least one trace before the lower 32bit timebase flips
+ SSX_TRACE("PERIODIC TIMESTAMPING TRACE");
+
+ // restart the timer
+ ssx_timer_schedule(&g_ssx_trace_timer,
+ SSX_TRACE_TIMER_PERIOD,
+ 0);
+}
+
+// Use this function to synchronize the timebase between multiple Processors.
+// proc A can send proc B it's current timebase and then proc B can set that
+// as the current timebase for tracing purposes. It can also be used
+// to set the current time to 0. This function changes the timebase for
+// all entries that are currently in the trace buffer. Setting the current
+// timebase to 0 will cause previous traces to have very large timestamps.
+void ssx_trace_set_timebase(SsxTimebase timebase)
+{
+ g_ssx_trace_buf.time_adj64 = timebase - ssx_ext_timebase_get();
+}
+
+void ssx_trace_init(uint32_t timebase_frequency_hz,
+ SsxTimebase initial_timebase)
+{
+ //set the trace timebase HZ (used by parsing tools)
+ g_ssx_trace_buf.hz = timebase_frequency_hz;
+
+ if(initial_timebase != SSX_TIMEBASE_CONTINUES)
+ {
+ //Set the timebase adjustment. The external timebase
+ //is not adjustable so we use a software adjustment instead.
+ //Typically, this should only be used by the first processor to come
+ //up in order to set the timebase to 0. Other processors
+ //will want to synchronize with the first processor's timebase.
+ ssx_trace_set_timebase(initial_timebase);
+ }
+
+ // Schedule the timer that puts a timestamp in the trace buffer
+ // periodically. This allows us to use 32bit timestamps.
+ ssx_timer_schedule(&g_ssx_trace_timer,
+ SSX_TRACE_TIMER_PERIOD,
+ 0);
+}
+
+#endif
diff --git a/src/ssx/trace/ssxtracefiles.mk b/src/ssx/trace/ssxtracefiles.mk
new file mode 100644
index 0000000..dc3d058
--- /dev/null
+++ b/src/ssx/trace/ssxtracefiles.mk
@@ -0,0 +1,63 @@
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: src/ssx/trace/ssxtracefiles.mk $
+#
+# OpenPOWER OnChipController Project
+#
+# Contributors Listed Below - COPYRIGHT 2015
+# [+] International Business Machines Corp.
+#
+#
+# Licensed 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.
+#
+# IBM_PROLOG_END_TAG
+# @file ssxtracefiles.mk
+#
+# @brief mk for including SSX trace object files
+#
+# @page ChangeLogs Change Logs
+# @section ssxtracefiles.mk
+# @verbatim
+#
+#
+# Change Log ******************************************************************
+# Flag Defect/Feature User Date Description
+# ------ -------------- ---------- ------------ -----------
+#
+# @endverbatim
+#
+##########################################################################
+# Include Files
+##########################################################################
+
+
+
+##########################################################################
+# Object Files
+##########################################################################
+SSXTRACE-C-SOURCES = ssx_trace_core.c ssx_trace_big.c ssx_trace_binary.c
+
+SSXTRACE-S-SOURCES =
+
+SSXTRACE-TIMER-C-SOURCES =
+SSXTRACE-TIMER-S-SOURCES =
+
+SSXTRACE-THREAD-C-SOURCES +=
+SSXTRACE-THREAD-S-SOURCES +=
+
+
+SSXTRACE_OBJECTS += $(SSXTRACE-C-SOURCES:.c=.o) $(SSXTRACE-S-SOURCES:.S=.o)
+
+
+
OpenPOWER on IntegriCloud