From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796324423; b=YWtfWRENG1Tf9Akm1LwNTG/h1TujVVO4G151GqkEiuqHAtsSIvFXEPkOJJHx1PHvlRxY S0USwP8YIfMv3xUd6w73I7GVBs9EFVCT6Q5iDLOammVDdyu8945gtGVfGTFGYdsrkZj46 I5TLenjX19OzcpcoirVG1R63E+3+UoXAVK9zo76sGKiWY0vmBbtZB9AzTJFBupqClNyRJ 9sfX5K5C/FuhWHwoJpGLmWrGM7k1P7ndz9gTGAEgX+AOrteloHLUZhBHTJ1iA/vfxvIck +sHcB1rl+Yakh3HMk4Et4FAUe+vjfdZRF9J3J/ijnWtWVazXR2dCBafcf6eru6tiBDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796324423; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=tNqsg1yBI2iwNCDKXXjbfNevCNQjb6arH7I9lRz5DtQ=; b=m+W9BkvndVjlUegZAvmc5NejxWW2i8Ukyq0wGFGUUYYILo7y40VVHcCrCoJMTSb4kIPk QO90QX+EBPTpRQ9iPOKGHyQd2s25HnQjCjDRK/0bH/37eHDyXcRvarcAI9Cn+KhbLAcke ddS73oPvdglP3rxDlDWtB1pAXe3fvk4NJinOpGKpV+m2DkLM4RbnbnZY3qnuTTJLLONX+ QVBGVEzfigkUX4b8YRfRbNaHsOEgilBOKqJXoXhTfgjYWHf0Vv0ks4BFM03fchJsg1TP4 ImqdL6DP4Xs1VfBomJK5gL5A2imOMsRsStePEzlh23RwLHUf0Kz0kMx2zRxJvmNZZEg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=aPYzkLCS; arc=none smtp.remote-ip=209.85.221.70 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4397B606A6A3 for ; Thu, 3 Dec 2026 19:00:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4397B606A6A3 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.a=rsa-sha256 header.s=20260707 header.b=aPYzkLCS Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-48e0ef019a4so124655f8f.3 for ; Thu, 03 Dec 2026 11:00:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796324422; x=1796929222; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=tNqsg1yBI2iwNCDKXXjbfNevCNQjb6arH7I9lRz5DtQ=; b=aPYzkLCSjjG84/o2b48CxsJwFPkV8Rgb/lJx1YnTcGbUl0L7hRc51MsmX/fuhcukDN NIHurx4IlI6DiJ2SVXrhmzQuDkPbJVapQ0ssMMHiFK98H7DfkgDS0LCpdkYnmBfIsz3R ulHEIwPFYwCl1V2M1EFD9pX7E8HC9YdKJtMSgqrU1ZbtAwvjC4t+RjVIGqzWnYZgu2cy o0sMPdMyl9ZuudbHyfTY0h/iuYKqxCYpXwOq4Pzo8UiP8ZVYg304YUKKvQ1M2/OC3+1h nXOs85xLpEK3aAABS1xMWLGNkVgT4gYTx+dZLfKLWl6JCWI4evsqWMDcsUpSHVbfJDoK kU1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796324422; x=1796929222; h=content-type: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:content-type; bh=tNqsg1yBI2iwNCDKXXjbfNevCNQjb6arH7I9lRz5DtQ=; b=ST5blDzon8OrH67RPt96dp/PSZTe1fA+sn3lDAIXknQPtobpVkWh2jbTbL5ZTISDmM 7QdqAo2SVpTCgjY+hwtD1oVgVh8CKovt0S7cdI7eyyfOvWSLObGDVUMNxsX5b8z2T0vc PVlRYgNWEdzQzVtWu3lbRPiwyKrfiSXsoaLR+tT87rYWn6SNVgcXe7SnJmreRXl1zPhd PPYMUu2T34WUcvGhR+LkNUwkGqRQ4fIFTZOUP7GZrS4iw5rf6L7H1SxzMIrgAm/aYZKN F2yo/T6u87/I0GIzGlkoXVWn04DOM8XeX0DdLh0MLvla+lLMOSp1qVZ/5dUB/SPDn++R 6v5A== X-Forwarded-Encrypted: i=1; AL+hErEa7ec4Nl521mLd+kRTb07DSOfxBhw2nndAAlW+eyVOorMcbg+Zx531bGOqJSTtRCTtNwqpeostiorBdh4=@vger.kernel.org X-Gm-Message-State: APuU4Z9fweWbjp0owNZSRE8+J9ELOE0aZDrUAZlC+b2gD6/0PDOPLCrB UD0eQSgBxmu4tjKLQqzjbLe2McAP0g/94iN1Qw7B8y/Jz+7A+9tmIinkVlrnIyRqL5UHGVAb6FG 9Lu8dkKzUIZSaWswCwIC9OA== X-Received: from wroc9.prod.google.com ([2002:adf:ed89:0:b0:493:1d71:a33b]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:5f42:0:b0:4a3:8b21:51c1 with SMTP id ffacd0b85a97d-4abb9de7e00mr94656498f8f.53.1796324421438; Thu, 03 Dec 2026 11:00:21 -0800 (PST) Date: Thu, 3 Dec 2026 18:59:54 +0000 In-Reply-To: <20261203190007.2431041-1-vdonnefort@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261203190007.2431041-1-vdonnefort@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261203190007.2431041-7-vdonnefort@google.com> Subject: [PATCH v10 06/19] tracing/remotes: Use a single per-remote polling work From: Vincent Donnefort To: rostedt@goodmis.org, mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org Cc: mathieu.desnoyers@efficios.com, kernel-team@android.com, linux-kernel@vger.kernel.org, Vincent Donnefort Content-Type: text/plain; charset="UTF-8" Having a per-iterator polling work is wasteful when logging several trace_remote per_cpu/trace_pipe files in parallel. This results in one work running per-CPU, where only one would suffice. Transition to a single per-remote polling work, scheduled on the first consumer creation and stopped when the last consuming iterator is freed. This blanket polls all CPUs, regardless of which ones are actually being read. This is acceptable because the poll consists of reading the meta-page, which is a fast operation. Also, it is more common to log all CPUs in the system than only one, so this use-case should be favoured. Signed-off-by: Vincent Donnefort --- kernel/trace/trace_remote.c | 51 +++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/kernel/trace/trace_remote.c b/kernel/trace/trace_remote.c index d85f00b6a60b..038a8e35ac64 100644 --- a/kernel/trace/trace_remote.c +++ b/kernel/trace/trace_remote.c @@ -26,7 +26,6 @@ enum tri_type { struct trace_remote_iterator { struct trace_remote *remote; struct trace_seq seq; - struct delayed_work poll_work; unsigned long lost_events; u64 ts; struct ring_buffer_iter *rb_iter; @@ -55,8 +54,10 @@ struct trace_remote { struct rw_semaphore reader_lock; struct rw_semaphore *pcpu_reader_locks; unsigned int nr_readers; + unsigned int poll_cnt; unsigned int poll_ms; bool tracing_on; + struct delayed_work poll_work; }; static DEFINE_MUTEX(trace_remotes_lock); @@ -351,17 +352,6 @@ static bool trace_remote_has_cpu(struct trace_remote *remote, int cpu) return ring_buffer_poll_remote(remote->trace_buffer, cpu) == 0; } -static void __poll_remote(struct work_struct *work) -{ - struct delayed_work *dwork = to_delayed_work(work); - struct trace_remote_iterator *iter; - - iter = container_of(dwork, struct trace_remote_iterator, poll_work); - ring_buffer_poll_remote(iter->remote->trace_buffer, iter->cpu); - schedule_delayed_work((struct delayed_work *)work, - msecs_to_jiffies(iter->remote->poll_ms)); -} - static void __free_ring_buffer_iter(struct trace_remote_iterator *iter, int cpu) { if (cpu != RING_BUFFER_ALL_CPUS) { @@ -405,6 +395,36 @@ static int __alloc_ring_buffer_iter(struct trace_remote_iterator *iter, int cpu) return 0; } +static void trace_remote_do_poll(struct trace_remote *remote) +{ + ring_buffer_poll_remote(remote->trace_buffer, RING_BUFFER_ALL_CPUS); + schedule_delayed_work(&remote->poll_work, msecs_to_jiffies(remote->poll_ms)); +} + +static void __poll_remote(struct work_struct *work) +{ + struct delayed_work *dwork = to_delayed_work(work); + + trace_remote_do_poll(container_of(dwork, struct trace_remote, poll_work)); +} + +static void trace_remote_inc_poll(struct trace_remote *remote) +{ + /* poll_cnt <= nr_readers, inherits its overflow protection */ + if (!remote->poll_cnt++) + trace_remote_do_poll(remote); +} + +static void trace_remote_dec_poll(struct trace_remote *remote) +{ + if (WARN_ON_ONCE(!remote->poll_cnt)) + return; + + remote->poll_cnt--; + if (!remote->poll_cnt) + cancel_delayed_work_sync(&remote->poll_work); +} + static struct trace_remote_iterator *trace_remote_iter(struct trace_remote *remote, int cpu, enum tri_type type) { @@ -434,9 +454,7 @@ static struct trace_remote_iterator switch (type) { case TRI_CONSUMING: - ring_buffer_poll_remote(remote->trace_buffer, cpu); - INIT_DELAYED_WORK(&iter->poll_work, __poll_remote); - schedule_delayed_work(&iter->poll_work, msecs_to_jiffies(remote->poll_ms)); + trace_remote_inc_poll(remote); break; case TRI_NONCONSUMING: ret = __alloc_ring_buffer_iter(iter, cpu); @@ -470,7 +488,7 @@ static void trace_remote_iter_free(struct trace_remote_iterator *iter) switch (iter->type) { case TRI_CONSUMING: - cancel_delayed_work_sync(&iter->poll_work); + trace_remote_dec_poll(remote); break; case TRI_NONCONSUMING: __free_ring_buffer_iter(iter, iter->cpu); @@ -1003,6 +1021,7 @@ int trace_remote_register(const char *name, struct trace_remote_callbacks *cbs, remote->poll_ms = 100; mutex_init(&remote->lock); init_rwsem(&remote->reader_lock); + INIT_DELAYED_WORK(&remote->poll_work, __poll_remote); guard(mutex)(&trace_remotes_lock); -- 2.56.1.915.g69d5ec7298-goog