handle ENOMEM in tools/offcputime
Summary: BPF_STACK_TRACE(_name, _size) will allocate space for _size stack traces (see https://github.com/torvalds/linux/blob/master/kernel/bpf/stackmap.c#L30-L50). If we've already used all of this space, subsequent calls to bpf_get_stackid() will return -ENOMEM (see https://github.com/torvalds/linux/blob/master/kernel/bpf/stackmap.c#L173-L176). This causes our BPF bytecode to store this value in key_t.stack_id and subsequently causes our python application to crash due to a KeyError when invoking stack_traces.walk(k.stack_id). Let's avoid calling stack_traces.walk(k.stack_id) with back stackid's Test Plan: Run offcputime.py in an extreme case; with space for only a single stack trace ``` devbig680[bcc](tools): sed_in_file 's/BPF_STACK_TRACE(stack_traces, 1024)/BPF_STACK_TRACE(stack_traces, 1)/' tools/offcputime.py && \ > ~/bcc_run_tool.sh offcputime -f 5; \ > git reset --hard HEAD swapper/30;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 496 swapper/26;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 553 swapper/28;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 604 swapper/31;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 692 swapper/23;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 713 swapper/18;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 919 swapper/16;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 1051 swapper/20;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 1056 swapper/21;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 1585 swapper/24;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 1597 swapper/27;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 1610 swapper/17;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 1674 swapper/22;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 2390 swapper/25;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 2574 swapper/19;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 2589 swapper/29;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 8428 swapper/8;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 15272 swapper/15;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 15591 swapper/11;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 17934 swapper/9;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 18100 swapper/14;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 18266 swapper/10;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 20124 swapper/12;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 20887 swapper/13;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 23453 swapper/3;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 27296 swapper/5;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 29094 swapper/6;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 29799 swapper/7;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 31522 swapper/1;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 32269 swapper/4;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 35585 swapper/2;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 37627 WARNING: 249 stack traces could not be displayed. Consider increasing stack trace storage size. HEAD is now at d3365e9 [RFC] handle ENOMEM in tools/offcputime` ```
Showing
Please register or sign in to comment