Skip to content

Commit c690213

Browse files
Yangzheng BaiYangzheng Bai
authored andcommitted
Changing coding style, and use array instead of pointer arithmatics
Reduce the complexity of for loop Remove pointer arithmatics
1 parent 527cfa9 commit c690213

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

benchmarks/lockhammer/src/lockhammer.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,15 @@ int main(int argc, char** argv)
179179
return 1;
180180
}
181181
csv = strtok(optarg, ",");
182-
for (int i = 0; i < num_cores && csv != NULL; csv = strtok(NULL, ","), ++i) {
182+
for (int i = 0; i < num_cores && csv != NULL; ++i)
183+
{
183184
optval = strtol(csv, (char **) NULL, 10);
184-
if (optval >= 0 && optval < num_cores) *(args.pinorder + i) = optval;
185-
else fprintf(stderr, "WARNING: core number %ld is out of range.\n", optval);
185+
if (optval >= 0 && optval < num_cores) {
186+
args.pinorder[i] = optval;
187+
} else {
188+
fprintf(stderr, "WARNING: core number %ld is out of range.\n", optval);
189+
}
190+
csv = strtok(NULL, ",");
186191
}
187192
break;
188193
case 's':
@@ -382,14 +387,18 @@ void* hmr(void *ptr)
382387
} else {
383388
/*
384389
* Non-zero core value indicates next core to pin, zero value means
385-
* fallback to default interleave mode.
390+
* fallback to default interleave mode. Note: -o and -i may have
391+
* conflicting pinning order that causes two or more threads to pin
392+
* on the same core. This feature interaction is intended by design
393+
* which allows 0 to serve as don't care mask and only changing the
394+
* pinning order we want to change for specific -i interleave mode.
386395
*/
387-
if (pinorder && *(pinorder + mycore)) {
388-
CPU_SET(*(pinorder + mycore), &affin_mask);
396+
if (pinorder && pinorder[mycore]) {
397+
CPU_SET(pinorder[mycore], &affin_mask);
389398
sched_setaffinity(0, sizeof(cpu_set_t), &affin_mask);
390-
} else {
391-
/* Calculate affinity mask for my core and set affinity */
392-
/* The concept of "interleave" is used here to allow for specifying
399+
} else { /* Calculate affinity mask for my core and set affinity */
400+
/*
401+
* The concept of "interleave" is used here to allow for specifying
393402
* whether increasing cores counts first populate physical cores or
394403
* hardware threads within the same physical core. This assumes the
395404
* following relationship between logical core numbers (N), hardware

0 commit comments

Comments
 (0)