A_IRQ: Count number of interrupts using /proc/interrupts
authorSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 29 Dec 2021 09:12:42 +0000 (10:12 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 29 Dec 2021 09:12:42 +0000 (10:12 +0100)
sar/sadc will no longer use /proc/stat file to calculate interrupts
statistics. They will use /proc/interrupts and will display per-CPU
statistics.
This first patch updates the function used to count the number of
interrupts.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
activity.c
count.c
count.h
sa_wrap.c

index 85b34b86db3803ff2ce3177b2b688555783d9542..0917d6001972139b6ca85ec8f2232335a990a6c9 100644 (file)
@@ -162,12 +162,12 @@ struct activity pcsw_act = {
 /* Interrupts statistics */
 struct activity irq_act = {
        .id             = A_IRQ,
-       .options        = AO_COUNTED,
-       .magic          = ACTIVITY_MAGIC_BASE + 1,
+       .options        = AO_COUNTED + AO_MATRIX,
+       .magic          = ACTIVITY_MAGIC_BASE + 2,
        .group          = G_INT,
 #ifdef SOURCE_SADC
-       .f_count_index  = 1,    /* wrap_get_irq_nr() */
-       .f_count2_index = -1,
+       .f_count_index  = 0,    /* wrap_get_cpu_nr() */
+       .f_count2_index = 1,    /* wrap_get_irq_nr() */
        .f_read         = wrap_read_stat_irq,
 #endif
 #ifdef SOURCE_SAR
@@ -194,7 +194,7 @@ struct activity irq_act = {
        .item_list_sz   = 0,
        .g_nr           = 0,
        .nr_ini         = -1,
-       .nr2            = 1,
+       .nr2            = -1,
        .nr_max         = NR_IRQS + 1,
        .nr             = {-1, -1, -1},
        .nr_allocated   = 0,
diff --git a/count.c b/count.c
index c1a976476fa91c72f7dfa7751cb64bdb649f1f14..0adc25e14722868da4158262edf5caecb3acd657 100644 (file)
--- a/count.c
+++ b/count.c
@@ -268,40 +268,6 @@ __nr_t get_diskstats_dev_nr(int count_part, int only_used_dev)
 #ifdef SOURCE_SADC
 /*---------------- BEGIN: FUNCTIONS USED BY SADC ONLY ---------------------*/
 
-/*
- ***************************************************************************
- * Count number of interrupts that are in /proc/stat file.
- *
- * RETURNS:
- * Number of interrupts, including total number of interrupts.
- ***************************************************************************
- */
-__nr_t get_irq_nr(void)
-{
-       FILE *fp;
-       char line[8192];
-       __nr_t in = 0;
-       int pos = 4;
-
-       if ((fp = fopen(STAT, "r")) == NULL)
-               return 0;
-
-       while (fgets(line, sizeof(line), fp) != NULL) {
-
-               if (!strncmp(line, "intr ", 5)) {
-
-                       while (pos < strlen(line)) {
-                               in++;
-                               pos += strcspn(line + pos + 1, " ") + 1;
-                       }
-               }
-       }
-
-       fclose(fp);
-
-       return in;
-}
-
 /*
  ***************************************************************************
  * Find number of serial lines that support tx/rx accounting
diff --git a/count.h b/count.h
index cf0b16060b624a8817f62d91eb35224656713cba..5197ff00442de82d5411aea7950b9d834ba7af27 100644 (file)
--- a/count.h
+++ b/count.h
@@ -21,8 +21,6 @@ __nr_t get_irqcpu_nr
        (char *, int, int);
 __nr_t get_diskstats_dev_nr
        (int, int);
-__nr_t get_irq_nr
-       (void);
 __nr_t get_serial_nr
        (void);
 __nr_t get_iface_nr
index 53681469675d12c14083ac76347137de391e8b2f..67615426b514ce6b8d219f7735e709cba36e60b0 100644 (file)
--- a/sa_wrap.c
+++ b/sa_wrap.c
@@ -1225,7 +1225,8 @@ __read_funct_t wrap_read_psimem(struct activity *a)
 
 /*
  ***************************************************************************
- * Count number of interrupts that are in /proc/stat file.
+ * Count number of interrupts that are in /proc/interrupts file, including
+ * total number of interrupts.
  * Truncate the number of different individual interrupts to NR_IRQS.
  *
  * IN:
@@ -1240,8 +1241,13 @@ __nr_t wrap_get_irq_nr(struct activity *a)
 {
        __nr_t n;
 
-       if ((n = get_irq_nr()) > (a->bitmap->b_size + 1)) {
-               n = a->bitmap->b_size + 1;
+       /*
+        * Get number of different interrupts.
+        * Number of CPU (including CPU "all") has already been calculated and saved in a->nr_ini.
+        */
+       n = get_irqcpu_nr(INTERRUPTS, a->bitmap->b_size, a->nr_ini - 1);
+       if (n > 0) {
+               n++;    /* Add 1 for total number of interrupts. A value of bitmap->b_size + 1 is OK. */
        }
 
        return n;