+static double get_bench_time(cycles_t before, cycles_t after)
+{
+ double ret;
+
+ ret = (((double)(after - before) / (g_freq / 1000.0)) / 1000000000.0);
+
+ return ret;
+}
+
+void bench_init(void)
+{
+ open_logs();
+ if (g_freq == 0) {
+ g_freq = calibrate_cpu_freq();
+ //fprintf(fp, "CPU frequency %f Ghz\n\n", g_freq);
+ }
+}
+
+void bench_close(void)
+{
+ close_logs();
+ printf("Benchmark results in %s\n", RESULTS_FILE_NAME);
+}
+
+double bench_get_create_session(void)
+{
+ if ((time_create_session_start == 0) &&
+ (time_create_session_end == 0)) {
+ fprintf(fp, "NO DATA\n");
+ return 0;
+ }
+
+ return get_bench_time(time_create_session_start, time_create_session_end);
+}
+
+double bench_get_destroy_session(void)
+{
+ if ((time_destroy_session_start == 0) &&
+ (time_destroy_session_end == 0)) {
+ fprintf(fp, "NO DATA\n");
+ return 0;
+ }
+
+ return get_bench_time(time_destroy_session_start, time_destroy_session_end);
+}
+
+/*
+ * Complete UST notification process time break down in different actions.
+ */
+void bench_print_ust_notification(void)
+{
+ double res, total = 0;
+
+ fprintf(fp, "--- UST notification time ---\n");
+
+ if (time_ust_notify_mmap_start == 0 || time_ust_notify_mmap_stop == 0) {
+ goto no_data;
+ }
+
+ res = get_bench_time(time_ust_notify_mmap_start,
+ time_ust_notify_mmap_stop);
+ fprintf(fp, "mmap() call time\n");
+ fprintf(fp, "Time: %.20f sec.\n", res);
+
+ total += res;
+
+ if (time_ust_notify_perms_start == 0 || time_ust_notify_perms_stop == 0) {
+ goto no_data;
+ }
+
+ res = get_bench_time(time_ust_notify_perms_start,
+ time_ust_notify_perms_stop);
+ fprintf(fp, "Setting permissions (chown/chmod)\n");
+ fprintf(fp, "Time: %.20f sec.\n", res);
+
+ total += res;
+
+ if (time_ust_notify_shm_start == 0 || time_ust_notify_shm_stop == 0) {
+ goto no_data;
+ }
+
+ res = get_bench_time(time_ust_notify_shm_start,
+ time_ust_notify_shm_stop);
+ fprintf(fp, "shm_open/ftruncate/fchmod\n");
+ fprintf(fp, "Time: %.20f sec.\n", res);
+
+ total += res;
+
+ fprintf(fp, "Global UST nonification time\n");
+ fprintf(fp, "Time: %.20f sec.\n", total);
+ return;
+
+no_data:
+ fprintf(fp, "NO DATA\n");
+ return;
+}
+
+/*
+ * Time taken by an UST apps to unregister.
+ */
+void bench_print_ust_unregister(void)
+{
+ double res;
+
+ fprintf(fp, "--- UST unregister time ---\n");
+
+ if (time_ust_unregister_start == 0 || time_ust_unregister_stop == 0) {
+ goto no_data;
+ }
+
+ res = get_bench_time(time_ust_unregister_start, time_ust_unregister_stop);
+ fprintf(fp, "UST unregister time\n");
+ fprintf(fp, "Time: %.20f sec.\n", res);
+ return;
+
+no_data:
+ fprintf(fp, "NO DATA\n");
+ return;
+}
+
+/*
+ * This time value is only coherent is an UST application registered.
+ */
+void bench_print_ust_register(void)
+{
+ double res, total = 0;
+
+ fprintf(fp, "--- UST registration time ---\n");
+
+ if (time_ust_register_start == 0 || time_ust_register_stop == 0) {
+ goto no_data;