From nobody Mon Jun 8 05:24:43 2026 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (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 7F40D26E6F2 for ; Tue, 2 Jun 2026 00:44:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780361061; cv=none; b=Z5CX76xmHZWoTjJTHBVwjweHBPhMNwLlN1Pdcr51Ydtw5yEvytyI64aoMHkyezeuhKDza8YMv+kJQc/wlZeJV75cmST24J6F5mU9Z0sdGcWPYRh43xluUDYLJeWRbT/3ixwEkCdW2F+7uGvm+zBXJamnFtlJ9IVjnJs++/Tess8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780361061; c=relaxed/simple; bh=0LUonfPrE1kWtwRfsjkmrwfwIRLeDnNvuJNsHEeDqZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E2mlutQ3QfD+ME+fDqHB3FlrFi9MFZ0lt8hJKkGIiS4cWdPYn+okb6voDPoBu5hUMMrafRhBv2GPzdKIqVSCtw+tKavV5f8ZtQXbYHoSxrpJ0OhfzTb1f3noRqu7x4zXAFzXbzM73RYwGMr+iKBTDabKhKtroFXwRzpZrCWI1TY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wbinvd.org; spf=pass smtp.mailfrom=wbinvd.org; dkim=pass (2048-bit key) header.d=wbinvd.org header.i=@wbinvd.org header.b=JE7SYVrL; arc=none smtp.client-ip=74.125.82.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wbinvd.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wbinvd.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wbinvd.org header.i=@wbinvd.org header.b="JE7SYVrL" Received: by mail-dy1-f182.google.com with SMTP id 5a478bee46e88-304f590dd91so3251610eec.0 for ; Mon, 01 Jun 2026 17:44:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wbinvd.org; s=wbinvd; t=1780361060; x=1780965860; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VanU0jfd0XG0PBJ3m9uemoc4Gb0wVkw7ywXii/IfKnY=; b=JE7SYVrLEpsRo+zn9F/2O18YVIVnoh4PsfodbPqThWcizxVOgYWY+CqrfX2738AJin +u0OxD4Rt0q6jOSaf+Zr7LebOvaRbuc5wzs6ERi6SqFPvbd8Hr/EPuXzjFIksiSUni/c sqJT88r0MT03ZujFUWT1F2c0ocap3rFnRZP6gY4yypfqxLkmLVCeqQfprWZb6MAlI+CJ jtsP3j3mCZ1kUd25GtWcBjs+tc/Pr+qLiUG+GebgphfK5k+jdE7iZXtUAd8DNiOkCrOC n77aeJTY/jWEyxmY6YH07XIBy8gnBVwthRMzIU4K2IM5WsJlysERJRN2flHcijo9UOu0 8kwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780361060; x=1780965860; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VanU0jfd0XG0PBJ3m9uemoc4Gb0wVkw7ywXii/IfKnY=; b=dFVuBAob/9pm9H4hE0vitLr3J5tNZOPeduBy5Ym4nrmV80H9l5WtjXQOfTNt2u5ouT kiBQDxh/M8yM8kMZxG7nJRDfk6lNz1rHw7nRTJS6IeTjbgRtvrAqc+24Ikc69Y5nIpvP Liz+/HBvmmmgMpfruM7yoWLqOvW59WsG2NpKNaF5XgNF6E3mje57TjMuLt/OrP28A6Xy heluPZJ+26cG4UHWGR+ZKKfobL+fY1yqDMgkpqKD9/m4wP/LbMpign1yasbqom3AcfAQ 0OAGCrAbFopF6OpmCRYM6xV35EsP6G+0xrxskc11PL7L7ByW+KzGFomDYNvs8BbCCWli 0DEQ== X-Gm-Message-State: AOJu0Yzf5qb+bVEUJLYDI9TJd47XCRX+5/Z/g40C5v5NFt7XaZPk58pD OsMZA//n/ugAnGa67uTOTMG7IDsdml7ExE5B2rph9DdfIsTM9iubD9keyXBIysEodmOukT7aCrq qHRgG X-Gm-Gg: Acq92OFN0rVKeMhVWzBKBo9FEudYDk122mdtKMJqiK6p3h5NGyk0xQQtKtFbEroy92M 6yEcqLX0FK0QAjx78ip6hXKN+TVp2Cu6ttkyaMzMJEsNfkY5LKIKE6xXG9iH6fkgnsG6H3qJjG5 8LZfcNn5A1JNJD5eqWf0xOugF0cMuK4rAo8FuGmy3vWHxhp34iPysIEwklxTD3ibkDrARz6HHZm qsfoBVAsjOCrdAT2G3HA0KzAw6WkHKsLhoBTnOxMFkW+N6f/XREbG85Zy/gjlzr90y7tvLMXm58 008Mv2QaKu5RLKpNfuQlb9xYDjq2tAo4QIyDYrSN5WmzD7JqIr9zbAg1F8u2u+ImOLaFmMnOiSW QZ4igs0zL6WTNkGkY6CtO+dNYu6V13K386iEmM09tVv+0emSXg8yjs072bWu4Gssu+l7aG0KBI7 DYTtb9McdSesVBgI+0GyvH0l23puZARIoUeO+a X-Received: by 2002:a05:7300:724d:b0:304:bce9:25fa with SMTP id 5a478bee46e88-304fa525843mr6102312eec.4.1780361059611; Mon, 01 Jun 2026 17:44:19 -0700 (PDT) Received: from mozart.vkv.me ([2001:5a8:468b:d015:e55d:f6f2:1f67:2056]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-304ed2c10c1sm9892762eec.1.2026.06.01.17.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2026 17:44:19 -0700 (PDT) From: Calvin Owens To: linux-kernel@vger.kernel.org Cc: linux-rt-devel@lists.linux.dev, Rodolfo Giometti , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Greg Kroah-Hartman , Eliav Farber , Michael Byczkowski , Ingo Molnar , David Laight , Thomas Gleixner Subject: [PATCH v7 1/1] pps: pps-gpio: split IRQ handler into hardirq timestamper + threaded handler Date: Mon, 1 Jun 2026 17:44:09 -0700 Message-ID: <2e32729029fbf6977ecf04665eb00f2efd3e2c17.1780359378.git.calvin@wbinvd.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Michael Byczkowski Split the pps-gpio interrupt handler into a primary (hardirq) handler that captures the PPS timestamp at interrupt entry, and a threaded handler that processes the event. This produces the same two-part handler structure on both PREEMPT_RT and non-RT kernels. On non-RT kernels the threaded portion runs immediately after the primary, with no behavioral change compared to the previous single-handler implementation. On PREEMPT_RT, where interrupt handlers are force-threaded by default, the previous single-handler implementation captured the timestamp inside the threaded portion, after IRQ-thread scheduling delay. With the split, the timestamp is captured in true hardirq context as it is on non-RT kernels, eliminating a significant source of PPS jitter on RT systems. Tested-by: Michael Byczkowski Tested-by: Calvin Owens Acked-by: Rodolfo Giometti Signed-off-by: Michael Byczkowski Signed-off-by: Calvin Owens Reviewed-by: Sebastian Andrzej Siewior --- drivers/pps/clients/pps-gpio.c | 37 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c index 935da68610c7..ed111621ee5f 100644 --- a/drivers/pps/clients/pps-gpio.c +++ b/drivers/pps/clients/pps-gpio.c @@ -35,33 +35,44 @@ struct pps_gpio_device_data { bool capture_clear; unsigned int echo_active_ms; /* PPS echo active duration */ unsigned long echo_timeout; /* timer timeout value in jiffies */ + struct pps_event_time ts; /* timestamp captured in hardirq */ }; =20 /* * Report the PPS event */ =20 -static irqreturn_t pps_gpio_irq_handler(int irq, void *data) +/* + * Primary hardirq handler -- runs in hardirq context even on PREEMPT_RT. + * Only captures the timestamp; all other work is deferred to the thread. + */ +static irqreturn_t pps_gpio_irq_hardirq(int irq, void *data) { - const struct pps_gpio_device_data *info; - struct pps_event_time ts; - int rising_edge; + struct pps_gpio_device_data *info =3D data; + + pps_get_ts(&info->ts); =20 - /* Get the time stamp first */ - pps_get_ts(&ts); + return IRQ_WAKE_THREAD; +} =20 - info =3D data; +/* + * Threaded handler -- processes the PPS event using the timestamp + * captured in hardirq context above. + */ +static irqreturn_t pps_gpio_irq_thread(int irq, void *data) +{ + struct pps_gpio_device_data *info =3D data; + int rising_edge; =20 - /* Small trick to bypass the check on edge's direction when capture_clear= is unset */ rising_edge =3D info->capture_clear ? gpiod_get_value(info->gpio_pin) : !info->assert_falling_edge; if ((rising_edge && !info->assert_falling_edge) || (!rising_edge && info->assert_falling_edge)) - pps_event(info->pps, &ts, PPS_CAPTUREASSERT, data); + pps_event(info->pps, &info->ts, PPS_CAPTUREASSERT, data); else if (info->capture_clear && ((rising_edge && info->assert_falling_edge) || (!rising_edge && !info->assert_falling_edge))) - pps_event(info->pps, &ts, PPS_CAPTURECLEAR, data); + pps_event(info->pps, &info->ts, PPS_CAPTURECLEAR, data); else dev_warn_ratelimited(&info->pps->dev, "IRQ did not trigger any PPS event= \n"); =20 @@ -210,8 +221,10 @@ static int pps_gpio_probe(struct platform_device *pdev) } =20 /* register IRQ interrupt handler */ - ret =3D request_irq(data->irq, pps_gpio_irq_handler, - get_irqf_trigger_flags(data), data->info.name, data); + ret =3D request_threaded_irq(data->irq, + pps_gpio_irq_hardirq, pps_gpio_irq_thread, + get_irqf_trigger_flags(data) | IRQF_ONESHOT, + data->info.name, data); if (ret) { pps_unregister_source(data->pps); dev_err(dev, "failed to acquire IRQ %d\n", data->irq); --=20 2.47.3