[botan-devel] Set the cpu speed in the environment or command line for ./botan speed

Jeffrey Walton noloader at gmail.com
Thu Mar 8 08:54:53 EST 2018

On Thu, Mar 8, 2018 at 8:48 AM, Jack Lloyd <jack at randombit.net> wrote:
> On Thu, Mar 08, 2018 at 12:52:16PM +0000, Uri Blumenthal wrote:
>> I'd like to see something like --cpu-clock-speed, instead of or in addition to the --cpu-clock-ratio.
>> Reason: for some CPUs one *cannot accurately* measure their clocks, so an approach that requires knowing *both* the measured and the claimed clocks is bound to fail. Which is why what @noloader is asking for makes perfect sense.
> I am not understanding how a specified clock speed would be at all
> useful.
> speed measures intervals based on wall time (whatever clock_gettime or
> std::chrono::system_clock returns). Whenever a timer starts or stops,
> it also gets the value of the cycle counter (if it is available). So
> if initial cycle counter was C1 and finish cycle counter was C2, and
> our interval was (wall clock) 1 second, then we know the clock ticks
> at (C2-C1) Hz.
> So the only question would be, if the clocks Hz matches the "clock
> speed" of the machine, ie the rate of instruction dispatch. That just
> affects reporting, where we convert "cycle counts as the machine
> reports them" to "cycles as you the human expect them to be on this
> machine". Which is what the ratio is for.
> Imagine having --cpu-clock-speed instead of a ratio. Say the user sets
> it to 1000 (ie the CPU clock ticks 1000 times per second).  Again we
> measure a 1 second wall clock time interval. We find the cycle counter
> had values C1 at start and C2 at end. Say they had values 500 and
> 2000. Then we know (as with prior) that the clock ticks at 1500 times
> per second. But the user has claimed it ticks at 1000 times per
> second. Which would imply that 1.5 seconds had passed, instead of the
> 1 second we measured on the clock. I don't see what one could do at
> this point besides spit out an error since obviously something is
> incorrect.
> Now, something like --cpu-clock-speed would be very useful *IF* our
> native measurement of operations was in cycles, and then we were
> converting that to time intervals. But the speed util doesn't work
> that way.
> Maybe I'm missing something, if so let me know!

Here's what I see on my LeMaker HiKey:

    $ ./botan speed --msec=3000 SHA-1 SHA-224 SHA-256
    SHA-160 hash buffer size 1024 bytes: 664.520 MiB/sec (1993.561 MiB
in 3000.001 ms)
    SHA-224 hash buffer size 1024 bytes: 599.788 MiB/sec (1799.363 MiB
in 3000.000 ms)
    SHA-256 hash buffer size 1024 bytes: 599.463 MiB/sec (1798.391 MiB
in 3000.001 ms)

Notice it is missing a cpb measurement.

If I can, say --cpu-clock-freq=1.2 (GiHz), then Botan can calculate
the cpb for me.

To be clear, I'm only interested in the cpb count. That is the way I
measure an implementation's performance.


More information about the botan-devel mailing list