@@ -93,6 +93,9 @@ static int open_and_attach_perf_event(__u64 config, int period,
9393 for (i = 0 ; i < nr_cpus ; i ++ ) {
9494 fd = syscall (__NR_perf_event_open , & attr , -1 , i , -1 , 0 );
9595 if (fd < 0 ) {
96+ /* Ignore CPU that is offline */
97+ if (errno == ENODEV )
98+ continue ;
9699 fprintf (stderr , "failed to init perf sampling: %s\n" ,
97100 strerror (errno ));
98101 return -1 ;
@@ -185,23 +188,22 @@ int main(int argc, char **argv)
185188 return 1 ;
186189 }
187190
188- obj = llcstat_bpf__open ();
189- if (!obj ) {
190- fprintf (stderr , "failed to open BPF object\n" );
191+ nr_cpus = libbpf_num_possible_cpus ();
192+ if (nr_cpus < 0 ) {
193+ fprintf (stderr , "failed to get # of possible cpus: '%s'!\n" ,
194+ strerror (- nr_cpus ));
191195 return 1 ;
192196 }
193-
194- nr_cpus = libbpf_num_possible_cpus ();
195197 mlinks = calloc (nr_cpus , sizeof (* mlinks ));
196198 rlinks = calloc (nr_cpus , sizeof (* rlinks ));
197199 if (!mlinks || !rlinks ) {
198200 fprintf (stderr , "failed to alloc mlinks or rlinks\n" );
199- goto cleanup ;
201+ return 1 ;
200202 }
201203
202- err = llcstat_bpf__load ( obj );
203- if (err ) {
204- fprintf (stderr , "failed to load BPF object: %d \n" , err );
204+ obj = llcstat_bpf__open_and_load ( );
205+ if (! obj ) {
206+ fprintf (stderr , "failed to open and/or load BPF object\n" );
205207 goto cleanup ;
206208 }
207209
0 commit comments