profile_perf_event_cnt = 0;
 }
 
+static int profile_open_perf_event(int mid, int cpu, int map_fd)
+{
+       int pmu_fd;
+
+       pmu_fd = syscall(__NR_perf_event_open, &metrics[mid].attr,
+                        -1 /*pid*/, cpu, -1 /*group_fd*/, 0);
+       if (pmu_fd < 0) {
+               if (errno == ENODEV) {
+                       p_info("cpu %d may be offline, skip %s profiling.",
+                               cpu, metrics[mid].name);
+                       profile_perf_event_cnt++;
+                       return 0;
+               }
+               return -1;
+       }
+
+       if (bpf_map_update_elem(map_fd,
+                               &profile_perf_event_cnt,
+                               &pmu_fd, BPF_ANY) ||
+           ioctl(pmu_fd, PERF_EVENT_IOC_ENABLE, 0)) {
+               close(pmu_fd);
+               return -1;
+       }
+
+       profile_perf_events[profile_perf_event_cnt++] = pmu_fd;
+       return 0;
+}
+
 static int profile_open_perf_events(struct profiler_bpf *obj)
 {
        unsigned int cpu, m;
-       int map_fd, pmu_fd;
+       int map_fd;
 
        profile_perf_events = calloc(
                sizeof(int), obj->rodata->num_cpu * obj->rodata->num_metric);
                if (!metrics[m].selected)
                        continue;
                for (cpu = 0; cpu < obj->rodata->num_cpu; cpu++) {
-                       pmu_fd = syscall(__NR_perf_event_open, &metrics[m].attr,
-                                        -1/*pid*/, cpu, -1/*group_fd*/, 0);
-                       if (pmu_fd < 0 ||
-                           bpf_map_update_elem(map_fd, &profile_perf_event_cnt,
-                                               &pmu_fd, BPF_ANY) ||
-                           ioctl(pmu_fd, PERF_EVENT_IOC_ENABLE, 0)) {
+                       if (profile_open_perf_event(m, cpu, map_fd)) {
                                p_err("failed to create event %s on cpu %d",
                                      metrics[m].name, cpu);
                                return -1;
                        }
-                       profile_perf_events[profile_perf_event_cnt++] = pmu_fd;
                }
        }
        return 0;