From patchwork Tue Jul 6 14:58:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 470483 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp5111638jao; Tue, 6 Jul 2021 08:33:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUry9Y6HAMBDAd0Qis66Bj5p+pYgBtlxzPPRkBAUklPVXSEDkf0JZtLXVk1UbT/XOnaz4g X-Received: by 2002:a05:6402:1a48:: with SMTP id bf8mr7027978edb.201.1625585599997; Tue, 06 Jul 2021 08:33:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625585599; cv=none; d=google.com; s=arc-20160816; b=QLgf7Bm5WbcNb3ftU1Mpd0EgljoJvaVoaCCqH1n8UX1vyoygsTWDL11To2/DXhmET+ yZSqzCRGLBNTYICKps99PQnIfzRhYZUmzkc8biyuJgnZhWotFjWt4rbLeQ4cVlUupzJd XBOjB2PQovg98aha+0PCcD+j+IdtyXFIVaPV8iXwlmwArUyBwMt/KfsULKZy7q5l+MXb E+i7An6nAH9ySzyqvbepzprlMIXJQ7PrxLy5SStWPxOJUSCva/slNk1ocG000YpUsiV2 7nhAYFK05MGMgv00+Yc88wgAGE+F0dH50QK1pr7RVOHB9lePfdqubYJjDpp28q1rRRYL OOVQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=eT5up0kian05/LgF6zUXsmuwoQua1u5bvZFkNOmLsvE=; b=ghrVoOPVpFyftjjNZ87yQ5ncOsXw4113IDb5EXBho/yW3dsK3UGA36BQCZCzzur/OQ MQruA3J7HzmHCPB9TyPnmy2qsWiUlTvk++4/7rI1lRVG12vN0LyZKxyx4BWqsvCxKSwj IFhHM9QxCYSugcjFKFtNNZKmc/3+Zl4vuzTnsTZMJoJdjMaafblkWGjIl9ad7j7wWP6/ Pr6TB5W4SPKcsQa4Gjcd6Alz/13puXve0OmlxLop7UyKxLi+0zQOC0ecV5hfbgnKOm5q NvtrsAuB95REC7OZOL4BwcMBMMjbkfg0qTaMVigpw73Uq6faClpvu1ir0LJqtcIgrqu2 cmtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=z2ZmcB7I; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b1si18758985ejb.152.2021.07.06.08.33.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 08:33:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=z2ZmcB7I; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0n4Y-0004Dk-VH for patch@linaro.org; Tue, 06 Jul 2021 11:33:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0mfP-0005ZS-8s for qemu-devel@nongnu.org; Tue, 06 Jul 2021 11:07:20 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:50848) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0mfM-0007Ft-8K for qemu-devel@nongnu.org; Tue, 06 Jul 2021 11:07:19 -0400 Received: by mail-wm1-x32a.google.com with SMTP id o22so13830354wms.0 for ; Tue, 06 Jul 2021 08:07:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eT5up0kian05/LgF6zUXsmuwoQua1u5bvZFkNOmLsvE=; b=z2ZmcB7IOrkvFSNxrJM/15GqzpZkc1FyaEBmUdHnLjEZa/wBZ5ENUvlxM1gQPbKk0T fMGIvScz+av4k60qcWhGhQrI3OM2GJEO9br2/evaIJhgDoB9UQ1BVIE9sbIeW6kgFOWC GdhutuP4PbHSBfHn8i7m0DmCtAehpZjX2+Vdz+W77AHm7DFvv2BkmZN9C/tid+VvB+u8 QPqfDUc5OwYpmMAEBP/ENMKVOVSbiYw4o1TIsnFrs0L1scRtIK38CJxoWjOHltNOmEpA zaUHQXN0V4UcoApF8iBdwGwgpvasBYVSe6ozbcB5REGLnZOzX1FUCZOWRqkOgdJJ40ZA bVcw== 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=eT5up0kian05/LgF6zUXsmuwoQua1u5bvZFkNOmLsvE=; b=e4cSBHuOUBzSA21QQAz37y5EzMQ8rfgDwQ4M5Z6A+Qm9EargBqTiKgaA2cmpLopR6S vgkfY+oYx8uviIJ3euuEKqL2twc2MF0lcCiZFu/hOnS2TkWNe8wAMlt0o+KeCA9r13vD KnZEYaCG2Tu83OOWs9ZutWB6hn7P+r44368IURIrY7N3IrOj9kbWYe90527IwvEJQLjT DtC2oTQna7USNVE+j9goAarPZ7+TZyphM+Wp/zf0jUaCYFtnu/02xHVXq+J4gl4dzm2T QvrwtJ7OUlaogMlA/pr9XoPpBi19yCnVUtFoQAfFc9v4qo3lolmKSyrteBwphM38+Kiy 1sww== X-Gm-Message-State: AOAM532J2MdM2eyO7yWcXc6n33yimQp7UQNUclzSg9NVpL02Eb0UliFL OgnxNJh1d501+CwQJAbSvT7NQQ== X-Received: by 2002:a1c:4e0b:: with SMTP id g11mr1273600wmh.167.1625584033697; Tue, 06 Jul 2021 08:07:13 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id n2sm11546551wrx.40.2021.07.06.08.07.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 08:07:12 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A03541FFBD; Tue, 6 Jul 2021 15:58:21 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 36/39] plugins/cache: Enable cache parameterization Date: Tue, 6 Jul 2021 15:58:14 +0100 Message-Id: <20210706145817.24109-37-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210706145817.24109-1-alex.bennee@linaro.org> References: <20210706145817.24109-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.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, 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: fam@euphon.net, berrange@redhat.com, f4bug@amsat.org, stefanha@redhat.com, crosa@redhat.com, pbonzini@redhat.com, Mahmoud Mandour , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , aurelien@aurel32.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Mahmoud Mandour Enabled configuring both icache and dcache parameters using plugin parameters. Signed-off-by: Mahmoud Mandour Signed-off-by: Alex Bennée Message-Id: <20210623125458.450462-3-ma.mandourr@gmail.com> --- contrib/plugins/cache.c | 47 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) -- 2.20.1 diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c index e9955cdc3a..b550ef31b0 100644 --- a/contrib/plugins/cache.c +++ b/contrib/plugins/cache.c @@ -99,8 +99,28 @@ static inline uint64_t extract_set(Cache *cache, uint64_t addr) return (addr & cache->set_mask) >> cache->blksize_shift; } +static const char *cache_config_error(int blksize, int assoc, int cachesize) +{ + if (cachesize % blksize != 0) { + return "cache size must be divisible by block size"; + } else if (cachesize % (blksize * assoc) != 0) { + return "cache size must be divisible by set size (assoc * block size)"; + } else { + return NULL; + } +} + +static bool bad_cache_params(int blksize, int assoc, int cachesize) +{ + return (cachesize % blksize) != 0 || (cachesize % (blksize * assoc) != 0); +} + 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; @@ -397,7 +417,19 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, for (i = 0; i < argc; i++) { char *opt = argv[i]; - if (g_str_has_prefix(opt, "limit=")) { + if (g_str_has_prefix(opt, "iblksize=")) { + iblksize = g_ascii_strtoll(opt + 9, NULL, 10); + } else if (g_str_has_prefix(opt, "iassoc=")) { + iassoc = g_ascii_strtoll(opt + 7, NULL, 10); + } else if (g_str_has_prefix(opt, "icachesize=")) { + icachesize = g_ascii_strtoll(opt + 11, NULL, 10); + } else if (g_str_has_prefix(opt, "dblksize=")) { + dblksize = g_ascii_strtoll(opt + 9, NULL, 10); + } else if (g_str_has_prefix(opt, "dassoc=")) { + dassoc = g_ascii_strtoll(opt + 7, NULL, 10); + } else if (g_str_has_prefix(opt, "dcachesize=")) { + dcachesize = g_ascii_strtoll(opt + 11, NULL, 10); + } else if (g_str_has_prefix(opt, "limit=")) { limit = g_ascii_strtoll(opt + 6, NULL, 10); } else { fprintf(stderr, "option parsing failed: %s\n", opt); @@ -406,7 +438,20 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, } dcache = cache_init(dblksize, dassoc, dcachesize); + if (!dcache) { + const char *err = cache_config_error(dblksize, dassoc, dcachesize); + fprintf(stderr, "dcache cannot be constructed from given parameters\n"); + fprintf(stderr, "%s\n", err); + return -1; + } + icache = cache_init(iblksize, iassoc, icachesize); + if (!icache) { + const char *err = cache_config_error(iblksize, iassoc, icachesize); + fprintf(stderr, "icache cannot be constructed from given parameters\n"); + fprintf(stderr, "%s\n", err); + return -1; + } rng = g_rand_new();