Main Page   Compound List   File List   Compound Members   File Members  

main.cc File Reference

The code for instruction-level-reduction. More...

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Compounds

struct  reference_record_s
 A record structure in which a reference record will be passed and stored. More...


Typedefs

typedef char tag_t
 The type for the tag that indicates the type of a reference.

typedef unsigned long long int timestamp_t
 The type for the cycle counter timestamp.

typedef unsigned char length_t
 The type for length values.

typedef unsigned long int address_space_ID_t
 The type for the address space identifier, a.k.a. the page number holding the base level of the page table.

typedef unsigned long int address_t
 The type for virtual addresses.


Functions

void process_trace ()
 The actual engine for handling references.

int main (const unsigned int argc, const char **const argv)
 The entry point.


Variables

const tag_t TAG_END_OF_TRACE = 'e'
 The tag to mark the end of the trace.


Detailed Description

The code for instruction-level-reduction.

Author:
Scott F. H. Kaplan <sfkaplan@cs.amherst.edu>
Date:
December 2002
This file contains all of the code for the instruction-level-reduction reference handler, which converts the binary output of the Laplace raw reference trace a difference-encoded text format.

Definition in file main.cc.


Typedef Documentation

typedef unsigned long int address_space_ID_t
 

The type for the address space identifier, a.k.a. the page number holding the base level of the page table.

Definition at line 40 of file main.cc.

Referenced by process_trace().

typedef unsigned long int address_t
 

The type for virtual addresses.

Definition at line 43 of file main.cc.

Referenced by process_trace().

typedef unsigned char length_t
 

The type for length values.

Definition at line 36 of file main.cc.

typedef char tag_t
 

The type for the tag that indicates the type of a reference.

Definition at line 30 of file main.cc.

typedef unsigned long long int timestamp_t
 

The type for the cycle counter timestamp.

Definition at line 33 of file main.cc.

Referenced by process_trace().


Function Documentation

int main const unsigned int    argc,
const char **const    argv
 

The entry point.

Parameters:
argc The number of arguments given at the command line.
argv The vector of argument strings passed at the command line.
Returns:
An execution result code.
Parse the command line arguments. For this utility, there should be none, as input is taken from stdin, and output is sent to stdout.

Definition at line 210 of file main.cc.

References process_trace().

00210                                                         {
00211 
00212   // Were the correct number of arguments passed?
00213   if (argc != 1) {
00214 
00215     // No.  Emit usage and exit.
00216     fprintf(stderr, "Usage: %s <NO ARGUMENTS>\n", argv[0]);
00217     exit(1);
00218 
00219   }
00220 
00221   // Perform the reference handling.
00222   process_trace();
00223 
00224   // Exit successfully.
00225   return 0;
00226 
00227 } // main

void process_trace  
 

The actual engine for handling references.

Read every record from the raw reference trace (via stdin), perform difference encoding on the values (as described in the README file), and emit a text representation.

Definition at line 79 of file main.cc.

References address_space_ID_t, address_t, reference_record_s::tag, TAG_END_OF_TRACE, and timestamp_t.

Referenced by main().

00079                  {
00080 
00081   // Allocate a single reference record into which the binary source
00082   // will be read, one record at a time.
00083   reference_record_s binary_record;
00084 
00085   // The previous timestamp.
00086   timestamp_t previous_timestamp = 0;
00087 
00088   // The previous virtual address space ID (tracked without regard to
00089   // reference type).
00090   address_space_ID_t previous_address_space_ID = 0;
00091 
00092   // An array storing the previous virtual addresses of each type,
00093   // initialized.  Note that for efficiency, we allocate an array that
00094   // is large enough so that there is an entry for each possible tag
00095   // value.
00096   const unsigned int bits_per_byte = 8;
00097   const unsigned int number_possible_tags =
00098     (unsigned int)pow(2.0, (double)(sizeof(tag_t) * bits_per_byte));
00099   address_t previous_address[number_possible_tags];
00100   for (unsigned int i = 0; i < number_possible_tags; i++) {
00101     previous_address[i] = 0;
00102   }
00103 
00104   // A record number counter, used for debugging purposes.
00105   unsigned long long int record_number = 1;
00106 
00107   // Read binary records until the end of the trace has been reached.
00108   do {
00109 
00110     // Attempt to read the next record.
00111     size_t read_result = fread(&binary_record,
00112              sizeof(binary_record),
00113              1,
00114              stdin);
00115 
00116     // Ensure that the read succeeded; otherwise, bail out.
00117     if (read_result != 1) {
00118 
00119       if (feof(stdin)) {
00120   fprintf(stderr, "Premature EOF\n");
00121       } else {
00122   fprintf(stderr, "Failed in reading binary record\n");
00123       }
00124 
00125       exit(1);
00126 
00127     }
00128 
00129     // Have we reached the end of the trace?
00130     if (binary_record.tag == TAG_END_OF_TRACE) {
00131 
00132       // Yes, so emit the ending tag.
00133       printf("%c\n", binary_record.tag);
00134 
00135     } else {
00136 
00137       // Calculate the timestamp difference and adopt the new
00138       // timestamp.
00139       timestamp_t timestamp_difference =
00140   binary_record.timestamp - previous_timestamp;
00141       previous_timestamp = binary_record.timestamp;
00142 
00143       // Calculate the address space ID to emit.  Is it the same as
00144       // the previous address space ID, emit zero; otherwise, emit the
00145       // changed address space ID.
00146       address_space_ID_t address_space_ID = 0;
00147       if (binary_record.address_space_ID !=
00148     previous_address_space_ID) {
00149   address_space_ID = binary_record.address_space_ID;
00150   previous_address_space_ID = address_space_ID;
00151       }
00152 
00153       // Calculate the virtual address difference based on the
00154       // reference type.
00155       char address_difference_sign;
00156       address_t address_difference_magnitude;
00157       if (binary_record.virtual_address <
00158     previous_address[binary_record.tag]) {
00159 
00160   address_difference_sign = '-';
00161   address_difference_magnitude =
00162     previous_address[binary_record.tag] -
00163     binary_record.virtual_address;
00164 
00165       } else {
00166 
00167   address_difference_sign = '+';
00168   address_difference_magnitude =
00169     binary_record.virtual_address - 
00170     previous_address[binary_record.tag];
00171 
00172       }
00173       previous_address[binary_record.tag] =
00174   binary_record.virtual_address;
00175 
00176       printf("%c %qx %hx %lx %c %lx\n",
00177        binary_record.tag,
00178        timestamp_difference,
00179        binary_record.length,
00180        address_space_ID,
00181        address_difference_sign,
00182        address_difference_magnitude);
00183 
00184       record_number++;
00185 
00186     }
00187 
00188   } while (binary_record.tag != TAG_END_OF_TRACE);
00189 
00190 } // process_trace


Variable Documentation

const tag_t TAG_END_OF_TRACE = 'e'
 

The tag to mark the end of the trace.

Definition at line 64 of file main.cc.

Referenced by process_trace().


Generated on Tue Jan 21 10:43:36 2003 for instruction-level-reduction by doxygen1.3-rc2