From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796324423; b=R8E0EiytFBDsDB3xQsvqXQUJu09kl3Un+jBCtu0E3Z9dN0BGJaEGn2hX5F8cE+tTs/DJ XyIOazcQMnX7u940qQLxjQvpRFJ4BTgbAWrGQYycXxlmEncgcd3LRcFQvyqV1dvJC9tHK TnteZyX0RL97xOEw5imMN0H84J8EdpZLN7NFWprYWeo/34322irpIXnXZU6NNShmcxcq+ KgSHydzv5G3unzE25AtWpgfqdDo/rO5XX1Ct4+q5Yo4wM1Fvs22cnwiBOpefcGg2bipBY KzLYHY0aSVvDU0ghBChGFwHcl2sU4dHpYLNVs63i498UlQ56LoPJPFaKLuGfW+9W9ig== 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=K9LY5JrC+WpY5O/P9IU1zfJkgLWqRMZ0fWTa63iamQLtMlkp2O/3GzYVtEage7+9ip23 +e03+zCjr5mQ8/hk1vMKycoJIgRU6Z5F4In70QjtPUW7E58Ver5Ue2u3uqKGmU85Sa2DM huKOfcoZALvZiqaJXPNkRDQZLZLbWmC2ym+pNdOpowIGswwQO2FBJuikGAC0XFdjRtOLy SbbRrHAa2OQYL3tSXa9yoSx3p+cfeYjgNbc/IcBAAFgKN3PGmpFKp7DGIfmOGOpezS+f6 CGn6Esvdet1EQndLIkx08HjXiWZIeahWDSkKkNOvfE9cFZFDz/fTcA42T2NqmkggY2A== 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.72 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (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 76821606A68C for ; Thu, 3 Dec 2026 19:00:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 76821606A68C 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-f72.google.com with SMTP id ffacd0b85a97d-48c6a1d4034so142408f8f.0 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=eNPlFoVtiV2pZAXdk7K3KG7pKuTbq1aIImlkNqZ2+4lhxJ8FzPX+L0qkQHS03csb9a RtxcDlq1V+alogZqos5cnVAWpr9nEODHUhGFJT7H/Xfb7myayIvk0OjWTAJntc5SPnp8 HTPsgKX4Xx3spOpXd3/vRFfsTUxIHmOekXjisjGnfGrLx8qf1NOUMlk0+nbu+/ocxspP puEWKtA29CZ6QViKVzxL60Px9PJx6E80jw3B3mML1kbNkSNH1R2gSO4wTbDwpwC7cvtU VNF4F8lD0YIglXZxHMyJTH5MwFkagybqS0JI/D6WvSfmul8iRz75e0Uev/aV0TBJsrTf Ua4A== X-Forwarded-Encrypted: i=1; AL+hErEImew6hAjNzf06+OBsGZSJNYnLKIpugP15ZX7km4NmIBVjE8xc5OoiIFJ4+gRB8bTLRypSQHWo7wo+gLNidpq+Uv4=@vger.kernel.org X-Gm-Message-State: APuU4Z/9Lq7wQ1V5wUlAidp2iKKlPZ8kPClqBzEzDWeY/nOmgh7ARuTp SDo1HNo2ZwHhwITZf4aT4qi4Q4TY1oUx8FWjag29q+W1kk2UdYIklA0l9t1BC5P0T0oSrSBbpEZ Hly2cEBlh3e8FB+DyI6PE2g== 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-trace-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