From: Mahmoud Mandour <ma.mandourr@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Mahmoud Mandour" <ma.mandourr@gmail.com>,
"Alex Bennée" <alex.bennee@linaro.org>
Subject: [PATCH v4 2/5] plugins/cache: Enable cache parameterization
Date: Wed, 23 Jun 2021 14:54:54 +0200 [thread overview]
Message-ID: <20210623125458.450462-3-ma.mandourr@gmail.com> (raw)
In-Reply-To: <20210623125458.450462-1-ma.mandourr@gmail.com>
Enabled configuring both icache and dcache parameters using plugin
parameters.
Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
---
contrib/plugins/cache.c | 47 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
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();
--
2.25.1
next prev parent reply other threads:[~2021-06-23 12:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-23 12:54 [PATCH v4 0/5] plugins: New TCG plugin for cache modelling Mahmoud Mandour
2021-06-23 12:54 ` [PATCH v4 1/5] plugins: Added a new cache modelling plugin Mahmoud Mandour
2021-06-23 12:54 ` Mahmoud Mandour [this message]
2021-06-23 12:54 ` [PATCH v4 3/5] plugins/cache: Added FIFO and LRU eviction policies Mahmoud Mandour
2021-06-23 12:54 ` [PATCH v4 4/5] docs/devel: Added cache plugin to the plugins docs Mahmoud Mandour
2021-06-23 14:00 ` Mahmoud Mandour
2021-06-28 5:38 ` [PATCH v5] " Mahmoud Mandour
2021-06-23 12:54 ` [PATCH v4 5/5] MAINTAINTERS: Added myself as a reviewer for TCG Plugins Mahmoud Mandour
2021-07-07 9:27 ` [PATCH v5] MAINTAINERS: " Mahmoud Mandour
2021-07-05 16:11 ` [PATCH v4 0/5] plugins: New TCG plugin for cache modelling Alex Bennée
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210623125458.450462-3-ma.mandourr@gmail.com \
--to=ma.mandourr@gmail.com \
--cc=alex.bennee@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).