From nobody Fri Oct 10 18:13:39 2025 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 ARC-Seal: i=1; a=rsa-sha256; t=1623125370; cv=none; d=zohomail.com; s=zohoarc; b=Yf0oA+zrRriLYHjF1b4028QQ59qnjOvFWwvfeGvSi35Z614zk+65Pbh5mOmNlNWSSTe4CFUT0n7N+cD501tVDPEbVfOhTgbkY9YlnKwVWj7h/LrGckmmQ8NwDS3KnLhq8JfpsSX01IMKNgIlbo++AgCggzUJkFIcKdBou24XFo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623125370; 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=RVydF8W/6ZNYBMXe/l8al/gKrABRXvmDJUUWROof7X8=; b=iKbHZmV/hu/GpQYLTmF3F+FQzI5UcpxHdwFosN4T4SvRrMxA33EUmO0aV8s53poyTjuAxVI0xUJ6uLtqAl1pno5Sk+HB53dD86tylREcKtkNfaWTPIYOBlZduHR/KKJcvAb9Wmp4BAXhYqrT6xk5raIWxDabnqlvXSQKldhST2s= ARC-Authentication-Results: i=1; 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 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 1623125370537246.30971871385168; Mon, 7 Jun 2021 21:09:30 -0700 (PDT) Received: from localhost ([::1]:38042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqT3R-0006ag-EX for importer@patchew.org; Tue, 08 Jun 2021 00:09:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqT2F-0003tQ-9u for qemu-devel@nongnu.org; Tue, 08 Jun 2021 00:08:15 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:37672) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqT2B-0008Mc-Qp for qemu-devel@nongnu.org; Tue, 08 Jun 2021 00:08:15 -0400 Received: by mail-wr1-x435.google.com with SMTP id i94so14852788wri.4 for ; Mon, 07 Jun 2021 21:08:11 -0700 (PDT) Received: from localhost.localdomain ([197.61.123.212]) by smtp.gmail.com with ESMTPSA id y189sm16862008wmy.25.2021.06.07.21.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 21:08:10 -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=RVydF8W/6ZNYBMXe/l8al/gKrABRXvmDJUUWROof7X8=; b=EvDR+mNCh0kHyxqJyLQbtZjKltl6zfxnkmu1ErcSgQyFDgmtKd5+kJFEJySRj4jWh9 0i2QxHAqqOvJ5AZ7d0JdR3mTsqetg+dN3H7JHQKNstQT5rOThQVQ4zvJnIHceWO0dja/ cTMMveT3uo/vGuYfPSoG5r7CbTjdXteBhm4XWA3vl4fY+9OQ7I/29Ca19cvy7hLiUoD9 NHfhANR3utzm3trUfVGnByBTDzMKxaPplKgzUnPm7YlYh8kaynuUf3OzGRrz1fw2PYqg 48mteOowEtUyzsFiKGx+gJJ6E/1tghNYWQTFnz5v23NgHU7H48LMLONPkEdSm7FpK2Bu 0R9g== 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=RVydF8W/6ZNYBMXe/l8al/gKrABRXvmDJUUWROof7X8=; b=R5n2AKSI377VWTjxMKrFA5tLaNMBrxZ5uKU7g4z4ieIqejkWfjktU65EtC96xPlRPn RJxlUNKMBI6fevM3Yxr5EeHO+JtbxnLoP0eRBPeYnmF+2JZ7/4iaVVzVaMe6x4E44CsK VICZ0u0V6yySy4DJDYJFquCmFpvYDQl7aqwPllDLmLdbFEHftivw7Ut9RK01LbbyAi6H DyNB9ExBwEeUbLt6/haVvR6+XlTV5zK/wJbTNJZeLTxaOw7LL6PTf6UZWmM03pgxlTLI zu675WO+AEn3KhsuZeDBfYpCMy/GHrzlJ2DIa9n7iMtAVP+vQxG5ids+vJRxBMQPNeUY DuLw== X-Gm-Message-State: AOAM5334jzp51GOeUvKhdaAvCpVrCiq5bVSeMgEizKppOePFjsHIL25e r7Sb9dk7t4wO34F0fOM35UOhX42WHIibUw== X-Google-Smtp-Source: ABdhPJxh/JFJanrgKDvHjB0a+dkIHAGqkWSF+iosKsXmepzdM6hXhkzm0z3ywv20InusdHc3rQpVWQ== X-Received: by 2002:adf:c54b:: with SMTP id s11mr20478065wrf.349.1623125290341; Mon, 07 Jun 2021 21:08:10 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 3/4] plugins/cache: Enabled cache parameterization Date: Tue, 8 Jun 2021 06:05:31 +0200 Message-Id: <20210608040532.56449-4-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210608040532.56449-1-ma.mandourr@gmail.com> References: <20210608040532.56449-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::435; envelope-from=ma.mandourr@gmail.com; helo=mail-wr1-x435.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) Content-Type: text/plain; charset="utf-8" Made both icache and dcache configurable through plugin arguments. Signed-off-by: Mahmoud Mandour --- contrib/plugins/cache.c | 44 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c index 715e5443b0..d8e8c750b6 100644 --- a/contrib/plugins/cache.c +++ b/contrib/plugins/cache.c @@ -104,8 +104,17 @@ static inline uint64_t extract_set(struct Cache *cache= , uint64_t addr) return (addr & cache->set_mask) >> cache->blksize_shift; } =20 +static bool bad_cache_params(int blksize, int assoc, int cachesize) +{ + return (cachesize % blksize) !=3D 0 || (cachesize % (blksize * assoc) = !=3D 0); +} + static struct Cache *cache_init(int blksize, int assoc, int cachesize) { + if (bad_cache_params(blksize, assoc, cachesize)) { + return NULL; + } + struct Cache *cache; int i; uint64_t blk_mask; @@ -403,8 +412,30 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qem= u_info_t *info, =20 for (i =3D 0; i < argc; i++) { char *opt =3D argv[i]; - if (g_str_has_prefix(opt, "limit=3D")) { - limit =3D g_ascii_strtoull(opt + 6, NULL, 10); + if (g_str_has_prefix(opt, "I=3D")) { + gchar **toks =3D g_strsplit(opt + 2, " ", -1); + if (g_strv_length(toks) !=3D 3) { + g_strfreev(toks); + 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); + g_strfreev(toks); + } else if (g_str_has_prefix(opt, "D=3D")) { + gchar **toks =3D g_strsplit(opt + 2, " ", -1); + if (g_strv_length(toks) !=3D 3) { + g_strfreev(toks); + 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); + g_strfreev(toks); + } else if (g_str_has_prefix(opt, "limit=3D")) { + limit =3D g_ascii_strtoll(opt + 6, NULL, 10); } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; @@ -412,7 +443,16 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qem= u_info_t *info, } =20 dcache =3D cache_init(dblksize, dassoc, dcachesize); + if (!dcache) { + fprintf(stderr, "dcache cannot be constructed from given parameter= s\n"); + return -1; + } + icache =3D cache_init(iblksize, iassoc, icachesize); + if (!icache) { + fprintf(stderr, "icache cannot be constructed from given parameter= s\n"); + return -1; + } =20 qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); --=20 2.25.1