From patchwork Mon Jul 12 12:26:50 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: 473109 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp2910649jao; Mon, 12 Jul 2021 05:53:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLT9pPjh1WUhcVWCJLiDk1a4y0w5tsyKZgpTYAcWJFrLbjxkpYE93dIjbQLBky+0WrZkn+ X-Received: by 2002:ab0:24d3:: with SMTP id k19mr18181757uan.140.1626094386883; Mon, 12 Jul 2021 05:53:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626094386; cv=none; d=google.com; s=arc-20160816; b=pXJ04Be1UE6UzAEDWDGesrf3wYw2wD35ytM0FQ2YgPwANdI6n8etuAlQSJ3T62FdUX 8bjtwTkJ1s+eaAygyUSxSB0GBgxK+b5cRIfbkvDceRow6SOxhMW0/VitzXf3k8HLfb/r FgLnxIETjHoCyF+rf1jdylQQiKClWl38ZmYKQzYnWRKzl7dNNxV7LdXrM446m+VX8T7J 6tZ2yTbF0XWvjp9Q4RJMD79XhP87vyDlZSLvzqc8ch+qQkGUFA8R3UG+UTvyqxA637xs A5saU9UpAQNQjFGVxUY88j9GduRjghGIhzmHqA5TFMPyWw3S+XPxlcWvhbPoYw+zb41s uHwA== 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=4RUje/NtLDQsjrm5Fp/QYjd0g9AvH8bzaEhpNLm1Wos=; b=FpqVYqEu5bHPALnvGb4V6u7oLhNTECJRpJuiwlPLUtpv2wY1X/lsiVcnU4kiQ39SpZ 3yPiGZJObIg2u5dwTsRVayrbvqIZ3HIR3xgFr/hkCZsoSpxT7NPOTp8xoCVmGcLX1bBK XW0yjUpGL8T7dCAjhwh2mPT/RWI1u5My+eZ34KU8oNoEQoBmCAGc9JsYQBTQEh/f7otZ rs+x6x19xnaAuHWXWRfX4NUwNdzzmngYu9Ccok8gZtegXG3V1PmqogvFApNOwJuajV/+ tMrJ9pYamlP7RENs9jJNQNtXRloCPkNl1YqrJwXus4/7UM2clZOenr65Mzn9YjvBxZz6 ZR6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="l5Bl/l8b"; 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 l7si972966vsh.374.2021.07.12.05.53.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Jul 2021 05:53:06 -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="l5Bl/l8b"; 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]:57456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m2vQo-0007fY-78 for patch@linaro.org; Mon, 12 Jul 2021 08:53:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2v7R-0004xb-65 for qemu-devel@nongnu.org; Mon, 12 Jul 2021 08:33:05 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:35395) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m2v7O-0002LZ-Km for qemu-devel@nongnu.org; Mon, 12 Jul 2021 08:33:04 -0400 Received: by mail-wm1-x32f.google.com with SMTP id j25-20020a05600c1c19b02902269686f585so1107268wms.0 for ; Mon, 12 Jul 2021 05:33:02 -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=4RUje/NtLDQsjrm5Fp/QYjd0g9AvH8bzaEhpNLm1Wos=; b=l5Bl/l8bfm9CtcRNnat71enRKXTOBf4T0RgfBeo9ygzU0EfdVJrx0dK7EBrtMXoPi8 l2nrIbxmmu1TDfwGmCiFbNUl67SLQUay4gZVj25h9Ajl6OmSJ16uBrDiJ7CoC897G2Bb Q6U0lt6tCtYQuVtkzXEtbYsLvCikzEUWPOsC1xoURXCEYM2AuAW4xiIpoQvbkqCoSVlj Vm95ZN1CYv66iQGn8by/ccIHULYzjTvJ4uCz8+3NfDCAJx0VaED3uvmj+FPbiGs2Qw6M e8jDxXvJEfZ7s3i12i7TN5fWjhVcW8dKTR6KYouF5NET/ZYpAeVWRhzSLq2FezJX6JcI rz0g== 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=4RUje/NtLDQsjrm5Fp/QYjd0g9AvH8bzaEhpNLm1Wos=; b=CiviOy8iPxGYem1qapkohaqsqkLpgUNTWYqxlVL99I5GSwmAcpC7AetcC1UngH59Iq UCVsmYM5QVHy9oz+ziRZYPhG7nBn7WoknSZQETa3Uw8kx5FidPteW8suG08a+qhfPGQ9 vjOfpT4EcrPHT0QDCApHK+ZSIV4oqrOUpWUwdkz1lfTsMNahD++TR5ZYvQdnt5nrn1wH 22TYDL4SwnWj8b/mVJepBkLIpWsB5E3vPpSYY6g9Jy5kpV77TP1j/8vKMqvx499kb3gR IVVgfvBLC9H2ZE8NnXpS6Q+NxzTHZMZvkakjLCKIj26LLkRvl7AaX7rgleVii7qggzOc TbSw== X-Gm-Message-State: AOAM532mHK2vDa07zea4uDAfnGhsHGJXk2gJc6+BKnhKuY4TVmeWajCP yvhs97eE5AzMgqpcyCzhWHdRig== X-Received: by 2002:a7b:c113:: with SMTP id w19mr14345673wmi.44.1626093181392; Mon, 12 Jul 2021 05:33:01 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id j10sm14003254wrt.35.2021.07.12.05.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 05:32:56 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B25D91FFBF; Mon, 12 Jul 2021 13:26:57 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 37/40] plugins/cache: Enable cache parameterization Date: Mon, 12 Jul 2021 13:26:50 +0100 Message-Id: <20210712122653.11354-38-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210712122653.11354-1-alex.bennee@linaro.org> References: <20210712122653.11354-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32f.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: Alexandre Iooss , Mahmoud Mandour , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org 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> Message-Id: <20210709143005.1554-38-alex.bennee@linaro.org> -- 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();