From patchwork Thu Oct 17 20:03:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13840775 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58564227BAF for ; Thu, 17 Oct 2024 20:05:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729195546; cv=none; b=aRe68yAAY99BSNYmNTzPQrvl6K5W+gLxt5fptyXjEWgGs0hs/fXVvBD1yzVDlkij54bCEKQzbqEvlBOYQADehcio9bSnDIyjNi2vuHrW1ydnlu9p/eSTmmXTL4y3xaiP99v2sNNRslyx6U389im2/BtzJpg62/m67F8kedphJHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729195546; c=relaxed/simple; bh=23HROOojmsVm7HvD6MPx9GzVRfwFWRS5ZFpf+J9zznE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NhfHgISkO3gnHf+qKvkd0/LskhOXqvsJGY/75JNhzEuzBgM/t3O1tBf7i8a4HoTUxrYBHx4zd2lQ4lh9oOOw8e/+6zxxBaKV7lqecTEhanxP3A6+h22xVTOmejM/tqPhNJXgHX9BiTTIC7t7YF7DsSn23s0mjSbfJxgbWw0JV6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0493AC4CED6; Thu, 17 Oct 2024 20:05:45 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t1Wl8-00000003uh8-27eO; Thu, 17 Oct 2024 16:06:10 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" Subject: [PATCH 1/3] libtracefs utest: Add test to check handling multiple dynamic events Date: Thu, 17 Oct 2024 16:03:22 -0400 Message-ID: <20241017200609.932728-2-rostedt@goodmis.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241017200609.932728-1-rostedt@goodmis.org> References: <20241017200609.932728-1-rostedt@goodmis.org> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Steven Rostedt (Google)" Add a new "mutli probes" test that will create kprobes, kretprobes, uprobes, uretprobes, eprobes and synthetic events and make sure that the counters of those events are working properly. Signed-off-by: Steven Rostedt (Google) --- utest/tracefs-utest.c | 162 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c index 5bfd665b9990..742f4546bef0 100644 --- a/utest/tracefs-utest.c +++ b/utest/tracefs-utest.c @@ -2574,6 +2574,167 @@ static void test_uprobes(void) test_uprobes_instance(test_instance); } +static void test_multi_probes_instance(struct tracefs_instance *instance) +{ + struct probe_test tests[] = { + { TRACEFS_DYNEVENT_UPROBE, "p", "utest", "utest_u", NULL, "arg1=$stack2" }, + { TRACEFS_DYNEVENT_URETPROBE, "r", "utest", "utest_r", NULL, "arg1=$retval" }, + { TRACEFS_DYNEVENT_EPROBE, "e", NULL, "sopen_in", "syscalls.sys_enter_openat", + "file=+0($filename):ustring" }, + { TRACEFS_DYNEVENT_EPROBE, "e", "etest", "sopen_out", "syscalls.sys_exit_openat", + "res=$ret:u64" }, + { TRACEFS_DYNEVENT_KPROBE, "p", NULL, "mkdir", "do_mkdirat", "path=+u0($arg2):ustring" }, + { TRACEFS_DYNEVENT_KPROBE, "p", NULL, "close", "close_fd", NULL }, + { TRACEFS_DYNEVENT_KPROBE, "p", "ptest", "open2", "do_sys_openat2", + "file=+u0($arg2):ustring flags=+0($arg3):x64" }, + { TRACEFS_DYNEVENT_KRETPROBE, NULL, NULL, "retopen", "do_sys_openat2", "ret=$retval" }, + { TRACEFS_DYNEVENT_KRETPROBE, NULL, NULL, NULL, "do_sys_open", "ret=$retval" }, + }; + struct test_synth sevents[] = { + {"synth_1", "sched", "sched_waking", "sched", "sched_switch", "pid", "next_pid", "pid_match"}, + {"synth_2", "syscalls", "sys_enter_openat2", "syscalls", "sys_exit_openat2", "__syscall_nr", "__syscall_nr", "nr_match"}, + }; + int sevents_count = sizeof(sevents) / sizeof((sevents)[0]); + int count = sizeof(tests) / sizeof((tests)[0]); + struct tracefs_dynevent **probes; + struct tracefs_synth **synth; + struct tep_handle *tep; + char self[PATH_MAX] = { 0 }; + char *target = NULL; + char *tsys, *tevent; + char *tmp, *sav; + /* The below matches the tests and sevents arrays */ + const int uprobes_cnt = 1; + const int uretprobes_cnt = 1; + const int eprobes_cnt = 2; + const int kprobes_cnt = 3; + const int kretprobes_cnt = 2; + int ret; + int i; + + synth = calloc(sevents_count + 1, sizeof(*synth)); + + tep = tracefs_local_events(NULL); + CU_TEST(tep != NULL); + + destroy_dynevents(TRACEFS_DYNEVENT_ALL); + + for (i = 0; i < sevents_count; i++) { + synth[i] = tracefs_synth_alloc(tep, sevents[i].name, + sevents[i].start_system, sevents[i].start_event, + sevents[i].end_system, sevents[i].end_event, + sevents[i].start_match_field, sevents[i].end_match_field, + sevents[i].match_name); + CU_TEST(synth[i] != NULL); + } + + probes = calloc(count + 1, sizeof(*probes)); + CU_TEST(probes != NULL); + CU_TEST(readlink("/proc/self/exe", self, sizeof(self)) > 0); + CU_TEST(asprintf(&target, "%s:0x%0*llx", self, (int)(sizeof(void *) * 2), FOFFSET) > 0); + + for (i = 0; i < count; i++) { + switch (tests[i].type) { + case TRACEFS_DYNEVENT_UPROBE: + tests[i].address = target; + probes[i] = tracefs_uprobe_alloc(tests[i].system, tests[i].event, + self, FOFFSET, tests[i].format); + break; + case TRACEFS_DYNEVENT_URETPROBE: + tests[i].address = target; + probes[i] = tracefs_uretprobe_alloc(tests[i].system, tests[i].event, + self, FOFFSET, tests[i].format); + break; + case TRACEFS_DYNEVENT_KPROBE: + probes[i] = tracefs_kprobe_alloc(tests[i].system, tests[i].event, + tests[i].address, tests[i].format); + break; + case TRACEFS_DYNEVENT_KRETPROBE: + probes[i] = tracefs_kretprobe_alloc(tests[i].system, tests[i].event, + tests[i].address, tests[i].format, 0); + break; + case TRACEFS_DYNEVENT_EPROBE: + tmp = strdup(tests[i].address); + tsys = strtok_r(tmp, "./", &sav); + tevent = strtok_r(NULL, "", &sav); + probes[i] = tracefs_eprobe_alloc(tests[i].system, tests[i].event, + tsys, tevent, tests[i].format); + free(tmp); + break; + default: + CU_TEST(0); + break; + } + + CU_TEST(probes[i] != NULL); + } + probes[i] = NULL; + + get_dynevents_check(TRACEFS_DYNEVENT_ALL, 0); + CU_TEST(check_probes(tests, count, probes, false, instance, tep)); + + for (i = 0; i < count; i++) { + CU_TEST(tracefs_dynevent_create(probes[i]) == 0); + } + + get_dynevents_check(TRACEFS_DYNEVENT_ALL, count); + + for (i = 0; i < sevents_count; i++) { + CU_TEST(tracefs_synth_create(synth[i]) == 0); + } + + get_dynevents_check(TRACEFS_DYNEVENT_ALL, count + sevents_count); + + CU_TEST(check_probes(tests, count, probes, true, instance, tep)); + + get_dynevents_check(TRACEFS_DYNEVENT_UPROBE, uprobes_cnt); + get_dynevents_check(TRACEFS_DYNEVENT_URETPROBE, uretprobes_cnt); + get_dynevents_check(TRACEFS_DYNEVENT_UPROBE | + TRACEFS_DYNEVENT_URETPROBE, uprobes_cnt + uretprobes_cnt); + + get_dynevents_check(TRACEFS_DYNEVENT_KPROBE, kprobes_cnt); + get_dynevents_check(TRACEFS_DYNEVENT_KRETPROBE, kretprobes_cnt); + get_dynevents_check(TRACEFS_DYNEVENT_KPROBE | + TRACEFS_DYNEVENT_KRETPROBE, kprobes_cnt + kretprobes_cnt); + + get_dynevents_check(TRACEFS_DYNEVENT_EPROBE, eprobes_cnt); + + get_dynevents_check(TRACEFS_DYNEVENT_SYNTH, sevents_count); + + get_dynevents_check(TRACEFS_DYNEVENT_EPROBE | TRACEFS_DYNEVENT_SYNTH, + eprobes_cnt + sevents_count); + + + for (i = 0; i < count; i++) { + CU_TEST(tracefs_dynevent_destroy(probes[i], false) == 0); + } + + get_dynevents_check(TRACEFS_DYNEVENT_ALL, sevents_count); + + for (i = 0; i < sevents_count; i++) { + ret = tracefs_synth_destroy(synth[i]); + CU_TEST(ret == 0); + } + + get_dynevents_check(TRACEFS_DYNEVENT_ALL, 0); + + for (i = 0; i < count; i++) + tracefs_dynevent_free(probes[i]); + + for (i = 0; i < sevents_count; i++) + tracefs_synth_free(synth[i]); + + free(synth); + free(probes); + free(target); + tep_free(tep); +} + +static void test_multi_probes(void) +{ + test_multi_probes_instance(test_instance); +} + static void test_instance_file(void) { struct tracefs_instance *instance = NULL; @@ -3693,4 +3854,5 @@ void test_tracefs_lib(void) CU_add_test(suite, "synthetic events", test_synthetic); CU_add_test(suite, "eprobes", test_eprobes); CU_add_test(suite, "uprobes", test_uprobes); + CU_add_test(suite, "multi probe test", test_multi_probes); } From patchwork Thu Oct 17 20:03:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13840774 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54ECD227397 for ; Thu, 17 Oct 2024 20:05:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729195546; cv=none; b=EUXc/NsxxezFPvpcGsIGxL+phNNX8ecqV9er/Ntxils5kBz/HQvHhk2EC48RdmKMgQ8F0uYdneIbObRL6KwBK7aShsfiTYaUHz/tD11r44MdKynuXXOphuEFXMdby4lGAEGvbR3eDiad1er5QWgO8nYl12e840zZM0b0VAuWakA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729195546; c=relaxed/simple; bh=buzsaZnHnAntSoMLRcdU7/Kg3ecUfqpY50aQ+cHrD30=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q94oHhaAxraor/PZqkoTBwqdM7vSQJbgUn8VhGXch2Fm3RM8yfHfLs8AtHw4V+d3C0P4B7a1erriYg32nTd8EmWnhrYDpyGDYA4+RixOKCmar+qILJJ9JzbHxcPmmaOWhFRbAb94hEQR7ouVmw+csAx08fmwFT8Nj5JpvhKTPmA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F353DC4CED5; Thu, 17 Oct 2024 20:05:45 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t1Wl8-00000003uhB-2EsW; Thu, 17 Oct 2024 16:06:10 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" , Adrien Nader Subject: [PATCH 2/3] libtracefs utest: Fix min percent test Date: Thu, 17 Oct 2024 16:03:23 -0400 Message-ID: <20241017200609.932728-3-rostedt@goodmis.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241017200609.932728-1-rostedt@goodmis.org> References: <20241017200609.932728-1-rostedt@goodmis.org> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Steven Rostedt (Google)" On PowerPC 64 which has 64K pages, it screws up the accounting of some calculations used for tests. For instance, 1% of the ring buffer may not be more than a page. So testing 1% and then subtracting the number of events per page is going to lead to a negative number. This will obviously fail. Take into account that the subbuffer may be very large, and to make a minimum percent to use in case a subbuffer size is greater than 1%. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=219358 Reported-by: Adrien Nader Signed-off-by: Steven Rostedt (Google) --- utest/tracefs-utest.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c index 742f4546bef0..b5095a18bb16 100644 --- a/utest/tracefs-utest.c +++ b/utest/tracefs-utest.c @@ -1340,6 +1340,17 @@ static void test_cpu_read_buf_percent(struct test_cpu_data *data, int percent) /* For percent == 0, just test for any data */ if (percent) { + int min_percent; + + /* + * For architectures like PowerPC with 64K PAGE_SIZE and thus + * large sub buffers, where we will not have over 100 sub buffers + * percent must at least cover more than 1 sub buffer. + */ + min_percent = (100 + (data->nr_subbufs - 1)) / data->nr_subbufs; + if (percent < min_percent) + percent = min_percent; + expect = data->nr_subbufs * data->events_per_buf * percent / 100; /* Add just under the percent */ From patchwork Thu Oct 17 20:03:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13840773 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56B68227BAE for ; Thu, 17 Oct 2024 20:05:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729195546; cv=none; b=Q5mLxDjUU/MwxGFyYex6utjcTDjKHW5icCtpugqJrSRA/OrgTM/ndyM07BNBQ1nhBSXdvyMHDnE746msoUrnjQdRv5LZwDTDNdJNg0VhyRIwhBb/CbL/x2QIFeMSTJvtV+jxWe1+g29UsEnx8xZ9J0paXCCqiOJlP+Pf+prLD30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729195546; c=relaxed/simple; bh=mRvYD46HogsseOblnw3hLrunIP1w2ubXtC5e8MdXrDk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eLZPzYodL9WvnoaFnLNGkKC3M9x8I5wlDU4m+SrR8g0OGZBFArpcM39XR0LR7zpj10yujqAQ12mCS7QLwbvLHf/+9YyxrJv5AV9+TKlyZYvd+wb7uVoW6fXdYgDhjxVnQVvUxbQ0GfEu96vpaJgalvshNkwjpZkSKdqCBgk5bIs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED859C4CED2; Thu, 17 Oct 2024 20:05:45 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t1Wl8-00000003uhG-2Lr7; Thu, 17 Oct 2024 16:06:10 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" , Adrien Nader Subject: [PATCH 3/3] libtracefs utest: Do not test more events than what the ring buffer can hold Date: Thu, 17 Oct 2024 16:03:24 -0400 Message-ID: <20241017200609.932728-4-rostedt@goodmis.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241017200609.932728-1-rostedt@goodmis.org> References: <20241017200609.932728-1-rostedt@goodmis.org> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Steven Rostedt (Google)" The test_instance_cpu_read() will test events_per_buf * 50 events. But on PowerPC64 which has 64K size subbuffers, there may not be 50 subbuffers in a per CPU ring buffer. That means the test will overflow and it will read less events than expected. Check to make sure that the number to test is not going to add more events than what a single ring buffer can hold. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=219358 Reported-by: Adrien Nader Signed-off-by: Steven Rostedt (Google) --- utest/tracefs-utest.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c index b5095a18bb16..46fa31c88cf6 100644 --- a/utest/tracefs-utest.c +++ b/utest/tracefs-utest.c @@ -1270,6 +1270,8 @@ static void test_cpu_read(struct test_cpu_data *data, int expect) static void test_instance_trace_cpu_read(struct tracefs_instance *instance, bool map) { struct test_cpu_data data; + size_t buffer_size; + int big_num = 50; if (setup_trace_cpu(instance, &data, true, map)) return; @@ -1278,7 +1280,14 @@ static void test_instance_trace_cpu_read(struct tracefs_instance *instance, bool test_cpu_read(&data, data.events_per_buf / 2); test_cpu_read(&data, data.events_per_buf); test_cpu_read(&data, data.events_per_buf + 1); - test_cpu_read(&data, data.events_per_buf * 50); + + buffer_size = tracefs_instance_get_buffer_size(instance, 0) * 1024; + if (data.events_per_buf * big_num > (buffer_size - data.events_per_buf)) { + big_num = (buffer_size / data.events_per_buf); + big_num -= data.events_per_buf * 2; + CU_TEST(big_num > 0); + } + test_cpu_read(&data, data.events_per_buf * big_num); shutdown_trace_cpu(&data); }