Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp1233195img; Tue, 26 Feb 2019 17:12:48 -0800 (PST) X-Google-Smtp-Source: AHgI3IYn47nk0Yn13zZzkrhJ8L73qzSa1VXNnipscOqtAQN5YM64d8souSsEw2K/o/FgzjoxKTDw X-Received: by 2002:aa7:90c1:: with SMTP id k1mr1519540pfk.202.1551229968252; Tue, 26 Feb 2019 17:12:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551229968; cv=none; d=google.com; s=arc-20160816; b=bbf3pJosTtvEVd1JONAn6nRJVzu0zFh72QNZHQO5cZ1mm9+9yXlZwgaDrm0P/bCOBL /ag+z5wWWn4Ja24p0lIRsNASdmsHzdDBzQkaFvDD2CQ8I+RyUwVYz3OrF/tosFWjYq8E lJG8G02rVJgkz55KtRFqRA9BK7KIPmI+KJkH1OxSGxDCsZXLtzsS9NL1qmVy8+t/3o4+ kqdIUBqRxdQR1EoINc6zCVCvpHfxjZrHg97FRI0GLHE48rL2AcrUxsiA2dCTOt/fmdhS YcvmwvdwLWYm+Fe3L4DexVXIDh1IO0647um7cxZgXWTtKCi5Qm3m3snz4F3LqF224gQ3 NGrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:subject :from:cc:to:dkim-signature; bh=wmFQbYxgCFg7pzeDgrYLsS02n2Qqv1NJ96353ZpVYYU=; b=O3J9RskdnyM/nSOer88DTPV2PmYywFpba5ccpKgzcrbdpUxFWJGXTwaf6eMZJTKHj2 9ahikKoVu/GlIv2AAcKYK5HupAkNcHe7su8AqIXfc87YsBRWe+lqikVyDrQ4HrT3f17X TcNZMpkszTYDAsiEx3sSIxcQTHhmVU56six+BS7sLFODX1xHFEUnK9UT0g+xExFeH827 jeEIz1D4UCBC6nFCr/LQ0u8O/URRqiUyY1dCUug8dyiCuxnj7Rx7tu8oNNyjhAkX4tSb wI0EDI9vJ/HbJdXgiuh2di1oGeUmzyJWrG5j263Tdno++wDW8loga3GZwhTFU47BCI/o 0b0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=NEjaQSIK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2si3923247pla.287.2019.02.26.17.12.32; Tue, 26 Feb 2019 17:12:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=NEjaQSIK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729361AbfB0BMM (ORCPT + 99 others); Tue, 26 Feb 2019 20:12:12 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:38146 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729108AbfB0BML (ORCPT ); Tue, 26 Feb 2019 20:12:11 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1R18w0Z083402; Wed, 27 Feb 2019 01:12:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : from : subject : message-id : date : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=wmFQbYxgCFg7pzeDgrYLsS02n2Qqv1NJ96353ZpVYYU=; b=NEjaQSIKHRYdVMCW8tIi+URAaqB25AQXLF5krnqQpFD7QGBdUsfnsZRH6p1F52EoLEOm ue0XkMyV56njH2cO/6XOaFRx9Ra6uKcbq0VH15mk8nFG1G08fI7CJlI6ixGxMYDamzhv lpyQnGVyuWEcQRrWNIdfjYFAs3NqoEqmIejsq0lomFMtrNTzuMHgvZTYOj8tiVWi9ne5 oavFJkfz3ckB+ypUinOpamy2LFIO07aE95HrdAzfzp6dSyedU8RoZbOKXmohErZ7Wrw1 IBW+Nf+BHyHgz6v+K1LPcYclZFG4TqegPVyqfQUvwvMjgZfMhn5uvA5S9XHxkJjzHu+X Cg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2qtxtrqwnt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 27 Feb 2019 01:12:00 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x1R1Btwl013786 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 27 Feb 2019 01:11:55 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x1R1Bsh3021015; Wed, 27 Feb 2019 01:11:55 GMT Received: from [10.182.69.106] (/10.182.69.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 26 Feb 2019 17:11:54 -0800 To: linux-kernel@vger.kernel.org Cc: john.stultz@linaro.org, tglx@linutronix.de, sboyd@kernel.org, Joe Jin From: Dongli Zhang Subject: Why the return type of jiffies_to_usecs() is 'unsigned int' but not 'unsigned long' Message-ID: Date: Wed, 27 Feb 2019 09:15:02 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9179 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902270005 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, I am writing to ask about why the return type of jiffies_to_usecs() and jiffies_to_msecs() are 'unsigned int', but not 'unsigned long'? For instance, about jiffies_to_usecs(), suppose the input is 0x7770ef70 (2003893872), that is, jiffies_to_usecs(0x7770ef70). Suppose USEC_PER_SEC=1000000L and HZ=1000, we expect the result to be 0x000001d291274d80. However, as the return type is 'unsigned int', the leading 32 bits are ignored and the actual result is 0x91274d80. expected jiffies_to_usecs(0x7770ef70) : 0x000001d291274d80 current jiffies_to_usecs(0x7770ef70) : 0x91274d80 I think jiffies_to_msecs() would have the same issue. As both jiffies_to_usecs() and jiffies_to_msecs() are totally called by 680 locations in the lasted mainline linux kernel, the below patch would generate lots of warnings. Almost all warnings are due to printk or trace event. diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h index fa92824..d961b30 100644 --- a/include/linux/jiffies.h +++ b/include/linux/jiffies.h @@ -288,8 +288,8 @@ extern unsigned long preset_lpj; /* * Convert various time units to each other: */ -extern unsigned int jiffies_to_msecs(const unsigned long j); -extern unsigned int jiffies_to_usecs(const unsigned long j); +extern unsigned long jiffies_to_msecs(const unsigned long j); +extern unsigned long jiffies_to_usecs(const unsigned long j); static inline u64 jiffies_to_nsecs(const unsigned long j) { diff --git a/kernel/time/time.c b/kernel/time/time.c index 2edb508..72c139d 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -305,7 +305,7 @@ COMPAT_SYSCALL_DEFINE1(adjtimex, struct compat_timex __user *, utp) * Avoid unnecessary multiplications/divisions in the * two most common HZ cases: */ -unsigned int jiffies_to_msecs(const unsigned long j) +unsigned long jiffies_to_msecs(const unsigned long j) { #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ) return (MSEC_PER_SEC / HZ) * j; @@ -322,7 +322,7 @@ unsigned int jiffies_to_msecs(const unsigned long j) } EXPORT_SYMBOL(jiffies_to_msecs); -unsigned int jiffies_to_usecs(const unsigned long j) +unsigned long jiffies_to_usecs(const unsigned long j) { /* * Hz usually doesn't go much further MSEC_PER_SEC. -- 2.7.4 ------------------------------------------------------ While I am still struggling on those warnings, would you please confirm if the 'unsigned int' return type is by design on purpose or it is a bug as I mentioned above? So far the latest 4.9.x stable kernel is affected by a steal usage 100% issue and the root cause is the incorrect return type of jiffies_to_usecs(). I will discuss that in another email thread for more details later to facilitate people to grep/search for similar/same issue on google in the future. That issue is not reproducible after I change the return type of jiffies_to_usecs() to 'unsigned long'. Thank you very much! Dongli Zhang