]> git.pld-linux.org Git - packages/irqbalance.git/blob - irqbalance-cputree-parse.patch
- BR: pkgconfig
[packages/irqbalance.git] / irqbalance-cputree-parse.patch
1 diff -up irqbalance-0.55/irqbalance-0.55/cputree.c.orig irqbalance-0.55/irqbalance-0.55/cputree.c
2 --- irqbalance-0.55/irqbalance-0.55/cputree.c.orig      2006-12-10 15:04:59.000000000 -0500
3 +++ irqbalance-0.55/irqbalance-0.55/cputree.c   2007-09-28 12:43:35.000000000 -0400
4 @@ -26,6 +26,8 @@
5  
6  #define _GNU_SOURCE
7  
8 +#include <ctype.h>
9 +#include <fcntl.h>
10  #include <stdio.h>
11  #include <stdlib.h>
12  #include <unistd.h>
13 @@ -131,34 +133,30 @@ static void fill_cache_domain(void)
14  }
15  
16  
17 -static void do_one_cpu(char *path)
18 +static void do_one_cpu(int dfd, char *d_name)
19  {
20         struct cpu_core *cpu;
21         FILE *file;
22         char new_path[PATH_MAX];
23  
24         /* skip offline cpus */
25 -       snprintf(new_path, PATH_MAX, "%s/online", path);
26 -       file = fopen(new_path, "r");
27 -       if (file) {
28 -               char *line = NULL;
29 -               size_t size = 0;
30 -               if (getline(&line, &size, file)==0)
31 +       snprintf(new_path, PATH_MAX, "%s/online", d_name);
32 +       int fd = openat(dfd, new_path, O_RDONLY);
33 +       if (fd != -1) {
34 +               char buf[1];
35 +               ssize_t n = read(fd, buf, sizeof(buf));
36 +               close(fd);
37 +               if (n != sizeof(buf))
38                         return;
39 -               fclose(file);
40 -               if (line && line[0]=='0') {
41 -                       free(line);
42 +               if (buf[0] == '0')
43                         return;
44 -               }
45 -               free(line);
46         }
47  
48 -       cpu = malloc(sizeof(struct cpu_core));
49 +       cpu = calloc(1, sizeof(struct cpu_core));
50         if (!cpu)
51                 return;
52 -       memset(cpu, 0, sizeof(struct cpu_core));
53  
54 -       cpu->number = strtoul(&path[27], NULL, 10);
55 +       cpu->number = strtoul(&d_name[3], NULL, 10);
56         
57         cpu_set(cpu->number, cpu->mask);
58  
59 @@ -170,43 +168,45 @@ static void do_one_cpu(char *path)
60                 return;
61         }
62  
63 +       char *line = NULL;
64 +       size_t size = 0;
65  
66         /* try to read the package mask; if it doesn't exist assume solitary */
67 -       snprintf(new_path, PATH_MAX, "%s/topology/core_siblings", path);
68 -       file = fopen(new_path, "r");
69 +       snprintf(new_path, PATH_MAX, "%s/topology/core_siblings", d_name);
70 +       fd = openat(dfd, new_path, O_RDONLY);
71 +       file = fd == -1 ? NULL : fdopen(fd, "r");
72         cpu_set(cpu->number, cpu->package_mask);
73         if (file) {
74 -               char *line = NULL;
75 -               size_t size = 0;
76                 if (getline(&line, &size, file)) 
77                         cpumask_parse_user(line, strlen(line), cpu->package_mask);
78                 fclose(file);
79 -               free(line);
80 -       }
81 +       } else if (fd != -1)
82 +               close(fd);
83  
84         /* try to read the cache mask; if it doesn't exist assume solitary */
85         /* We want the deepest cache level available so try index1 first, then index2 */
86         cpu_set(cpu->number, cpu->cache_mask);
87 -       snprintf(new_path, PATH_MAX, "%s/cache/index1/shared_cpu_map", path);
88 -       file = fopen(new_path, "r");
89 +       snprintf(new_path, PATH_MAX, "%s/cache/index1/shared_cpu_map", d_name);
90 +       fd = openat(dfd, new_path, O_RDONLY);
91 +       file = fd == -1 ? NULL : fdopen(fd, "r");
92         if (file) {
93 -               char *line = NULL;
94 -               size_t size = 0;
95                 if (getline(&line, &size, file)) 
96                         cpumask_parse_user(line, strlen(line), cpu->cache_mask);
97                 fclose(file);
98 -               free(line);
99 -       }
100 -       snprintf(new_path, PATH_MAX, "%s/cache/index2/shared_cpu_map", path);
101 -       file = fopen(new_path, "r");
102 +       } else if (fd != -1)
103 +               close(fd);
104 +
105 +       snprintf(new_path, PATH_MAX, "%s/cache/index2/shared_cpu_map", d_name);
106 +       fd = openat(dfd, new_path, O_RDONLY);
107 +       file = fd == -1 ? NULL : fdopen(fd, "r");
108         if (file) {
109 -               char *line = NULL;
110 -               size_t size = 0;
111                 if (getline(&line, &size, file)) 
112                         cpumask_parse_user(line, strlen(line), cpu->cache_mask);
113                 fclose(file);
114 -               free(line);
115 -       }
116 +       } else if (fd != -1)
117 +               close(fd);
118 +
119 +       free(line);
120  
121         /* 
122            blank out the banned cpus from the various masks so that interrupts
123 @@ -311,18 +311,19 @@ void parse_cpu_tree(void)
124  {
125         DIR *dir;
126         struct dirent *entry;
127 +       int dfd;
128  
129         cpus_complement(unbanned_cpus, banned_cpus);
130  
131         dir = opendir("/sys/devices/system/cpu");
132         if (!dir)
133                 return;
134 +       dfd = dirfd(dir);
135         do {
136                 entry = readdir(dir);
137 -                if (entry && strlen(entry->d_name)>3 && strstr(entry->d_name,"cpu")) {
138 -                       char new_path[PATH_MAX];
139 -                       sprintf(new_path, "/sys/devices/system/cpu/%s", entry->d_name);
140 -                       do_one_cpu(new_path);
141 +                if (entry && strlen(entry->d_name)>3 && memcmp(entry->d_name,"cpu",3) == 0
142 +                   && isdigit(entry->d_name[3])) {
143 +                       do_one_cpu(dfd, entry->d_name);
144                 }
145         } while (entry);
146         closedir(dir);  
This page took 0.079155 seconds and 3 git commands to generate.