From patchwork Sat Dec 16 04:22:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 179814 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp30574dyi; Fri, 15 Dec 2023 20:25:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IENRYqsgRzk/HlQin3dcvsFMBZuyeu5L8AAceL6Mz7e17/CeDMXycr8MU6eHLShIBHJ9wVB X-Received: by 2002:a50:8701:0:b0:552:fc86:d417 with SMTP id i1-20020a508701000000b00552fc86d417mr148385edb.15.1702700725368; Fri, 15 Dec 2023 20:25:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702700725; cv=none; d=google.com; s=arc-20160816; b=yqrlkXGLm0tEawlSwiW7FDkdQ/EwWfr8nmnCqE7i+/0haMvVEGfj1WrgaWPH9T+mr3 iQGD74Kpjmb1A0mpY9/0QDQl6infqT6bVnKYLmw5hsVg1v3kkJj3vJTfstQjoJ+JNHe/ OnK+Q5XNndLvnDpcvTkPj3WR/RoRyyGPl7Bi2tbSko7ltwIj8sNQzqXInbDKgJZXXEFL lHM0hLa1TyeVWQ/3te51zFTNbKNaeBsuz9eVGOcxUULYtM55A53PyrybgUuOX6//i+5+ GDcMgvzxER+ntoswc9SAPcIPSv2hSUvk0AVbjspWztqi4PMnlLvOAsdA8eOZxFm5RdsX 3j5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=eRXNISRySPQ9ooYh5iHpeBHMLEX0jQCUguba0gV5XLQ=; fh=dSbO5nrudX1o1/5h1aiDXadU1yIdyz7bM/pnn0K5lFA=; b=BANCy1MHqBmCiL+GJA6KpwAt+1uE99Dfqa2wQNvsdxsg941PPq1+d7VZoMlE2YsIeF WnbLBH24JUDaAfTJ8ciE+LR++OXMcxpR0G6+hbd5h20jUYpiVAaSF60T3oJ0yV8FZlM5 770JmRwlCErhv92tzdeDTr1DXEE5sjcYUooAJuBUuuUqU8Gj6m3yjXvNRiwle/uCd3vb odTgwU6nz1HCgrvraT/7ff4kYZhLGV0+LzO7b7GjNQR+7ewIb5kDC7d9D02hgSGFWSQZ aOM4L0GxY04Yab8d/ayK9xd91xfE9ITP3ThmwI6jbtQdyQi/ofXYNvqKJe0vRDfcMVPM HmlA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-2054-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2054-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d25-20020a50cd59000000b0054cb7887a54si8355477edj.119.2023.12.15.20.25.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 20:25:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2054-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-2054-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2054-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BF7401F25CF8 for ; Sat, 16 Dec 2023 04:25:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06B2033094; Sat, 16 Dec 2023 04:21:56 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C1F01A28A for ; Sat, 16 Dec 2023 04:21:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C31EC116B4; Sat, 16 Dec 2023 04:21:54 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rEMCL-00000002yFl-0EfZ; Fri, 15 Dec 2023 23:22:45 -0500 Message-ID: <20231216042244.832048983@goodmis.org> User-Agent: quilt/0.67 Date: Fri, 15 Dec 2023 23:22:25 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Joel Fernandes , Vincent Donnefort Subject: [for-linus][PATCH 11/15] ring-buffer: Remove useless update to write_stamp in rb_try_to_discard() References: <20231216042214.905262999@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785411115727326820 X-GMAIL-MSGID: 1785411115727326820 From: "Steven Rostedt (Google)" When filtering is enabled, a temporary buffer is created to place the content of the trace event output so that the filter logic can decide from the trace event output if the trace event should be filtered out or not. If it is to be filtered out, the content in the temporary buffer is simply discarded, otherwise it is written into the trace buffer. But if an interrupt were to come in while a previous event was using that temporary buffer, the event written by the interrupt would actually go into the ring buffer itself to prevent corrupting the data on the temporary buffer. If the event is to be filtered out, the event in the ring buffer is discarded, or if it fails to discard because another event were to have already come in, it is turned into padding. The update to the write_stamp in the rb_try_to_discard() happens after a fix was made to force the next event after the discard to use an absolute timestamp by setting the before_stamp to zero so it does not match the write_stamp (which causes an event to use the absolute timestamp). But there's an effort in rb_try_to_discard() to put back the write_stamp to what it was before the event was added. But this is useless and wasteful because nothing is going to be using that write_stamp for calculations as it still will not match the before_stamp. Remove this useless update, and in doing so, we remove another cmpxchg64()! Also update the comments to reflect this change as well as remove some extra white space in another comment. Link: https://lore.kernel.org/linux-trace-kernel/20231215081810.1f4f38fe@rorschach.local.home Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Joel Fernandes Cc: Vincent Donnefort Fixes: b2dd797543cf ("ring-buffer: Force absolute timestamp on discard of event") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ring_buffer.c | 47 +++++++++----------------------------- 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 2668dde23343..ad4af0cba159 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -2983,25 +2983,6 @@ static unsigned rb_calculate_event_length(unsigned length) return length; } -static u64 rb_time_delta(struct ring_buffer_event *event) -{ - switch (event->type_len) { - case RINGBUF_TYPE_PADDING: - return 0; - - case RINGBUF_TYPE_TIME_EXTEND: - return rb_event_time_stamp(event); - - case RINGBUF_TYPE_TIME_STAMP: - return 0; - - case RINGBUF_TYPE_DATA: - return event->time_delta; - default: - return 0; - } -} - static inline bool rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer, struct ring_buffer_event *event) @@ -3009,8 +2990,6 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer, unsigned long new_index, old_index; struct buffer_page *bpage; unsigned long addr; - u64 write_stamp; - u64 delta; new_index = rb_event_index(event); old_index = new_index + rb_event_ts_length(event); @@ -3019,14 +2998,10 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer, bpage = READ_ONCE(cpu_buffer->tail_page); - delta = rb_time_delta(event); - - if (!rb_time_read(&cpu_buffer->write_stamp, &write_stamp)) - return false; - - /* Make sure the write stamp is read before testing the location */ - barrier(); - + /* + * Make sure the tail_page is still the same and + * the next write location is the end of this event + */ if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) { unsigned long write_mask = local_read(&bpage->write) & ~RB_WRITE_MASK; @@ -3037,20 +3012,20 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer, * to make sure that the next event adds an absolute * value and does not rely on the saved write stamp, which * is now going to be bogus. + * + * By setting the before_stamp to zero, the next event + * is not going to use the write_stamp and will instead + * create an absolute timestamp. This means there's no + * reason to update the wirte_stamp! */ rb_time_set(&cpu_buffer->before_stamp, 0); - /* Something came in, can't discard */ - if (!rb_time_cmpxchg(&cpu_buffer->write_stamp, - write_stamp, write_stamp - delta)) - return false; - /* * If an event were to come in now, it would see that the * write_stamp and the before_stamp are different, and assume * that this event just added itself before updating * the write stamp. The interrupting event will fix the - * write stamp for us, and use the before stamp as its delta. + * write stamp for us, and use an absolute timestamp. */ /* @@ -3487,7 +3462,7 @@ static void check_buffer(struct ring_buffer_per_cpu *cpu_buffer, return; /* - * If this interrupted another event, + * If this interrupted another event, */ if (atomic_inc_return(this_cpu_ptr(&checking)) != 1) goto out;