From patchwork Tue Jan 16 14:17: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: 124730 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp1043294lje; Tue, 16 Jan 2018 07:04:19 -0800 (PST) X-Google-Smtp-Source: ACJfBot61834BtZ7U1YkzOyFfAJizQmI/lOaPVXPUjL9P+b9UxLmxlCPty/dQru1AAtQXE5zpwlk X-Received: by 10.37.130.77 with SMTP id d13mr4658141ybn.377.1516115059497; Tue, 16 Jan 2018 07:04:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516115059; cv=none; d=google.com; s=arc-20160816; b=qMB0tAQT/MGc2EBPeSHYdG5iCXe/0dOTf0BGha2A+b6JLRa5xqpEfmw8BuUXFsU0R0 06zSNaiZ8N3IcVj99ZMdjxlmyb1KtTwEptg+rGNo5Hh72xzrV+os+6v7a09y1E0BuwTT qXb8JO1mei4SMxBDmFv6nwhAW7YLH50fyCUl2yvag17G+GLVJl9Ymg7B9+qdvGpM61UX QA95ac4Vdn0lqxOb7aFffYrTgbkEZzN+9f1u9PnW5VnxuMHt5YFPooawCkxht5bHNNpu umvTrIoxnQq/ucWZxNLO8VTctnV32sEEPtZr2Ep8UCw1AuieDCARk3+UYkxbnFujUtdZ qmbA== 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=jQ0zev7HbBd4Se78/C004unL1JvTQkF6pSVZna7txHs=; b=A77CmhTDnsduwoqhqrIrt09jYQsSooOScZGV6JkWwU5Hx6GA6dqG6cT1H+fkHF4bq9 Ze0vbjzYMHbz5hnk85tGYP+j22SRWkHdr1xSLd97h4Q0AQ9yfQZ2YSt8ZzlOUGtJsFp1 eXn2l4bOdrAOFmHUAEC5CrbDHSvtD/ekE1H2iAjIfgcq5uKBSlh3UOiLDDy8URv5tioR C+Ay+3BVdkB0oCMw1WSe+NspmDuo1Ir2ctM0Iyz3Wwd/VPfRDdEqqDrwxbKB9EBwCtx/ BEReCSP5TrVjX/7dcE6BdE0ENETII7BvGyOL9s+/v33A1f+ovHxdV1NS15iGZfcDuVA/ UV0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=LZj1UfJ3; 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 i186si562840ybc.620.2018.01.16.07.04.18 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 16 Jan 2018 07:04:18 -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=LZj1UfJ3; 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]:39565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebSmf-0007x1-Pu for patch@linaro.org; Tue, 16 Jan 2018 10:04:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50600) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebS4J-0003IM-LM for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebS4G-00051y-Ao for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:27 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:45406) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ebS4G-000501-3o for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:24 -0500 Received: by mail-wr0-x241.google.com with SMTP id 16so15333055wry.12 for ; Tue, 16 Jan 2018 06:18:24 -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=jQ0zev7HbBd4Se78/C004unL1JvTQkF6pSVZna7txHs=; b=LZj1UfJ3Exnuh21rfgf0SmGxg0c1lMZmF/4LT3PHiGHQrRy4KXleIQdpWM+Nf3exqJ N+ElMqF3OVz5h3higYHCcBCmT6i49GJr3QyPUZjCITrYZYJf8uTEpwnaNz765IeEb5my 4Uf7A8ST9lz0BDyhAbLZ5GM1hR24aZ9I5pRTpXo4Vp9148YTAhQCx09jMVG680126yRC gX01GOhkE1EfybvM/QnwpmR/6h9dzAk7AtYBIg1QcYjvk/STDdcUUEpRsCyKBDJtNpPy Dd9xgCy5w86xPI+MFeB8XviO49GRt273K8G+iP5NPBzOXcFXwATAhR8kUUpl2YWVLdrX TI/w== 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=jQ0zev7HbBd4Se78/C004unL1JvTQkF6pSVZna7txHs=; b=aL1lInle1H77a1+V9k5xDb69pwgQztRpwcpfRkiHoo1O9dJ+yT/ALwtQnLaLnR44iF O1zGyFUSKX8Hqpnh32Szv9jpVa6i/2z6J0fBm6l3y4NwpaviQ+0ZYwhlGWdr0R/NL5Vt akuisCi9nIUpZPwqjJwYZ608wYesL/NKS1NBWwaDBC9BUvKlGYAN0tHI9dqHX1Z7fB7n x6BKcQ63Tf5ixEZ71SEi82/yxxEUoXmxFJRMI+WnaMlW3PX3Wc6quB3aKmvr/gns1485 lK5RxdNH+V9t/SZ8BeIR7AzDFWEf1nS6pHEQRDkZdxmmsunUYbnPoDbHMmTLO6l5eQV1 xUhw== X-Gm-Message-State: AKwxytcrNUD8QHeZgJ55CJmDehne4haq7Slxh8mypu0lHkVrbgzN9oQy KQQq8bhLRX8T8l540Et5lc5/73R3 X-Received: by 10.223.134.58 with SMTP id 55mr15229967wrv.262.1516112302793; Tue, 16 Jan 2018 06:18:22 -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 u10sm1537758wrg.6.2018.01.16.06.18.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jan 2018 06:18:21 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 15:17:15 +0100 Message-Id: <1516112253-14480-34-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516112253-14480-1-git-send-email-pbonzini@redhat.com> References: <1516112253-14480-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 33/51] 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..8c7f1d7 --- /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 Tue Jan 16 14:17: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: 124725 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp1041414lje; Tue, 16 Jan 2018 06:59:39 -0800 (PST) X-Google-Smtp-Source: ACJfBosxWRhl+FCrjI9be1zZsvkFJ1tjfc94qFybesik5qltAoCKBkf8APqHG4tAL+IaCq4Mdg62 X-Received: by 10.37.51.136 with SMTP id z130mr25766533ybz.445.1516114779506; Tue, 16 Jan 2018 06:59:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516114779; cv=none; d=google.com; s=arc-20160816; b=LKcrR+Vuf15rDGZf3i0mth85CFXsalwCoeT0SmA+Ugj+ub3tEfx9FK0e2HvDdzYM05 W1/TvHAB/jljYSFBNkKHMyOGpvPmIxbI4TZ+j1L0XGDGbywyPgGa97VpHX6WG0c9k96I wfG8KT2AOujva1CJvFmFQBilJepPv1XfT+uoGfbXl/eUFrX6C8PrGtj0pHhzg89KItQo xJzg04/gidIbN3p0PKHVrKOFJHc+EEYXiZQTC6E/G6/EmdBWCpM34ooqmZkAdk3zeN3/ 9zldU7foNz/deCvD3Jn7VH4wsmyFdjQUp/4p9p1K2mzlnAdThzyGAVOURUw7F2jCKKTe IlAQ== 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=nM5x7nn6gBUN79XLiJu7Jfxk/UEegVHCqc7JSXTe0hE=; b=tseHlqOtm//NcVSUdTXM9AOzi9C6NhhxFNugYLK28TvuvAP6N1RMDQ/cGVMvMy9kKT aapiwzQTagve/ibjZwftF4/xvJPwN9xibk5mZDA2G/ylYNPvc9xq9xPhGEVv+xZ7KPgi ahK1SWBfCYFfKhxP0jW+g8Bhr7VTSSoxrDqtLJSq0gRaU6UEZDSeBJ+LlrslvKawt6MM yNMx1wmTOgMXlSLajPbFYhcNS7nUPF4vfZ+vVfnVqAxDzLw4bflX6Qd7SSdO7IodPvQM hSE4cl6SgsKED6C1OSECqjgMIszGbW8wDN+Wia5xsj5M9llBwqINc1uIDK2lwqcbLQzM p3vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=rnYEapmb; 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 e11si540137ybk.263.2018.01.16.06.59.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 16 Jan 2018 06:59:39 -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=rnYEapmb; 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]:39470 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebSiA-0002jF-QO for patch@linaro.org; Tue, 16 Jan 2018 09:59:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebS4N-0003OK-Lv for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebS4H-00055n-Qz for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:31 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:44170) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ebS4H-00054A-JZ for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:25 -0500 Received: by mail-wm0-x241.google.com with SMTP id t74so8752398wme.3 for ; Tue, 16 Jan 2018 06:18:25 -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=nM5x7nn6gBUN79XLiJu7Jfxk/UEegVHCqc7JSXTe0hE=; b=rnYEapmb0GG+0d8XSTitKJMs3WekyyFozMTB4eJYzAIQ3i4s73XFkGeWWTd6IEKWeM /Saxg7o0z070A+Rf1UiwRWcSAX7hFQX4cn4D+AjYZk7RqaaVL+ASJu3Y0cXXbe6K7eoT vFnrdW8ac0vsBtiE9Z9P3imnGb6ji+ogWS+nUymaIkNQPOlOyds5djwaH0XejQMF2G0s fK+xzcTnR8U/m9M3us3SPrqxv9SFijxENmNKmOEznFLWBrJQbI1zFhLz8+ZyWM2Jy4bp HcBUvQQSVJt4epixTGLOsZShKaw+mqG5DpUz4pV6FvAL4WaGpYIRbNxQUokJA2SdTJ3m kG7w== 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=nM5x7nn6gBUN79XLiJu7Jfxk/UEegVHCqc7JSXTe0hE=; b=k2pWRd4g/kXZvBqICnlhdQMQsYsPh6FAWU1YlNesOfEawQgKOi5tEjrF0MmEfxRJkb kvME3gc0ZdQetuKuPDjAolcLwOpWijps+MJjF1vjORKfSxir+w6TNFUuoEumqFDAYk7e 5rla1OQktJIiTYQsD6xv1+F1n1RpLT0Zu6ZDscQ2A76q/n04iCQIyi3p3LK8oTy7ECSI Z4V1tv+xUTMXWOj7UoJq28lVLFS7tent/POK5tv93g6uO/6IozANg4b8nYs11sAk4nDN MDNwD2xy6F5WDo8FR4f8DOoxh/V6lrkG1U12pJ+Rcunrr7Z6YXxCwWeKZ3gjSvN9KxBr 1s7A== X-Gm-Message-State: AKwxytdHjlxjn3O/UCaEAzlmk1HWpjuUN88TBfkL6TGuhHRi3iqeqW92 ERaAz7Mxc/+XT38tWmZ+zlne72QQ X-Received: by 10.28.129.212 with SMTP id c203mr13009478wmd.98.1516112304252; Tue, 16 Jan 2018 06:18:24 -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 u10sm1537758wrg.6.2018.01.16.06.18.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jan 2018 06:18:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 15:17:16 +0100 Message-Id: <1516112253-14480-35-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516112253-14480-1-git-send-email-pbonzini@redhat.com> References: <1516112253-14480-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::241 Subject: [Qemu-devel] [PULL 34/51] 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..be71a00 --- /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 Tue Jan 16 14:17:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 124733 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp1044865lje; Tue, 16 Jan 2018 07:09:11 -0800 (PST) X-Google-Smtp-Source: ACJfBovvf4rrV4UaMxUHJih3InoYEUS6HfPaGaCSBfl8bIZwJiLeW03lOdMYNklM9KC6NC2M3yG3 X-Received: by 10.37.134.17 with SMTP id y17mr18667139ybk.307.1516115351675; Tue, 16 Jan 2018 07:09:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516115351; cv=none; d=google.com; s=arc-20160816; b=pbdcR0MRIayPpbaoxvN+4abriFqRildyiAW61g7WCyfcsqDZ7VuhRdBEh8FW1cMjmM eyA4f0jY6ODI2b8Vra1yC0M6OL1cjTBLmulax2mqGo3ZJYyZH7IB6EQBk5/JKYZMwZqQ SZ7VtKN5pCOR77hmHTy3HlTlN0yXz087EQLH2MDrvDl6/9QvFMRp8ko0tUxLNQ0TAFUM 5xg1o6eKWOo0txQzDNof22+0RH0M3q+xVR9SgqcN3B4E2WuoTFR1UFImlRyU3D0UDTeu 7RjZAllEflNsPCFEVds0L7Rb8DYDBgarIZSD/ASLUsLYswpkt6SRoL0s1kpkgtWfKJOb +Xjw== 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=y5SEfdW7ZC7mDkfXCjU7E1AGIp1r7bwJgmh5mQjTXh4XNWg8WoZKMivbsohvRoq1ZW 8YRr58FRLGx7nUkIU+G6k+Ri1SfhRvLhDUDnJn2QxfIOPSCxCuvrkR/JaUhxS0n7C/Qw 48NmQNq9D2L2PsimqKkRaDFXMMkegS8bZS/GV6jPY5NDll3KaOPy7BOnUXDOM4TA2UQ+ +u+1WPLdeq9FZLIfQb1F2SAlafWEHBWn3HavdDnPpC1t3tPKsrPR7Ho5dMH9X+/Xn1DK qrRl64mB0FZGOBuAVpS9qUOPwdLKcyQZ8xCS/PLM7191SLbVyxInKt2uVe3zl0ut+qGu LdPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=T4hzDXSi; 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 64si570012ybs.248.2018.01.16.07.09.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 16 Jan 2018 07:09:11 -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=T4hzDXSi; 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]:39615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebSrO-00032W-QB for patch@linaro.org; Tue, 16 Jan 2018 10:09:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51056) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebS4k-0003ky-NU for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebS4j-0005aD-De for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:54 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:42430) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ebS4j-0005Zc-4J for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:53 -0500 Received: by mail-wm0-x243.google.com with SMTP id b141so8774386wme.1 for ; Tue, 16 Jan 2018 06:18:53 -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=T4hzDXSilPiOMrLQL5TjgKyRhn9zDMByq/0OnhwfhhivCJvLcEKbUCoLzKkznvCgSm DP26VZEv2jEHlDVgzq1xuXIReblBalsA4stazqdpY7N5gx063IdZpN6S+bZMv1K9n+WB xWjsYWI3FZn3B61VPoyu+0aLbEwTHFWW1lqKY+FivCLfMVUOXQn236AQZ88JWAJFF4UZ RoPqSFAmunTvd1SAJ8ZA33jvD5+pVYfRSMa3uc3dnMyQZ+X+0Hu9Smvnr/AzGstvGFj0 WO4X6wUbVrjLTU7CKmb7YjX7Axzp9qpKhmWu3dYNl2P0VJ7g7v+iSEvfcTVh38SANtuW 90ZA== 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=BpLk05BpMpD/8+LGWeAkWp4Qx+CXrb/KVd1mqAQTlSLL9uASbjT55nDeI2h1JIf4+J Ln3/Jci741vztSE+++XZpRiM3NKmNY8q2gbJf0bX1M1xld5H3rWymQYpF792bpaMIPZT 1f/aQUm2T650PEPdBz/yIwIdKL6rP16aC9mYY0zXQqCYAyUHHWIrAmc2LCkJEXNogzOZ wkq9Za+ynx1OqinJYriv7PaanchkFMYlJhxfW9S+BnTJ64juHZ/kKW9T7vkW4uLnNgPa DsOYGqEP8WRrn/nZcBq4qwCUI56jYX2JOsuX/a6fTv0pi8Pm94YPjfFK13VW98chjyso TmYA== X-Gm-Message-State: AKwxytdC1+eKe6aPI085KCJkWwQutMowpXjC1fHn22+sN/hTl582mMHU hb34+edqPllN6j50OqbbPXUqcX/M X-Received: by 10.28.143.204 with SMTP id r195mr14099806wmd.51.1516112331684; Tue, 16 Jan 2018 06:18:51 -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 u10sm1537758wrg.6.2018.01.16.06.18.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jan 2018 06:18:50 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 15:17:32 +0100 Message-Id: <1516112253-14480-51-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516112253-14480-1-git-send-email-pbonzini@redhat.com> References: <1516112253-14480-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::243 Subject: [Qemu-devel] [PULL 50/51] 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 Tue Jan 16 14:17:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 124727 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp1042453lje; Tue, 16 Jan 2018 07:02:11 -0800 (PST) X-Google-Smtp-Source: ACJfBotgt5nhEFr0v5/zdc94XAntiAuA8un5t8ti+M99xlQU7JcVzVl+/nwguNPq8NPtBTiFjgJQ X-Received: by 10.37.161.201 with SMTP id a67mr5844132ybi.250.1516114931430; Tue, 16 Jan 2018 07:02:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516114931; cv=none; d=google.com; s=arc-20160816; b=A0yNWrGT2qxJHpTSBaSSq+uuZrZUROxWgdY3F1A/IkDCmEuaZf1teu94fdWXS5Optj Tr+koc8TNja3CNPtqmKvGHtUvBdD9f+CG6Aya2FMcbqKuG9cxDGqJ0EDmGyAsHBLHkn2 gq79vua3h1W5024WKu4HcwaY5b83UEbuGlAum/3R0rqvd8JoPsJ1C46MXprhxdSP320v saq5LRy+ZTm2QdfFDtql5a6tpGCFfDuITwpvzUAk36tpnaZ6GVK3vjwb6pAFtvdeh2IR kDA/PxDeSnVswqzSP9CRDDz4+OjUmriRGOZAHBmcGI60GCL56e8cyS6WQtNtql+xVK5p ZXcg== 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=XVXpTNERZuDfLChI1As/F3vkRhV3SxX66Rw2nV7mweQ=; b=wnTrStGXkmh0xDBebtgWWeI335h5xY4aEekp+SjOgvcAen3NbMDng9wEpNNsO2v/3O b9OMYT53NIUpIAEB4LFcwvevBDZJ0UpPDe0kxfRxYrn26PyiJIdAcTBAfNKjgJSNOc4q rUl9iGnTPKgQAtLElBLL6Alomr/Vz3K2l48kRLwTb7Jnt3Obtkqa+Av4V1/G5fpVJUEc TthKn0xi+dIgoJDMpMBu9RzyVkTzKwF/GCh1SD8G5vuAar/HH3VGB/ZxmSEX68SiDDCf 7CIH0ua84wlujH5kATtTh/nDxZW1sOrqMVCtTSAYHHWzPziYyuTqHwNITcP7/Gqyvxgs ySIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=CgqjTBV7; 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 67si523109ybh.375.2018.01.16.07.02.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 16 Jan 2018 07:02:11 -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=CgqjTBV7; 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]:39493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebSkc-0005Fs-Lt for patch@linaro.org; Tue, 16 Jan 2018 10:02:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebS4m-0003ma-8Y for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebS4l-0005bc-5p for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:56 -0500 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]:43932) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ebS4k-0005at-Sp for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:55 -0500 Received: by mail-wm0-x22b.google.com with SMTP id g1so8680182wmg.2 for ; Tue, 16 Jan 2018 06:18:54 -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=XVXpTNERZuDfLChI1As/F3vkRhV3SxX66Rw2nV7mweQ=; b=CgqjTBV7fSXrWaNcAw6gHWMpYypGtqVSiV9f/RqpHjsIBhes0aeMzuAZGBYcA09PrD gfZG7sVgl10jn1ObMX5sTPrhlF0YKKi62Luf9cMiFtA3D045uRZSfUI4LDwpwcQ7qsnu UqGObHg2Pd3XweLffo3d/T7qKcc+V0umEVQF6gFsM0g+4Ph/q/lqRcESLQiSRjdfx5Eh yPr0xBLdjnMFlqubqXuPZqjGng8t1OTpQW+RRPZ3C9dzR2dBPIrtDScy58Roeb3qeeYc 0INq3/GueLaqZUOQQGydbDNLFDXy+WTw05KFFn6cGk5CJ8q+oCA1x9GVFFNqBPYrZiRh LCRA== 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=XVXpTNERZuDfLChI1As/F3vkRhV3SxX66Rw2nV7mweQ=; b=sjZeOHSivcjDCw4GtIJVQYDaG2Rnx3C98rT/HNdxN1N0Swkq70OLorHnSgApEFTRR9 1CT+SSYUQwcf3mPTB6L63xEBuzhIWtrvBAXIThULXFLhSNbm0gUlgtjM18A2EtC9n8iF 7vtshLdxl64JoLKheychYBH3LSsAGAHOp3lsVugb9KCu9+ehHOrkrFfGJTfFosWTXI5t OiTsK+DXewYzEq3SPia1Gm9LMpPdh39oam7/5lyyfadyo+tRCIJOxZTKYX/bpQ50vYUh Ue5zJo92YQcTGxwvVWxgqItgcnhuH1rB+AzI4+mWP5TBdwg/f86INN4601+7kwyuXiNB xV4w== X-Gm-Message-State: AKwxytfChN/EFNdCe3WqD1AFEhOyArFktLu2GivwdC0r6UBOP+t/aut7 i3Dm6klH3nY6o+/UTVn/HmDazqb7 X-Received: by 10.28.148.150 with SMTP id w144mr13241278wmd.0.1516112333559; Tue, 16 Jan 2018 06:18:53 -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 u10sm1537758wrg.6.2018.01.16.06.18.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jan 2018 06:18:52 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 15:17:33 +0100 Message-Id: <1516112253-14480-52-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516112253-14480-1-git-send-email-pbonzini@redhat.com> References: <1516112253-14480-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::22b Subject: [Qemu-devel] [PULL 51/51] 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..101e84d --- /dev/null +++ b/scripts/analyse-locks-simpletrace.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Analyse lock events and compute statistics +# +# 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"]))