From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF2AAC433F5 for ; Fri, 19 Nov 2021 16:13:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AC1D361004 for ; Fri, 19 Nov 2021 16:13:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AC1D361004 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FysHBxZo9DhGrRlXzV88GSclzAU5T9R7aQcnqNSlcHk=; b=hwwdY9VqrUZvzx QgvB64XeGcb4h49D6ogxvZen7JuPSCFQ/cHJVwhiWnPlHRV1a7o0P7n/qPMZs5NLg9RIuKEixT0SZ gkmpWTC4s5v/xyP/rJR+E+jZi9m8IFfXJYF7FlQLVOVY+uoGeTGyQ03aPfsDTf7zFgFu5hGH8an6x uu9QTojCrT81PMY97TC9RMRzVnqHbbsPztcyh0qJov8mqfkB2wNCFEw6AISRKpMD5qUwv54OMUUsZ wZnZu1HUFNXcLQBQxLA7uVCs+hWox64SiAOKzXYZ9feyiZ1bjcd3ys1SJD1PqcXojvD3x+L57jjkM 8+0Vs8q3plffseQi7bTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mo6V3-00Ay26-Pu; Fri, 19 Nov 2021 16:12:30 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mo6Uy-00Ay0Q-Vm for linux-arm-kernel@lists.infradead.org; Fri, 19 Nov 2021 16:12:26 +0000 Received: by mail-wr1-x42b.google.com with SMTP id w29so18965283wra.12 for ; Fri, 19 Nov 2021 08:12:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=ugr1swvvEJM7P07dTrUMW86aHmgr9RVOKFoLL2kQN7k=; b=lFlyvkBNI61mJyUJLQ1+hcFZu152Rj5qZK9mAkDP6bOJesLhBEd3Q4Oq83qIYEd64n YITNPwkZi9S7IB6Inh60GB/VEkSv28veKOaIGDMIPbCKTFzqAkbspPLR28oVvo5U5vKX ni4AocUEsv6MI6QlC5aDBhUxTPYJ6WUDtSoDVTmcNAcrcrW+S1gPrCGf3ON0VZfJ6JKa 0KBtAUbroY6eHDRyQJdN136bKjpeWs281Zu15Ruh/5ySpQ1d5ekmM8Ta6jagf5CN7g3S kwp92bvu9VLsql4q4anafWvPndH2TGTUpGf0qg8qKM1C7v1a4tqdU9+hNI70/o/Awrbu 5GRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=ugr1swvvEJM7P07dTrUMW86aHmgr9RVOKFoLL2kQN7k=; b=syGpARYVxy8Io9Gg0OaJkPV2gxla1BTyVCPIlRW3Ib+I2iEORLZACjUNci5g0uLlqL J0REPx0LvSFT7BZOm9rRgTU8OuMfJ1Y0gIXqYFIIBraTDhsm5DEaW/hGG3+K6Lf5dXT3 +MbUnJL7WcEPoyCJg1vodgFbuyunK5AH59f5ZWpT7dLPKuHISr5nRqkVHww0LNUJiGRq GPr+dwzY04SAkV+U34M95W7F7yPOVk+H0PR3tf/5WRuRIZ3rVY8vzbVV0klxYwsMaxZ7 N+Gfdp+zLM8O8XvDOKxVqgMooaJh2fIdO9Nvz4O8HN8PUjXGS0J6P/sWsm15LmoTZgoA B+4w== X-Gm-Message-State: AOAM531VvoE9t+bk7+vufavWU4wWl8gfimlX70lI5nM4ViiaSAEu5C5y zXnyraLdK9on6sZQPE9GNY4= X-Google-Smtp-Source: ABdhPJxXT53cxKGwOTawEJZsAHGDZX4/cS9uLMXoPT1yRB0yOWFLwaopD6E8urQvNF7W4NC52G5yJw== X-Received: by 2002:a05:6000:156a:: with SMTP id 10mr8724643wrz.87.1637338343047; Fri, 19 Nov 2021 08:12:23 -0800 (PST) Received: from [192.168.0.160] ([170.253.36.171]) by smtp.gmail.com with ESMTPSA id a1sm191231wri.89.2021.11.19.08.12.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Nov 2021 08:12:22 -0800 (PST) Message-ID: Date: Fri, 19 Nov 2021 17:12:19 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: [PATCH 00/17] Add memberof(), split some headers, and slightly simplify code Content-Language: en-US To: Arnd Bergmann Cc: LKML , Ajit Khaparde , Andrew Morton , Andy Shevchenko , Bjorn Andersson , Borislav Petkov , Corey Minyard , Chris Mason , Christian Brauner , David Sterba , Jani Nikula , Jason Wang , Jitendra Bhivare , John Hubbard , "John S . Gruber" , Jonathan Cameron , Joonas Lahtinen , Josef Bacik , Kees Cook , Ketan Mukadam , Len Brown , "Michael S. Tsirkin" , Miguel Ojeda , Mike Rapoport , Nick Desaulniers , "Rafael J. Wysocki" , Rasmus Villemoes , Rodrigo Vivi , Russell King , Somnath Kotur , Sriharsha Basavapatna , Subbu Seetharaman , Intel Graphics , ACPI Devel Maling List , Linux ARM , linux-btrfs , linux-scsi , Networking , "open list:DRM DRIVER FOR QEMU'S CIRRUS DEVICE" References: <20211119113644.1600-1-alx.manpages@gmail.com> <434296d3-8fe1-f1d2-ee9d-ea25d6c4e43e@gmail.com> From: "Alejandro Colomar (man-pages)" In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211119_081225_078335_6FDE00FB X-CRM114-Status: GOOD ( 43.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Arnd, On 11/19/21 16:57, Arnd Bergmann wrote: > > From what I can tell, linux/stddef.h is tiny, I don't think it's really > worth optimizing this part. I have spent some time last year > trying to untangle some of the more interesting headers, but ended > up not completing this as there are some really hard problems > once you start getting to the interesting bits. In this case it was not about being worth it or not, but that the fact that adding memberof() would break, unless I use 0 instead of NULL for the implementation of memberof(), which I'm against, or I split stddef. If I don't do either of those, I'm creating a circular dependency, and it doesn't compile. > > The approach I tried was roughly: > > - For each header in the kernel, create a preprocessed version > that includes all the indirect includes, from that start a set > of lookup tables that record which header is eventually included > by which ones, and the size of each preprocessed header in > bytes > > - For a given kernel configuration (e.g. defconfig or allmodconfig) > that I'm most interested in, look at which files are built, and what > the direct includes are in the source files. > > - Sort the headers by the product of the number of direct includes > and the preprocessed size: the largest ones are those that are > worth looking at first. > > - use graphviz to visualize the directed graph showing the includes > between the top 100 headers in that list. You get something like > I had in [1], or the version afterwards at [2]. > > - split out unneeded indirect includes from the headers in the center > of that graph, typically by splitting out struct definitions. > > - repeat. > > The main problem with this approach is that as soon as you start > actually reducing the unneeded indirect includes, you end up with > countless .c files that no longer build because they are missing a > direct include for something that was always included somewhere > deep underneath, so I needed a second set of scripts to add > direct includes to every .c file. > > On the plus side, I did see something on the order of a 30% > compile speed improvement with clang, which is insane > given that this only removed dead definitions. Huh! I'd like to see the kernel some day not having _any_ hidden dependencies. For the moment, since my intent is familiarizing with kernel programming, and not necessarily improving performance considerably (at least not in the first rounds of changes), I prefer starting where it more directly affects what I initially intended to change in the kernel, which in this case was adding memberof(). > >> But I'll note that linux/fs.h, linux/sched.h, linux/mm.h are >> interesting headers for further splitting. >> >> >> BTW, I also have a longstanding doubt about >> how header files are organized in the kernel, >> and which headers can and cannot be included >> from which other files. >> >> For example I see that files in samples or scripts or tools, >> that redefine many things such as offsetof() or ARRAY_SIZE(), >> and I don't know if there's a good reason for that, >> or if I should simply remove all that stuff and >> include everywhere I see offsetof() being used. > > The main issue here is that user space code should not > include anything outside of include/uapi/ and arch/*/include/uapi/ Okay. That's good to know. So everything can use uapi code, and uapi code can only use uapi code, right? Every duplicate definition of something outside of uapi should/could be removed. > > offsetof() is defined in include/linux/stddef.h, so this is by > definition not accessible here. It appears that there is also > an include/uapi/linux/stddef.h that is really strange because > it includes linux/compiler_types.h, which in turn is outside > of uapi/. This should probably be fixed. I see. Then, perhaps it would be better to define offsetof() _only_ inside uapi/, and use that definition from everywhere else, and therefore remove the non-uapi version, right? Thanks, Alex -- Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/ _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel