more buffer elimination
git-svn-id: https://irqbalance.googlecode.com/svn/trunk@5 46b42954-3823-0410-bd82-eb80b452c9b5
This commit is contained in:
parent
65dd199f40
commit
9744cb104e
14
cputree.c
14
cputree.c
|
@ -142,7 +142,7 @@ static void do_one_cpu(char *path)
|
||||||
file = fopen(new_path, "r");
|
file = fopen(new_path, "r");
|
||||||
if (file) {
|
if (file) {
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t size=0;
|
size_t size = 0;
|
||||||
if (getline(&line, &size, file)==0)
|
if (getline(&line, &size, file)==0)
|
||||||
return;
|
return;
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
@ -176,8 +176,8 @@ static void do_one_cpu(char *path)
|
||||||
file = fopen(new_path, "r");
|
file = fopen(new_path, "r");
|
||||||
cpu_set(cpu->number, cpu->package_mask);
|
cpu_set(cpu->number, cpu->package_mask);
|
||||||
if (file) {
|
if (file) {
|
||||||
char *line;
|
char *line = NULL;
|
||||||
size_t size;
|
size_t size = 0;
|
||||||
if (getline(&line, &size, file))
|
if (getline(&line, &size, file))
|
||||||
cpumask_parse_user(line, strlen(line), cpu->package_mask);
|
cpumask_parse_user(line, strlen(line), cpu->package_mask);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
@ -190,8 +190,8 @@ static void do_one_cpu(char *path)
|
||||||
snprintf(new_path, PATH_MAX, "%s/cache/index1/shared_cpu_map", path);
|
snprintf(new_path, PATH_MAX, "%s/cache/index1/shared_cpu_map", path);
|
||||||
file = fopen(new_path, "r");
|
file = fopen(new_path, "r");
|
||||||
if (file) {
|
if (file) {
|
||||||
char *line;
|
char *line = NULL;
|
||||||
size_t size;
|
size_t size = 0;
|
||||||
if (getline(&line, &size, file))
|
if (getline(&line, &size, file))
|
||||||
cpumask_parse_user(line, strlen(line), cpu->cache_mask);
|
cpumask_parse_user(line, strlen(line), cpu->cache_mask);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
@ -200,8 +200,8 @@ static void do_one_cpu(char *path)
|
||||||
snprintf(new_path, PATH_MAX, "%s/cache/index2/shared_cpu_map", path);
|
snprintf(new_path, PATH_MAX, "%s/cache/index2/shared_cpu_map", path);
|
||||||
file = fopen(new_path, "r");
|
file = fopen(new_path, "r");
|
||||||
if (file) {
|
if (file) {
|
||||||
char *line;
|
char *line = NULL;
|
||||||
size_t size;
|
size_t size = 0;
|
||||||
if (getline(&line, &size, file))
|
if (getline(&line, &size, file))
|
||||||
cpumask_parse_user(line, strlen(line), cpu->cache_mask);
|
cpumask_parse_user(line, strlen(line), cpu->cache_mask);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
17
network.c
17
network.c
|
@ -24,6 +24,7 @@
|
||||||
* even though the amount of work is high; this file is there to compensate for this
|
* even though the amount of work is high; this file is there to compensate for this
|
||||||
* by adding actual package counts to the calculated amount of work of interrupts
|
* by adding actual package counts to the calculated amount of work of interrupts
|
||||||
*/
|
*/
|
||||||
|
#define _GNU_SOURCE
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -123,15 +124,20 @@ void account_for_nic_stats(void)
|
||||||
{
|
{
|
||||||
struct nic *nic;
|
struct nic *nic;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char line[8192];
|
char *line = NULL;
|
||||||
|
size_t size = 0;
|
||||||
file = fopen("/proc/net/dev", "r");
|
file = fopen("/proc/net/dev", "r");
|
||||||
if (!file)
|
if (!file)
|
||||||
return;
|
return;
|
||||||
/* first two lines are headers */
|
/* first two lines are headers */
|
||||||
if (fgets(line, 8191, file)==NULL)
|
if (getline(&line, &size, file)==0) {
|
||||||
|
free(line);
|
||||||
return;
|
return;
|
||||||
if (fgets(line, 8191, file)==NULL)
|
}
|
||||||
|
if (getline(&line, &size, file)==0) {
|
||||||
|
free(line);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (!feof(file)) {
|
while (!feof(file)) {
|
||||||
uint64_t rxcount;
|
uint64_t rxcount;
|
||||||
|
@ -139,7 +145,9 @@ void account_for_nic_stats(void)
|
||||||
uint64_t delta;
|
uint64_t delta;
|
||||||
int dummy;
|
int dummy;
|
||||||
char *c, *c2;
|
char *c, *c2;
|
||||||
if (fgets(line, 8191, file)==NULL)
|
if (getline(&line, &size, file)==0)
|
||||||
|
break;
|
||||||
|
if (line==NULL)
|
||||||
break;
|
break;
|
||||||
c = strchr(line, ':');
|
c = strchr(line, ':');
|
||||||
if (c==NULL) /* header line */
|
if (c==NULL) /* header line */
|
||||||
|
@ -172,4 +180,5 @@ void account_for_nic_stats(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
1
numa.c
1
numa.c
|
@ -24,6 +24,7 @@
|
||||||
* In addition the PCI class information is used to refine the classification
|
* In addition the PCI class information is used to refine the classification
|
||||||
* of interrupt sources
|
* of interrupt sources
|
||||||
*/
|
*/
|
||||||
|
#define _GNU_SOURCE
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
11
powermode.c
11
powermode.c
|
@ -18,6 +18,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor,
|
* 51 Franklin Street, Fifth Floor,
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
#define _GNU_SOURCE
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -36,7 +37,8 @@ static unsigned int hysteresis;
|
||||||
void check_power_mode(void)
|
void check_power_mode(void)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char line[4096];
|
char *line = NULL;
|
||||||
|
size_t size = 0;
|
||||||
char *c;
|
char *c;
|
||||||
uint64_t dummy, irq, softirq;
|
uint64_t dummy, irq, softirq;
|
||||||
line[0]=0;
|
line[0]=0;
|
||||||
|
@ -44,9 +46,11 @@ void check_power_mode(void)
|
||||||
file = fopen("/proc/stat", "r");
|
file = fopen("/proc/stat", "r");
|
||||||
if (!file)
|
if (!file)
|
||||||
return;
|
return;
|
||||||
if (fgets(line, 4095, file)==NULL)
|
if (getline(&line, &size, file)==0)
|
||||||
memset(line,0, 4096);
|
size=0;
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
if (!line)
|
||||||
|
return;
|
||||||
c=&line[4];
|
c=&line[4];
|
||||||
dummy = strtoull(c, &c, 10); /* user */
|
dummy = strtoull(c, &c, 10); /* user */
|
||||||
dummy = strtoull(c, &c, 10); /* nice */
|
dummy = strtoull(c, &c, 10); /* nice */
|
||||||
|
@ -71,5 +75,6 @@ void check_power_mode(void)
|
||||||
hysteresis = 0;
|
hysteresis = 0;
|
||||||
}
|
}
|
||||||
previous = irq;
|
previous = irq;
|
||||||
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor,
|
* 51 Franklin Street, Fifth Floor,
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
#define _GNU_SOURCE
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -32,16 +33,18 @@
|
||||||
void parse_proc_interrupts(void)
|
void parse_proc_interrupts(void)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char line[LINESIZE+1];
|
char *line = NULL;
|
||||||
|
size_t size = 0;
|
||||||
|
|
||||||
line[LINESIZE] = 0;
|
|
||||||
file = fopen("/proc/interrupts", "r");
|
file = fopen("/proc/interrupts", "r");
|
||||||
if (!file)
|
if (!file)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* first line is the header we don't need; nuke it */
|
/* first line is the header we don't need; nuke it */
|
||||||
if (fgets(line, LINESIZE, file)==NULL)
|
if (getline(&line, &size, file)==0) {
|
||||||
|
free(line);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (!feof(file)) {
|
while (!feof(file)) {
|
||||||
cpumask_t present;
|
cpumask_t present;
|
||||||
|
@ -50,7 +53,7 @@ void parse_proc_interrupts(void)
|
||||||
uint64_t count;
|
uint64_t count;
|
||||||
char *c, *c2;
|
char *c, *c2;
|
||||||
|
|
||||||
if (fgets(line, LINESIZE, file)==NULL)
|
if (getline(&line, &size, file)==0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,4 +88,5 @@ void parse_proc_interrupts(void)
|
||||||
set_interrupt_count(number, count, &present);
|
set_interrupt_count(number, count, &present);
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue