for (i = 0; i < nr_cpus; i++) {
fd = syscall(__NR_perf_event_open, &attr, -1, i, -1, 0);
if (fd < 0) {
+ /* Ignore CPU that is offline */
+ if (errno == ENODEV)
+ continue;
fprintf(stderr, "failed to init perf sampling: %s\n",
strerror(errno));
return -1;
return 1;
}
- obj = llcstat_bpf__open();
- if (!obj) {
- fprintf(stderr, "failed to open BPF object\n");
+ nr_cpus = libbpf_num_possible_cpus();
+ if (nr_cpus < 0) {
+ fprintf(stderr, "failed to get # of possible cpus: '%s'!\n",
+ strerror(-nr_cpus));
return 1;
}
-
- nr_cpus = libbpf_num_possible_cpus();
mlinks = calloc(nr_cpus, sizeof(*mlinks));
rlinks = calloc(nr_cpus, sizeof(*rlinks));
if (!mlinks || !rlinks) {
fprintf(stderr, "failed to alloc mlinks or rlinks\n");
- goto cleanup;
+ return 1;
}
- err = llcstat_bpf__load(obj);
- if (err) {
- fprintf(stderr, "failed to load BPF object: %d\n", err);
+ obj = llcstat_bpf__open_and_load();
+ if (!obj) {
+ fprintf(stderr, "failed to open and/or load BPF object\n");
goto cleanup;
}
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
// Copyright (c) 2020 Wenbo Zhang
//
-// Based on numamove(8) from from BPF-Perf-Tools-Book by Brendan Gregg.
+// Based on numamove(8) from BPF-Perf-Tools-Book by Brendan Gregg.
// 8-Jun-2020 Wenbo Zhang Created this.
#include <argp.h>
#include <signal.h>
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
// Copyright (c) 2020 Wenbo Zhang
//
-// Based on readahead(8) from from BPF-Perf-Tools-Book by Brendan Gregg.
+// Based on readahead(8) from BPF-Perf-Tools-Book by Brendan Gregg.
// 8-Jun-2020 Wenbo Zhang Created this.
#include <argp.h>
#include <signal.h>
// Based on xfsslower(8) from BCC by Brendan Gregg & Dina Goldshtein.
// 9-Mar-2020 Wenbo Zhang Created this.
#include <argp.h>
-#include <limits.h>
-#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <time.h>
+#include <unistd.h>
#include <bpf/libbpf.h>
#include <bpf/bpf.h>
#include "xfsslower.h"
#define PERF_BUFFER_TIME_MS 10
#define PERF_POLL_TIMEOUT_MS 100
-
static struct env {
pid_t pid;
time_t duration;
obj = xfsslower_bpf__open();
if (!obj) {
- fprintf(stderr, "failed to open and/or load BPF object\n");
+ fprintf(stderr, "failed to open BPF object\n");
return 1;
}