// 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"utils.h"#include"osnoise.h"#include"timerlat.h"#include"timerlat_aa.h"#include"timerlat_u.h"structtimerlat_top_params{char*cpus;cpu_set_tmonitored_cpus;char*trace_output;char*cgroup_name;unsignedlonglongruntime;longlongstop_us;longlongstop_total_us;longlongtimerlat_period_us;longlongprint_stack;intsleep_time;intoutput_divisor;intduration;intquiet;intset_sched;intdma_latency;intno_aa;intaa_only;intdump_tasks;intcgroup;inthk_cpus;intuser_top;intuser_workload;intkernel_workload;intpretty_output;intwarmup;intbuffer_size;intdeepest_idle_state;cpu_set_thk_cpu_set;structsched_attrsched_param;structtrace_events*events;};structtimerlat_top_cpu{unsignedlonglongirq_count;unsignedlonglongthread_count;unsignedlonglonguser_count;unsignedlonglongcur_irq;unsignedlonglongmin_irq;unsignedlonglongsum_irq;unsignedlonglongmax_irq;unsignedlonglongcur_thread;unsignedlonglongmin_thread;unsignedlonglongsum_thread;unsignedlonglongmax_thread;unsignedlonglongcur_user;unsignedlonglongmin_user;unsignedlonglongsum_user;unsignedlonglongmax_user;};structtimerlat_top_data{structtimerlat_top_cpu*cpu_data;intnr_cpus;};/* * timerlat_free_top - free runtime data */staticvoidtimerlat_free_top(structtimerlat_top_data*data){free(data->cpu_data);free(data);}/* * timerlat_alloc_histogram - alloc runtime data */staticstructtimerlat_top_data*timerlat_alloc_top(intnr_cpus){structtimerlat_top_data*data;intcpu;data=calloc(1,sizeof(*data));if(!data)returnNULL;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)gotocleanup;/* set the min to max */for(cpu=0;cpu<nr_cpus;cpu++){data->cpu_data[cpu].min_irq=