Skip to content

Commit

Permalink
fix empty interrupt statistic when CPU1 is offline
Browse files Browse the repository at this point in the history
File "/proc/interrupts" contains statistics for CPUs that are not
only available, but also online. That is, when reading the
information from this file should use the number of CPUs that are
online.
In this patch, in all functions where the information is read from
the file "/proc/interrupts", function "cpu_cores_count_get"
is replaced by the function "cpu_online_cores_count_get".

Signed-off-by: Oleksandr_Tyshchenko <oleksandr.tyshchenko@ti.com>
  • Loading branch information
Oleksandr_Tyshchenko authored and Patrick Titiano committed Oct 9, 2012
1 parent 904ea26 commit 3bff560
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
20 changes: 20 additions & 0 deletions common/cpuinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,26 @@ double cpu_load_get(unsigned int delta_idle,
return load;
}

/* ------------------------------------------------------------------------*//**
* @FUNCTION cpu_online_cores_count_get
* @BRIEF return the number of CPU cores online
* @RETURNS number of CPU cores online
* @param[in] none
* @DESCRIPTION return the number of CPU cores online
*//*------------------------------------------------------------------------ */
unsigned int cpu_online_cores_count_get(void)
{
unsigned int i, cpu_total_count, cpu_online_count;

cpu_total_count = cpu_cores_count_get();
cpu_online_count = 0;
for (i = 0; i < cpu_total_count; i ++) {
if (cpu_is_online(i) == 1)
cpu_online_count ++;
}

return cpu_online_count;
}

/* ------------------------------------------------------------------------*//**
* @FUNCTION cpu_cores_count_get
Expand Down
1 change: 1 addition & 0 deletions common/cpuinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ char *cpu_gets(char s[CPU_NAME_MAX_LENGTH]);
char *cpu_full_name_get(char s[CPU_FULL_NAME_MAX_LENGTH]);

unsigned int cpu_cores_count_get(void);
unsigned int cpu_online_cores_count_get(void);

unsigned int cpu_is_online(unsigned short cpu);
int cpu_proc_stats_get(unsigned int cpu,
Expand Down
6 changes: 3 additions & 3 deletions linux/interrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ int irq_total_count_get(FILE *fp)
char irq_ctrl_name[256], dev_name[256];
int ret;

cpu_count = cpu_cores_count_get();
cpu_count = cpu_online_cores_count_get();
if (cpu_count == 0) {
fprintf(stderr, "%s(): cpu_count == 0!\n", __func__);
return IRQ_ERR_CPU;
Expand Down Expand Up @@ -244,7 +244,7 @@ int irq_count_get(unsigned int n, FILE *fp)
char irq_ctrl_name[256], dev_name[256];
int ret;

cpu_count = cpu_cores_count_get();
cpu_count = cpu_online_cores_count_get();
if (cpu_count == 0) {
fprintf(stderr, "%s(): cpu_count == 0!\n", __func__);
return IRQ_ERR_CPU;
Expand Down Expand Up @@ -360,7 +360,7 @@ char *irq_dev_name_get(unsigned int n, FILE *fp, char name[256])
int ret;

dprintf("%s(): looking for irq #%u name ...\n", __func__, n);
cpu_count = cpu_cores_count_get();
cpu_count = cpu_online_cores_count_get();
if (cpu_count == 0) {
fprintf(stderr, "%s(): cpu_count == 0!\n", __func__);
return NULL;
Expand Down

0 comments on commit 3bff560

Please sign in to comment.