From: Eric DeVolder <eric.devolder@oracle.com>
To: linux-kernel@vger.kernel.org, david@redhat.com,
osalvador@suse.de, corbet@lwn.net, tglx@linutronix.de,
mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
x86@kernel.org, bhe@redhat.com, ebiederm@xmission.com,
kexec@lists.infradead.org
Cc: hpa@zytor.com, gregkh@linuxfoundation.org, rafael@kernel.org,
vgoyal@redhat.com, dyoung@redhat.com, lf32.dev@gmail.com,
akpm@linux-foundation.org, naveen.n.rao@linux.vnet.ibm.com,
zohar@linux.ibm.com, bhelgaas@google.com, vbabka@suse.cz,
tiwai@suse.de, seanjc@google.com, linux@weissschuh.net,
vschneid@redhat.com, linux-mm@kvack.org,
linux-doc@vger.kernel.org, sourabhjain@linux.ibm.com,
konrad.wilk@oracle.com, boris.ostrovsky@oracle.com,
eric.devolder@oracle.com
Subject: [PATCH v24 01/10] drivers/base: refactor cpu.c to use .is_visible()
Date: Wed, 28 Jun 2023 14:52:06 -0400 [thread overview]
Message-ID: <20230628185215.40707-2-eric.devolder@oracle.com> (raw)
In-Reply-To: <20230628185215.40707-1-eric.devolder@oracle.com>
Greg Kroah-Hartman requested that this file use the .is_visible()
method instead of #ifdefs for the attributes in cpu.c.
static struct attribute *cpu_root_attrs[] = {
#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
&dev_attr_probe.attr,
&dev_attr_release.attr,
#endif
&cpu_attrs[0].attr.attr,
&cpu_attrs[1].attr.attr,
&cpu_attrs[2].attr.attr,
&dev_attr_kernel_max.attr,
&dev_attr_offline.attr,
&dev_attr_isolated.attr,
#ifdef CONFIG_NO_HZ_FULL
&dev_attr_nohz_full.attr,
#endif
#ifdef CONFIG_GENERIC_CPU_AUTOPROBE
&dev_attr_modalias.attr,
#endif
NULL
};
To that end:
- the .is_visible() method is implemented, and IS_ENABLED(), rather
than #ifdef, is used to determine the visibility of the attribute.
- the DEVICE_ATTR() attributes are moved outside of #ifdefs, so that
those structs are always present for the cpu_root_attrs[].
- the #ifdefs guarding the attributes in the cpu_root_attrs[] are moved
to the corresponding callback function; as the callback function must
exist now that the attribute is always compiled-in (though not
necessarily visible).
No functionality change intended.
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
---
drivers/base/cpu.c | 67 ++++++++++++++++++++++++++++++++++++----------
1 file changed, 53 insertions(+), 14 deletions(-)
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index c1815b9dae68..75fa46a567a1 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -82,13 +82,14 @@ void unregister_cpu(struct cpu *cpu)
per_cpu(cpu_sys_devices, logical_cpu) = NULL;
return;
}
+#endif /* CONFIG_HOTPLUG_CPU */
-#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
static ssize_t cpu_probe_store(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t count)
{
+#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
ssize_t cnt;
int ret;
@@ -100,6 +101,9 @@ static ssize_t cpu_probe_store(struct device *dev,
unlock_device_hotplug();
return cnt;
+#else
+ return 0;
+#endif
}
static ssize_t cpu_release_store(struct device *dev,
@@ -107,6 +111,7 @@ static ssize_t cpu_release_store(struct device *dev,
const char *buf,
size_t count)
{
+#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
ssize_t cnt;
int ret;
@@ -118,12 +123,13 @@ static ssize_t cpu_release_store(struct device *dev,
unlock_device_hotplug();
return cnt;
+#else
+ return 0;
+#endif
}
static DEVICE_ATTR(probe, S_IWUSR, NULL, cpu_probe_store);
static DEVICE_ATTR(release, S_IWUSR, NULL, cpu_release_store);
-#endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
-#endif /* CONFIG_HOTPLUG_CPU */
#ifdef CONFIG_KEXEC
#include <linux/kexec.h>
@@ -273,14 +279,16 @@ static ssize_t print_cpus_isolated(struct device *dev,
}
static DEVICE_ATTR(isolated, 0444, print_cpus_isolated, NULL);
-#ifdef CONFIG_NO_HZ_FULL
static ssize_t print_cpus_nohz_full(struct device *dev,
struct device_attribute *attr, char *buf)
{
+#ifdef CONFIG_NO_HZ_FULL
return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(tick_nohz_full_mask));
+#else
+ return 0;
+#endif
}
static DEVICE_ATTR(nohz_full, 0444, print_cpus_nohz_full, NULL);
-#endif
static void cpu_device_release(struct device *dev)
{
@@ -301,12 +309,12 @@ static void cpu_device_release(struct device *dev)
*/
}
-#ifdef CONFIG_GENERIC_CPU_AUTOPROBE
static ssize_t print_cpu_modalias(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int len = 0;
+#ifdef CONFIG_GENERIC_CPU_AUTOPROBE
u32 i;
len += sysfs_emit_at(buf, len,
@@ -322,9 +330,11 @@ static ssize_t print_cpu_modalias(struct device *dev,
len += sysfs_emit_at(buf, len, ",%04X", i);
}
len += sysfs_emit_at(buf, len, "\n");
+#endif
return len;
}
+#ifdef CONFIG_GENERIC_CPU_AUTOPROBE
static int cpu_uevent(const struct device *dev, struct kobj_uevent_env *env)
{
char *buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
@@ -451,32 +461,61 @@ struct device *cpu_device_create(struct device *parent, void *drvdata,
}
EXPORT_SYMBOL_GPL(cpu_device_create);
-#ifdef CONFIG_GENERIC_CPU_AUTOPROBE
static DEVICE_ATTR(modalias, 0444, print_cpu_modalias, NULL);
-#endif
static struct attribute *cpu_root_attrs[] = {
-#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
&dev_attr_probe.attr,
&dev_attr_release.attr,
-#endif
&cpu_attrs[0].attr.attr,
&cpu_attrs[1].attr.attr,
&cpu_attrs[2].attr.attr,
&dev_attr_kernel_max.attr,
&dev_attr_offline.attr,
&dev_attr_isolated.attr,
-#ifdef CONFIG_NO_HZ_FULL
&dev_attr_nohz_full.attr,
-#endif
-#ifdef CONFIG_GENERIC_CPU_AUTOPROBE
&dev_attr_modalias.attr,
-#endif
NULL
};
+static umode_t
+cpu_root_attr_is_visible(struct kobject *kobj,
+ struct attribute *attr, int unused)
+{
+ umode_t mode = attr->mode;
+
+ if (IS_ENABLED(CONFIG_ARCH_CPU_PROBE_RELEASE)) {
+ if (attr == &dev_attr_probe.attr)
+ return mode;
+ if (attr == &dev_attr_release.attr)
+ return mode;
+ }
+ if (attr == &cpu_attrs[0].attr.attr)
+ return mode;
+ if (attr == &cpu_attrs[1].attr.attr)
+ return mode;
+ if (attr == &cpu_attrs[2].attr.attr)
+ return mode;
+ if (attr == &dev_attr_kernel_max.attr)
+ return mode;
+ if (attr == &dev_attr_offline.attr)
+ return mode;
+ if (attr == &dev_attr_isolated.attr)
+ return mode;
+ if (IS_ENABLED(CONFIG_NO_HZ_FULL)) {
+ if (attr == &dev_attr_nohz_full.attr)
+ return mode;
+ }
+ if (IS_ENABLED(CONFIG_GENERIC_CPU_AUTOPROBE)) {
+ if (attr == &dev_attr_modalias.attr)
+ return mode;
+ }
+
+ return 0;
+}
+
static const struct attribute_group cpu_root_attr_group = {
.attrs = cpu_root_attrs,
+ .is_visible = cpu_root_attr_is_visible,
};
static const struct attribute_group *cpu_root_attr_groups[] = {
--
2.31.1
next prev parent reply other threads:[~2023-06-28 18:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-28 18:52 [PATCH v24 00/10] crash: Kernel handling of CPU and memory hot un/plug Eric DeVolder
2023-06-28 18:52 ` Eric DeVolder [this message]
2023-06-29 13:25 ` [PATCH v24 01/10] drivers/base: refactor cpu.c to use .is_visible() Eric DeVolder
2023-06-28 18:52 ` [PATCH v24 02/10] drivers/base: refactor memory.c " Eric DeVolder
2023-06-29 13:25 ` Eric DeVolder
2023-06-28 18:52 ` [PATCH v24 03/10] crash: move a few code bits to setup support of crash hotplug Eric DeVolder
2023-06-28 18:52 ` [PATCH v24 04/10] crash: add generic infrastructure for crash hotplug support Eric DeVolder
2023-06-28 18:52 ` [PATCH v24 05/10] kexec: exclude elfcorehdr from the segment digest Eric DeVolder
2023-06-28 18:52 ` [PATCH v24 06/10] crash: memory and CPU hotplug sysfs attributes Eric DeVolder
2023-06-28 18:52 ` [PATCH v24 07/10] x86/crash: add x86 crash hotplug support Eric DeVolder
2023-06-28 18:52 ` [PATCH v24 08/10] crash: hotplug support for kexec_load() Eric DeVolder
2023-06-28 18:52 ` [PATCH v24 09/10] crash: change crash_prepare_elf64_headers() to for_each_possible_cpu() Eric DeVolder
2023-06-28 18:52 ` [PATCH v24 10/10] x86/crash: optimize CPU changes Eric DeVolder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230628185215.40707-2-eric.devolder@oracle.com \
--to=eric.devolder@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=bhelgaas@google.com \
--cc=boris.ostrovsky@oracle.com \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=david@redhat.com \
--cc=dyoung@redhat.com \
--cc=ebiederm@xmission.com \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=kexec@lists.infradead.org \
--cc=konrad.wilk@oracle.com \
--cc=lf32.dev@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@weissschuh.net \
--cc=mingo@redhat.com \
--cc=naveen.n.rao@linux.vnet.ibm.com \
--cc=osalvador@suse.de \
--cc=rafael@kernel.org \
--cc=seanjc@google.com \
--cc=sourabhjain@linux.ibm.com \
--cc=tglx@linutronix.de \
--cc=tiwai@suse.de \
--cc=vbabka@suse.cz \
--cc=vgoyal@redhat.com \
--cc=vschneid@redhat.com \
--cc=x86@kernel.org \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox