Received: by 2002:a05:7208:c250:b0:86:f851:443 with SMTP id w16csp945284rbd; Thu, 13 Jun 2024 02:02:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVWDlCK0958pvXOpqpk+oafAL06LAedTIgUTxLnseHSG6i4c5m1Y0LGFbnGtiPBF1NT3Q9AG3iHCHfXODY5KdwePZ7lShcO3ItL9ZfzOw== X-Google-Smtp-Source: AGHT+IHC5ldgMb9MLPYc5CEbCofZInplAxcJbJ3f40qp3vNs005uIK+pxO0mn4Tp2RHoO/q7cv85 X-Received: by 2002:a05:6e02:178f:b0:375:adcd:e6c3 with SMTP id e9e14a558f8ab-375cd161edcmr46314595ab.14.1718269369465; Thu, 13 Jun 2024 02:02:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718269369; cv=pass; d=google.com; s=arc-20160816; b=0oJwOd0uh5Qd5Zkh/pg6tnE/fk32mT3CM3cIR+pOBWmryfoYYHUCmKUXswPVyt99lT SvHPlNV8s6u4sVWwk+l4WbommL9PkEUX5F7Q/CvyYDAI3cfNG7c4AZMRRs2bGT+ElQpB 7kbzZiJxSFPeXclZhjadk95lH4a6c0obpMaboTtjYQQ+aWp2lu24miwNCY1YWMPwUqb2 U1p29He/zlxM/XeLvZcKwW7wJDB0bn+Ua3yocBt9yznmQkO3nthYRP5mqTje3KjtJSb/ zEMSlocmBGDrppCi5Rzf4N+5oavCdyeDNR6hoW0k/LjKuCDatPcPRIkyRv2E6Y7siHVx sU2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=yw5CW5jOrZSABOP/Ow6ygc5frftO+gGrNG5WU8PIBfU=; fh=FmG7DF7uo3pnVoAtry0cqJ348XVgt1uALjdDXZ1F5tQ=; b=Tv+X35sxBbTIo9dG5DfGvrOdv5hLMwXlHnhN7xqgQV+IZgYIvCybr4eKSaJE1uDZrk y0qzoaZ0+kZp4YH386e8beeBJmR6AKbMPhva6c6APHhyrkW/J9NgtDQUGL8iEVbSn7cY ninfq+Gx7hdCyIL7aT6j9IJ60QDXfEE1dc/Ca6sm/q74DXNH2Ku99XWf9pc8NYHavPOK 0E1bofrO56Nse+eSeC9cbviLKq8Gwgh29ScFAkKbh/8JwXgujZLAEGHEJkrxeBEjEcvP BcYYM/DBtkK6cHnIGKU46KxPcmngnWS4KsZaOS6+QsaqnyklbYPOt8P1QVQbdbdKeFSz Y0Lg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-212901-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212901-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6fee5776b55si908785a12.763.2024.06.13.02.02.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 02:02:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212901-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-212901-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212901-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BBCF6286F15 for ; Thu, 13 Jun 2024 09:01:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 484D013E888; Thu, 13 Jun 2024 09:01:13 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (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 B42BE84D39; Thu, 13 Jun 2024 09:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718269272; cv=none; b=WuJgj+gbUpJIf0EYQfKwQLjbXx/GhMiZaX6qNgtIdz7jUcRfuPV6v33Dh1ttIYeH12PvowNdqKGJEqhoman6FE5OYbNIcGrKWGHvVX2UZ1rWdpqjD2c7MGPbJ+YHkJiUpJghO2p6kJM5UREKAv5IRqA51P4LDbZAu90yU+cLDUg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718269272; c=relaxed/simple; bh=jN3LOegYWmxr2RDFSuira4nM3GDTISmpuP/5mtjQPv8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hIScCql+CqHv4e8UIULAGj/3/9UTpcaw+XhiYnhDJCG6lVaxbZi/UXlMgMM7WRi5T8Lx9rw8rOkCnmWL1TJDTp9xJNOqrmUXXyzniw6bPgF2j/uJRFy06o+qejeatLJM6IVokP0WzvYFLqowZpqOEJbbm8IxW94sE9VBOzZljRg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4W0Gbc336nz4f3kkK; Thu, 13 Jun 2024 17:01:00 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 0A2801A0181; Thu, 13 Jun 2024 17:01:07 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBXKBFOtWpmHK1uPQ--.16895S5; Thu, 13 Jun 2024 17:01:06 +0800 (CST) From: Zhang Yi To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, djwong@kernel.org, hch@infradead.org, brauner@kernel.org, david@fromorbit.com, chandanbabu@kernel.org, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [PATCH -next v5 1/8] math64: add rem_u64() to just return the remainder Date: Thu, 13 Jun 2024 17:00:26 +0800 Message-Id: <20240613090033.2246907-2-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240613090033.2246907-1-yi.zhang@huaweicloud.com> References: <20240613090033.2246907-1-yi.zhang@huaweicloud.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-CM-TRANSID:cCh0CgBXKBFOtWpmHK1uPQ--.16895S5 X-Coremail-Antispam: 1UD129KBjvJXoWxJrWfWFy8CF4rGw1kAF1fZwb_yoW8AF47pF sxCF98GFW8KFy3Ja1IyF12yr1Yv3Z7Gr47XFWagrW8u343tw4F9r4fJF4ftF4UJws3Aw45 GFy7GrWrWryavF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUSYLPUUUUU = X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi Add a new helper rem_u64() to only get the remainder of unsigned 64bit divide with 32bit divisor. Signed-off-by: Zhang Yi Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- include/linux/math64.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/math64.h b/include/linux/math64.h index d34def7f9a8c..efbe58c157e3 100644 --- a/include/linux/math64.h +++ b/include/linux/math64.h @@ -3,6 +3,7 @@ #define _LINUX_MATH64_H #include +#include #include #include #include @@ -12,6 +13,20 @@ #define div64_long(x, y) div64_s64((x), (y)) #define div64_ul(x, y) div64_u64((x), (y)) +/** + * rem_u64 - remainder of unsigned 64bit divide with 32bit divisor + * @dividend: unsigned 64bit dividend + * @divisor: unsigned 32bit divisor + * + * Return: dividend % divisor + */ +static inline u32 rem_u64(u64 dividend, u32 divisor) +{ + if (is_power_of_2(divisor)) + return dividend & (divisor - 1); + return dividend % divisor; +} + /** * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder * @dividend: unsigned 64bit dividend @@ -86,6 +101,13 @@ static inline s64 div64_s64(s64 dividend, s64 divisor) #define div64_long(x, y) div_s64((x), (y)) #define div64_ul(x, y) div_u64((x), (y)) +static inline u32 rem_u64(u64 dividend, u32 divisor) +{ + if (is_power_of_2(divisor)) + return dividend & (divisor - 1); + return do_div(dividend, divisor); +} + #ifndef div_u64_rem static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder) { -- 2.39.2