From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7C5A343F76; Sat, 4 May 2024 02:56:30 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 09E164025D; Sat, 4 May 2024 02:56:30 +0200 (CEST) Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by mails.dpdk.org (Postfix) with ESMTP id BB6FC40150 for ; Sat, 4 May 2024 02:56:28 +0200 (CEST) Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6f457853950so204203b3a.0 for ; Fri, 03 May 2024 17:56:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1714784187; x=1715388987; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=S8qvHd/AA9dcWsF1SugYGg+stXxBJfyRpfkVHd6YQ34=; b=HbS680TX4TSS0o49N89W5ecIMvevJJOn3XvDi09v5Fn3gI0Zm553bmmZcWJ2Wx1PzC AnMpknzOkEnRpr1IgaF9fgV9pDRTmbdP5jOLCbRdhS0XQBB3xku+XLPTlJhpieAm39+8 eHzwMLIAKTwcDG4+/0ONTCptS+YzKxNW8beE8V1ydZqb7zDO8VI55U1+c+gSkgHWO3K5 KvDhW1ydL5SqcA9haHsLlmhbWIUvv+k3+MJDfyWGuyx6x68YXhLB1yZGvMu+oyx+ZcWS unZl0nFGJJKixTwKL6QRe0uT2y76uCIeF5LAVczGQr/iUvIbGE4BQFY3O8cLUzO+WBOB 6adw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714784187; x=1715388987; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S8qvHd/AA9dcWsF1SugYGg+stXxBJfyRpfkVHd6YQ34=; b=CuVlRaCJYWxOPUVa/ReozflhVpzTTvGeLTqvlQfoSUPDYoEeZv1bGd3BmsX/+B7wCg Y1ZqRpqrsmt8XOiddv8R4qRCvkIMe2rDL9Nr1W3kN/Vr50EZ04CoYKDZvOF6DaBjBF0m Lk8OhyAH0epwWIgUe533/jYaYlKqHAnz3Jm/NFryhfqoCQBtFu3/DHRQx0CuM2KI8093 uGNSGbov3H6kYUR+XEwQgiWXEr2juoH3x7Tqqmw31e8QyUAXgQHRCIk711PQlja1p/eL +hv+Go9/R1v8K9SEn9nbYPqwmfR/MV7W0ouJ8/UYKAeRzVfRLigaRgdFoJuxqWBgsvv6 7IRg== X-Forwarded-Encrypted: i=1; AJvYcCUlyrQGFZqcKDIoSrhXT7ZEEWt3zH/BH1Cvbwq04XAtzhxcxomHG/x9Mdy4GoYP2w38OniI1EFJYTwFN4o= X-Gm-Message-State: AOJu0YyY9vajPUlDAKlawR25HSNuxxGGvfoU4mZU4P9tPQDyKFwtXe+L SywTRO19o3HVhSJqwLNUioittzl2A23lM9fAoTG7Y5cPxsrRXxNN5plzTsKeh1Y= X-Google-Smtp-Source: AGHT+IEmEkp0hcnqQ11oYJPRK7J7BNXf8oAx4J89S5FGyjX9UZKn46rqkkDT95U13lVM1m6PFA2RNw== X-Received: by 2002:a17:90a:b281:b0:2aa:8130:e3eb with SMTP id c1-20020a17090ab28100b002aa8130e3ebmr10747064pjr.11.1714784187544; Fri, 03 May 2024 17:56:27 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id r89-20020a17090a43e200b002a7e4b99752sm7598584pjg.0.2024.05.03.17.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 17:56:27 -0700 (PDT) Date: Fri, 3 May 2024 17:56:24 -0700 From: Stephen Hemminger To: Daniel Gregory Cc: Ruifeng Wang , dev@dpdk.org, Punit Agrawal , Liang Ma Subject: Re: [PATCH] eal/arm: replace RTE_BUILD_BUG on non-constant Message-ID: <20240503175624.54dd0a72@hermes.local> In-Reply-To: <20240503094605.GB3883350@ste-uk-lab-gw> References: <20240502142116.63760-1-daniel.gregory@bytedance.com> <20240502092045.02a426fe@hermes.local> <20240502174420.GA3883350@ste-uk-lab-gw> <20240502144826.42d7012a@hermes.local> <20240503094605.GB3883350@ste-uk-lab-gw> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Fri, 3 May 2024 10:46:05 +0100 Daniel Gregory wrote: > On Thu, May 02, 2024 at 02:48:26PM -0700, Stephen Hemminger wrote: > > There are already constant checks like this elsewhere in the file. > > Yes, but they're in macros, rather than inlined functions, so my > understanding was that at compile time, macro expansion has put the > memorder constant in the _Static_assert call as opposed to still being > a function parameter in the inline definition. Gcc and clang are smart enough that it is possible to use the internal __builtin_constant_p() in the function. Some examples in DPDK: static __rte_always_inline int rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table, unsigned int n, struct rte_mempool_cache *cache) { int ret; unsigned int remaining; uint32_t index, len; void **cache_objs; /* No cache provided */ if (unlikely(cache == NULL)) { remaining = n; goto driver_dequeue; } /* The cache is a stack, so copy will be in reverse order. */ cache_objs = &cache->objs[cache->len]; if (__extension__(__builtin_constant_p(n)) && n <= cache->len) { It should be possible to use RTE_BUILD_BUG_ON() or static_assert here. Changing a compile time check into a runtime check means that buggy programs blow up much later and in a confusing manner. And it impacts all code that is doing a spin lock, certainly one of the hottest paths in DPDK.