GithubHelp home page GithubHelp logo

clocks's Introduction

Code to test various clocks under Linux (and OSX)

Some quick notes on the code:

  • The ClockTest.sh script compiles the code, and executes the test programs. It uses taskset to ensure that the tests don't migrate to different CPUs. (taskset is done only for the C++ test – the JVM uses so many threads that pinning them all to a single CPU is probably not a good idea). You'll need to modify the script to specify the correct location for JAVA_HOME on your system, or set JAVA_HOME prior to calling the script.

  • The script detects whether the rdtscp instruction is available by querying /proc/cpuinfo. If not, it bypasses that code (which would otherwise throw a SIGILL).

  • You can also pass in the CPU frequency, in GHz. If you don't, then a frequency of 1 is used, which has the effect of returning the tick count unmodified for those clock sources that use tick counts (i.e., anything having to do with the RDTSC instruction).

  • If the script doesn't seem to be working, execute it with “bash -xv ClockTest.sh” to see the actual commands.

© Copyright 2014 by Bill Torpey. All Rights Reserved.

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

clocks's People

Contributors

btorpey avatar carl-mastrangelo avatar wallstprog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

clocks's Issues

Fix for crash if BUCKETS changed

The code does a bit-wise AND with 255 of the iteration step to find the location where to store the sample; this obviously only works if the number of buckets is 255, and usually leads to crazy results or crashes otherwise.
The fix is trivial - do a modulo operation instead. Code diff below:

diff --git a/ClockBench.cpp b/ClockBench.cpp
index 8b73921..680e641 100755
--- a/ClockBench.cpp
+++ b/ClockBench.cpp
@@ -168,7 +168,7 @@ int main(int argc, char** argv)

    {
       for (int i = 0; i < ITERS * BUCKETS; ++i) {
-         int n = i & 0xff;
+         int n = i % BUCKETS;
          timestamp[n] = cpuid_rdtsc();
       }
       for (int i = 0; i < BUCKETS; ++i) {
@@ -183,7 +183,7 @@ int main(int argc, char** argv)
    #ifdef RDTSCP
    {
       for (int i = 0; i < ITERS * BUCKETS; ++i) {
-         int n = i & 0xff;
+         int n = i % BUCKETS;
          timestamp[n] = rdtscp();
       }
       for (int i = 0; i < BUCKETS; ++i) {
@@ -193,11 +193,11 @@ int main(int argc, char** argv)
       x.print();
       x.dump(file);
    }
-   #endif
+  #endif

    {
       for (int i = 0; i < ITERS * BUCKETS; ++i) {
-         int n = i & 0xff;
+         int n = i % BUCKETS;
          timestamp[n] = rdtsc();
       }
       for (int i = 0; i < BUCKETS; ++i) {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.