Skip to content

getcpu

Intro

getcpu - Find the current processors system call.

Description

The getcpu() system call returns both the CPU and NUMA node on which the calling thread is currently executing as well as an abstract ‘cache’ (whose contents are only of use and meaning to the kernel) into two user-space arguments. This allows applications to, for instance, optimize data locality; i.e. determine if the data the thread is presently operating on is allocated in a way that the thread can maximize cache hits given its current CPU and node.

There are no edge-cases, drawbacks or advantages of using getcpu() as compared to other system calls as its purpose is simply to report the current processor and NUMA node for the calling thread of execution and nothing else.

Arguments

  • cpu:unsigned int*[KU] - pointer to an integer into which the CPU number will be written. If a null value is passed, no CPU number is returned.
  • node:unsigned int*[KU] - pointer to an integer into which the NUMA node number will be written. If a null value is passed, no NUMA node number is returned.
  • tcache:struct getcpu_cache*[KU] - pointer to a getcpu cache structure. If a null value is passed, no getcpu cache structure is returned.

Available Tags

  • K - Originated from kernel-space.
  • U - Originated from user space (for example, pointer to user space memory used to get it)
  • OPT - Optional argument - might not always be available (passed with null value)

Hooks

sys_getcpu()

Type

Kprobes

Purpose

To track the usage of the getcpu() syscall and log any data that might be relevant to the developers.

Example Use Case

The getcpu() system call can be used in applications to optimize data locality, i.e. determine if the data the thread is presently operating on is allocated in a way that the thread can maximize cache hits given its current CPU and node. This can be especially useful for applications that are running on large systems with multiple processors and NUMA nodes.

Issues

None.

  • sched_migrate_task() - Used to migrate a task between different CPUs or NUMA nodes.
  • sched_setaffinity() - Used to set an affinity mask for a process or thread.

This document was automatically generated by OpenAI and needs review. It might not be accurate and might contain errors. The authors of Tracee recommend that the user reads the "events.go" source file to understand the events and their arguments better.