From patchwork Wed Apr 7 03:48:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12186755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A27EC433B4 for ; Wed, 7 Apr 2021 03:48:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6215F613BD for ; Wed, 7 Apr 2021 03:48:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344405AbhDGDsi (ORCPT ); Tue, 6 Apr 2021 23:48:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344473AbhDGDsg (ORCPT ); Tue, 6 Apr 2021 23:48:36 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2871C061756 for ; Tue, 6 Apr 2021 20:48:26 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id i18so12867383wrm.5 for ; Tue, 06 Apr 2021 20:48:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GhgN9ZPY/lPzKhC3zAsTD0jvINhSSdDVi9g9xC6kkw4=; b=iiYstPkKqzB4bbbxM+AD4WECKCXTPs7sgvBMZ97uHLK/Hv6mZJMSPYfX5doR94lW0J R5uLLyJFUtLDeczhQG0XJ8Bom1bIUIe+sqo912WihnCMB/iIx3iFg8KsKcHpYXPPiwjn BpToXYnDsbcxeC3b+JsX9Cn9bXadlluP7mIQZESTqg5ZJwRjO3CuIGUE6VXje8vpb7Pi 1lR4mUT4fR9h/gD2n+xMzZwBmA1K9Lkm6cQfhrtYkTPq8eLpTbmU206LZXNs7LWlN57M sLdUJ6rmj19wH3SAhUTDXfHX2picxBMVGbVWdVnkNAuXfyd3ia0pYyQkYd2Urr1B0C/W 89ag== 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=GhgN9ZPY/lPzKhC3zAsTD0jvINhSSdDVi9g9xC6kkw4=; b=t98gEKOH71nI52dMQnSWqdS3DxW3ap0jHVC8KiqVMH2/HMWxr64xls08KnSO7oPMxq 28bzNb5bXaMcn27XsPJK3s9eIR95Bst9l3yinfFM1/P1PfKuILwU2iv/sXkkEzSWY/fU maNF6OVOjKnN+F6p4ePrxvwEdDzLUoPlxg/1Xi5i/nueAv52LhwUUXnkMJer3vJCx1rM YWZZ4pQP8yUj7T+HPr92LtovofQ+yYdSSz1WNYQpfdzUpKfCIu0Tvc5ytt/78u9XsJYE v5eiztWIop0pkRU5f/pU8QsimXmsoot3iOmPYI+GfQqS0Likby2VR5LTZK1xKgqUag8+ bzRw== X-Gm-Message-State: AOAM531Erl/nVLavMMxsEPnMiB1g1odtEEQ4q3jBGqwCjNaNl9IJW1T7 5jgChsWGYerO25rt90dTnmMoNxGiGwVV+g== X-Google-Smtp-Source: ABdhPJwyUOJcMgihBlye0unQ9lr8gBA0/g/E/jS9VvmriRHfNCh2i3TOkqcY6XfdsggEtKDEiufvPA== X-Received: by 2002:a5d:4a48:: with SMTP id v8mr1580994wrs.107.1617767305534; Tue, 06 Apr 2021 20:48:25 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id l21sm5684973wmg.41.2021.04.06.20.48.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 20:48:25 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 1/4] libtracefs: Iterate over raw events in sorted order Date: Wed, 7 Apr 2021 06:48:19 +0300 Message-Id: <20210407034822.2373958-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210407034822.2373958-1-tz.stoyanov@gmail.com> References: <20210407034822.2373958-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Changed the logic of tracefs_iterate_raw_events(): instead of iterating in CPU order, walk through the events from all CPU buffers and read the oldest first. Fixed the problem with cpu number in the record, passed to the callback - set the real CPU number instead of 0. Signed-off-by: Tzvetomir Stoyanov (VMware) --- src/tracefs-events.c | 247 +++++++++++++++++++++++++++---------------- 1 file changed, 156 insertions(+), 91 deletions(-) diff --git a/src/tracefs-events.c b/src/tracefs-events.c index 825f916..da56943 100644 --- a/src/tracefs-events.c +++ b/src/tracefs-events.c @@ -51,120 +51,129 @@ page_to_kbuf(struct tep_handle *tep, void *page, int size) return kbuf; } -static int read_kbuf_record(struct kbuffer *kbuf, struct tep_record *record) +struct cpu_iterate { + struct tep_record record; + struct tep_event *event; + struct kbuffer *kbuf; + void *page; + int psize; + int rsize; + int cpu; + int fd; +}; + +static int read_kbuf_record(struct cpu_iterate *cpu) { unsigned long long ts; void *ptr; - ptr = kbuffer_read_event(kbuf, &ts); - if (!ptr || !record) + if (!cpu || !cpu->kbuf) + return -1; + ptr = kbuffer_read_event(cpu->kbuf, &ts); + if (!ptr) return -1; - memset(record, 0, sizeof(*record)); - record->ts = ts; - record->size = kbuffer_event_size(kbuf); - record->record_size = kbuffer_curr_size(kbuf); - record->cpu = 0; - record->data = ptr; - record->ref_count = 1; + memset(&cpu->record, 0, sizeof(cpu->record)); + cpu->record.ts = ts; + cpu->record.size = kbuffer_event_size(cpu->kbuf); + cpu->record.record_size = kbuffer_curr_size(cpu->kbuf); + cpu->record.cpu = cpu->cpu; + cpu->record.data = ptr; + cpu->record.ref_count = 1; - kbuffer_next_event(kbuf, NULL); + kbuffer_next_event(cpu->kbuf, NULL); return 0; } -static int -get_events_in_page(struct tep_handle *tep, void *page, - int size, int cpu, - int (*callback)(struct tep_event *, - struct tep_record *, - int, void *), - void *callback_context) +int read_next_page(struct tep_handle *tep, struct cpu_iterate *cpu) { - struct tep_record record; - struct tep_event *event; - struct kbuffer *kbuf; - int id, cnt = 0; + cpu->rsize = read(cpu->fd, cpu->page, cpu->psize); + if (cpu->rsize <= 0) + return -1; + + cpu->kbuf = page_to_kbuf(tep, cpu->page, cpu->rsize); + if (!cpu->kbuf) + return -1; + + return 0; +} + +int read_next_record(struct tep_handle *tep, struct cpu_iterate *cpu) +{ + int id; + + do { + while (!read_kbuf_record(cpu)) { + id = tep_data_type(tep, &(cpu->record)); + cpu->event = tep_find_event(tep, id); + if (cpu->event) + return 0; + } + } while (!read_next_page(tep, cpu)); + + return -1; +} + +static int read_cpu_pages(struct tep_handle *tep, struct cpu_iterate *cpus, int count, + int (*callback)(struct tep_event *, + struct tep_record *, + int, void *), + void *callback_context) +{ + bool has_data = false; int ret; + int i, j; - if (size <= 0) - return 0; + for (i = 0; i < count; i++) { + ret = read_next_record(tep, cpus + i); + if (!ret) + has_data = true; + } - kbuf = page_to_kbuf(tep, page, size); - if (!kbuf) - return 0; - - ret = read_kbuf_record(kbuf, &record); - while (!ret) { - id = tep_data_type(tep, &record); - event = tep_find_event(tep, id); - if (event) { - cnt++; - if (callback && - callback(event, &record, cpu, callback_context)) + while (has_data) { + j = count; + for (i = 0; i < count; i++) { + if (!cpus[i].event) + continue; + if (j == count || cpus[j].record.ts > cpus[i].record.ts) + j = i; + } + if (j < count) { + if (callback(cpus[j].event, &cpus[j].record, cpus[j].cpu, callback_context)) break; + cpus[j].event = NULL; + read_next_record(tep, cpus + j); + } else { + has_data = false; } - ret = read_kbuf_record(kbuf, &record); } - kbuffer_free(kbuf); - - return cnt; + return 0; } -/* - * tracefs_iterate_raw_events - Iterate through events in trace_pipe_raw, - * per CPU trace buffers - * @tep: a handle to the trace event parser context - * @instance: ftrace instance, can be NULL for the top instance - * @cpus: Iterate only through the buffers of CPUs, set in the mask. - * If NULL, iterate through all CPUs. - * @cpu_size: size of @cpus set - * @callback: A user function, called for each record from the file - * @callback_context: A custom context, passed to the user callback function - * - * If the @callback returns non-zero, the iteration stops - in that case all - * records from the current page will be lost from future reads - * - * Returns -1 in case of an error, or 0 otherwise - */ -int tracefs_iterate_raw_events(struct tep_handle *tep, - struct tracefs_instance *instance, - cpu_set_t *cpus, int cpu_size, - int (*callback)(struct tep_event *, - struct tep_record *, - int, void *), - void *callback_context) +static int open_cpu_files(struct tracefs_instance *instance, cpu_set_t *cpus, + int cpu_size, struct cpu_iterate **all_cpus, int *count) { + struct cpu_iterate *tmp; unsigned int p_size; struct dirent *dent; char file[PATH_MAX]; - void *page = NULL; struct stat st; + int ret = -1; + int fd = -1; char *path; DIR *dir; - int ret; int cpu; - int fd; - int r; + int i = 0; - if (!tep || !callback) - return -1; - - p_size = getpagesize(); path = tracefs_instance_get_file(instance, "per_cpu"); if (!path) return -1; dir = opendir(path); - if (!dir) { - ret = -1; - goto error; - } - page = malloc(p_size); - if (!page) { - ret = -1; - goto error; - } + if (!dir) + goto out; + p_size = getpagesize(); while ((dent = readdir(dir))) { const char *name = dent->d_name; @@ -174,32 +183,88 @@ int tracefs_iterate_raw_events(struct tep_handle *tep, if (cpus && !CPU_ISSET_S(cpu, cpu_size, cpus)) continue; sprintf(file, "%s/%s", path, name); - ret = stat(file, &st); - if (ret < 0 || !S_ISDIR(st.st_mode)) + if (stat(file, &st) < 0 || !S_ISDIR(st.st_mode)) continue; sprintf(file, "%s/%s/trace_pipe_raw", path, name); fd = open(file, O_RDONLY | O_NONBLOCK); if (fd < 0) continue; - do { - r = read(fd, page, p_size); - if (r > 0) - get_events_in_page(tep, page, r, cpu, - callback, callback_context); - } while (r > 0); - close(fd); + tmp = realloc(*all_cpus, (i + 1) * sizeof(struct cpu_iterate)); + if (!tmp) { + close(fd); + goto out; + } + memset(tmp + i, 0, sizeof(struct cpu_iterate)); + tmp[i].fd = fd; + tmp[i].cpu = cpu; + tmp[i].page = malloc(p_size); + tmp[i].psize = p_size; + *all_cpus = tmp; + *count = i + 1; + if (!tmp[i++].page) + goto out; } + ret = 0; -error: +out: if (dir) closedir(dir); - free(page); tracefs_put_tracing_file(path); return ret; } +/* + * tracefs_iterate_raw_events - Iterate through events in trace_pipe_raw, + * per CPU trace buffers + * @tep: a handle to the trace event parser context + * @instance: ftrace instance, can be NULL for the top instance + * @cpus: Iterate only through the buffers of CPUs, set in the mask. + * If NULL, iterate through all CPUs. + * @cpu_size: size of @cpus set + * @callback: A user function, called for each record from the file + * @callback_context: A custom context, passed to the user callback function + * + * If the @callback returns non-zero, the iteration stops - in that case all + * records from the current page will be lost from future reads + * The events are iterated in sorted order, oldest first. + * + * Returns -1 in case of an error, or 0 otherwise + */ +int tracefs_iterate_raw_events(struct tep_handle *tep, + struct tracefs_instance *instance, + cpu_set_t *cpus, int cpu_size, + int (*callback)(struct tep_event *, + struct tep_record *, + int, void *), + void *callback_context) +{ + struct cpu_iterate *all_cpus = NULL; + int count = 0; + int ret; + int i; + + if (!tep || !callback) + return -1; + + ret = open_cpu_files(instance, cpus, cpu_size, &all_cpus, &count); + if (ret < 0) + goto out; + ret = read_cpu_pages(tep, all_cpus, count, callback, callback_context); + +out: + if (all_cpus) { + for (i = 0; i < count; i++) { + close(all_cpus[i].fd); + free(all_cpus[i].page); + } + free(all_cpus); + } + + return ret; +} + static char **add_list_string(char **list, const char *name, int len) { if (!list) From patchwork Wed Apr 7 03:48:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12186759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C39AAC43461 for ; Wed, 7 Apr 2021 03:48:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9CF876139E for ; Wed, 7 Apr 2021 03:48:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344473AbhDGDsi (ORCPT ); Tue, 6 Apr 2021 23:48:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344553AbhDGDsh (ORCPT ); Tue, 6 Apr 2021 23:48:37 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95790C06175F for ; Tue, 6 Apr 2021 20:48:27 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id a12so6547240wrq.13 for ; Tue, 06 Apr 2021 20:48:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jKf1WZ85dsSSiPEXRaAsFO5Kg/MZ0gSQmPkou2CkCVk=; b=EhI27iOK9eQv80Q7+v0l3nbFVhRBU433M+xAoZr1blngEvkqNvZIK8sIqSB3R/ia42 gRG2RTltcaNuuROQTlT9WWI5fE3CcX94QIE5/qbn/XX2+i+GChUHJX55aY8DP8TmbDzf 5VJznAnaetVET0WMqVvNJloVyiZyeH1XP7lY4aqs4gZJliI8J74nssXLWhoEGu6UyzZh L9CiHpA2ZqbL1s6eARYIEZi0zPys/iiHq8vWwVEmbf3ITH5S1DUnSmB72cOQS/fUTNfR ssCycitq3ORRkuBOjUnhGW0QtchnzdAmbaplzud3Vj05ADx8Z4ObwaIC1AqWd5Fbe2XT yxnw== 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=jKf1WZ85dsSSiPEXRaAsFO5Kg/MZ0gSQmPkou2CkCVk=; b=Ot/QJdqFbACOM/AB3uFtrd/hQThkZisikYynZmlCADrPkQVhNXMGYKu6KPzqcQP/H2 uHLd9le7vJ1CjOPR36/cPOZ+Y3w51yojGGRRBO/ueZi5o90DQgTK8tGrZug5OTJiKygB 5ucUa2273I3O58xv7TubXyJ+UR4le1gCtt+4CdwVdmi0ZPTQdBRTQo5KPYp72J21Ex0b 5GDBSlTHgtDydUwkphg4mKjIoFJELIxKhzrgHjo/VR62defBrNzFn7aqn8QiE+hU3Kf8 Lc3WJKsVcL53yhdCOsOwxVknTyZWxyOfkTi8OiK4bzzrAnoI7tGCJPbwA2xmjAL1CfqJ uMxQ== X-Gm-Message-State: AOAM530sM9MuwvL5Ll4yV8MlwJFCFiEXP7eNlphS4N/o5VTFLiOtaPAs ogspxbLfEg+Slj3vfvx9qn8J3O1/kDFDMA== X-Google-Smtp-Source: ABdhPJzexohgslTNN3G8nqjdGW2yZBkDBOvsqXU42e6W6Yb3fe0qanhcNQnji8hjL0Noux2H3p7/ug== X-Received: by 2002:adf:8292:: with SMTP id 18mr1628750wrc.160.1617767306358; Tue, 06 Apr 2021 20:48:26 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id l21sm5684973wmg.41.2021.04.06.20.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 20:48:25 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 2/4] libtracefs: Unit test for iterate over raw events in sorted order Date: Wed, 7 Apr 2021 06:48:20 +0300 Message-Id: <20210407034822.2373958-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210407034822.2373958-1-tz.stoyanov@gmail.com> References: <20210407034822.2373958-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Enhanced the unit test of tracefs_iterate_raw_events() API to check if events are iterated in sorted order: latest first. Added a check for the correct CPU number in the record, passed to the callback. Signed-off-by: Tzvetomir Stoyanov (VMware) --- utest/tracefs-utest.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c index ed2693b..fea4e1f 100644 --- a/utest/tracefs-utest.c +++ b/utest/tracefs-utest.c @@ -20,7 +20,7 @@ #define TRACEFS_SUITE "trasefs library" #define TEST_INSTANCE_NAME "cunit_test_iter" #define TEST_TRACE_DIR "/tmp/trace_utest.XXXXXX" -#define TEST_ARRAY_SIZE 500 +#define TEST_ARRAY_SIZE 5000 #define ALL_TRACERS "available_tracers" #define CUR_TRACER "current_tracer" @@ -36,6 +36,7 @@ struct test_sample { }; static struct test_sample test_array[TEST_ARRAY_SIZE]; static int test_found; +static unsigned long long last_ts; static int test_callback(struct tep_event *event, struct tep_record *record, int cpu, void *context) @@ -45,8 +46,13 @@ static int test_callback(struct tep_event *event, struct tep_record *record, int *cpu_test = (int *)context; int i; + CU_TEST(last_ts <= record->ts); + last_ts = record->ts; + if (cpu_test && *cpu_test >= 0 && *cpu_test != cpu) return 0; + CU_TEST(cpu == record->cpu); + field = tep_find_field(event, "buf"); if (field) { sample = ((struct test_sample *)(record->data + field->offset)); @@ -136,6 +142,7 @@ static void test_instance_iter_raw_events(struct tracefs_instance *instance) ret = tracefs_iterate_raw_events(NULL, instance, NULL, 0, test_callback, NULL); CU_TEST(ret < 0); + last_ts = 0; ret = tracefs_iterate_raw_events(test_tep, NULL, NULL, 0, test_callback, NULL); CU_TEST(ret == 0); ret = tracefs_iterate_raw_events(test_tep, instance, NULL, 0, NULL, NULL); From patchwork Wed Apr 7 03:48:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12186757 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D956C43460 for ; Wed, 7 Apr 2021 03:48:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFCCD6139E for ; Wed, 7 Apr 2021 03:48:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344553AbhDGDsj (ORCPT ); Tue, 6 Apr 2021 23:48:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348435AbhDGDsh (ORCPT ); Tue, 6 Apr 2021 23:48:37 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6B22C061760 for ; Tue, 6 Apr 2021 20:48:28 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id b9so8436049wrs.1 for ; Tue, 06 Apr 2021 20:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uIyNlIOtluNrnYmSi6DquZO21hCTzvwo0SUqb4QYjNg=; b=kVQuW3JK3tMZ108N8DyAeo7u9TkI9DupWeKv2PTCJkmHmBNym3IYif+F9a5i1QgATD PIwcvjOiMCQMzcEAlrAJZM0gyTT4HugZGuED01tvMjqaKHa9PAXzw1rVtGb3NWDRfXeA cfXzzDFVs2RVv0FHR3sdg7xTVNyb4dYSWLP5svnyI/+/HdvDb8qUKnHEXsb2Flmqvgj7 dLYVCq2bz7Z3oaDP0mMWSzlQiRiKRLXQyPf3l+wy7c8Bp52aBKOzuQcU97A3kD11AVM9 hrAgoOUuaZ/q7NbX0YCF9vTpERC8NeXrewUtMHEIWthuueCQM5B/QZvqcZ+2WzYxOXXy sqlg== 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=uIyNlIOtluNrnYmSi6DquZO21hCTzvwo0SUqb4QYjNg=; b=BTgAgBrKa1fKvgG3vwXVCXVEbi8VOmxAghJQxL2wgLCUmhn5QrqdGNH/e/bOv62c/8 pRyzZgbPTD7Vzv+cVEH3q1vdLs1nnH4maA0Ex8Pzc9f8nLyzFix8bTLM8e2cQZonsHIV EUD2wpLmqeEtz/jr5TD70PadVtEu8Cn41hiCKryCpJwtWutMkGnTgo+WqNWIDV3BE3Gx 3kneje4qBNRFVY3Ce+uCTbuXCc+FqQO8+Fa2E7NS/Ps+YiYooooCHjkFOGRJz+R2D33N ZlYywCFxshJbMPPQtvNdVeWQ00dOWA2gWVgmTBpYeLsxsBGQPYfFhtfCWfgH12E2pgOX TAgg== X-Gm-Message-State: AOAM530qvMZb6vzFP3R+6F/NENAgTYxeY3NzXxn81EaC5dVdUrHadVle sTrli+p576/Ba2t1OnhiW2+Z6dmxqRaSeA== X-Google-Smtp-Source: ABdhPJx0WawKKtNaVoxZET9Obbd+ZPOtGD6Sff20W41Om4uYX4nV4m2xHopO4mFIBAk008hpzfJxiw== X-Received: by 2002:a5d:654a:: with SMTP id z10mr1613595wrv.335.1617767307453; Tue, 06 Apr 2021 20:48:27 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id l21sm5684973wmg.41.2021.04.06.20.48.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 20:48:26 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 3/4] libtracefs: Unit test for iterate over raw events in selected CPUs Date: Wed, 7 Apr 2021 06:48:21 +0300 Message-Id: <20210407034822.2373958-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210407034822.2373958-1-tz.stoyanov@gmail.com> References: <20210407034822.2373958-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Enhanced the unit test of tracefs_iterate_raw_events() API to walk through the selected CPUs only. Added some forgotten calls to CPU_FREE() for freeing used CPU sets. Signed-off-by: Tzvetomir Stoyanov (VMware) --- utest/tracefs-utest.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c index fea4e1f..f9441af 100644 --- a/utest/tracefs-utest.c +++ b/utest/tracefs-utest.c @@ -49,8 +49,9 @@ static int test_callback(struct tep_event *event, struct tep_record *record, CU_TEST(last_ts <= record->ts); last_ts = record->ts; - if (cpu_test && *cpu_test >= 0 && *cpu_test != cpu) - return 0; + if (cpu_test && *cpu_test >= 0) { + CU_TEST(*cpu_test == cpu); + } CU_TEST(cpu == record->cpu); field = tep_find_field(event, "buf"); @@ -105,18 +106,30 @@ static void test_iter_write(struct tracefs_instance *instance) sched_setaffinity(0, cpu_size, cpusave); close(fd); + CPU_FREE(cpuset); + CPU_FREE(cpusave); } static void iter_raw_events_on_cpu(struct tracefs_instance *instance, int cpu) { + int cpus = sysconf(_SC_NPROCESSORS_CONF); + cpu_set_t *cpuset = NULL; + int cpu_size = 0; int check = 0; int ret; int i; + if (cpu >= 0) { + cpuset = CPU_ALLOC(cpus); + cpu_size = CPU_ALLOC_SIZE(cpus); + CPU_ZERO_S(cpu_size, cpuset); + CPU_SET(cpu, cpuset); + } test_found = 0; + last_ts = 0; test_iter_write(instance); - ret = tracefs_iterate_raw_events(test_tep, instance, NULL, 0, + ret = tracefs_iterate_raw_events(test_tep, instance, cpuset, cpu_size, test_callback, &cpu); CU_TEST(ret == 0); if (cpu < 0) { @@ -132,6 +145,9 @@ static void iter_raw_events_on_cpu(struct tracefs_instance *instance, int cpu) } CU_TEST(test_found == check); } + + if (cpuset) + CPU_FREE(cpuset); } static void test_instance_iter_raw_events(struct tracefs_instance *instance) From patchwork Wed Apr 7 03:48:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12186761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA11EC433B4 for ; Wed, 7 Apr 2021 03:48:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C93DD6139E for ; Wed, 7 Apr 2021 03:48:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348437AbhDGDsk (ORCPT ); Tue, 6 Apr 2021 23:48:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348435AbhDGDsk (ORCPT ); Tue, 6 Apr 2021 23:48:40 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9AACC06174A for ; Tue, 6 Apr 2021 20:48:29 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id x7so16315059wrw.10 for ; Tue, 06 Apr 2021 20:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iTrrOjheyODyYOoClyjpDFGkqyffXuRBbUQv0pwSG5M=; b=R/rwfHHlzm4DR0F0KMY84yVIqF+rkl5mOefakP8tsnJvP6q7sGj1EydbMGZqdVUtqo SyioozOJOa6o0yO8oIF8WPyNkn3m6YtlO1ht0+dq3GPFAEGiOtIvIGnBnkJF/hpvHs4e tjHzJ8olpD95y8rNUzC8PwAOifgEiDl4aCuTrAd8KClpkvQMivwhfmAALTpajSV/9dih FMwTW18xf62SFbZRYDH6uG478Xlej6oebm8mOdI2Z4kpRaR5Q9Q0n2O64IKNHBiyZdAk sXckazCRHmH+Bbj2H+4dmQC3R2zscjZMELi9sEM+ZpK6TQPKjaEyLCAS4lkwQyVi6GSl BR0w== 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=iTrrOjheyODyYOoClyjpDFGkqyffXuRBbUQv0pwSG5M=; b=HQUjfaI7vMQdzNly3pXz45Bm4hYZ+XcYy2j1LYHcIHeNtU9ysKBCAKa9LduDDtupH5 EYTnPyVcEk6ErEinDGjBeLHZ6yz8GSSur0n6e/oPTj/PuSt3OYwd5AZFDffoyEW8UCqA YqQ/0+XMBvmURvlPt1dBPl97SjW9EQLYhwBX3m7ZBVOQFRdRszeVQgbsANmMTTU7OQ49 2ZYYBKoOWKNyyTstVQRQFtmNvcd8Tf+IzqQhdfG1tnCIiWwFWYYyX6WFhmwFlhWUGDK7 mMllA6lIoRFvjXHIeWXR8iW95DpOoEbQJVPznkOWalD9gY09n6g9HKfelZ0tn6ifLtGo N//Q== X-Gm-Message-State: AOAM532lMI+AfSpw/IS2k0vTvtEEdTvG1GAr3Q/R8Nw/LU2x8sHvDket Ys+bs1vuWXKFZMdjCI8SSME= X-Google-Smtp-Source: ABdhPJw1+t0+VTE5Z1KgR5NvsAqB/97l2JikYhGdagXaCDI9/kThLjqCfKigCHnLBW71Wo9Vsmerpw== X-Received: by 2002:a05:6000:1209:: with SMTP id e9mr1654027wrx.36.1617767308453; Tue, 06 Apr 2021 20:48:28 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id l21sm5684973wmg.41.2021.04.06.20.48.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 20:48:27 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 4/4] libtracefs: tracefs_iterate_raw_events() documentation update Date: Wed, 7 Apr 2021 06:48:22 +0300 Message-Id: <20210407034822.2373958-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210407034822.2373958-1-tz.stoyanov@gmail.com> References: <20210407034822.2373958-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Updated the man page of tracefs_iterate_raw_events() API: - Fixed a typo in the function name. - Added a new sentence, describing the iteration in sorted order. Signed-off-by: Tzvetomir Stoyanov (VMware) --- Documentation/libtracefs-events.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Documentation/libtracefs-events.txt b/Documentation/libtracefs-events.txt index 9608a12..78c9834 100644 --- a/Documentation/libtracefs-events.txt +++ b/Documentation/libtracefs-events.txt @@ -37,14 +37,14 @@ local machine, or it may be a path to a copy of the tracefs directory from another machine. The last entry in the array as a NULL pointer. The array must be freed with _tracefs_list_free()_ API. -The _tracefs_interate_raw_events()_ function will read the tracefs raw +The _tracefs_iterate_raw_events()_ function will read the tracefs raw data buffers and call the specified _callback_ function for every event it -encounters. An initialized _tep_ handler is required (See -_tracefs_local_events_(3)). If _instance_ is NULL, then the toplevel -tracefs buffer is used, otherwise the buffer for the corresponding -_instance_ is read. To filter only on a subset of CPUs, _cpus_ and -_cpu_size_ may be set to only call _callback_ with events that occurred on -the CPUs specified, otherwise if _cpus_ is NULL then the _callback_ +encounters. Events are iterated in sorted order: oldest first. An initialized +_tep_ handler is required (See _tracefs_local_events_(3)). If _instance_ is +NULL, then the toplevel tracefs buffer is used, otherwise the buffer for +the corresponding _instance_ is read. To filter only on a subset of CPUs, +_cpus_ and _cpu_size_ may be set to only call _callback_ with events that +occurred on the CPUs specified, otherwise if _cpus_ is NULL then the _callback_ function will be called for all events, and _cpu_size_ is ignored. The _callback_ function will be called with the following parameters: A pointer to a struct tep_event that corresponds to the type of event the