SourceForge.net Logo
Home

Manipulate Hardware Performance Counter Events

mpcnt

Manipulate P6/P4/AMD64/EM64T hardware performance counters.

mpcnt -s ctr cccr escr <msr value <msr value>>   (START P4/EM64T)
      -s ctr evtsel                              (START P6/AMD64)
      -p ctr <ctr ...>                           (PAUSE (STOP))
      -u ctr <ctr ...>                           (RESUME)
      -z ctr <ctr ...>                           (ZERO (RESET))
      -r ctr <ctr ...>                           (READ)
      -q ctr <ctr ...>                           (READ INTERACTIVE)
      -qf ctr <ctr ...> <-f fn> <-t sec>         (READ TO FILE)
      -qso ctr <ctr ...> <-t sec>                (READ TO STDOUT)
                         <-c target_cpu>         (Target CPU)
Where:
------
       ***** Command verbs *****
  -s
  -start
     Stars the requested performance counter on requested processors
     - ctr specifies a counter number or name
     - P6/AMD64:
       * evtsel specifies the 32-bit value of the Event Select
         register associated with the counter. The actual Event
         Select registger number is implied from the counter number.
     - P4/EM64T:
       * cccr specifies the 32-bit value of the CCCR register
         associated with the counter.
       * escr specifies the 32-bit value of the ESCR register
         associated with the counter/CCCR value.
       * msr/value is an MSR number/value pair required to set up the
         counter. Neither one is checked for validity.
 -p
  -pause
     Pauses (stops) the requested counters. The counters stop counting.
     The counter contents is left unchanged.

  -u
  -resume
     Resumes (unpauses?) the requested counters. The counters resume
     counting from where they left off.

  -z
  -reset
     Resets (clears) the requested counters. The counter is set
     to zero. If counting is not stopped the counter continues counting.

  -r
  -read
     Read and display contents of requested counters.

  -q
  -query
     Read and display contents of requestes counter and go into input mode.
     - From input mode you can Query (again) or End the current event.
     - Output to STDOUT.

  -qf
  -queryf
     Read contents of requested counters continually.
     - Output to 'ctr.out' file, unless -f option specified.
     - Read time interval is 1 second unless -t is specified.

  -qso
  -queryso
     Read contents of requested counters continually.
     - Output to STDOUT.
     - Read time interval is 1 second unless -t is specified.

       ***** Command modifiers *****

  -c target_cpu
  -cpu target_cpu
     Specifies the processor(s) to which the requested command is sent.
     Valid values for target_cpu are:
     - The word 'all'. This is the default.
     - A cpu number
     - A cpu name in the form CPU#
     - The word 'LP0'. This means the Logical 0 (even) CPUs in a
       HyperThreaded physical CPU.
     - The word 'LP1'. This means the Logical 1 (odd) CPUs in a
       HyperThreaded physical CPU.

  -f fn
  -file fn
    Specifies filename where read values will be written to.

  -t sec
  -time sec
    Specifies time interval time, in seconds, between event reads.
Notes:
------
 1) It is *YOUR RESPONSIBILITY* to know and understand what you are doing.
    If you're not sure, don't do it and take a look at the processor documentation.
 2) mpcnt **DOES NOT** work on P5 (Pentium) machines.
 3) On P6 systems you must remember that both counters are started/stopped
    using PerfEvtSel0. That means if you want the counters to count you
    must start some event on counter 0.
 4) Given number 3 above, you can't stop a single counter on a P6 system.
    When you say "stop/pause a counter" you are really saying "stop/pause
    *BOTH* counters."
 5) mpcnt accepts the correct form of the start command based on the
    machine you are running.
 6) If you specify options that are not applicable to the command they
    will be ignored. For example, if you specify the -f and/or -t option with
    -s, both will be ignored.
 7) If you specify conflicting/duplicate options then the right-most option
    is used. For example, if you specify the -f option twice, then the value
    given with the rightmost -f will be used.

Examples:
---------
  1) mpcnt -s ctr0 0x00430079
     - On a P6 processor, set ctr0 to count CPU_CYCLES_UNHALTED.
  2) mpcnt -s ctr1 0x004300c0
     - On a P6 processor, set ctr1 to count INSTR_RETIRED.
  3) mpcnt -s ctr1 0x01234567
     - On a P6 processor, set ctr0 to count whatever 0x01234567 means.
  4) mpcnt -s ctr12 0x00039000 0x0400060c
     - On a P4/EM64T processor, set ctr12 to count non-bogus Instr_retired.
  5) mpcnt -s 3 0x00037000 0x3000040c
     - On a P4/EM64T processor, set ctr3 to count ITLB_misses.
  6) mpcnt -s 1 0x004300c0
     - On an AMD64 processor, set ctr1 to count RETIRED_X86_INSTR.
  7) mpcnt -s 3 0x004300c1
     - On an AMD64 processor, set ctr1 to count RETIRED_UOPS.

Home