Skip to content

Helper function bpf_get_smp_processor_id

v4.1

Definition

Copyright (c) 2015 The Libbpf Authors. All rights reserved.

Get the SMP (symmetric multiprocessing) processor id. Note that all programs run with migration disabled, which means that the SMP processor id is stable during all the execution of the program.

Returns

The SMP id of the processor running the program.

static __bpf_fastcall __u32 (* const bpf_get_smp_processor_id)(void) = (void *) 8;

Usage

The bpf_get_smp_processor_id helper function returns a 32-bit value, containing the id of the current SMP (symmetric multiprocessing) processor executing the program. This helper function allows eBPF programs to identify the processor id, which can be useful for performance monitoring or debugging.

Program types

This helper call can be used in the following program types:

Example

#include <vmlinux.h>
#include <bpf/bpf_helpers.h>

SEC("tp/syscalls/sys_enter_open")
int sys_open_trace(void *ctx) {
    __u32 processor = bpf_get_smp_processor_id();
    bpf_printk("Executed on processor %u.\n", processor);
    return 0;
}