perf bench numa: Use NSEC_PER_U?SEC
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 8 Aug 2016 14:55:38 +0000 (11:55 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 23 Aug 2016 18:37:33 +0000 (15:37 -0300)
Following kernel practices, using linux/time64.h

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-7vnv15263y50qku76p4w5xk6@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/bench/numa.c

index f7f530081aa9421a0e01ae362fa02c3192c2896c..8efe904e486bf98b63e24b7904652f10ca5ec7e9 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/wait.h>
 #include <sys/prctl.h>
 #include <sys/types.h>
+#include <linux/time64.h>
 
 #include <numa.h>
 #include <numaif.h>
@@ -1004,7 +1005,7 @@ static void calc_convergence(double runtime_ns_max, double *convergence)
        if (strong && process_groups == g->p.nr_proc) {
                if (!*convergence) {
                        *convergence = runtime_ns_max;
-                       tprintf(" (%6.1fs converged)\n", *convergence/1e9);
+                       tprintf(" (%6.1fs converged)\n", *convergence / NSEC_PER_SEC);
                        if (g->p.measure_convergence) {
                                g->all_converged = true;
                                g->stop_work = true;
@@ -1012,7 +1013,7 @@ static void calc_convergence(double runtime_ns_max, double *convergence)
                }
        } else {
                if (*convergence) {
-                       tprintf(" (%6.1fs de-converged)", runtime_ns_max/1e9);
+                       tprintf(" (%6.1fs de-converged)", runtime_ns_max / NSEC_PER_SEC);
                        *convergence = 0;
                }
                tprintf("\n");
@@ -1022,7 +1023,7 @@ static void calc_convergence(double runtime_ns_max, double *convergence)
 static void show_summary(double runtime_ns_max, int l, double *convergence)
 {
        tprintf("\r #  %5.1f%%  [%.1f mins]",
-               (double)(l+1)/g->p.nr_loops*100.0, runtime_ns_max/1e9 / 60.0);
+               (double)(l+1)/g->p.nr_loops*100.0, runtime_ns_max / NSEC_PER_SEC / 60.0);
 
        calc_convergence(runtime_ns_max, convergence);
 
@@ -1179,8 +1180,8 @@ static void *worker_thread(void *__tdata)
 
                if (details >= 3) {
                        timersub(&stop, &start, &diff);
-                       runtime_ns_max = diff.tv_sec * 1000000000;
-                       runtime_ns_max += diff.tv_usec * 1000;
+                       runtime_ns_max = diff.tv_sec * NSEC_PER_SEC;
+                       runtime_ns_max += diff.tv_usec * NSEC_PER_USEC;
 
                        if (details >= 0) {
                                printf(" #%2d / %2d: %14.2lf nsecs/op [val: %016"PRIx64"]\n",
@@ -1192,23 +1193,23 @@ static void *worker_thread(void *__tdata)
                        continue;
 
                timersub(&stop, &start0, &diff);
-               runtime_ns_max = diff.tv_sec * 1000000000ULL;
-               runtime_ns_max += diff.tv_usec * 1000ULL;
+               runtime_ns_max = diff.tv_sec * NSEC_PER_SEC;
+               runtime_ns_max += diff.tv_usec * NSEC_PER_USEC;
 
                show_summary(runtime_ns_max, l, &convergence);
        }
 
        gettimeofday(&stop, NULL);
        timersub(&stop, &start0, &diff);
-       td->runtime_ns = diff.tv_sec * 1000000000ULL;
-       td->runtime_ns += diff.tv_usec * 1000ULL;
-       td->speed_gbs = bytes_done / (td->runtime_ns / 1e9) / 1e9;
+       td->runtime_ns = diff.tv_sec * NSEC_PER_SEC;
+       td->runtime_ns += diff.tv_usec * NSEC_PER_USEC;
+       td->speed_gbs = bytes_done / (td->runtime_ns / NSEC_PER_SEC) / 1e9;
 
        getrusage(RUSAGE_THREAD, &rusage);
-       td->system_time_ns = rusage.ru_stime.tv_sec * 1000000000ULL;
-       td->system_time_ns += rusage.ru_stime.tv_usec * 1000ULL;
-       td->user_time_ns = rusage.ru_utime.tv_sec * 1000000000ULL;
-       td->user_time_ns += rusage.ru_utime.tv_usec * 1000ULL;
+       td->system_time_ns = rusage.ru_stime.tv_sec * NSEC_PER_SEC;
+       td->system_time_ns += rusage.ru_stime.tv_usec * NSEC_PER_USEC;
+       td->user_time_ns = rusage.ru_utime.tv_sec * NSEC_PER_SEC;
+       td->user_time_ns += rusage.ru_utime.tv_usec * NSEC_PER_USEC;
 
        free_data(thread_data, g->p.bytes_thread);
 
@@ -1469,7 +1470,7 @@ static int __bench_numa(const char *name)
        }
        /* Wait for all the threads to start up: */
        while (g->nr_tasks_started != g->p.nr_tasks)
-               usleep(1000);
+               usleep(USEC_PER_MSEC);
 
        BUG_ON(g->nr_tasks_started != g->p.nr_tasks);
 
@@ -1488,9 +1489,9 @@ static int __bench_numa(const char *name)
 
                timersub(&stop, &start, &diff);
 
-               startup_sec = diff.tv_sec * 1000000000.0;
-               startup_sec += diff.tv_usec * 1000.0;
-               startup_sec /= 1e9;
+               startup_sec = diff.tv_sec * NSEC_PER_SEC;
+               startup_sec += diff.tv_usec * NSEC_PER_USEC;
+               startup_sec /= NSEC_PER_SEC;
 
                tprintf(" threads initialized in %.6f seconds.\n", startup_sec);
                tprintf(" #\n");
@@ -1529,14 +1530,14 @@ static int __bench_numa(const char *name)
        tprintf("\n ###\n");
        tprintf("\n");
 
-       runtime_sec_max = diff.tv_sec * 1000000000.0;
-       runtime_sec_max += diff.tv_usec * 1000.0;
-       runtime_sec_max /= 1e9;
+       runtime_sec_max = diff.tv_sec * NSEC_PER_SEC;
+       runtime_sec_max += diff.tv_usec * NSEC_PER_USEC;
+       runtime_sec_max /= NSEC_PER_SEC;
 
-       runtime_sec_min = runtime_ns_min/1e9;
+       runtime_sec_min = runtime_ns_min / NSEC_PER_SEC;
 
        bytes = g->bytes_done;
-       runtime_avg = (double)runtime_ns_sum / g->p.nr_tasks / 1e9;
+       runtime_avg = (double)runtime_ns_sum / g->p.nr_tasks / NSEC_PER_SEC;
 
        if (g->p.measure_convergence) {
                print_res(name, runtime_sec_max,
@@ -1562,7 +1563,7 @@ static int __bench_numa(const char *name)
        print_res(name, bytes / 1e9,
                "GB,", "data-total",            "GB data processed, total");
 
-       print_res(name, runtime_sec_max * 1e9 / (bytes / g->p.nr_tasks),
+       print_res(name, runtime_sec_max * NSEC_PER_SEC / (bytes / g->p.nr_tasks),
                "nsecs,", "runtime/byte/thread","nsecs/byte/thread runtime");
 
        print_res(name, bytes / g->p.nr_tasks / 1e9 / runtime_sec_max,
@@ -1581,9 +1582,9 @@ static int __bench_numa(const char *name)
                                snprintf(tname, 32, "process%d:thread%d", p, t);
                                print_res(tname, td->speed_gbs,
                                        "GB/sec",       "thread-speed", "GB/sec/thread speed");
-                               print_res(tname, td->system_time_ns / 1e9,
+                               print_res(tname, td->system_time_ns / NSEC_PER_SEC,
                                        "secs", "thread-system-time", "system CPU time/thread");
-                               print_res(tname, td->user_time_ns / 1e9,
+                               print_res(tname, td->user_time_ns / NSEC_PER_SEC,
                                        "secs", "thread-user-time", "user CPU time/thread");
                        }
                }