From patchwork Mon Oct 2 17:59:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 114639 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp946035qgn; Mon, 2 Oct 2017 10:59:19 -0700 (PDT) X-Received: by 10.98.65.152 with SMTP id g24mr14951299pfd.1.1506967159302; Mon, 02 Oct 2017 10:59:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506967159; cv=none; d=google.com; s=arc-20160816; b=XcsbeypL7NgxNDtpsSFKxJfL5c3xKaE5B0DoAz6M3DswfzWoUFSfSM1hinKi9IU4Ww Q8Sx/aUawR/r8bisKD53miH2DZ+wsQ9A2L447nRFvPTErCMp/i6jyd5nGfKE/Kn1SkTU lVIffvCDR0FHuSTVdNAqw/MyFL4l5S39JjuB2NRdlNtkVIKlmLyop4N/AfV0mCftFOKO 5VAhmUlgNj2mo1OBhZKvoYs2l+egBLJkZcyhl+fZ9rfNMbf88WimZyG8YvksfR65kUW2 KtTArbN+NqxzgkiAR3eNErmwoNDaXhyTY8NJlnLsaHTWFNWSd0aCSMOIUStLXPuPLOrn BI2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature:arc-authentication-results; bh=yYpXga4MbuDiiuOdekll2uIlu3XIbF60uDrMNc517Kc=; b=UWVXFwxowA6ZsyP6a4oy7jC1ZRQTuYAu4JgnzoSiKdAtaAYuEkUxsE34AdRWDSdF82 OndfVxxrA+WE/CYFx6cjHlqp5fYE9dlVoq6JYsGkXq8/5f+mltMA+saVLscnHspNpViy +5ezePat/eogNCBY3L+5Ha2CmCHTrD5ATURsZB4mZRQan5sL3opnySW4SXH3QnRlXxby zpTzvYN+xfoTor8ek3Z+N3/enBqIMZdzZpQ7Kp3kAH6itPCEZggoRMiFoH8A1p8hZ+Ww RjpaBnR6eiu/ywKqAUXofvCsYUdHKBDgMAQbn3eteDu9afGCDo+e7GCvNotfeiV57k+a l7AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UU/JZ/Ed; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g207si2013872pfb.262.2017.10.02.10.59.19; Mon, 02 Oct 2017 10:59:19 -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; dkim=pass header.i=@linaro.org header.s=google header.b=UU/JZ/Ed; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752002AbdJBR7R (ORCPT + 26 others); Mon, 2 Oct 2017 13:59:17 -0400 Received: from mail-qt0-f170.google.com ([209.85.216.170]:47694 "EHLO mail-qt0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751251AbdJBR7P (ORCPT ); Mon, 2 Oct 2017 13:59:15 -0400 Received: by mail-qt0-f170.google.com with SMTP id z50so3369826qtj.4 for ; Mon, 02 Oct 2017 10:59:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=yYpXga4MbuDiiuOdekll2uIlu3XIbF60uDrMNc517Kc=; b=UU/JZ/EdjlRFzD/bbEby+3fteFI296D9CQb6SoVamCiQRQnODSDdakh35IUfJ91uRC 4ejKkVN/ThehpPyGQ9WcybVxgcq7l0yDFHt5BkuC152AxAsNOuysU4hcaKTl++WQs0mR VYwz6sXbnzj64SKSLF1uW3JnFPp9Y0v2hnpoQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=yYpXga4MbuDiiuOdekll2uIlu3XIbF60uDrMNc517Kc=; b=OHwy0iKAZ1C6PQVY97wMqLfsV3TLKWcoGR50zm5YhmWQNu0mFunIfxzlmag39sr5UA swJzg7CK0+epgJXVMNm85egv0XkQ1ESWQB081w1n7pUCmVjpfyJh/yKuOrqDOPhQJ/fL oR4vla1oS8PsXWsifGD+I6nDq0EMcRvGLc7V3BWewBkbcBYSl6XPDPwctDtsehCXJWsr GvsFptjAjDbhZJfb9qJii9pAULwbEYQ1QgR2VLkDpw00pgbA4hPfg9RR4/hANZ0u6tFw UWTVxASmSHKZ6mkuhdGJg354d6gya5ywr2gA9ROL97bYlaji0kyYQtH3LsJ+JE8QbArV VdeA== X-Gm-Message-State: AMCzsaVTK4WmaaEhGY4OudhV0FgDXiAeaOPAdTNTYSWHzBfXlMouw8q2 P/0JZ3erKBNcQrcexL7koVuAPg== X-Google-Smtp-Source: AOwi7QAO+PS7BZIx3Zyykic9yf1F7rJ1K9o4ajcXPce71GXByN8T9gbjipsjbiTt3Mcl+cgUUHGNyg== X-Received: by 10.200.45.237 with SMTP id q42mr10868442qta.60.1506967154715; Mon, 02 Oct 2017 10:59:14 -0700 (PDT) Received: from xanadu.home (modemcable045.234-175-137.mc.videotron.ca. [137.175.234.45]) by smtp.gmail.com with ESMTPSA id v40sm7518900qta.9.2017.10.02.10.59.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Oct 2017 10:59:14 -0700 (PDT) Date: Mon, 2 Oct 2017 13:59:13 -0400 (EDT) From: Nicolas Pitre To: Thomas Gleixner cc: linux-kernel@vger.kernel.org Subject: [PATCH/RFC] cpuhp code and data usage on UP systems Message-ID: User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On !SMP systems, we end up with the following array definition: static struct cpuhp_step cpuhp_ap_states[] = { [CPUHP_ONLINE] = { .name = "online", .startup.single = NULL, .teardown.single = NULL, }, }; where CPUHP_ONLINE = 187. That means up to 99.5% of this array is unused but still allocated in the kernel's .data section i.e. 3760 bytes. The same issue exists with cpuhp_bp_states being 1720 bytes. The goal of this patch is mainly about illustrating the issue and reducing .data usage. I have no clear idea when this stuff is really needed besides standard CPU hotplug. Not knowing exactly what I'm doing here, I made it conditional on CONFIG_SMP for now. There might be a case for moving that code to a separate file (cpuhp.c maybe?) and omitting it from the kernel when unneeded. Comments? include/linux/cpu.h | 4 ++++ include/linux/cpuhotplug.h | 27 +++++++++++++++++++-------- kernel/cpu.c | 26 ++++++++++++++++---------- kernel/power/Kconfig | 3 +++ 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index acf5308fad..46756fb980 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -35,6 +35,8 @@ #include "smpboot.h" +#ifdef CONFIG_CPUHP + /** * cpuhp_cpu_state - Per cpu hotplug state storage * @state: The current cpu state @@ -1036,8 +1038,6 @@ core_initcall(cpu_hotplug_pm_sync_init); #endif /* CONFIG_PM_SLEEP_SMP */ -int __boot_cpu_id; - #endif /* CONFIG_SMP */ /* Boot processor state steps */ @@ -1709,6 +1709,16 @@ device_initcall(cpuhp_sysfs_init); #endif /* + * Must be called _AFTER_ setting up the per_cpu areas + */ +void __init boot_cpu_state_init(void) +{ + per_cpu_ptr(&cpuhp_state, smp_processor_id())->state = CPUHP_ONLINE; +} + +#endif /* CONFIG_CPUHP */ + +/* * cpu_bit_bitmap[] is a special, "compressed" data structure that * represents all NR_CPUS bits binary values of 1<state = CPUHP_ONLINE; -} diff --git a/include/linux/cpu.h b/include/linux/cpu.h index ca73bc1563..4130ede0f9 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -29,7 +29,11 @@ struct cpu { }; extern void boot_cpu_init(void); +#ifdef CONFIG_CPUHP extern void boot_cpu_state_init(void); +#else +static inline void boot_cpu_state_init(void) { } +#endif extern void cpu_init(void); extern void trap_init(void); diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index f24bfb2b9a..c51e2980a7 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -150,15 +150,23 @@ enum cpuhp_state { CPUHP_ONLINE, }; +#ifdef CONFIG_CPUHP +#define ___P(proto, def_retcode) extern proto; +#else +#define ___P(proto, def_retcode) static inline proto { return def_retcode } +#endif + +___P( int __cpuhp_setup_state(enum cpuhp_state state, const char *name, bool invoke, int (*startup)(unsigned int cpu), - int (*teardown)(unsigned int cpu), bool multi_instance); - + int (*teardown)(unsigned int cpu), bool multi_instance), 0; ) +___P( int __cpuhp_setup_state_cpuslocked(enum cpuhp_state state, const char *name, bool invoke, int (*startup)(unsigned int cpu), int (*teardown)(unsigned int cpu), - bool multi_instance); + bool multi_instance), 0; ) + /** * cpuhp_setup_state - Setup hotplug state callbacks with calling the callbacks * @state: The state for which the calls are installed @@ -239,10 +247,12 @@ static inline int cpuhp_setup_state_multi(enum cpuhp_state state, (void *) teardown, true); } +___P( int __cpuhp_state_add_instance(enum cpuhp_state state, struct hlist_node *node, - bool invoke); + bool invoke), 0; ) +___P( int __cpuhp_state_add_instance_cpuslocked(enum cpuhp_state state, - struct hlist_node *node, bool invoke); + struct hlist_node *node, bool invoke), 0; ) /** * cpuhp_state_add_instance - Add an instance for a state and invoke startup @@ -282,8 +292,8 @@ cpuhp_state_add_instance_nocalls_cpuslocked(enum cpuhp_state state, return __cpuhp_state_add_instance_cpuslocked(state, node, false); } -void __cpuhp_remove_state(enum cpuhp_state state, bool invoke); -void __cpuhp_remove_state_cpuslocked(enum cpuhp_state state, bool invoke); +___P( void __cpuhp_remove_state(enum cpuhp_state state, bool invoke), ; ) +___P( void __cpuhp_remove_state_cpuslocked(enum cpuhp_state state, bool invoke), ; ) /** * cpuhp_remove_state - Remove hotplug state callbacks and invoke the teardown @@ -325,8 +335,9 @@ static inline void cpuhp_remove_multi_state(enum cpuhp_state state) __cpuhp_remove_state(state, false); } +___P( int __cpuhp_state_remove_instance(enum cpuhp_state state, - struct hlist_node *node, bool invoke); + struct hlist_node *node, bool invoke), 0; ) /** * cpuhp_state_remove_instance - Remove hotplug instance from state and invoke diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig index e8517b63eb..28acf47105 100644 --- a/kernel/power/Kconfig +++ b/kernel/power/Kconfig @@ -311,3 +311,6 @@ config PM_GENERIC_DOMAINS_OF config CPU_PM bool + +config CPUHP + def_bool SMP