From patchwork Mon Jan 11 17:33:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 360771 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 60AFBC433E9 for ; Mon, 11 Jan 2021 17:34:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 383E722C97 for ; Mon, 11 Jan 2021 17:34:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389606AbhAKRek (ORCPT ); Mon, 11 Jan 2021 12:34:40 -0500 Received: from mx2.suse.de ([195.135.220.15]:50976 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388795AbhAKRek (ORCPT ); Mon, 11 Jan 2021 12:34:40 -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 0C920ADCD; Mon, 11 Jan 2021 17:33:59 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [RFC v2 2/6] cyclictest: Move thread data to struct thread_param Date: Mon, 11 Jan 2021 18:33:47 +0100 Message-Id: <20210111173351.4971-3-dwagner@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210111173351.4971-1-dwagner@suse.de> References: <20210111173351.4971-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/cyclictest/cyclictest.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index 9225e52aa982..c0e7600b4740 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -113,6 +113,9 @@ static char *policyname(int policy); /* Struct to transfer parameters to the thread */ struct thread_param { + pthread_t thread; + int threadstarted; + int tid; int prio; int policy; int mode; @@ -141,9 +144,6 @@ struct thread_stat { long *smis; long *hist_array; long *outliers; - pthread_t thread; - int threadstarted; - int tid; long reduce; long redmax; long cycleofmax; @@ -530,7 +530,7 @@ static void *timerthread(void *param) interval.tv_sec = par->interval / USEC_PER_SEC; interval.tv_nsec = (par->interval % USEC_PER_SEC) * 1000; - stat->tid = gettid(); + par->tid = gettid(); sigemptyset(&sigset); sigaddset(&sigset, par->signal); @@ -539,7 +539,7 @@ static void *timerthread(void *param) if (par->mode == MODE_CYCLIC) { sigev.sigev_notify = SIGEV_THREAD_ID | SIGEV_SIGNAL; sigev.sigev_signo = par->signal; - sigev.sigev_notify_thread_id = stat->tid; + sigev.sigev_notify_thread_id = par->tid; timer_create(par->clock, &sigev, &timer); tspec.it_interval = interval; } @@ -613,7 +613,7 @@ static void *timerthread(void *param) setitimer(ITIMER_REAL, &itimer, NULL); } - stat->threadstarted++; + par->threadstarted++; while (!shutdown) { @@ -719,7 +719,7 @@ static void *timerthread(void *param) shutdown++; pthread_mutex_lock(&break_thread_id_lock); if (break_thread_id == 0) { - break_thread_id = stat->tid; + break_thread_id = par->tid; tracemark("hit latency threshold (%llu > %d)", (unsigned long long) diff, tracelimit); break_thread_value = diff; @@ -795,7 +795,7 @@ static void *timerthread(void *param) /* switch to normal */ schedp.sched_priority = 0; sched_setscheduler(0, SCHED_OTHER, &schedp); - stat->threadstarted = -1; + par->threadstarted = -1; return NULL; } @@ -1298,7 +1298,7 @@ static void print_tids(struct thread_param *par[], int nthreads) printf("# Thread Ids:"); for (i = 0; i < nthreads; i++) - printf(" %05d", par[i]->stats->tid); + printf(" %05d", par[i]->tid); printf("\n"); } @@ -1412,7 +1412,7 @@ static void print_stat(FILE *fp, struct thread_param *par, int index, int verbos fmt = "T:%2d (%5d) P:%2d I:%ld C:%7lu " "Min:%7ld Act:%5ld Avg:%5ld Max:%8ld"; - fprintf(fp, fmt, index, stat->tid, par->prio, + fprintf(fp, fmt, index, par->tid, par->prio, par->interval, stat->cycles, stat->min, stat->act, stat->cycles ? (long)(stat->avg/stat->cycles) : 0, stat->max); @@ -1468,7 +1468,7 @@ static void rstat_print_stat(struct thread_param *par, int index, int verbose, i fmt = "T:%2d (%5d) P:%2d I:%ld C:%7lu " "Min:%7ld Act:%5ld Avg:%5ld Max:%8ld"; - dprintf(fd, fmt, index, stat->tid, par->prio, + dprintf(fd, fmt, index, par->tid, par->prio, par->interval, stat->cycles, stat->min, stat->act, stat->cycles ? (long)(stat->avg/stat->cycles) : 0, stat->max); @@ -1969,9 +1969,9 @@ int main(int argc, char **argv) stat->min = 1000000; stat->max = 0; stat->avg = 0.0; - stat->threadstarted = 1; stat->smi_count = 0; - status = pthread_create(&stat->thread, &attr, timerthread, par); + par->threadstarted = 1; + status = pthread_create(&par->thread, &attr, timerthread, par); if (status) fatal("failed to create thread %d: %s\n", i, strerror(status)); @@ -2041,10 +2041,10 @@ int main(int argc, char **argv) if (quiet) quiet = 2; for (i = 0; i < num_threads; i++) { - if (statistics[i]->threadstarted > 0) - pthread_kill(statistics[i]->thread, SIGTERM); - if (statistics[i]->threadstarted) { - pthread_join(statistics[i]->thread, NULL); + if (parameters[i]->threadstarted > 0) + pthread_kill(parameters[i]->thread, SIGTERM); + if (parameters[i]->threadstarted) { + pthread_join(parameters[i]->thread, NULL); if (quiet && !histogram) print_stat(stdout, parameters[i], i, 0, 0); } From patchwork Mon Jan 11 17:33:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 360770 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 C2227C4332D for ; Mon, 11 Jan 2021 17:34:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 885C522CAD for ; Mon, 11 Jan 2021 17:34:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389609AbhAKRem (ORCPT ); Mon, 11 Jan 2021 12:34:42 -0500 Received: from mx2.suse.de ([195.135.220.15]:51010 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389493AbhAKRel (ORCPT ); Mon, 11 Jan 2021 12:34:41 -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 A81EFAE1F; Mon, 11 Jan 2021 17:33:59 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [RFC v2 4/6] rt-utils: Add JSON common header output helper Date: Mon, 11 Jan 2021 18:33:49 +0100 Message-Id: <20210111173351.4971-5-dwagner@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210111173351.4971-1-dwagner@suse.de> References: <20210111173351.4971-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. Reviewed-by: Daniel Wagner --- src/include/rt-utils.h | 4 +++ src/lib/rt-utils.c | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h index 39ddbd9eae29..ca9984d7cf35 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(FILE *f, 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..8fe0b7ed1f63 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,60 @@ 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"); + + cmdline[0] = '\0'; + for (i = 0; i < argc;) { + cmdline = strcat(cmdline, argv[i]); + i++; + if (i < argc) + cmdline = strcat(cmdline, " "); + } + + return cmdline; +} + +void rt_write_json(FILE *f, int argc, char *argv[], + void (*cb)(FILE *, void *), + void *data) +{ + struct utsname buf; + char *cmdline; + + 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); +} From patchwork Mon Jan 11 17:33:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 360769 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 93A64C433E9 for ; Mon, 11 Jan 2021 17:36:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6024D22BEF for ; Mon, 11 Jan 2021 17:36:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389676AbhAKRf2 (ORCPT ); Mon, 11 Jan 2021 12:35:28 -0500 Received: from mx2.suse.de ([195.135.220.15]:51206 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389459AbhAKRfW (ORCPT ); Mon, 11 Jan 2021 12:35:22 -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 00FC6AE5C; Mon, 11 Jan 2021 17:34:00 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [RFC v2 5/6] cyclictest: Add JSON output feature Date: Mon, 11 Jan 2021 18:33:50 +0100 Message-Id: <20210111173351.4971-6-dwagner@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210111173351.4971-1-dwagner@suse.de> References: <20210111173351.4971-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/cyclictest/cyclictest.c | 51 ++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index c0e7600b4740..d746e822be72 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -217,6 +218,7 @@ static struct timespec globalt; static char fifopath[MAX_PATH]; static char histfile[MAX_PATH]; +static char outfile[MAX_PATH]; static struct thread_param **parameters; static struct thread_stat **statistics; @@ -843,6 +845,7 @@ static void display_help(int error) " latency is hit. Useful for low bandwidth.\n" "-N --nsecs print results in ns instead of us (default us)\n" "-o RED --oscope=RED oscilloscope mode, reduce verbose output by RED\n" + " --output=FILENAME write final results into FILENAME, JSON formatted\n" "-p PRIO --priority=PRIO priority of highest prio thread\n" " --policy=NAME policy of measurement thread, where NAME may be one\n" " of: other, normal, batch, idle, fifo or rr.\n" @@ -950,7 +953,7 @@ enum option_values { OPT_TRIGGER_NODES, OPT_UNBUFFERED, OPT_NUMA, OPT_VERBOSE, OPT_DBGCYCLIC, OPT_POLICY, OPT_HELP, OPT_NUMOPTS, OPT_ALIGNED, OPT_SECALIGNED, OPT_LAPTOP, OPT_SMI, - OPT_TRACEMARK, OPT_POSIX_TIMERS, + OPT_TRACEMARK, OPT_POSIX_TIMERS, OPT_OUTPUT }; /* Process commandline options */ @@ -984,6 +987,7 @@ static void process_options(int argc, char *argv[]) {"refresh_on_max", no_argument, NULL, OPT_REFRESH }, {"nsecs", no_argument, NULL, OPT_NSECS }, {"oscope", required_argument, NULL, OPT_OSCOPE }, + {"output", required_argument, NULL, OPT_OUTPUT }, {"priority", required_argument, NULL, OPT_PRIORITY }, {"quiet", no_argument, NULL, OPT_QUIET }, {"priospread", no_argument, NULL, OPT_PRIOSPREAD }, @@ -1078,6 +1082,9 @@ static void process_options(int argc, char *argv[]) case 'o': case OPT_OSCOPE: oscope_reduction = atoi(optarg); break; + case OPT_OUTPUT: + strncpy(outfile, optarg, strnlen(optarg, MAX_PATH-1)); + break; case 'p': case OPT_PRIORITY: priority = atoi(optarg); @@ -1695,6 +1702,40 @@ static void rstat_setup(void) return; } +static void write_stats(FILE *f, void *data) +{ + struct thread_param **par = parameters; + unsigned int i, j, comma; + struct thread_stat *s; + + fprintf(f, " \"num_threads\": %d,\n", num_threads); + fprintf(f, " \"resolution_in_ns\": %u,\n", use_nsecs); + fprintf(f, " \"thread\": {\n"); + for (i = 0; i < num_threads; i++) { + fprintf(f, " \"%u\": {\n", i); + + fprintf(f, " \"histogram\": {"); + s = par[i]->stats; + for (j = 0, comma = 0; j < histogram; j++) { + if (s->hist_array[j] == 0) + continue; + fprintf(f, "%s", comma ? ",\n" : "\n"); + fprintf(f, " \"%u\": %" PRIu64,j, s->hist_array[j]); + comma = 1; + } + if (comma) + fprintf(f, "\n"); + fprintf(f, " },\n"); + fprintf(f, " \"cycles\": %" PRIu64 ",\n", s->cycles); + fprintf(f, " \"min\": %" PRIu64 ",\n", s->min); + fprintf(f, " \"max\": %" PRIu64 ",\n", s->max); + fprintf(f, " \"avg\": %.2f,\n", s->avg/s->cycles); + fprintf(f, " \"cpu\": %d,\n", par[i]->cpu); + fprintf(f, " \"node\": %d\n", par[i]->node); + fprintf(f, " }%s\n", i == num_threads - 1 ? "" : ","); + } + fprintf(f, " }\n"); +} int main(int argc, char **argv) { @@ -2038,6 +2079,14 @@ int main(int argc, char **argv) if (!verbose && !quiet && refresh_on_max) printf("\033[%dB", num_threads + 2); + if (strlen(outfile) != 0) { + FILE *f = fopen(outfile, "w"); + if (!f) + err_exit(errno, "Failed to open output file '%s'", outfile); + rt_write_json(f, argc, argv, write_stats, NULL); + fclose(f); + } + if (quiet) quiet = 2; for (i = 0; i < num_threads; i++) {