Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1547987ybl; Fri, 23 Aug 2019 23:07:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvwz62uWdkDoz6T8qAcOXzURY3rHAUx/zn/5ftWwF4lhifMc3JAZ93OECWOC0T2cAUiZtk X-Received: by 2002:a63:4c46:: with SMTP id m6mr6130557pgl.59.1566626842418; Fri, 23 Aug 2019 23:07:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566626842; cv=none; d=google.com; s=arc-20160816; b=czgW3iBQrF0A78XYIf6dXphIjekW8dvyWUFHy71vDwNyLNY5yklefqxW7UNgtcBm4d Q2pOSxsyaJpeFddHKdl9H+faF2vDI/SVj9/lqe4ueJYfx+Y9wb/oZoG13dvHBgBMvV6h R1rPo+lV3H+qyGjwoPm+u4ZwV7czN4SsyEdV4CcE69j2gwlG7Xg7U+D6jpLJvsn2R6vU ++xRhn/U/YSWm5+Vuv4ebUVnkzJMLDXVQSQTRYZIaKlVuj2QIwXv5tyQgq86HTBjy6zX X8YxM5i18zv8drIK9qAQ2LnUYcqMvLPKFudJydliNZ/AC5I7xbecKjvtg/DXaYz7aF8X aeKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=kDV1vhN0wODBotvyRh1M9ntCF2zJ8VrUcg/cgB4CwYg=; b=GuPRCBMndA4DCP6MLyhIgrxzlTXpBAR83AZgn+2YuuUzpFiQ2wtRwvzfYqCFq0ltm2 npDpIkfxTArq04UMEwTCVkYqWMl/hPzUqXoacD7YdqjXlOxkoJo9CsgrsFQ5PIlzYZB2 /eH++w2RH9sIgGL4hOcf0FgGhUu7aic9NMvceCha3Fe6ifuu9m6ybD3MSSpQSLryNHMQ 63j8Crb8pj8iiMw4c70fnoWpNZgxalzfVeEWbJsNfaAQjcMf2RyNic9ixz1CYshv/zL0 8Cg5L8mbzb8rGX60g4sdwzBNWVSmMvdLyFXjwzmyU8gm+Zso8hGzmhrV2RTqE/PSeiWx gTKg== 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=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l10si4399770plb.314.2019.08.23.23.07.07; Fri, 23 Aug 2019 23:07:22 -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; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726921AbfHXGFN (ORCPT + 99 others); Sat, 24 Aug 2019 02:05:13 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:34651 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726058AbfHXGFN (ORCPT ); Sat, 24 Aug 2019 02:05:13 -0400 Received: by mail-pf1-f194.google.com with SMTP id b24so8066246pfp.1 for ; Fri, 23 Aug 2019 23:05:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=kDV1vhN0wODBotvyRh1M9ntCF2zJ8VrUcg/cgB4CwYg=; b=NISril8xgnKPq8sH+bCA8IO/00VdT0J7DX966/UC6mCE/72dFUrF7OugxQnNUyx07c gnCn9tsil/6IR0PztUNNrJo/x6H/2skN3q22V68SvU+cWBOnfBCZj3pH/ovAowVL4rKE vJcyEK7Qf6c0Uw51KycnjThnuOkBzpo62VCWif06KXKUwDCNrNnWMIdEGzFG/rFvFBtB sC9R1Z8Kw/rwo3TRHJ1P5i8mevEh6wnucEkw/s6UW7Ggi9NKdjA72hTeZ7T6RuMBSMNC wsA8MWSYSrVgbwuUnlap1RjwSVDICO9sLPmjcVFr9VnK1VyfmlO/upIY1CW8WKekiP+O WAmA== X-Gm-Message-State: APjAAAWGoHpZAx1Pa3O+KiNl3Mvu7ZjpeaD9cAHur9d1yy1pvrDftv8y FcXjGsOiyjkHSLd4nIYy1zM= X-Received: by 2002:a62:53c3:: with SMTP id h186mr9304094pfb.178.1566626712276; Fri, 23 Aug 2019 23:05:12 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id w2sm4300882pjr.27.2019.08.23.23.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2019 23:05:11 -0700 (PDT) From: Nadav Amit To: Peter Zijlstra Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Thomas Garnier , Ingo Molnar , Nadav Amit Subject: [PATCH 0/7] x86/percpu: Use segment qualifiers Date: Fri, 23 Aug 2019 15:44:17 -0700 Message-Id: <20190823224424.15296-1-namit@vmware.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org GCC 6+ supports segment qualifiers. Using them allows to implement several optimizations: 1. Avoid unnecessary instructions when an operation is carried on read/written per-cpu value, and instead allow the compiler to set instructions that access per-cpu value directly. 2. Make this_cpu_ptr() more efficient and allow its value to be cached, since preemption must be disabled when this_cpu_ptr() is used. 3. Provide better alternative for this_cpu_read_stable() that caches values more efficiently using alias attribute to const variable. 4. Allow the compiler to perform other optimizations (e.g. CSE). 5. Use rip-relative addressing in per_cpu_read_stable(), which make it PIE-ready. "size" and Peter's compare do not seem to show the impact on code size reduction correctly. Summing the code size according to nm on defconfig shows a minor reduction from 11451310 to 11451310 (0.09%). RFC->v1: * Fixing i386 build bug * Moving chunk to the right place [Peter] Nadav Amit (7): compiler: Report x86 segment support x86/percpu: Use compiler segment prefix qualifier x86/percpu: Use C for percpu accesses when possible x86: Fix possible caching of current_task percpu: Assume preemption is disabled on per_cpu_ptr() x86/percpu: Optimized arch_raw_cpu_ptr() x86/current: Aggressive caching of current arch/x86/include/asm/current.h | 30 +++ arch/x86/include/asm/fpu/internal.h | 7 +- arch/x86/include/asm/percpu.h | 293 +++++++++++++++++++------ arch/x86/include/asm/preempt.h | 3 +- arch/x86/include/asm/resctrl_sched.h | 14 +- arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/common.c | 7 +- arch/x86/kernel/cpu/current.c | 16 ++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 +- arch/x86/kernel/process_32.c | 4 +- arch/x86/kernel/process_64.c | 4 +- include/asm-generic/percpu.h | 12 + include/linux/compiler-gcc.h | 4 + include/linux/compiler.h | 2 +- include/linux/percpu-defs.h | 33 ++- 15 files changed, 346 insertions(+), 88 deletions(-) create mode 100644 arch/x86/kernel/cpu/current.c -- 2.17.1