]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/transport/tci6614/ipc/examples/common/bench_common.h
transport: add to PDK
[processor-sdk/pdk.git] / packages / ti / transport / tci6614 / ipc / examples / common / bench_common.h
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2011 - 2018, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
33 #include <xdc/std.h>
35 /* XDC.RUNTIME module Headers */
36 #include <xdc/runtime/Types.h>
38 /* IPC module Headers */
39 #include <ti/ipc/MessageQ.h>
41 /* CSL modules */
42 #include <ti/csl/csl_chip.h>
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
48 #define VERBOSE_MODE 0
50 /* Message allocation/free Defines */
51 #define MSG_FREE_FAILED (-1)
52 #define MSG_FREE_GOOD (0)
53 #define MSG_PREALLOC_GOOD    (0)
55 /* Core Synchronization Defines */
56 #define CORE_SYNC_NULL_CORE (-1)
58 #define CORE_SYNC_TX_SIDE_READY (2)
59 #define CORE_SYNC_RX_SIDE_READY (3)
61 #define SEND_MESSAGE_LAST_MESSAGE (4)
63 /* Convert cycles to microseconds */
64 #define CYCLES_TO_US(CYCLES, CPUFREQ) \
65     ((UInt32)((((Double)CYCLES * 1000000))/(Double)CPUFREQ))
67 #define CYCLES_TO_US_DB(CYCLES, CPUFREQ) \
68     ((Double)((((Double)CYCLES * 1000000))/(Double)CPUFREQ))
69     
70 /* Convert cycles to nanoseconds */
71 #define CYCLES_TO_NS(CYCLES, CPUFREQ) \
72     ((UInt32)((((Double)CYCLES * 1000000000))/(Double)CPUFREQ))
74 /* Convert Timestamp64 to UInt64 */
75 #define TIMESTAMP64_TO_UINT64(ts64hi, ts64lo) \
76     ((((UInt64) ts64hi) << 32) | ((UInt64) ts64lo))
78 typedef struct Statistics 
79 {
80     UInt numVals;
81     Double stddev;
82     UInt32 max;
83     UInt32 min;
84     UInt maxIndex;
85     UInt minIndex;
86     Double mean;
87 } Statistics;
89 #define MESSAGE_SIZE_IN_BYTES (48)
90 typedef struct TstMsg 
91 {
92   MessageQ_MsgHeader header;      /* 32 bytes */
93   Int src;
94   Int flags;
95   Int numMsgs; 
96   Int seqNum;
97 } TstMsg;
99 inline UInt32 l2_global_address (UInt32 addr)
101   UInt32 coreNum;
103   if (addr & 0xF0000000)
104   {
105     /* Address is already global, return */
106     return (addr);
107   }
109   /* Get the core number. */
110   coreNum = CSL_chipReadReg (CSL_CHIP_DNUM); 
112   /* Compute the global address. */
113   return (addr + (0x10000000 + (coreNum * 0x1000000)));
116 int32_t Osal_dataBufferInitMemory(uint32_t dataBufferSize);
117  
118 Void getStats(UInt32 *values, UInt numVals, Statistics *stats);
119 Void attachAll(UInt numCores);
120 Void detachAll(UInt numCores);
122 /* Common benchmark functions */
123 Void setLocalId (Void);
124 Int allocateMessages (Uint32 numMsgs, UInt16 heapId, TstMsg **msgPtrArray);
125 Int freeMessages (Uint32 numMsgs, TstMsg **msgPtrArray);
126 void syncSendCore (Int16 *syncCoresArrayPtr, 
127                                      MessageQ_Handle coreRcvMsgQ, 
128                                      MessageQ_QueueId *remoteCoreQIdArrayPtr, 
129                                      TstMsg **syncMsgPtrArray,
130                                      Bool freeRxMsgs);
131 void syncReceiveCore (Int16 *syncCoresArrayPtr, 
132                                      MessageQ_Handle coreRcvMsgQ, 
133                                      MessageQ_QueueId *remoteCoreQIdArrayPtr);
134 UInt32 sendMessages (UInt16 numberOfReceivingCores,
135                                          UInt32 *numMsgsToSendPerCoreArrayPtr,
136                                          MessageQ_QueueId *remoteCoreQIdArrayPtr, 
137                                          TstMsg **msgPtrArray);
138 UInt32 receiveMessages(Int16 *sendCoresArrayPtr, MessageQ_Handle coreRcvMsgQ,
139                                             TstMsg **rxMsgPtrArray, UInt32 uSecDelayPerMsg);
140 UInt64 getStartTime64();
141 UInt64 getExecutionTime64(UInt64 startTime,  UInt64 tsReadAdjust);
142 void calculateThroughput (UInt32 numMsgsRx, UInt64 executionTime, Types_FreqHz cpuFrequency);
143  
144 #ifdef __cplusplus
146 #endif