From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 71D762C3277 for ; Fri, 26 Dec 2025 18:00:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766772005; cv=none; b=S1XfgejLUcp170MdB5S20D6fUAkh0o7k7xPXeP/Ee+CKMhZMutvxzxx/04moGKxeF0Jeltmp2+YnPK6sRpoutdyfqZNxBuz+D7xTTFFHw2/smXZcCyDg3edwb81REDIA7TtCCVCyOLyhvQOHAjYSSxHTGNv6RJKMX0uL1lGsdcw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766772005; c=relaxed/simple; bh=y/I7q0O4Ga58ZlxZPQG8u8oKJCJD29rWNCtbiWnl85g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=omVa+Co0lPyTaO0IG4p6/r9beMG7YSn8HI5cmm8F2HSwaDdD3Q6pkenmmkZW/n9q7AlzJfUzh+CL7wv2HlU05M4w53SovzJXxF7zK/X4urT99KKsKSwiYGPaGr5MPu98EdOcX4R9Ff5vwk+eXKzFqwrG72NvO4O109yrmnpJwo8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=OGfgBETZ; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=IbT6VYCB; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="OGfgBETZ"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="IbT6VYCB" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5BQ8c2Xe951139 for ; Fri, 26 Dec 2025 18:00:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ZfYs8xJ+7MQfozKFwq/ifb0ZE64KSo+e0VJzhZF5FyM=; b=OGfgBETZxSB9JVKi du1A8RUCqiqIV1/yG3Qq0JVpLyIduPwsKkyZH9Pj+FpC1U2CnpIe0HjUp/3+VRpx TGmShtWSN9wcPa9D3RqEqKOVOp3QLzn1KGlsVWnGb85oPkTmZnltDISzD81UBXGZ 6AQMTx4Q0auILoSAURFDir3Z2LaLTcbC9ECWukw+PaW8AhFb7Ov7ccTRQqh/ikKW hW0N4zPxP1SSCkbNDMoygx2GpjPSh2h2wZ8zQgc/B2rasKUjEwOjlAtgF2lSV3xi XFfxw3arHrJR0WuBNDrI1BJbjDEElD2BuxpoP2oVJw20duZfXYdUMIjaFLoFunEl bAvSxQ== Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4b8v9y3qec-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 26 Dec 2025 18:00:02 +0000 (GMT) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-7c7957d978aso8839277b3a.1 for ; Fri, 26 Dec 2025 10:00:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1766772001; x=1767376801; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ZfYs8xJ+7MQfozKFwq/ifb0ZE64KSo+e0VJzhZF5FyM=; b=IbT6VYCBywhZbhCEIri2QmWyMeZpPN6weEBjHNr/t4yUteyj6WukL5iJjB9BT5N+4H T6/EXkmcvQUr0wF/zvlRbzA8gO82yqtzWhtvCTsFak2/w2GzWSIaCgALoJigzK7XOCjq DCnGHgECP5F2cYGC1rLUDnL/jITzNUA1K+ldvcJJPKGqEZ1WYqFkbNC0u3io/+3cnfQv bE3uHWSbvqZu41aKorXqWjwtAnVfDXZOA2CWtr1AoVdpYuqPYJVP2gQjReAYEIbn3pck UwaidpJfCgUm/La454IFS0JHpA4Ki4IO5L4xNNd+Y50oam4ovFHYOftXy0aLOZSRkDuz cl5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766772001; x=1767376801; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZfYs8xJ+7MQfozKFwq/ifb0ZE64KSo+e0VJzhZF5FyM=; b=isX4Fyd23v9lGjIyOb74RW/zTX7eczksE1zYBH1iGF1bOOczabV4fDkkVTOjBGxKPT pQrblccL6JdWdoDXDqcKfFkUV4NyTnRyLjnu+cTS6CinVf5WoswQtpfaX9zAwv8EJAGS YB8Z92uAFTFAHtc5VBtUl7qlJFdiCaRgP5JLGhjCHUbPDXHcXqCEAo/E8NwLu4kLIUx4 cfvxIWDU3lmiY/yAz2n9+ErM9tbChAY+drXtZ7yPurPASqcJhNnbhL3mGq6fCimDU5Wf yuBu3Ihs7PIa3JdH+gtkNAo9ix9pTonRCbgUpLmpBYgCXOOLxeqwA8mkBM6zL6QIdLq8 Kmyw== X-Forwarded-Encrypted: i=1; AJvYcCU+pOruw4uEhPDC3BCxszS+t0gf8v9soqobUAmkM2gpvqH2Uzuy3H59CSdR6FLIaz0d29xYJdldYXdHXNQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyWW2qOUU6nCB24VJhTzA1MA5WmKihAQWGcJO/xYSyyfpnK8YdC q8XgFnXMQsDubH+h7j/wb0UsbpS0XiRrLMr599fQ/b8bFZi8+M/7PVYO5GnJlx+cBFm3fBfzYaj 4ysxXqZrpB+0nCDuivFfz6yf4b4WbpkfQ05BnJl4qcGsbvGnh9mmS6HAX7DlJn+U+zxc= X-Gm-Gg: AY/fxX5H1aOt6kOYzOrLTQvX11hG3NX/sL0m2oHrtYVwhMNUDd9QXIdF58tph2g8cOV AabbfDnqxzCtf8UoSggbEOL9fJgtBv2ZbnyB86OiQj7bmWnXdCy7964KLHHuu36qk0RR1a5RWht Y+ALzb+pJujg2SVmis19siInoIt1zOIvTlJ/eTTCfn/OFkr3igf9N2Ib4ckErZ17QMDVqwcnbFv gsUaPkMQGAfeb6/gsHPGSaN6g6nQaJre5vqSv7ijY7Mk/AIHc0FcAWbQci/YDRfItQbH0QISv7q AKduEX/83759U2q1yYaRDtmAZcNKlhcn+eRuU0DQRgDdqVcEeqmlMhBkECpJxSLEnUA4Kl8DBjo FwYlo1EOodFN5oF1/WZbkcldwo3xkNNhaWPofxw== X-Received: by 2002:a05:6a00:e11:b0:7ab:e844:1e76 with SMTP id d2e1a72fcca58-7ff6420d910mr19282733b3a.5.1766772001162; Fri, 26 Dec 2025 10:00:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrjdKe74XNeyCLrdBcvmvuUM9K5k3eYfkt5yHRiiGMnTiJ4XHanppN7uvWarTMwn+8NtSfwg== X-Received: by 2002:a05:6a00:e11:b0:7ab:e844:1e76 with SMTP id d2e1a72fcca58-7ff6420d910mr19282715b3a.5.1766772000625; Fri, 26 Dec 2025 10:00:00 -0800 (PST) Received: from [192.168.0.195] ([49.204.27.144]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7ff7e0a1a2asm22487141b3a.41.2025.12.26.09.59.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Dec 2025 10:00:00 -0800 (PST) Message-ID: Date: Fri, 26 Dec 2025 23:29:55 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] clk: qcom: rcg2: compute 2d using duty fraction directly To: Bjorn Andersson Cc: Michael Turquette , Stephen Boyd , Taniya Das , Ajit Pandey , Imran Shaik , Jagadeesh Kona , linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org References: <20251222-duty_cycle_precision-v1-1-b0da8e9fdab7@oss.qualcomm.com> Content-Language: en-US From: Taniya Das In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: VaFOC6e-zX8aawgbevSkn62EicdKVnyQ X-Proofpoint-ORIG-GUID: VaFOC6e-zX8aawgbevSkn62EicdKVnyQ X-Authority-Analysis: v=2.4 cv=Uolu9uwB c=1 sm=1 tr=0 ts=694ecd22 cx=c_pps a=rEQLjTOiSrHUhVqRoksmgQ==:117 a=CGk/GHK3MkyyyFueakV4jQ==:17 a=IkcTkHD0fZMA:10 a=wP3pNCr1ah4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=COk6AnOGAAAA:8 a=EUspDBNiAAAA:8 a=62drwnB435mJaXsBqUkA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=2VI0MkxyNR6bbpdq8BZq:22 a=TjNXssC_j7lpFel5tvFf:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjI2MDE2OCBTYWx0ZWRfXx8leeBbyGZcA 4m4YCONqzCFX+zDCBh92vMn3/XOxOEb/Vdnn6GRSK+Aq6/eKSDLyH7Er7/ZD54jFpPGdR43+aM2 oiETRqBwX21oMoSD3XtV/K02AeXwHo4uGKDjq8MzbDvHH5GdEpS1ooGY8FdN4HuhcfRR7Qe2N9b H88R4/TB5n3NdJryrJDN+Ba/wIBzRl8XJmXToFBKgln+/4imY6wiHIjo+3e9MXCVYl6Qixjg9Bf /5GxEHYGdHoqBbe/HB4hr0UWlsCXEyxGUimRPkQgO5J1w1SCfwLcYpTx9sSvjheuov1oDxvkoWs pGxOKrkfhey0bu1OuIAasrK4bS9Mx0W8E3EwBl7riW/KgSRX9Ynp0uQNAkNfpNdn1ZEUpamv9jd RTvzURrSeJynrnb0YDxUaCOs+ROPW/lGrrvXag4+cVS97rLT/Ym8z0WNkMAHG2WQTbVKlle0GeI jAchjpM4fQ7I0fT5IxQ== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-12-26_05,2025-12-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 spamscore=0 suspectscore=0 adultscore=0 phishscore=0 impostorscore=0 bulkscore=0 lowpriorityscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2512120000 definitions=main-2512260168 On 12/25/2025 9:21 AM, Bjorn Andersson wrote: > On Tue, Dec 23, 2025 at 04:18:20PM +0530, Taniya Das wrote: >> >> >> On 12/23/2025 12:39 AM, Bjorn Andersson wrote: >>> On Mon, Dec 22, 2025 at 10:38:14PM +0530, Taniya Das wrote: >>>> From: Taniya Das >>> >>> Please use oss.qualcomm.com. >>> >> >> My bad, will update it. >> >>>> >>>> The duty-cycle calculation in clk_rcg2_set_duty_cycle() currently >>>> derives an intermediate percentage `duty_per = (num * 100) / den` and >>>> then computes: >>>> >>>> d = DIV_ROUND_CLOSEST(n * duty_per * 2, 100); >>>> >>>> This introduces integer truncation at the percentage step (division by >>>> `den`) and a redundant scaling by 100, which can reduce precision for >>>> large `den` and skew the final rounding. >>>> >>>> Compute `2d` directly from the duty fraction to preserve precision and >>>> avoid the unnecessary scaling: >>>> >>>> d = DIV_ROUND_CLOSEST(n * duty->num * 2, duty->den); >>>> >>>> This keeps the intended formula `d ≈ n * 2 * (num/den)` while performing >>>> a single, final rounded division, improving accuracy especially for small >>>> duty cycles or large denominators. It also removes the unused `duty_per` >>>> variable, simplifying the code. >>>> >>>> There is no functional changes beyond improved numerical accuracy. >>>> >>>> Fixes: 7f891faf596ed ("clk: qcom: clk-rcg2: Add support for duty-cycle for RCG") >>>> Signed-off-by: Taniya Das >>>> --- >>>> Signed-off-by: Taniya Das >>>> --- >>>> drivers/clk/qcom/clk-rcg2.c | 6 ++---- >>>> 1 file changed, 2 insertions(+), 4 deletions(-) >>>> >>>> diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c >>>> index e18cb8807d73534c6437c08aeb524353a2eab06f..2838d4cb2d58ea1e351d6a5599045c72f4dc3801 100644 >>>> --- a/drivers/clk/qcom/clk-rcg2.c >>>> +++ b/drivers/clk/qcom/clk-rcg2.c >>>> @@ -755,7 +755,7 @@ static int clk_rcg2_get_duty_cycle(struct clk_hw *hw, struct clk_duty *duty) >>>> static int clk_rcg2_set_duty_cycle(struct clk_hw *hw, struct clk_duty *duty) >>>> { >>>> struct clk_rcg2 *rcg = to_clk_rcg2(hw); >>>> - u32 notn_m, n, m, d, not2d, mask, duty_per, cfg; >>>> + u32 notn_m, n, m, d, not2d, mask, cfg; >>>> int ret; >>>> >>>> /* Duty-cycle cannot be modified for non-MND RCGs */ >>>> @@ -774,10 +774,8 @@ static int clk_rcg2_set_duty_cycle(struct clk_hw *hw, struct clk_duty *duty) >>>> >>>> n = (~(notn_m) + m) & mask; >>>> >>>> - duty_per = (duty->num * 100) / duty->den; >>>> - >>>> /* Calculate 2d value */ >>>> - d = DIV_ROUND_CLOSEST(n * duty_per * 2, 100); >>>> + d = DIV_ROUND_CLOSEST(n * duty->num * 2, duty->den); >>> >>> This looks better/cleaner. But for my understanding, can you share some >>> example numbers that shows the problem? >>> >> >> Sure Bjorn, will share the examples. >> > > I don't think these examples need to necessarily be added in the git > history - in particular since the proposed new style looks more > reasonable than what's currently is in the code. > > So, providing them here would suffice, for me at least. Frequency requirement from customers as below. F(10000, P_BI_TCXO, 2, 1, 960), For example, with N = 960. Duty cycle(%)| num/den | d_old |NOT_2D(old)| d_new |NOT_2D(new)|Match -------------------------------------------------------------------- 0.05 | 1/2000 | 0 |0x0000FFFF | 1 |0x0000FFFE |No 0.10 | 1/1000 | 0 |0x0000FFFF | 2 |0x0000FFFD |No 0.3125 | 1/320 | 0 |0x0000FFFF | 6 |0x0000FFF9 |No 0.50 | 1/200 | 0 |0x0000FFFF | 10 |0x0000FFF5 |No 0.78125 | 1/128 | 0 |0x0000FFFF | 15 |0x0000FFF0 |No 2.00 | 1/50 | 38 |0x0000FFD9 | 38 |0x0000FFD9 |Yes 2.10 | 7/333 | 38 |0x0000FFD9 | 40 |0x0000FFD7 |No 2.50 | 1/40 | 38 |0x0000FFD9 | 48 |0x0000FFCF |No 3.00 | 3/100 | 58 |0x0000FFC5 | 58 |0x0000FFC5 |Yes > > > Adding kunit tests certainly sounds useful though. > Sure, will take a look. -- Thanks, Taniya Das