Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1676450pxy; Fri, 23 Apr 2021 14:09:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzDBAOHI2tm6s94CeRnctZx8imyBKtDE51/OGdb0qDBAVu+xUq4tyCsCtILPa7Pyv+3OoX X-Received: by 2002:aa7:dd0f:: with SMTP id i15mr6742352edv.12.1619212160297; Fri, 23 Apr 2021 14:09:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619212160; cv=none; d=google.com; s=arc-20160816; b=jdvr+Bghrk4csOdKYgcdmVJhvn4U7xCwHX0a7BJ5iVCUnESTxwsVsMne5qmNP+deGQ u94zw2ZIJuty5BD30yvjIbTOTkF2ied5lYyKS9ufi1VY7FijRMAW248owXerHNenHSMV qm6hgVo+WongBjLtD3Eht7D7fSIbxwe1S6yrhPqoJoT2cdzumqIm3Gw0+39x8Pd2I2AV dO6zYF25LOpVqe3O/yhnKmvNRmanoik7YqGIAzEByshtNKBxB4KtaqLwomGKylmHrEfV DgCRgeA8EDCA9Ov/7kjnSiBpZIruSQK0M6n/3Ced9odnWQiVR1lsDbaveKSamqBbycge 1+Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hKtcejd59fWGgV7d92DuIMwhT2ZEr2PwdDSRZUQfld4=; b=apJS+YmcXYLM8g7JIfhtL9XtfJdFSzxkq3EYBWnJHUgtcL4qDZDGpV+rWk4tDuD9fN GXnz/9sMCm96k2PBWC8uynuwmjOJc/E1hO1QEfPYqutdYVDWFh3wRauwQiUgW/4T6gI2 n6CFNsnHQpLoqeoxmIVhwfNf5I3bBO6o/YN5t+vzi0Jw4Y3HB34eiuVGIOVbvDF94qM7 5LE6MyFU2DtwdgLvjhyB7CjrBdhiHH8advIivzH+LbsZH0hsN2nHZ70S2z92RR/yuqSE Re+fZO0jUEx/GuUCnrXJ+d/geIpHDCr+uSUL2oRpvnJvCK0h5qwG36cBiTT09fFLInvw 3gvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R2opC7AJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h22si6399228eds.540.2021.04.23.14.08.57; Fri, 23 Apr 2021 14:09:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R2opC7AJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244129AbhDWVH4 (ORCPT + 99 others); Fri, 23 Apr 2021 17:07:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26618 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244070AbhDWVHh (ORCPT ); Fri, 23 Apr 2021 17:07:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619212019; 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=hKtcejd59fWGgV7d92DuIMwhT2ZEr2PwdDSRZUQfld4=; b=R2opC7AJ4RFQ2e4q/Eh7U8KN0HIBZ5/zquxHGS8qwodtGKXHTz3CmIBujgTGHvKJ+zALxc hAT75BBhc6YbiEcu+dAviyUy+vI5euv3zjHQFQptlfPyKwEyHKkuUpZX+bcE20zv/+TeeO Ti9qEzDXrOED5zYqfU8N2Dok0jXQZ+M= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-574-4iDXcDBuO1K4iJpRfLvojw-1; Fri, 23 Apr 2021 17:06:55 -0400 X-MC-Unique: 4iDXcDBuO1K4iJpRfLvojw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6FE4D10053E7; Fri, 23 Apr 2021 21:06:54 +0000 (UTC) Received: from x1.bristot.me.homenet.telecomitalia.it (ovpn-112-8.rdu2.redhat.com [10.10.112.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D0DB29175; Fri, 23 Apr 2021 21:06:47 +0000 (UTC) From: Daniel Bristot de Oliveira To: linux-kernel@vger.kernel.org Cc: Phil Auld , Sebastian Andrzej Siewior , Kate Carcia , Daniel Bristot de Oliveira , Jonathan Corbet , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexandre Chartre , Clark Willaims , John Kacur , Juri Lelli , linux-doc@vger.kernel.org Subject: [RFC PATCH V2 7/9] tracing: Add __print_ns_to_secs() and __print_ns_without_secs() helpers Date: Fri, 23 Apr 2021 23:05:42 +0200 Message-Id: <805d8a6f58c6a0008dbe4307a2c00304b18728ea.1619210818.git.bristot@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steven Rostedt To have nanosecond output displayed in a more human readable format, its nicer to convert it to a seconds format (XXX.YYYYYYYYY). The problem is that to do so, the numbers must be divided by NSEC_PER_SEC, and moded too. But as these numbers are 64 bit, this can not be done simply with '/' and '%' operators, but must use do_div() instead. Instead of performing the expensive do_div() in the hot path of the tracepoint, it is more efficient to perform it during the output phase. But passing in do_div() can confuse the parser, and do_div() doesn't work exactly like a normal C function. It modifies the number in place, and we don't want to modify the actual values in the ring buffer. Two helper functions are now created: __print_ns_to_secs() and __print_ns_without_secs() They both take a value of nanoseconds, and the former will return that number divided by NSEC_PER_SEC, and the latter will mod it with NSEC_PER_SEC giving a way to print a nice human readable format: __print_fmt("time=%llu.%09u", __print_ns_to_secs(REC->nsec_val), __print_ns_without_secs(REC->nsec_val)) Cc: Jonathan Corbet Cc: Steven Rostedt Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Alexandre Chartre Cc: Clark Willaims Cc: John Kacur Cc: Juri Lelli Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Steven Rostedt Signed-off-by: Daniel Bristot de Oliveira --- include/trace/trace_events.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h index 8268bf747d6f..c60fd1037b91 100644 --- a/include/trace/trace_events.h +++ b/include/trace/trace_events.h @@ -33,6 +33,21 @@ static const char TRACE_SYSTEM_STRING[] = \ __stringify(TRACE_SYSTEM) +#undef __print_ns_to_secs +#define __print_ns_to_secs(value) \ + ({ \ + u64 ____val = (u64)value; \ + do_div(____val, NSEC_PER_SEC); \ + ____val; \ + }) + +#undef __print_ns_without_secs +#define __print_ns_without_secs(value) \ + ({ \ + u64 ____val = (u64)value; \ + (u32) do_div(____val, NSEC_PER_SEC); \ + }) + TRACE_MAKE_SYSTEM_STR(); #undef TRACE_DEFINE_ENUM @@ -736,6 +751,16 @@ static inline void ftrace_test_probe_##call(void) \ #undef __print_array #undef __print_hex_dump +/* + * The below is not executed in the kernel. It is only what is + * displayed in the print format for userspace to parse. + */ +#undef __print_ns_to_secs +#define __print_ns_to_secs(val) val / 1000000000UL + +#undef __print_ns_without_secs +#define __print_ns_without_secs(val) val % 1000000000UL + #undef TP_printk #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args) -- 2.26.3