{"id":2228116,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2228116/?format=json","web_url":"http://patchwork.ozlabs.org/project/opensbi/patch/20260425104048.2335262-5-anup.patel@oss.qualcomm.com/","project":{"id":67,"url":"http://patchwork.ozlabs.org/api/1.1/projects/67/?format=json","name":"OpenSBI development","link_name":"opensbi","list_id":"opensbi.lists.infradead.org","list_email":"opensbi@lists.infradead.org","web_url":"https://github.com/riscv/opensbi","scm_url":"","webscm_url":""},"msgid":"<20260425104048.2335262-5-anup.patel@oss.qualcomm.com>","date":"2026-04-25T10:40:48","name":"[v2,4/4] lib: sbi_timer: Introduce sbi_timer_compute_delta() and friends","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"986025ea475ce10a792e2ccb5835f912738d9b66","submitter":{"id":92322,"url":"http://patchwork.ozlabs.org/api/1.1/people/92322/?format=json","name":"Anup Patel","email":"anup.patel@oss.qualcomm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/opensbi/patch/20260425104048.2335262-5-anup.patel@oss.qualcomm.com/mbox/","series":[{"id":501434,"url":"http://patchwork.ozlabs.org/api/1.1/series/501434/?format=json","web_url":"http://patchwork.ozlabs.org/project/opensbi/list/?series=501434","date":"2026-04-25T10:40:44","name":"Timer events for OpenSBI","version":2,"mbox":"http://patchwork.ozlabs.org/series/501434/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2228116/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2228116/checks/","tags":{},"headers":{"Return-Path":"\n <opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=AGmwzKuj;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=EouvBMjd;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g2mb03XY6z1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 25 Apr 2026 20:41:11 +1000 (AEST)","from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wGaRY-0000000ELsX-1QUP;\n\tSat, 25 Apr 2026 10:41:00 +0000","from mx0b-0031df01.pphosted.com ([205.220.180.131])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wGaRV-0000000ELrA-3JVC\n\tfor opensbi@lists.infradead.org;\n\tSat, 25 Apr 2026 10:40:59 +0000","from pps.filterd (m0279872.ppops.net [127.0.0.1])\n\tby mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 63P3mWB81021184;\n\tSat, 25 Apr 2026 10:40:53 GMT","from apblrppmta01.qualcomm.com\n (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19])\n\tby mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4drp07gpwn-1\n\t(version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);\n\tSat, 25 Apr 2026 10:40:53 +0000 (GMT)","from pps.filterd (APBLRPPMTA01.qualcomm.com [127.0.0.1])\n\tby APBLRPPMTA01.qualcomm.com (8.18.1.7/8.18.1.7) with ESMTP id\n 63PAeo1u005575;\n\tSat, 25 Apr 2026 10:40:50 GMT","from pps.reinject (localhost [127.0.0.1])\n\tby APBLRPPMTA01.qualcomm.com (PPS) with ESMTPS id 4drpph2c88-1\n\t(version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);\n\tSat, 25 Apr 2026 10:40:49 +0000 (GMT)","from APBLRPPMTA01.qualcomm.com (APBLRPPMTA01.qualcomm.com\n [127.0.0.1])\n\tby pps.reinject (8.18.1.12/8.18.1.12) with ESMTP id 63PAensE005546;\n\tSat, 25 Apr 2026 10:40:49 GMT","from hu-devc-blr-u24-a.qualcomm.com (hu-anuppate-blr.qualcomm.com\n [10.131.36.165])\n\tby APBLRPPMTA01.qualcomm.com (PPS) with ESMTPS id 63PAenTP005541\n\t(version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);\n\tSat, 25 Apr 2026 10:40:49 +0000 (GMT)","by hu-devc-blr-u24-a.qualcomm.com (Postfix, from userid 486687)\n\tid 206B822A38; Sat, 25 Apr 2026 16:10:49 +0530 (+0530)"],"DKIM-Signature":["v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:\n\tMessage-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=v9nG6iHyWBUPo6cnsvaAV4lBq2wdOORIkgaQ4haDzJE=; b=AGmwzKuj7p6p0q\n\tUNFp4Qyhtk2yBkmURKPeUqeH+oGnL+T4gHGyYXz4urUsom0iDUvukrF9M5+MfzggeBf+Hh2JHyKTq\n\t3bcveKkOPk53PxF79uz8tBuAESBw8h0XsCqvgIzfKr9h5vMPFci3WLTl/1VJnZ0XUCK+c5XMDDoUq\n\tSsX2mh0JciitwBqDexgCaV3oQ2CmEsMXE3qxhTAzBBVuBMRx8aqbNNPaV+Om4/V7twIfVYPeyphKs\n\t1eMykmLH3cXVxVRGGu7lMylT7cG+r0JdD1a7sX/GymR1qT6+Vwwr+O05REW9TcgWtfc5fjmQF2iMP\n\tLI6Qe4S5uAot3EGyxFVw==;","v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n\tcc:content-transfer-encoding:date:from:in-reply-to:message-id\n\t:mime-version:references:subject:to; s=qcppdkim1; bh=a2Qs0rOo8VY\n\t0J10VKitDrHju/jl1TasJMsYFSsrrtw4=; b=EouvBMjdT2Aq4gmqbT/uh+Ui3f4\n\t4guKWSsWyLVxzIVNC4MnLAfqU0DT9v5sK845EYiOIVjDrtB09u6vEhMLTfrK2xID\n\tj0Ut9XLPSKCvlRmyv2t9ACCLKTklAJdbOo8s4P+42stsDPcv1gccKRiSxgEVaawq\n\tHHlpVP4s83DvVnv49/TrmlHqmpvQdOn8TTkX5M3pxp+vjB0cqahMj7dwKoIG6Acc\n\tOrms02iVSsnUXbbC3rXteaovFHuSz5p4vSeLKVX0RAIkM/6O3kYVumfv+SL8CisX\n\tloIYQ2afMshoKyUdJgaujIDvAbHUaBBXKqT6rGzwd6QTO8v9b+jPxXX/ysQ=="],"From":"Anup Patel <anup.patel@oss.qualcomm.com>","To":"Atish Patra <atish.patra@linux.dev>","Cc":"Andrew Jones <andrew.jones@oss.qualcomm.com>,\n        Samuel Holland <samuel.holland@sifive.com>,\n        Anup Patel <anup@brainfault.org>, opensbi@lists.infradead.org,\n        Anup Patel <anup.patel@oss.qualcomm.com>","Subject":"[PATCH v2 4/4] lib: sbi_timer: Introduce sbi_timer_compute_delta()\n and friends","Date":"Sat, 25 Apr 2026 16:10:48 +0530","Message-ID":"<20260425104048.2335262-5-anup.patel@oss.qualcomm.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260425104048.2335262-1-anup.patel@oss.qualcomm.com>","References":"<20260425104048.2335262-1-anup.patel@oss.qualcomm.com>","MIME-Version":"1.0","X-QCInternal":["smtphost","smtphost"],"X-Authority-Analysis":"v=2.4 cv=K8QS2SWI c=1 sm=1 tr=0 ts=69ec9a35 cx=c_pps\n a=Ou0eQOY4+eZoSc0qltEV5Q==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17\n a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22\n a=yx91gb_oNiZeI1HMLzn7:22 a=EUspDBNiAAAA:8 a=sbnM9rFSS_IGgtnRH10A:9","X-Proofpoint-ORIG-GUID":"Bzsasqa3IiWFiEsmWj92yWWSv91R0ku6","X-Proofpoint-GUID":"Bzsasqa3IiWFiEsmWj92yWWSv91R0ku6","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDI1MDEwNiBTYWx0ZWRfX4yTk3n1wWsqE\n TaIUCKPQFXaxnwaaRruwLyF1quV7VtkNunS0dKGCpJHAXJE4oPibRIXdzbwQr0kKoXeAmc3jqgQ\n ie7tlMMI2fGixBZMfuMHkuAZyHVsDBgxtcy19hOogjU30F/C1o7RTVbmqqoVLrNWWJufih/3fIy\n QCtmbGnl0GnAMYieq3x+FQe7JsP2EzTKiy8GEQ00TLa2dyhlDOORdVzdF0zd0nMIK3nxZANaTHV\n V12NZ41cfZUzB7xIGJx+u81AYxBVHaEUto/sjiyZb1Sam7ai0gXVWD5946pHIQWNBWjINgXcqa9\n s5jU+qx6H+HXDuehLu96YjdndabQRMF1vY1yDgp/xXMfFSsBU5bua9fC66HdYsvAeblhw0/glCo\n BgO+5fAW1C8qL+OIlaHZRpEtcrM/1uP4p1VwpdvsrO4DwV1ajPEI586m7R5a9mogOH5lmaCuVLS\n Ibb6fJhl9DravPnpEUA==","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-04-25_02,2026-04-21_02,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n clxscore=1015 impostorscore=0 spamscore=0 malwarescore=0 phishscore=0\n priorityscore=1501 adultscore=0 lowpriorityscore=0 bulkscore=0 suspectscore=0\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2604250106","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20260425_034057_961130_009DBAA9 ","X-CRM114-Status":"GOOD (  12.67  )","X-Spam-Score":"-2.7 (--)","X-Spam-Report":"Spam detection software,\n running on the system \"bombadil.infradead.org\",\n has NOT identified this incoming email as spam.  The original\n message has been attached to this so you can view it or label\n similar future email.  If you have any questions, see\n the administrator of that system for details.\n Content preview:  The users of timer event have to compute next_event (aka\n timer\n    value in the future) based on desired units and unit frequency. Introduce\n    sbi_timer_compute_delta() and friends to simplify computing nex [...]\n Content analysis details:   (-2.7 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\n -0.7 RCVD_IN_DNSWL_LOW      RBL: Sender listed at https://www.dnswl.org/, low\n                             trust\n                             [205.220.180.131 listed in list.dnswl.org]\n  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record\n -0.0 SPF_PASS               SPF: sender matches SPF record\n -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from\n                             envelope-from domain\n  0.1 DKIM_SIGNED            Message has a DKIM or DK signature,\n not necessarily valid\n -0.1 DKIM_VALID             Message has at least one valid DKIM or DK\n signature\n -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n                             [score: 0.0000]","X-BeenThere":"opensbi@lists.infradead.org","X-Mailman-Version":"2.1.34","Precedence":"list","List-Id":"<opensbi.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/opensbi>,\n <mailto:opensbi-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/opensbi/>","List-Post":"<mailto:opensbi@lists.infradead.org>","List-Help":"<mailto:opensbi-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/opensbi>,\n <mailto:opensbi-request@lists.infradead.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"opensbi\" <opensbi-bounces@lists.infradead.org>","Errors-To":"opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"The users of timer event have to compute next_event (aka timer value\nin the future) based on desired units and unit frequency. Introduce\nsbi_timer_compute_delta() and friends to simplify computing next_event\nfor timer event users.\n\nSigned-off-by: Anup Patel <anup.patel@oss.qualcomm.com>\n---\n include/sbi/sbi_timer.h | 27 +++++++++++++++++++++++++++\n lib/sbi/sbi_timer.c     | 14 ++++++++++----\n 2 files changed, 37 insertions(+), 4 deletions(-)","diff":"diff --git a/include/sbi/sbi_timer.h b/include/sbi/sbi_timer.h\nindex 914a5f12..2a040927 100644\n--- a/include/sbi/sbi_timer.h\n+++ b/include/sbi/sbi_timer.h\n@@ -88,6 +88,21 @@ struct sbi_timer_device {\n \n struct sbi_scratch;\n \n+/** Compute timer value delta based on arbitary units */\n+u64 sbi_timer_compute_delta(ulong units, u64 unit_freq);\n+\n+/** Compute timer value delta from milliseconds */\n+static inline u64 sbi_timer_compute_mdelta(ulong msecs)\n+{\n+\treturn sbi_timer_compute_delta(msecs, 1000);\n+}\n+\n+/** Compute timer value delta from microseconds */\n+static inline u64 sbi_timer_compute_udelta(ulong usecs)\n+{\n+\treturn sbi_timer_compute_delta(usecs, 1000000);\n+}\n+\n /** Generic delay loop of desired granularity */\n void sbi_timer_delay_loop(ulong units, u64 unit_freq,\n \t\t\t  void (*delay_fn)(void *), void *opaque);\n@@ -125,6 +140,18 @@ bool sbi_timer_waitms_until(bool (*predicate)(void *), void *arg,\n /** Get timer value for current HART */\n u64 sbi_timer_value(void);\n \n+/** Compute timer value after specified milliseconds */\n+static inline u64 sbi_timer_value_after_msecs(ulong msecs)\n+{\n+\treturn sbi_timer_value() + sbi_timer_compute_mdelta(msecs);\n+}\n+\n+/** Compute timer value after specified microseconds */\n+static inline u64 sbi_timer_value_after_usecs(ulong usecs)\n+{\n+\treturn sbi_timer_value() + sbi_timer_compute_udelta(usecs);\n+}\n+\n /** Get virtualized timer value for current HART */\n u64 sbi_timer_virt_value(void);\n \ndiff --git a/lib/sbi/sbi_timer.c b/lib/sbi/sbi_timer.c\nindex 4b16dbb2..ec25e5ce 100644\n--- a/lib/sbi/sbi_timer.c\n+++ b/lib/sbi/sbi_timer.c\n@@ -58,6 +58,15 @@ static void nop_delay_fn(void *opaque)\n \tcpu_relax();\n }\n \n+u64 sbi_timer_compute_delta(ulong units, u64 unit_freq)\n+{\n+\tu64 delta;\n+\n+\tdelta = ((u64)timer_dev->timer_freq * (u64)units);\n+\tdelta = delta / unit_freq;\n+\treturn delta;\n+}\n+\n void sbi_timer_delay_loop(ulong units, u64 unit_freq,\n \t\t\t  void (*delay_fn)(void *), void *opaque)\n {\n@@ -72,15 +81,12 @@ void sbi_timer_delay_loop(ulong units, u64 unit_freq,\n \t/* Save starting timer value */\n \tstart_val = get_time_val();\n \n-\t/* Compute desired timer value delta */\n-\tdelta = ((u64)timer_dev->timer_freq * (u64)units);\n-\tdelta = delta / unit_freq;\n-\n \t/* Use NOP delay function if delay function not available */\n \tif (!delay_fn)\n \t\tdelay_fn = nop_delay_fn;\n \n \t/* Busy loop until desired timer value delta reached */\n+\tdelta = sbi_timer_compute_delta(units, unit_freq);\n \twhile ((get_time_val() - start_val) < delta)\n \t\tdelay_fn(opaque);\n }\n","prefixes":["v2","4/4"]}