From 38d57c13494cca80decdf9cd275d62795bd12c00 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Wed, 12 Jan 2022 17:48:44 +0100 Subject: [PATCH] mpstat: Don't use read_stat_irq() function mpstat used read_stat_irq() function from rd_stats.c to get the total number of interrupts among all processors. This function is to be heavily modified to deal with sar's new interrupts statistics report. So create a new function which will be used only by mpstat and include it in its code. Signed-off-by: Sebastien GODARD --- mpstat.c | 61 +++++++++++++++++++++++++++++++++++++++++++------------- mpstat.h | 11 ++++++++-- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/mpstat.c b/mpstat.c index f6bd297..0c0d409 100644 --- a/mpstat.c +++ b/mpstat.c @@ -31,7 +31,6 @@ #include "version.h" #include "mpstat.h" -#include "rd_stats.h" #include "count.h" #include /* For setlocale() */ @@ -61,7 +60,7 @@ struct stats_cpu *st_node[3]; * Structure used to save total number of interrupts received * among all CPU and for each CPU. */ -struct stats_irq *st_irq[3]; +struct stats_global_irq *st_irq[3]; /* * Structures used to save, for each interrupt, the number @@ -198,12 +197,12 @@ void salloc_mp_struct(int nr_cpus) } memset(st_node[i], 0, STATS_CPU_SIZE * nr_cpus); - if ((st_irq[i] = (struct stats_irq *) malloc(STATS_IRQ_SIZE * nr_cpus)) + if ((st_irq[i] = (struct stats_global_irq *) malloc(STATS_GLOBAL_IRQ_SIZE * nr_cpus)) == NULL) { perror("malloc"); exit(4); } - memset(st_irq[i], 0, STATS_IRQ_SIZE * nr_cpus); + memset(st_irq[i], 0, STATS_GLOBAL_IRQ_SIZE * nr_cpus); if ((st_irqcpu[i] = (struct stats_irqcpu *) malloc(STATS_IRQCPU_SIZE * nr_cpus * irqcpu_nr)) == NULL) { @@ -286,7 +285,7 @@ void sfree_mp_struct(void) void fwd_irq_values(struct stats_irqcpu *st_ic[], unsigned int c, unsigned int last, int ic_nr, int curr) { - struct stats_irq *st_irq_i, *st_irq_j; + struct stats_global_irq *st_irq_i, *st_irq_j; struct stats_irqcpu *p, *q; int j; @@ -1202,7 +1201,7 @@ void write_plain_isumcpu_stats(int dis, unsigned long long itv, int prev, int cu char *prev_string, char *curr_string, unsigned char offline_cpu_bitmap[]) { struct stats_cpu *scc, *scp; - struct stats_irq *sic, *sip; + struct stats_global_irq *sic, *sip; unsigned long long pc_itv; int cpu; @@ -1271,7 +1270,7 @@ void write_json_isumcpu_stats(int tab, unsigned long long itv, int prev, int cur unsigned char offline_cpu_bitmap[]) { struct stats_cpu *scc, *scp; - struct stats_irq *sic, *sip; + struct stats_global_irq *sic, *sip; unsigned long long pc_itv; int cpu, next = FALSE; @@ -1792,6 +1791,39 @@ void write_stats(int curr, int dis) write_stats_core(!curr, curr, dis, cur_time[!curr], cur_time[curr]); } +/* + *************************************************************************** + * Read total number of interrupts from /proc/stat. + * + * IN: + * @st_irq Structure where total number of interrupts will be saved. + * + * OUT: + * @st_irq Structure with total number of interrupts. + *************************************************************************** + */ +void read_stat_total_irq(struct stats_global_irq *st_irq) +{ + FILE *fp; + char line[1024]; + unsigned long long irq_nr; + + if ((fp = fopen(STAT, "r")) == NULL) + return; + + while (fgets(line, sizeof(line), fp) != NULL) { + + if (!strncmp(line, "intr ", 5)) { + /* Read total number of interrupts received since system boot */ + sscanf(line + 5, "%llu", &irq_nr); + st_irq->irq_nr = (unsigned int) irq_nr; + + break; + } + } + + fclose(fp); +} /* *************************************************************************** * Read stats from /proc/interrupts or /proc/softirqs. @@ -1808,7 +1840,7 @@ void write_stats(int curr, int dis) void read_interrupts_stat(char *file, struct stats_irqcpu *st_ic[], int ic_nr, int curr) { FILE *fp; - struct stats_irq *st_irq_i; + struct stats_global_irq *st_irq_i; struct stats_irqcpu *p; char *line = NULL, *li; unsigned long irq = 0; @@ -1885,8 +1917,9 @@ void read_interrupts_stat(char *file, struct stats_irqcpu *st_ic[], int ic_nr, i /* * No need to set (st_irqcpu + cpu * irqcpu_nr)->irq_name: * This is the same as st_irqcpu->irq_name. - * Now save current interrupt value for current CPU (in stats_irqcpu structure) - * and total number of interrupts received by current CPU (in stats_irq structure). + * Now save current interrupt value for current CPU (in + * stats_irqcpu structure) and total number of interrupts + * received by current CPU (in stats_global_irq structure). */ p->interrupt = strtoul(cp, &next, 10); st_irq_i->irq_nr += p->interrupt; @@ -1962,7 +1995,7 @@ void rw_mpstat_loop(int dis_hdr, int rows) * (this is the first value on the line "intr:" in the /proc/stat file). */ if (DISPLAY_IRQ_SUM(actflags)) { - read_stat_irq(st_irq[0], 1); + read_stat_total_irq(st_irq[0]); } /* @@ -1982,7 +2015,7 @@ void rw_mpstat_loop(int dis_hdr, int rows) mp_tstamp[1] = mp_tstamp[0]; memset(st_cpu[1], 0, STATS_CPU_SIZE * (cpu_nr + 1)); memset(st_node[1], 0, STATS_CPU_SIZE * (cpu_nr + 1)); - memset(st_irq[1], 0, STATS_IRQ_SIZE * (cpu_nr + 1)); + memset(st_irq[1], 0, STATS_GLOBAL_IRQ_SIZE * (cpu_nr + 1)); memset(st_irqcpu[1], 0, STATS_IRQCPU_SIZE * (cpu_nr + 1) * irqcpu_nr); if (DISPLAY_SOFTIRQS(actflags)) { memset(st_softirqcpu[1], 0, STATS_IRQCPU_SIZE * (cpu_nr + 1) * softirqcpu_nr); @@ -2005,7 +2038,7 @@ void rw_mpstat_loop(int dis_hdr, int rows) uptime_cs[2] = uptime_cs[0]; memcpy(st_cpu[2], st_cpu[0], STATS_CPU_SIZE * (cpu_nr + 1)); memcpy(st_node[2], st_node[0], STATS_CPU_SIZE * (cpu_nr + 1)); - memcpy(st_irq[2], st_irq[0], STATS_IRQ_SIZE * (cpu_nr + 1)); + memcpy(st_irq[2], st_irq[0], STATS_GLOBAL_IRQ_SIZE * (cpu_nr + 1)); memcpy(st_irqcpu[2], st_irqcpu[0], STATS_IRQCPU_SIZE * (cpu_nr + 1) * irqcpu_nr); if (DISPLAY_SOFTIRQS(actflags)) { memcpy(st_softirqcpu[2], st_softirqcpu[0], @@ -2046,7 +2079,7 @@ void rw_mpstat_loop(int dis_hdr, int rows) /* Read total number of interrupts received among all CPU */ if (DISPLAY_IRQ_SUM(actflags)) { - read_stat_irq(st_irq[curr], 1); + read_stat_total_irq(st_irq[curr]); } /* diff --git a/mpstat.h b/mpstat.h index 23229dc..40e6fe3 100644 --- a/mpstat.h +++ b/mpstat.h @@ -7,6 +7,7 @@ #define _MPSTAT_H #include "common.h" +#include "rd_stats.h" /* *************************************************************************** @@ -90,11 +91,17 @@ struct stats_irqcpu { char irq_name[MAX_IRQ_LEN]; }; +#define STATS_IRQCPU_SIZE (sizeof(struct stats_irqcpu)) + +struct stats_global_irq { + unsigned long long irq_nr; +}; + +#define STATS_GLOBAL_IRQ_SIZE (sizeof(struct stats_global_irq)) + struct cpu_topology { int phys_package_id; int logical_core_id; }; -#define STATS_IRQCPU_SIZE (sizeof(struct stats_irqcpu)) - #endif -- 2.50.1