OpenMP Runtime
tomp_log.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013, Texas Instruments Incorporated - http://www.ti.com/
00003  *   All rights reserved.
00004  *
00005  *  Redistribution and use in source and binary forms, with or without
00006  *  modification, are permitted provided that the following conditions are met:
00007  *      * Redistributions of source code must retain the above copyright
00008  *        notice, this list of conditions and the following disclaimer.
00009  *      * Redistributions in binary form must reproduce the above copyright
00010  *        notice, this list of conditions and the following disclaimer in the
00011  *        documentation and/or other materials provided with the distribution.
00012  *      * Neither the name of Texas Instruments Incorporated nor the
00013  *        names of its contributors may be used to endorse or promote products
00014  *        derived from this software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00026  * POSSIBILITY OF SUCH DAMAGE.
00027  */
00034 #ifndef _TOMP_LOG_H_
00035 #define _TOMP_LOG_H_
00036 
00038 #define tomp_LOG_WITH_PRINTF    (1)
00039 
00040 #if tomp_LOG_WITH_PRINTF
00041 #include <stdio.h>
00042 #endif
00043 
00044 #include <stdlib.h>     // for exit()
00045 
00046 extern void tomp_sendExitEvents(void);
00047 
00049 typedef enum { tomp_ErrorKind_EM_ALLOC = 0, 
00050                tomp_ErrorKind_EM_ALLOC_SIZE,
00051                tomp_ErrorKind_NULL_PTR,
00052                tomp_ErrorKind_OEM_INIT,
00053                tomp_ErrorKind_OMP_INIT,
00054                tomp_ErrorKind_QMSS
00055 } tomp_ErrorKind_e;
00056 
00058 extern const char *tomp_ErrorString[];
00059 
00060 #define GLOBAL_TIMESTAMP_ADRS (0x023101F0)
00061 
00062 static inline unsigned long long getGlobalTimeStamp()
00063 {
00064     return _itoll( *(unsigned int *)(4+GLOBAL_TIMESTAMP_ADRS),
00065                    *(unsigned int *)(GLOBAL_TIMESTAMP_ADRS));
00066 }
00067 
00068 
00073 static inline void tomp_logError(tomp_ErrorKind_e  e,
00074                                  const char       *file,
00075                                  int               line)
00076 {
00077     #if tomp_LOG_WITH_PRINTF
00078     printf("INTERNAL ERROR: %s - %s, %d\n", tomp_ErrorString[e], file, line);
00079     #endif
00080     tomp_sendExitEvents();
00081     exit(1);
00082 } 
00083 
00088 static inline void tomp_logErrorStr(tomp_ErrorKind_e  e, 
00089                                     const char       *str, 
00090                                     const char       *file,
00091                                     int               line)
00092 {
00093     #if tomp_LOG_WITH_PRINTF
00094     printf("INTERNAL ERROR: %s (%s) - %s, %d\n", tomp_ErrorString[e],
00095                                                  str, file, line);
00096     #endif
00097     tomp_sendExitEvents();
00098     exit(1);
00099 } 
00100 
00104 static inline void tomp_logDebug1(const char *fmt, int arg1)
00105 {
00106 #if defined (TOMP_TRACE_LEVEL) && (TOMP_TRACE_LEVEL > 0)
00107     #if tomp_LOG_WITH_PRINTF
00108     printf("(%016llu) ", getGlobalTimeStamp());
00109     printf(fmt, arg1);
00110     #endif
00111 #endif
00112 }
00113 
00117 static inline void tomp_logDebug2(const char *fmt, int arg1, int arg2)
00118 {
00119 #if defined (TOMP_TRACE_LEVEL) && (TOMP_TRACE_LEVEL > 0)
00120     #if tomp_LOG_WITH_PRINTF
00121     printf("(%016llu) ", getGlobalTimeStamp());
00122     printf(fmt, arg1, arg2);
00123     #endif
00124 #endif
00125 }
00126 
00130 static inline void tomp_logDebug3(const char *fmt, int arg1, int arg2, int arg3)
00131 {
00132 #if defined (TOMP_TRACE_LEVEL) && (TOMP_TRACE_LEVEL > 0)
00133     #if tomp_LOG_WITH_PRINTF
00134     printf("(%016llu) ", getGlobalTimeStamp());
00135     printf(fmt, arg1, arg2, arg3);
00136     #endif
00137 #endif
00138 }
00139 
00140 
00141 /******************
00142  * TASK STATISTICS 
00143  ******************/
00144 //#define TASK_STATS
00145 #ifdef TASK_STATS
00146 
00147 typedef struct {
00148     unsigned short      id;
00149     unsigned short      parent_id;
00150     unsigned long long  gen_cycle;
00151     unsigned int        start_cycle_delta;
00152     unsigned int        end_cycle_delta;
00153     unsigned char       gen_core;
00154     unsigned char       exec_core;
00155 } TaskStats;
00156 
00157 extern TaskStats tomp_TaskStats[];
00158 #endif
00159 
00160 
00161 #endif /* _TOMP_LOG_H_ */
00162 
00163 
 All Classes Files Functions Variables Typedefs Enumerations Defines