Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1957648ybl; Thu, 29 Aug 2019 01:14:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqywyB4vRI0COoDsLdEwcDajy5NE3Vndjg0h9m6BKvkbx8Pmm3MyAY421cyhyQqvDeH8OVqr X-Received: by 2002:aa7:8f2e:: with SMTP id y14mr9806555pfr.113.1567066445621; Thu, 29 Aug 2019 01:14:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567066445; cv=none; d=google.com; s=arc-20160816; b=epQMpda1Gaq85qQbYnrBEW+DLKvLKkWZaTSYK6QbOdWXX69tnOitv0YZLuc63tZBWT HxLu48ECWNo01jGquoEEOx9e1oHH6oRqsLq+Y5FaiSgzvsXXrIdgpF/ZPQyF0dhuCAS2 vRO1FxW9mo2Tq9U4PxROuVhH2Wt19bLMOQRaD+sC2bp+iD0elTT1SHESrkpdo99xjayC sEFEebQFlrO+cTSJOsMoMYiJD6emmVUisYIr8OjRI5M1KROdeaj6bYg0zW1vJvI1CSGA BRBVM1v9/K/1mVAqdcwB/TGZbWbX2/Vwh4bA7du4EwHz7+tgbepJJPsMJQ7mDlezRKhq QR4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=NQbGrfBK8UPTqkSP0DVYO7BC9icQxBhXWmYmocR1KYY=; b=pxCW/ETVOqkUCtNuvIOQ4RKJ7iJMUVnosvciXLq56YI/0+WgTVC+/I95sG/slsNSxD fWbZHV3SzHu3Mg69+4/4RVJiHeSR/v05RP1zdVQeQT7Hf70WkxJPCS32jUdiRpjNH7T5 UQLebxlcygif60oTV4mfBFaPTZVJbCWIMAFUeWR/lKdcNOpCl1hs+VXhBSUoeXx8AwfA GdwqJuvMaduP6sWr17Ukt96hf/ndghR/2HBgyw93A+iMFqlvoQmGUlwKNtDJhxrOIDA8 8TGLTyfOv0yncqfZTjWhg6d3qHrh5vqXFc2ONy1uZE7B1rp6kbKK8GGXxGqeDZaO/zVg WBvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b42si1534943pjc.18.2019.08.29.01.13.49; Thu, 29 Aug 2019 01:14:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726384AbfH2IMw (ORCPT + 99 others); Thu, 29 Aug 2019 04:12:52 -0400 Received: from mx2.suse.de ([195.135.220.15]:57376 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725776AbfH2IMw (ORCPT ); Thu, 29 Aug 2019 04:12:52 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 204D5AC8E; Thu, 29 Aug 2019 08:12:51 +0000 (UTC) Date: Thu, 29 Aug 2019 10:12:49 +0200 From: Petr Mladek To: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= Cc: Sergey Senozhatsky , Steven Rostedt , Andrew Morton , Jani Nikula , Jonathan Corbet , metux IT consult Enrico Weigelt , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] vsprintf: introduce %dE for error constants Message-ID: <20190829081249.3zvvsa4ggb5pfozl@pathway.suse.cz> References: <20190827211244.7210-1-uwe@kleine-koenig.org> <20190828113216.p2yiha4xyupkbcbs@pathway.suse.cz> <74303921-aa95-9962-2254-27e556af54f4@kleine-koenig.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <74303921-aa95-9962-2254-27e556af54f4@kleine-koenig.org> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 2019-08-28 21:18:37, Uwe Kleine-K?nig wrote: > Hello Petr, > > On 8/28/19 1:32 PM, Petr Mladek wrote: > > On Tue 2019-08-27 23:12:44, Uwe Kleine-K?nig wrote: > >> Petr Mladek had some concerns: > >>> There are ideas to make the code even more tricky to reduce > >>> the size, keep it fast. > >> > >> I think Enrico Weigelt's suggestion to use a case is the best > >> performance-wise so that's what I picked up. Also I hope that > >> performance isn't that important because the need to print an error > >> should not be so common that it really hurts in production. This is contadicting. The "best" performance-wise solution was choosen in favor of space. The next sentence says that performance is not important. > > I personally do not like switch/case. It is a lot of code. > > I wonder if it even saved some space. > > I guess we have to die either way. Either it is quick or it is space > efficient. I am more concerned about the size. Well, array of strings will be both fast and size efficient. > With the big case I trust the compiler to pick something > sensible expecting that it adapts for example to -Osize. I am not sure what are the expectations here. I can't imagine another translation than: if (val == 1) str = "EPERM"; else if (val == 2) str = "ENOENT" else if (val == 3) str = "ESRCH" ... It means that all constans will be hardcoded in the code instead of in data section. Plus there will be instructions for each if/else part. > > If you want to safe space, I would use u16 to store the numbers. > > Or I would use array of strings. There will be only few holes. > > > > You might also consider handling only the most commonly > > used codes from errno.h and errno-base.h (1..133). There will > > be no holes and the codes are stable. > > I'd like to postpone the discussion about "how" until we agreed about > the "if at all". It seems that all people like this feature. BTW: I though more about generating or cut&pasting the arrary. I can't find any reasonable way how to generate it. But both, errno.h and errno-base.h, are super stable. Only comments were modified or new codes added. Most of them are defined by POSIX so they should remain stable. Therefore cut&pasted array of strings looks acceptable. We should only allow to easily check numbers for each code, e.g. by defining the array as const err_str * [] { "0" /* 0 Success */ "EPERM", /* 1 Operation not permitted */ "ENOENT", /* 2 No such file or directory */ "ESRCH", /* 3 No such process */ ... If there is a hole, we could use something like: "-41", /* 41 Skipped. EWOULDBLOCK is defined as EAGAIN. Operation would block */ Best Regards, Petr