[Kernel documentation] tracking points for using Linux kernel [tracepoint]

Source: Internet
Author: User

This document describes the tracking points in the Linux kernel and how to use them. The examples provided in this document detail how to insert tracing points in the kernel and how to associate probe functions with tracing points. Some examples of probe functions are also provided.

 

Purpose of tracking points

Tracing points in the Code provide hooks for calling probe functions at runtime. Tracking points can be enabled (connected to the probe function) or disabled (No probe function is connected ). Tracking points in the off state will not produce any effect, except for a little time overhead (checking the conditions of a branch Statement) and space overhead (add several code for function calling at the end of the instrumented function [do not know how to translate the appropriate], and add a Data Structure in the independent area ). If a tracing point is opened, the connection detection function is called every time the tracing point is executed, and it is in the invocation context of the caller. After the probe function is executed, it is returned to the caller (continue execution from the tracing point ).

Tracking points can be placed in important locations in the code. They are lightweight hook functions that can pass any number of parameters. The prototype can be found in the header file that defines the tracing point.

Tracking points can be used for system tracing and Performance Statistics.

Ø usage

Each tracking point contains two elements:

-
Tracking point definition. In the header file.

-
Tracking point declaration. In the c file.

When using tracing, the header file Linux/tracepoint. h.

For example, in the file [INCLUDE/Trace/subsys. H:

# Include <Linux/tracepoint. h>

 

Declare_trace (subsys_eventname,

Tp_proto (int
Firstarg, struct task_struct * P ),

Tp_args (firstarg,
P ));

In the file [subsys/file. C] (where the tracing declaration is added:

# Include <trace/subsys. h>

 

Define_trace (subsys_eventname );

 

Void somefct (void)

{

...

Trace_subsys_eventname (ARG,
Task );

...

}

In the Code:

-
Subsys_eventname is the descriptor of the event to be tracked.

-
Subsys is the name of the subsystem.

-
Eventname is the name of the event to be tracked.

-
Tp_proto (INT firstarg, struct
Task_struct * P) is the prototype of the probe function called by this tracing point.

-
Tp_args (firstarg, p) indicates the parameter name, which is the same as that in the prototype.

You can use the register_trace_subsys_eventname () function to bind a probe function to a tracing point. Unregister_trace_subsys_eventname () can remove a probe function.

Tracepoint_synchronize_unregister () must be called in the module's launch function to ensure that no code continues to use this probe function. This operation, coupled with the prohibition of preemption near the probe function, ensures that the removal of the probe function and the uninstallation of the module are safe.

The tracking point mechanism allows you to insert multiple instances of the same tracking point. However, the names of any tracing point must be unique throughout the kernel. Otherwise, type conflicts may occur. You can rename [name mangling] using the name of the prototype tracing point to ensure the correctness of the type. Verification of the type correctness of the probe function is performed by the compiler when the probe function is registered. Tracking points can be placed in inline functions, inline static functions, unrolled loops, and common functions.

We recommend that you use the name framework "subsys_event", which effectively limits the conflict. The tracking point name is a global variable in the kernel: whether in the core kernel image or in the module, tracking points with the same name are considered to be the same tracking point.

If Tracing points must be used in the kernel module, you can use export_tracepoint_symbol_gpl () or export_tracepoint_symbol () to export these tracing points.

Ø probe/Trace point instance

See examples provided in samples/tracepoints.

They need to be compiled with the kernel. If you select config_sample_tracepoints = m, these examples will be compiled during the make operation (instead of 'make
Modules ').

Enter the system as root:

Modprobe tracepoint-sample (insmod order is not important)

Modprobe tracepoint-probe-Sample

CAT/proc/tracepoint-sample (returns an expected error)

Rmmod tracepoint-sample tracepoint-probe-Sample

Dmesg

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.