Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 May 2020 10:10:08 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r360623 - head/sys/compat/linuxkpi/common/include/linux
Message-ID:  <202005041010.044AA8wZ065436@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Mon May  4 10:10:07 2020
New Revision: 360623
URL: https://svnweb.freebsd.org/changeset/base/360623

Log:
  Optimise use of sg_page_count() in __sg_page_iter_next() in the LinuxKPI.
  No need to compute value twice.
  
  No functional change intended.
  
  MFC after:	1 week
  Sponsored by:	Mellanox Technologies

Modified:
  head/sys/compat/linuxkpi/common/include/linux/scatterlist.h

Modified: head/sys/compat/linuxkpi/common/include/linux/scatterlist.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/scatterlist.h	Mon May  4 09:58:45 2020	(r360622)
+++ head/sys/compat/linuxkpi/common/include/linux/scatterlist.h	Mon May  4 10:10:07 2020	(r360623)
@@ -416,6 +416,8 @@ sg_page_count(struct scatterlist *sg)
 static inline bool
 __sg_page_iter_next(struct sg_page_iter *piter)
 {
+	unsigned int pgcount;
+
 	if (piter->internal.nents == 0)
 		return (0);
 	if (piter->sg == NULL)
@@ -424,8 +426,11 @@ __sg_page_iter_next(struct sg_page_iter *piter)
 	piter->sg_pgoffset += piter->internal.pg_advance;
 	piter->internal.pg_advance = 1;
 
-	while (piter->sg_pgoffset >= sg_page_count(piter->sg)) {
-		piter->sg_pgoffset -= sg_page_count(piter->sg);
+	while (1) {
+		pgcount = sg_page_count(piter->sg);
+		if (likely(piter->sg_pgoffset < pgcount))
+			break;
+		piter->sg_pgoffset -= pgcount;
 		piter->sg = sg_next(piter->sg);
 		if (--piter->internal.nents == 0)
 			return (0);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005041010.044AA8wZ065436>