1 |
48 |
alirezamon |
/*
|
2 |
|
|
* Copyright (c) 2010-2011 The University of Texas at Austin
|
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 are
|
7 |
|
|
* met: redistributions of source code must retain the above copyright
|
8 |
|
|
* notice, this list of conditions and the following disclaimer;
|
9 |
|
|
* redistributions in binary form must reproduce the above copyright
|
10 |
|
|
* notice, this list of conditions and the following disclaimer in the
|
11 |
|
|
* documentation and/or other materials provided with the distribution;
|
12 |
|
|
* neither the name of the copyright holders nor the names of its
|
13 |
|
|
* contributors may be used to endorse or promote products derived from
|
14 |
|
|
* this software without specific prior written permission.
|
15 |
|
|
*
|
16 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17 |
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18 |
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19 |
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
20 |
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23 |
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24 |
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26 |
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
|
|
*/
|
28 |
|
|
|
29 |
|
|
#ifndef NETRACE_H_
|
30 |
|
|
#define NETRACE_H_
|
31 |
|
|
|
32 |
|
|
// Includes
|
33 |
|
|
#include <stdio.h>
|
34 |
|
|
#include <stdlib.h>
|
35 |
|
|
#include <string.h>
|
36 |
|
|
|
37 |
|
|
// Macro Definitions
|
38 |
|
|
//#define DEBUG_ON
|
39 |
|
|
#define NT_MAGIC 0x484A5455
|
40 |
|
|
#define NT_BMARK_NAME_LENGTH 30
|
41 |
|
|
#define NT_DEPENDENCY_ARRAY_SIZE 200
|
42 |
|
|
#define nt_checked_malloc(x) _nt_checked_malloc(x,__FILE__,__LINE__)
|
43 |
|
|
#define nt_error(x) _nt_error(x,__FILE__,__LINE__)
|
44 |
|
|
#define NT_NUM_PACKET_TYPES 31
|
45 |
|
|
#define NT_NUM_NODE_TYPES 4
|
46 |
|
|
#define NT_NODE_TYPE_L1D 0
|
47 |
|
|
#define NT_NODE_TYPE_L1I 1
|
48 |
|
|
#define NT_NODE_TYPE_L2 2
|
49 |
|
|
#define NT_NODE_TYPE_MC 3
|
50 |
|
|
#define NT_READ_AHEAD 100000//1000000
|
51 |
|
|
|
52 |
|
|
// Type Declaration
|
53 |
|
|
typedef unsigned int nt_dependency_t;
|
54 |
|
|
typedef struct nt_header nt_header_t;
|
55 |
|
|
typedef struct nt_regionhead nt_regionhead_t;
|
56 |
|
|
typedef struct nt_packet nt_packet_t;
|
57 |
|
|
typedef struct nt_dep_ref_node nt_dep_ref_node_t;
|
58 |
|
|
typedef struct nt_packet_list nt_packet_list_t;
|
59 |
|
|
|
60 |
|
|
struct nt_header {
|
61 |
|
|
unsigned int nt_magic;
|
62 |
|
|
float version;
|
63 |
|
|
char benchmark_name[NT_BMARK_NAME_LENGTH];
|
64 |
|
|
unsigned char num_nodes;
|
65 |
|
|
unsigned long long int num_cycles;
|
66 |
|
|
unsigned long long int num_packets;
|
67 |
|
|
unsigned int notes_length; // Includes null-terminating char
|
68 |
|
|
unsigned int num_regions;
|
69 |
|
|
char* notes;
|
70 |
|
|
nt_regionhead_t* regions;
|
71 |
|
|
};
|
72 |
|
|
|
73 |
|
|
struct nt_regionhead {
|
74 |
|
|
unsigned long long int seek_offset;
|
75 |
|
|
unsigned long long int num_cycles;
|
76 |
|
|
unsigned long long int num_packets;
|
77 |
|
|
};
|
78 |
|
|
|
79 |
|
|
struct nt_packet {
|
80 |
|
|
unsigned long long int cycle;
|
81 |
|
|
unsigned int id;
|
82 |
|
|
unsigned int addr;
|
83 |
|
|
unsigned char type;
|
84 |
|
|
unsigned char src;
|
85 |
|
|
unsigned char dst;
|
86 |
|
|
unsigned char node_types;
|
87 |
|
|
unsigned char num_deps;
|
88 |
|
|
nt_dependency_t* deps;
|
89 |
|
|
};
|
90 |
|
|
|
91 |
|
|
struct nt_dep_ref_node {
|
92 |
|
|
nt_packet_t* node_packet;
|
93 |
|
|
unsigned int packet_id;
|
94 |
|
|
unsigned int ref_count;
|
95 |
|
|
nt_dep_ref_node_t* next_node;
|
96 |
|
|
};
|
97 |
|
|
|
98 |
|
|
struct nt_packet_list {
|
99 |
|
|
nt_packet_t* node_packet;
|
100 |
|
|
nt_packet_list_t* next;
|
101 |
|
|
};
|
102 |
|
|
|
103 |
|
|
// Data Members
|
104 |
|
|
extern char* nt_input_popencmd;
|
105 |
|
|
extern FILE* nt_input_tracefile;
|
106 |
|
|
extern char* nt_input_buffer;
|
107 |
|
|
extern nt_header_t* nt_input_trheader;
|
108 |
|
|
extern int nt_dependencies_off;
|
109 |
|
|
extern int nt_self_throttling;
|
110 |
|
|
extern int nt_primed_self_throttle;
|
111 |
|
|
extern int nt_done_reading;
|
112 |
|
|
extern unsigned long long int nt_latest_active_packet_cycle;
|
113 |
|
|
extern nt_dep_ref_node_t** nt_dependency_array;
|
114 |
|
|
extern unsigned long long int nt_num_active_packets;
|
115 |
|
|
extern const char* nt_packet_types[];
|
116 |
|
|
extern int nt_packet_sizes[];
|
117 |
|
|
extern const char* nt_node_types[];
|
118 |
|
|
extern nt_packet_list_t* nt_cleared_packets_list;
|
119 |
|
|
extern nt_packet_list_t* nt_cleared_packets_list_tail;
|
120 |
|
|
extern int nt_track_cleared_packets_list;
|
121 |
|
|
|
122 |
|
|
// Interface Functions
|
123 |
|
|
void nt_open_trfile( char* );
|
124 |
|
|
void nt_disable_dependencies( void );
|
125 |
|
|
void nt_seek_region( nt_regionhead_t* );
|
126 |
|
|
nt_packet_t* nt_read_packet( void );
|
127 |
|
|
int nt_dependencies_cleared( nt_packet_t* );
|
128 |
|
|
void nt_clear_dependencies_free_packet( nt_packet_t* );
|
129 |
|
|
void nt_close_trfile( void );
|
130 |
|
|
void nt_init_cleared_packets_list();
|
131 |
|
|
void nt_init_self_throttling();
|
132 |
|
|
nt_packet_list_t* nt_get_cleared_packets_list();
|
133 |
|
|
void nt_empty_cleared_packets_list();
|
134 |
|
|
|
135 |
|
|
// Utility Functions
|
136 |
|
|
void nt_print_trheader( void );
|
137 |
|
|
void nt_print_packet( nt_packet_t* );
|
138 |
|
|
nt_header_t* nt_get_trheader( void );
|
139 |
|
|
float nt_get_trversion( void );
|
140 |
|
|
int nt_get_src_type( nt_packet_t* );
|
141 |
|
|
int nt_get_dst_type( nt_packet_t* );
|
142 |
|
|
const char* nt_node_type_to_string( int );
|
143 |
|
|
const char* nt_packet_type_to_string( nt_packet_t* );
|
144 |
|
|
int nt_get_packet_size( nt_packet_t* );
|
145 |
|
|
|
146 |
|
|
// Netrace Internal Helper Functions
|
147 |
|
|
int nt_little_endian( void );
|
148 |
|
|
nt_header_t* nt_read_trheader( void );
|
149 |
|
|
void nt_print_header( nt_header_t* );
|
150 |
|
|
void nt_free_trheader( nt_header_t* );
|
151 |
|
|
int nt_get_headersize( void );
|
152 |
|
|
nt_packet_t* nt_packet_malloc( void );
|
153 |
|
|
nt_dependency_t* nt_dependency_malloc( unsigned char );
|
154 |
|
|
nt_dep_ref_node_t* nt_get_dependency_node( unsigned int );
|
155 |
|
|
nt_dep_ref_node_t* nt_add_dependency_node( unsigned int );
|
156 |
|
|
nt_packet_t* nt_remove_dependency_node( unsigned int );
|
157 |
|
|
void nt_delete_all_dependencies( void );
|
158 |
|
|
nt_packet_t* nt_packet_copy( nt_packet_t* );
|
159 |
|
|
void nt_packet_free( nt_packet_t* );
|
160 |
|
|
void nt_read_ahead( unsigned long long int );
|
161 |
|
|
void nt_prime_self_throttle( void );
|
162 |
|
|
void nt_add_cleared_packet_to_list( nt_packet_t* );
|
163 |
|
|
void* _nt_checked_malloc( size_t, const char*, int ); // Use the macro defined above instead of this function
|
164 |
|
|
void _nt_error( const char* , const char* , const int ); // Use the macro defined above instead of this functio
|
165 |
|
|
|
166 |
|
|
// Backend functions for creating trace files
|
167 |
|
|
void nt_dump_header( nt_header_t*, FILE* );
|
168 |
|
|
void nt_dump_packet( nt_packet_t*, FILE* );
|
169 |
|
|
|
170 |
|
|
#endif /*NETRACE_H_*/
|