// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
*/
#define _GNU_SOURCE
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <errno.h>
#include <sched.h>
#include <pthread.h>
#include "timerlat.h"
#include "timerlat_aa.h"
#include "timerlat_u.h"
#include "timerlat_bpf.h"
struct timerlat_top_cpu {
unsigned long long irq_count;
unsigned long long thread_count;
unsigned long long user_count;
unsigned long long cur_irq;
unsigned long long min_irq;
unsigned long long sum_irq;
unsigned long long max_irq;
unsigned long long cur_thread;
unsigned long long min_thread;
unsigned long long sum_thread;
unsigned long long max_thread;
unsigned long long cur_user;
unsigned long long min_user;
unsigned long long sum_user;
unsigned long long max_user;
};
struct timerlat_top_data {
struct timerlat_top_cpu *cpu_data;
int nr_cpus;
};
/*
* timerlat_free_top - free runtime data
*/
static void
timerlat_free_top(struct timerlat_top_data *data)
{
free(data->cpu_data);
free(data);
}
/*
* timerlat_alloc_histogram - alloc runtime data
*/
static struct timerlat_top_data *timerlat_alloc_top(int nr_cpus)
{
struct timerlat_top_data *data;
int cpu;
data = calloc(1, sizeof(*data));
if (!data)
return NULL;
data->nr_cpus = nr_cpus;
/* one set of histograms per CPU */
data->cpu_data = calloc(1, sizeof(*data->cpu_data) * nr_cpus);
if (!data->cpu_data)
goto cleanup;
/* set the min to max */
for (cpu = 0; cpu < nr_cpus; cpu++) {
data->cpu_data[cpu].min_irq = ~0;
data->cpu_data[cpu].min_thread = ~0;
data->cpu_data[cpu].min_user = ~0;
}
return data;
cleanup:
timerlat_free_top(data);
return NULL;
}
static void
timerlat_top_reset_sum(struct timerlat_top_cpu *summary)
{
memset(summary, 0, sizeof(*summary));
summary->min_irq = ~0;
summary->min_thread =