Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2004554ybl; Thu, 19 Dec 2019 06:33:37 -0800 (PST) X-Google-Smtp-Source: APXvYqy5P3q0e4X3Zp0Lux+zzqga+tjIOsdhxgb1G/YsNok4Aj89dOdczgq1gfKys7xDIZE2WEeF X-Received: by 2002:a05:6830:10d7:: with SMTP id z23mr9178585oto.114.1576766016963; Thu, 19 Dec 2019 06:33:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576766016; cv=none; d=google.com; s=arc-20160816; b=aHYqEkFsyrgabfTPXU5ivsUtVlgxt74IlHGznihxV8zvMvya0E2iJnr2NjiKORLbkY s8R43izliHXJH6RJXUHtYt5myzroMbGBHHw+/ZtXlwYH48YouAkBmHyQGm3QbMCXrzN1 nEFZ3+KE7gXvjKRQCvqTHbOl6v1lfGrD2gEWNMNV5/7vVBjPCWAVADxfNlaQQfzW3z9J jj/Hu6xMPvz9EiBMQG7aJnl4gTeHWE3BB4nJxax9qZw10KduRCztAtvLMj8ZRRKAhcNQ c1vgTL03t7NwwgGSlxp7xcZ5IXW5qCw4ypbkgjVcYVkIzURoU5DNmZ3Xl1JkvH4TT5R1 aHvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=aEi4oJqgOLr5rRLiD5I1WzWFDvDWb99ogFRyo+dLQM4=; b=nvu8oCEudBqUipnw0CbWZPFv/nmKnvVBuQk2r87tE18mwMarMu5AQegWmXMr+B26Up WGlnNmYck7EPrlVISZXOgngnkkL55fahre8F6/zLgoUXUm7wi9q2+7741Y6IEj+/H4eI BlAqvaV4oozuxvDKfJDcJnHjFDtIDqCFGD26X23t9UA7jIkrEB2taxSgzPVzPkS7PoAz 4KaUQvi4Oj10KgNjSpwX+KRKTxdDfyAXM5zPhcd4goqG4kNB7os/TU3fXb83A4oSJF9q jmSCkRiP6L9K29BSKJrJzsqW13K6bOLBJrGJTDzTVWmacG5g7kYiCs9iShOeGGw5jQu0 gcFA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t12si3390053otq.53.2019.12.19.06.33.23; Thu, 19 Dec 2019 06:33:36 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726846AbfLSObZ (ORCPT + 99 others); Thu, 19 Dec 2019 09:31:25 -0500 Received: from relay.sw.ru ([185.231.240.75]:54454 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726757AbfLSObY (ORCPT ); Thu, 19 Dec 2019 09:31:24 -0500 Received: from dhcp-172-16-24-104.sw.ru ([172.16.24.104]) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1ihwpc-0006gx-Ov; Thu, 19 Dec 2019 17:31:12 +0300 Subject: Re: [PATCH RFC] sched: Micro optimization in pick_next_task() and in check_preempt_curr() From: Kirill Tkhai To: Peter Zijlstra Cc: mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, linux-kernel@vger.kernel.org References: <157675913272.349305.8936736338884044103.stgit@localhost.localdomain> <20191219131242.GK2827@hirez.programming.kicks-ass.net> <20191219140252.GS2871@hirez.programming.kicks-ass.net> Message-ID: <423860b3-b35a-ff25-6abf-845ef4be6e8e@virtuozzo.com> Date: Thu, 19 Dec 2019 17:31:12 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19.12.2019 17:25, Kirill Tkhai wrote: > On 19.12.2019 17:02, Peter Zijlstra wrote: >> On Thu, Dec 19, 2019 at 02:12:42PM +0100, Peter Zijlstra wrote: >>> On Thu, Dec 19, 2019 at 03:39:14PM +0300, Kirill Tkhai wrote: >>>> In kernel/sched/Makefile files, describing different sched classes, already >>>> go in the order from the lowest priority class to the highest priority class: >>>> >>>> idle.o fair.o rt.o deadline.o stop_task.o >>>> >>>> The documentation of GNU linker says, that section appears in the order >>>> they are seen during link time (see [1]): >>>> >>>>> Normally, the linker will place files and sections matched by wildcards >>>>> in the order in which they are seen during the link. You can change this >>>>> by using the SORT keyword, which appears before a wildcard pattern >>>>> in parentheses (e.g., SORT(.text*)). >>>> >>>> So, we may expect const variables from idle.o will go before ro variables >>>> from fair.o in RO_DATA section, while ro variables from fair.o will go >>>> before ro variables from rt.o, etc. >>>> >>>> (Also, it looks like the linking order is already used in kernel, e.g. >>>> in drivers/md/Makefile) >>>> >>>> Thus, we may introduce an optimization based on xxx_sched_class addresses >>>> in these two hot scheduler functions: pick_next_task() and check_preempt_curr(). >>>> >>>> One more result of the patch is that size of object file becomes a little >>>> less (excluding added BUG_ON(), which goes in __init section): >>>> >>>> $size kernel/sched/core.o >>>> text data bss dec hex filename >>>> before: 66446 18957 676 86079 1503f kernel/sched/core.o >>>> after: 66398 18957 676 86031 1500f kernel/sched/core.o >>> >>> Does LTO preserve this behaviour? I've never quite dared do this exact >>> optimization. >> >> Also, ld.lld seems a popular option. > > I asked on their IRC. Oh, it looks like no way is for this. > > About the link: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/sections.html > > (17:19:25) nbjoerg: but it is not guarenteed behavior > (17:19:50) nbjoerg: if for some strange reason you really need to enforce relative orders of global objects, put them in consecutively named sections Introduction of sched_class::id instead of this patch's approach does not have a big sense, since this will help in check_preempt_curr() only. And this requires too many new lines of code.