From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 A27483A7F5D for ; Wed, 10 Jun 2026 13:05:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781096730; cv=none; b=ix/3t6xsySQfOzjNOMqQjU9+M0f2pvsVrS7G7knyQyE8kdMhe8UZM2OW1FR3OXNJfYmI2bZ+qxkfi9pSvz7FROAZultmrHsL3806Cin4dwRD+14hPJtYeSdN0wJz6mhqQjkBfWGQXp8PRdnKNorsPTp7tpDVoIXzB8SGj57KR2I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781096730; c=relaxed/simple; bh=FeftGIkIL5YCozM9Jt0jXsDJSfZ5CVGAVHeAvwB5OiY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qo4ASIIz9/SoFrcqOIcAHG6EH7uFGEv3DcclN/lO2jakP2q0AvTAFq/UKAesPQ5Lk+3X2sfUznSzeLpyqrA6XMHeZ1P9Oc6xbv4yk6oIlYVo6DFfnxKBsQPRdlj13I4lk1YaisPq7e9svRoMO5SIbh6ZNDMAHO9HgXe4Fj5Bnrg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Q2d539Om; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Q2d539Om" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781096725; 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=YPmMPGikHnmfqQvtWsMKKE1ehlX8PFP4GGsNTku/VEs=; b=Q2d539OmWRrj+5RiVxEklrNZG69ufyvRs1VOr+dt54K7laNrA9UXdtMNh8TRQTYw5uHDqF +FTrl11V3zvDbY+vafRA0KfGKJx7HitUOMm7xHRHkVk7rrZwsf6KttJ7LtXdMB1LB1tccf QwvgH+vmC9qe9dpOybE+CZHVihTXeps= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-634-ZpN4zONwNtOv-tijfJXhpQ-1; Wed, 10 Jun 2026 09:05:22 -0400 X-MC-Unique: ZpN4zONwNtOv-tijfJXhpQ-1 X-Mimecast-MFC-AGG-ID: ZpN4zONwNtOv-tijfJXhpQ_1781096721 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 17B6F180AE1C; Wed, 10 Jun 2026 13:05:21 +0000 (UTC) Received: from vschneid-thinkpadt14sgen2i.remote.csb (unknown [10.44.33.130]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 12E743008B35; Wed, 10 Jun 2026 13:05:17 +0000 (UTC) From: Valentin Schneider To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Tomas Glozar , Costa Shulyupin , Crystal Wood , Ivan Pravdin Subject: [RFC PATCH 1/2] tracing/osnoise: Sample IPI counts Date: Wed, 10 Jun 2026 15:04:51 +0200 Message-ID: <20260610130457.1304245-2-vschneid@redhat.com> In-Reply-To: <20260610130457.1304245-1-vschneid@redhat.com> References: <20260610130457.1304245-1-vschneid@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Osnoise already implictly accounts IPIs via its IRQ tracking, however it can be interesting to distiguish between the two: undesired IPIs usually imply a software configuration issue (e.g. wrong/incomplete CPU isolation) whereas undesired (non-IPI) IRQs usually imply a hardware configuration issue. Signed-off-by: Valentin Schneider --- Note that this is modifying the osnoise:osnoise_entry Ftrace entry; I know trace events are sort of supposed to be stable, but I'm not sure about ftrace entries. Alternatively I can have this be purely supported in userspace osnoise by hooking into the IPI events and counting IPIs separately from the osnoise events. --- include/trace/events/osnoise.h | 1 + kernel/trace/trace_entries.h | 6 ++- kernel/trace/trace_osnoise.c | 80 ++++++++++++++++++++++++++++++++-- 3 files changed, 81 insertions(+), 6 deletions(-) diff --git a/include/trace/events/osnoise.h b/include/trace/events/osnoise.h index 3f42736238014..58442e58fe652 100644 --- a/include/trace/events/osnoise.h +++ b/include/trace/events/osnoise.h @@ -19,6 +19,7 @@ struct osnoise_sample { int irq_count; /* # IRQs during this sample */ int softirq_count; /* # softirqs during this sample */ int thread_count; /* # threads during this sample */ + int ipi_count; /* # IPIs during this sample */ }; #ifdef CONFIG_TIMERLAT_TRACER diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h index 54417468fdeb1..aed778d859d37 100644 --- a/kernel/trace/trace_entries.h +++ b/kernel/trace/trace_entries.h @@ -430,16 +430,18 @@ FTRACE_ENTRY(osnoise, osnoise_entry, __field( unsigned int, irq_count ) __field( unsigned int, softirq_count ) __field( unsigned int, thread_count ) + __field( unsigned int, ipi_count ) ), - F_printk("noise:%llu\tmax_sample:%llu\thw:%u\tnmi:%u\tirq:%u\tsoftirq:%u\tthread:%u\n", + F_printk("noise:%llu\tmax_sample:%llu\thw:%u\tnmi:%u\tirq:%u\tsoftirq:%u\tthread:%u\tipi:%u\n", __entry->noise, __entry->max_sample, __entry->hw_count, __entry->nmi_count, __entry->irq_count, __entry->softirq_count, - __entry->thread_count) + __entry->thread_count, + __entry->ipi_count) ); FTRACE_ENTRY(timerlat, timerlat_entry, diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index 75678053b21c5..574629a6b22b3 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -35,6 +35,7 @@ #include #include +#include #define CREATE_TRACE_POINTS #include @@ -83,6 +84,10 @@ struct osnoise_instance { static struct list_head osnoise_instances; +static struct cpumask osnoise_cpumask; +static struct cpumask save_cpumask; +static struct cpumask kthread_cpumask; + static bool osnoise_has_registered_instances(void) { return !!list_first_or_null_rcu(&osnoise_instances, @@ -203,6 +208,11 @@ struct osn_thread { u64 delta_start; }; +/* IPI runtime info */ +struct osn_ipi { + u64 count; +}; + /* * Runtime information: this structure saves the runtime information used by * one sampling thread. @@ -215,6 +225,7 @@ struct osnoise_variables { struct osn_irq irq; struct osn_softirq softirq; struct osn_thread thread; + struct osn_ipi ipi; local_t int_counter; }; @@ -505,6 +516,7 @@ __record_osnoise_sample(struct osnoise_sample *sample, struct trace_buffer *buff entry->irq_count = sample->irq_count; entry->softirq_count = sample->softirq_count; entry->thread_count = sample->thread_count; + entry->ipi_count = sample->ipi_count; trace_buffer_unlock_commit_nostack(buffer, event); } @@ -1288,6 +1300,7 @@ trace_sched_switch_callback(void *data, bool preempt, * Hook the osnoise tracer callbacks to handle the noise from other * threads on the necessary kernel events. */ + static int hook_thread_events(void) { int ret; @@ -1319,6 +1332,60 @@ static void unhook_thread_events(void) unregister_migration_monitor(); } +static void ipi_emission(struct osnoise_variables *osn_var, unsigned int dst_cpu) +{ + if (!osn_var->sampling) + return; + + osn_var->ipi.count++; +} + +static void trace_ipi_send_cpu_callback(void *data, unsigned int cpu, + unsigned long callsite, void *callback) +{ + struct osnoise_variables *osn_var; + + osn_var = per_cpu_ptr(&per_cpu_osnoise_var, cpu); + ipi_emission(osn_var, cpu); +} + +static void trace_ipi_send_cpumask_callback(void *data, const struct cpumask *cpumask, + unsigned long callsite, void *callback) +{ + struct osnoise_variables *osn_var; + int cpu; + + for_each_cpu_and(cpu, cpumask, &osnoise_cpumask) { + osn_var = per_cpu_ptr(&per_cpu_osnoise_var, cpu); + ipi_emission(osn_var, cpu); + } +} + +static int hook_ipi_events(void) +{ + int ret; + + ret = register_trace_ipi_send_cpu(trace_ipi_send_cpu_callback, NULL); + if (ret) + return -EINVAL; + + ret = register_trace_ipi_send_cpumask(trace_ipi_send_cpumask_callback, NULL); + if (ret) + goto out_unreg; + + return 0; + +out_unreg: + unregister_trace_ipi_send_cpu(trace_ipi_send_cpu_callback, NULL); + return -EINVAL; +} + +static void unhook_ipi_events(void) +{ + unregister_trace_ipi_send_cpu(trace_ipi_send_cpu_callback, NULL); + unregister_trace_ipi_send_cpumask(trace_ipi_send_cpumask_callback, NULL); +} + /* * save_osn_sample_stats - Save the osnoise_sample statistics * @@ -1333,6 +1400,7 @@ save_osn_sample_stats(struct osnoise_variables *osn_var, struct osnoise_sample * s->irq_count = osn_var->irq.count; s->softirq_count = osn_var->softirq.count; s->thread_count = osn_var->thread.count; + s->ipi_count = osn_var->ipi.count; } /* @@ -1349,6 +1417,7 @@ diff_osn_sample_stats(struct osnoise_variables *osn_var, struct osnoise_sample * s->irq_count = osn_var->irq.count - s->irq_count; s->softirq_count = osn_var->softirq.count - s->softirq_count; s->thread_count = osn_var->thread.count - s->thread_count; + s->ipi_count = osn_var->ipi.count - s->ipi_count; } /* @@ -1613,10 +1682,6 @@ static int run_osnoise(void) return ret; } -static struct cpumask osnoise_cpumask; -static struct cpumask save_cpumask; -static struct cpumask kthread_cpumask; - /* * osnoise_sleep - sleep until the next period */ @@ -2892,12 +2957,18 @@ static int osnoise_hook_events(void) goto out_unhook_irq; retval = hook_thread_events(); + if (retval) + goto out_unhook_softirq; + + retval = hook_ipi_events(); /* * All fine! */ if (!retval) return 0; + unhook_thread_events(); +out_unhook_softirq: unhook_softirq_events(); out_unhook_irq: unhook_irq_events(); @@ -2906,6 +2977,7 @@ static int osnoise_hook_events(void) static void osnoise_unhook_events(void) { + unhook_ipi_events(); unhook_thread_events(); unhook_softirq_events(); unhook_irq_events(); -- 2.54.0