18fdd4d70SJohn Kariuki# spdk_top {#spdk_top} 28fdd4d70SJohn Kariuki 312fcbc9bSwawrykThe spdk_top application is designed to resemble the standard top in that it provides a real-time insights into CPU cores usage by SPDK 412fcbc9bSwawryklightweight threads and pollers. Have you ever wondered which CPU core is used most by your SPDK instance? Are you building your own bdev 512fcbc9bSwawrykor library and want to know if your code is running efficiently? Are your new pollers busy most of the time? The spdk_top application uses 6*a04e3c7aSKrzysztof Karas[RPC](https://spdk.io/doc/jsonrpc.html) calls to collect performance metrics and displays them in a report that you can analyze and determine 7*a04e3c7aSKrzysztof Karasif your code is running efficiently so that you can tune your implementation and get more from SPDK. 88fdd4d70SJohn Kariuki 912fcbc9bSwawrykWhy doesn't the classic top utility work for SPDK? SPDK uses a polled-mode design; a reactor thread running on each CPU core assigned to 1012fcbc9bSwawrykan SPDK application schedules SPDK lightweight threads and pollers to run on the CPU core. Therefore, the standard Linux top utility is 1112fcbc9bSwawryknot effective for analyzing the CPU usage for polled-mode applications like SPDK because it just reports that they are using 100% of the 1212fcbc9bSwawrykCPU resources assigned to them. The spdk_top utility was developed to analyze and report the CPU cycles used to do real work vs just 1312fcbc9bSwawrykpolling for work. The utility relies on instrumentation added to pollers to track when they are doing work vs. polling for work. The 1412fcbc9bSwawrykspdk_top utility gets the fine grained metrics from the pollers, analyzes and report the metrics on a per poller, thread and core basis. 1512fcbc9bSwawrykThis information enables users to identify CPU cores that are busy doing real work so that they can determine if the application 1612fcbc9bSwawrykneeds more or less CPU resources. 178fdd4d70SJohn Kariuki 186cc23f29SKrzysztof Karasspdk_top uses RPCs to communicate with the app it is viewing, so it will work only with those that run RPC server and support 196cc23f29SKrzysztof Karas`thread_get_stats`, `thread_get_pollers`, `framework_get_reactors` methods. Apps currently meeting this criteria: 206cc23f29SKrzysztof Karasspdk_tgt, nvmf_tgt, vhost, iscsi_tgt. 216cc23f29SKrzysztof Karas 221e1fd9acSwawryk## Run spdk_top 2378d8ba28Swawryk 246c0cebf1SKrzysztof KarasBefore running spdk_top you need to run the SPDK application whose performance you want to analyze using spdk_top. 258fdd4d70SJohn Kariuki 268fdd4d70SJohn KariukiRun the spdk_top application 278fdd4d70SJohn Kariuki 288fdd4d70SJohn Kariuki~~~{.sh} 298fdd4d70SJohn Kariuki./build/bin/spdk_top 308fdd4d70SJohn Kariuki~~~ 318fdd4d70SJohn Kariuki 321e1fd9acSwawryk## Bottom menu 3378d8ba28Swawryk 346c0cebf1SKrzysztof KarasMenu at the bottom of SPDK top window shows many options for changing displayed data. Each menu item has a key associated with it in square brackets. 356c0cebf1SKrzysztof Karas 366c0cebf1SKrzysztof Karas* Quit - quits the SPDK top application. 37be1ff6deSKrzysztof Karas* Switch tab - allows to select THREADS/POLLERS/CORES tabs. 3812fcbc9bSwawryk* Previous page/Next page - scrolls up/down to the next set of rows displayed. Indicator in the bottom-left corner shows current page and number 3912fcbc9bSwawryk of all available pages. 406c0cebf1SKrzysztof Karas* Item details - displays details pop-up window for highlighted data row. Selection is changed by pressing UP and DOWN arrow keys. 41be1ff6deSKrzysztof Karas* Help - displays help pop-up window. 428fdd4d70SJohn Kariuki 431e1fd9acSwawryk## Threads Tab 4478d8ba28Swawryk 456c0cebf1SKrzysztof KarasThe threads tab displays a line item for each spdk thread. The information displayed shows: 468fdd4d70SJohn Kariuki 476c0cebf1SKrzysztof Karas* Thread name - name of SPDK thread. 486c0cebf1SKrzysztof Karas* Core - core on which the thread is currently running. 496c0cebf1SKrzysztof Karas* Active/Timed/Paused pollers - number of pollers grouped by type on this thread. 506c0cebf1SKrzysztof Karas* Idle/Busy - how many microseconds the thread was idle/busy. 516c0cebf1SKrzysztof Karas 526c0cebf1SKrzysztof Karas\n 5312fcbc9bSwawrykBy pressing ENTER key a pop-up window appears, showing above and a list of pollers running on selected 5412fcbc9bSwawrykthread (with poller name, type, run count and period). 556c0cebf1SKrzysztof KarasPop-up then can be closed by pressing ESC key. 566c0cebf1SKrzysztof Karas 576c0cebf1SKrzysztof KarasTo learn more about spdk threads see @ref concurrency. 588fdd4d70SJohn Kariuki 591e1fd9acSwawryk## Pollers Tab 6078d8ba28Swawryk 616c0cebf1SKrzysztof KarasThe pollers tab displays a line item for each poller. The information displayed shows: 628fdd4d70SJohn Kariuki 636c0cebf1SKrzysztof Karas* Poller name - name of currently selected poller. 646c0cebf1SKrzysztof Karas* Type - type of poller (Active/Paused/Timed). 656c0cebf1SKrzysztof Karas* On thread - thread on which the poller is running. 666c0cebf1SKrzysztof Karas* Run count - how many times poller was run. 676c0cebf1SKrzysztof Karas* Period - poller period in microseconds. If period equals 0 then it is not displayed. 686c0cebf1SKrzysztof Karas* Status - whether poller is currently Busy (red color) or Idle (blue color). 696c0cebf1SKrzysztof Karas 706c0cebf1SKrzysztof Karas\n 716c0cebf1SKrzysztof KarasPoller pop-up window can be displayed by pressing ENTER on a selected data row and displays above information. 726c0cebf1SKrzysztof KarasPop-up can be closed by pressing ESC key. 738fdd4d70SJohn Kariuki 741e1fd9acSwawryk## Cores Tab 7578d8ba28Swawryk 766c0cebf1SKrzysztof KarasThe cores tab provides insights into how the application is using the CPU cores assigned to it. The information displayed for each core shows: 778fdd4d70SJohn Kariuki 786c0cebf1SKrzysztof Karas* Core - core number. 796c0cebf1SKrzysztof Karas* Thread count - number of threads currently running on core. 806c0cebf1SKrzysztof Karas* Poller count - total number of pollers running on core. 816c0cebf1SKrzysztof Karas* Idle/Busy - how many microseconds core was idle (including time when core ran pollers but did not find any work) or doing actual work. 823c701ad9SRichael Zhuang* Intr - whether this core is in interrupt mode or not. 838fdd4d70SJohn Kariuki 846c0cebf1SKrzysztof Karas\n 8512fcbc9bSwawrykPressing ENTER key makes a pop-up window appear, showing above information, along with a list of threads running on selected core. Cores details 8612fcbc9bSwawrykwindow allows to select a thread and display thread details pop-up on top of it. To close both pop-ups use ESC key. 87be1ff6deSKrzysztof Karas 881e1fd9acSwawryk## Help Window 8978d8ba28Swawryk 909ebb3561SKrzysztof KarasHelp window pop-up can be invoked by pressing 'h' key inside any tab. It contains explanations for each key used inside the spdk_top application. 919ebb3561SKrzysztof Karas 929ebb3561SKrzysztof Karas## Scheduler Pop-up 939ebb3561SKrzysztof Karas 949ebb3561SKrzysztof KarasCurrent scheduler information may be displayed with 'g' key inside all tabs. It contains scheduler name and period along with governor 959ebb3561SKrzysztof Karasname. 96