From patchwork Wed May 17 14:52:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 100003 Delivered-To: patch@linaro.org Received: by 10.182.142.97 with SMTP id rv1csp256163obb; Wed, 17 May 2017 07:58:21 -0700 (PDT) X-Received: by 10.55.162.136 with SMTP id l130mr3498831qke.275.1495033101594; Wed, 17 May 2017 07:58:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495033101; cv=none; d=google.com; s=arc-20160816; b=l1Pa4hwgm7aAT8kovGqvQkbitvmkwfVQ6s6TgelAZ7ARH8ygvUqJ52fzCwZFE4gmFY MqfgihxOakcEe3/UB4m1fWWg24nD5cKYR0MwNXwowDEIZvlO5CXowjFj+OqrXM2YKHc6 KATgnug+FwuBk85uMdv+Sr3A8XN4dwN8RcYxgJiRROkRerxugjZGMPvXQH9+MkHWvrUs qo6LioLRqotl9XrJAeywShCXCr4Vfy6aKRQMWoRrzl2F2foR+omEZyN7IIzLgKbRWVGY rjzmzGJeR/Fl2FVb1WIAJgKISiP6qdHxg1iFXaHWbg5NoR5zyHIAuuBKBRHE/9ju3Muo 4KRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=rcMB9rObBzfaiH0juvPXMmfOxfhZ44tiN81BcEBHgnw=; b=P2knokxuvhcXhzVTSt3iuNzAwwOa6Vb1o8Gag+JmoQ4SaI3ya71dTdm4WV55TXWn9A FR+6tPZZ18nDtS1SlBsyhi1cgBjnXsND2WTTvJzRahCVBMeIRABV5/ug/ehtbJoaMDlc DmhTs5OOD6XB3bC53kZnGxaKQz9V/VJXA3Qa5+aLOzA+rI60ef9CBJ4T70u8wWtx9LkF YFakwJbVICxESR6l8Za5m0UTHM8h/rEAm9shDiIJ/r4kEEoHAFvUraCi7KlMDK2IG3tJ /uvk9RQk5gkBR9rrOPhsMTQapj+bA0MMkNScOgw0QLLwDQ685CPhd5BPvhsDDCBc6U9X 0AJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id m184si2357118qkf.307.2017.05.17.07.58.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 17 May 2017 07:58:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0P7-0006mK-6n for patch@linaro.org; Wed, 17 May 2017 10:58:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50702) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0J8-0001iz-Jn for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dB0J5-0004eh-QH for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:10 -0400 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:33945) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dB0J5-0004eI-Gy for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:07 -0400 Received: by mail-wr0-x22d.google.com with SMTP id l9so12460518wre.1 for ; Wed, 17 May 2017 07:52:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rcMB9rObBzfaiH0juvPXMmfOxfhZ44tiN81BcEBHgnw=; b=T3rfBvALSU32R2qZxHmU7oACQHK7obgnVz5TGcoKL2p9FXokKie5Yuy/iNJ7s5jHdl MMf0t1q1f7dFabtQep62kHY/hnPH0XeuLRNsFUQLK1X2PyT2GnfduuiQuyengcERX70h D0F+j7v1g0cN5wQKEUp/v4FY5dcr8+GE0sYM8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rcMB9rObBzfaiH0juvPXMmfOxfhZ44tiN81BcEBHgnw=; b=EeB33oAuKEBD2DkaH5ps1WJMIFq8ifS61+YpcMGVwm0z65JsPrBv6T5tvkbW5d+V+R 7dhKVNJf3bricbV6xUwSlf/B1rbXiduiM+7qlc+7PFIeOF68w6vD85JD3zosE2pcxryY cPgLSL/UgkDWMvzKH/XlChrgOhjZFfci16pllpcm1Mwa/cmubSxCSfp/Wtn/FaWhLHuf rK50U7N4LHPAZSomfirg2EM2+Msdq7s6F1pGO5pfrEgiBhaJKIE8NbF4vuNN8RIk2aGc F81lGHhjtrn/42E5553Z5Dv+GS4jYyRBOtsPtpyvLeJDq3XB3SA7ZQR15zzEDTD9IxHn +wmg== X-Gm-Message-State: AODbwcC6t72hvRpWDq16mUydkFR4P6bYGVnsm45ctEczcAz15QXcZrYS Hu0KfvK+oZM6I3Er X-Received: by 10.223.172.149 with SMTP id o21mr2470391wrc.181.1495032726207; Wed, 17 May 2017 07:52:06 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id t30sm2385254wrc.24.2017.05.17.07.52.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 May 2017 07:52:04 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 906273E0655; Wed, 17 May 2017 15:52:59 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: pbonzini@redhat.com, stefanha@redhat.com Date: Wed, 17 May 2017 15:52:54 +0100 Message-Id: <20170517145259.28979-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170517145259.28979-1-alex.bennee@linaro.org> References: <20170517145259.28979-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22d Subject: [Qemu-devel] [PATCH v2 1/6] scripts/replay-dump.py: replay log dumper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This script is a debugging tool for looking through the contents of a replay log file. It is incomplete but should fail gracefully at events it doesn't understand. It currently understands two different log formats as the audio record/replay support was merged during since MTTCG. It was written to help debug what has caused the BQL changes to break replay support. Signed-off-by: Alex Bennée --- scripts/replay-dump.py | 272 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100755 scripts/replay-dump.py -- 2.11.0 Reviewed-by: Philippe Mathieu-Daudé diff --git a/scripts/replay-dump.py b/scripts/replay-dump.py new file mode 100755 index 0000000000..fdd178aba0 --- /dev/null +++ b/scripts/replay-dump.py @@ -0,0 +1,272 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Dump the contents of a recorded execution stream +# +# Copyright (c) 2017 Alex Bennée +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, see . + +import argparse +import struct +from collections import namedtuple + +# This mirrors some of the global replay state which some of the +# stream loading refers to. Some decoders may read the next event so +# we need handle that case. Calling reuse_event will ensure the next +# event is read from the cache rather than advancing the file. + +class ReplayState(object): + def __init__(self): + self.event = -1 + self.event_count = 0 + self.already_read = False + self.current_checkpoint = 0 + self.checkpoint = 0 + + def set_event(self, ev): + self.event = ev + self.event_count += 1 + + def get_event(self): + self.already_read = False + return self.event + + def reuse_event(self, ev): + self.event = ev + self.already_read = True + + def set_checkpoint(self): + self.checkpoint = self.event - self.checkpoint_start + + def get_checkpoint(self): + return self.checkpoint + +replay_state = ReplayState() + +# Simple read functions that mirror replay-internal.c +# The file-stream is big-endian and manually written out a byte at a time. + +def read_byte(fin): + "Read a single byte" + return struct.unpack('>B', fin.read(1))[0] + +def read_event(fin): + "Read a single byte event, but save some state" + if replay_state.already_read: + return replay_state.get_event() + else: + replay_state.set_event(read_byte(fin)) + return replay_state.event + +def read_word(fin): + "Read a 16 bit word" + return struct.unpack('>H', fin.read(2))[0] + +def read_dword(fin): + "Read a 32 bit word" + return struct.unpack('>I', fin.read(4))[0] + +def read_qword(fin): + "Read a 64 bit word" + return struct.unpack('>Q', fin.read(8))[0] + +# Generic decoder structure +Decoder = namedtuple("Decoder", "eid name fn") + +def call_decode(table, index, dumpfile): + "Search decode table for next step" + decoder = next((d for d in table if d.eid == index), None) + if not decoder: + print "Could not decode index: %d" % (index) + print "Entry is: %s" % (decoder) + print "Decode Table is:\n%s" % (table) + return False + else: + return decoder.fn(decoder.eid, decoder.name, dumpfile) + +# Print event +def print_event(eid, name, string=None, event_count=None): + "Print event with count" + if not event_count: + event_count = replay_state.event_count + + if string: + print "%d:%s(%d) %s" % (event_count, name, eid, string) + else: + print "%d:%s(%d)" % (event_count, name, eid) + + +# Decoders for each event type + +def decode_unimp(eid, name, _unused_dumpfile): + "Unimplimented decoder, will trigger exit" + print "%s not handled - will now stop" % (name) + return False + +# Checkpoint decoder +def swallow_async_qword(eid, name, dumpfile): + "Swallow a qword of data without looking at it" + step_id = read_qword(dumpfile) + print " %s(%d) @ %d" % (name, eid, step_id) + return True + +async_decode_table = [ Decoder(0, "REPLAY_ASYNC_EVENT_BH", swallow_async_qword), + Decoder(1, "REPLAY_ASYNC_INPUT", decode_unimp), + Decoder(2, "REPLAY_ASYNC_INPUT_SYNC", decode_unimp), + Decoder(3, "REPLAY_ASYNC_CHAR_READ", decode_unimp), + Decoder(4, "REPLAY_ASYNC_EVENT_BLOCK", decode_unimp), + Decoder(5, "REPLAY_ASYNC_EVENT_NET", decode_unimp), +] +# See replay_read_events/replay_read_event +def decode_async(eid, name, dumpfile): + """Decode an ASYNC event""" + + print_event(eid, name) + + async_event_kind = read_byte(dumpfile) + async_event_checkpoint = read_byte(dumpfile) + + if async_event_checkpoint != replay_state.current_checkpoint: + print " mismatch between checkpoint %d and async data %d" % ( + replay_state.current_checkpoint, async_event_checkpoint) + return True + + return call_decode(async_decode_table, async_event_kind, dumpfile) + + +def decode_instruction(eid, name, dumpfile): + ins_diff = read_dword(dumpfile) + print_event(eid, name, "0x%x" % (ins_diff)) + return True + +def decode_audio_out(eid, name, dumpfile): + audio_data = read_dword(dumpfile) + print_event(eid, name, "%d" % (audio_data)) + return True + +def decode_checkpoint(eid, name, dumpfile): + """Decode a checkpoint. + + Checkpoints contain a series of async events with their own specific data. + """ + replay_state.set_checkpoint() + # save event count as we peek ahead + event_number = replay_state.event_count + next_event = read_event(dumpfile) + + # if the next event is EVENT_ASYNC there are a bunch of + # async events to read, otherwise we are done + if next_event != 3: + print_event(eid, name, "no additional data", event_number) + else: + print_event(eid, name, "more data follows", event_number) + + replay_state.reuse_event(next_event) + return True + +def decode_checkpoint_init(eid, name, dumpfile): + print_event(eid, name) + return True + +def decode_interrupt(eid, name, dumpfile): + print_event(eid, name) + return True + +def decode_clock(eid, name, dumpfile): + clock_data = read_qword(dumpfile) + print_event(eid, name, "0x%x" % (clock_data)) + return True + + +# pre-MTTCG merge +v5_event_table = [Decoder(0, "EVENT_INSTRUCTION", decode_instruction), + Decoder(1, "EVENT_INTERRUPT", decode_interrupt), + Decoder(2, "EVENT_EXCEPTION", decode_unimp), + Decoder(3, "EVENT_ASYNC", decode_async), + Decoder(4, "EVENT_SHUTDOWN", decode_unimp), + Decoder(5, "EVENT_CHAR_WRITE", decode_unimp), + Decoder(6, "EVENT_CHAR_READ_ALL", decode_unimp), + Decoder(7, "EVENT_CHAR_READ_ALL_ERROR", decode_unimp), + Decoder(8, "EVENT_CLOCK_HOST", decode_clock), + Decoder(9, "EVENT_CLOCK_VIRTUAL_RT", decode_clock), + Decoder(10, "EVENT_CP_CLOCK_WARP_START", decode_checkpoint), + Decoder(11, "EVENT_CP_CLOCK_WARP_ACCOUNT", decode_checkpoint), + Decoder(12, "EVENT_CP_RESET_REQUESTED", decode_checkpoint), + Decoder(13, "EVENT_CP_SUSPEND_REQUESTED", decode_checkpoint), + Decoder(14, "EVENT_CP_CLOCK_VIRTUAL", decode_checkpoint), + Decoder(15, "EVENT_CP_CLOCK_HOST", decode_checkpoint), + Decoder(16, "EVENT_CP_CLOCK_VIRTUAL_RT", decode_checkpoint), + Decoder(17, "EVENT_CP_INIT", decode_checkpoint_init), + Decoder(18, "EVENT_CP_RESET", decode_checkpoint), +] + +# post-MTTCG merge, AUDIO support added +v6_event_table = [Decoder(0, "EVENT_INSTRUCTION", decode_instruction), + Decoder(1, "EVENT_INTERRUPT", decode_interrupt), + Decoder(2, "EVENT_EXCEPTION", decode_unimp), + Decoder(3, "EVENT_ASYNC", decode_async), + Decoder(4, "EVENT_SHUTDOWN", decode_unimp), + Decoder(5, "EVENT_CHAR_WRITE", decode_unimp), + Decoder(6, "EVENT_CHAR_READ_ALL", decode_unimp), + Decoder(7, "EVENT_CHAR_READ_ALL_ERROR", decode_unimp), + Decoder(8, "EVENT_AUDIO_OUT", decode_audio_out), + Decoder(9, "EVENT_AUDIO_IN", decode_unimp), + Decoder(10, "EVENT_CLOCK_HOST", decode_clock), + Decoder(11, "EVENT_CLOCK_VIRTUAL_RT", decode_clock), + Decoder(12, "EVENT_CP_CLOCK_WARP_START", decode_checkpoint), + Decoder(13, "EVENT_CP_CLOCK_WARP_ACCOUNT", decode_checkpoint), + Decoder(14, "EVENT_CP_RESET_REQUESTED", decode_checkpoint), + Decoder(15, "EVENT_CP_SUSPEND_REQUESTED", decode_checkpoint), + Decoder(16, "EVENT_CP_CLOCK_VIRTUAL", decode_checkpoint), + Decoder(17, "EVENT_CP_CLOCK_HOST", decode_checkpoint), + Decoder(18, "EVENT_CP_CLOCK_VIRTUAL_RT", decode_checkpoint), + Decoder(19, "EVENT_CP_INIT", decode_checkpoint_init), + Decoder(20, "EVENT_CP_RESET", decode_checkpoint), +] + +def parse_arguments(): + "Grab arguments for script" + parser = argparse.ArgumentParser() + parser.add_argument("-f", "--file", help='record/replay dump to read from', + required=True) + return parser.parse_args() + +def decode_file(filename): + "Decode a record/replay dump" + dumpfile = open(filename, "rb") + + # read and throwaway the header + version = read_dword(dumpfile) + junk = read_qword(dumpfile) + + print "HEADER: version 0x%x" % (version) + if version == 0xe02006: + event_decode_table = v6_event_table + replay_state.checkpoint_start = 12 + else: + event_decode_table = v5_event_table + replay_state.checkpoint_start = 10 + + try: + decode_ok = True + while decode_ok: + event = read_event(dumpfile) + decode_ok = call_decode(event_decode_table, event, dumpfile) + finally: + dumpfile.close() + +if __name__ == "__main__": + args = parse_arguments() + decode_file(args.file) From patchwork Wed May 17 14:52:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 99997 Delivered-To: patch@linaro.org Received: by 10.182.142.97 with SMTP id rv1csp254291obb; Wed, 17 May 2017 07:54:20 -0700 (PDT) X-Received: by 10.200.34.60 with SMTP id o57mr3346592qto.41.1495032859958; Wed, 17 May 2017 07:54:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495032859; cv=none; d=google.com; s=arc-20160816; b=XlYqJEI+xGUdPoPJbtGLwujzas5wEyjGHyWfOqW70obrPG8DyQ/GMmM+wvYtNcioNG 2/1ASzzh0nhQWTQFkZyLvzhC227vG0+aGgoDQ+Od4WsPD6lUmrxtTxFeKAlscqgUKU6e b0XlDSJESPWEDKN/hyK1rfMhgrNGD083lG7Gke6pcKrn3cxpEI1WSCeK7X+GjJv3irhU 7SNHMzn0xH8Pt8Chk2Ne8sDOzK5ysgKT5cH4NkASHpzsDbuGDh0Cq7MnTq3VqrkSbjfX uPgttgf2ORAUW8MZtGmjDHQJ1WdiDk3cvz9NYpt9Q+YvWgSen0ROJAVJzH4Vgmt2wNfe 5RlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=f9S/5vQAaqH5p1VznmOtF2yJj3YXgg3ABa33JNSOsG0=; b=VSK3LzaianIvvhAZ+zJfFCnQmik1sNdeF/LfW6wbsWEQatAwUlrFvffyG6xnEJl9Tv RcQ8xNpddignrUc4RFEdY3Srhre1ylZ2UpBRLTJYA9llEuQ0AqxUGMqZ2+CCX09H6UDD 80cHibEJIgqiSvBiR+svYo51Oa6AkGUnRyDQjTgwO7gpwqP6ZexJDMLfFI6S0/iDnaNC Xr876pNTOCaawsZ1gCL2xo5eFT7cKu428Hooyhxih+vduuwQrt+1+krPOcXT4X+b9S/l GZ5MZ/4YDH5OYg5d5QcX98qJz9M2OXTvsbzQ+RhgzaZ/QVcwkOU+NNCETmjDRIIuXTye V78A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q10si2402654qta.105.2017.05.17.07.54.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 17 May 2017 07:54:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49379 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0LD-0002z2-B8 for patch@linaro.org; Wed, 17 May 2017 10:54:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0J8-0001iy-Je for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dB0J6-0004ew-HB for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:10 -0400 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:37469) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dB0J6-0004ec-B9 for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:08 -0400 Received: by mail-wm0-x22e.google.com with SMTP id d127so19125370wmf.0 for ; Wed, 17 May 2017 07:52:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f9S/5vQAaqH5p1VznmOtF2yJj3YXgg3ABa33JNSOsG0=; b=HXNECJWpeJnSrNwCgu7Qydu+TyymrNCiFlpJQaEoXLOWsXkiosVuooALkTlrh26ZxH 4tjyEqxFtQf+38vilQndvel1k1Y7qBFMLsEOxnCox8IeYjIvdS5/OM61eiJVfX2mFCWN g0K+2O58UJ+cC6MF6RHdw7stynA5vAVatKKNY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f9S/5vQAaqH5p1VznmOtF2yJj3YXgg3ABa33JNSOsG0=; b=kZSvOhVwIZhZTylBNyODLSGxVKwBfWsmhQjNgytu2NAd4sSxTX6O0lqG2N7FNdIJ/G V+eyIvbCqXMe2El+RHzKAMeCjWbDOWzMdC6dotPnAvWeNqyoTCEpoKhcgxgAfHI0N+HY 4g5fdHWG5UpSrXiJ38Bp9gkLia4BzBdj6ykAEa/IYKL4ArqN4lRjFaN4Pil3H/MGVoy6 iWTyCEkjqeV5mbgneSm1Yya0LgTqzH0RFgL+uTgJqgU84CTkxlt3dqjHKKHyxH75uNp5 jUB+5r1nKOqv/bhJh4dZadGjxRvecLL88AcalFgH8Igp+2JZZE7VXGvEsspO5kfAaLyD nsag== X-Gm-Message-State: AODbwcB5gn9QrHgzhHzMem6cqOjw3VKdwLG56e+yKpKY3XjeYk0U7KAR 9Bxnlzx5kjv8WU6T X-Received: by 10.28.207.207 with SMTP id f198mr11939199wmg.85.1495032727150; Wed, 17 May 2017 07:52:07 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id c37sm2247425wra.16.2017.05.17.07.52.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 May 2017 07:52:04 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id A1E7E3E0662; Wed, 17 May 2017 15:52:59 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: pbonzini@redhat.com, stefanha@redhat.com Date: Wed, 17 May 2017 15:52:55 +0100 Message-Id: <20170517145259.28979-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170517145259.28979-1-alex.bennee@linaro.org> References: <20170517145259.28979-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22e Subject: [Qemu-devel] [PATCH v2 2/6] scripts/qemu-gdb/timers.py: new helper to dump timer state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This introduces the qemu-gdb command "qemu timers" which will dump the state of the main timers in the system. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- scripts/qemu-gdb.py | 3 ++- scripts/qemugdb/timers.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 scripts/qemugdb/timers.py -- 2.11.0 diff --git a/scripts/qemu-gdb.py b/scripts/qemu-gdb.py index b3f8e04f77..3e7adb87dc 100644 --- a/scripts/qemu-gdb.py +++ b/scripts/qemu-gdb.py @@ -26,7 +26,7 @@ import os, sys sys.path.append(os.path.dirname(__file__)) -from qemugdb import aio, mtree, coroutine +from qemugdb import aio, mtree, coroutine, timers class QemuCommand(gdb.Command): '''Prefix for QEMU debug support commands''' @@ -38,6 +38,7 @@ QemuCommand() coroutine.CoroutineCommand() mtree.MtreeCommand() aio.HandlersCommand() +timers.TimersCommand() coroutine.CoroutineSPFunction() coroutine.CoroutinePCFunction() diff --git a/scripts/qemugdb/timers.py b/scripts/qemugdb/timers.py new file mode 100644 index 0000000000..be71a001e3 --- /dev/null +++ b/scripts/qemugdb/timers.py @@ -0,0 +1,54 @@ +#!/usr/bin/python +# GDB debugging support +# +# Copyright 2017 Linaro Ltd +# +# Author: Alex Bennée +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. + +# 'qemu timers' -- display the current timerlists + +import gdb + +class TimersCommand(gdb.Command): + '''Display the current QEMU timers''' + + def __init__(self): + 'Register the class as a gdb command' + gdb.Command.__init__(self, 'qemu timers', gdb.COMMAND_DATA, + gdb.COMPLETE_NONE) + + def dump_timers(self, timer): + "Follow a timer and recursively dump each one in the list." + # timer should be of type QemuTimer + gdb.write(" timer %s/%s (cb:%s,opq:%s)\n" % ( + timer['expire_time'], + timer['scale'], + timer['cb'], + timer['opaque'])) + + if int(timer['next']) > 0: + self.dump_timers(timer['next']) + + + def process_timerlist(self, tlist, ttype): + gdb.write("Processing %s timers\n" % (ttype)) + gdb.write(" clock %s is enabled:%s, last:%s\n" % ( + tlist['clock']['type'], + tlist['clock']['enabled'], + tlist['clock']['last'])) + if int(tlist['active_timers']) > 0: + self.dump_timers(tlist['active_timers']) + + + def invoke(self, arg, from_tty): + 'Run the command' + main_timers = gdb.parse_and_eval("main_loop_tlg") + + # This will break if QEMUClockType in timer.h is redfined + self.process_timerlist(main_timers['tl'][0], "Realtime") + self.process_timerlist(main_timers['tl'][1], "Virtual") + self.process_timerlist(main_timers['tl'][2], "Host") + self.process_timerlist(main_timers['tl'][3], "Virtual RT") From patchwork Wed May 17 14:52:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 99991 Delivered-To: patch@linaro.org Received: by 10.182.142.97 with SMTP id rv1csp253455obb; Wed, 17 May 2017 07:52:40 -0700 (PDT) X-Received: by 10.200.40.193 with SMTP id j1mr3652010qtj.186.1495032760055; Wed, 17 May 2017 07:52:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495032760; cv=none; d=google.com; s=arc-20160816; b=ckU1iVodJoEmrALACxB3ROw5qQNdHrtxbk41v9TecxDFX38qKsbg4flpSU7oNZdRUz d8mvR5OKcZWQ+ATWoDObV0ZsGRJoPYfN7AbAdAdjs5rlqAmZHazX0KxNKrEXAuux3+e6 QAn4GfNcXR31riruR0VgbK4cCRcZqO7jZAfBnLf5vPznjQYPDUOCtTBJ3/lWv5h3hkdk 11livi3iY+I2cEq79i8NS/1wcbwvkyJUdxxiAxqbdC+Ow/lrppewTvPkcf6ch+oBroCS nj1p2sFPw6ntg0HzrIf4zcwf5zrb2qo4tCuH0KyElFhetsuci9YzMRAdINH6fJITPB/2 87WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=vTYtpBDRzxzM+fZ0Ec4/8/8UNwCxlePzzhuR8PHRSx8=; b=hUZQNw+ZTvPcBGVBJk02Ouf/D8yTU+qGYyiEBZht7/Hx/2mC+AtsIz0wWjSDG/j6x4 yT3X/iM3ilUP73Y3XSs0miI/N4NwEgOb8y5l3aqPCWeB1zJCBDcBZ5ULTT1ThNhNSuU/ D263D0GkSjhYHWrzqJbo/DsgRh7oIV5wHaaBBOzMWFedFzCYFPviReakLJDBscrf7tm6 v40iNmwXpjjN90d3lnYbOTFehWTeuAPZ7X7jSJX3QS2ffyXCHfIoFr9cPyacNuf6Al5H /cWW+krt+xVgFeGsNj0y5xYERF3pLHoMqktDIZ2MMIJ01XF1Oj0nXVFgKbwDop9YrvhY X1UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k61si2478841qtd.172.2017.05.17.07.52.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 17 May 2017 07:52:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49375 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0Jb-0001oO-Hs for patch@linaro.org; Wed, 17 May 2017 10:52:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0J8-0001jL-Ma for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dB0J7-0004fA-Hv for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:10 -0400 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:36111) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dB0J7-0004f2-Bb for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:09 -0400 Received: by mail-wm0-x22f.google.com with SMTP id 70so13261416wmq.1 for ; Wed, 17 May 2017 07:52:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vTYtpBDRzxzM+fZ0Ec4/8/8UNwCxlePzzhuR8PHRSx8=; b=WAbWTAWHxa+uOVbHGMS2soTKy/wPkgKcm1g5x44lk4PjsUPM7yzSXXyIRAG9HfDbtG bsouFGs1gMoByi3nXo9sb8mstsswHfGVOo3zwLiyViA67pycsca0gbdYxnNEH+hDDavT VkZTjxOFkGiqaCAs61nXkyv1hZ8iRxj0EEZqc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vTYtpBDRzxzM+fZ0Ec4/8/8UNwCxlePzzhuR8PHRSx8=; b=EC9+u9mIKCI8dwMBObrX2cVgSdSIKCbVa7fsHwJKix9Kh1FExtXEloLGPcDDSvBg23 hYidFhBpH1Zunvb+3qdfazhBXbXITJUgY09y+4Nvy/N3CK9bPPA44kPdlIej3MRewH8S ztrJrmJVU+NaTugDlmb83/7/tlhNAvBQX8wkH2Qjm0Puh1hb2IMT7Y3qUfR/iTE2XiwX uVY0UHXBCPFvxVorxmISnnUGNUFxfR5v9VAgmJbOEU5z/9ooNDs218DDjdPgYQy3H1P5 1EDK854rDsXXP4r/APzHOjxpxgk/L5gyTPGi1mE+oL8D0PICXND0F6Cuzm7MyGO6lFBo wdzQ== X-Gm-Message-State: AODbwcDRZDW1HuNhNrRD1lJi/TLCJjJXrdCNfKmiuln2sjbKKf4sdE8P RYHQEeLQyxolrjQR X-Received: by 10.28.87.72 with SMTP id l69mr10597009wmb.111.1495032728010; Wed, 17 May 2017 07:52:08 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id b201sm18156845wme.2.2017.05.17.07.52.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 May 2017 07:52:04 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id B37663E0873; Wed, 17 May 2017 15:52:59 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: pbonzini@redhat.com, stefanha@redhat.com Date: Wed, 17 May 2017 15:52:56 +0100 Message-Id: <20170517145259.28979-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170517145259.28979-1-alex.bennee@linaro.org> References: <20170517145259.28979-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22f Subject: [Qemu-devel] [PATCH v2 3/6] scripts/qemu-gdb/tcg: new helper to dump tcg state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This adds a simple helper to dump lock state within TCG. Signed-off-by: Alex Bennée --- scripts/qemu-gdb.py | 3 ++- scripts/qemugdb/tcg.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 scripts/qemugdb/tcg.py -- 2.11.0 Reviewed-by: Philippe Mathieu-Daudé diff --git a/scripts/qemu-gdb.py b/scripts/qemu-gdb.py index 3e7adb87dc..91e928f6af 100644 --- a/scripts/qemu-gdb.py +++ b/scripts/qemu-gdb.py @@ -26,7 +26,7 @@ import os, sys sys.path.append(os.path.dirname(__file__)) -from qemugdb import aio, mtree, coroutine, timers +from qemugdb import aio, mtree, coroutine, timers, tcg class QemuCommand(gdb.Command): '''Prefix for QEMU debug support commands''' @@ -39,6 +39,7 @@ coroutine.CoroutineCommand() mtree.MtreeCommand() aio.HandlersCommand() timers.TimersCommand() +tcg.TCGLockStatusCommand() coroutine.CoroutineSPFunction() coroutine.CoroutinePCFunction() diff --git a/scripts/qemugdb/tcg.py b/scripts/qemugdb/tcg.py new file mode 100644 index 0000000000..8c7f1d7454 --- /dev/null +++ b/scripts/qemugdb/tcg.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# GDB debugging support, TCG status +# +# Copyright 2016 Linaro Ltd +# +# Authors: +# Alex Bennée +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. +# +# Contributions after 2012-01-13 are licensed under the terms of the +# GNU GPL, version 2 or (at your option) any later version. + +# 'qemu tcg-lock-status' -- display the TCG lock status across threads + +import gdb + +class TCGLockStatusCommand(gdb.Command): + '''Display TCG Execution Status''' + def __init__(self): + gdb.Command.__init__(self, 'qemu tcg-lock-status', gdb.COMMAND_DATA, + gdb.COMPLETE_NONE) + + def invoke(self, arg, from_tty): + gdb.write("Thread, BQL (iothread_mutex), Replay, Blocked?\n") + for thread in gdb.inferiors()[0].threads(): + thread.switch() + + iothread = gdb.parse_and_eval("iothread_locked") + replay = gdb.parse_and_eval("replay_locked") + + frame = gdb.selected_frame() + if frame.name() == "__lll_lock_wait": + frame.older().select() + mutex = gdb.parse_and_eval("mutex") + owner = gdb.parse_and_eval("mutex->__data.__owner") + blocked = ("__lll_lock_wait waiting on %s from %d" % + (mutex, owner)) + else: + blocked = "not blocked" + + gdb.write("%d/%d, %s, %s, %s\n" % (thread.num, thread.ptid[1], + iothread, replay, blocked)) From patchwork Wed May 17 14:52:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 100001 Delivered-To: patch@linaro.org Received: by 10.182.142.97 with SMTP id rv1csp254689obb; Wed, 17 May 2017 07:55:22 -0700 (PDT) X-Received: by 10.55.18.141 with SMTP id 13mr3692638qks.135.1495032922150; Wed, 17 May 2017 07:55:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495032922; cv=none; d=google.com; s=arc-20160816; b=Jy7gOqyRkY1SD9ExdsIEmHk7u/E0gLyRp+9rpjTGGUH+QgSRoAJfcuINUaFSAH5rdw JM4fm2UpvRI8/3NMRutv25qJHm6Y51Agd/MRhPL0t1uDznmZUsGHlL1xZWTvKEaapRIz Cfc3DbDln7Z6UMIcEE3k46F8JR+9ZXUMnjJe0UxOuYDCjJ1js3zB/z568gOXuxqhzKOf Podh88eRgZzDhYvFTJNs9qWxxHu3k0cMALA4C//QKWsoUITO83flj6iUNzhya/JpO5HR JI++i153Sa3cIj/F/dgKN4FKnDQGZOGahUoQv6wefSNxsNDJrKwEN2kHAy2MkMhY+AP3 5LRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=qOkG1Gzi7LEm5JRwN5qbVc+hJqe9ViKx3y1dYHKPk6Y=; b=TlHbsLLRpGJKtgZ9nRCtp+G1X7dACjda8kLckAJQDhfFfOr/T0lxct+MfpRaZFYW9d S5/rKnYUhBe0Gyy9KA1gGqxtjQcsFOGzrZ4IfsQPNHFIL0YPKHOC+Dut935TSoBn/NAw le4vN92eE46OJH3kQNGKqbEWdzE0TXMfgGHHEd1dAZ8OG3N2F/H+/zQc4eMygcCR6pfU KQFRroIXVupdiWo5rWKIbgRYxygP/M9O/13iiMPhshvFJkLOk+Y3BMVCYJ64SECFvRXd MCgdtYHtyebjysttJmi78/RC2xwgK8p3ZqBBgaGYNWTdKKonBPSNuSAlPYEN9r4HBIBh S8XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id i31si2394681qtc.198.2017.05.17.07.55.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 17 May 2017 07:55:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49383 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0MD-0003zH-Mu for patch@linaro.org; Wed, 17 May 2017 10:55:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50727) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0J9-0001lW-9q for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dB0J8-0004fT-4Q for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:11 -0400 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]:33486) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dB0J7-0004f6-VL for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:10 -0400 Received: by mail-wr0-x232.google.com with SMTP id w50so12426487wrc.0 for ; Wed, 17 May 2017 07:52:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qOkG1Gzi7LEm5JRwN5qbVc+hJqe9ViKx3y1dYHKPk6Y=; b=cTgOLJb0SpLaC031sOPN8VerEzUw/9sPhqQCE+MHzWwF6TpBTTEM8CDfvPGj6awjAO 4GbdHa81+lizK5gg0RhbV0r7lu6hhLHn57LmBDyi+NyS9neecmiuc4KLtilFk0XkNNc5 /fCwP2BeiZPgHKLaayoOQ4FN1m2rADfkNIhG0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qOkG1Gzi7LEm5JRwN5qbVc+hJqe9ViKx3y1dYHKPk6Y=; b=D1T50dy+D0Q5+kRYqb6NVKnagnSNma6HQNjveB1q7BHA7zRiH/aTOBE2bbzqP+u4u4 9Vyy3PlFreXbbE0nBGliZ7Q7lcsfbLWSfAJUcgA86AaGcv6nRBFHK3S/CL4p0rQEdpX5 ZhmVB/Y7QdjHdgqFd2CRXCdjnKiivJzkwsV2rU5ORbTEp5xlVj+fbRsnS6ri+ld/y9am FgfrXgIcWrbCosT9qlihOK56LAcSvZHCdY1sCl2Zg++RCvDeu5fGruyjnT/Pwkon3YgX rSlQh3rwsUcd4QdxCHZLEcRr4HCcEIa32nKHDMw35nMPj0Fpk+QTSavx+tRMPdB+bLsw ejSA== X-Gm-Message-State: AODbwcCryqcUrcY6hwQ5i7JeKf1asIb7F0TVQm6FCSpHR/RJWDrAbWOO 2EEZGfWsyX515HfZ X-Received: by 10.223.163.21 with SMTP id c21mr2476506wrb.38.1495032728850; Wed, 17 May 2017 07:52:08 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id s110sm2759117wrc.5.2017.05.17.07.52.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 May 2017 07:52:04 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id C641B3E087F; Wed, 17 May 2017 15:52:59 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: pbonzini@redhat.com, stefanha@redhat.com Date: Wed, 17 May 2017 15:52:57 +0100 Message-Id: <20170517145259.28979-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170517145259.28979-1-alex.bennee@linaro.org> References: <20170517145259.28979-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::232 Subject: [Qemu-devel] [PATCH v2 4/6] cputlb: remove tlb_flush_count X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , cota@braap.org, =?utf-8?q?Alex_Be?= =?utf-8?b?bm7DqWU=?= , qemu-devel@nongnu.org, Peter Crosthwaite Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Flushing of the CPU TLB is no longer a simple count. The ratio of self-flushes to cross-flushes and if they need to synchronise across vCPUs has more of an impact. To correctly capture this we'll replace the simple count with trace points in a future patch. Signed-off-by: Alex Bennée --- cputlb.c | 4 ---- include/exec/cputlb.h | 1 - translate-all.c | 1 - 3 files changed, 6 deletions(-) -- 2.11.0 diff --git a/cputlb.c b/cputlb.c index f5d056cc08..d1859c3f37 100644 --- a/cputlb.c +++ b/cputlb.c @@ -92,9 +92,6 @@ static void flush_all_helper(CPUState *src, run_on_cpu_func fn, } } -/* statistics */ -int tlb_flush_count; - /* This is OK because CPU architectures generally permit an * implementation to drop entries from the TLB at any time, so * flushing more entries than required is only an efficiency issue, @@ -112,7 +109,6 @@ static void tlb_flush_nocheck(CPUState *cpu) } assert_cpu_is_self(cpu); - tlb_debug("(count: %d)\n", tlb_flush_count++); tb_lock(); diff --git a/include/exec/cputlb.h b/include/exec/cputlb.h index 3f941783c5..dac9901da5 100644 --- a/include/exec/cputlb.h +++ b/include/exec/cputlb.h @@ -23,7 +23,6 @@ /* cputlb.c */ void tlb_protect_code(ram_addr_t ram_addr); void tlb_unprotect_code(ram_addr_t ram_addr); -extern int tlb_flush_count; #endif #endif diff --git a/translate-all.c b/translate-all.c index b3ee876526..eeb3807242 100644 --- a/translate-all.c +++ b/translate-all.c @@ -1927,7 +1927,6 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf) atomic_read(&tcg_ctx.tb_ctx.tb_flush_count)); cpu_fprintf(f, "TB invalidate count %d\n", tcg_ctx.tb_ctx.tb_phys_invalidate_count); - cpu_fprintf(f, "TLB flush count %d\n", tlb_flush_count); tcg_dump_info(f, cpu_fprintf); tb_unlock(); From patchwork Wed May 17 14:52:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 100002 Delivered-To: patch@linaro.org Received: by 10.182.142.97 with SMTP id rv1csp255280obb; Wed, 17 May 2017 07:56:34 -0700 (PDT) X-Received: by 10.55.141.133 with SMTP id p127mr3239602qkd.216.1495032994165; Wed, 17 May 2017 07:56:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495032994; cv=none; d=google.com; s=arc-20160816; b=vm1t/ozot37Tg/Q5En1ui4iymw7t84FEHx0GNYohXVS2nOWX4fIcV28+4CqKSBjSDT Aj8aDNnGjuQojB4N/zwwu8J81F6QrQCKVM5+7MQCPzTfwdKFH7qWL0nNnR7A4qKB5O5t pHlbHTeNLHccaFxHOKHcRWxUX+taQFxG2vz4BkMeQJUig5HBdPybxEgMRxh8jXFVE0H7 uTRuPJRuG2XHghoh3nHC10GL3x2qFv73uNBq44EFOLwqsTDKajcu2FPtCgPvA78vBR9N 2DkXBe/lVTbLCGw6/6J/d4uHPw8nHyhSvGeb8hfaR7A+M/YHWaJPMNIuMm3XoS08/p3Z NAQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=fkx3DolIxITVCWhGdxcm2J15pc5f5bdwpaYpklZZI14=; b=wvJ61eHUYEaLj76qAd4ptBPmUIHIpUBOJ8ykScH4Jy8j1CnMGv60pEHCExOyCW/9HJ r5ghZK9SBVty0Aw66XD3KA41t5Wn9XiFYs5rvNfGDBe1F6/koO2/wcaVsl34uSOqgIWU kXg5iajuxgSfUpa2kSryp9uyL2lfNGL61CFQRTsUS3MYBRyPNZjv5TveRtVpjlpXo8J6 7bnIDbLnaobySnj6taJTtnwZQ/9rjwkF5Or7RPJJ/gFD+0w7DOiiikOF+mpDuNpTNv0p wuCAqfLcElSHg/q9QbYEMIopXI3thpk/T6TIqZSxK3q9es7lDueCTBFSWVVmHvV2D/pt XgRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id w124si2413645qkc.185.2017.05.17.07.56.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 17 May 2017 07:56:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0NN-0004uB-MT for patch@linaro.org; Wed, 17 May 2017 10:56:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0JA-0001nb-Qe for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dB0J9-0004gL-8V for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:12 -0400 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:36130) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dB0J9-0004fZ-0P for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:11 -0400 Received: by mail-wm0-x22e.google.com with SMTP id 70so13262455wmq.1 for ; Wed, 17 May 2017 07:52:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fkx3DolIxITVCWhGdxcm2J15pc5f5bdwpaYpklZZI14=; b=YSLZQo8SAxhOYWvsuP/KzyKCZ5FChOUcC+9vN0Q78EEzY+MEl8oe4hw+Gxw0/hg5pd T1c5gkykGddw5UBMnWZ132+TlXR7uDKY3c/hmDsFHxMNnSWPP9aHFKdjsHu484fwiJDv qM/xg4uYDgVDH1AEq8Ka/v6g+Drpkovv+VNTw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fkx3DolIxITVCWhGdxcm2J15pc5f5bdwpaYpklZZI14=; b=de9PKCvZ/tv+zzJChhGYLRSTvN3mAHHqaLPEUoZJfuaM1VG+G5WnU0YMYn5EW43BBW doVcGATUzDG2zCEbMLo8g0+fpJczWOEo23RnDgkvpwkfz0NDIqTwnytLYChQCvLC+gn+ 1ajq4vlM4buqq/W+A/5H6rIBcyzGJMGs4y5ITawz/mcSfUgcZuF8RAQWb1mYZ3PCYt/T ZyMeex/pWquyUB+lhUUTuSULA9Rqw3PEV/UlhuVAb+itvpYV07wnY7RpUbYBl6D4Ciyx bVvIZJmzRDz5Zyg7P0Zo1dbn49zGGNvkNXbajwOzHd08hbq55kXJ8XB+fm92vqF6nauH lm1g== X-Gm-Message-State: AODbwcDti0n0mUvCjdMUoiExAHjkHl+QQrxnx8ezTJbh7vCTEgJcBBHc t2PiBGuzeboEX56y X-Received: by 10.28.24.207 with SMTP id 198mr6585004wmy.86.1495032729823; Wed, 17 May 2017 07:52:09 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 2sm19188660wmk.20.2017.05.17.07.52.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 May 2017 07:52:08 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id D7C7D3E08CD; Wed, 17 May 2017 15:52:59 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: pbonzini@redhat.com, stefanha@redhat.com Date: Wed, 17 May 2017 15:52:58 +0100 Message-Id: <20170517145259.28979-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170517145259.28979-1-alex.bennee@linaro.org> References: <20170517145259.28979-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22e Subject: [Qemu-devel] [PATCH v2 5/6] cputlb: add trace events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , cota@braap.org, =?utf-8?q?Alex_Be?= =?utf-8?b?bm7DqWU=?= , qemu-devel@nongnu.org, Peter Crosthwaite Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Given the range of costs for various SoftMMU TLB operations from deferring work for the currently running vCPU to bring the whole emulated machine to a stop for synchronised updates simple counters are less useful. Instead we log events via the trace infrastructure and we can then post-process the data in a range of ways. tlb_flush_self - the vCPU flushed its own TLB tlb_flush_async_schedule - work was scheduled and the vCPU kicked tlb_flush_synced_schedule - exclusive work was scheduled on a vCPU tlb_flush_work - scheduled work was done We can use the difference between the work being scheduled and tlb_flush_work to calculate the latency introduced. Signed-off-by: Alex Bennée --- cputlb.c | 34 +++++++++++++++++++++++++++++++++- trace-events | 7 +++++++ 2 files changed, 40 insertions(+), 1 deletion(-) -- 2.11.0 Reviewed-by: Philippe Mathieu-Daudé diff --git a/cputlb.c b/cputlb.c index d1859c3f37..b2490863e4 100644 --- a/cputlb.c +++ b/cputlb.c @@ -127,6 +127,7 @@ static void tlb_flush_nocheck(CPUState *cpu) static void tlb_flush_global_async_work(CPUState *cpu, run_on_cpu_data data) { + trace_tlb_flush_work(__func__, cpu->cpu_index); tlb_flush_nocheck(cpu); } @@ -135,17 +136,22 @@ void tlb_flush(CPUState *cpu) if (cpu->created && !qemu_cpu_is_self(cpu)) { if (atomic_mb_read(&cpu->pending_tlb_flush) != ALL_MMUIDX_BITS) { atomic_mb_set(&cpu->pending_tlb_flush, ALL_MMUIDX_BITS); + trace_tlb_flush_async_schedule(__func__, current_cpu ? + current_cpu->cpu_index : + cpu->cpu_index, cpu->cpu_index); async_run_on_cpu(cpu, tlb_flush_global_async_work, RUN_ON_CPU_NULL); } } else { - tlb_flush_nocheck(cpu); + trace_tlb_flush_self(__func__, cpu->cpu_index); + tlb_flush_global_async_work(cpu, RUN_ON_CPU_NULL); } } void tlb_flush_all_cpus(CPUState *src_cpu) { const run_on_cpu_func fn = tlb_flush_global_async_work; + trace_tlb_flush_async_schedule(__func__, src_cpu->cpu_index, -1); flush_all_helper(src_cpu, fn, RUN_ON_CPU_NULL); fn(src_cpu, RUN_ON_CPU_NULL); } @@ -153,6 +159,7 @@ void tlb_flush_all_cpus(CPUState *src_cpu) void tlb_flush_all_cpus_synced(CPUState *src_cpu) { const run_on_cpu_func fn = tlb_flush_global_async_work; + trace_tlb_flush_synced_schedule(__func__, src_cpu->cpu_index, -1); flush_all_helper(src_cpu, fn, RUN_ON_CPU_NULL); async_safe_run_on_cpu(src_cpu, fn, RUN_ON_CPU_NULL); } @@ -163,6 +170,8 @@ static void tlb_flush_by_mmuidx_async_work(CPUState *cpu, run_on_cpu_data data) unsigned long mmu_idx_bitmask = data.host_int; int mmu_idx; + trace_tlb_flush_work(__func__, cpu->cpu_index); + assert_cpu_is_self(cpu); tb_lock(); @@ -196,12 +205,16 @@ void tlb_flush_by_mmuidx(CPUState *cpu, uint16_t idxmap) if (pending_flushes) { tlb_debug("reduced mmu_idx: 0x%" PRIx16 "\n", pending_flushes); + trace_tlb_flush_async_schedule(__func__, + current_cpu->cpu_index, + cpu->cpu_index); atomic_or(&cpu->pending_tlb_flush, pending_flushes); async_run_on_cpu(cpu, tlb_flush_by_mmuidx_async_work, RUN_ON_CPU_HOST_INT(pending_flushes)); } } else { + trace_tlb_flush_self(__func__, cpu->cpu_index); tlb_flush_by_mmuidx_async_work(cpu, RUN_ON_CPU_HOST_INT(idxmap)); } @@ -212,6 +225,7 @@ void tlb_flush_by_mmuidx_all_cpus(CPUState *src_cpu, uint16_t idxmap) const run_on_cpu_func fn = tlb_flush_by_mmuidx_async_work; tlb_debug("mmu_idx: 0x%"PRIx16"\n", idxmap); + trace_tlb_flush_async_schedule(__func__, src_cpu->cpu_index, -1); flush_all_helper(src_cpu, fn, RUN_ON_CPU_HOST_INT(idxmap)); fn(src_cpu, RUN_ON_CPU_HOST_INT(idxmap)); @@ -223,6 +237,7 @@ void tlb_flush_by_mmuidx_all_cpus_synced(CPUState *src_cpu, const run_on_cpu_func fn = tlb_flush_by_mmuidx_async_work; tlb_debug("mmu_idx: 0x%"PRIx16"\n", idxmap); + trace_tlb_flush_synced_schedule(__func__, src_cpu->cpu_index, -1); flush_all_helper(src_cpu, fn, RUN_ON_CPU_HOST_INT(idxmap)); async_safe_run_on_cpu(src_cpu, fn, RUN_ON_CPU_HOST_INT(idxmap)); @@ -252,6 +267,7 @@ static void tlb_flush_page_async_work(CPUState *cpu, run_on_cpu_data data) assert_cpu_is_self(cpu); tlb_debug("page :" TARGET_FMT_lx "\n", addr); + trace_tlb_flush_work(__func__, cpu->cpu_index); /* Check if we need to flush due to large pages. */ if ((addr & env->tlb_flush_mask) == env->tlb_flush_addr) { @@ -285,9 +301,12 @@ void tlb_flush_page(CPUState *cpu, target_ulong addr) tlb_debug("page :" TARGET_FMT_lx "\n", addr); if (!qemu_cpu_is_self(cpu)) { + trace_tlb_flush_async_schedule(__func__, current_cpu->cpu_index, + cpu->cpu_index); async_run_on_cpu(cpu, tlb_flush_page_async_work, RUN_ON_CPU_TARGET_PTR(addr)); } else { + trace_tlb_flush_self(__func__, cpu->cpu_index); tlb_flush_page_async_work(cpu, RUN_ON_CPU_TARGET_PTR(addr)); } } @@ -312,6 +331,7 @@ static void tlb_flush_page_by_mmuidx_async_work(CPUState *cpu, tlb_debug("page:%d addr:"TARGET_FMT_lx" mmu_idx:0x%lx\n", page, addr, mmu_idx_bitmap); + trace_tlb_flush_work(__func__, cpu->cpu_index); for (mmu_idx = 0; mmu_idx < NB_MMU_MODES; mmu_idx++) { if (test_bit(mmu_idx, &mmu_idx_bitmap)) { @@ -336,6 +356,7 @@ static void tlb_check_page_and_flush_by_mmuidx_async_work(CPUState *cpu, unsigned long mmu_idx_bitmap = addr_and_mmuidx & ALL_MMUIDX_BITS; tlb_debug("addr:"TARGET_FMT_lx" mmu_idx: %04lx\n", addr, mmu_idx_bitmap); + trace_tlb_flush_work(__func__, cpu->cpu_index); /* Check if we need to flush due to large pages. */ if ((addr & env->tlb_flush_mask) == env->tlb_flush_addr) { @@ -343,9 +364,11 @@ static void tlb_check_page_and_flush_by_mmuidx_async_work(CPUState *cpu, TARGET_FMT_lx "/" TARGET_FMT_lx ")\n", env->tlb_flush_addr, env->tlb_flush_mask); + trace_tlb_flush_self(__func__, cpu->cpu_index); tlb_flush_by_mmuidx_async_work(cpu, RUN_ON_CPU_HOST_INT(mmu_idx_bitmap)); } else { + trace_tlb_flush_self(__func__, cpu->cpu_index); tlb_flush_page_by_mmuidx_async_work(cpu, data); } } @@ -361,9 +384,12 @@ void tlb_flush_page_by_mmuidx(CPUState *cpu, target_ulong addr, uint16_t idxmap) addr_and_mmu_idx |= idxmap; if (!qemu_cpu_is_self(cpu)) { + trace_tlb_flush_async_schedule(__func__, current_cpu->cpu_index, + cpu->cpu_index); async_run_on_cpu(cpu, tlb_check_page_and_flush_by_mmuidx_async_work, RUN_ON_CPU_TARGET_PTR(addr_and_mmu_idx)); } else { + trace_tlb_flush_self(__func__, cpu->cpu_index); tlb_check_page_and_flush_by_mmuidx_async_work( cpu, RUN_ON_CPU_TARGET_PTR(addr_and_mmu_idx)); } @@ -376,6 +402,7 @@ void tlb_flush_page_by_mmuidx_all_cpus(CPUState *src_cpu, target_ulong addr, target_ulong addr_and_mmu_idx; tlb_debug("addr: "TARGET_FMT_lx" mmu_idx:%"PRIx16"\n", addr, idxmap); + trace_tlb_flush_async_schedule(__func__, src_cpu->cpu_index, -1); /* This should already be page aligned */ addr_and_mmu_idx = addr & TARGET_PAGE_MASK; @@ -393,6 +420,7 @@ void tlb_flush_page_by_mmuidx_all_cpus_synced(CPUState *src_cpu, target_ulong addr_and_mmu_idx; tlb_debug("addr: "TARGET_FMT_lx" mmu_idx:%"PRIx16"\n", addr, idxmap); + trace_tlb_flush_synced_schedule(__func__, src_cpu->cpu_index, -1); /* This should already be page aligned */ addr_and_mmu_idx = addr & TARGET_PAGE_MASK; @@ -406,6 +434,8 @@ void tlb_flush_page_all_cpus(CPUState *src, target_ulong addr) { const run_on_cpu_func fn = tlb_flush_page_async_work; + trace_tlb_flush_async_schedule(__func__, src->cpu_index, -1); + flush_all_helper(src, fn, RUN_ON_CPU_TARGET_PTR(addr)); fn(src, RUN_ON_CPU_TARGET_PTR(addr)); } @@ -415,6 +445,8 @@ void tlb_flush_page_all_cpus_synced(CPUState *src, { const run_on_cpu_func fn = tlb_flush_page_async_work; + trace_tlb_flush_synced_schedule(__func__, src->cpu_index, -1); + flush_all_helper(src, fn, RUN_ON_CPU_TARGET_PTR(addr)); async_safe_run_on_cpu(src, fn, RUN_ON_CPU_TARGET_PTR(addr)); } diff --git a/trace-events b/trace-events index e582d6315d..500f84b8c4 100644 --- a/trace-events +++ b/trace-events @@ -78,6 +78,13 @@ disable exec_tb(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR disable exec_tb_nocache(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR disable exec_tb_exit(void *last_tb, unsigned int flags) "tb:%p flags=%x" +# SoftMMU TLB flushes +# - setting to=-1 indicates work scheduled on all vCPUs +tlb_flush_self(const char *fn, int vcpu) "%s: cpu %d" +tlb_flush_async_schedule(const char *fn, int from, int to) "%s: from_cpu=%d to_cpu=%d" +tlb_flush_synced_schedule(const char *fn, int from, int to) "%s: from_cpu=%d to_cpu=%d" +tlb_flush_work(const char *fn, int vcpu) "%s: cpu %d" + # translate-all.c translate_block(void *tb, uintptr_t pc, uint8_t *tb_code) "tb:%p, pc:0x%"PRIxPTR", tb_code:%p" From patchwork Wed May 17 14:52:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 99995 Delivered-To: patch@linaro.org Received: by 10.182.142.97 with SMTP id rv1csp254016obb; Wed, 17 May 2017 07:53:45 -0700 (PDT) X-Received: by 10.200.48.44 with SMTP id f41mr3274643qte.88.1495032825477; Wed, 17 May 2017 07:53:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495032825; cv=none; d=google.com; s=arc-20160816; b=CXN8hS1py1JMlV4CKJ3J4LBceCpoUlDcZRESbMpJ1FpHkJSdlO7Xiygz09bE8uIayD 9VPSflCtxJGd5OXDa6WyX3D7/jmQf6/R39wxrHIKxB6FJ2TMI5u7pyeQ+Cm2HuwIsLV5 8sGdhc6PLaXfIF4p4Rt7G/T2nkIDx73PYpT/glhr48TODxQFcqPBOGXutZkBK252D+7K E5ubOOoqZE1AnkTumoDqmm2SqqS3oJxUWN64oLGEDzmfoKnFCcSsWKe7ACvq+0LDcNT+ 2GG9UqY67zIHRZfBsD441hnXHP3+wEqWNAwPl1zH2K5wpny1ovP7UClpJDc8+/9R7aTx s3ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=zr8eaC1w14Cw1tsLDUZYCE/XYLWMKJGYH7RPzbyRiBQ=; b=keJwfUa+dNMZ0zr70R/tKNLen6RQScJYR5ewWSkcLi7kAOw5D8v1ANgSwucjL+OexL QbcrH55Y85V5sEGqSjWRAwYV5u8MGCKmpFZTPAmDiOH6H6IaWhYOvBHQHSMz/mMAdkqn td3KMFyzjzTfFOb50yg2AKkSCogHmudwz8tLqF0M7RwmqwVij1A376bADMwZyo/iCeWg NeH1rUQDQXnBCipnzpXTzhZtE98H77com7iuDJVrudk8SV2AFYtEYlG1rZGLR7BUZy47 hnK4irm8UUwEGWM9ceDupYMpULPGu05gneBNkgyyN2IYZGcMsNqsdHFoKAGYmfxeIfQb BRnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t64si2385883qkt.145.2017.05.17.07.53.45 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 17 May 2017 07:53:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49377 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0Ke-0002jv-Tm for patch@linaro.org; Wed, 17 May 2017 10:53:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0JB-0001qc-K0 for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dB0JA-0004hH-Cr for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:13 -0400 Received: from mail-wr0-x22b.google.com ([2a00:1450:400c:c0c::22b]:33987) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dB0JA-0004gT-3T for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:12 -0400 Received: by mail-wr0-x22b.google.com with SMTP id l9so12462915wre.1 for ; Wed, 17 May 2017 07:52:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zr8eaC1w14Cw1tsLDUZYCE/XYLWMKJGYH7RPzbyRiBQ=; b=I/AVSdxStsN51eRIO2vsIOMeQCZeTVLw1kpFwPftxOEg2KFG7V4l6fp46dz86rQl3c fmPtzR4ZGp5DDFt8BBxUCKoOfZoEnfd7YQBGFwA+J5aVuAFDUIegnWQdbjaV44N+zOLs ookJyJVUlo78lQTRbM5aImBFe+pPtxCm5nlMY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zr8eaC1w14Cw1tsLDUZYCE/XYLWMKJGYH7RPzbyRiBQ=; b=uNWcN+Jvi5pBkNK/NxmqqtFhz8ghLa3wk38x3++y8ZFD7sRHj7pl/xGKZkE3609ct2 +dLLnYfCCE0YYWUF/1llxLwph02zx4NkwW5MYwuZ6PMK+wcCbVvTi+Mp1vDg5MntDoQj zfM58DTPEprVRUTdSJUvpefTqgpYj1dd1/wMdR/K/Uj3G3soO4e9NAGfZGwkdHqNuecS 4CWyuRIM+DJAiDXYR9OlqEc71vpNmSHzs7Gycw4KkgMKDOyx7BFdeV3tkYpFjtaE5f96 DV5zRen4Adir1wAJy4k6nPMrGbFvMtGidDmXqjb5/eMstZl+TUznM6QfvBaLHVyVsifO OU9g== X-Gm-Message-State: AODbwcA0Am4Dn5SpGexsPTnLDvDr19UEJpyFeN42GKPXaJ5i/dTQKHxR jDfDFwDwCUeCqGgI X-Received: by 10.223.179.199 with SMTP id x7mr2898073wrd.72.1495032730881; Wed, 17 May 2017 07:52:10 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id n27sm1530670wra.57.2017.05.17.07.52.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 May 2017 07:52:08 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id E7F7F3E08D5; Wed, 17 May 2017 15:52:59 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: pbonzini@redhat.com, stefanha@redhat.com Date: Wed, 17 May 2017 15:52:59 +0100 Message-Id: <20170517145259.28979-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170517145259.28979-1-alex.bennee@linaro.org> References: <20170517145259.28979-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22b Subject: [Qemu-devel] [PATCH v2 6/6] new script/analyse-tlb-flushes-simpletrace.py X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is a simple helper script to extract TLB flush stats from the a simpletrace file and plot the results. Signed-off-by: Alex Bennée --- v2 - re-factored for new trace events - added time and latency graphs --- scripts/analyse-tlb-flushes-simpletrace.py | 144 +++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100755 scripts/analyse-tlb-flushes-simpletrace.py -- 2.11.0 diff --git a/scripts/analyse-tlb-flushes-simpletrace.py b/scripts/analyse-tlb-flushes-simpletrace.py new file mode 100755 index 0000000000..03fab8c86b --- /dev/null +++ b/scripts/analyse-tlb-flushes-simpletrace.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Generate a simple graph of flushes over time +# +# Author: Alex Bennée +# +# analyzer = CpuTLBFlushAnalyser(4) +# simpletrace.process("../trace-events-all", "../trace-22464", analyzer) + +import os +import simpletrace +import argparse +import numpy as np +import matplotlib +# Force matplotlib to not use any Xwindows backend. +matplotlib.use('Agg') +import matplotlib.pyplot as plt + +class FlushType: + Self, Async, Synced = range(3) + +class CpuTLBFlushAnalyser(simpletrace.Analyzer): + "A simpletrace Analyser for extracting flush stats." + + def __init__(self, nvcpus): + self.flush_total = 0 + self.flush_all = 0 + self.nvcpus = nvcpus + self.vcpu_last = [[] for _ in range(nvcpus)] + self.flush_self = [] + self.flush_self_times = [] + self.flush_async = [] + self.flush_async_times = [] + self.flush_synced = [] + self.flush_synced_times = [] + self.flush_work = [] + + self.unmatched_work = [] + + def __save_queue(self, vcpu, record): + self.flush_total += 1 + # FIXME: don't seem to see -1 + if vcpu > 0x7fffffff: + self.flush_all += 1 + for i in range(0, self.nvcpus): + self.vcpu_last[i].append(record) + else: + self.vcpu_last[vcpu].append(record) + + def tlb_flush_self(self, timestamp, fn, vcpu): + self.__save_queue(vcpu, (timestamp[0], FlushType.Self)) + self.flush_self.append((timestamp[0], vcpu)) + + def tlb_flush_async_schedule(self, timestamp, fn, from_vcpu, to_vcpu): + self.__save_queue(to_vcpu, (timestamp[0], FlushType.Async, + to_vcpu, from_vcpu)) + self.flush_async.append((timestamp[0], to_vcpu)) + + def tlb_flush_synced_schedule(self, timestamp, fn, from_vcpu, to_vcpu): + self.__save_queue(to_vcpu, (timestamp[0], FlushType.Synced, + to_vcpu, from_vcpu)) + self.flush_synced.append((timestamp[0], to_vcpu)) + + def tlb_flush_work(self, timestamp, fn, vcpu): + "Check when it was queued and work out how long it took" + + if len(self.vcpu_last[vcpu]): + last = self.vcpu_last[vcpu].pop(0) + latency = timestamp[0] - last[0] + switcher = { + FlushType.Self: lambda a: a.flush_self_times.append(latency), + FlushType.Async: lambda a: a.flush_async_times.append(latency), + FlushType.Synced: lambda a: a.flush_synced_times.append(latency), + } + switcher.get(last[1])(self) + + self.flush_work.append((timestamp[0], vcpu)) + else: + self.unmatched_work.append((timestamp[0], vcpu, fn)) + + + + +def get_args(): + "Grab options" + parser = argparse.ArgumentParser() + parser.add_argument("--output", "-o", type=str, help="Render plot to file") + parser.add_argument("--vcpus", type=int, help="Number of vCPUS") + parser.add_argument("--graph", choices=['time', 'latency'], default='time') + parser.add_argument("events", type=str, help='trace file read from') + parser.add_argument("tracefile", type=str, help='trace file read from') + return parser.parse_args() + +def plot_time_series(time_data, label): + "Plot one timeseries, return star and end time limits" + counts = np.arange(0, len(time_data)) + times = [x[0] for x in time_data] + plt.plot(times, counts, label=label) + return (times[0],times[-1]) + + +if __name__ == '__main__': + args = get_args() + + # Gather data from the trace + analyzer = CpuTLBFlushAnalyser(args.vcpus) + + simpletrace.process(args.events, args.tracefile, analyzer) + + # Print some summary stats + print ("Flushes: self:%d async:%d synced:%d" % + ( len(analyzer.flush_self), + len(analyzer.flush_async), + len(analyzer.flush_synced))) + + if args.graph == 'time': + start_self, end_self = plot_time_series(analyzer.flush_self, "Self") + start_async, end_async = plot_time_series(analyzer.flush_async, "Async") + start_synced, end_synced = plot_time_series(analyzer.flush_synced, "Self") + + # start right at the edge + plt.xlim(xmin=min(start_self, start_async, start_synced)) + elif args.graph == 'latency': + + # Three subplots, the axes array is 1-d + + f, (ax_self, ax_async, ax_synced) = plt.subplots(3, sharex=True) + ax_self.set_title("Distribution") + + ax_self.hist(analyzer.flush_self_times, 10, normed=1, + facecolor='green', alpha=0.5) + ax_self.hist(analyzer.flush_async_times, 10, normed=1, + facecolor='blue', alpha=0.5) + ax_self.hist(analyzer.flush_synced_times, + 10, normed=1, + facecolor='red', alpha=0.5) + else: + raise ValueError("Bad graph type") + + if args.output: + plt.savefig(args.output) + else: + plt.show()