cache.c (14f3110a99d4edf683c6b503ca02dba09a124aff) cache.c (53366adf9c0c6b00ec54ff3074037c82995c7ed0)
1/*
2 * Copyright (C) 2021, Mahmoud Mandour <ma.mandourr@gmail.com>
3 *
4 * License: GNU GPL, version 2 or later.
5 * See the COPYING file in the top-level directory.
6 */
7
8#include <inttypes.h>
9#include <stdio.h>
10#include <glib.h>
11
12#include <qemu-plugin.h>
13
1/*
2 * Copyright (C) 2021, Mahmoud Mandour <ma.mandourr@gmail.com>
3 *
4 * License: GNU GPL, version 2 or later.
5 * See the COPYING file in the top-level directory.
6 */
7
8#include <inttypes.h>
9#include <stdio.h>
10#include <glib.h>
11
12#include <qemu-plugin.h>
13
14#define STRTOLL(x) g_ascii_strtoll(x, NULL, 10)
15
14QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
15
16static enum qemu_plugin_mem_rw rw = QEMU_PLUGIN_MEM_RW;
17
18static GHashTable *miss_ht;
19
20static GMutex hashtable_lock;
21static GRand *rng;

--- 719 unchanged lines hidden (view full) ---

741 l2_cachesize = l2_assoc * l2_blksize * 2048;
742
743 policy = LRU;
744
745 cores = sys ? qemu_plugin_n_vcpus() : 1;
746
747 for (i = 0; i < argc; i++) {
748 char *opt = argv[i];
16QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
17
18static enum qemu_plugin_mem_rw rw = QEMU_PLUGIN_MEM_RW;
19
20static GHashTable *miss_ht;
21
22static GMutex hashtable_lock;
23static GRand *rng;

--- 719 unchanged lines hidden (view full) ---

743 l2_cachesize = l2_assoc * l2_blksize * 2048;
744
745 policy = LRU;
746
747 cores = sys ? qemu_plugin_n_vcpus() : 1;
748
749 for (i = 0; i < argc; i++) {
750 char *opt = argv[i];
749 if (g_str_has_prefix(opt, "iblksize=")) {
750 l1_iblksize = g_ascii_strtoll(opt + 9, NULL, 10);
751 } else if (g_str_has_prefix(opt, "iassoc=")) {
752 l1_iassoc = g_ascii_strtoll(opt + 7, NULL, 10);
753 } else if (g_str_has_prefix(opt, "icachesize=")) {
754 l1_icachesize = g_ascii_strtoll(opt + 11, NULL, 10);
755 } else if (g_str_has_prefix(opt, "dblksize=")) {
756 l1_dblksize = g_ascii_strtoll(opt + 9, NULL, 10);
757 } else if (g_str_has_prefix(opt, "dassoc=")) {
758 l1_dassoc = g_ascii_strtoll(opt + 7, NULL, 10);
759 } else if (g_str_has_prefix(opt, "dcachesize=")) {
760 l1_dcachesize = g_ascii_strtoll(opt + 11, NULL, 10);
761 } else if (g_str_has_prefix(opt, "limit=")) {
762 limit = g_ascii_strtoll(opt + 6, NULL, 10);
763 } else if (g_str_has_prefix(opt, "cores=")) {
764 cores = g_ascii_strtoll(opt + 6, NULL, 10);
765 } else if (g_str_has_prefix(opt, "l2cachesize=")) {
766 l2_cachesize = g_ascii_strtoll(opt + 6, NULL, 10);
767 } else if (g_str_has_prefix(opt, "l2blksize=")) {
768 l2_blksize = g_ascii_strtoll(opt + 6, NULL, 10);
769 } else if (g_str_has_prefix(opt, "l2assoc=")) {
770 l2_assoc = g_ascii_strtoll(opt + 6, NULL, 10);
771 } else if (g_str_has_prefix(opt, "evict=")) {
772 gchar *p = opt + 6;
773 if (g_strcmp0(p, "rand") == 0) {
751 g_autofree char **tokens = g_strsplit(opt, "=", 2);
752
753 if (g_strcmp0(tokens[0], "iblksize") == 0) {
754 l1_iblksize = STRTOLL(tokens[1]);
755 } else if (g_strcmp0(tokens[0], "iassoc") == 0) {
756 l1_iassoc = STRTOLL(tokens[1]);
757 } else if (g_strcmp0(tokens[0], "icachesize") == 0) {
758 l1_icachesize = STRTOLL(tokens[1]);
759 } else if (g_strcmp0(tokens[0], "dblksize") == 0) {
760 l1_dblksize = STRTOLL(tokens[1]);
761 } else if (g_strcmp0(tokens[0], "dassoc") == 0) {
762 l1_dassoc = STRTOLL(tokens[1]);
763 } else if (g_strcmp0(tokens[0], "dcachesize") == 0) {
764 l1_dcachesize = STRTOLL(tokens[1]);
765 } else if (g_strcmp0(tokens[0], "limit") == 0) {
766 limit = STRTOLL(tokens[1]);
767 } else if (g_strcmp0(tokens[0], "cores") == 0) {
768 cores = STRTOLL(tokens[1]);
769 } else if (g_strcmp0(tokens[0], "l2cachesize") == 0) {
770 l2_cachesize = STRTOLL(tokens[1]);
771 } else if (g_strcmp0(tokens[0], "l2blksize") == 0) {
772 l2_blksize = STRTOLL(tokens[1]);
773 } else if (g_strcmp0(tokens[0], "l2assoc") == 0) {
774 l2_assoc = STRTOLL(tokens[1]);
775 } else if (g_strcmp0(tokens[0], "evict") == 0) {
776 if (g_strcmp0(tokens[1], "rand") == 0) {
774 policy = RAND;
777 policy = RAND;
775 } else if (g_strcmp0(p, "lru") == 0) {
778 } else if (g_strcmp0(tokens[1], "lru") == 0) {
776 policy = LRU;
779 policy = LRU;
777 } else if (g_strcmp0(p, "fifo") == 0) {
780 } else if (g_strcmp0(tokens[1], "fifo") == 0) {
778 policy = FIFO;
779 } else {
780 fprintf(stderr, "invalid eviction policy: %s\n", opt);
781 return -1;
782 }
783 } else {
784 fprintf(stderr, "option parsing failed: %s\n", opt);
785 return -1;

--- 40 unchanged lines hidden ---
781 policy = FIFO;
782 } else {
783 fprintf(stderr, "invalid eviction policy: %s\n", opt);
784 return -1;
785 }
786 } else {
787 fprintf(stderr, "option parsing failed: %s\n", opt);
788 return -1;

--- 40 unchanged lines hidden ---