From patchwork Wed Sep 8 10:02:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Saenz Julienne X-Patchwork-Id: 508184 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 50897C433EF for ; Wed, 8 Sep 2021 10:02:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B46B60724 for ; Wed, 8 Sep 2021 10:02:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242127AbhIHKDZ (ORCPT ); Wed, 8 Sep 2021 06:03:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54786 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231723AbhIHKDZ (ORCPT ); Wed, 8 Sep 2021 06:03:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631095337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=7np63vMuWkV60dGYkoyZGooYdzdN27SafRW+cIGzbFA=; b=bNIhMGinaPwliNv3eUWki3M7qhI3f+QvgbRfMJVk5H5WF66fbJBXESJ3a0EVLlix3lqAFn il7LKC07+kRi2/TUOfPbf5oRh8WYBGvNBBPRMDzcrNb8KM0+xq/fnO9m3uJwGPVG4sxkVI Xsjoy0+BCYO+RfnV9ZtpT7GDPXEM+hQ= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-18-UU7_5TA5OnyEUUpt-d-bew-1; Wed, 08 Sep 2021 06:02:16 -0400 X-MC-Unique: UU7_5TA5OnyEUUpt-d-bew-1 Received: by mail-wm1-f70.google.com with SMTP id f17-20020a05600c155100b002f05f30ff03so836347wmg.3 for ; Wed, 08 Sep 2021 03:02:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7np63vMuWkV60dGYkoyZGooYdzdN27SafRW+cIGzbFA=; b=Yo2gfKyVUU8xopeT2J4fNe/QTKrtgzOI4oTKnm6wbOd9Lix6JaKpgFXuhI3bYchi2V ONaxyU/auZpmtEhvIWQ1BCx0sA4yM/nZSg1k0v6MFx/BwnwpO55VoGNIBO7JrdSjSWsO NoEgmkxpsJTqSWZo9f6MTujCEtlEmJjBYmIizS0YAcC4COdLLC+4LdwHU7dHrjTu3jg+ eDfaUw/FbvU4BB/ns9oixVtA5Ber5iBqbyzNC1KOim00gocQViZ/L4Ja0c3hs12wLhmp lSQ7nLh5+28NE2rKKbeg6ZQjAOkCTm0HfqqB/g3dO/eXn1VNUYYONZBBu3H+W7gHX52U 1sDQ== X-Gm-Message-State: AOAM5303C1G2kKgfLlNCgUBfD6lF3ztBhkfCoxtqJIK+zaOeTCPCVXpa BKFeawN9BLTzeWFGxIo+VelL6nuxpytRUEzbteTxSAs7wZbfn2o2EGu11jO6z/vJ9Sg4nB+Rxo2 IfJW7ijCQhOFs5NdZgzSqTuFDDN0dJ7z//zWcIRvn0u8T4YEMAFvIxT5XKZJFQiThbJZXIpsFgf NnTKg= X-Received: by 2002:a5d:424c:: with SMTP id s12mr3086040wrr.8.1631095334803; Wed, 08 Sep 2021 03:02:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwD/OynwPP2uVeO/SFdGI1Oc92DXRzE54Gxs8tXramtnZv8IiYznyKC9MS+ckbZCxNdol5v8g== X-Received: by 2002:a5d:424c:: with SMTP id s12mr3086009wrr.8.1631095334547; Wed, 08 Sep 2021 03:02:14 -0700 (PDT) Received: from vian.redhat.com ([2a0c:5a80:3811:7600:8004:a383:c7c9:7f11]) by smtp.gmail.com with ESMTPSA id k16sm1679963wrx.87.2021.09.08.03.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:02:14 -0700 (PDT) From: Nicolas Saenz Julienne To: linux-rt-users@vger.kernel.org, peterx@redhat.com Cc: williams@redhat.com, jkacur@redhat.com, nsaenzju@redhat.com Subject: [PATCH 1/3] oslat: rename cpu_mhz/cpu_hz to timer_mhz/cpu_hz Date: Wed, 8 Sep 2021 12:02:07 +0200 Message-Id: <20210908100209.118609-1-nsaenzju@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org 'cpu_mhz' in oslat actually represents the frequency at which the high frequency timer we measure with ticks. There is no need for it to match the CPU frequency, nor will do on all supported architectures. So rename it to 'timer_mhz' in order to better match reality. Signed-off-by: Nicolas Saenz Julienne --- src/oslat/oslat.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c index 6ff5ba8..a4aa5f1 100644 --- a/src/oslat/oslat.c +++ b/src/oslat/oslat.c @@ -123,7 +123,7 @@ struct thread { pthread_t thread_id; /* NOTE! this is also how many ticks per us */ - unsigned int cpu_mhz; + unsigned int timer_mhz; cycles_t int_total; stamp_t frc_start; stamp_t frc_stop; @@ -228,7 +228,7 @@ static int move_to_core(int core_i) return sched_setaffinity(0, sizeof(cpus), &cpus); } -static cycles_t __measure_cpu_hz(void) +static cycles_t __measure_timer_hz(void) { struct timeval tvs, tve; stamp_t s, e; @@ -244,13 +244,13 @@ static cycles_t __measure_cpu_hz(void) return (cycles_t) ((e - s) / sec); } -static unsigned int measure_cpu_mhz(void) +static unsigned int measure_timer_mhz(void) { cycles_t m, mprev, d; - mprev = __measure_cpu_hz(); + mprev = __measure_timer_hz(); do { - m = __measure_cpu_hz(); + m = __measure_timer_hz(); if (m > mprev) d = m - mprev; else @@ -263,7 +263,7 @@ static unsigned int measure_cpu_mhz(void) static void thread_init(struct thread *t) { - t->cpu_mhz = measure_cpu_mhz(); + t->timer_mhz = measure_timer_mhz(); t->maxlat = 0; t->overflow_sum = 0; t->minlat = (uint64_t)-1; @@ -288,7 +288,7 @@ static void thread_init(struct thread *t) static float cycles_to_sec(const struct thread *t, uint64_t cycles) { - return cycles / (t->cpu_mhz * 1e6); + return cycles / (t->timer_mhz * 1e6); } static void insert_bucket(struct thread *t, stamp_t value) @@ -296,7 +296,7 @@ static void insert_bucket(struct thread *t, stamp_t value) int index, us; uint64_t extra; - index = value / t->cpu_mhz; + index = value / t->timer_mhz; assert(index >= 0); us = index + 1; assert(us > 0); @@ -450,7 +450,7 @@ static void write_summary(struct thread *t) calculate(t); putfield("Core", t[i].core_i, "d", ""); - putfield("CPU Freq", t[i].cpu_mhz, "u", " (Mhz)"); + putfield("Timer Freq", t[i].timer_mhz, "u", " (Mhz)"); for (j = 0; j < g.bucket_size; j++) { if (j < g.bucket_size-1 && g.output_omit_zero_buckets) { @@ -494,7 +494,7 @@ static void write_summary_json(FILE *f, void *data) for (i = 0; i < g.n_threads; ++i) { fprintf(f, " \"%u\": {\n", i); fprintf(f, " \"cpu\": %d,\n", t[i].core_i); - fprintf(f, " \"freq\": %d,\n", t[i].cpu_mhz); + fprintf(f, " \"freq\": %d,\n", t[i].timer_mhz); fprintf(f, " \"min\": %" PRIu64 ",\n", t[i].minlat); fprintf(f, " \"avg\": %3lf,\n", t[i].average); fprintf(f, " \"max\": %" PRIu64 ",\n", t[i].maxlat); From patchwork Wed Sep 8 10:02:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Saenz Julienne X-Patchwork-Id: 508183 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.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, 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 05C3FC433FE for ; Wed, 8 Sep 2021 10:02:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D805460724 for ; Wed, 8 Sep 2021 10:02:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344656AbhIHKD1 (ORCPT ); Wed, 8 Sep 2021 06:03:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35992 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244785AbhIHKD0 (ORCPT ); Wed, 8 Sep 2021 06:03:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631095338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vQO9iSkszaVOlA3tgO9wf1YTbQ1fetYfEhpRUvtLp7Q=; b=HqfQk4dr+rOQF17z8zhAF3LvgrxfD+V0SLYd9uPQSiURQT79G9ZMS4J8v52871DQxBZ2QV db1SFfzGuqAFWC33+GGpmWYKyfGfaWCn2m6y9sTEHXrUCFrzKEShQZbGvqnE2vKb+asxji NZbLiYLDVJB9chCufdORVSmVa5boK/0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-485-Weda-fanOQ2Uqpd5bKKREQ-1; Wed, 08 Sep 2021 06:02:17 -0400 X-MC-Unique: Weda-fanOQ2Uqpd5bKKREQ-1 Received: by mail-wr1-f72.google.com with SMTP id 102-20020adf82ef000000b001576e345169so353883wrc.7 for ; Wed, 08 Sep 2021 03:02:17 -0700 (PDT) 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=vQO9iSkszaVOlA3tgO9wf1YTbQ1fetYfEhpRUvtLp7Q=; b=j4+in1qPZdGX8aqmtsHfmoAHg6OvNHsY8V59Bd9WJRNeNKRMW+N8Ah+oS266pEE54E Zl2aelKwMv8R386+rrkC3cPZnrrVnhYjhFzmAK6+39e1t9QloUE4lyT7wWoWcw03crmR nc/2AzZ3SgOIdxIKkgQzPjqadfedQlDYORbnHsk+N9fDTeqjsFiwdQuAHUq3I5E52ucd IbfLsJ9op1Lxo3i2uAVC7KC2AmnvWwOhnMXu+3D5eYVDWuT7ZfZm1tEfGX1zYmBWQ8Ls +Yq5MAo8nUEuzjNKkhF5E1wEV/5cKlhdmaCx500hGe+Rk9c7uijLZvVdVGvFvivmjSx9 cSbA== X-Gm-Message-State: AOAM533pGDEM6y15Mr8dJoWcliRuTGbM3HnQaCuSs2Vp5eDUR6FNnO0N lJF5ZWQTfuM1uilSBm5dYPh5++jj4mdkrqSssewQwrLrtLSRL5ivTr0VuEzt/+S1n4Y+cb88JFb XixSD303amTT+5BOMussebRrvf8xHLVWXBsPl0dkeK9CR0KSa0ui0TbX/C9TNw4uHdWQBhcV2MS kb21A= X-Received: by 2002:a1c:7c18:: with SMTP id x24mr2634687wmc.49.1631095336201; Wed, 08 Sep 2021 03:02:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXxWXofU70T0tEjlC+/FnIg4EOQp3LkMw9btrj2CpmGDYYKf4jTXNdGC7lTuxdyesd3qLXRQ== X-Received: by 2002:a1c:7c18:: with SMTP id x24mr2634660wmc.49.1631095335941; Wed, 08 Sep 2021 03:02:15 -0700 (PDT) Received: from vian.redhat.com ([2a0c:5a80:3811:7600:8004:a383:c7c9:7f11]) by smtp.gmail.com with ESMTPSA id k16sm1679963wrx.87.2021.09.08.03.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:02:15 -0700 (PDT) From: Nicolas Saenz Julienne To: linux-rt-users@vger.kernel.org, peterx@redhat.com Cc: williams@redhat.com, jkacur@redhat.com, nsaenzju@redhat.com Subject: [PATCH 3/3] oslat: Allow for arch specific timer frequency measurements Date: Wed, 8 Sep 2021 12:02:09 +0200 Message-Id: <20210908100209.118609-3-nsaenzju@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100209.118609-1-nsaenzju@redhat.com> References: <20210908100209.118609-1-nsaenzju@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Some architectures have special purpose registers to query the system timer's frequency. Let's use that when available. Signed-off-by: Nicolas Saenz Julienne --- src/oslat/oslat.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c index bd155a6..23ca9b6 100644 --- a/src/oslat/oslat.c +++ b/src/oslat/oslat.c @@ -51,6 +51,9 @@ # define atomic_inc(ptr) __sync_add_and_fetch((ptr), 1) # if defined(__x86_64__) # define relax() __asm__ __volatile__("pause" ::: "memory") + +#define measure_timer_mhz generic_measure_timer_mhz + static inline void frc(uint64_t *pval) { uint32_t low, high; @@ -61,12 +64,18 @@ static inline void frc(uint64_t *pval) } # elif defined(__i386__) # define relax() __asm__ __volatile__("pause" ::: "memory") + +#define measure_timer_mhz generic_measure_timer_mhz + static inline void frc(uint64_t *pval) { __asm__ __volatile__("rdtsc" : "=A" (*pval)); } # elif defined(__PPC64__) # define relax() do { } while (0) + +#define measure_timer_mhz generic_measure_timer_mhz + static inline void frc(uint64_t *pval) { __asm__ __volatile__("mfspr %0, 268\n" : "=r" (*pval)); @@ -74,6 +83,15 @@ static inline void frc(uint64_t *pval) # elif defined(__aarch64__) # define relax() __asm__ __volatile("yield" : : : "memory") +static inline unsigned int measure_timer_mhz(void) +{ + unsigned int val; + + __asm__ __volatile__("mrs %0, cntfrq_el0" : "=r" (val)); + + return val / 1e6; +} + static inline void frc(uint64_t *pval) { @@ -257,7 +275,7 @@ static cycles_t __measure_timer_hz(void) return (cycles_t) ((e - s) / sec); } -static unsigned int measure_timer_mhz(void) +static unsigned int __attribute__((unused)) generic_measure_timer_mhz(void) { cycles_t m, mprev, d;