User Component
- Parse command-line arguments. Since you usually want to bind your
process to a CPU to prevent migration, it would be handy to be
able to specify which CPU you wish to be bound to. By default,
the process is bound to CPU 0, but by specifying the "-r " option,
you can dictate which CPU on which you wish the program to be bound.
- Bind to the specified processor (CPU 0 by default).
- Get a handle to the Perfmon device driver by opening
/dev/perfmon
.
- Set the PCR register to accumulate CPU cycles in PIC0 and instructions
executed in PIC1 while in user mode. This can be easily changed.
- Run an example function. This includes the following steps to get
accurate data:
- Call gethrtime() to get the current value of the hi-res clock.
- Call clr_pic() to clear the values of both PIC registers (this
is to help prevent overflow from occurring).
- Call cpu_sync(), which ensures that all previous instructions and
memory references have completed execution.
- Get the current value of both PIC registers.
- Call the function that does the computations in which you're
interested.
- Call cpu_sync().
- Get the current value of both PIC registers.
- Call gethrtime().
- Lastly, the elapsed wall-clock time, instructions executed, CPU cycles
taken, and CPI are calculated and printed.