Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp35850pxb; Thu, 30 Sep 2021 00:03:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOpna94hfYINCKNbOVL8dt7RtzUEKcU6G8GIqCXGAlL7AjDZv+H+Fo78cuIKFHg9YvfiKP X-Received: by 2002:a63:e756:: with SMTP id j22mr3511481pgk.362.1632985418773; Thu, 30 Sep 2021 00:03:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632985418; cv=none; d=google.com; s=arc-20160816; b=J2mv8ZqbZ9fUIvSBcG4wo3BqFsC6SnjGXxQhtHUyO4LBFcGCcEdri3tlr+3XMrhGoV mh7YSRtprgQ4XfyOfRv/N5N7LfHI2pHfnchXis3PvRcCbGhrVmy/tbTcl11ubUW6mGTv dxQWXuH7EAH7nlh01CODJJVW6dWkG0H+bE+t9CUQ2N9epDV/cycwbe9+tQtSB72wKU4T Qa0AWQ3Nb/sGxGNvFFhk9LrM6R9OnyFfNaiMua7A1dqfqRbLUAJwVrtWSLYhn5a02JHf ZFQ/G5cq12cCqThEZ0G9IXEwDz6Ky8YvHhHKN8TOxj/Jn4adf44jtFpBEWe32dOlJkmL S9qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :in-reply-to:from:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature:dkim-filter; bh=eW1eEXG11Bypoi+FV8uiotGNCEojVR4mkRgvwylIyMI=; b=RpuIKBUJmIJiotK+hMjMdTVud+WaKdbrK0VCEP+xmqBzeqq2gqkNS3/kS8uvjzIGcA soXiQFKy/sRQDiFSpENcsj6JJAEfzUicKcpYy7+4FmcSXPa0h13XqnNNteSGUUgMJ3XM L/8ZXUcsneyjcMYj7VyOBvMimDk43Ms3SECJgcnDt0gnuDwOsArb+CjpJsXEfltuK+yT EJjut5GYTqj9LkBr2k2UdZiQN2xUcQvOItVkun1KtCPzaUxNHt9jWWxlictu87j/98tV zHp2OxqdqadFfHjYVn1uVhf7CXfg603vs/KFHcNkxmfQ6xfOu0baTCSBvjJuV3QdYoC3 Y7sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=n4ifgIDr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m13si2577320pff.61.2021.09.30.00.03.11; Thu, 30 Sep 2021 00:03:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=n4ifgIDr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348478AbhI3HDQ (ORCPT + 99 others); Thu, 30 Sep 2021 03:03:16 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:54977 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348460AbhI3HDO (ORCPT ); Thu, 30 Sep 2021 03:03:14 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20210930070130euoutp02fb19142c66a15f545f67c8a40d2fc36a~ph3hSIqgt0102501025euoutp02Q for ; Thu, 30 Sep 2021 07:01:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20210930070130euoutp02fb19142c66a15f545f67c8a40d2fc36a~ph3hSIqgt0102501025euoutp02Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1632985290; bh=eW1eEXG11Bypoi+FV8uiotGNCEojVR4mkRgvwylIyMI=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=n4ifgIDrP2fs0YjViVnhghZStSeMkUJKeYw07rW4617KPJRnA1Ijich0lBl3AYFr6 +EGSAf9cGWMcMTrVN7TDqhX1kvgbe5OB/jUXcj4/FILDUumi0r5XLg/4W5rziZEXCG fhbgDsjGBHn3QqAC/4lJd3rvjTi0HxrAkvLhcqu0= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20210930070130eucas1p11d6ee47400095ab39a21a45745240a83~ph3g_prRW1326013260eucas1p1Y; Thu, 30 Sep 2021 07:01:30 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 41.C6.42068.AC065516; Thu, 30 Sep 2021 08:01:30 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20210930070129eucas1p1c6b125c2814aaa411fbb1e947ccfeda1~ph3gfVwP90109601096eucas1p18; Thu, 30 Sep 2021 07:01:29 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20210930070129eusmtrp1cd969802e2fb15e366ec5d7073a2927c~ph3gel4ss1326113261eusmtrp1I; Thu, 30 Sep 2021 07:01:29 +0000 (GMT) X-AuditID: cbfec7f4-c71ff7000002a454-aa-615560caddc1 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 20.6B.20981.9C065516; Thu, 30 Sep 2021 08:01:29 +0100 (BST) Received: from [106.210.131.79] (unknown [106.210.131.79]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20210930070129eusmtip28d7df6ec940314fd751080be28efd822~ph3gCEHsy2177221772eusmtip2C; Thu, 30 Sep 2021 07:01:29 +0000 (GMT) Message-ID: <3bf2b596-ad7a-c62b-77db-89f1a252d3f8@samsung.com> Date: Thu, 30 Sep 2021 09:01:28 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Thunderbird/93.0 Subject: Re: [PATCH v2 2/3] drm/i915/utils: do not depend on config being defined Content-Language: en-GB To: Lucas De Marchi Cc: intel-gfx@lists.freedesktop.org, Daniel Vetter , dri-devel@lists.freedesktop.org, Masahiro Yamada , linux-kernel@vger.kernel.org From: Andrzej Hajda In-Reply-To: <20210929225433.7z76swcouyas7upd@ldmartin-desk2> Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIKsWRmVeSWpSXmKPExsWy7djPc7qnEkITDdYdE7BYfmYds8WVr+/Z LGZP2MxkcXnXHDaLp4+XsVk8fHCD1YHNY/Gel0wem1Z1snnc7z7O5PF5k1wASxSXTUpqTmZZ apG+XQJXxvqV7WwFl5Qr1rXUNjDOkO1i5OSQEDCRuN/4nrGLkYtDSGAFo8SNVfPYIJwvjBL3 VjYwg1QJCXxmlDjVkgzT8XfefxaIouWMEjt/r2GGcN4zSjz6tBUow8HBK2AncbExFaSBRUBV 4vj1t2CDeAUEJU7OfMICYosKJEi8vreJDcQWFgiW+HzsLlicWUBcounLSlYQW0RAT2LXketM IPOZBbYzSux+0QPWwCagKfF3800wm1PAVmLCrnWMEM3yEs1bZzNDXHqBQ2LepWAI20XiwYGT LBC2sMSr41vYIWwZidOTe6Di9RL3V7SAPSMh0MEosXXDTqhB1hJ3zv1iA3mMGWjx+l36EGFH iZYpJxlBwhICfBI33gpCnMAnMWnbdGaIMK9ER5sQRLWixP2zW6EGikssvfCVbQKj0iykUJmF 5PtZSJ6ZhbB3ASPLKk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Q5mJRHeH+LBiUK8KYmVValF+fFFpTmpxYcY TYGhMZFZSjQ5HxjjeSXxhmYGpoYmZpYGppZmxkrivCZH1sQLCaQnlqRmp6YWpBbB9DFxcEo1 MC3LevFMP5R961vBYys1HD36Cn4fZ59l/MOl4YzsFJGfd3bVm23hMr6578vSINfPh3b7Sa7V cNjIcfKNncDs29objN9NY3+u0uH9UbbJtsXzypPDF+uqprLo9Kz9XGEo2HD4xKZHN2ycotm2 qLTPCDmQvvSnjOzK1UydtuvnLny4c+OWhrry7GKbWwmxosbzwq7x3p8Soyq2/uHp3jP76zlN jp2K6rC0v3ur3LK5uD711o8wB71DtwszAs/+OF1yz0iWceP9b7JZwU17Zz1Yp/9OdO/jp8+E 7h3QYWaeNGO5We69O03hNlJqxm+1I3o35S3cb6jw4zvfi8LkdNaPX5fYbxF/c2blrcB1oat5 PQ4osRRnJBpqMRcVJwIAGJwrfzkDAAA= X-CMS-MailID: 20210930070129eucas1p1c6b125c2814aaa411fbb1e947ccfeda1 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20210929183439eucas1p1de30c3fb5681a8c8d250f482954f92ed X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20210929183439eucas1p1de30c3fb5681a8c8d250f482954f92ed References: <20210929183357.1490204-1-lucas.demarchi@intel.com> <20210929183357.1490204-3-lucas.demarchi@intel.com> <20210929225433.7z76swcouyas7upd@ldmartin-desk2> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org W dniu 30.09.2021 o 00:54, Lucas De Marchi pisze: > On Wed, Sep 29, 2021 at 11:08:18PM +0200, Andrzej Hajda wrote: >> >> W dniu 29.09.2021 o 20:33, Lucas De Marchi pisze: >>> Like the IS_ENABLED() counterpart, we can make IS_CONFIG_NONZERO() to >>> return the right thing when the config is not defined rather than a >>> build error, with the limitation that it can't be used on preprocessor >>> context. >>> >>> The trick here is that macro names can't start with a number or >>> dash, so >>> we stringify the argument and check that the first char is a number >>> != 0 >>> (or starting with a dash to cover negative numbers). Except for -O0 >>> builds the strings are all eliminated. >>> >>> Taking CONFIG_DRM_I915_REQUEST_TIMEOUT in >>> drivers/gpu/drm/i915/gem/i915_gem_context.c as example, we have the >>> following output of the preprocessor: >>> >>> old: >>>   if (((20000) != 0) && >>> new: >>>   if (( ("20000"[0] > '0' && "20000"[0] < '9') || "20000"[0] == '-' >>> ) && >>> >>> New one looks worse, but is also eliminated from the object: >>> >>> $ size drivers/gpu/drm/i915/gem/i915_gem_context.o.* >>>     text    data     bss     dec     hex filename >>>    52021    1070     232   53323    d04b >>> drivers/gpu/drm/i915/gem/i915_gem_context.o.new >>>    52021    1070     232   53323    d04b >>> drivers/gpu/drm/i915/gem/i915_gem_context.o.old >>> >>> Signed-off-by: Lucas De Marchi >>> --- >>>   drivers/gpu/drm/i915/i915_utils.h | 6 +++++- >>>   1 file changed, 5 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/gpu/drm/i915/i915_utils.h >>> b/drivers/gpu/drm/i915/i915_utils.h >>> index 02bbfa4d68d3..436ce612c46a 100644 >>> --- a/drivers/gpu/drm/i915/i915_utils.h >>> +++ b/drivers/gpu/drm/i915/i915_utils.h >>> @@ -28,6 +28,7 @@ >>>   #include >>>   #include >>>   #include >>> +#include >>>   #include >>>   #include >>> >>> @@ -469,6 +470,9 @@ static inline bool timer_expired(const struct >>> timer_list *t) >>>    * >>>    * Returns 0 if @config is 0, 1 if set to any value. >>>    */ >>> -#define IS_CONFIG_NONZERO(config) ((config) != 0) >>> +#define IS_CONFIG_NONZERO(config) (                        \ >>> +    (__stringify_1(config)[0] > '0' && __stringify_1(config)[0] < >>> '9') ||    \ >>> +    __stringify_1(config)[0] == '-'                        \ >>> +) >> >> >> Quite clever trick, but I see two issues: >> >> - gcc < 8.1 treats expressions with string indices (ex. "abc"[0]) as >> non-constant expressions, so they cannot be used everywhere, for example >> in global variable initializations, > > ugh, that would kill the idea - having the strings and additional > runtime checks would not be good. Maybe if we check with > __builtin_constant_p() and do the simpler expansion if it's not > constant? I think it is just matter of disallowing such construct in places where compiler expects constant expression. If accepted, the expression is apparently evaluated in compile time. See [1]. [1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69960#c18 > >> >> - it does not work with hex (0x1) or octal values (01) > > indeed, but I guess that would be fixable by checking (s[0] == '0' && > s[1] == '\0')? > However, it seems kconfig doesn't support setting int options to hex or > octal. I've spotted in include/generated/autoconf.h following line: #define CONFIG_ILLEGAL_POINTER_VALUE 0xdead000000000000 It corresponds to following kconfig entry: config ILLEGAL_POINTER_VALUE        hex        default 0 if X86_32        default 0xdead000000000000 if X86_64 Grepping shows more: grep -r --include=Kconfig -3 -P '^\s*hex' . Anyway do you really need to handle undefined case? If not, the macro can stay simple, w/o hacky constructs. Regards Andrzej > > If I try an hex value in menuconfig it says "You have made an invalid > entry." > If I try editing .config or setting via scripts/config --set-val, it > just gets reset when trying to generate include/generated/autoconf.h > > Lucas De Marchi > >> >> It is probably OK for private macro, but it can hurt in kconfig.h, >> especially the 2nd issue >> >> >> Regards >> >> Andrzej >> >>> >>>   #endif /* !__I915_UTILS_H */ >