Skip to content

Commit f097e34

Browse files
committed
utils/hwloc: Unmix spaces and tabs
Signed-off-by: Clément Foyer <[email protected]>
1 parent 17d0842 commit f097e34

13 files changed

+798
-798
lines changed

utils/hwloc/common-ps.c

+92-92
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include "misc.h"
2424

2525
int hwloc_ps_read_process(hwloc_topology_t topology, hwloc_const_bitmap_t topocpuset,
26-
struct hwloc_ps_process *proc,
27-
unsigned long flags)
26+
struct hwloc_ps_process *proc,
27+
unsigned long flags)
2828
{
2929
#ifdef HAVE_DIRENT_H
3030
hwloc_pid_t realpid;
@@ -68,9 +68,9 @@ int hwloc_ps_read_process(hwloc_topology_t topology, hwloc_const_bitmap_t topocp
6868
n = read(fd, comm, sizeof(comm) - 1);
6969
close(fd);
7070
if (n > 0) {
71-
comm[n] = '\0';
72-
if (n > 1 && comm[n-1] == '\n')
73-
comm[n-1] = '\0';
71+
comm[n] = '\0';
72+
if (n > 1 && comm[n-1] == '\n')
73+
comm[n-1] = '\0';
7474
}
7575

7676
} else {
@@ -81,19 +81,19 @@ int hwloc_ps_read_process(hwloc_topology_t topology, hwloc_const_bitmap_t topocp
8181
snprintf(path, pathlen, "/proc/%ld/stat", proc->pid);
8282
fd = open(path, O_RDONLY);
8383
if (fd >= 0) {
84-
/* "pid (comm) ..." */
85-
n = read(fd, stats, sizeof(stats) - 1);
86-
close(fd);
87-
if (n > 0) {
88-
stats[n] = '\0';
89-
parenl = strchr(stats, '(');
90-
parenr = strchr(stats, ')');
91-
if (!parenr)
92-
parenr = &stats[sizeof(stats)-1];
93-
*parenr = '\0';
94-
if (parenl)
95-
snprintf(comm, sizeof(comm), "%s", parenl+1);
96-
}
84+
/* "pid (comm) ..." */
85+
n = read(fd, stats, sizeof(stats) - 1);
86+
close(fd);
87+
if (n > 0) {
88+
stats[n] = '\0';
89+
parenl = strchr(stats, '(');
90+
parenr = strchr(stats, ')');
91+
if (!parenr)
92+
parenr = &stats[sizeof(stats)-1];
93+
*parenr = '\0';
94+
if (parenl)
95+
snprintf(comm, sizeof(comm), "%s", parenl+1);
96+
}
9797
}
9898
}
9999

@@ -147,78 +147,78 @@ int hwloc_ps_read_process(hwloc_topology_t topology, hwloc_const_bitmap_t topocp
147147
unsigned nbth = 0;
148148
/* count threads */
149149
while ((taskdirent = readdir(taskdir))) {
150-
tid = strtol(taskdirent->d_name, &end, 10);
151-
if (*end)
152-
/* Not a number */
153-
continue;
154-
nbth++;
150+
tid = strtol(taskdirent->d_name, &end, 10);
151+
if (*end)
152+
/* Not a number */
153+
continue;
154+
nbth++;
155155
}
156156
if (nbth > 1) {
157-
/* if there's more than one thread, see if some are bound */
158-
proc->threads = calloc(nbth, sizeof(*proc->threads));
159-
if (proc->threads) {
160-
/* reread the directory but gather info now */
161-
rewinddir(taskdir);
162-
unsigned i = 0;
163-
while ((taskdirent = readdir(taskdir))) {
164-
char *path2;
165-
unsigned path2len;
166-
167-
tid = strtol(taskdirent->d_name, &end, 10);
168-
if (*end)
169-
/* Not a number */
170-
continue;
171-
172-
proc->threads[i].tid = tid;
173-
174-
path2len = pathlen + 1 + 21 + 1 + 4 + 1;
175-
path2 = malloc(path2len);
176-
if (path2) {
177-
int commfd;
178-
snprintf(path2, path2len, "%s/%ld/comm", path, tid);
179-
commfd = open(path2, O_RDWR);
180-
if (commfd >= 0) {
181-
n = read(commfd, proc->threads[i].name, sizeof(proc->threads[i].name));
182-
close(commfd);
183-
if (n <= 0)
184-
proc->threads[i].name[0] = '\0';
185-
else if ((size_t)n < sizeof(proc->threads[i].name))
186-
proc->threads[i].name[n] = '\0';
187-
proc->threads[i].name[sizeof(proc->threads[i].name)-1] = '\0';
188-
end = strchr(proc->threads[i].name, '\n');
189-
if (end)
190-
*end = '\0';
191-
}
192-
free(path2);
193-
}
194-
195-
if (flags & HWLOC_PS_FLAG_LASTCPULOCATION) {
196-
if (hwloc_linux_get_tid_last_cpu_location(topology, tid, cpuset))
197-
goto next;
198-
} else {
199-
if (hwloc_linux_get_tid_cpubind(topology, tid, cpuset))
200-
goto next;
201-
}
202-
hwloc_bitmap_and(cpuset, cpuset, topocpuset);
203-
if (hwloc_bitmap_iszero(cpuset))
204-
goto next;
205-
206-
proc->threads[i].cpuset = hwloc_bitmap_dup(cpuset);
207-
if (!hwloc_bitmap_isequal(cpuset, topocpuset)) {
208-
proc->threads[i].bound = 1;
209-
proc->nboundthreads++;
210-
}
211-
212-
next:
213-
i++;
214-
proc->nthreads++;
215-
if (i == nbth)
216-
/* ignore the lastly created threads, I'm too lazy to reallocate */
217-
break;
218-
}
219-
} else {
220-
/* failed to alloc, behave as if there were no threads */
221-
}
157+
/* if there's more than one thread, see if some are bound */
158+
proc->threads = calloc(nbth, sizeof(*proc->threads));
159+
if (proc->threads) {
160+
/* reread the directory but gather info now */
161+
rewinddir(taskdir);
162+
unsigned i = 0;
163+
while ((taskdirent = readdir(taskdir))) {
164+
char *path2;
165+
unsigned path2len;
166+
167+
tid = strtol(taskdirent->d_name, &end, 10);
168+
if (*end)
169+
/* Not a number */
170+
continue;
171+
172+
proc->threads[i].tid = tid;
173+
174+
path2len = pathlen + 1 + 21 + 1 + 4 + 1;
175+
path2 = malloc(path2len);
176+
if (path2) {
177+
int commfd;
178+
snprintf(path2, path2len, "%s/%ld/comm", path, tid);
179+
commfd = open(path2, O_RDWR);
180+
if (commfd >= 0) {
181+
n = read(commfd, proc->threads[i].name, sizeof(proc->threads[i].name));
182+
close(commfd);
183+
if (n <= 0)
184+
proc->threads[i].name[0] = '\0';
185+
else if ((size_t)n < sizeof(proc->threads[i].name))
186+
proc->threads[i].name[n] = '\0';
187+
proc->threads[i].name[sizeof(proc->threads[i].name)-1] = '\0';
188+
end = strchr(proc->threads[i].name, '\n');
189+
if (end)
190+
*end = '\0';
191+
}
192+
free(path2);
193+
}
194+
195+
if (flags & HWLOC_PS_FLAG_LASTCPULOCATION) {
196+
if (hwloc_linux_get_tid_last_cpu_location(topology, tid, cpuset))
197+
goto next;
198+
} else {
199+
if (hwloc_linux_get_tid_cpubind(topology, tid, cpuset))
200+
goto next;
201+
}
202+
hwloc_bitmap_and(cpuset, cpuset, topocpuset);
203+
if (hwloc_bitmap_iszero(cpuset))
204+
goto next;
205+
206+
proc->threads[i].cpuset = hwloc_bitmap_dup(cpuset);
207+
if (!hwloc_bitmap_isequal(cpuset, topocpuset)) {
208+
proc->threads[i].bound = 1;
209+
proc->nboundthreads++;
210+
}
211+
212+
next:
213+
i++;
214+
proc->nthreads++;
215+
if (i == nbth)
216+
/* ignore the lastly created threads, I'm too lazy to reallocate */
217+
break;
218+
}
219+
} else {
220+
/* failed to alloc, behave as if there were no threads */
221+
}
222222
}
223223
closedir(taskdir);
224224
}
@@ -342,16 +342,16 @@ void hwloc_ps_free_process(struct hwloc_ps_process *proc)
342342
if (proc->nthreads)
343343
for(i=0; i<proc->nthreads; i++)
344344
if (proc->threads[i].cpuset)
345-
hwloc_bitmap_free(proc->threads[i].cpuset);
345+
hwloc_bitmap_free(proc->threads[i].cpuset);
346346
free(proc->threads);
347347

348348
hwloc_bitmap_free(proc->cpuset);
349349
}
350350

351351
int hwloc_ps_foreach_process(hwloc_topology_t topology, hwloc_const_bitmap_t topocpuset,
352-
void (*callback)(hwloc_topology_t topology, struct hwloc_ps_process *proc, void *cbdata),
353-
void *cbdata,
354-
unsigned long flags, const char *only_name, long uid)
352+
void (*callback)(hwloc_topology_t topology, struct hwloc_ps_process *proc, void *cbdata),
353+
void *cbdata,
354+
unsigned long flags, const char *only_name, long uid)
355355
{
356356
#ifdef HAVE_DIRENT_H
357357
DIR *dir;

utils/hwloc/common-ps.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ struct hwloc_ps_process {
3737
#define HWLOC_PS_FLAG_UID (1UL<<3)
3838

3939
int hwloc_ps_read_process(hwloc_topology_t topology, hwloc_const_bitmap_t topocpuset,
40-
struct hwloc_ps_process *proc,
41-
unsigned long flags);
40+
struct hwloc_ps_process *proc,
41+
unsigned long flags);
4242

4343
int hwloc_ps_foreach_process(hwloc_topology_t topology, hwloc_const_bitmap_t topocpuset,
44-
void (*callback)(hwloc_topology_t topology, struct hwloc_ps_process *proc, void *cbdata),
45-
void *cbdata,
46-
unsigned long flags, const char *only_name, long only_uid);
44+
void (*callback)(hwloc_topology_t topology, struct hwloc_ps_process *proc, void *cbdata),
45+
void *cbdata,
46+
unsigned long flags, const char *only_name, long only_uid);
4747

4848
int hwloc_ps_foreach_child(hwloc_topology_t topology, hwloc_const_bitmap_t topocpuset,
4949
long pid,

0 commit comments

Comments
 (0)