Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp8348309rwi; Tue, 25 Oct 2022 05:45:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4rVWZ0c0jXZND4R+gHi7yStX5HEi2j7uXArlm/LTJe98FvkgtPFDC+J4NMw+joeQ3b+G+j X-Received: by 2002:a05:6402:1cca:b0:460:7d72:8f2 with SMTP id ds10-20020a0564021cca00b004607d7208f2mr26201584edb.205.1666701925240; Tue, 25 Oct 2022 05:45:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666701925; cv=none; d=google.com; s=arc-20160816; b=VrlOqYTQ+D0AbuQUOx5wLBaZKsDM4lGtrgAyPw6l/wjHh6sN4TBdzVu9m6DrHiWX9e MWUukfQwrTBez8JsvqWunKmKoLYXGC2mEaylB7FoHOv2n/opV0eElWLF2O7e8ozh77xZ QTg30JA0/x/CvV6SZca25D7ivTGan9BVdMh7hqoo7wnqTEUeonCRjBRGTklLxJ8kJX3e lND0R+av6HqJrqWBIkZ6suH4N7Yd5b+eCzLCUUgGIQayWBk9UVmZ9Ta/qArWSAdzGroQ 6Ycs9zORfd6dHY+xgSnYlsCdtX16l+g1bNWY8rUgVJRSo+O1/1SpU2Igy/K2azAuRVM1 xBLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LOwAJVpdEHW3eNgliqNp/dcHJO1xsTkiaikllsMi22U=; b=SQwNbPyh6C6xX4LDbUSC1GjHqvH0h9d+5lKINjaHajUwwHKKYBhcHTTK6R9sctatDV fyAjo/xPxdrzkfNm68KrC0Rrg/tRrnOrlmOrsFwdg6iNSx5tgx74HFxiXK6tgCCrefdD 66ThlFzfhBsgspfzlvf/i/5wVrMQvtCMIUVJp5zKE7lEFpsgeOVhtbl8FyA4pJdkPYPe oFLSVcToVTnFKBEBziDSt2wdSxGQVSU9l0n42jwbobIBlrEwnc+ThqsHcmQoPmW3NuL8 N6ah9KVWX5qOvXpvFdtWiQNCeDPgPhSxfNNYUcH1LoQpng4A1bPSeCAJ6uDdn1xHJrMR k+Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hxU5gYVN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m25-20020a1709066d1900b007919388d2c6si1788520ejr.357.2022.10.25.05.45.00; Tue, 25 Oct 2022 05:45:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hxU5gYVN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231244AbiJYMSp (ORCPT + 99 others); Tue, 25 Oct 2022 08:18:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231259AbiJYMSk (ORCPT ); Tue, 25 Oct 2022 08:18:40 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70601181CA2 for ; Tue, 25 Oct 2022 05:18:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666700316; x=1698236316; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E39ZJi+fK0k/tLrnny5MphRS3c/RTFP05Ljn5tZgGl0=; b=hxU5gYVN+ci2RNLS2a9dxwfq7+Ny5LGFupn8fY7OuzFOnF8sFPq0y3B3 A9DMjGvCL0DESbfNYAV3Nx/csMLOPMrUzbt6cpTXgtZiiVhnahtzqI0TJ f+KqDL3N4+G3mGbUENe34LywCZeoVLFTl/6FP05b4tZef8d/wGVzwU8OM RM+oIY2ytrCt7LzDT7JAcugHor1j7AnVz2ZRjgCB48GZRTAN7eqeWfoZs 4roeRX3ClqFpQT90Da/MO5iOJTLiadfD/lhc3N2loB2YgGk+CtAOMu6w2 jNj/pI3NCPApLau02A6JIz0OISiVdZWY9pbaGT37/y9FxHR1p3/d0xRfN w==; X-IronPort-AV: E=McAfee;i="6500,9779,10510"; a="305270694" X-IronPort-AV: E=Sophos;i="5.95,212,1661842800"; d="scan'208";a="305270694" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2022 05:18:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10510"; a="634074074" X-IronPort-AV: E=Sophos;i="5.95,212,1661842800"; d="scan'208";a="634074074" Received: from sunyi-station.sh.intel.com (HELO sunyi-station..) ([10.239.159.10]) by fmsmga007.fm.intel.com with ESMTP; 25 Oct 2022 05:18:33 -0700 From: Yi Sun To: dave.hansen@intel.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, x86@kernel.org Cc: sohil.mehta@intel.com, ak@linux.intel.com, ilpo.jarvinen@linux.intel.com, heng.su@intel.com, tony.luck@intel.com, dave.hansen@linux.intel.com, Yi Sun Subject: [RESEND PATCH v5 2/2] tools/testing/fpu: Add script to consume trace log of xsave latency Date: Tue, 25 Oct 2022 20:17:49 +0800 Message-Id: <20221025121749.584519-3-yi.sun@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221025121749.584519-1-yi.sun@intel.com> References: <20221025121749.584519-1-yi.sun@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Consume the trace log dumped by trace points x86_fpu_latency_xsave and x86_fpu_latency_xrstor, calculate latency ranges for each RFBM and XINUSE combination including min, max, average and 97% tail latency. Add the average of 97% tail latency to remove the unreasonable data which is introduced by interrupts or other noise. By adding the experimental code disabling interrupts before the calculation of latency, it's obvious to get the 3% tail latency has been filtered. Make use of sqlite3 to make the data statistics more efficient and concise. The output looks like following: EVENTs RFBM XINUSE lat_min lat_max lat_avg lat_avg(97%) ---------------------- ------- ------ ------- ------- ------- ------------ x86_fpu_latency_xrstor 0x206e7 0x0 364 364 364 364 x86_fpu_latency_xrstor 0x206e7 0x202 112 1152 300 276 x86_fpu_latency_xsave 0x206e7 0x202 80 278 141 137 x86_fpu_latency_xsave 0x206e7 0x246 108 234 180 177 The XSAVE/XRSTOR latency trace log can be got by two ways: 1. Generated by Kernel debugfs echo 1 > /sys/kernel/debug/tracing/events/x86_fpu/enable cat /sys/kernel/debug/tracing/trace_pipe > trace-log 2. Generated by helper tool like 'trace-cmd' trace-cmd record -e x86_fpu -F trace-cmd report > trace-log Reviewed-by: Tony Luck Signed-off-by: Yi Sun diff --git a/tools/testing/fpu/xsave-latency-trace.sh b/tools/testing/fpu/xsave-latency-trace.sh new file mode 100755 index 000000000000..d45563984fd6 --- /dev/null +++ b/tools/testing/fpu/xsave-latency-trace.sh @@ -0,0 +1,227 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# (c) 2022 Yi Sun + +trace_log=$1 +trace_lat_log=".trace_lat_log" +db_name="db_trace" +db_file="${db_name}.db" +table_raw="t_trace" +table_tail="t_trace_tail" +table_results="t_results" +events="x86_fpu_latency_xsave|x86_fpu_latency_xrstor" + +# The regex for the trace log. The rough pattern: +# (proc) (No.cpu) (flags) (timestamp): (tracepoint): latency:(123) RFBM:0x(123) XINUSE:0x(123)$ +# Fold the regex into 3 parts making it easier to read. +regex1="([^\ ]*)[[:space:]]*\[([0-9]+)\][[:space:]]*(.....\ )?[[:space:]]*" +regex2="([0-9.]*):[[:space:]]*([^\ :]*):.*latency:([0-9]*)[[:space:]]*" +regex3="RFBM:(0x[0-9a-f]*)[[:space:]]*XINUSE:(0x[0-9a-f]*)$" + +function usage() { + echo "This script consumes the tracepoint data, and dumps out the" + echo "latency ranges for each RFBM combination." + echo "Usage:" + echo "$0 " + echo " trace-log:" + echo " Either generated by Kernel sysfs:" + echo " echo 1 > /sys/kernel/debug/tracing/events/x86_fpu/enable" + echo " cat /sys/kernel/debug/tracing/trace_pipe > trace-log" + echo "" + echo " Or generate by helper tool like 'trace-cmd':" + echo " trace-cmd record -e x86_fpu" + echo " trace-cmd report > trace-log" +} + +# Check the dependent tools +# {@}: a list of third-part tools +function check_packages() { + for pack in "$@"; do + which $pack >& /dev/null + if [[ $? != 0 ]]; then + echo "Please install $pack before running this script." + exit 1 + fi + done +} + +# Run SQL command with sqlite3 +# ${*}: SQL command fed to sqlite3 +function SQL_CMD() { + sqlite3 $db_file "$*" +} + +# Run SQL command with sqlite3 and format the output with headers and column. +# ${*}: SQL command fed to sqlite3 +function SQL_CMD_HEADER() { + sqlite3 -column -header $db_file "$*" +} + +# Create a table in the DB +# ${1}: name of the table +function create_table() { + if [[ "$1" == "" ]]; then + echo "Empty table name!" + exit 1 + fi + SQL_CMD "create table $1 ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + process TEXT, + cpu INT, + timestamp FLOAT, + event_name TEXT, + lat INT, + RFBM INT, + XINUSE INT);" +} + +# Round to the nearest whole number +# ${1}: a float number +# Output: integer +function round() { + echo "scale=0; ($1+0.5)/1" | bc +} + +# Insert a record in the trace table +# +# process cpu timestamp event_name lat RFBM XINUSE +# $2 $3 $4 $5 $6 $7 $8 + +function insert_line() { + if [[ "$1" == "" ]]; then + echo "Empty table name!" + exit 1 + fi + SQL_CMD "INSERT INTO $1 (process, cpu, timestamp, event_name, lat, RFBM, XINUSE) + VALUES (\"$2\", $3, $4, \"$5\", $6, $7, $8);" +} + +# Show the results of the trace statistics +function get_latency_stat() { + SQL_CMD "create table $table_results ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + event_name TEXT, + RFBM INT, + XINUSE INT, + lat_min INT, + lat_max INT, + lat_avg INT, + lat_tail_avg INT);" + + for((i=0; i<$cnt; i++));do + event_name=`get_comb_item $table_raw $i event_name` + RFBM=`get_comb_item $table_raw $i RFBM` + XINUSE=`get_comb_item $table_raw $i XINUSE` + lat_min=`get_comb_item $table_raw $i min\(lat\)` + lat_max=`get_comb_item $table_raw $i max\(lat\)` + lat_avg=`get_comb_item $table_raw $i avg\(lat\)` + lat_tail_avg=`get_comb_item $table_tail $i avg\(lat\)` + + lat_avg=`round $lat_avg` + lat_tail_avg=`round $lat_tail_avg` + + SQL_CMD "INSERT INTO $table_results + (event_name, RFBM,XINUSE, lat_min, lat_max, lat_avg, lat_tail_avg) + VALUES (\"$event_name\", $RFBM, $XINUSE, $lat_min, $lat_max, + $lat_avg, $lat_tail_avg);" + done + + SQL_CMD_HEADER "select event_name[EVENTs],printf('0x%x',RFBM)[RFBM], + printf('0x%x',XINUSE)[XINUSE],lat_min,lat_max,lat_avg, + lat_tail_avg[lat_avg(97%)] + from $table_results;" +} + +# Get the count of the combination of event_name, RFBM, XINUSE amount all lat trace records +function get_combs_cnt() { + SQL_CMD "SELECT event_name, RFBM, XINUSE from $table_raw + group by event_name,RFBM,XINUSE;" | wc -l +} + +# Get a specified combination from a table +# ${1}: name of table +# ${2}: the order of the combination of event_name, RFBM, XINUSE +# ${3}: the items which are wanted to be shown +function get_comb_item() { + table=$1 + cnt=$2 + col=$3 + SQL_CMD "SELECT $col from $table group by event_name,RFBM,XINUSE limit $cnt,1;" +} + +# Get count of the records in a given table +# ${1}: name of the table +function get_rows_cnt() { + table=$1 + SQL_CMD "SELECT count(*) from $table;" +} + +# Generate a new table from the raw trace table removing 3% tail traces. +function gen_tail_lat() { + cnt=`get_combs_cnt` + create_table $table_tail + + for((i=0; i<$cnt; i++));do + create_table t$i + event_name=`get_comb_item $table_raw $i event_name` + RFBM=`get_comb_item $table_raw $i RFBM` + XINUSE=`get_comb_item $table_raw $i XINUSE` + + SQL_CMD "insert into t$i(process,cpu,timestamp,event_name,lat,RFBM,XINUSE) + select process,cpu,timestamp,event_name,lat,RFBM,XINUSE + from $table_raw where event_name=\"$event_name\" and RFBM=$RFBM and + XINUSE=$XINUSE ORDER BY lat ASC;" + + row=`get_rows_cnt t$i` + row=`echo "scale=0; ($row*0.97 + 0.5)/1" | bc` + + SQL_CMD "insert into $table_tail + (process,cpu,timestamp,event_name,lat,RFBM,XINUSE) + select process,cpu,timestamp,event_name,lat,RFBM,XINUSE + from t$i limit 0,$row;" + done + +} + +if [[ ! -e "$trace_log" || $# != 1 ]];then + usage + exit 1 +fi + +# Check dependency +# Make sure having following packages +check_packages sqlite3 bc wc cut + +# Filter trace log keeping latency related lines only +grep -E "$events" $trace_log > $trace_lat_log +cnt_lines=`wc -l $trace_lat_log | cut -d' ' -f1` +# Remove the old db file if it existed before creating +[[ -f $db_file ]] && rm -rf $db_file + +create_table $table_raw + +# Read each line from the temp file and insert into the table +i=0 +while IFS= read -r line; +do + ((i = i + 1)) + echo -ne "(${i}/$cnt_lines) Importing trace log into database!\r" + if [[ "$line" =~ ${regex1}${regex2}${regex3} ]]; then + pname=${BASH_REMATCH[1]} + cpu=${BASH_REMATCH[2]} + ts=${BASH_REMATCH[4]} + ename=${BASH_REMATCH[5]} + lat=${BASH_REMATCH[6]} + ((rfbm=${BASH_REMATCH[7]})) + ((xinuse=${BASH_REMATCH[8]})) + + insert_line $table_raw $pname $cpu $ts $ename $lat $rfbm $xinuse + fi +done < $trace_lat_log + +gen_tail_lat +get_latency_stat + +# Cleanup +rm -rf $trace_lat_log $db_file -- 2.34.1