These days, I am trying to use perf to evaluate my codes. I found there are two hardware events which are reference cpu cycles and cpu cycles. And I know ref-cpu-cycles is working at the fixed cpu frequency, and cpu-cycles could be changed along with frequency scaling. Now what I am confused about is whether I could use this ref-cpu-cycles to get a piece of code's execution time? How to get the fixed cpu frequency? From /proc/cpuinfo? However, according to my knowledge, there is no real time concept in cpu except the real-time system. So, how this ref-cpu-cycles works? How to get the fixed cpu frequency? Does it have some connections with the external real time clock (RTC)?
In addition, modern cpu could process much more than necessary instructions. The hw event - instructions - in perf is to count the retired instructions which only includes the necessary instructions. If it is like this, however it seems that the ref-cpu-cycles/cpu-cycles also counts cycles when unnecessary instructions are being executed.
I don't know whether I clarified my question. Or maybe I am totally wrong. Could some help me?