From nobody Fri Apr 4 21:41:26 2025 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A5F01F9438 for ; Wed, 8 Jan 2025 11:46:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736336770; cv=none; b=Gem/CL53ykw0NhqSpEPV2fcRIaZ9t5rxCt+HiflRqSVlyQaF/Pc8bhLIViRcddnOhqU+L6B/zWsCOZZqH/6CNqB0MrZ42V8VQHddx47efEoVMCOaO8CVmwK66zV3JdTZjXm3H+fY7AHcWztQKFD50WEjQH57EpNj6RLvd2+LlRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736336770; c=relaxed/simple; bh=2zGrh6Bb4n7JJV94xdpbEofaJlW8JBXkmFVpd7d6OaY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=m0dX1nR4UpcPF33QYId60s67s7NfOQHGMRRrbUOAZMtwAsFlwFGTJe1rhZoysgeRwJcmnxyH+13OcHCsBAZcya9sNdk6k16F0GFQaJ6788lzk1PuyVF33oTpQknjc7lTWm271ok9zboGeqwzs5VbvmPYLfadKcN1XsrQ4SDe2s4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=N59nt5Pe; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="N59nt5Pe" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-385ded5e92aso3307895f8f.3 for ; Wed, 08 Jan 2025 03:46:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736336767; x=1736941567; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1lQEJoOrOtFhLM0V6NW85dekf5jRkM+x/j5FFakF4z0=; b=N59nt5Pe/9X89Y7uK/lfdExFCLaVxny4f9LLiby/5cybFPoZ21rNttBEiAQau1K0Lc WLJC5h0dB21Z2kYm9+P+Inu5KSuaHcDdSm02QLtpzXxOUDEJWln5n27B7nMk1fvbOCWo iB1Ig0Auz3BwnnxN26rQthg7Ge5NF279LZvH3mpPfEroEZxv5kFQZpjc+ky7h75FCOru s0aPxYsqkRpEmcYEe3vxmXpYqF8rvXgTxJlK+oPWhpLLOM+o06x8omaUbUlLjz65OA6i mgkjjX256OP8mj7F1Z2pmvhcosTo9MCV42JmLyUWYYb4DPia2MBJEo7gmqE92Q+5OsKE 5G8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736336767; x=1736941567; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1lQEJoOrOtFhLM0V6NW85dekf5jRkM+x/j5FFakF4z0=; b=Ko6UsMlNR/+EN4l4GEo7OKavQs/FT/hnHkNACeH7w/shW3puyl5evbZEDJ9R/RuX+W VkEgsM1paCf0fThsy0DtC28bI9CXswf+LGAaUskYzR017wSFQjUwTcEwG6ysWX3vBP9/ lkSMuSoCnpL9c/9ces8r4jh8BoDRCJ6Da/HL5QzH0UEdE/wTOKtlEXSZ1vIdTS7+ZevU /71gNrmSzW2wq2PbBMAbdccxyHd6ZRptCQ8s3QvHm4AV4uCJ6zNBgVXkQz+9KW2EZJzF pGcD+wuSFufoLSef58A8RRo2XgoJBkSTyg5WuW2SG892K87XmTabvZWsKcV98Yona5wt /sdQ== X-Forwarded-Encrypted: i=1; AJvYcCUZyTukDcpdYwBGYEqcbqPuP+o5bsTtcsQqHIT5n/gi4Pl616qYHNjYKAmgvUSbfhSdxhSo7JCtqrrleOA=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9Vuj6ogEfz/bYks0/JTnM/to5MU6utqX6cwD5inpPvAmnSk+5 8AjXhljFPl8DqVdDDIOb8eFzQULVI+zdVqgmVsxK5fnt60GJBom0tJJyZOhz+1dN8wyciw0IXJa 8KBsqqpZdK0qpXmx1Ug== X-Google-Smtp-Source: AGHT+IH9nVUXukGdhao/KGMQEQ2ZZRu7hj12bJxObkGyvYkwyEhx99i/TvuPbWjySunFSoVAevMNDD+4C2F0t7to X-Received: from wmbez12.prod.google.com ([2002:a05:600c:83cc:b0:436:7123:f80a]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:47c5:0:b0:386:1cd3:8a09 with SMTP id ffacd0b85a97d-38a872d2addmr1799776f8f.1.1736336767575; Wed, 08 Jan 2025 03:46:07 -0800 (PST) Date: Wed, 8 Jan 2025 11:45:27 +0000 In-Reply-To: <20250108114536.627715-1-vdonnefort@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250108114536.627715-1-vdonnefort@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250108114536.627715-4-vdonnefort@google.com> Subject: [PATCH v2 03/12] ring-buffer: Expose buffer_data_page material From: Vincent Donnefort To: rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, linux-trace-kernel@vger.kernel.org, maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, jstultz@google.com, qperret@google.com, will@kernel.org, kernel-team@android.com, linux-kernel@vger.kernel.org, Vincent Donnefort Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for allowing the write of ring-buffer compliant pages outside of ring_buffer.c, move to the header, struct buffer_data_page and timestamp encoding functions into the publicly available ring_buffer.h. Signed-off-by: Vincent Donnefort diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h index 61e785adc011..a80057371da4 100644 --- a/include/linux/ring_buffer.h +++ b/include/linux/ring_buffer.h @@ -3,8 +3,10 @@ #define _LINUX_RING_BUFFER_H =20 #include -#include #include +#include + +#include =20 #include =20 @@ -20,6 +22,8 @@ struct ring_buffer_event { u32 array[]; }; =20 +#define RB_EVNT_HDR_SIZE (offsetof(struct ring_buffer_event, array)) + /** * enum ring_buffer_type - internal ring buffer types * @@ -61,11 +65,50 @@ enum ring_buffer_type { RINGBUF_TYPE_TIME_STAMP, }; =20 +#define TS_SHIFT 27 +#define TS_MASK ((1ULL << TS_SHIFT) - 1) +#define TS_DELTA_TEST (~TS_MASK) + +/* + * We need to fit the time_stamp delta into 27 bits. + */ +static inline bool test_time_stamp(u64 delta) +{ + return !!(delta & TS_DELTA_TEST); +} + unsigned ring_buffer_event_length(struct ring_buffer_event *event); void *ring_buffer_event_data(struct ring_buffer_event *event); u64 ring_buffer_event_time_stamp(struct trace_buffer *buffer, struct ring_buffer_event *event); =20 +#define BUF_PAGE_HDR_SIZE offsetof(struct buffer_data_page, data) + +/* Max payload is BUF_PAGE_SIZE - header (8bytes) */ +#define BUF_MAX_DATA_SIZE (BUF_PAGE_SIZE - (sizeof(u32) * 2)) + +#define BUF_PAGE_SIZE (PAGE_SIZE - BUF_PAGE_HDR_SIZE) + +#define RB_ALIGNMENT 4U +#define RB_MAX_SMALL_DATA (RB_ALIGNMENT * RINGBUF_TYPE_DATA_TYPE_LEN_MAX) +#define RB_EVNT_MIN_SIZE 8U /* two 32bit words */ + +#ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS +# define RB_FORCE_8BYTE_ALIGNMENT 0 +# define RB_ARCH_ALIGNMENT RB_ALIGNMENT +#else +# define RB_FORCE_8BYTE_ALIGNMENT 1 +# define RB_ARCH_ALIGNMENT 8U +#endif + +#define RB_ALIGN_DATA __aligned(RB_ARCH_ALIGNMENT) + +struct buffer_data_page { + u64 time_stamp; /* page time stamp */ + local_t commit; /* write committed index */ + unsigned char data[] RB_ALIGN_DATA; /* data of buffer page */ +}; + /* * ring_buffer_discard_commit will remove an event that has not * been committed yet. If this is used, then ring_buffer_unlock_commit diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 3d5d32ecd3fa..0e5e9272debf 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -152,23 +152,6 @@ int ring_buffer_print_entry_header(struct trace_seq *s) /* Used for individual buffers (after the counter) */ #define RB_BUFFER_OFF (1 << 20) =20 -#define BUF_PAGE_HDR_SIZE offsetof(struct buffer_data_page, data) - -#define RB_EVNT_HDR_SIZE (offsetof(struct ring_buffer_event, array)) -#define RB_ALIGNMENT 4U -#define RB_MAX_SMALL_DATA (RB_ALIGNMENT * RINGBUF_TYPE_DATA_TYPE_LEN_MAX) -#define RB_EVNT_MIN_SIZE 8U /* two 32bit words */ - -#ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS -# define RB_FORCE_8BYTE_ALIGNMENT 0 -# define RB_ARCH_ALIGNMENT RB_ALIGNMENT -#else -# define RB_FORCE_8BYTE_ALIGNMENT 1 -# define RB_ARCH_ALIGNMENT 8U -#endif - -#define RB_ALIGN_DATA __aligned(RB_ARCH_ALIGNMENT) - /* define RINGBUF_TYPE_DATA for 'case RINGBUF_TYPE_DATA:' */ #define RINGBUF_TYPE_DATA 0 ... RINGBUF_TYPE_DATA_TYPE_LEN_MAX =20 @@ -311,10 +294,6 @@ EXPORT_SYMBOL_GPL(ring_buffer_event_data); #define for_each_online_buffer_cpu(buffer, cpu) \ for_each_cpu_and(cpu, buffer->cpumask, cpu_online_mask) =20 -#define TS_SHIFT 27 -#define TS_MASK ((1ULL << TS_SHIFT) - 1) -#define TS_DELTA_TEST (~TS_MASK) - static u64 rb_event_time_stamp(struct ring_buffer_event *event) { u64 ts; @@ -333,12 +312,6 @@ static u64 rb_event_time_stamp(struct ring_buffer_even= t *event) =20 #define RB_MISSED_MASK (3 << 30) =20 -struct buffer_data_page { - u64 time_stamp; /* page time stamp */ - local_t commit; /* write committed index */ - unsigned char data[] RB_ALIGN_DATA; /* data of buffer page */ -}; - struct buffer_data_read_page { unsigned order; /* order of the page */ struct buffer_data_page *data; /* actual data, stored in this page */ @@ -397,14 +370,6 @@ static void free_buffer_page(struct buffer_page *bpage) kfree(bpage); } =20 -/* - * We need to fit the time_stamp delta into 27 bits. - */ -static inline bool test_time_stamp(u64 delta) -{ - return !!(delta & TS_DELTA_TEST); -} - struct rb_irq_work { struct irq_work work; wait_queue_head_t waiters; --=20 2.47.1.613.gc27f4b7a9f-goog