Skip to content

Commit cf1be3f

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

13 files changed

+765
-765
lines changed

utils/hwloc/common-ps.c

+93-93
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

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

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

350350
int hwloc_ps_foreach_process(hwloc_topology_t topology, hwloc_const_bitmap_t topocpuset,
351-
void (*callback)(hwloc_topology_t topology, struct hwloc_ps_process *proc, void *cbdata),
352-
void *cbdata,
353-
unsigned long flags, const char *only_name, long uid)
351+
void (*callback)(hwloc_topology_t topology, struct hwloc_ps_process *proc, void *cbdata),
352+
void *cbdata,
353+
unsigned long flags, const char *only_name, long uid)
354354
{
355355
#ifdef HAVE_DIRENT_H
356356
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
void hwloc_ps_pidcmd(struct hwloc_ps_process *proc, const char *pidcmd);
4949

0 commit comments

Comments
 (0)