Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1283006lqh; Mon, 6 May 2024 02:57:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVLMYpaS3nPGKhQIVbh45s4ItT/fH7k+VHCpZbEbCbnfo8lVf6naeogA2rf/Ux9attOr3KIWsrzPeQ3f0qaengWwsGicnkr3xp1CZLM1w== X-Google-Smtp-Source: AGHT+IFkakhyMAT8cmZniqvdPPm6F9f/MpvDC4h4mkhP8bOq6MxdPrQoDzJalSLrbAiX6OWMtg3y X-Received: by 2002:a17:906:b7d7:b0:a59:a727:1e8c with SMTP id fy23-20020a170906b7d700b00a59a7271e8cmr3683630ejb.1.1714989472111; Mon, 06 May 2024 02:57:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714989472; cv=pass; d=google.com; s=arc-20160816; b=mCvYhyUKKMmYjxmFyRGbqNDX1iq6qekSHtapbeTFrgTXhFVLz82IT+qMiyvpHBXJvP 2tVv3f2cwYOmM3D6F2vH23jvQJnb80ItNRbpbVB0gw/vABsmCIXSUHmVhn5RPutOPpnG SQzB9/fo+HoVRlysKkdYJPyYmlArHDsO0YrsU+gad7ftcQ85TUs2pGkOIPqYIGpJxFge X0tqHcMtII22wCtqyvTCP+XF3SHo9snGHEgqnxWgderrpgIpIdYNNeBWRgNzmqJxb0oG bLxRRC+Lu4k91WOvQScDax0BkILxmvSZl031+cHza3VCppfkAsM+GlAnLegCEyparSs1 xsrw== 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:dkim-signature; bh=7sNEPItdnYq5dUp2uNwub+6pyruyf1tE3B+iFWZIeyI=; fh=XQR/2xX0Fo1qiXvWXbqY2WT0J3RtRMz5arolgjVK/GU=; b=AlpDH109n+248rv5WSEGuzSDDiu96YO/Ix+9APBxrQZy2XQdALbPqbH3suQME68dmZ UNHEFR/qrcdqvdEVST/Mwz/ttV4Y5OBwIH8gAXQub4Dyu8/AdA42VDHlPHm0H7MxtWLa ocKdyTSIftUxO75354MCcgVuafITi6qj/BZnXy3BDh0vnYWz5g1VLkavNWgs1DYOXGLy o1m5ejZo2yffv8XLJENNwpBtmaKEQF0U0FBEFAL2Kx9gFmsgMa0X+sGEOZABMutvdtmu nP3AriL0JMgkNlRoJDeSR6CQd7diMzDv0si9fkJ2kKqhtgqIGM96Q9kAuur6sc+1xoyp wpWA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ligb693h; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-169607-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169607-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dp20-20020a170906c15400b00a59cef2b06csi909320ejc.96.2024.05.06.02.57.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 02:57:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169607-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ligb693h; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-169607-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169607-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0F8991F23FA4 for ; Mon, 6 May 2024 09:51:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 015E81448D8; Mon, 6 May 2024 09:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ligb693h" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 7F12C143873; Mon, 6 May 2024 09:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714988983; cv=none; b=dJayyhfbo+n7Ps0xix6ieT98J3h7OCxdoqgHiMq9RhYSvcuqpPThIYm1OEMKC/03OkhnejLTfay4TiY/yDBh7/jBhl/0TGULGQGzsoNY/OlY3zKAH78Z5jnRMOB8X00Sz+iwJcGg19UAd9GjMny7+JNGEx2D3FdXdsbJBBiLojE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714988983; c=relaxed/simple; bh=zNMrnqdTnU4juvK6TJKM+ormOVy/r4fkCnoEfvM7eVQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DpH+eO3xuYiYZ9pG3OQ7/11aK0C0O3M2uOzsT7YtNpd6ZhHuqycIZkHVOBesfB/m+bafhLyDBRa92fIf3hwNuNCM2QUvQJSmMjQY+GWBcZ1+r+jJwcvttrNkamEphrUbr1KSILgIOV8xePbEnzGrvkkg9KefLCdcIUb/I6zQFc4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ligb693h; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714988981; x=1746524981; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zNMrnqdTnU4juvK6TJKM+ormOVy/r4fkCnoEfvM7eVQ=; b=ligb693hP4UpXuxCg3bHdh67HW9HJMfG7Tn7ycSrzJxm1I/HSRjQcZKU LRCawka2R4btzSzGICCY74C8Whndvor0g2ik5CN0tlRIoTIpWXnCcIFIF gw5H3JXVRpaGglcekoQ0rJJXc/4RJvJBkJGc/SzDdEMzK2SUnUqAc8J4L FY+WB3HiC+pmcX6zX/1BQbupBXI9D/Ahnqc+qRGmu9vfM+57OUPfA0TpG ZhaRK6P1FNLWzaDMVQqWR2n4FCzZ7EWCyds2z6mnHBKh2QADPHEldr6Hq KLe4aF6dH7bRXFha+k4RejawvdcoE46B9tpbstlwvIbYj0SFi5dihdGb6 Q==; X-CSE-ConnectionGUID: rs0zloBdSLKhENU2NKiCxg== X-CSE-MsgGUID: SlXtbRLqTRe86ujp10oTtw== X-IronPort-AV: E=McAfee;i="6600,9927,11064"; a="28201058" X-IronPort-AV: E=Sophos;i="6.07,258,1708416000"; d="scan'208";a="28201058" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 02:49:41 -0700 X-CSE-ConnectionGUID: MIuyeYVmSyygRWA7+cSyPw== X-CSE-MsgGUID: HxPNJw+KS/6gcQDDh5C/1Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,258,1708416000"; d="scan'208";a="58995754" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orviesa002.jf.intel.com with ESMTP; 06 May 2024 02:49:38 -0700 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Joerg Roedel , Will Deacon , "Rafael J. Wysocki" , Magnus Karlsson , nex.sw.ncis.osdt.itp.upstreaming@intel.com, bpf@vger.kernel.org, netdev@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 6/7] page_pool: check for DMA sync shortcut earlier Date: Mon, 6 May 2024 11:48:54 +0200 Message-ID: <20240506094855.12944-7-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240506094855.12944-1-aleksander.lobakin@intel.com> References: <20240506094855.12944-1-aleksander.lobakin@intel.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 We can save a couple more function calls in the Page Pool code if we check for dma_need_sync() earlier, just when we test pp->p.dma_sync. Move both these checks into an inline wrapper and call the PP wrapper over the generic DMA sync function only when both are true. You can't cache the result of dma_need_sync() in &page_pool, as it may change anytime if an SWIOTLB buffer is allocated or mapped. Signed-off-by: Alexander Lobakin --- net/core/page_pool.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/net/core/page_pool.c b/net/core/page_pool.c index e680c4af2745..84132c978773 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -399,16 +399,26 @@ static struct page *__page_pool_get_cached(struct page_pool *pool) return page; } -static void page_pool_dma_sync_for_device(const struct page_pool *pool, - const struct page *page, - unsigned int dma_sync_size) +static void __page_pool_dma_sync_for_device(const struct page_pool *pool, + const struct page *page, + u32 dma_sync_size) { +#ifdef CONFIG_DMA_NEED_SYNC dma_addr_t dma_addr = page_pool_get_dma_addr(page); dma_sync_size = min(dma_sync_size, pool->p.max_len); - dma_sync_single_range_for_device(pool->p.dev, dma_addr, - pool->p.offset, dma_sync_size, - pool->p.dma_dir); + __dma_sync_single_for_device(pool->p.dev, dma_addr + pool->p.offset, + dma_sync_size, pool->p.dma_dir); +#endif +} + +static __always_inline void +page_pool_dma_sync_for_device(const struct page_pool *pool, + const struct page *page, + u32 dma_sync_size) +{ + if (pool->dma_sync && dma_dev_need_sync(pool->p.dev)) + __page_pool_dma_sync_for_device(pool, page, dma_sync_size); } static bool page_pool_dma_map(struct page_pool *pool, struct page *page) @@ -430,8 +440,7 @@ static bool page_pool_dma_map(struct page_pool *pool, struct page *page) if (page_pool_set_dma_addr(page, dma)) goto unmap_failed; - if (pool->dma_sync) - page_pool_dma_sync_for_device(pool, page, pool->p.max_len); + page_pool_dma_sync_for_device(pool, page, pool->p.max_len); return true; @@ -701,9 +710,7 @@ __page_pool_put_page(struct page_pool *pool, struct page *page, if (likely(__page_pool_page_can_be_recycled(page))) { /* Read barrier done in page_ref_count / READ_ONCE */ - if (pool->dma_sync) - page_pool_dma_sync_for_device(pool, page, - dma_sync_size); + page_pool_dma_sync_for_device(pool, page, dma_sync_size); if (allow_direct && page_pool_recycle_in_cache(page, pool)) return NULL; @@ -842,9 +849,7 @@ static struct page *page_pool_drain_frag(struct page_pool *pool, return NULL; if (__page_pool_page_can_be_recycled(page)) { - if (pool->dma_sync) - page_pool_dma_sync_for_device(pool, page, -1); - + page_pool_dma_sync_for_device(pool, page, -1); return page; } -- 2.45.0