From nobody Fri May 3 12:26:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626283637633251.84359443406618; Wed, 14 Jul 2021 10:27:17 -0700 (PDT) Received: from localhost ([::1]:52834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3ifE-00024R-IZ for importer@patchew.org; Wed, 14 Jul 2021 13:27:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3idU-0008NB-DE for qemu-devel@nongnu.org; Wed, 14 Jul 2021 13:25:28 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:40550) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3idP-0005dR-Hk for qemu-devel@nongnu.org; Wed, 14 Jul 2021 13:25:28 -0400 Received: by mail-wm1-x334.google.com with SMTP id f8-20020a1c1f080000b029022d4c6cfc37so3081278wmf.5 for ; Wed, 14 Jul 2021 10:25:23 -0700 (PDT) Received: from localhost.localdomain ([102.41.175.227]) by smtp.gmail.com with ESMTPSA id l18sm6434393wme.29.2021.07.14.10.25.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 10:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WnusAEAyfZfbEUVNFaz2SidIzioGK97iFgSAymrfuw8=; b=h79E14m8AkzaudlYkN/EqOip6NbTl7HX4Yl0rCHXLGTrQDJYDuPyQ55dExS5IhrRyj Smern6yuZFdLdQQnEtOiFJQ8LRxToeCEtlSeJFus0Na+ugATlBZnJ0+7tt3ycERCgmgW SUodca4Q50z4Q06pujL0EY+k2HXEx2dOE1YtsdoV9nS08A3weKWh/z7jiYnA4uHxnYeL Q6IHXJzsdA7xX1099IjAY1Ue40T/pT5+bBQIWa8VCAu2TAOAn2/xtXgFzC88/yPZi0ll rWa6UYBi+mx8ZOdnW55BgPbGe9RfFT7RdyMI7Iw9t9fr92siFn6fD9RPwND0R44Rs9nL 5Sdg== 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=WnusAEAyfZfbEUVNFaz2SidIzioGK97iFgSAymrfuw8=; b=ntBuTWDMD0GH55FaSP248FqALPXsnp9AU4mGBsNTXkHKNkygVLWXaSuhbRs8Jnjh5m 9LWzv5PB25nn5dH48vAgZuUWSk71tcfvcSbbgyAfkNB25WN2M6xiQlNxX8LgfQWRMT4d qrWqJ7DKigjcqJcmPzkAtHEMSN6t4YvLs1Zy3ltSIa7us4XY2qmJsgoC5cn+FTpxQBXT HYp1iCfh/fLFDzJ0mtrUMrquMtaiAi/vGHulYzAukprRo+0mrmta3wjQwFwLSP8tThhl S2AtFTC2mVq4uDQFc3UMt6e5zXjhXg6AbS00/sKoxx4WPUHSmHvLQy7jKRqczESqRe24 KbDA== X-Gm-Message-State: AOAM533VvHtX5CdpQBhV6W+xM8mD4LwzwpzwO1SDwxl9x6jCWAEXvJcO N/RuNgOa5el1OsuGKUBvGaUm4GssxIeopg== X-Google-Smtp-Source: ABdhPJwEH3ZNE/vfGsYoYvM6/UHV2/3YA2WbyGn8cnnxUgenipXBKkdv+WUK1omVknbtYRN8kQMHdQ== X-Received: by 2002:a1c:1d8e:: with SMTP id d136mr12427234wmd.52.1626283521800; Wed, 14 Jul 2021 10:25:21 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 1/6] plugins/cache: Fixed a bug with destroying FIFO metadata Date: Wed, 14 Jul 2021 19:21:47 +0200 Message-Id: <20210714172151.8494-2-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210714172151.8494-1-ma.mandourr@gmail.com> References: <20210714172151.8494-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x334.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour , cota@braap.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626283639421100001 Content-Type: text/plain; charset="utf-8" This manifests itself when associativity degree is greater than the number of sets and FIFO is used, otherwise it's also a memory leak whenever FIFO was used. Signed-off-by: Mahmoud Mandour Reviewed-by: Alex Benn=C3=A9e --- contrib/plugins/cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c index bf0d2f6097..4a71602639 100644 --- a/contrib/plugins/cache.c +++ b/contrib/plugins/cache.c @@ -200,7 +200,7 @@ static void fifo_destroy(Cache *cache) { int i; =20 - for (i =3D 0; i < cache->assoc; i++) { + for (i =3D 0; i < cache->num_sets; i++) { g_queue_free(cache->sets[i].fifo_queue); } } --=20 2.25.1 From nobody Fri May 3 12:26:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626283638204470.35866580136496; Wed, 14 Jul 2021 10:27:18 -0700 (PDT) Received: from localhost ([::1]:52920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3ifF-00027r-76 for importer@patchew.org; Wed, 14 Jul 2021 13:27:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3idW-0008O2-9X for qemu-devel@nongnu.org; Wed, 14 Jul 2021 13:25:30 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:40552) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3idT-0005fs-Fh for qemu-devel@nongnu.org; Wed, 14 Jul 2021 13:25:29 -0400 Received: by mail-wm1-x336.google.com with SMTP id f8-20020a1c1f080000b029022d4c6cfc37so3081334wmf.5 for ; Wed, 14 Jul 2021 10:25:24 -0700 (PDT) Received: from localhost.localdomain ([102.41.175.227]) by smtp.gmail.com with ESMTPSA id l18sm6434393wme.29.2021.07.14.10.25.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 10:25:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rk3htMMb3bfqB/M3qyqhgxhOXapf/D+thLXQN5K9iqg=; b=EmVbtbh0r2Us2q671BS2liiGmzxXC3pMcVhUTGLlpT+fIsO2hCO8uVFyiShsE0bdoP 3gJjLpEkSGooH0v4pjccq+ySE0RY9LKJJsj+Lf8XPDK18WsIZ/8aOFqTO/SPE76qtnkB k08vIr+N9vIVVpLBHQ8gPmqNBc9o3VodC8EGCaxD5UaPJncGGI2zpfXHwk9FmD+rfes4 LbIKL+EuDsJP2Gr7kDOfvg0dob0dWJif4RDBWBoq+9ly6ReY8DkueW9n7Cz5YykUjAiK KDfRmyig/On6n0kYLmzA/SWwu/cFtp6ObBkvvld3Yk3wwVs4zt7xRqrMviMyfqKUPxhh 9kIA== 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=Rk3htMMb3bfqB/M3qyqhgxhOXapf/D+thLXQN5K9iqg=; b=oyL93+E5JC8eu3LpFv+PlbJcoxJRQ2OQv3dbCPB04NoYYIAuE+l4RL13XiDrqWmYzv CxenVTTmuYDsVoWzjQSIVdG9/I8GDPrdQEf3ESekbv9OYh1XbvF8FTp6JKr4Y1uIyf5w hPvPOOTzCOg5dnhIiYjHqtJtTAKLNA9rSXo70QvVRz3gR0l4rFUn9oghlLW1/0ckyL4D XzyNuh7F5BGGB4bcTlXJ5Cpu+dgFnTnOsCTIG1AdG0cxEb1llHqOwm2xgWocwZVfyYLF YueqUwiazKib+MTUg1XOnmHlrISlMqhlB7Sxqvc/RCEqClUVNHdCWVYFpQdGHG7Bt0qZ 9r0w== X-Gm-Message-State: AOAM530cnnp4RIjGaEcr65/7RGM98SgTiW4vtem4upNEAzaIKC/RMCVC mqR2zQvqT+KqalYEiEUSSQNZg3JVwigokQ== X-Google-Smtp-Source: ABdhPJw1xmuO/7mb4MIw8aZSU6/iHTLoL9xbg/Eey1kPSi1Dg1UfEF5RE8HnBU+jcSoMfOeTlW4fxg== X-Received: by 2002:a1c:f70b:: with SMTP id v11mr12516820wmh.186.1626283523387; Wed, 14 Jul 2021 10:25:23 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 2/6] plugins/cache: limited the scope of a mutex lock Date: Wed, 14 Jul 2021 19:21:48 +0200 Message-Id: <20210714172151.8494-3-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210714172151.8494-1-ma.mandourr@gmail.com> References: <20210714172151.8494-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour , cota@braap.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626283639425100002 Content-Type: text/plain; charset="utf-8" It's not necessary to lock the address translation portion of the vcpu_mem_access callback. Signed-off-by: Mahmoud Mandour Reviewed-by: Alex Benn=C3=A9e --- contrib/plugins/cache.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c index 4a71602639..695fb969dc 100644 --- a/contrib/plugins/cache.c +++ b/contrib/plugins/cache.c @@ -355,15 +355,14 @@ static void vcpu_mem_access(unsigned int vcpu_index, = qemu_plugin_meminfo_t info, struct qemu_plugin_hwaddr *hwaddr; InsnData *insn; =20 - g_mutex_lock(&mtx); hwaddr =3D qemu_plugin_get_hwaddr(info, vaddr); if (hwaddr && qemu_plugin_hwaddr_is_io(hwaddr)) { - g_mutex_unlock(&mtx); return; } =20 effective_addr =3D hwaddr ? qemu_plugin_hwaddr_phys_addr(hwaddr) : vad= dr; =20 + g_mutex_lock(&mtx); if (!access_cache(dcache, effective_addr)) { insn =3D (InsnData *) userdata; insn->dmisses++; --=20 2.25.1 From nobody Fri May 3 12:26:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626283639151995.7700929461473; Wed, 14 Jul 2021 10:27:19 -0700 (PDT) Received: from localhost ([::1]:52954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3ifG-00029A-4G for importer@patchew.org; Wed, 14 Jul 2021 13:27:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3idV-0008NL-Bt for qemu-devel@nongnu.org; Wed, 14 Jul 2021 13:25:29 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:53094) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3idT-0005gT-Fg for qemu-devel@nongnu.org; Wed, 14 Jul 2021 13:25:29 -0400 Received: by mail-wm1-x32e.google.com with SMTP id g12so2084311wme.2 for ; Wed, 14 Jul 2021 10:25:26 -0700 (PDT) Received: from localhost.localdomain ([102.41.175.227]) by smtp.gmail.com with ESMTPSA id l18sm6434393wme.29.2021.07.14.10.25.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 10:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SukRF58NpvmPFNZKWh62vrFHgotopGXPTaY3xAEaGPA=; b=SlMvXQnVk3E5DeBXgGz4jRYbNs+T+qGAswdVnjTG73+0XZcA8ShAJt/7/Ke7OCIkWh QloZhBzVnF17o4mmI5tto11JeRNdNIhlHbajiPT1FC2FCCmB4q65CnK9j7ZdCdC9ZGgS uKtCN74PTEulfA7xJ+K9wighkuh2L6jgBYAunLB4BwjpBkbmafEUALmGSj5ejmRIH9bl q6gplcWwJjEJXVbu09z08uH5MdGDp+GrUgUZzmgBjtujzSLYH0Z/5yj3xB5WbHmMcEJe R3rcQyCW1eCw5CfXtLHvKfzDaTiLS+HesNMyoIRitziHWTrHEz75746XxfHr/bnnAyQO EvZA== 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=SukRF58NpvmPFNZKWh62vrFHgotopGXPTaY3xAEaGPA=; b=MxiVsnxtRMTMImD830UK1gzNA85CXZdyMAZsN3ACRqIgIExEfM3Qj0nReWGcDHZclk KIivOYhJ65ymKzS9ZBkCxjKuMFi7xZAiodMuGnsXNBRBNZBkZKzS5eBX1kjTxP17m5iW 393IsFSbDXVAzgcz299HyOz/9ONM6W5VgwywUp87ILJtt3bJHiRG5x0T67EtDPWw4fKP BUPTaz+81LjxvviSwAlTFSVd3GpAtvDFFO/xYsAVJNAaNVR5oN5lNfd8uvoL/tSfMmd4 3zOu4zcbISVqDGXgAWpWUxrhUsI9GrNELyvr9zCU2ttVIwivKvFSuGez8nnypLP3TsVU Oe0w== X-Gm-Message-State: AOAM5317Br9CkL70Rz0IotwI65t4QxqzndN2/D//jvAkRoLYqPpaBcvA l4+9adphcsI96Payrj3p7q3EiHdrEwimig== X-Google-Smtp-Source: ABdhPJwLyEhr7IdtAkf8eHNgxtdlBRIEfV2k11WwtlQF5XCqxm+tddY1SRI7pNLxdttqGMdi71i3Fw== X-Received: by 2002:a1c:3c8a:: with SMTP id j132mr6611619wma.5.1626283524858; Wed, 14 Jul 2021 10:25:24 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 3/6] plugins/cache: Fixed a use-after-free bug with multithreaded usermode Date: Wed, 14 Jul 2021 19:21:49 +0200 Message-Id: <20210714172151.8494-4-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210714172151.8494-1-ma.mandourr@gmail.com> References: <20210714172151.8494-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour , cota@braap.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626283641257100005 Content-Type: text/plain; charset="utf-8" Since callbacks may be interleaved because of multithreaded execution, we should not make assumptions about `plugin_exit` either. The problem with `plugin_exit` is that it frees shared data structures (caches and `miss_ht` hash table). It should not be assumed that callbacks will not be called after it and hence use already-freed data structures. This is mitigated in this commit by synchronizing the call to `plugin_exit` through locking to ensure execlusive access to data structures, and NULL-ifying those data structures so that subsequent callbacks can check whether the data strucutres are freed, and if so, immediately exit. It's okay to immediately exit and don't account for those callbacks since they won't be accounted for anyway since `plugin_exit` is already called once and reported the statistics. Signed-off-by: Mahmoud Mandour --- contrib/plugins/cache.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c index 695fb969dc..a452aba01c 100644 --- a/contrib/plugins/cache.c +++ b/contrib/plugins/cache.c @@ -363,6 +363,11 @@ static void vcpu_mem_access(unsigned int vcpu_index, q= emu_plugin_meminfo_t info, effective_addr =3D hwaddr ? qemu_plugin_hwaddr_phys_addr(hwaddr) : vad= dr; =20 g_mutex_lock(&mtx); + if (dcache =3D=3D NULL) { + g_mutex_unlock(&mtx); + return; + } + if (!access_cache(dcache, effective_addr)) { insn =3D (InsnData *) userdata; insn->dmisses++; @@ -380,6 +385,11 @@ static void vcpu_insn_exec(unsigned int vcpu_index, vo= id *userdata) g_mutex_lock(&mtx); insn_addr =3D ((InsnData *) userdata)->addr; =20 + if (icache =3D=3D NULL) { + g_mutex_unlock(&mtx); + return; + } + if (!access_cache(icache, insn_addr)) { insn =3D (InsnData *) userdata; insn->imisses++; @@ -406,12 +416,24 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct= qemu_plugin_tb *tb) effective_addr =3D (uint64_t) qemu_plugin_insn_vaddr(insn); } =20 + g_mutex_lock(&mtx); + + /* + * is the plugin_exit callback called? If so, any further callback + * registration is useless as it won't get accounted for after cal= ling + * plugin_exit once already, and also will use miss_ht after it's = freed + */ + if (miss_ht =3D=3D NULL) { + g_mutex_unlock(&mtx); + return; + } + /* * Instructions might get translated multiple times, we do not cre= ate * new entries for those instructions. Instead, we fetch the same * entry from the hash table and register it for the callback agai= n. */ - g_mutex_lock(&mtx); + data =3D g_hash_table_lookup(miss_ht, GUINT_TO_POINTER(effective_a= ddr)); if (data =3D=3D NULL) { data =3D g_new0(InsnData, 1); @@ -527,13 +549,20 @@ static void log_top_insns() =20 static void plugin_exit(qemu_plugin_id_t id, void *p) { + g_mutex_lock(&mtx); log_stats(); log_top_insns(); =20 cache_free(dcache); + dcache =3D NULL; + cache_free(icache); + icache =3D NULL; =20 g_hash_table_destroy(miss_ht); + miss_ht =3D NULL; + + g_mutex_unlock(&mtx); } =20 static void policy_init() --=20 2.25.1 From nobody Fri May 3 12:26:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626283724614788.1778110943852; Wed, 14 Jul 2021 10:28:44 -0700 (PDT) Received: from localhost ([::1]:58366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3igd-0005mo-FR for importer@patchew.org; Wed, 14 Jul 2021 13:28:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3idX-0008QK-TP for qemu-devel@nongnu.org; Wed, 14 Jul 2021 13:25:31 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:39778) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3idT-0005gf-Qz for qemu-devel@nongnu.org; Wed, 14 Jul 2021 13:25:31 -0400 Received: by mail-wm1-x32e.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso4384639wmh.4 for ; Wed, 14 Jul 2021 10:25:27 -0700 (PDT) Received: from localhost.localdomain ([102.41.175.227]) by smtp.gmail.com with ESMTPSA id l18sm6434393wme.29.2021.07.14.10.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 10:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l38aQRI2rzDIqUMZhp7jHSxY2lEYFMkxgCQ8I8cOe7U=; b=neMUOFKaj4sxujSoWpzocTq4FGS2bkC5p1SkrhZe/5ut+q7x7zqh3Mui2JDX21YYxE m0phcKWTpznSQVRxp78lBsOexyq3w7MKNevtu8ifeUc6U0cCUAM8Ov/z8dklFfVoXaqB MU4g/n0YtULe14Rr9aT18scUKlzVzVFZLDgX1+0U0j48syHBiMx2369q7E+eSIIxDvYA 8TAJuZHe1TcMsAMQsElamhwNCENGs5HJrraoS9mgISlRnucsDsPztR62noMVgbZzI7oc iDXkNWHSgoKjIMopWyZrCCWkx7awvu2KVdfQVsgbZdKgth6hI3c50fQmTwnLzy3v8wg1 P6BA== 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=l38aQRI2rzDIqUMZhp7jHSxY2lEYFMkxgCQ8I8cOe7U=; b=jfthbs4xZxi/ds+hpK47cA4VjB6jk6UAzTXjMuxqex0qk78Wnb8TqsDFi8GBT8l/6X d1cD4XPjWH9NMdOzPyEzMW3XRdExjYkqsYSC5NFVUIeV4J7SGiNqoKakEcplTu+ELH4D hWwLDXvewEG8KwWcGsNqpoyIU0UAUTCdZsZwWUHUA688OfdQ+Xk0VYzJeI7hPgn9HNW/ vekntQCw7E+ZdK33o4zPYK1SE5NRiyyQP0WF3OUuL3hG0N+0uWp66dJRhZGGRL+UdEWa GuKdBWd9pXBfDce0rWTfjkQtH/e8iF+/mNm66wlpd0TX4YMu0DWmYyaMCo9xv2ZpFn1H MuVw== X-Gm-Message-State: AOAM533E+HgrmRmf39dz3r8FVJuvLWpnD4HtkbCI5bTv9tvrLezx8P8w fT4IPOuJnEt3dKhJDKRSe4G9Lh9H+RgDvg== X-Google-Smtp-Source: ABdhPJx+7DDrNaypMKJjy3cSk2gIkkIb8q8GxmrYtXMzoCd5x7pcQBu10HCM5RVx2WJAstbr0xM4qQ== X-Received: by 2002:a1c:9d8f:: with SMTP id g137mr5183227wme.13.1626283526385; Wed, 14 Jul 2021 10:25:26 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 4/6] plugins/cache: Supported multicore cache modelling Date: Wed, 14 Jul 2021 19:21:50 +0200 Message-Id: <20210714172151.8494-5-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210714172151.8494-1-ma.mandourr@gmail.com> References: <20210714172151.8494-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour , cota@braap.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626283726934100002 Content-Type: text/plain; charset="utf-8" Multicore L1 cache modelling is introduced and is supported for both full system emulation and linux-user. For full-system emulation, L1 icache and dcache are maintained for each available core, since this information is exposed to the plugin through `qemu_plugin_n_vcpus()`. For linux-user, a static number of cores is assumed (default 1 core, and can be provided as a plugin argument `cores=3DN`). Every memory access goes through one of these caches, this approach is taken as it's somewhat akin to what happens on real setup, where a program that dispatches more threads than the available cores, they'll thrash each other Signed-off-by: Mahmoud Mandour --- contrib/plugins/cache.c | 156 ++++++++++++++++++++++++++++++---------- 1 file changed, 117 insertions(+), 39 deletions(-) diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c index a452aba01c..60f7be208b 100644 --- a/contrib/plugins/cache.c +++ b/contrib/plugins/cache.c @@ -23,11 +23,6 @@ static GRand *rng; static int limit; static bool sys; =20 -static uint64_t dmem_accesses; -static uint64_t dmisses; - -static uint64_t imem_accesses; -static uint64_t imisses; =20 enum EvictionPolicy { LRU, @@ -90,13 +85,22 @@ typedef struct { uint64_t imisses; } InsnData; =20 +typedef struct { + uint64_t dmem_accesses; + uint64_t dmisses; + uint64_t imem_accesses; + uint64_t imisses; +} CoreStats; + void (*update_hit)(Cache *cache, int set, int blk); void (*update_miss)(Cache *cache, int set, int blk); =20 void (*metadata_init)(Cache *cache); void (*metadata_destroy)(Cache *cache); =20 -Cache *dcache, *icache; +static int cores; +CoreStats *stats; +Cache **dcaches, **icaches; =20 static int pow_of_two(int num) { @@ -233,10 +237,6 @@ static bool bad_cache_params(int blksize, int assoc, i= nt cachesize) =20 static Cache *cache_init(int blksize, int assoc, int cachesize) { - if (bad_cache_params(blksize, assoc, cachesize)) { - return NULL; - } - Cache *cache; int i; uint64_t blk_mask; @@ -263,6 +263,24 @@ static Cache *cache_init(int blksize, int assoc, int c= achesize) return cache; } =20 +static Cache **caches_init(int blksize, int assoc, int cachesize) +{ + Cache **caches; + int i; + + if (bad_cache_params(blksize, assoc, cachesize)) { + return NULL; + } + + caches =3D g_new(Cache *, cores); + + for (i =3D 0; i < cores; i++) { + caches[i] =3D cache_init(blksize, assoc, cachesize); + } + + return caches; +} + static int get_invalid_block(Cache *cache, uint64_t set) { int i; @@ -353,6 +371,7 @@ static void vcpu_mem_access(unsigned int vcpu_index, qe= mu_plugin_meminfo_t info, { uint64_t effective_addr; struct qemu_plugin_hwaddr *hwaddr; + int cache_idx; InsnData *insn; =20 hwaddr =3D qemu_plugin_get_hwaddr(info, vaddr); @@ -363,17 +382,24 @@ static void vcpu_mem_access(unsigned int vcpu_index, = qemu_plugin_meminfo_t info, effective_addr =3D hwaddr ? qemu_plugin_hwaddr_phys_addr(hwaddr) : vad= dr; =20 g_mutex_lock(&mtx); - if (dcache =3D=3D NULL) { + cache_idx =3D vcpu_index % cores; + if (dcaches[cache_idx] =3D=3D NULL) { g_mutex_unlock(&mtx); return; } =20 - if (!access_cache(dcache, effective_addr)) { + if (!access_cache(dcaches[cache_idx], effective_addr)) { insn =3D (InsnData *) userdata; insn->dmisses++; - dmisses++; + if (cores > 1) { + stats[cores].dmisses++; + } + stats[cache_idx].dmisses++; + } + if (cores > 1) { + stats[cores].dmem_accesses++; } - dmem_accesses++; + stats[cache_idx].dmem_accesses++; g_mutex_unlock(&mtx); } =20 @@ -381,21 +407,29 @@ static void vcpu_insn_exec(unsigned int vcpu_index, v= oid *userdata) { uint64_t insn_addr; InsnData *insn; + uint64_t cache_idx; =20 g_mutex_lock(&mtx); insn_addr =3D ((InsnData *) userdata)->addr; =20 - if (icache =3D=3D NULL) { + cache_idx =3D vcpu_index % cores; + if (icaches[cache_idx] =3D=3D NULL) { g_mutex_unlock(&mtx); return; } =20 - if (!access_cache(icache, insn_addr)) { + if (!access_cache(icaches[cache_idx], insn_addr)) { insn =3D (InsnData *) userdata; insn->imisses++; - imisses++; + if (cores > 1) { + stats[cores].imisses++; + } + stats[cache_idx].imisses++; } - imem_accesses++; + if (cores > 1) { + stats[cores].imem_accesses++; + } + stats[cache_idx].imem_accesses++; g_mutex_unlock(&mtx); } =20 @@ -475,6 +509,22 @@ static void cache_free(Cache *cache) g_free(cache); } =20 +/* + * caches_free(): free an array of Cache structs. + * @caches: caches to free + * + * Calling cache_free for each cache in @caches, and then NULL-ify them so= that + * we mark them as freed, other async callbacks can check to see whether a= cache + * is freed already or not by checking against NULL. + */ +static void caches_free(Cache **caches) +{ + for (int i =3D 0; i < cores; i++) { + cache_free(caches[i]); + caches[i] =3D NULL; + } +} + static int dcmp(gconstpointer a, gconstpointer b) { InsnData *insn_a =3D (InsnData *) a; @@ -493,19 +543,38 @@ static int icmp(gconstpointer a, gconstpointer b) =20 static void log_stats() { - g_autoptr(GString) rep =3D g_string_new(""); - g_string_append_printf(rep, - "Data accesses: %lu, Misses: %lu\nMiss rate: %lf%%\n\n", - dmem_accesses, - dmisses, - ((double) dmisses / (double) dmem_accesses) * 100.0); - - g_string_append_printf(rep, - "Instruction accesses: %lu, Misses: %lu\nMiss rate: %lf%%\n\n", - imem_accesses, - imisses, - ((double) imisses / (double) imem_accesses) * 100.0); + int i, iters; + CoreStats cs; + double dmiss_rate, imiss_rate; + + g_autoptr(GString) rep =3D g_string_new("core #, data accesses, data m= isses," + " dmiss rate, insn accesses," + " insn misses, imiss rate\n"); + + /* Only iterate and print a sum row if cores > 1 */ + iters =3D cores =3D=3D 1 ? 1 : cores + 1; + for (i =3D 0; i < iters; i++) { + cs =3D stats[i]; + dmiss_rate =3D ((double) cs.dmisses) / (cs.dmem_accesses) * 100.0; + imiss_rate =3D ((double) cs.imisses) / (cs.imem_accesses) * 100.0; + + if (i =3D=3D cores) { + g_string_append_printf(rep, "%-8s", "sum"); + } else { + g_string_append_printf(rep, "%-8d", i); + } + + g_string_append_printf(rep, "%-14lu %-12lu %9.4lf%% %-14lu %-12lu" + " %9.4lf%%\n", + cs.dmem_accesses, + cs.dmisses, + cs.dmem_accesses ? dmiss_rate : 0.0, + cs.imem_accesses, + cs.imisses, + cs.imem_accesses ? imiss_rate : 0.0); + } =20 + g_string_append(rep, "\n"); qemu_plugin_outs(rep->str); } =20 @@ -553,15 +622,14 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) log_stats(); log_top_insns(); =20 - cache_free(dcache); - dcache =3D NULL; - - cache_free(icache); - icache =3D NULL; + caches_free(dcaches); + caches_free(icaches); =20 g_hash_table_destroy(miss_ht); miss_ht =3D NULL; =20 + g_free(stats); + g_mutex_unlock(&mtx); } =20 @@ -608,6 +676,8 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu= _info_t *info, =20 policy =3D LRU; =20 + cores =3D sys ? qemu_plugin_n_vcpus() : 1; + for (i =3D 0; i < argc; i++) { char *opt =3D argv[i]; if (g_str_has_prefix(opt, "iblksize=3D")) { @@ -624,6 +694,8 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu= _info_t *info, dcachesize =3D g_ascii_strtoll(opt + 11, NULL, 10); } else if (g_str_has_prefix(opt, "limit=3D")) { limit =3D g_ascii_strtoll(opt + 6, NULL, 10); + } else if (g_str_has_prefix(opt, "cores=3D")) { + cores =3D g_ascii_strtoll(opt + 6, NULL, 10); } else if (g_str_has_prefix(opt, "evict=3D")) { gchar *p =3D opt + 6; if (g_strcmp0(p, "rand") =3D=3D 0) { @@ -644,22 +716,28 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qe= mu_info_t *info, =20 policy_init(); =20 - dcache =3D cache_init(dblksize, dassoc, dcachesize); - if (!dcache) { + dcaches =3D caches_init(dblksize, dassoc, dcachesize); + if (!dcaches) { const char *err =3D cache_config_error(dblksize, dassoc, dcachesiz= e); fprintf(stderr, "dcache cannot be constructed from given parameter= s\n"); fprintf(stderr, "%s\n", err); return -1; } =20 - icache =3D cache_init(iblksize, iassoc, icachesize); - if (!icache) { + icaches =3D caches_init(iblksize, iassoc, icachesize); + if (!icaches) { const char *err =3D cache_config_error(iblksize, iassoc, icachesiz= e); fprintf(stderr, "icache cannot be constructed from given parameter= s\n"); fprintf(stderr, "%s\n", err); return -1; } =20 + /* + * plus one to save the sum in. If only one core is used then no need = to + * get an auxiliary struct. + */ + stats =3D g_new0(CoreStats, cores =3D=3D 1 ? 1 : cores + 1); + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); =20 --=20 2.25.1 From nobody Fri May 3 12:26:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626283724768677.1086298903322; Wed, 14 Jul 2021 10:28:44 -0700 (PDT) Received: from localhost ([::1]:58432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3igd-0005pN-Oz for importer@patchew.org; Wed, 14 Jul 2021 13:28:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3idW-0008Oj-Ox for qemu-devel@nongnu.org; Wed, 14 Jul 2021 13:25:30 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:41488) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3idV-0005hr-9F for qemu-devel@nongnu.org; Wed, 14 Jul 2021 13:25:30 -0400 Received: by mail-wm1-x336.google.com with SMTP id a5-20020a7bc1c50000b02901e3bbe0939bso1962183wmj.0 for ; Wed, 14 Jul 2021 10:25:28 -0700 (PDT) Received: from localhost.localdomain ([102.41.175.227]) by smtp.gmail.com with ESMTPSA id l18sm6434393wme.29.2021.07.14.10.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 10:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jcYcrXSu+KqlQ/6QrGFdUV6rCUe9Kbh1qvz/TUIqCys=; b=gHiJmZ0V0T4FyGzjyh+GYXbsTnUi6dFa+GD35KyQc9kb5ER5DHmK6M8QHGpNOX1eIH /UmUOwG8IlfrjCKbOppD0UEOKuQ/oO5YPIAqXltwBJrV0uwQTO7Sxmsi9lF3k/GNrf8j VdRpkjUhptMrAAMTqIWfyEysUL8meP+tcEk3t+qMXs80IGaqxCttzps26GfkU/GnfTA/ vfkvqilCJPVmHQqoue6q7rXXU8ngc5LuSxPM8MV0of4evqV3EfQ0UOxzdkxJs4IS9rB4 b2jgHmW/sHsI+wiCJUyUr7iI9cwVFmusSEaDw9UGIjZFHWfbq0V9Jd8Xcl5Sm6V8gLe2 KY8g== 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=jcYcrXSu+KqlQ/6QrGFdUV6rCUe9Kbh1qvz/TUIqCys=; b=LAOmUC+RldKjuBuzT4fWWxfUu3Ng5z/V17/Fx5tZe7hkzNIS7uXs1BNp1OKe2NscNt QpZ3ukwepnOeGehkiWd/2COHnTuqNbU2/kdw84BQAkZA9uNiymbwhRw7YQI92swcnPS5 TqSzdc7ogmS2YOva5DJGYnNScHiLYDwhRbC0OLRJnxCWYNkZUoqhZ1LUzHJicERW39o8 31jE7vBvUjUeTJ8ytdF98AwZOd9TyMHKm6zjQwiYME26paX8HQjMgHj7DubXE3yYuwy4 XZFARuXro4hNOHuH9I0XQXtJyRxqTjphudK8MJ/+FF7jWAfb6eijuU+6tSJerHsGW3/M br0A== X-Gm-Message-State: AOAM531oKaUHbEn8G7rSfUYE2hx6H9s498tXP/rUv3Rm2SiivEA0FiSD 9NfUXxuE4VwDfguUjLD9WAv7jwZjPSPiGw== X-Google-Smtp-Source: ABdhPJwTygRiSwFZOD/UFdaLLZOCa9HwqFcYy+Jzfc2Zy8+g0WVmBHHfRXrIWgdFwLjie9QxMDLHAQ== X-Received: by 2002:a1c:2142:: with SMTP id h63mr12753967wmh.84.1626283527752; Wed, 14 Jul 2021 10:25:27 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 5/6] docs/devel/tcg-plugins: added cores arg to cache plugin Date: Wed, 14 Jul 2021 19:21:51 +0200 Message-Id: <20210714172151.8494-6-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210714172151.8494-1-ma.mandourr@gmail.com> References: <20210714172151.8494-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour , cota@braap.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626283726905100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mahmoud Mandour --- docs/devel/tcg-plugins.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst index 595b8e0ea4..370c11373f 100644 --- a/docs/devel/tcg-plugins.rst +++ b/docs/devel/tcg-plugins.rst @@ -330,11 +330,8 @@ configuration when a given working set is run:: =20 will report the following:: =20 - Data accesses: 996479, Misses: 507 - Miss rate: 0.050879% - - Instruction accesses: 2641737, Misses: 18617 - Miss rate: 0.704726% + core #, data accesses, data misses, dmiss rate, insn accesses, insn mi= sses, imiss rate + 0 996695 508 0.0510% 2642799 18617 = 0.7044% =20 address, data misses, instruction 0x424f1e (_int_malloc), 109, movq %rax, 8(%rcx) @@ -378,3 +375,9 @@ The plugin has a number of arguments, all of them are o= ptional: Sets the eviction policy to POLICY. Available policies are: :code:`lru`, :code:`fifo`, and :code:`rand`. The plugin will use the specified policy= for both instruction and data caches. (default: POLICY =3D :code:`lru`) + + * arg=3D"cores=3DN" + + Sets the number of cores for which we maintain separate icache and dcach= e. + (default: for linux-user, N =3D 1, for full system emulation: N =3D cores + available to guest) --=20 2.25.1 From nobody Fri May 3 12:26:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626283786788941.5498728561919; Wed, 14 Jul 2021 10:29:46 -0700 (PDT) Received: from localhost ([::1]:33726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3ihd-0008C3-Ld for importer@patchew.org; Wed, 14 Jul 2021 13:29:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3idc-0008S4-Df for qemu-devel@nongnu.org; Wed, 14 Jul 2021 13:25:40 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:53097) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3idW-0005jk-T9 for qemu-devel@nongnu.org; Wed, 14 Jul 2021 13:25:34 -0400 Received: by mail-wm1-x331.google.com with SMTP id g12so2084437wme.2 for ; Wed, 14 Jul 2021 10:25:30 -0700 (PDT) Received: from localhost.localdomain ([102.41.175.227]) by smtp.gmail.com with ESMTPSA id l18sm6434393wme.29.2021.07.14.10.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 10:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/MgSxNTXj24fmsVtKLZKGMUSHi7S+elrSni9PhwS8No=; b=Ild5PhSy4FIQvEheWdayucZkih6yFYrmi8Xy8NEkIk0egsavgSXuQjo/Mk9yy5bUYg JmtcFY7vMjWmWpwyM0ExXlS3jIFfYj1WVuGjpx833g+X94TcgRekdwORKlspXG7fDhrw 7ZxNbTVuW7l9sPa4YI8gq0A87FKdqDZ6kf4FJiFzyhaKT3Kgn+kw6fojMdAsDGuex6sA Gfgi8P2G33k4mBeCMNTvn28bKpR6LADlwTfFp2LeWbiRcOYbosjEmRfOXbIB9TL97kwW 419NimGZLj8PU4qrZ6mpDlYP0u8fnIoDQt4Nanc1qzWynpyXI3s/AnOHnxwZUtS42hvG qdXA== 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=/MgSxNTXj24fmsVtKLZKGMUSHi7S+elrSni9PhwS8No=; b=aD0GsyEosp7OR0HBuZ0nxsjJ/BSHmc4bTw8a/Wq+LQszMVZrrkh84Ja+9He9HXWmA/ WZ3HPILX8AAhQe2hBUWSzPLq09/F3eFxff9hZvg8T+uIevZnF2Mvuq8Fix3yabGukCWI Ub95+zIlx1lq5WVV84reW6hb8LjcamifNPZrB8RRstZAbCo66HRHOKeKgsbt4EckJMRk TdgfafUfKi/Owh3fsTUlMKt4hUJB2X0FqVj+LP0zxFkVLyr85lNNt3SbMGwDkjavFxeg 3+Jv66/+Wd4jOs/UV7PG8V6t8XyJnEegg1StsHVTTjDxg6YEcf+0dv9EqPl+Ibze4bxZ 9/LQ== X-Gm-Message-State: AOAM531hSwmoF+kRQgUFXrCSyV3PLoZWVO56PvVZ0ac1Ulo/Zz3HvZr4 Mc+83cBw1AxLqC6f7LeKtekN85tomk0NZw== X-Google-Smtp-Source: ABdhPJx+tYkda9XkMF9q5uybC6XHoaKJB/yahIkm9lha77NhfRYEvZvfMZwplJOXRaDk6cPhx4QqAg== X-Received: by 2002:a05:600c:1d11:: with SMTP id l17mr12534006wms.169.1626283529202; Wed, 14 Jul 2021 10:25:29 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 6/6] plugins/cache: Fixed "function decl. is not a prototype" warnings Date: Wed, 14 Jul 2021 19:21:52 +0200 Message-Id: <20210714172151.8494-7-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210714172151.8494-1-ma.mandourr@gmail.com> References: <20210714172151.8494-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x331.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour , cota@braap.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626283787876100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mahmoud Mandour Reviewed-by: Alex Benn=C3=A9e --- contrib/plugins/cache.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c index 60f7be208b..f82a8310dc 100644 --- a/contrib/plugins/cache.c +++ b/contrib/plugins/cache.c @@ -541,7 +541,7 @@ static int icmp(gconstpointer a, gconstpointer b) return insn_a->imisses < insn_b->imisses ? 1 : -1; } =20 -static void log_stats() +static void log_stats(void) { int i, iters; CoreStats cs; @@ -578,7 +578,7 @@ static void log_stats() qemu_plugin_outs(rep->str); } =20 -static void log_top_insns() +static void log_top_insns(void) { int i; GList *curr, *miss_insns; @@ -633,7 +633,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) g_mutex_unlock(&mtx); } =20 -static void policy_init() +static void policy_init(void) { switch (policy) { case LRU: --=20 2.25.1