From nobody Mon Feb 9 01:20:12 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1622356918; cv=none; d=zohomail.com; s=zohoarc; b=E2Y8ZCQ/idjti5yDra+t3fU033KvEduBPsb6rVUGRQILgdkdOZ9VLsdnJ9G08XBM+toUBU70M3Q+9A2+bY9iPbhtTNtYhz4/jDspr4pTgG07c17gVEVGxGV6LI5OTLTHwcEtM8UiojM6UsjNZKq51+2I+pL9WMwXJipkejdg+98= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622356918; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yJpEnBBLwnL7hxOOCxZgHivdNATscGG91R17yNlKa78=; b=cnDDeF3vB7DT72aGJyi1lLGBcl9AEvMeaIbXPaUVmaaGHaZSgyYwigvRDi3otudvHOzIx59m3ez8CXqivRRkhDUbgJo+BF+qp0e4b1cmd38nCzKMJpkTbN7WorVR7S2mLbSA+2wqTU8WRdJkYZnxZMYdN96juHgtK31NCFQ07Xg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622356918242568.0517054468211; Sat, 29 May 2021 23:41:58 -0700 (PDT) Received: from localhost ([::1]:38870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnF93-0001Jf-7F for importer@patchew.org; Sun, 30 May 2021 02:41:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnF4l-00044X-8O for qemu-devel@nongnu.org; Sun, 30 May 2021 02:37:32 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:52002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnF4i-0003Er-7L for qemu-devel@nongnu.org; Sun, 30 May 2021 02:37:31 -0400 Received: by mail-wm1-x333.google.com with SMTP id r13so3879092wmq.1 for ; Sat, 29 May 2021 23:37:27 -0700 (PDT) Received: from localhost.localdomain ([102.44.10.239]) by smtp.gmail.com with ESMTPSA id 3sm2732431wmi.7.2021.05.29.23.37.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 May 2021 23:37: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=yJpEnBBLwnL7hxOOCxZgHivdNATscGG91R17yNlKa78=; b=UDmPuqq0dZQV84kkkC1JbsJkiR7rHK0Dvw3yba9mVGJOB9Vid6CqOHm7+nujPvHIOR XEuvmRvol0f6aZBDc3Zg8XnruDpjb2HmVYKab9ZWyzVMwmm/4m2TaqUoEypY2jMpJxKA 3x0nj0nqEc8qxXE751hBKMD/rdjsA/DO7YDiMTQLpSMDaP1fr1PeA0h0N0StwgrCb0sK 4Nu4gAivQVob4K7iS9EShwxJGSPU5LTVuokSWJV4dqYOmF0LC19Syo8t93zLrw7trf/O 9v5wHJEgbIa696S5ZtEMbv0642cYdSugINa2rBqdEEP/7dx9bv4XpxRWQWGWNOdFJVu7 IH5g== 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=yJpEnBBLwnL7hxOOCxZgHivdNATscGG91R17yNlKa78=; b=SMHmt9otdRKtcBjzDEc4xgjivHHSNajuQiaPwAMFm6KBLiN4K8Uv1++vmnSua7Eb1Q HnmDhOkslnF9Nh31rPh2bCKtTnTfhDcjA3pmpfUV/YzMtcp5wqtp/Oklpl7caqzecSik bY1IaRJBoWB74CAJ6y6T3wAHj+g13Ef+aVNfafcVcykK4PhjGQgLYtojiTYH6YtGsvK+ RlRCOlmQ0XEOGb2bHcG7dVa4u9A6pB25W6avxxibZZiBPlVNQT0bzQBmmjElGFOwryt8 M7yXzYjrQV99YhhrlOAuhopcLDUJsoPEi1xsi8C8hp6NrKAmREaPiJ4yYuXZww76FH1F Y7KQ== X-Gm-Message-State: AOAM5339tXm39uLYj5DzylAE5oUAS9YcrSMS3XI7hZHSVP7JzP8XE9x5 dUkJKtysTo0EC7cJYrD5AYG6fIN93YaBhA== X-Google-Smtp-Source: ABdhPJyBZAr0qtj2vivIfRPcoEeWbRzGdST+BiuQIdP7ob9c512uyGSRYvBW/mUjqTjtNIdYZHLS/w== X-Received: by 2002:a7b:c207:: with SMTP id x7mr8416712wmi.42.1622356646560; Sat, 29 May 2021 23:37:26 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 2/3] plugins: cache: Enabled parameterization and added trace printing Date: Sun, 30 May 2021 08:37:11 +0200 Message-Id: <20210530063712.6832-3-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210530063712.6832-1-ma.mandourr@gmail.com> References: <20210530063712.6832-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::333; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x333.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 , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Type: text/plain; charset="utf-8" Made both icache and dcache configurable through plugin arguments and added memory trace printing in a separate file. Signed-off-by: Mahmoud Mandour --- contrib/plugins/cache.c | 68 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c index 8c9d1dd538..fa0bf1dd40 100644 --- a/contrib/plugins/cache.c +++ b/contrib/plugins/cache.c @@ -22,7 +22,7 @@ static GRand *rng; static GHashTable *dmiss_ht; static GHashTable *imiss_ht; =20 -static GMutex dmtx, imtx; +static GMutex dmtx, imtx, fmtx; =20 static int limit; static bool sys; @@ -33,6 +33,8 @@ static uint64_t dmisses; static uint64_t imem_accesses; static uint64_t imisses; =20 +FILE *tracefile; + static enum qemu_plugin_mem_rw rw =3D QEMU_PLUGIN_MEM_RW; =20 enum AccessResult { @@ -205,6 +207,16 @@ static void vcpu_mem_access(unsigned int cpu_index, qe= mu_plugin_meminfo_t info, insn_addr =3D ((struct InsnData *) userdata)->addr; effective_addr =3D hwaddr ? qemu_plugin_hwaddr_phys_addr(hwaddr) : vad= dr; =20 + if (tracefile) { + g_mutex_lock(&fmtx); + g_autoptr(GString) rep =3D g_string_new(""); + bool is_store =3D qemu_plugin_mem_is_store(info); + g_string_append_printf(rep, "%c: 0x%" PRIx64, + is_store ? 'S' : 'L', effective_addr); + fprintf(tracefile, "%s\n", rep->str); + g_mutex_unlock(&fmtx); + } + if (access_cache(dcache, effective_addr) =3D=3D MISS) { struct InsnData *insn =3D get_or_create(dmiss_ht, userdata, insn_a= ddr); insn->misses++; @@ -221,11 +233,20 @@ static void vcpu_insn_exec(unsigned int vcpu_index, v= oid *userdata) g_mutex_lock(&imtx); addr =3D ((struct InsnData *) userdata)->addr; =20 + if (tracefile) { + g_mutex_lock(&fmtx); + g_autoptr(GString) rep =3D g_string_new(""); + g_string_append_printf(rep, "I: 0x%" PRIx64, addr); + fprintf(tracefile, "%s\n", rep->str); + g_mutex_unlock(&fmtx); + } + if (access_cache(icache, addr) =3D=3D MISS) { struct InsnData *insn =3D get_or_create(imiss_ht, userdata, addr); insn->misses++; imisses++; } + imem_accesses++; g_mutex_unlock(&imtx); } @@ -352,6 +373,15 @@ static void plugin_exit() =20 g_mutex_unlock(&dmtx); g_mutex_unlock(&imtx); + + if (tracefile) { + fclose(tracefile); + } +} + +static bool bad_cache_params(int blksize, int assoc, int cachesize) +{ + return (cachesize % blksize) !=3D 0 || (cachesize % (blksize * assoc) = !=3D 0); } =20 QEMU_PLUGIN_EXPORT @@ -377,14 +407,48 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qe= mu_info_t *info, =20 for (i =3D 0; i < argc; i++) { char *opt =3D argv[i]; - if (g_str_has_prefix(opt, "limit=3D")) { + if (g_str_has_prefix(opt, "I=3D")) { + gchar **toks =3D g_strsplit(opt + 2, " ", -1); + if (g_strv_length(toks) !=3D 3) { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + icachesize =3D g_ascii_strtoull(toks[0], NULL, 10); + iassoc =3D g_ascii_strtoull(toks[1], NULL, 10); + iblksize =3D g_ascii_strtoull(toks[2], NULL, 10); + } else if (g_str_has_prefix(opt, "D=3D")) { + gchar **toks =3D g_strsplit(opt + 2, " ", -1); + if (g_strv_length(toks) !=3D 3) { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + dcachesize =3D g_ascii_strtoull(toks[0], NULL, 10); + dassoc =3D g_ascii_strtoull(toks[1], NULL, 10); + dblksize =3D g_ascii_strtoull(toks[2], NULL, 10); + } else if (g_str_has_prefix(opt, "limit=3D")) { limit =3D g_ascii_strtoull(opt + 6, NULL, 10); + } else if (g_str_has_prefix(opt, "tracefile=3D")) { + char *file_name =3D opt + 10; + tracefile =3D fopen(file_name, "w"); + if (!tracefile) { + fprintf(stderr, "could not open: %s for writing\n", file_n= ame); + } } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; } } =20 + if (bad_cache_params(iblksize, iassoc, icachesize)) { + fprintf(stderr, "icache cannot be constructed from given parameter= s\n"); + return -1; + } + + if (bad_cache_params(dblksize, dassoc, dcachesize)) { + fprintf(stderr, "dcache cannot be constructed from given parameter= s\n"); + return -1; + } + dcache =3D cache_init(dblksize, dassoc, dcachesize); icache =3D cache_init(iblksize, iassoc, icachesize); =20 --=20 2.25.1