162306a36Sopenharmony_ci.. SPDX-License-Identifier: (GPL-2.0+ OR CC-BY-4.0) 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci====================================================== 462306a36Sopenharmony_ciDiscovering Linux kernel subsystems used by a workload 562306a36Sopenharmony_ci====================================================== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci:Authors: - Shuah Khan <skhan@linuxfoundation.org> 862306a36Sopenharmony_ci - Shefali Sharma <sshefali021@gmail.com> 962306a36Sopenharmony_ci:maintained-by: Shuah Khan <skhan@linuxfoundation.org> 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciKey Points 1262306a36Sopenharmony_ci========== 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci * Understanding system resources necessary to build and run a workload 1562306a36Sopenharmony_ci is important. 1662306a36Sopenharmony_ci * Linux tracing and strace can be used to discover the system resources 1762306a36Sopenharmony_ci in use by a workload. The completeness of the system usage information 1862306a36Sopenharmony_ci depends on the completeness of coverage of a workload. 1962306a36Sopenharmony_ci * Performance and security of the operating system can be analyzed with 2062306a36Sopenharmony_ci the help of tools such as: 2162306a36Sopenharmony_ci `perf <https://man7.org/linux/man-pages/man1/perf.1.html>`_, 2262306a36Sopenharmony_ci `stress-ng <https://www.mankier.com/1/stress-ng>`_, 2362306a36Sopenharmony_ci `paxtest <https://github.com/opntr/paxtest-freebsd>`_. 2462306a36Sopenharmony_ci * Once we discover and understand the workload needs, we can focus on them 2562306a36Sopenharmony_ci to avoid regressions and use it to evaluate safety considerations. 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ciMethodology 2862306a36Sopenharmony_ci=========== 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci`strace <https://man7.org/linux/man-pages/man1/strace.1.html>`_ is a 3162306a36Sopenharmony_cidiagnostic, instructional, and debugging tool and can be used to discover 3262306a36Sopenharmony_cithe system resources in use by a workload. Once we discover and understand 3362306a36Sopenharmony_cithe workload needs, we can focus on them to avoid regressions and use it 3462306a36Sopenharmony_cito evaluate safety considerations. We use strace tool to trace workloads. 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ciThis method of tracing using strace tells us the system calls invoked by 3762306a36Sopenharmony_cithe workload and doesn't include all the system calls that can be invoked 3862306a36Sopenharmony_ciby it. In addition, this tracing method tells us just the code paths within 3962306a36Sopenharmony_cithese system calls that are invoked. As an example, if a workload opens a 4062306a36Sopenharmony_cifile and reads from it successfully, then the success path is the one that 4162306a36Sopenharmony_ciis traced. Any error paths in that system call will not be traced. If there 4262306a36Sopenharmony_ciis a workload that provides full coverage of a workload then the method 4362306a36Sopenharmony_cioutlined here will trace and find all possible code paths. The completeness 4462306a36Sopenharmony_ciof the system usage information depends on the completeness of coverage of a 4562306a36Sopenharmony_ciworkload. 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ciThe goal is tracing a workload on a system running a default kernel without 4862306a36Sopenharmony_cirequiring custom kernel installs. 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ciHow do we gather fine-grained system information? 5162306a36Sopenharmony_ci================================================= 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_cistrace tool can be used to trace system calls made by a process and signals 5462306a36Sopenharmony_ciit receives. System calls are the fundamental interface between an 5562306a36Sopenharmony_ciapplication and the operating system kernel. They enable a program to 5662306a36Sopenharmony_cirequest services from the kernel. For instance, the open() system call in 5762306a36Sopenharmony_ciLinux is used to provide access to a file in the file system. strace enables 5862306a36Sopenharmony_cius to track all the system calls made by an application. It lists all the 5962306a36Sopenharmony_cisystem calls made by a process and their resulting output. 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ciYou can generate profiling data combining strace and perf record tools to 6262306a36Sopenharmony_cirecord the events and information associated with a process. This provides 6362306a36Sopenharmony_ciinsight into the process. "perf annotate" tool generates the statistics of 6462306a36Sopenharmony_cieach instruction of the program. This document goes over the details of how 6562306a36Sopenharmony_cito gather fine-grained information on a workload's usage of system resources. 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ciWe used strace to trace the perf, stress-ng, paxtest workloads to illustrate 6862306a36Sopenharmony_ciour methodology to discover resources used by a workload. This process can 6962306a36Sopenharmony_cibe applied to trace other workloads. 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ciGetting the system ready for tracing 7262306a36Sopenharmony_ci==================================== 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ciBefore we can get started we will show you how to get your system ready. 7562306a36Sopenharmony_ciWe assume that you have a Linux distribution running on a physical system 7662306a36Sopenharmony_cior a virtual machine. Most distributions will include strace command. Let’s 7762306a36Sopenharmony_ciinstall other tools that aren’t usually included to build Linux kernel. 7862306a36Sopenharmony_ciPlease note that the following works on Debian based distributions. You 7962306a36Sopenharmony_cimight have to find equivalent packages on other Linux distributions. 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ciInstall tools to build Linux kernel and tools in kernel repository. 8262306a36Sopenharmony_ciscripts/ver_linux is a good way to check if your system already has 8362306a36Sopenharmony_cithe necessary tools:: 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci sudo apt-get build-essentials flex bison yacc 8662306a36Sopenharmony_ci sudo apt install libelf-dev systemtap-sdt-dev libaudit-dev libslang2-dev libperl-dev libdw-dev 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_cicscope is a good tool to browse kernel sources. Let's install it now:: 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci sudo apt-get install cscope 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ciInstall stress-ng and paxtest:: 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci apt-get install stress-ng 9562306a36Sopenharmony_ci apt-get install paxtest 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ciWorkload overview 9862306a36Sopenharmony_ci================= 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ciAs mentioned earlier, we used strace to trace perf bench, stress-ng and 10162306a36Sopenharmony_cipaxtest workloads to show how to analyze a workload and identify Linux 10262306a36Sopenharmony_cisubsystems used by these workloads. Let's start with an overview of these 10362306a36Sopenharmony_cithree workloads to get a better understanding of what they do and how to 10462306a36Sopenharmony_ciuse them. 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ciperf bench (all) workload 10762306a36Sopenharmony_ci------------------------- 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ciThe perf bench command contains multiple multi-threaded microkernel 11062306a36Sopenharmony_cibenchmarks for executing different subsystems in the Linux kernel and 11162306a36Sopenharmony_cisystem calls. This allows us to easily measure the impact of changes, 11262306a36Sopenharmony_ciwhich can help mitigate performance regressions. It also acts as a common 11362306a36Sopenharmony_cibenchmarking framework, enabling developers to easily create test cases, 11462306a36Sopenharmony_ciintegrate transparently, and use performance-rich tooling subsystems. 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ciStress-ng netdev stressor workload 11762306a36Sopenharmony_ci---------------------------------- 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_cistress-ng is used for performing stress testing on the kernel. It allows 12062306a36Sopenharmony_ciyou to exercise various physical subsystems of the computer, as well as 12162306a36Sopenharmony_ciinterfaces of the OS kernel, using "stressor-s". They are available for 12262306a36Sopenharmony_ciCPU, CPU cache, devices, I/O, interrupts, file system, memory, network, 12362306a36Sopenharmony_cioperating system, pipelines, schedulers, and virtual machines. Please refer 12462306a36Sopenharmony_cito the `stress-ng man-page <https://www.mankier.com/1/stress-ng>`_ to 12562306a36Sopenharmony_cifind the description of all the available stressor-s. The netdev stressor 12662306a36Sopenharmony_cistarts specified number (N) of workers that exercise various netdevice 12762306a36Sopenharmony_ciioctl commands across all the available network devices. 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_cipaxtest kiddie workload 13062306a36Sopenharmony_ci----------------------- 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_cipaxtest is a program that tests buffer overflows in the kernel. It tests 13362306a36Sopenharmony_cikernel enforcements over memory usage. Generally, execution in some memory 13462306a36Sopenharmony_cisegments makes buffer overflows possible. It runs a set of programs that 13562306a36Sopenharmony_ciattempt to subvert memory usage. It is used as a regression test suite for 13662306a36Sopenharmony_ciPaX, but might be useful to test other memory protection patches for the 13762306a36Sopenharmony_cikernel. We used paxtest kiddie mode which looks for simple vulnerabilities. 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ciWhat is strace and how do we use it? 14062306a36Sopenharmony_ci==================================== 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ciAs mentioned earlier, strace which is a useful diagnostic, instructional, 14362306a36Sopenharmony_ciand debugging tool and can be used to discover the system resources in use 14462306a36Sopenharmony_ciby a workload. It can be used: 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci * To see how a process interacts with the kernel. 14762306a36Sopenharmony_ci * To see why a process is failing or hanging. 14862306a36Sopenharmony_ci * For reverse engineering a process. 14962306a36Sopenharmony_ci * To find the files on which a program depends. 15062306a36Sopenharmony_ci * For analyzing the performance of an application. 15162306a36Sopenharmony_ci * For troubleshooting various problems related to the operating system. 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ciIn addition, strace can generate run-time statistics on times, calls, and 15462306a36Sopenharmony_cierrors for each system call and report a summary when program exits, 15562306a36Sopenharmony_cisuppressing the regular output. This attempts to show system time (CPU time 15662306a36Sopenharmony_cispent running in the kernel) independent of wall clock time. We plan to use 15762306a36Sopenharmony_cithese features to get information on workload system usage. 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_cistrace command supports basic, verbose, and stats modes. strace command when 16062306a36Sopenharmony_cirun in verbose mode gives more detailed information about the system calls 16162306a36Sopenharmony_ciinvoked by a process. 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ciRunning strace -c generates a report of the percentage of time spent in each 16462306a36Sopenharmony_cisystem call, the total time in seconds, the microseconds per call, the total 16562306a36Sopenharmony_cinumber of calls, the count of each system call that has failed with an error 16662306a36Sopenharmony_ciand the type of system call made. 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_ci * Usage: strace <command we want to trace> 16962306a36Sopenharmony_ci * Verbose mode usage: strace -v <command> 17062306a36Sopenharmony_ci * Gather statistics: strace -c <command> 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ciWe used the “-c” option to gather fine-grained run-time statistics in use 17362306a36Sopenharmony_ciby three workloads we have chose for this analysis. 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci * perf 17662306a36Sopenharmony_ci * stress-ng 17762306a36Sopenharmony_ci * paxtest 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ciWhat is cscope and how do we use it? 18062306a36Sopenharmony_ci==================================== 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ciNow let’s look at `cscope <https://cscope.sourceforge.net/>`_, a command 18362306a36Sopenharmony_ciline tool for browsing C, C++ or Java code-bases. We can use it to find 18462306a36Sopenharmony_ciall the references to a symbol, global definitions, functions called by a 18562306a36Sopenharmony_cifunction, functions calling a function, text strings, regular expression 18662306a36Sopenharmony_cipatterns, files including a file. 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ciWe can use cscope to find which system call belongs to which subsystem. 18962306a36Sopenharmony_ciThis way we can find the kernel subsystems used by a process when it is 19062306a36Sopenharmony_ciexecuted. 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ciLet’s checkout the latest Linux repository and build cscope database:: 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git linux 19562306a36Sopenharmony_ci cd linux 19662306a36Sopenharmony_ci cscope -R -p10 # builds cscope.out database before starting browse session 19762306a36Sopenharmony_ci cscope -d -p10 # starts browse session on cscope.out database 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ciNote: Run "cscope -R -p10" to build the database and c"scope -d -p10" to 20062306a36Sopenharmony_cienter into the browsing session. cscope by default cscope.out database. 20162306a36Sopenharmony_ciTo get out of this mode press ctrl+d. -p option is used to specify the 20262306a36Sopenharmony_cinumber of file path components to display. -p10 is optimal for browsing 20362306a36Sopenharmony_cikernel sources. 20462306a36Sopenharmony_ci 20562306a36Sopenharmony_ciWhat is perf and how do we use it? 20662306a36Sopenharmony_ci================================== 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ciPerf is an analysis tool based on Linux 2.6+ systems, which abstracts the 20962306a36Sopenharmony_ciCPU hardware difference in performance measurement in Linux, and provides 21062306a36Sopenharmony_cia simple command line interface. Perf is based on the perf_events interface 21162306a36Sopenharmony_ciexported by the kernel. It is very useful for profiling the system and 21262306a36Sopenharmony_cifinding performance bottlenecks in an application. 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ciIf you haven't already checked out the Linux mainline repository, you can do 21562306a36Sopenharmony_ciso and then build kernel and perf tool:: 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git linux 21862306a36Sopenharmony_ci cd linux 21962306a36Sopenharmony_ci make -j3 all 22062306a36Sopenharmony_ci cd tools/perf 22162306a36Sopenharmony_ci make 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ciNote: The perf command can be built without building the kernel in the 22462306a36Sopenharmony_cirepository and can be run on older kernels. However matching the kernel 22562306a36Sopenharmony_ciand perf revisions gives more accurate information on the subsystem usage. 22662306a36Sopenharmony_ci 22762306a36Sopenharmony_ciWe used "perf stat" and "perf bench" options. For a detailed information on 22862306a36Sopenharmony_cithe perf tool, run "perf -h". 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ciperf stat 23162306a36Sopenharmony_ci--------- 23262306a36Sopenharmony_ciThe perf stat command generates a report of various hardware and software 23362306a36Sopenharmony_cievents. It does so with the help of hardware counter registers found in 23462306a36Sopenharmony_cimodern CPUs that keep the count of these activities. "perf stat cal" shows 23562306a36Sopenharmony_cistats for cal command. 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_ciPerf bench 23862306a36Sopenharmony_ci---------- 23962306a36Sopenharmony_ciThe perf bench command contains multiple multi-threaded microkernel 24062306a36Sopenharmony_cibenchmarks for executing different subsystems in the Linux kernel and 24162306a36Sopenharmony_cisystem calls. This allows us to easily measure the impact of changes, 24262306a36Sopenharmony_ciwhich can help mitigate performance regressions. It also acts as a common 24362306a36Sopenharmony_cibenchmarking framework, enabling developers to easily create test cases, 24462306a36Sopenharmony_ciintegrate transparently, and use performance-rich tooling. 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ci"perf bench all" command runs the following benchmarks: 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci * sched/messaging 24962306a36Sopenharmony_ci * sched/pipe 25062306a36Sopenharmony_ci * syscall/basic 25162306a36Sopenharmony_ci * mem/memcpy 25262306a36Sopenharmony_ci * mem/memset 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ciWhat is stress-ng and how do we use it? 25562306a36Sopenharmony_ci======================================= 25662306a36Sopenharmony_ci 25762306a36Sopenharmony_ciAs mentioned earlier, stress-ng is used for performing stress testing on 25862306a36Sopenharmony_cithe kernel. It allows you to exercise various physical subsystems of the 25962306a36Sopenharmony_cicomputer, as well as interfaces of the OS kernel, using stressor-s. They 26062306a36Sopenharmony_ciare available for CPU, CPU cache, devices, I/O, interrupts, file system, 26162306a36Sopenharmony_cimemory, network, operating system, pipelines, schedulers, and virtual 26262306a36Sopenharmony_cimachines. 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_ciThe netdev stressor starts N workers that exercise various netdevice ioctl 26562306a36Sopenharmony_cicommands across all the available network devices. The following ioctls are 26662306a36Sopenharmony_ciexercised: 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci * SIOCGIFCONF, SIOCGIFINDEX, SIOCGIFNAME, SIOCGIFFLAGS 26962306a36Sopenharmony_ci * SIOCGIFADDR, SIOCGIFNETMASK, SIOCGIFMETRIC, SIOCGIFMTU 27062306a36Sopenharmony_ci * SIOCGIFHWADDR, SIOCGIFMAP, SIOCGIFTXQLEN 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_ciThe following command runs the stressor:: 27362306a36Sopenharmony_ci 27462306a36Sopenharmony_ci stress-ng --netdev 1 -t 60 --metrics command. 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ciWe can use the perf record command to record the events and information 27762306a36Sopenharmony_ciassociated with a process. This command records the profiling data in the 27862306a36Sopenharmony_ciperf.data file in the same directory. 27962306a36Sopenharmony_ci 28062306a36Sopenharmony_ciUsing the following commands you can record the events associated with the 28162306a36Sopenharmony_cinetdev stressor, view the generated report perf.data and annotate the to 28262306a36Sopenharmony_ciview the statistics of each instruction of the program:: 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_ci perf record stress-ng --netdev 1 -t 60 --metrics command. 28562306a36Sopenharmony_ci perf report 28662306a36Sopenharmony_ci perf annotate 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ciWhat is paxtest and how do we use it? 28962306a36Sopenharmony_ci===================================== 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_cipaxtest is a program that tests buffer overflows in the kernel. It tests 29262306a36Sopenharmony_cikernel enforcements over memory usage. Generally, execution in some memory 29362306a36Sopenharmony_cisegments makes buffer overflows possible. It runs a set of programs that 29462306a36Sopenharmony_ciattempt to subvert memory usage. It is used as a regression test suite for 29562306a36Sopenharmony_ciPaX, and will be useful to test other memory protection patches for the 29662306a36Sopenharmony_cikernel. 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_cipaxtest provides kiddie and blackhat modes. The paxtest kiddie mode runs 29962306a36Sopenharmony_ciin normal mode, whereas the blackhat mode tries to get around the protection 30062306a36Sopenharmony_ciof the kernel testing for vulnerabilities. We focus on the kiddie mode here 30162306a36Sopenharmony_ciand combine "paxtest kiddie" run with "perf record" to collect CPU stack 30262306a36Sopenharmony_citraces for the paxtest kiddie run to see which function is calling other 30362306a36Sopenharmony_cifunctions in the performance profile. Then the "dwarf" (DWARF's Call Frame 30462306a36Sopenharmony_ciInformation) mode can be used to unwind the stack. 30562306a36Sopenharmony_ci 30662306a36Sopenharmony_ciThe following command can be used to view resulting report in call-graph 30762306a36Sopenharmony_ciformat:: 30862306a36Sopenharmony_ci 30962306a36Sopenharmony_ci perf record --call-graph dwarf paxtest kiddie 31062306a36Sopenharmony_ci perf report --stdio 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_ciTracing workloads 31362306a36Sopenharmony_ci================= 31462306a36Sopenharmony_ci 31562306a36Sopenharmony_ciNow that we understand the workloads, let's start tracing them. 31662306a36Sopenharmony_ci 31762306a36Sopenharmony_ciTracing perf bench all workload 31862306a36Sopenharmony_ci------------------------------- 31962306a36Sopenharmony_ci 32062306a36Sopenharmony_ciRun the following command to trace perf bench all workload:: 32162306a36Sopenharmony_ci 32262306a36Sopenharmony_ci strace -c perf bench all 32362306a36Sopenharmony_ci 32462306a36Sopenharmony_ci**System Calls made by the workload** 32562306a36Sopenharmony_ci 32662306a36Sopenharmony_ciThe below table shows the system calls invoked by the workload, number of 32762306a36Sopenharmony_citimes each system call is invoked, and the corresponding Linux subsystem. 32862306a36Sopenharmony_ci 32962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 33062306a36Sopenharmony_ci| System Call | # calls | Linux Subsystem | System Call (API) | 33162306a36Sopenharmony_ci+===================+===========+=================+=========================+ 33262306a36Sopenharmony_ci| getppid | 10000001 | Process Mgmt | sys_getpid() | 33362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 33462306a36Sopenharmony_ci| clone | 1077 | Process Mgmt. | sys_clone() | 33562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 33662306a36Sopenharmony_ci| prctl | 23 | Process Mgmt. | sys_prctl() | 33762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 33862306a36Sopenharmony_ci| prlimit64 | 7 | Process Mgmt. | sys_prlimit64() | 33962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 34062306a36Sopenharmony_ci| getpid | 10 | Process Mgmt. | sys_getpid() | 34162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 34262306a36Sopenharmony_ci| uname | 3 | Process Mgmt. | sys_uname() | 34362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 34462306a36Sopenharmony_ci| sysinfo | 1 | Process Mgmt. | sys_sysinfo() | 34562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 34662306a36Sopenharmony_ci| getuid | 1 | Process Mgmt. | sys_getuid() | 34762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 34862306a36Sopenharmony_ci| getgid | 1 | Process Mgmt. | sys_getgid() | 34962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 35062306a36Sopenharmony_ci| geteuid | 1 | Process Mgmt. | sys_geteuid() | 35162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 35262306a36Sopenharmony_ci| getegid | 1 | Process Mgmt. | sys_getegid | 35362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 35462306a36Sopenharmony_ci| close | 49951 | Filesystem | sys_close() | 35562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 35662306a36Sopenharmony_ci| pipe | 604 | Filesystem | sys_pipe() | 35762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 35862306a36Sopenharmony_ci| openat | 48560 | Filesystem | sys_opennat() | 35962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 36062306a36Sopenharmony_ci| fstat | 8338 | Filesystem | sys_fstat() | 36162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 36262306a36Sopenharmony_ci| stat | 1573 | Filesystem | sys_stat() | 36362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 36462306a36Sopenharmony_ci| pread64 | 9646 | Filesystem | sys_pread64() | 36562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 36662306a36Sopenharmony_ci| getdents64 | 1873 | Filesystem | sys_getdents64() | 36762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 36862306a36Sopenharmony_ci| access | 3 | Filesystem | sys_access() | 36962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 37062306a36Sopenharmony_ci| lstat | 1880 | Filesystem | sys_lstat() | 37162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 37262306a36Sopenharmony_ci| lseek | 6 | Filesystem | sys_lseek() | 37362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 37462306a36Sopenharmony_ci| ioctl | 3 | Filesystem | sys_ioctl() | 37562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 37662306a36Sopenharmony_ci| dup2 | 1 | Filesystem | sys_dup2() | 37762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 37862306a36Sopenharmony_ci| execve | 2 | Filesystem | sys_execve() | 37962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 38062306a36Sopenharmony_ci| fcntl | 8779 | Filesystem | sys_fcntl() | 38162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 38262306a36Sopenharmony_ci| statfs | 1 | Filesystem | sys_statfs() | 38362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 38462306a36Sopenharmony_ci| epoll_create | 2 | Filesystem | sys_epoll_create() | 38562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 38662306a36Sopenharmony_ci| epoll_ctl | 64 | Filesystem | sys_epoll_ctl() | 38762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 38862306a36Sopenharmony_ci| newfstatat | 8318 | Filesystem | sys_newfstatat() | 38962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 39062306a36Sopenharmony_ci| eventfd2 | 192 | Filesystem | sys_eventfd2() | 39162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 39262306a36Sopenharmony_ci| mmap | 243 | Memory Mgmt. | sys_mmap() | 39362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 39462306a36Sopenharmony_ci| mprotect | 32 | Memory Mgmt. | sys_mprotect() | 39562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 39662306a36Sopenharmony_ci| brk | 21 | Memory Mgmt. | sys_brk() | 39762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 39862306a36Sopenharmony_ci| munmap | 128 | Memory Mgmt. | sys_munmap() | 39962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 40062306a36Sopenharmony_ci| set_mempolicy | 156 | Memory Mgmt. | sys_set_mempolicy() | 40162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 40262306a36Sopenharmony_ci| set_tid_address | 1 | Process Mgmt. | sys_set_tid_address() | 40362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 40462306a36Sopenharmony_ci| set_robust_list | 1 | Futex | sys_set_robust_list() | 40562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 40662306a36Sopenharmony_ci| futex | 341 | Futex | sys_futex() | 40762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 40862306a36Sopenharmony_ci| sched_getaffinity | 79 | Scheduler | sys_sched_getaffinity() | 40962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 41062306a36Sopenharmony_ci| sched_setaffinity | 223 | Scheduler | sys_sched_setaffinity() | 41162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 41262306a36Sopenharmony_ci| socketpair | 202 | Network | sys_socketpair() | 41362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 41462306a36Sopenharmony_ci| rt_sigprocmask | 21 | Signal | sys_rt_sigprocmask() | 41562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 41662306a36Sopenharmony_ci| rt_sigaction | 36 | Signal | sys_rt_sigaction() | 41762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 41862306a36Sopenharmony_ci| rt_sigreturn | 2 | Signal | sys_rt_sigreturn() | 41962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 42062306a36Sopenharmony_ci| wait4 | 889 | Time | sys_wait4() | 42162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 42262306a36Sopenharmony_ci| clock_nanosleep | 37 | Time | sys_clock_nanosleep() | 42362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 42462306a36Sopenharmony_ci| capget | 4 | Capability | sys_capget() | 42562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 42662306a36Sopenharmony_ci 42762306a36Sopenharmony_ciTracing stress-ng netdev stressor workload 42862306a36Sopenharmony_ci------------------------------------------ 42962306a36Sopenharmony_ci 43062306a36Sopenharmony_ciRun the following command to trace stress-ng netdev stressor workload:: 43162306a36Sopenharmony_ci 43262306a36Sopenharmony_ci strace -c stress-ng --netdev 1 -t 60 --metrics 43362306a36Sopenharmony_ci 43462306a36Sopenharmony_ci**System Calls made by the workload** 43562306a36Sopenharmony_ci 43662306a36Sopenharmony_ciThe below table shows the system calls invoked by the workload, number of 43762306a36Sopenharmony_citimes each system call is invoked, and the corresponding Linux subsystem. 43862306a36Sopenharmony_ci 43962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 44062306a36Sopenharmony_ci| System Call | # calls | Linux Subsystem | System Call (API) | 44162306a36Sopenharmony_ci+===================+===========+=================+=========================+ 44262306a36Sopenharmony_ci| openat | 74 | Filesystem | sys_openat() | 44362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 44462306a36Sopenharmony_ci| close | 75 | Filesystem | sys_close() | 44562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 44662306a36Sopenharmony_ci| read | 58 | Filesystem | sys_read() | 44762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 44862306a36Sopenharmony_ci| fstat | 20 | Filesystem | sys_fstat() | 44962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 45062306a36Sopenharmony_ci| flock | 10 | Filesystem | sys_flock() | 45162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 45262306a36Sopenharmony_ci| write | 7 | Filesystem | sys_write() | 45362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 45462306a36Sopenharmony_ci| getdents64 | 8 | Filesystem | sys_getdents64() | 45562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 45662306a36Sopenharmony_ci| pread64 | 8 | Filesystem | sys_pread64() | 45762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 45862306a36Sopenharmony_ci| lseek | 1 | Filesystem | sys_lseek() | 45962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 46062306a36Sopenharmony_ci| access | 2 | Filesystem | sys_access() | 46162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 46262306a36Sopenharmony_ci| getcwd | 1 | Filesystem | sys_getcwd() | 46362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 46462306a36Sopenharmony_ci| execve | 1 | Filesystem | sys_execve() | 46562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 46662306a36Sopenharmony_ci| mmap | 61 | Memory Mgmt. | sys_mmap() | 46762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 46862306a36Sopenharmony_ci| munmap | 3 | Memory Mgmt. | sys_munmap() | 46962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 47062306a36Sopenharmony_ci| mprotect | 20 | Memory Mgmt. | sys_mprotect() | 47162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 47262306a36Sopenharmony_ci| mlock | 2 | Memory Mgmt. | sys_mlock() | 47362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 47462306a36Sopenharmony_ci| brk | 3 | Memory Mgmt. | sys_brk() | 47562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 47662306a36Sopenharmony_ci| rt_sigaction | 21 | Signal | sys_rt_sigaction() | 47762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 47862306a36Sopenharmony_ci| rt_sigprocmask | 1 | Signal | sys_rt_sigprocmask() | 47962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 48062306a36Sopenharmony_ci| sigaltstack | 1 | Signal | sys_sigaltstack() | 48162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 48262306a36Sopenharmony_ci| rt_sigreturn | 1 | Signal | sys_rt_sigreturn() | 48362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 48462306a36Sopenharmony_ci| getpid | 8 | Process Mgmt. | sys_getpid() | 48562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 48662306a36Sopenharmony_ci| prlimit64 | 5 | Process Mgmt. | sys_prlimit64() | 48762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 48862306a36Sopenharmony_ci| arch_prctl | 2 | Process Mgmt. | sys_arch_prctl() | 48962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 49062306a36Sopenharmony_ci| sysinfo | 2 | Process Mgmt. | sys_sysinfo() | 49162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 49262306a36Sopenharmony_ci| getuid | 2 | Process Mgmt. | sys_getuid() | 49362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 49462306a36Sopenharmony_ci| uname | 1 | Process Mgmt. | sys_uname() | 49562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 49662306a36Sopenharmony_ci| setpgid | 1 | Process Mgmt. | sys_setpgid() | 49762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 49862306a36Sopenharmony_ci| getrusage | 1 | Process Mgmt. | sys_getrusage() | 49962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 50062306a36Sopenharmony_ci| geteuid | 1 | Process Mgmt. | sys_geteuid() | 50162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 50262306a36Sopenharmony_ci| getppid | 1 | Process Mgmt. | sys_getppid() | 50362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 50462306a36Sopenharmony_ci| sendto | 3 | Network | sys_sendto() | 50562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 50662306a36Sopenharmony_ci| connect | 1 | Network | sys_connect() | 50762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 50862306a36Sopenharmony_ci| socket | 1 | Network | sys_socket() | 50962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 51062306a36Sopenharmony_ci| clone | 1 | Process Mgmt. | sys_clone() | 51162306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 51262306a36Sopenharmony_ci| set_tid_address | 1 | Process Mgmt. | sys_set_tid_address() | 51362306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 51462306a36Sopenharmony_ci| wait4 | 2 | Time | sys_wait4() | 51562306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 51662306a36Sopenharmony_ci| alarm | 1 | Time | sys_alarm() | 51762306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 51862306a36Sopenharmony_ci| set_robust_list | 1 | Futex | sys_set_robust_list() | 51962306a36Sopenharmony_ci+-------------------+-----------+-----------------+-------------------------+ 52062306a36Sopenharmony_ci 52162306a36Sopenharmony_ciTracing paxtest kiddie workload 52262306a36Sopenharmony_ci------------------------------- 52362306a36Sopenharmony_ci 52462306a36Sopenharmony_ciRun the following command to trace paxtest kiddie workload:: 52562306a36Sopenharmony_ci 52662306a36Sopenharmony_ci strace -c paxtest kiddie 52762306a36Sopenharmony_ci 52862306a36Sopenharmony_ci**System Calls made by the workload** 52962306a36Sopenharmony_ci 53062306a36Sopenharmony_ciThe below table shows the system calls invoked by the workload, number of 53162306a36Sopenharmony_citimes each system call is invoked, and the corresponding Linux subsystem. 53262306a36Sopenharmony_ci 53362306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 53462306a36Sopenharmony_ci| System Call | # calls | Linux Subsystem | System Call (API) | 53562306a36Sopenharmony_ci+===================+===========+=================+======================+ 53662306a36Sopenharmony_ci| read | 3 | Filesystem | sys_read() | 53762306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 53862306a36Sopenharmony_ci| write | 11 | Filesystem | sys_write() | 53962306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 54062306a36Sopenharmony_ci| close | 41 | Filesystem | sys_close() | 54162306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 54262306a36Sopenharmony_ci| stat | 24 | Filesystem | sys_stat() | 54362306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 54462306a36Sopenharmony_ci| fstat | 2 | Filesystem | sys_fstat() | 54562306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 54662306a36Sopenharmony_ci| pread64 | 6 | Filesystem | sys_pread64() | 54762306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 54862306a36Sopenharmony_ci| access | 1 | Filesystem | sys_access() | 54962306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 55062306a36Sopenharmony_ci| pipe | 1 | Filesystem | sys_pipe() | 55162306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 55262306a36Sopenharmony_ci| dup2 | 24 | Filesystem | sys_dup2() | 55362306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 55462306a36Sopenharmony_ci| execve | 1 | Filesystem | sys_execve() | 55562306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 55662306a36Sopenharmony_ci| fcntl | 26 | Filesystem | sys_fcntl() | 55762306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 55862306a36Sopenharmony_ci| openat | 14 | Filesystem | sys_openat() | 55962306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 56062306a36Sopenharmony_ci| rt_sigaction | 7 | Signal | sys_rt_sigaction() | 56162306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 56262306a36Sopenharmony_ci| rt_sigreturn | 38 | Signal | sys_rt_sigreturn() | 56362306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 56462306a36Sopenharmony_ci| clone | 38 | Process Mgmt. | sys_clone() | 56562306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 56662306a36Sopenharmony_ci| wait4 | 44 | Time | sys_wait4() | 56762306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 56862306a36Sopenharmony_ci| mmap | 7 | Memory Mgmt. | sys_mmap() | 56962306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 57062306a36Sopenharmony_ci| mprotect | 3 | Memory Mgmt. | sys_mprotect() | 57162306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 57262306a36Sopenharmony_ci| munmap | 1 | Memory Mgmt. | sys_munmap() | 57362306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 57462306a36Sopenharmony_ci| brk | 3 | Memory Mgmt. | sys_brk() | 57562306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 57662306a36Sopenharmony_ci| getpid | 1 | Process Mgmt. | sys_getpid() | 57762306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 57862306a36Sopenharmony_ci| getuid | 1 | Process Mgmt. | sys_getuid() | 57962306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 58062306a36Sopenharmony_ci| getgid | 1 | Process Mgmt. | sys_getgid() | 58162306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 58262306a36Sopenharmony_ci| geteuid | 2 | Process Mgmt. | sys_geteuid() | 58362306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 58462306a36Sopenharmony_ci| getegid | 1 | Process Mgmt. | sys_getegid() | 58562306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 58662306a36Sopenharmony_ci| getppid | 1 | Process Mgmt. | sys_getppid() | 58762306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 58862306a36Sopenharmony_ci| arch_prctl | 2 | Process Mgmt. | sys_arch_prctl() | 58962306a36Sopenharmony_ci+-------------------+-----------+-----------------+----------------------+ 59062306a36Sopenharmony_ci 59162306a36Sopenharmony_ciConclusion 59262306a36Sopenharmony_ci========== 59362306a36Sopenharmony_ci 59462306a36Sopenharmony_ciThis document is intended to be used as a guide on how to gather fine-grained 59562306a36Sopenharmony_ciinformation on the resources in use by workloads using strace. 59662306a36Sopenharmony_ci 59762306a36Sopenharmony_ciReferences 59862306a36Sopenharmony_ci========== 59962306a36Sopenharmony_ci 60062306a36Sopenharmony_ci * `Discovery Linux Kernel Subsystems used by OpenAPS <https://elisa.tech/blog/2022/02/02/discovery-linux-kernel-subsystems-used-by-openaps>`_ 60162306a36Sopenharmony_ci * `ELISA-White-Papers-Discovering Linux kernel subsystems used by a workload <https://github.com/elisa-tech/ELISA-White-Papers/blob/master/Processes/Discovering_Linux_kernel_subsystems_used_by_a_workload.md>`_ 60262306a36Sopenharmony_ci * `strace <https://man7.org/linux/man-pages/man1/strace.1.html>`_ 60362306a36Sopenharmony_ci * `perf <https://man7.org/linux/man-pages/man1/perf.1.html>`_ 60462306a36Sopenharmony_ci * `paxtest README <https://github.com/opntr/paxtest-freebsd/blob/hardenedbsd/0.9.14-hbsd/README>`_ 60562306a36Sopenharmony_ci * `stress-ng <https://www.mankier.com/1/stress-ng>`_ 60662306a36Sopenharmony_ci * `Monitoring and managing system status and performance <https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/monitoring_and_managing_system_status_and_performance/index>`_ 607