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");
|
||||
if (file) {
|
||||
char *line = NULL;
|
||||
size_t size=0;
|
||||
size_t size = 0;
|
||||
if (getline(&line, &size, file)==0)
|
||||
return;
|
||||
fclose(file);
|
||||
|
@ -176,8 +176,8 @@ static void do_one_cpu(char *path)
|
|||
file = fopen(new_path, "r");
|
||||
cpu_set(cpu->number, cpu->package_mask);
|
||||
if (file) {
|
||||
char *line;
|
||||
size_t size;
|
||||
char *line = NULL;
|
||||
size_t size = 0;
|
||||
if (getline(&line, &size, file))
|
||||
cpumask_parse_user(line, strlen(line), cpu->package_mask);
|
||||
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);
|
||||
file = fopen(new_path, "r");
|
||||
if (file) {
|
||||
char *line;
|
||||
size_t size;
|
||||
char *line = NULL;
|
||||
size_t size = 0;
|
||||
if (getline(&line, &size, file))
|
||||
cpumask_parse_user(line, strlen(line), cpu->cache_mask);
|
||||
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);
|
||||
file = fopen(new_path, "r");
|
||||
if (file) {
|
||||
char *line;
|
||||
size_t size;
|
||||
char *line = NULL;
|
||||
size_t size = 0;
|
||||
if (getline(&line, &size, file))
|
||||
cpumask_parse_user(line, strlen(line), cpu->cache_mask);
|
||||
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
|
||||
* by adding actual package counts to the calculated amount of work of interrupts
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
@ -123,15 +124,20 @@ void account_for_nic_stats(void)
|
|||
{
|
||||
struct nic *nic;
|
||||
FILE *file;
|
||||
char line[8192];
|
||||
char *line = NULL;
|
||||
size_t size = 0;
|
||||
file = fopen("/proc/net/dev", "r");
|
||||
if (!file)
|
||||
return;
|
||||
/* first two lines are headers */
|
||||
if (fgets(line, 8191, file)==NULL)
|
||||
if (getline(&line, &size, file)==0) {
|
||||
free(line);
|
||||
return;
|
||||
if (fgets(line, 8191, file)==NULL)
|
||||
}
|
||||
if (getline(&line, &size, file)==0) {
|
||||
free(line);
|
||||
return;
|
||||
}
|
||||
|
||||
while (!feof(file)) {
|
||||
uint64_t rxcount;
|
||||
|
@ -139,7 +145,9 @@ void account_for_nic_stats(void)
|
|||
uint64_t delta;
|
||||
int dummy;
|
||||
char *c, *c2;
|
||||
if (fgets(line, 8191, file)==NULL)
|
||||
if (getline(&line, &size, file)==0)
|
||||
break;
|
||||
if (line==NULL)
|
||||
break;
|
||||
c = strchr(line, ':');
|
||||
if (c==NULL) /* header line */
|
||||
|
@ -172,4 +180,5 @@ void account_for_nic_stats(void)
|
|||
|
||||
}
|
||||
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
|
||||
* of interrupt sources
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
|
11
powermode.c
11
powermode.c
|
@ -18,6 +18,7 @@
|
|||
* 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
@ -36,7 +37,8 @@ static unsigned int hysteresis;
|
|||
void check_power_mode(void)
|
||||
{
|
||||
FILE *file;
|
||||
char line[4096];
|
||||
char *line = NULL;
|
||||
size_t size = 0;
|
||||
char *c;
|
||||
uint64_t dummy, irq, softirq;
|
||||
line[0]=0;
|
||||
|
@ -44,9 +46,11 @@ void check_power_mode(void)
|
|||
file = fopen("/proc/stat", "r");
|
||||
if (!file)
|
||||
return;
|
||||
if (fgets(line, 4095, file)==NULL)
|
||||
memset(line,0, 4096);
|
||||
if (getline(&line, &size, file)==0)
|
||||
size=0;
|
||||
fclose(file);
|
||||
if (!line)
|
||||
return;
|
||||
c=&line[4];
|
||||
dummy = strtoull(c, &c, 10); /* user */
|
||||
dummy = strtoull(c, &c, 10); /* nice */
|
||||
|
@ -71,5 +75,6 @@ void check_power_mode(void)
|
|||
hysteresis = 0;
|
||||
}
|
||||
previous = irq;
|
||||
free(line);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
@ -32,16 +33,18 @@
|
|||
void parse_proc_interrupts(void)
|
||||
{
|
||||
FILE *file;
|
||||
char line[LINESIZE+1];
|
||||
char *line = NULL;
|
||||
size_t size = 0;
|
||||
|
||||
line[LINESIZE] = 0;
|
||||
file = fopen("/proc/interrupts", "r");
|
||||
if (!file)
|
||||
return;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
while (!feof(file)) {
|
||||
cpumask_t present;
|
||||
|
@ -50,7 +53,7 @@ void parse_proc_interrupts(void)
|
|||
uint64_t count;
|
||||
char *c, *c2;
|
||||
|
||||
if (fgets(line, LINESIZE, file)==NULL)
|
||||
if (getline(&line, &size, file)==0)
|
||||
break;
|
||||
|
||||
|
||||
|
@ -85,4 +88,5 @@ void parse_proc_interrupts(void)
|
|||
set_interrupt_count(number, count, &present);
|
||||
}
|
||||
fclose(file);
|
||||
free(line);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue