From nobody Tue Nov 26 15:35:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1707211572; cv=none; d=zohomail.com; s=zohoarc; b=e48XKHo+DgODOQK61XaaM8/PdERdfFkKNUlFbD4+HmT+V2/K8C/Cx5rW20c0JmY5V+wvRK9jl/OnMyo/UCWtWX4jI2004EjgGLR7caVzGx+Y3PpE834tcY8mIzs01U+gZVqI0DjOYWh+fqb8n981uwZ8rKnSc6mGebefl2qBIl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707211572; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jIM1lNqnf5XAacffBXN4ljIlTpT3DH/ZoqvjHNJUJG4=; b=ejFlygH4Phc680679PUQ4ioAbQi3qirILpcu5zGKKT7yczwOt0klCcGuMSde6HOrq2VNPG9dFtL9oX0iDPlG9dRoQtoKXR30VLEe+ZwO9rUEg+j0Tv8wAsDhUwrGFDVbu0A86eYLVqWsjJmH2Z+Eyk4y91wKi6xgye4HgA1dEp8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1707211572828827.8566721095799; Tue, 6 Feb 2024 01:26:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXHhy-00056o-Ad; Tue, 06 Feb 2024 04:25:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rXHhc-0004u5-V6 for qemu-devel@nongnu.org; Tue, 06 Feb 2024 04:25:17 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rXHhb-0004yU-4q for qemu-devel@nongnu.org; Tue, 06 Feb 2024 04:25:16 -0500 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40fc654a718so34402175e9.2 for ; Tue, 06 Feb 2024 01:25:14 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id u17-20020a05600c211100b0040fc5460109sm1312756wml.35.2024.02.06.01.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:25:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707211513; x=1707816313; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jIM1lNqnf5XAacffBXN4ljIlTpT3DH/ZoqvjHNJUJG4=; b=oRmcvAW5mtt31dbVvQKkS1FyobZlWH5GNipyeZspcIVKc8YqS/r23dk0oNV8hchRwR rQ56GRSqaXulHNfOs+IHLnVdScGo4Ui0XJnGK2zJuragDnwBxA+zWiKgMjMAzCkDmpXW zy9InmMsV5vQQz6iC6uGRvnf1kdQDxSe44VhfiV0uS0wkkt2lAgSQFivaLOBUOGMNyYk t7PTFsu6r0e+KU5XWXTSBLrME5V8D3x86SeR1HEFNTCnKLOX14E/Y9VhbYlqRO/OdWzd fPjY8kSgoMHj0xlyqh221KkE0y1IFO6RzmDnUm5eEvf7Z0D1R5MZNR8X9r90gSlgAmz8 ER/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707211513; x=1707816313; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jIM1lNqnf5XAacffBXN4ljIlTpT3DH/ZoqvjHNJUJG4=; b=PKYqMumFoF2I7yniMHqFAysDRmp8/gUjjJCm2BHqguYBtZyhkX8gAUbY36BNa2i9gO Sh33EH574TIjYtfppkJAdUYKXhB9J+I3PlOIYX1g4Js/cXaFqgFN2tAswVbyQsyLbenP Sr37/Ozgg/rH0SagCx8QG5HX6YcoBHmAjOid3YJ+CNIO+M67wmADZckWWZRguKuxLdPX dinoYW1G8EfM2o33ImZen+fZDzh92D8NoxxQYjqGrbot/pwBOJ1zphqIIFcEoGHtd4VO 9QR+KWmfxfHBcX+iUAIIFqnUHL3j1MZotMBMwQW/vBn3hElx75FLdp/sU5FnQSMnzJUR MosA== X-Gm-Message-State: AOJu0YwPYTO070oNiqRUPe+RUa63fEA1TPfcdJBsPrCp4PQXjBaj+ZvJ jM7OOBmUsbeLPz9smif8LrVp2V6NjM9ZgEHLviqlAZP2oaLqjYwtykal2ds1b+0uphdIlHpU+zI 69dk= X-Google-Smtp-Source: AGHT+IGfzL2qFIoVR1TI1sqiNkIsK+rV33OBKd5h4Og7CD2zH6V7ZOpof41PzB/OcZ9Cxm1O7F95XA== X-Received: by 2002:a05:600c:470b:b0:40e:b93e:4a0f with SMTP id v11-20020a05600c470b00b0040eb93e4a0fmr1850701wmo.19.1707211512798; Tue, 06 Feb 2024 01:25:12 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUtVWrdbotELh7Qs0BaH/u1pQwm0ogtBS6Y8QLdlvhDw1DNAWIt/YfgUGrt1OdvDNa7IvhLTx8cBkddlSmygUsnCDn7uTRb180nQIfiUZ5rAsSJ3FJ0hFiyo1OjYAyg+XSZ2XlP/8XcU564cxwckQtan/7H2sOn89kHcjc1pq1uA3UkMf167P0WfuZuPRVsBrOfg4BacHP5ataRifUjdF4PXU7A26X9Tk9QVr4UrOhlUUqVAL2iBaVQw3XdWsKZZ5N3fSWQo5fi6MdT4bZmAARlqIU8bwLj2mGqmulqPpp1R+a7RbDos6w39DQcbhNzhJTHaSVObf/HFLbhpR70t5QIOVIbsKkRSA== From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Eduardo Habkost , Alexandre Iooss , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Marcel Apfelbaum , Yanan Wang , Pierrick Bouvier , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 11/17] tests/plugin/insn: migrate to new per_vcpu API Date: Tue, 6 Feb 2024 13:24:16 +0400 Message-ID: <20240206092423.3005995-12-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240206092423.3005995-1-pierrick.bouvier@linaro.org> References: <20240206092423.3005995-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::32d; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x32d.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1707211573623100014 Signed-off-by: Pierrick Bouvier --- tests/plugin/insn.c | 106 +++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 56 deletions(-) diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c index 5fd3017c2b3..0d0a4cd1c34 100644 --- a/tests/plugin/insn.c +++ b/tests/plugin/insn.c @@ -16,25 +16,21 @@ =20 QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; =20 -#define MAX_CPUS 8 /* lets not go nuts */ - -typedef struct { - uint64_t insn_count; -} InstructionCount; - -static InstructionCount counts[MAX_CPUS]; -static uint64_t inline_insn_count; +static qemu_plugin_u64 insn_count; =20 static bool do_inline; static bool do_size; static GArray *sizes; =20 +typedef struct { + uint64_t hits; + uint64_t last_hit; + uint64_t total_delta; +} MatchCount; + typedef struct { char *match_string; - uint64_t hits[MAX_CPUS]; - uint64_t last_hit[MAX_CPUS]; - uint64_t total_delta[MAX_CPUS]; - GPtrArray *history[MAX_CPUS]; + struct qemu_plugin_scoreboard *counts; /* MatchCount */ } Match; =20 static GArray *matches; @@ -48,41 +44,40 @@ typedef struct { =20 static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) { - unsigned int i =3D cpu_index % MAX_CPUS; - InstructionCount *c =3D &counts[i]; - - c->insn_count++; + qemu_plugin_u64_add(insn_count, cpu_index, 1); } =20 static void vcpu_insn_matched_exec_before(unsigned int cpu_index, void *ud= ata) { - unsigned int i =3D cpu_index % MAX_CPUS; Instruction *insn =3D (Instruction *) udata; - Match *match =3D insn->match; + Match *insn_match =3D insn->match; + MatchCount *match =3D qemu_plugin_scoreboard_find(insn_match->counts, + cpu_index); + g_autoptr(GString) ts =3D g_string_new(""); =20 insn->hits++; g_string_append_printf(ts, "0x%" PRIx64 ", '%s', %"PRId64 " hits", insn->vaddr, insn->disas, insn->hits); =20 - uint64_t icount =3D counts[i].insn_count; - uint64_t delta =3D icount - match->last_hit[i]; + uint64_t icount =3D qemu_plugin_u64_get(insn_count, cpu_index); + uint64_t delta =3D icount - match->last_hit; =20 - match->hits[i]++; - match->total_delta[i] +=3D delta; + match->hits++; + match->total_delta +=3D delta; =20 g_string_append_printf(ts, - ", %"PRId64" match hits, " - "=CE=94+%"PRId64 " since last match," + " , cpu %u," + " %"PRId64" match hits," + " =CE=94+%"PRId64 " since last match," " %"PRId64 " avg insns/match\n", - match->hits[i], delta, - match->total_delta[i] / match->hits[i]); + cpu_index, + match->hits, delta, + match->total_delta / match->hits); =20 - match->last_hit[i] =3D icount; + match->last_hit =3D icount; =20 qemu_plugin_outs(ts->str); - - g_ptr_array_add(match->history[i], insn); } =20 static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) @@ -94,8 +89,8 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qem= u_plugin_tb *tb) struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, i); =20 if (do_inline) { - qemu_plugin_register_vcpu_insn_exec_inline( - insn, QEMU_PLUGIN_INLINE_ADD_U64, &inline_insn_count, 1); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_ADD_U64, insn_count, 1); } else { uint64_t vaddr =3D qemu_plugin_insn_vaddr(insn); qemu_plugin_register_vcpu_insn_exec_cb( @@ -117,10 +112,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct = qemu_plugin_tb *tb) * information about the instruction which we also need to * save if there is a hit. */ - if (matches) { + if (matches->len) { char *insn_disas =3D qemu_plugin_insn_disas(insn); - int j; - for (j =3D 0; j < matches->len; j++) { + for (int j =3D 0; j < matches->len; j++) { Match *m =3D &g_array_index(matches, Match, j); if (g_str_has_prefix(insn_disas, m->match_string)) { Instruction *rec =3D g_new0(Instruction, 1); @@ -150,36 +144,33 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) "len %d bytes: %ld insns\n", i, *cn= t); } } - } else if (do_inline) { - g_string_append_printf(out, "insns: %" PRIu64 "\n", inline_insn_co= unt); } else { - uint64_t total_insns =3D 0; - for (i =3D 0; i < MAX_CPUS; i++) { - InstructionCount *c =3D &counts[i]; - if (c->insn_count) { - g_string_append_printf(out, "cpu %d insns: %" PRIu64 "\n", - i, c->insn_count); - total_insns +=3D c->insn_count; - } + for (i =3D 0; i < qemu_plugin_num_vcpus(); i++) { + g_string_append_printf(out, "cpu %d insns: %" PRIu64 "\n", + i, qemu_plugin_u64_get(insn_count, i)); } g_string_append_printf(out, "total insns: %" PRIu64 "\n", - total_insns); + qemu_plugin_u64_sum(insn_count)); } qemu_plugin_outs(out->str); + + qemu_plugin_scoreboard_free(insn_count.score); + for (i =3D 0; i < matches->len; ++i) { + Match *m =3D &g_array_index(matches, Match, i); + g_free(m->match_string); + qemu_plugin_scoreboard_free(m->counts); + } + g_array_free(matches, TRUE); + g_array_free(sizes, TRUE); } =20 =20 /* Add a match to the array of matches */ static void parse_match(char *match) { - Match new_match =3D { .match_string =3D match }; - int i; - for (i =3D 0; i < MAX_CPUS; i++) { - new_match.history[i] =3D g_ptr_array_new(); - } - if (!matches) { - matches =3D g_array_new(false, true, sizeof(Match)); - } + Match new_match =3D { + .match_string =3D g_strdup(match), + .counts =3D qemu_plugin_scoreboard_new(sizeof(MatchCount)) }; g_array_append_val(matches, new_match); } =20 @@ -187,6 +178,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, const qemu_info_t *info, int argc, char **argv) { + matches =3D g_array_new(false, true, sizeof(Match)); + /* null terminated so 0 is not a special case */ + sizes =3D g_array_new(true, true, sizeof(unsigned long)); + for (int i =3D 0; i < argc; i++) { char *opt =3D argv[i]; g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); @@ -208,9 +203,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, } } =20 - if (do_size) { - sizes =3D g_array_new(true, true, sizeof(unsigned long)); - } + insn_count =3D qemu_plugin_scoreboard_u64( + qemu_plugin_scoreboard_new(sizeof(uint64_t))); =20 qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); --=20 2.43.0