From patchwork Fri Jan 12 11:30:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 124306 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1986785qgn; Fri, 12 Jan 2018 04:15:12 -0800 (PST) X-Google-Smtp-Source: ACJfBovF0kQXVycAFMNqqY+mMfRTPOqC7v2afBHC9CpCousU8z59mRBVZwJXRbvVRj97/7ygT70e X-Received: by 10.37.81.138 with SMTP id f132mr23060644ybb.58.1515759312245; Fri, 12 Jan 2018 04:15:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515759312; cv=none; d=google.com; s=arc-20160816; b=Pv1xaIblg6BlvU1CSasoaoeP64H00FpaO+QCg7lHi6e9Nkz3We7A+84KsPIv+oejjp WVYYXGFTqS3i4LBLwopOzE1A9/5H+41JjizbP5KFfMfCFHbYNK9dahvD5S8oTjVxAfZK 9p+XhPnLmFIQMgZj7mtPXXFDwpcANv72gCkXg01AOMceHc1d4VU1PQ1jIn5yBYbqaAYX VJx41dJuQQFhwCjuPDBQRznf41+cJYab7CXLG5amojO+QoqJu9iZMgw+At67QrAkrjK6 giRbWE7Opxy2LBkQ79cea9+h5tMZDn9nMV+OZM8qe5xptYqmBmqcLU5ULFs7geWznOcs oZKQ== 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=8uK7m+aJMARg3nM8RYFYCYedyXZ6erON3h2snC7pldM=; b=Hv2i0Dfph0dsTP+Rs9OI+wkrRh433fsxLAlWEwJexUtxwdh14aSK/Wx7sJl8J2ueA3 CEIFSvgYqxLTVDBFzzt647DTfHP4AwxC/PvWdESbZvhh6nILlp28SrDamyR+ZA9D+wGb 5gJZ5RRDOF1sDDDG+D67mvhOPhYA20uRakUJPQnJHQZAv7M9VTirj4tWEU+QTS8TfXog W1xiO3jts2L3OjDEYIX3vMFAk2xqUAB+wttDIIc6W2zSLZeJmvy+vh7fh54S96dyuHMx fCmwSIATNWJ8bf7eFEjGwaxRO3U0gAm5NSRgSz4cM/kIzYmVWq7Xx6LDD875UajiCC7L WtOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Gu6WeHjI; 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id i67si1196096ybi.643.2018.01.12.04.15.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 12 Jan 2018 04:15:12 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=Gu6WeHjI; 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=redhat.com Received: from localhost ([::1]:36462 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZyEp-0004yR-OX for patch@linaro.org; Fri, 12 Jan 2018 07:15:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZxZ4-0007ja-KV for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZxZ3-0005m8-Ka for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:02 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:37003) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eZxZ3-0005lV-DS for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:01 -0500 Received: by mail-wr0-x241.google.com with SMTP id f8so5037331wre.4 for ; Fri, 12 Jan 2018 03:32:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8uK7m+aJMARg3nM8RYFYCYedyXZ6erON3h2snC7pldM=; b=Gu6WeHjIKfSmDdb6oRzZdNG0zr6iEeEwyXbmc8jEfSzcFo0D+zNEUdzLezD3OSbVsk P6zONynhs3/y5mYRlUgb/2U8Uyvdgx0rQqSAz4RNdvHe3xmOwtUllEb54WULPyBMW1ps zJUkMoEA4KgASR0OeJrjPNrRumpLSaTKrw9E25UyBwbwAqkfimzF1u/Gy1U7fMQ10URH HC2qnTuQH/A7j+6jnPiGATtn+zRJVRi5Fgc27Tqu9tp3ZCfybvu7SoDrobPUCOm1X0fb eGB1SSdtrrwxN4o6G2/r9xo0OTmhHnZGAHp7PYDVLrp0nUsgvQ6FMWlyh816qWq3HBLN aJ8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=8uK7m+aJMARg3nM8RYFYCYedyXZ6erON3h2snC7pldM=; b=OGS1klkty4Qdu/V1rt+NgWg3qzKgf1pi330eJu+bihD/GJ9c5ppSmQ51ofzVQdWZDG 8M2df9xq/zVuUXnexk5gGfI0B9BQnLZGNyHB4FwSRH4+wZ7Utd1v9U97XuzBgsh6X0hP /fAyUrwhyyC4PvGhQ0gSkwJl2yRtzyv/ulpFNhO+N9/eEI98iL64GqGY0wY6n3GbLvM8 ycW6FxnUVTFGt7z3yBkMjVU3x3e86Hgvga0SEjiZsnS24GAapT1oJ0mYNxEqGvTJ6Id2 C5dLlWdZt6X/WTWd0weTtfUJdmfuQauyVnq3jnPbJyM9KqkQMjFSRmL6BRksgF6YyEte ulvg== X-Gm-Message-State: AKGB3mIC9esHTZSsjB2a/hIzgXD+nf02TJRsXg6pQqahbNE0fJaZiKCu Vt33ZdPhXf3dar42EZ7WrIxwVr6v X-Received: by 10.223.183.23 with SMTP id l23mr14776005wre.33.1515756720039; Fri, 12 Jan 2018 03:32:00 -0800 (PST) Received: from 640k.lan (dynamic-adsl-78-12-229-84.clienti.tiscali.it. [78.12.229.84]) by smtp.gmail.com with ESMTPSA id l8sm2732271wmg.46.2018.01.12.03.31.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 03:31:59 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 12 Jan 2018 12:30:59 +0100 Message-Id: <1515756676-3860-36-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1515756676-3860-1-git-send-email-pbonzini@redhat.com> References: <1515756676-3860-1-git-send-email-pbonzini@redhat.com> 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::241 Subject: [Qemu-devel] [PULL 35/52] scripts/qemu-gdb: add simple tcg lock status helper 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: =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée Add a simple helper to dump lock state. Signed-off-by: Alex Bennée Signed-off-by: Paolo Bonzini --- scripts/qemu-gdb.py | 3 ++- scripts/qemugdb/tcg.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 scripts/qemugdb/tcg.py -- 1.8.3.1 diff --git a/scripts/qemu-gdb.py b/scripts/qemu-gdb.py index b3f8e04..d58213e 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, tcg class QemuCommand(gdb.Command): '''Prefix for QEMU debug support commands''' @@ -38,6 +38,7 @@ QemuCommand() coroutine.CoroutineCommand() mtree.MtreeCommand() aio.HandlersCommand() +tcg.TCGLockStatusCommand() coroutine.CoroutineSPFunction() coroutine.CoroutinePCFunction() diff --git a/scripts/qemugdb/tcg.py b/scripts/qemugdb/tcg.py new file mode 100644 index 0000000..88d042e --- /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 Fri Jan 12 11:31:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 124305 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1968484qgn; Fri, 12 Jan 2018 03:59:31 -0800 (PST) X-Google-Smtp-Source: ACJfBovfPgzhd+PfcW2Tbro0G9C6Kg2KQKiL4sKj5R59VCmc27+XMJCBcCJpzt530EYo81hZ6glf X-Received: by 10.37.61.135 with SMTP id k129mr1233582yba.149.1515758371419; Fri, 12 Jan 2018 03:59:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515758371; cv=none; d=google.com; s=arc-20160816; b=DIqii8zqCpV+Zf40zvbth2U6/dInPzSvgcwNUuf7kVfhRqiqxwSAwXiQMKlw8O9deX nW2TUpo4+klSSgJbR1gWGxRsAvxiD3dc8bHDqAw7nH71MfUA3JdHT4ufQKQbMpH9WhpA 1DAue4dzH8MkEZzKOu4xAMj6pwSCek2dJY6fs/1ktoLO7xMHO8d3IiQyB45oYHQmRFGr uMllAu/xHItmW+49yqkOh8970OjRQZJfkHo7JAtjaKZHtjWG6HCNrBJ5VB3mFjS2Eva+ 5ZVtJSm+Nec8P3A+04+FyFlrvRMg+jkIRn6Hv5iacV5GgvrDn8bVMdI78u3lG97kQ/5Z M9/A== 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=IZajmzx9rYLPKOH9/4/XmxvTKJQx6xsNJtYxUYRx2LM=; b=STrAS9GhfjQbfGdGJwRPDSIZsXg11QZpsl/4+f63SwpigzlBd7ziqOVGKQqDNTwcZz iu8A7TVefDEGalGByyO3AIAoSIno81UYIi1faNVIgzjLGiAc02+cqN/Yh3nCJt0a0NA0 kN1Rj9D2Ad8G6ilYwzlV2cka0VGISm8E/w28Bw1/oSB2D0/skZnS9AlFbK3lmDwtlyBv ssRLCrZDQaIFsInPaDu2x9NG8Wf/O3NcmGd4+qNdYctTgJB3/qQa7h9LQLZ7BYASKv0L k05XiAE1JNPgQ+1BVth5docBMLS4Dzig7X8TBmBVBFDjaAorisO5r8JwWtXLMii1DlVb MnyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=R8sdTAro; 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v124si1343163ywf.321.2018.01.12.03.59.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 12 Jan 2018 03:59:31 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=R8sdTAro; 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=redhat.com Received: from localhost ([::1]:35687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZxze-0006yi-St for patch@linaro.org; Fri, 12 Jan 2018 06:59:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZxZ5-0007ky-Mm for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZxZ4-0005mc-L6 for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:03 -0500 Received: from mail-wr0-x234.google.com ([2a00:1450:400c:c0c::234]:33976) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eZxZ4-0005mL-Db for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:02 -0500 Received: by mail-wr0-x234.google.com with SMTP id 36so5058150wrh.1 for ; Fri, 12 Jan 2018 03:32:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IZajmzx9rYLPKOH9/4/XmxvTKJQx6xsNJtYxUYRx2LM=; b=R8sdTAroFYJtMmPIxzGXa4EM7D7FMbpvhcS7IJ/62hZnYsCHYtqUTs+8Aw6EGTmVTY 2Bwx68Q4V5bxKWgGPWIGV4UrlcpiFpytIGS+2nRDVQwJOb3+HOeAFlh3lyidshW9YOoz HfGGlUtJcJH9iAwY1h4xke+pWMhQXeH7FczHb6Xa2T76I7KKH6XhexUsJtyjdBzYpuzd 9gpgUiykDDMi53WBQwZps1cHSPSYMrqlQni/cuYYuWwy3H+QPsEcGUD/+CYbO4DhFIuJ bHGRO5SA6sqb+TSLcE4rvN0MS48Qh5VpgLl8J5SMP6gR5rbAs7MMWX/qBT3jWn2r8IzK fxgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=IZajmzx9rYLPKOH9/4/XmxvTKJQx6xsNJtYxUYRx2LM=; b=ALgCNYc74XNsrsSMYTfY8jHMpEU3Xx0laV2U3UNZG14af3oKSx8tQ6xMIKhmdryBco oZSeXUrAeEALHN5ukW0pAmNLJUjMEJ/lkDnodqIeQwA8wkJXTKPDzgbVxLbVJaTdPc/L GLuNl5pNoDoR2URdTk0rLvgQ/HNQQ+MRog3jfh/1p6+v2w5HMMvj9ttLUjg97plrYaBQ NnostZJ9uKpx706TftTT/TEXvkvSz66x8dUwswys0zoY/1lqRSlu2+1UbRGrlPslCu9h N4ha2Xy2wXeZIQ3z/IZ6r7SuuekQydhbdOpYvLxBD6lXibDafpdnFc7Ks8Uo+mmHt6HR mVjw== X-Gm-Message-State: AKGB3mJUq9ipPxvxd66HlZCBbuZHPS1x4tZmt6U74H6IocWuY7f45j75 w4IkF8859jmu1F7RpHHUbfUqOdZv X-Received: by 10.223.160.139 with SMTP id m11mr22577963wrm.119.1515756721089; Fri, 12 Jan 2018 03:32:01 -0800 (PST) Received: from 640k.lan (dynamic-adsl-78-12-229-84.clienti.tiscali.it. [78.12.229.84]) by smtp.gmail.com with ESMTPSA id l8sm2732271wmg.46.2018.01.12.03.32.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 03:32:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 12 Jan 2018 12:31:00 +0100 Message-Id: <1515756676-3860-37-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1515756676-3860-1-git-send-email-pbonzini@redhat.com> References: <1515756676-3860-1-git-send-email-pbonzini@redhat.com> 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::234 Subject: [Qemu-devel] [PULL 36/52] 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: =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée 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é Signed-off-by: Paolo Bonzini --- scripts/qemu-gdb.py | 3 ++- scripts/qemugdb/timers.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 scripts/qemugdb/timers.py -- 1.8.3.1 diff --git a/scripts/qemu-gdb.py b/scripts/qemu-gdb.py index d58213e..690827e 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, tcg +from qemugdb import aio, mtree, coroutine, tcg, timers class QemuCommand(gdb.Command): '''Prefix for QEMU debug support commands''' @@ -39,6 +39,7 @@ coroutine.CoroutineCommand() mtree.MtreeCommand() aio.HandlersCommand() tcg.TCGLockStatusCommand() +timers.TimersCommand() coroutine.CoroutineSPFunction() coroutine.CoroutinePCFunction() diff --git a/scripts/qemugdb/timers.py b/scripts/qemugdb/timers.py new file mode 100644 index 0000000..98ab7c6 --- /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 Fri Jan 12 11:31:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 124307 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1995905qgn; Fri, 12 Jan 2018 04:23:36 -0800 (PST) X-Google-Smtp-Source: ACJfBotd4+XXyhR2zXDXDHvdaKetMBJU7okdSSVCX0G27ia1R98x4ZXk1V1v7sVNF6CgaQpjGR37 X-Received: by 10.37.59.3 with SMTP id i3mr61307yba.188.1515759816755; Fri, 12 Jan 2018 04:23:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515759816; cv=none; d=google.com; s=arc-20160816; b=P52zPAA2iR2Jgw2yRgqA9JIUmMJ3w/PLPlwhSXSRG1NZ4CKhZ0ser9fP4hMHFm12uy 3FKf/tGS+BL2ZN0MiIxODHu8IZuNN/vcX1lZsUGdeINHFiCLO/aVSULTrOz6g6XBZ+xx Sda2FPKWg5290ZtH/iLvzWyOL69uig+VArgOfc06tH4Qh/3MtyYLgDdCoAbIzWdt13Da K8RxWMadzMaboB0crLxq3mofNtRDXKxcUmmRmUTTEZ8bPmemZs+fDaUEqfEVwoIo6WNb 7ET/4ye59lfshjtQbM2Qd5EI/3zeRldxOMOYkN8U2hW0cnBbF73WNt7HQlPveu3eUonZ 7QYQ== 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=ji3zYJr0a36HKOJ9HE/PLOaJVocmgHMoxyHaRzyhj0g=; b=iBbrg8ddpPY/CoQeckoDITlOBecmspArksZ580DcBgH+m6JXbOOqWSofwTw4hJVM+2 7XLy1XMFQOfQou23uPnX0+EwW7JhZhcFbUN2tpyG34MxWhiE/5Sv+zP1L6sADubj2of+ LuiAKsVmLGX4w1mbnSiDDIINjVAytfyDwOVvY80stcdLFES3ABnxJ5prH0EOUbyKSo/R z62y/Z0Kh2FlqPuYBjQcmGAGn7WQKKKcMfShe9Ds0tF0Q5B9iHFfSOuQxF5n4WR99hfe YoAWFLslAfIne1V88/GPv6IOuKEW6MSMpWKs6EqHn4zWJyxBiBu3dEm+QqSDf20+iVTx khcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=rhqLYj1c; 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v4si2187895ywf.683.2018.01.12.04.23.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 12 Jan 2018 04:23:36 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=rhqLYj1c; 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=redhat.com Received: from localhost ([::1]:36738 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZyMy-00033A-8H for patch@linaro.org; Fri, 12 Jan 2018 07:23:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZxZO-00084P-TR for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZxZN-00065g-Ll for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:22 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:43283) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eZxZN-00065E-Db for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:21 -0500 Received: by mail-wr0-x241.google.com with SMTP id s13so5021218wra.10 for ; Fri, 12 Jan 2018 03:32:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ji3zYJr0a36HKOJ9HE/PLOaJVocmgHMoxyHaRzyhj0g=; b=rhqLYj1cRJEItEnNNOVAAuT5VcjaKVYkwdJlXeL0NhYnm6/Y9KyxsE3z2+PTcwOgk2 ugdBioU3tC32RbhhvjRhn7+tQ6+bSiKMPWjn4oUmOWZJXRyYX1vlva9Irks9d67Npql+ D3m+itQIG+TNk5Bz37UwJVLfEt+RQm/nyEnyoAVGIjQnIkM5nPfVh2e26BKRq0ZsdQhD WJEVN2Ar0ASQiVLUxeirJxMgss1GsgyOlkeCeOsB/5CF2QXlkK8tHVA4x2wF3+4a6P9O teozDUTVvrLcG3SKlXNEOTmbruv50D18FKSe6D7NK6BSaaFh+A82oWNft2hL05NF2Le+ sizQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ji3zYJr0a36HKOJ9HE/PLOaJVocmgHMoxyHaRzyhj0g=; b=h13gTVJ/oE/4NHlIDZXaUFCXm0Cvz1PElZ1lWZzBufE3f5uHz9h5VcWAT9Ja85e06D CDZSpA5JfckM+Ye8t+hq6l82KB4iVyr+VZ0gNHKp7M4YcYbG+jxbFACMQUHrsdZxofjO q/O9KqsI82iN+u9CNoQK03lC6BWmfIV1SStcyTBOK2uRxrzGtUYtXt0+tueKyVQWZlbp 3roEkbi5WT7bG8Hz9Vb4G+yB4PfLpNj8zxKEcPlNkdPpLx0dNfAmw3HNxkzjfdeqLyCX 56PEGpAVsP68rCwWXGXFvzD6bE6pGqF9jM2C2I/wjCwIFY0OiTNkP/75r1m28VmbrDsa WHfg== X-Gm-Message-State: AKwxytcwqFXQo7fHMcRq67dCAbOpa24GG8NHfBMBQVb/TCxDIHd/TNFV 1jsy4YPr5X/C05WYDDnFO//X+SLd X-Received: by 10.223.161.198 with SMTP id v6mr969686wrv.65.1515756740032; Fri, 12 Jan 2018 03:32:20 -0800 (PST) Received: from 640k.lan (dynamic-adsl-78-12-229-84.clienti.tiscali.it. [78.12.229.84]) by smtp.gmail.com with ESMTPSA id l8sm2732271wmg.46.2018.01.12.03.32.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 03:32:18 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 12 Jan 2018 12:31:15 +0100 Message-Id: <1515756676-3860-52-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1515756676-3860-1-git-send-email-pbonzini@redhat.com> References: <1515756676-3860-1-git-send-email-pbonzini@redhat.com> 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::241 Subject: [Qemu-devel] [PULL 51/52] util/qemu-thread-*: add qemu_lock, locked and unlock 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: =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée Signed-off-by: Alex Bennée Signed-off-by: Paolo Bonzini --- include/qemu/thread.h | 39 +++++++++++++++++++++++++++++++++++---- util/qemu-thread-posix.c | 21 ++++++++++++--------- util/qemu-thread-win32.c | 20 +++++++++++--------- util/trace-events | 7 ++++--- 4 files changed, 62 insertions(+), 25 deletions(-) -- 1.8.3.1 diff --git a/include/qemu/thread.h b/include/qemu/thread.h index 9910f49..9af4e94 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -22,9 +22,31 @@ typedef struct QemuThread QemuThread; void qemu_mutex_init(QemuMutex *mutex); void qemu_mutex_destroy(QemuMutex *mutex); -void qemu_mutex_lock(QemuMutex *mutex); -int qemu_mutex_trylock(QemuMutex *mutex); -void qemu_mutex_unlock(QemuMutex *mutex); +int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int line); +void qemu_mutex_lock_impl(QemuMutex *mutex, const char *file, const int line); +void qemu_mutex_unlock_impl(QemuMutex *mutex, const char *file, const int line); + +#define qemu_mutex_lock(mutex) \ + qemu_mutex_lock_impl(mutex, __FILE__, __LINE__) +#define qemu_mutex_trylock(mutex) \ + qemu_mutex_trylock_impl(mutex, __FILE__, __LINE__) +#define qemu_mutex_unlock(mutex) \ + qemu_mutex_unlock_impl(mutex, __FILE__, __LINE__) + +static inline void (qemu_mutex_lock)(QemuMutex *mutex) +{ + qemu_mutex_lock(mutex); +} + +static inline int (qemu_mutex_trylock)(QemuMutex *mutex) +{ + return qemu_mutex_trylock(mutex); +} + +static inline void (qemu_mutex_unlock)(QemuMutex *mutex) +{ + qemu_mutex_unlock(mutex); +} /* Prototypes for other functions are in thread-posix.h/thread-win32.h. */ void qemu_rec_mutex_init(QemuRecMutex *mutex); @@ -39,7 +61,16 @@ void qemu_cond_destroy(QemuCond *cond); */ void qemu_cond_signal(QemuCond *cond); void qemu_cond_broadcast(QemuCond *cond); -void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex); +void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, + const char *file, const int line); + +#define qemu_cond_wait(cond, mutex) \ + qemu_cond_wait_impl(cond, mutex, __FILE__, __LINE__) + +static inline void (qemu_cond_wait)(QemuCond *cond, QemuMutex *mutex) +{ + qemu_cond_wait(cond, mutex); +} void qemu_sem_init(QemuSemaphore *sem, int init); void qemu_sem_post(QemuSemaphore *sem); diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 959a570..b789cf3 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -57,26 +57,28 @@ void qemu_mutex_destroy(QemuMutex *mutex) error_exit(err, __func__); } -void qemu_mutex_lock(QemuMutex *mutex) +void qemu_mutex_lock_impl(QemuMutex *mutex, const char *file, const int line) { int err; assert(mutex->initialized); + trace_qemu_mutex_lock(mutex, file, line); + err = pthread_mutex_lock(&mutex->lock); if (err) error_exit(err, __func__); - trace_qemu_mutex_locked(mutex); + trace_qemu_mutex_locked(mutex, file, line); } -int qemu_mutex_trylock(QemuMutex *mutex) +int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int line) { int err; assert(mutex->initialized); err = pthread_mutex_trylock(&mutex->lock); if (err == 0) { - trace_qemu_mutex_locked(mutex); + trace_qemu_mutex_locked(mutex, file, line); return 0; } if (err != EBUSY) { @@ -85,15 +87,16 @@ int qemu_mutex_trylock(QemuMutex *mutex) return -EBUSY; } -void qemu_mutex_unlock(QemuMutex *mutex) +void qemu_mutex_unlock_impl(QemuMutex *mutex, const char *file, const int line) { int err; assert(mutex->initialized); - trace_qemu_mutex_unlocked(mutex); err = pthread_mutex_unlock(&mutex->lock); if (err) error_exit(err, __func__); + + trace_qemu_mutex_unlock(mutex, file, line); } void qemu_rec_mutex_init(QemuRecMutex *mutex) @@ -152,14 +155,14 @@ void qemu_cond_broadcast(QemuCond *cond) error_exit(err, __func__); } -void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex) +void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const char *file, const int line) { int err; assert(cond->initialized); - trace_qemu_mutex_unlocked(mutex); + trace_qemu_mutex_unlock(mutex, file, line); err = pthread_cond_wait(&cond->cond, &mutex->lock); - trace_qemu_mutex_locked(mutex); + trace_qemu_mutex_locked(mutex, file, line); if (err) error_exit(err, __func__); } diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index 94f3491..ab60c0d 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -56,30 +56,32 @@ void qemu_mutex_destroy(QemuMutex *mutex) InitializeSRWLock(&mutex->lock); } -void qemu_mutex_lock(QemuMutex *mutex) +void qemu_mutex_lock_impl(QemuMutex *mutex, const char *file, const int line) { assert(mutex->initialized); + trace_qemu_mutex_lock(mutex, file, line); + AcquireSRWLockExclusive(&mutex->lock); - trace_qemu_mutex_locked(mutex); + trace_qemu_mutex_locked(mutex, file, line); } -int qemu_mutex_trylock(QemuMutex *mutex) +int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int line) { int owned; assert(mutex->initialized); owned = TryAcquireSRWLockExclusive(&mutex->lock); if (owned) { - trace_qemu_mutex_locked(mutex); + trace_qemu_mutex_locked(mutex, file, line); return 0; } return -EBUSY; } -void qemu_mutex_unlock(QemuMutex *mutex) +void qemu_mutex_unlock_impl(QemuMutex *mutex, const char *file, const int line) { assert(mutex->initialized); - trace_qemu_mutex_unlocked(mutex); + trace_qemu_mutex_unlock(mutex, file, line); ReleaseSRWLockExclusive(&mutex->lock); } @@ -140,12 +142,12 @@ void qemu_cond_broadcast(QemuCond *cond) WakeAllConditionVariable(&cond->var); } -void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex) +void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const char *file, const int line) { assert(cond->initialized); - trace_qemu_mutex_unlocked(mutex); + trace_qemu_mutex_unlock(mutex, file, line); SleepConditionVariableSRW(&cond->var, &mutex->lock, INFINITE, 0); - trace_qemu_mutex_locked(mutex); + trace_qemu_mutex_locked(mutex, file, line); } void qemu_sem_init(QemuSemaphore *sem, int init) diff --git a/util/trace-events b/util/trace-events index 025499f..515e625 100644 --- a/util/trace-events +++ b/util/trace-events @@ -56,6 +56,7 @@ lockcnt_futex_wait(const void *lockcnt, int val) "lockcnt %p waiting on %d" lockcnt_futex_wait_resume(const void *lockcnt, int new) "lockcnt %p after wait: %d" lockcnt_futex_wake(const void *lockcnt) "lockcnt %p waking up one waiter" -# util/qemu-thread-posix.c -qemu_mutex_locked(void *lock) "locked mutex %p" -qemu_mutex_unlocked(void *lock) "unlocked mutex %p" +# util/qemu-thread.c +qemu_mutex_lock(void *mutex, const char *file, const int line) "waiting on mutex %p (%s:%d)" +qemu_mutex_locked(void *mutex, const char *file, const int line) "taken mutex %p (%s:%d)" +qemu_mutex_unlock(void *mutex, const char *file, const int line) "released mutex %p (%s:%d)" From patchwork Fri Jan 12 11:31:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 124308 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1996942qgn; Fri, 12 Jan 2018 04:24:44 -0800 (PST) X-Google-Smtp-Source: ACJfBovVrJzyXwlfubNy3SRsjyv+CBmRQu2i36mj7nZn+MXhYhtwI/miEQOAa+xl79HkFNgnrxPO X-Received: by 10.37.216.3 with SMTP id p3mr23267513ybg.84.1515759884840; Fri, 12 Jan 2018 04:24:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515759884; cv=none; d=google.com; s=arc-20160816; b=K62wesPUJ08eZh4eUFEEc9Pb2bko2zrKhuRH63ju/74SfigXLNaLeB06mQsoOXkZ6l PbSuxSbPBy+0JD8Ge5CzIc6WQ4aClSvCUqu5b0Yu2NzR8WenB/12aHWsHTse88XMvaC6 eSC8W7rw5gm2tS3PUQ+AIdq50dEoRZ332lCfVpnLDumYmwwAC5KxH15zHwGnZYfrratx /F4MxZy2kitf4tS0atDLF76F5DNyLSsRLBxIBsSPjvItIX5SdR2Y9nKzmdVHL/yTxjwE LC5D62o9LV8iZaIAsdPayZ9r+F/hbflkiO/Z2GSkbyGBe4bQA+OdO/OYnZ5KXeZsW4hU cJgQ== 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=M0ZMFLJUiCrUyWZeCMLargX01+hYB4hFZwDirfHBgGc=; b=SkAFJFToVJ2DYy11yjZtnUT2RWbHYGm9mrTc/g+1VD/BFTASbwKZ8nMdjfOZFtFwoN r36mYzxY1ZMJdUPlNXoOGF6jBbYq5nkKKN6YJqlVy2I29TxQnLQFc11f9Of49m4FZ9DH l92utlyYfF+11NBJo0z9A/H03b7jHdrncW6M7j9UENEk+9YW8ruwqx2MkA7Zq87btsCq lgO4Jm6Eq9Dy9CUT7gJdV7AmzrtELyT9EEKhrkPQSgQ75rpIlKE7o6PiLoIJ3FgjfHnx B/qoXNRcLFHVPpEkwVJpgLKMo1RkdyktlQhsJzCOTrv0B+vlD3CvIc9bJvK7JNfcl5ha LtjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Hu4qz35W; 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o2si2540045ywc.795.2018.01.12.04.24.44 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 12 Jan 2018 04:24:44 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=Hu4qz35W; 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=redhat.com Received: from localhost ([::1]:36863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZyO4-0004MD-C6 for patch@linaro.org; Fri, 12 Jan 2018 07:24:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZxZP-000855-Kv for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZxZO-00066R-Kq for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:23 -0500 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:41786) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eZxZO-00065r-CN for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:22 -0500 Received: by mail-wm0-x22e.google.com with SMTP id g75so11524094wme.0 for ; Fri, 12 Jan 2018 03:32:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M0ZMFLJUiCrUyWZeCMLargX01+hYB4hFZwDirfHBgGc=; b=Hu4qz35WmvxrEVWbzhnSNYc9X4sVjecxETQ8I5sdCAhTiqwvjsOTJYlndlVXzemNm1 u4E08uMqB/VMQyypKXXwNK8PfVKk0Moj7xk2hx2QEonowNvLv8SRU4w2eb8jHwhrzAjr x3ecyaOPnqtWxbZN0f5KGglSsE8JCjOeCXIWy3NSQJshEH/jn2R+WMzkEP7fWRZMb109 q8WcJnpy750mPRN5QAx7OyIXfKgl+iHpoS/f6XW29yk4T8azfkd1zfFcpEKtPbkO8CbW GcwqZ3oMF74gjknI17sdNOzV7bOsxV5gxH4wCTkeGnOnXi0aLUxrpGo2Qnhdnum/uEko +YYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=M0ZMFLJUiCrUyWZeCMLargX01+hYB4hFZwDirfHBgGc=; b=JsAjQrtMxEBQFXBwvh2PTNRr5zj3bbExMsej3M1DkfhZ53WqI86fmK1t0skeDWO67T Mia0lM2e0KbiugHOI1uCwi3QuY20tZwALiRnh0Q521hQ7Xug/w+02Dh2RF6P7r/uZKXQ kbxRhbH5NLcR7uyskBy/Y0aKpC2CblnaqFcdqdnS5X/B10y5CIC+3BDkZpfrPM60hTUu Nl2Wk95drN/zb19PYk006cjF9rr1NE9UsQn+vbchk5SWnoIuykEElb5qlRcSQNURjefM anVyS+9HQOJMYbde/57E0noh8Q5NDltuufU3t/oh5hyn6JAfaxYH6gdmI35p81eOWKLD Wv5A== X-Gm-Message-State: AKwxytdvLuwvtOMmU4+LO7PTsayFHSmYb2qthj7/6MJRk5WZdHpMuWfG 7pRVEtdQ+TwbwLxyh6Iyx8hyV6c4 X-Received: by 10.28.35.200 with SMTP id j191mr4194322wmj.146.1515756740980; Fri, 12 Jan 2018 03:32:20 -0800 (PST) Received: from 640k.lan (dynamic-adsl-78-12-229-84.clienti.tiscali.it. [78.12.229.84]) by smtp.gmail.com with ESMTPSA id l8sm2732271wmg.46.2018.01.12.03.32.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 03:32:20 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 12 Jan 2018 12:31:16 +0100 Message-Id: <1515756676-3860-53-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1515756676-3860-1-git-send-email-pbonzini@redhat.com> References: <1515756676-3860-1-git-send-email-pbonzini@redhat.com> 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] [PULL 52/52] scripts/analyse-locks-simpletrace.py: script to analyse lock times 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: =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée This script allows analysis of mutex acquisition and hold times based on a trace file. Given a trace control file of: qemu_mutex_lock qemu_mutex_locked qemu_mutex_unlock And running with: $QEMU $QEMU_ARGS -trace events=./lock-trace You can analyse the results with: ./scripts/analyse-locks-simpletrace.py trace-events-all ./trace-21812 Signed-off-by: Alex Bennée Signed-off-by: Paolo Bonzini --- scripts/analyse-locks-simpletrace.py | 99 ++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 scripts/analyse-locks-simpletrace.py -- 1.8.3.1 diff --git a/scripts/analyse-locks-simpletrace.py b/scripts/analyse-locks-simpletrace.py new file mode 100755 index 0000000..a69ed5c --- /dev/null +++ b/scripts/analyse-locks-simpletrace.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Analyse lock events and +# +# Author: Alex Bennée +# + +import os +import simpletrace +import argparse +import numpy as np + +class MutexAnalyser(simpletrace.Analyzer): + "A simpletrace Analyser for checking locks." + + def __init__(self): + self.locks = 0 + self.locked = 0 + self.unlocks = 0 + self.mutex_records = {} + + def _get_mutex(self, mutex): + if not mutex in self.mutex_records: + self.mutex_records[mutex] = {"locks": 0, + "lock_time": 0, + "acquire_times": [], + "locked": 0, + "locked_time": 0, + "held_times": [], + "unlocked": 0} + + return self.mutex_records[mutex] + + def qemu_mutex_lock(self, timestamp, mutex, filename, line): + self.locks += 1 + rec = self._get_mutex(mutex) + rec["locks"] += 1 + rec["lock_time"] = timestamp[0] + rec["lock_loc"] = (filename, line) + + def qemu_mutex_locked(self, timestamp, mutex, filename, line): + self.locked += 1 + rec = self._get_mutex(mutex) + rec["locked"] += 1 + rec["locked_time"] = timestamp[0] + acquire_time = rec["locked_time"] - rec["lock_time"] + rec["locked_loc"] = (filename, line) + rec["acquire_times"].append(acquire_time) + + def qemu_mutex_unlock(self, timestamp, mutex, filename, line): + self.unlocks += 1 + rec = self._get_mutex(mutex) + rec["unlocked"] += 1 + held_time = timestamp[0] - rec["locked_time"] + rec["held_times"].append(held_time) + rec["unlock_loc"] = (filename, line) + + +def get_args(): + "Grab options" + parser = argparse.ArgumentParser() + parser.add_argument("--output", "-o", type=str, help="Render plot to file") + 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() + +if __name__ == '__main__': + args = get_args() + + # Gather data from the trace + analyser = MutexAnalyser() + simpletrace.process(args.events, args.tracefile, analyser) + + print ("Total locks: %d, locked: %d, unlocked: %d" % + (analyser.locks, analyser.locked, analyser.unlocks)) + + # Now dump the individual lock stats + for key, val in sorted(analyser.mutex_records.iteritems(), + key=lambda (k,v): v["locks"]): + print ("Lock: %#x locks: %d, locked: %d, unlocked: %d" % + (key, val["locks"], val["locked"], val["unlocked"])) + + acquire_times = np.array(val["acquire_times"]) + if len(acquire_times) > 0: + print (" Acquire Time: min:%d median:%d avg:%.2f max:%d" % + (acquire_times.min(), np.median(acquire_times), + acquire_times.mean(), acquire_times.max())) + + held_times = np.array(val["held_times"]) + if len(held_times) > 0: + print (" Held Time: min:%d median:%d avg:%.2f max:%d" % + (held_times.min(), np.median(held_times), + held_times.mean(), held_times.max())) + + # Check if any locks still held + if val["locks"] > val["locked"]: + print (" LOCK HELD (%s:%s)" % (val["locked_loc"])) + print (" BLOCKED (%s:%s)" % (val["lock_loc"]))