Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Basic_Consumer.cc

Go to the documentation of this file.
00001 // ===================================================================
00002 // Basic_Consumer.cc
00003 // Scott F. H. Kaplan -- sfkaplan@cs.amherst.edu
00004 // October 2002
00005 
00006 // A subclass of Consumer that emits a basic page-level reference
00007 // trace with no extra information about shared space or multiple
00008 // processes.  Canonical page numbers are emitted, however, so that
00009 // shared pages are not multiply counted.  The trace takes the
00010 // following form:
00011 //
00012 //   R 14fe3
00013 //
00014 // The first field is the ``type tag'':  A single character, either
00015 // 'R' or 'W', to indicate whether or not the reference is a read or a
00016 // write.  Note that this trace format does not distinguish between
00017 // kernel and user references.  Instruction references are considered
00018 // read operations.
00019 //
00020 // The second field is the page number: A hexidecimal value giving the
00021 // canonical page number being referenced.
00022 // ===================================================================
00023 
00024 
00025 
00026 // ===================================================================
00027 // INCLUDES
00028 
00029 #include "Basic_Consumer.hh"
00030 // ===================================================================
00031 
00032 
00033 
00034 // ===================================================================
00035 Basic_Consumer::Basic_Consumer (Reference_Reader* const reference_reader,
00036         const char* const kernel_pathname,
00037         const char* const output_file_pathname) :
00038   Consumer(reference_reader, kernel_pathname) {
00039 
00040   // Open the output file, checking for success.
00041   output_stream = fopen(output_file_pathname, "w");
00042   if (output_stream == NULL) {
00043     perror("Failure opening output file");
00044     exit(1);
00045   }
00046 
00047 } // Basic_Consumer::Basic_Consumer
00048 // ===================================================================
00049 
00050 
00051 
00052 // ===================================================================
00053 Basic_Consumer::~Basic_Consumer () {
00054 
00055   // Close the output file, checking for success.
00056   int close_result = fclose(output_stream);
00057   if (close_result == EOF) {
00058     perror("Failure closing output file");
00059     exit(1);
00060   }
00061 
00062 } // Basic_Consumer::~Basic_Consumer
00063 // ===================================================================
00064 
00065 
00066 
00067 // ===================================================================
00068 void
00069 Basic_Consumer::act_on_reference_record () {
00070 
00071   // Convert the input record's tag to a valid output tag.
00072   tag_t output_tag = 0;
00073   switch (reference_record->tag) {
00074     
00075   case TAG_USER_READ:
00076   case TAG_KERNEL_READ:
00077   case TAG_USER_INSTRUCTION_FETCH:
00078   case TAG_KERNEL_INSTRUCTION_FETCH:
00079 
00080     output_tag = TAG_KERNEL_READ;
00081     break;
00082 
00083   case TAG_USER_WRITE:
00084   case TAG_KERNEL_WRITE:
00085 
00086     output_tag = TAG_KERNEL_WRITE;
00087     break;
00088 
00089   default:
00090     fprintf(stderr,
00091       "act_on_reference_record(): Invalid tag %c(%d)\n",
00092       reference_record->tag,
00093       (int)reference_record->tag);
00094     exit(1);
00095 
00096   }
00097 
00098   // If the page referenced is in the kernel's address range, we need
00099   // to use the kernel's context.
00100   context_ID_t context_ID;
00101   if (reference_record->virtual_page.page_ID <
00102       KERNEL_VIRTUAL_PAGE_OFFSET) {
00103 
00104     context_ID = reference_record->virtual_page.context_ID;
00105 
00106   } else {
00107 
00108     context_ID = KERNEL_CONTEXT;
00109 
00110   }
00111   Process* process = safe_context_ID_to_process(context_ID);
00112   virtual_to_canonical_map_t* map = process->virtual_to_canonical_map;
00113 
00114   // Lookup the canonical page ID if one exists.
00115   bool V2C_mapping_exists;
00116   canonical_page_ID_t canonical_page_ID;
00117   lookup_canonical_page_ID(&V2C_mapping_exists,
00118        &canonical_page_ID,
00119        map,
00120        reference_record->virtual_page.page_ID);
00121 
00122   // Emit the new record only if a mapping was found (that is, if this
00123   // is not a reference to a buffer cache page).
00124   if (V2C_mapping_exists) {
00125     fprintf(output_stream, "%c %lx\n", output_tag, canonical_page_ID);
00126   }
00127 
00128 } // act_on_reference_record
00129 // ===================================================================

Generated on Fri Jan 31 10:33:33 2003 for Laplace-merge by doxygen1.3-rc2