Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp578337lqo; Fri, 10 May 2024 08:27:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVTugAfDyY8tCDM5yAckJGLfNOvFC2yo4IHoDNDEnza1/YKTGiTZF5NQAP0iB8unkXg8/CkS1+Wo1v+E8HSMh1pvIfbdECyfAUqdEi9zA== X-Google-Smtp-Source: AGHT+IGXSwP0u7KNeBbpTkU2xTAX0NYiSXeXrmxfgD+/0RL6PVvIWUOhsI2tRQQFPkI4/kDVnVLl X-Received: by 2002:a17:902:ce92:b0:1e4:320b:4311 with SMTP id d9443c01a7336-1eefa58cfcamr93241655ad.34.1715354869117; Fri, 10 May 2024 08:27:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715354869; cv=pass; d=google.com; s=arc-20160816; b=vnJ3h1v1jNmOP86pzOPyVz6/lM04G/LtV9aWjbtE2OQsUvbKLx++qNwhQxAi4R7Slm cPzA8drW5u73JfxO8CaiCb/4ccGy0s1osurLGB5F96JIdEX0Dez9LIHlPaBiespNEKPQ FaMpj7hCOZW90Fv8timOzgZvxcdrwzf+wynmWh3ARxZ9AVxXRV1UVNJ5/77l2jxB6BUa JKrHkPa2ATUugiFsvD8pZnQAEOjKq05AnVEuvgAlq9LyWsqKIKVDKPi7Pi0u79G4CPPR +yeBV0/Qbkvui+llI+rIxswshRT37PaK/JSyRD0WBFt4YTVOPKJG3PlP7HT+3vgPnkd5 tjOA== 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=zU69lrGM6m36Whruwd23N8azPjtiRj0gN9cF2KeFYeI=; fh=fjTEHGBlHfxpStRUWSYDnC4XzEW4k1ciLDXCC1WevXQ=; b=aKiYN/S4E2bcO3iNF5J9aJh5mYcpZ32aZ7eZCkQq6xPSh2SZOudMCx0BDc59I3aKvE emE8hS5qhWokTtjY5frOjxdKwZEkoYb/qWnUEUP1iuGtb/oo8XreqIHo8IC6bmqxLoxl 8A/dSFZv6ggFuj8Du6FsxokEicdQvZnoWP5dtvo66KKO9ap5ltHGz/QxxlIrYo+bKrBG DdpxDXes6MBo1WKbJBpRQfbFQL6MW8icFM6qFIWb6sX6MIqtzR1K78/v5285cOzufKEV 1+dnsArF+KTDQnMOfzszqFSMx90URB5iImV8UEf1ge2qGWIwyabr0dEMgTVYwOZt12Va LjRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mHVMt2Nj; 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-175943-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175943-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0c0394d4si37982845ad.413.2024.05.10.08.27.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 08:27:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175943-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; dkim=pass header.i=@intel.com header.s=Intel header.b=mHVMt2Nj; 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-175943-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175943-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B93AD2879F5 for ; Fri, 10 May 2024 15:27:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 77344172BA7; Fri, 10 May 2024 15:27:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="mHVMt2Nj" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 C7E3817166E; Fri, 10 May 2024 15:27:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715354847; cv=none; b=SMByFQoinkEB4VKVf474Kg3xanCnOSQu0ERlSQiG6SwP6BxWHpv5fTWjPDrjJ2qOua9GGTwbsQDOvBMQ0QHbRxf+X3ZDTwX658qIOxIxUZwyxs4RuMjnOxwSqRsom8/qYlcziIsahg2Dp0q+L/g7d4YffN3dgU9sLRQamAJBF0Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715354847; c=relaxed/simple; bh=96/bv+FJrC/OibdNW1EQaNdvgoLzh92ZX9ptg3yrNfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kIsPRmk5LXAa5Ctv813RLXfXti0oLKdmqYeF7hCLpc5Dy4xiM/2cnayGDKYOtstmAXsC4qRCoEcnyazKI2u7rvWja10dyFjrbr02W2tdrPDPnOfHqB6Hzn5WyvdGmufVf5/dsNSl+wseUNmbl5naBCTGS/apu3EfwIhFbVhuZqs= 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=mHVMt2Nj; arc=none smtp.client-ip=192.198.163.12 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=1715354843; x=1746890843; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=96/bv+FJrC/OibdNW1EQaNdvgoLzh92ZX9ptg3yrNfQ=; b=mHVMt2Nj7mLRfCJxoa9Zf9prx5NlPpV0xTf7YJNHQg4pI+C8pYIgDXIe nKt4zP3igiOw3iFLj8xb8yeFA+C5VmmUX4lI4mRHA6n9HwvOsrI+otlWP ClRBIeUrieGRQOoSZaOvdm0LwHqChHQjWBL2xcbI8soeh61ptLIoqRAlu Trf+LxscqaTmsvWPj9OiNxTV+Temgvddk7C812tFnrLWTYfL8vq8Q2Fpv OSVp773hPAZqMTfEMqis5Gd6NPB9+k1h1syYhDQ93GlVf2hh6KWgGrZXe OpCLzUhdl2VpL73d7ebHouWdQOU9nuQUn81o/GHyhafbDSZe1bV0ox+9R Q==; X-CSE-ConnectionGUID: Y9tXu5j2QYi09OP1W14vOw== X-CSE-MsgGUID: pxT+HJvoTLm8xUwqddAs0Q== X-IronPort-AV: E=McAfee;i="6600,9927,11068"; a="15152547" X-IronPort-AV: E=Sophos;i="6.08,151,1712646000"; d="scan'208";a="15152547" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2024 08:27:22 -0700 X-CSE-ConnectionGUID: XlGYlfGWQZGEqYtdblb2Bw== X-CSE-MsgGUID: usbMoM40QpOhVM75OYdiyg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,151,1712646000"; d="scan'208";a="30208238" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orviesa008.jf.intel.com with ESMTP; 10 May 2024 08:27:19 -0700 From: Alexander Lobakin To: intel-wired-lan@lists.osuosl.org Cc: Alexander Lobakin , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , nex.sw.ncis.osdt.itp.upstreaming@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC iwl-next 01/12] libeth: add cacheline / struct alignment helpers Date: Fri, 10 May 2024 17:26:09 +0200 Message-ID: <20240510152620.2227312-2-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510152620.2227312-1-aleksander.lobakin@intel.com> References: <20240510152620.2227312-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 Following the latest netdev trend, i.e. effective and usage-based field cacheline placement, add helpers to group and then assert struct fields by cachelines. For 64-bit with 64-byte cachelines, the assertions are more strict as the size can then be easily predicted. For the rest, just make sure they don't cross the specified bound. Signed-off-by: Alexander Lobakin --- include/net/libeth/cache.h | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 include/net/libeth/cache.h diff --git a/include/net/libeth/cache.h b/include/net/libeth/cache.h new file mode 100644 index 000000000000..3245a20b22d3 --- /dev/null +++ b/include/net/libeth/cache.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2024 Intel Corporation */ + +#ifndef __LIBETH_CACHE_H +#define __LIBETH_CACHE_H + +#include + +/* __aligned_largest is architecture-dependent. Get the actual alignment */ +#define ___LIBETH_LARGEST_ALIGN \ + sizeof(struct { long __UNIQUE_ID(long_); } __aligned_largest) +#define __LIBETH_LARGEST_ALIGN \ + (___LIBETH_LARGEST_ALIGN > SMP_CACHE_BYTES ? \ + ___LIBETH_LARGEST_ALIGN : SMP_CACHE_BYTES) +#define __LIBETH_LARGEST_ALIGNED(sz) \ + ALIGN(sz, __LIBETH_LARGEST_ALIGN) + +#define __libeth_cacheline_group_begin(grp) \ + __cacheline_group_begin(grp) __aligned(__LIBETH_LARGEST_ALIGN) +#define __libeth_cacheline_group_end(grp) \ + __cacheline_group_end(grp) __aligned(4) + +#define libeth_cacheline_group(grp, ...) \ + struct_group(grp, \ + __libeth_cacheline_group_begin(grp); \ + __VA_ARGS__ \ + __libeth_cacheline_group_end(grp); \ + ) + +#if defined(CONFIG_64BIT) && L1_CACHE_BYTES == 64 +#define libeth_cacheline_group_assert(type, grp, sz) \ + static_assert(offsetof(type, __cacheline_group_end__##grp) - \ + offsetofend(type, __cacheline_group_begin__##grp) == \ + (sz)) +#define __libeth_cacheline_struct_assert(type, sz) \ + static_assert(sizeof(type) == (sz)) +#else /* !CONFIG_64BIT || L1_CACHE_BYTES != 64 */ +#define libeth_cacheline_group_assert(type, grp, sz) \ + static_assert(offsetof(type, __cacheline_group_end__##grp) - \ + offsetofend(type, __cacheline_group_begin__##grp) <= \ + (sz)) +#define __libeth_cacheline_struct_assert(type, sz) \ + static_assert(sizeof(type) <= (sz)) +#endif /* !CONFIG_64BIT || L1_CACHE_BYTES != 64 */ + +#define __libeth_cls1(sz1) \ + __LIBETH_LARGEST_ALIGNED(sz1) +#define __libeth_cls2(sz1, sz2) \ + (__LIBETH_LARGEST_ALIGNED(sz1) + __LIBETH_LARGEST_ALIGNED(sz2)) +#define __libeth_cls3(sz1, sz2, sz3) \ + (__LIBETH_LARGEST_ALIGNED(sz1) + __LIBETH_LARGEST_ALIGNED(sz2) + \ + __LIBETH_LARGEST_ALIGNED(sz3)) +#define __libeth_cls(...) \ + CONCATENATE(__libeth_cls, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__) +#define libeth_cacheline_struct_assert(type, ...) \ + __libeth_cacheline_struct_assert(type, __libeth_cls(__VA_ARGS__)) + +#define libeth_cacheline_set_assert(type, ro, rw, c) \ + libeth_cacheline_group_assert(type, read_mostly, ro); \ + libeth_cacheline_group_assert(type, read_write, rw); \ + libeth_cacheline_group_assert(type, cold, c); \ + libeth_cacheline_struct_assert(type, ro, rw, c) + +#endif /* __LIBETH_CACHE_H */ -- 2.45.0