#include "builtin.h"
#include "util/util.h"
#include "util/cache.h"
#include "util/symbol.h"
#include "util/thread.h"
#include "util/header.h"
#include "util/parse-options.h"
#include "perf.h"
#include "util/debug.h"
#include "util/trace-event.h"
#include <sys/types.h>
static char const *input_name = "perf.data";
static int input;
static unsigned long page_size;
static unsigned long mmap_window = 32;
static unsigned long total_comm = 0;
static struct rb_root threads;
static struct thread *last_match;
static struct perf_header *header;
static u64 sample_type;
/*
* Scheduler benchmarks
*/
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/prctl.h>
#include <linux/unistd.h>
#include <semaphore.h>
#include <pthread.h>
#include <signal.h>
#include <values.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>
#include <fcntl.h>
#include <time.h>
#include <math.h>
#include <stdio.h>
#define PR_SET_NAME 15 /* Set process name */
#define BUG_ON(x) assert(!(x))
#define DEBUG 0
typedef unsigned long long nsec_t;
#define printk(x...) do { printf(x); fflush(stdout); } while (0)
nsec_t prev_printk;
#define __dprintk(x,y...) do { \
nsec_t __now = get_nsecs(), __delta = __now - prev_printk; \
\
prev_printk = __now; \
\
printf("%.3f [%Ld] [%.3f]: " x, (double)__now/1e6, __now, (double)__delta/1e6, y);\
} while (0)
#if !DEBUG
# define dprintk(x...) do { } while (0)
#else
# define dprintk(x...) __dprintk(x)
#endif
#define __DP() __dprintk("parent: line %d\n", __LINE__)
#define DP() dprintk("parent: line %d\n", __LINE__)
#define D() dprintk("task %ld: line %d\n", this_task->nr, __LINE__)
static nsec_t run_measurement_overhead;
static nsec_t sleep_measurement_overhead;
static nsec_t get_nsecs(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
}
static void burn_nsecs(nsec_t nsecs)
{
nsec_t T0 = get_nsecs(), T1;
do {
T1 = get_nsecs();
} while (T1 + run_measurement_overhead < T0 + nsecs);
}
static void sleep_nsecs(nsec_t nsecs)
{
struct timespec ts;
ts.tv_nsec = nsecs % 999999999;
ts.tv_sec = nsecs / 999999999;
nanosleep(&ts, NULL);
}
static void calibrate_run_measurement_overhead(void)
{
nsec_t T0, T1, delta, min_delta = 1000000000ULL;
int i;
for (i = 0; i < 10; i++) {
T0 = get_nsecs();
burn_nsecs(0);
T1 = get_nsecs();
delta = T1-T0;
min_delta = min(min_delta, delta);
}
run_measurement_overhead = min_delta;
printk("run measurement overhead: %Ld nsecs\n", min_delta);
}
static void calibrate_sleep_measurement_overhead(void)
{
nsec_t T0, T1, delta, min_delta = 1000000000ULL;
int i;
for (i = 0; i