From patchwork Tue Jan 26 09:19:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 371040 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 0C9D2C433E6 for ; Tue, 26 Jan 2021 09:26:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D78A72310E for ; Tue, 26 Jan 2021 09:26:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390463AbhAZJ0i (ORCPT ); Tue, 26 Jan 2021 04:26:38 -0500 Received: from mx2.suse.de ([195.135.220.15]:59410 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390123AbhAZJUb (ORCPT ); Tue, 26 Jan 2021 04:20:31 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B9563B282; Tue, 26 Jan 2021 09:19:48 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [rt-tests v4 02/12] signaltest: Move thread data to struct thread_param Date: Tue, 26 Jan 2021 10:19:36 +0100 Message-Id: <20210126091946.1241-3-dwagner@suse.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210126091946.1241-1-dwagner@suse.de> References: <20210126091946.1241-1-dwagner@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Group thread realated data such as thread ID to struct thread_param. Signed-off-by: Daniel Wagner --- src/signaltest/signaltest.c | 44 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/signaltest/signaltest.c b/src/signaltest/signaltest.c index c34bc994d886..dd5633d5fc51 100644 --- a/src/signaltest/signaltest.c +++ b/src/signaltest/signaltest.c @@ -40,6 +40,10 @@ /* Struct to transfer parameters to the thread */ struct thread_param { + pthread_t thread; + pthread_t tothread; + int threadstarted; + int tid; int id; int prio; int signal; @@ -47,6 +51,7 @@ struct thread_param { struct thread_stat *stats; int bufmsk; int cpu; + int interrupted; }; /* Struct for statistics */ @@ -58,11 +63,6 @@ struct thread_stat { long act; double avg; long *values; - pthread_t thread; - pthread_t tothread; - int threadstarted; - int tid; - int interrupted; }; static int shutdown; @@ -86,7 +86,7 @@ void *signalthread(void *param) pthread_t thread; cpu_set_t mask; - stat->tid = gettid(); + par->tid = gettid(); if (par->cpu != -1) { CPU_ZERO(&mask); @@ -105,7 +105,7 @@ void *signalthread(void *param) schedp.sched_priority = par->prio; sched_setscheduler(0, policy, &schedp); - stat->threadstarted++; + par->threadstarted++; clock_gettime(CLOCK_MONOTONIC, &before); @@ -128,7 +128,7 @@ void *signalthread(void *param) /* Get current time */ clock_gettime(CLOCK_MONOTONIC, &now); - pthread_kill(stat->tothread, SIGUSR1); + pthread_kill(par->tothread, SIGUSR1); /* Skip the first cycle */ if (first) { @@ -148,7 +148,7 @@ void *signalthread(void *param) if (!stopped && tracelimit && !par->id && (diff > tracelimit)) { stat->act = diff; - stat->interrupted = 1; + par->interrupted = 1; stopped++; shutdown++; } @@ -167,7 +167,7 @@ void *signalthread(void *param) schedp.sched_priority = 0; sched_setscheduler(0, SCHED_OTHER, &schedp); - stat->threadstarted = -1; + par->threadstarted = -1; return NULL; } @@ -298,7 +298,7 @@ static void print_stat(struct thread_param *par, int index, int verbose) if (quiet != 1) { printf("T:%2d (%5d) P:%2d C:%7lu " "Min:%7ld Act:%5ld Avg:%5ld Max:%8ld\n", - index, stat->tid, par->prio, + index, par->tid, par->prio, stat->cycles, stat->min, stat->act, stat->cycles ? (long)(stat->avg/stat->cycles) : 0, stat->max); @@ -389,8 +389,8 @@ int main(int argc, char **argv) stat[i].min = 1000000; stat[i].max = -1000000; stat[i].avg = 0.0; - stat[i].threadstarted = 1; - status = pthread_create(&stat[i].thread, NULL, signalthread, + par[i].threadstarted = 1; + status = pthread_create(&par[i].thread, NULL, signalthread, &par[i]); if (status) fatal("failed to create thread %d: %s\n", i, @@ -401,18 +401,18 @@ int main(int argc, char **argv) int allstarted = 1; for (i = 0; i < num_threads; i++) { - if (stat[i].threadstarted != 2) + if (par[i].threadstarted != 2) allstarted = 0; } if (!allstarted) continue; for (i = 0; i < num_threads - 1; i++) - stat[i].tothread = stat[i+1].thread; - stat[i].tothread = stat[0].thread; + par[i].tothread = par[i+1].thread; + par[i].tothread = par[0].thread; break; } - pthread_kill(stat[0].thread, signum); + pthread_kill(par[0].thread, signum); while (!shutdown) { char lavg[256]; @@ -443,12 +443,12 @@ int main(int argc, char **argv) if (quiet) quiet = 2; for (i = 0; i < num_threads; i++) { - if (stat[i].threadstarted > 0) - pthread_kill(stat[i].thread, SIGUSR1); - if (stat[i].interrupted) + if (par[i].threadstarted > 0) + pthread_kill(par[i].thread, SIGUSR1); + if (par[i].interrupted) printf("Thread %d exceeded trace limit.\n", i); - if (stat[i].threadstarted) { - pthread_join(stat[i].thread, NULL); + if (par[i].threadstarted) { + pthread_join(par[i].thread, NULL); print_stat(&par[i], i, 0); } if (stat[i].values) From patchwork Tue Jan 26 09:19:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 371038 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 A4A50C433E0 for ; Tue, 26 Jan 2021 09:27:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 482FA23104 for ; Tue, 26 Jan 2021 09:27:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390942AbhAZJ1U (ORCPT ); Tue, 26 Jan 2021 04:27:20 -0500 Received: from mx2.suse.de ([195.135.220.15]:59422 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390160AbhAZJUb (ORCPT ); Tue, 26 Jan 2021 04:20:31 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 0BDEAB284; Tue, 26 Jan 2021 09:19:49 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [rt-tests v4 03/12] rt-utils: Add JSON common header output helper Date: Tue, 26 Jan 2021 10:19:37 +0100 Message-Id: <20210126091946.1241-4-dwagner@suse.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210126091946.1241-1-dwagner@suse.de> References: <20210126091946.1241-1-dwagner@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org rt_write_json writes the common system information header of the rt-test currently executed. Signed-off-by: Daniel Wagner --- src/include/rt-utils.h | 4 +++ src/lib/rt-utils.c | 70 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h index 39ddbd9eae29..36af92b170df 100644 --- a/src/include/rt-utils.h +++ b/src/include/rt-utils.h @@ -80,4 +80,8 @@ static inline int64_t calctime(struct timespec t) return time; } +void rt_write_json(const char *filename, int argc, char *argv[], + void (*cb)(FILE *, void *), + void *data); + #endif /* __RT_UTILS.H */ diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c index 321a11b1172d..a679bab8c595 100644 --- a/src/lib/rt-utils.c +++ b/src/lib/rt-utils.c @@ -20,6 +20,7 @@ #include #include #include /* For SYS_gettid definitions */ +#include #include "rt-utils.h" #include "rt-sched.h" @@ -482,3 +483,72 @@ void disable_trace_mark(void) { close_tracemark_fd(); } + +static char *get_cmdline(int argc, char *argv[]) +{ + char *cmdline; + int len, i; + + len = 0; + for (i = 0; i < argc; i++) + len += strlen(argv[i]) + 1; + + cmdline = malloc(len); + if (!cmdline) + err_exit(ENOMEM, "Could not copy cmdline"); + + memset(cmdline, 0, len); + for (i = 0; i < argc;) { + cmdline = strcat(cmdline, argv[i]); + i++; + if (i < argc) + cmdline = strcat(cmdline, " "); + } + + return cmdline; +} + +void rt_write_json(const char *filename, int argc, char *argv[], + void (*cb)(FILE *, void *), + void *data) +{ + struct utsname buf; + char *cmdline; + FILE *f; + + if (!strcmp("-", filename)) { + f = stdout; + } else { + f = fopen(filename, "w"); + if (!f) + err_exit(errno, "Failed to open '%s'\n", filename); + } + + cmdline = get_cmdline(argc, argv); + if (!cmdline) + err_exit(ENOMEM, "get_cmdline()"); + + if (uname(&buf)) + err_exit(errno, "Could not retrieve system information"); + + fprintf(f, "{\n"); + fprintf(f, " \"file_version\": 1,\n"); + fprintf(f, " \"cmdline:\": \"%s\",\n", cmdline); + fprintf(f, " \"rt_test_version:\": \"%1.2f\",\n", VERSION); + fprintf(f, " \"sysinfo\": {\n"); + fprintf(f, " \"sysname\": \"%s\",\n", buf.sysname); + fprintf(f, " \"nodename\": \"%s\",\n", buf.nodename); + fprintf(f, " \"release\": \"%s\",\n", buf.release); + fprintf(f, " \"version\": \"%s\",\n", buf.version); + fprintf(f, " \"machine\": \"%s\"\n", buf.machine); + fprintf(f, " },\n"); + + (cb)(f, data); + + fprintf(f, "}\n"); + + free(cmdline); + + if (strcmp("-", filename)) + fclose(f); +} From patchwork Tue Jan 26 09:19:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 371037 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 AE90FC433E0 for ; Tue, 26 Jan 2021 16:39:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7ECF522473 for ; Tue, 26 Jan 2021 16:39:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391001AbhAZJZD (ORCPT ); Tue, 26 Jan 2021 04:25:03 -0500 Received: from mx2.suse.de ([195.135.220.15]:59476 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390176AbhAZJUc (ORCPT ); Tue, 26 Jan 2021 04:20:32 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 84741B822; Tue, 26 Jan 2021 09:19:50 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [rt-tests v4 08/12] ptsematest: Add JSON output feature Date: Tue, 26 Jan 2021 10:19:42 +0100 Message-Id: <20210126091946.1241-9-dwagner@suse.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210126091946.1241-1-dwagner@suse.de> References: <20210126091946.1241-1-dwagner@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Write the test results as JSON output to a file. This allows to simplifies any parsing later on. Signed-off-by: Daniel Wagner --- src/ptsematest/ptsematest.c | 120 ++++++++++++++++++++++++++++++------ 1 file changed, 101 insertions(+), 19 deletions(-) diff --git a/src/ptsematest/ptsematest.c b/src/ptsematest/ptsematest.c index 7d4ca97773d6..2755bfde5210 100644 --- a/src/ptsematest/ptsematest.c +++ b/src/ptsematest/ptsematest.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "rt-utils.h" #include "rt-get_cpu.h" @@ -155,6 +156,7 @@ static void display_help(int error) " days.\n" "-i INTV --interval=INTV base interval of thread in us default=1000\n" "-l LOOPS --loops=LOOPS number of loops: default=0(endless)\n" + " --output=FILENAME write final results into FILENAME, JSON formatted\n" "-p PRIO --prio=PRIO priority\n" "-q --quiet print a summary only on exit\n" "-S --smp SMP testing: options -a -t and same priority\n" @@ -180,6 +182,13 @@ static int distance = 500; static int smp; static int sameprio; static int quiet; +static char outfile[MAX_PATH]; + +enum option_value { + OPT_AFFINITY=1, OPT_BREAKTRACE, OPT_DISTANCE, OPT_DURATION, + OPT_HELP, OPT_INTERVAL, OPT_LOOPS, OPT_OUTPUT, OPT_PRIORITY, + OPT_QUIET, OPT_SMP, OPT_THREADS +}; static void process_options(int argc, char *argv[]) { @@ -190,17 +199,18 @@ static void process_options(int argc, char *argv[]) int option_index = 0; /** Options for getopt */ static struct option long_options[] = { - {"affinity", optional_argument, NULL, 'a'}, - {"breaktrace", required_argument, NULL, 'b'}, - {"distance", required_argument, NULL, 'd'}, - {"duration", required_argument, NULL, 'D'}, - {"help", no_argument, NULL, 'h'}, - {"interval", required_argument, NULL, 'i'}, - {"loops", required_argument, NULL, 'l'}, - {"priority", required_argument, NULL, 'p'}, - {"quiet", no_argument , NULL, 'q'}, - {"smp", no_argument, NULL, 'S'}, - {"threads", optional_argument, NULL, 't'}, + {"affinity", optional_argument, NULL, OPT_AFFINITY}, + {"breaktrace", required_argument, NULL, OPT_BREAKTRACE}, + {"distance", required_argument, NULL, OPT_DISTANCE}, + {"duration", required_argument, NULL, OPT_DURATION}, + {"help", no_argument, NULL, OPT_HELP}, + {"interval", required_argument, NULL, OPT_INTERVAL}, + {"loops", required_argument, NULL, OPT_LOOPS}, + {"output", required_argument, NULL, OPT_OUTPUT }, + {"priority", required_argument, NULL, OPT_PRIORITY}, + {"quiet", no_argument , NULL, OPT_QUIET}, + {"smp", no_argument, NULL, OPT_SMP}, + {"threads", optional_argument, NULL, OPT_THREADS}, {NULL, 0, NULL, 0} }; int c = getopt_long (argc, argv, "a::b:d:i:l:D:p:qSt::h", @@ -208,6 +218,7 @@ static void process_options(int argc, char *argv[]) if (c == -1) break; switch (c) { + case OPT_AFFINITY: case 'a': if (smp) { warn("-a ignored due to --smp\n"); @@ -223,20 +234,49 @@ static void process_options(int argc, char *argv[]) setaffinity = AFFINITY_USEALL; } break; - case 'b': tracelimit = atoi(optarg); break; - case 'd': distance = atoi(optarg); break; - case 'D': duration = parse_time_string(optarg); break; - case 'i': interval = atoi(optarg); break; + case OPT_BREAKTRACE: + case 'b': + tracelimit = atoi(optarg); + break; + case OPT_DISTANCE: + case 'd': + distance = atoi(optarg); + break; + case OPT_DURATION: + case 'D': + duration = parse_time_string(optarg); + break; + case OPT_INTERVAL: + case 'i': + interval = atoi(optarg); + break; + case OPT_HELP: case '?': - case 'h': display_help(0); break; - case 'l': max_cycles = atoi(optarg); break; - case 'p': priority = atoi(optarg); break; - case 'q': quiet = 1; break; + case 'h': + display_help(0); + break; + case OPT_LOOPS: + case 'l': + max_cycles = atoi(optarg); + break; + case OPT_OUTPUT: + strncpy(outfile, optarg, strnlen(optarg, MAX_PATH-1)); + break; + case OPT_PRIORITY: + case 'p': + priority = atoi(optarg); + break; + case OPT_QUIET: + case 'q': + quiet = 1; + break; + case OPT_SMP: case 'S': smp = 1; num_threads = max_cpus; setaffinity = AFFINITY_USEALL; break; + case OPT_THREADS: case 't': if (smp) { warn("-t ignored due to --smp\n"); @@ -316,6 +356,40 @@ static void print_stat(FILE *fp, struct params *receiver, struct params *sender, } } +struct params_stats { + struct params *receiver; + struct params *sender; +}; + +static void write_stats(FILE *f, void *data) +{ + struct params_stats *ps = data; + struct params *s, *r; + unsigned int i; + + fprintf(f, " \"num_threads\": %d,\n", num_threads); + fprintf(f, " \"thread\": {\n"); + for (i = 0; i < num_threads; i++) { + s = &ps->sender[i]; + r = &ps->receiver[i]; + fprintf(f, " \"%u\": {\n", i); + fprintf(f, " \"sender\": {\n"); + fprintf(f, " \"cpu\": %d,\n", s->cpu); + fprintf(f, " \"priority\": %d,\n", s->priority); + fprintf(f, " \"samples\": %d,\n", s->samples); + fprintf(f, " \"interval\": %ld\n", r->delay.tv_nsec/1000); + fprintf(f, " },\n"); + fprintf(f, " \"receiver\": {\n"); + fprintf(f, " \"cpu\": %d,\n", r->cpu); + fprintf(f, " \"priority\": %d,\n", r->priority); + fprintf(f, " \"min\": %d,\n", r->mindiff); + fprintf(f, " \"avg\": %.2f,\n", r->sumdiff/r->samples); + fprintf(f, " \"max\": %d\n", r->maxdiff); + fprintf(f, " }\n"); + fprintf(f, " }%s\n", i == num_threads - 1 ? "" : ","); + } + fprintf(f, " }\n"); +} int main(int argc, char *argv[]) { @@ -439,6 +513,14 @@ int main(int argc, char *argv[]) pthread_mutex_destroy(&syncmutex[i]); } + if (strlen(outfile) != 0) { + struct params_stats ps = { + .receiver = receiver, + .sender = sender, + }; + rt_write_json(outfile, argc, argv, write_stats, &ps); + } + nomem: return 0; From patchwork Tue Jan 26 09:19:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 371041 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 98B60C433E0 for ; Tue, 26 Jan 2021 09:25:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50E7023104 for ; Tue, 26 Jan 2021 09:25:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390896AbhAZJYp (ORCPT ); Tue, 26 Jan 2021 04:24:45 -0500 Received: from mx2.suse.de ([195.135.220.15]:59490 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390194AbhAZJUc (ORCPT ); Tue, 26 Jan 2021 04:20:32 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id CF72CB8F1; Tue, 26 Jan 2021 09:19:50 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [rt-tests v4 09/12] sigwaittest: Add JSON output feature Date: Tue, 26 Jan 2021 10:19:43 +0100 Message-Id: <20210126091946.1241-10-dwagner@suse.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210126091946.1241-1-dwagner@suse.de> References: <20210126091946.1241-1-dwagner@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Write the test results as JSON output to a file. This allows to simplifies any parsing later on. Signed-off-by: Daniel Wagner --- src/sigwaittest/sigwaittest.c | 117 ++++++++++++++++++++++++++++------ 1 file changed, 99 insertions(+), 18 deletions(-) diff --git a/src/sigwaittest/sigwaittest.c b/src/sigwaittest/sigwaittest.c index f10c24914d4a..0cdf30a6a769 100644 --- a/src/sigwaittest/sigwaittest.c +++ b/src/sigwaittest/sigwaittest.c @@ -39,6 +39,7 @@ #include #include #include +#include #include "rt-utils.h" #include "rt-get_cpu.h" @@ -220,6 +221,7 @@ static void display_help(int error) "-f [OPT] --fork[=OPT] fork new processes instead of creating threads\n" "-i INTV --interval=INTV base interval of thread in us default=1000\n" "-l LOOPS --loops=LOOPS number of loops: default=0(endless)\n" + " --output=FILENAME write final results into FILENAME, JSON formatted\n" "-p PRIO --prio=PRIO priority\n" "-q --quiet print a summary only on exit\n" "-t --threads one thread per available processor\n" @@ -240,6 +242,13 @@ static int duration; static int interval = 1000; static int distance = 500; static int quiet; +static char outfile[MAX_PATH]; + +enum option_value { + OPT_AFFINITY=1, OPT_BREAKTRACE, OPT_DISTANCE, OPT_DURATION, + OPT_FORK, OPT_HELP, OPT_INTERVAL, OPT_LOOPS, OPT_OUTPUT, + OPT_PRIORITY, OPT_QUIET, OPT_THREADS +}; static void process_options(int argc, char *argv[]) { @@ -251,17 +260,18 @@ static void process_options(int argc, char *argv[]) int option_index = 0; /** Options for getopt */ static struct option long_options[] = { - {"affinity", optional_argument, NULL, 'a'}, - {"breaktrace", required_argument, NULL, 'b'}, - {"distance", required_argument, NULL, 'd'}, - {"duration", required_argument, NULL, 'D'}, - {"fork", optional_argument, NULL, 'f'}, - {"help", no_argument, NULL, 'h'}, - {"interval", required_argument, NULL, 'i'}, - {"loops", required_argument, NULL, 'l'}, - {"priority", required_argument, NULL, 'p'}, - {"quiet", no_argument, NULL, 'q'}, - {"threads", optional_argument, NULL, 't'}, + {"affinity", optional_argument, NULL, OPT_AFFINITY}, + {"breaktrace", required_argument, NULL, OPT_BREAKTRACE}, + {"distance", required_argument, NULL, OPT_DISTANCE}, + {"duration", required_argument, NULL, OPT_DURATION}, + {"fork", optional_argument, NULL, OPT_FORK}, + {"help", no_argument, NULL, OPT_HELP}, + {"interval", required_argument, NULL, OPT_INTERVAL}, + {"loops", required_argument, NULL, OPT_LOOPS}, + {"output", required_argument, NULL, OPT_OUTPUT }, + {"priority", required_argument, NULL, OPT_PRIORITY}, + {"quiet", no_argument, NULL, OPT_QUIET}, + {"threads", optional_argument, NULL, OPT_THREADS}, {NULL, 0, NULL, 0} }; int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:qt::", @@ -269,6 +279,7 @@ static void process_options(int argc, char *argv[]) if (c == -1) break; switch (c) { + case OPT_AFFINITY: case 'a': if (optarg != NULL) { affinity = atoi(optarg); @@ -280,9 +291,19 @@ static void process_options(int argc, char *argv[]) setaffinity = AFFINITY_USEALL; } break; - case 'b': thistracelimit = atoi(optarg); break; - case 'd': distance = atoi(optarg); break; - case 'D': duration = parse_time_string(optarg); break; + case OPT_BREAKTRACE: + case 'b': + thistracelimit = atoi(optarg); + break; + case OPT_DISTANCE: + case 'd': + distance = atoi(optarg); + break; + case OPT_DURATION: + case 'D': + duration = parse_time_string(optarg); + break; + case OPT_FORK: case 'f': if (optarg != NULL) { wasforked = 1; @@ -294,14 +315,31 @@ static void process_options(int argc, char *argv[]) } else mustfork = 1; break; + case OPT_HELP: case '?': case 'h': display_help(0); break; - case 'i': interval = atoi(optarg); break; - case 'l': max_cycles = atoi(optarg); break; - case 'p': priority = atoi(optarg); break; - case 'q': quiet = 1; break; + case OPT_INTERVAL: + case 'i': + interval = atoi(optarg); + break; + case OPT_LOOPS: + case 'l': + max_cycles = atoi(optarg); + break; + case OPT_OUTPUT: + strncpy(outfile, optarg, strnlen(optarg, MAX_PATH-1)); + break; + case OPT_PRIORITY: + case 'p': + priority = atoi(optarg); + break; + case OPT_QUIET: + case 'q': + quiet = 1; + break; + case OPT_THREADS: case 't': if (optarg != NULL) num_threads = atoi(optarg); @@ -388,6 +426,41 @@ static void print_stat(FILE *fp, struct params *receiver, struct params *sender, } } +struct params_stats { + struct params *receiver; + struct params *sender; +}; + +static void write_stats(FILE *f, void *data) +{ + struct params_stats *ps = data; + struct params *s, *r; + unsigned int i; + + fprintf(f, " \"num_threads\": %d,\n", num_threads); + fprintf(f, " \"thread\": {\n"); + for (i = 0; i < num_threads; i++) { + s = &ps->sender[i]; + r = &ps->receiver[i]; + fprintf(f, " \"%u\": {\n", i); + fprintf(f, " \"sender\": {\n"); + fprintf(f, " \"cpu\": %d,\n", s->cpu); + fprintf(f, " \"priority\": %d,\n", s->priority); + fprintf(f, " \"samples\": %d,\n", s->samples); + fprintf(f, " \"interval\": %ld\n", r->delay.tv_nsec/1000); + fprintf(f, " },\n"); + fprintf(f, " \"receiver\": {\n"); + fprintf(f, " \"cpu\": %d,\n", r->cpu); + fprintf(f, " \"priority\": %d,\n", r->priority); + fprintf(f, " \"min\": %d,\n", r->mindiff); + fprintf(f, " \"avg\": %.2f,\n", r->sumdiff/r->samples); + fprintf(f, " \"max\": %d\n", r->maxdiff); + fprintf(f, " }\n"); + fprintf(f, " }%s\n", i == num_threads - 1 ? "" : ","); + } + fprintf(f, " }\n"); +} + int main(int argc, char *argv[]) { int i, totalsize = 0; @@ -627,6 +700,14 @@ int main(int argc, char *argv[]) } } + if (strlen(outfile) != 0) { + struct params_stats ps = { + .receiver = receiver, + .sender = sender, + }; + rt_write_json(outfile, argc, argv, write_stats, &ps); + } + nomem: if (mustfork) { munmap(param, totalsize); From patchwork Tue Jan 26 09:19:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 371036 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=-13.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, 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 8C970C433E0 for ; Tue, 26 Jan 2021 16:39:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C58322273 for ; Tue, 26 Jan 2021 16:39:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730766AbhAZJXi (ORCPT ); Tue, 26 Jan 2021 04:23:38 -0500 Received: from mx2.suse.de ([195.135.220.15]:57504 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389828AbhAZJUL (ORCPT ); Tue, 26 Jan 2021 04:20:11 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B4DA6B90F; Tue, 26 Jan 2021 09:19:51 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [rt-tests v4 12/12] rt-migrate-test: Add JSON output feature Date: Tue, 26 Jan 2021 10:19:46 +0100 Message-Id: <20210126091946.1241-13-dwagner@suse.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210126091946.1241-1-dwagner@suse.de> References: <20210126091946.1241-1-dwagner@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Write the test results as JSON output to a file. This allows to simplifies any parsing later on. Signed-off-by: Daniel Wagner --- src/rt-migrate-test/rt-migrate-test.c | 118 +++++++++++++++++++++----- 1 file changed, 99 insertions(+), 19 deletions(-) diff --git a/src/rt-migrate-test/rt-migrate-test.c b/src/rt-migrate-test/rt-migrate-test.c index 9bf716c9178c..9d34b3c7da52 100644 --- a/src/rt-migrate-test/rt-migrate-test.c +++ b/src/rt-migrate-test/rt-migrate-test.c @@ -19,11 +19,12 @@ #include #include #include -#include #include #include #include #include +#include + #include "rt-utils.h" int nr_tasks; @@ -99,6 +100,7 @@ static int done; static int loop; static int duration; static int quiet; +static char outfile[MAX_PATH]; static pthread_barrier_t start_barrier; static pthread_barrier_t end_barrier; @@ -160,6 +162,7 @@ static void usage(int error) "-h --help Print this help message\n" "-l LOOPS --loops=LOOPS Number of iterations to run (50)\n" "-m TIME --maxerr=TIME Max allowed error (microsecs)\n" + " --output=FILENAME write final results into FILENAME, JSON formatted\n" "-p PRIO --prio=PRIO base priority to start RT tasks with (2)\n" "-q --quiet print a summary only on exit\n" "-r TIME --run-time=TIME Run time (ms) to busy loop the threads (20)\n" @@ -169,22 +172,29 @@ static void usage(int error) exit(error); } +enum option_value { + OPT_CHECK=1, OPT_DURATION, OPT_EQUAL, OPT_HELP, OPT_LOOPS, + OPT_MAXERR, OPT_OUTPUT, OPT_PRIO, OPT_QUIET, OPT_RUN_TIME, + OPT_SLEEP_TIME +}; + static void parse_options(int argc, char *argv[]) { for (;;) { int option_index = 0; /** Options for getopt */ static struct option long_options[] = { - {"check", no_argument, NULL, 'c'}, - {"duration", required_argument, NULL, 'D'}, - {"equal", no_argument, NULL, 'e'}, - {"help", no_argument, NULL, 'h'}, - {"loops", required_argument, NULL, 'l'}, - {"maxerr", required_argument, NULL, 'm'}, - {"prio", required_argument, NULL, 'p'}, - {"quiet", no_argument, NULL, 'q'}, - {"run-time", required_argument, NULL, 'r'}, - {"sleep-time", required_argument, NULL, 's'}, + {"check", no_argument, NULL, OPT_CHECK}, + {"duration", required_argument, NULL, OPT_DURATION}, + {"equal", no_argument, NULL, OPT_EQUAL}, + {"help", no_argument, NULL, OPT_HELP}, + {"loops", required_argument, NULL, OPT_LOOPS}, + {"maxerr", required_argument, NULL, OPT_MAXERR}, + {"output", required_argument, NULL, OPT_OUTPUT }, + {"prio", required_argument, NULL, OPT_PRIO}, + {"quiet", no_argument, NULL, OPT_QUIET}, + {"run-time", required_argument, NULL, OPT_RUN_TIME}, + {"sleep-time", required_argument, NULL, OPT_SLEEP_TIME}, {NULL, 0, NULL, 0} }; int c = getopt_long(argc, argv, "cD:ehl:m:p:qr:s:", @@ -192,21 +202,50 @@ static void parse_options(int argc, char *argv[]) if (c == -1) break; switch (c) { - case 'c': check = 1; break; - case 'D': duration = parse_time_string(optarg); break; - case 'e': equal = 1; break; + case OPT_CHECK: + case 'c': + check = 1; + break; + case OPT_DURATION: + case 'D': + duration = parse_time_string(optarg); + break; + case OPT_EQUAL: + case 'e': + equal = 1; + break; + case OPT_HELP: case '?': case 'h': usage(0); break; - case 'l': nr_runs = atoi(optarg); break; - case 'm': max_err = usec2nano(atoi(optarg)); break; - case 'p': prio_start = atoi(optarg); break; - case 'q': quiet = 1; break; + case OPT_LOOPS: + case 'l': + nr_runs = atoi(optarg); + break; + case OPT_MAXERR: + case 'm': + max_err = usec2nano(atoi(optarg)); + break; + case OPT_OUTPUT: + strncpy(outfile, optarg, strnlen(optarg, MAX_PATH-1)); + break; + case OPT_PRIO: + case 'p': + prio_start = atoi(optarg); + break; + case OPT_QUIET: + case 'q': + quiet = 1; + break; + case OPT_RUN_TIME: case 'r': run_interval = atoi(optarg); break; - case 's': interval = atoi(optarg); break; + case OPT_SLEEP_TIME: + case 's': + interval = atoi(optarg); + break; default: usage(1); } @@ -313,6 +352,44 @@ static void print_results(void) } } +static void write_stats(FILE *f, void *data) +{ + int i; + int t; + unsigned long long tasks_max[nr_tasks]; + unsigned long long tasks_min[nr_tasks]; + unsigned long long tasks_avg[nr_tasks]; + + memset(tasks_max, 0, sizeof(tasks_max[0])*nr_tasks); + memset(tasks_min, 0xff, sizeof(tasks_min[0])*nr_tasks); + memset(tasks_avg, 0, sizeof(tasks_avg[0])*nr_tasks); + + for (i=0; i < nr_runs; i++) { + for (t=0; t < nr_tasks; t++) { + unsigned long long itv = intervals[i][t]; + + if (tasks_max[t] < itv) + tasks_max[t] = itv; + if (tasks_min[t] > itv) + tasks_min[t] = itv; + tasks_avg[t] += itv; + } + } + + fprintf(f, " \"num_threads\": %d,\n", nr_tasks); + fprintf(f, " \"thread\": {\n"); + for (i = 0; i < nr_tasks; i++) { + fprintf(f, " \"%u\": {\n", i); + fprintf(f, " \"prio\": %d,\n", calc_prio(i)); + fprintf(f, " \"min\": %lld,\n", nano2usec(tasks_min[i])); + fprintf(f, " \"avg\": %lld,\n", nano2usec(tasks_avg[i]) / nr_runs); + fprintf(f, " \"max\": %lld,\n", nano2usec(tasks_max[i])); + fprintf(f, " \"total\": %lld\n", nano2usec(tasks_avg[i])); + fprintf(f, " }%s\n", i == nr_tasks - 1 ? "" : ","); + } + fprintf(f, " }\n"); +} + static unsigned long busy_loop(unsigned long long start_time) { unsigned long long time; @@ -582,6 +659,9 @@ int main (int argc, char **argv) print_results(); + if (strlen(outfile) != 0) + rt_write_json(outfile, argc, argv, write_stats, NULL); + if (stop) { /* * We use this test in bash while loops