linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cpu/hotplug: Create SMT sysfs interface for all arches
@ 2019-03-01 17:42 Josh Poimboeuf
  2019-03-06 15:44 ` Thomas Gleixner
  2019-03-24 20:13 ` Thomas Gleixner
  0 siblings, 2 replies; 7+ messages in thread
From: Josh Poimboeuf @ 2019-03-01 17:42 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-kernel, x86, Andrea Arcangeli, Waiman Long, Peter Zijlstra,
	Jiri Kosina

Make the /sys/devices/system/cpu/smt/* files available on all arches, so
user space has a consistent way to detect whether SMT is enabled.

The 'control' file now shows 'notsupported' for architectures which
don't yet have CONFIG_HOTPLUG_SMT.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 .../ABI/testing/sysfs-devices-system-cpu      |  3 +-
 include/linux/cpu.h                           |  2 +-
 kernel/cpu.c                                  | 68 +++++++++++--------
 3 files changed, 43 insertions(+), 30 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
index 9605dbd4b5b5..4a11cba73085 100644
--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
@@ -514,7 +514,8 @@ Description:	Control Symetric Multi Threading (SMT)
 			 "on"		SMT is enabled
 			 "off"		SMT is disabled
 			 "forceoff"	SMT is force disabled. Cannot be changed.
-			 "notsupported" SMT is not supported by the CPU
+			 "notsupported" Runtime SMT toggling is not currently
+					supported for the architecture
 
 			 If control status is "forceoff" or "notsupported" writes
 			 are rejected.
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 5041357d0297..296753249343 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -182,7 +182,7 @@ extern enum cpuhp_smt_control cpu_smt_control;
 extern void cpu_smt_disable(bool force);
 extern void cpu_smt_check_topology(void);
 #else
-# define cpu_smt_control		(CPU_SMT_ENABLED)
+# define cpu_smt_control		(CPU_SMT_NOT_SUPPORTED)
 static inline void cpu_smt_disable(bool force) { }
 static inline void cpu_smt_check_topology(void) { }
 #endif
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 025f419d16f6..517ab1803a22 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -2017,19 +2017,6 @@ static const struct attribute_group cpuhp_cpu_root_attr_group = {
 
 #ifdef CONFIG_HOTPLUG_SMT
 
-static const char *smt_states[] = {
-	[CPU_SMT_ENABLED]		= "on",
-	[CPU_SMT_DISABLED]		= "off",
-	[CPU_SMT_FORCE_DISABLED]	= "forceoff",
-	[CPU_SMT_NOT_SUPPORTED]		= "notsupported",
-};
-
-static ssize_t
-show_smt_control(struct device *dev, struct device_attribute *attr, char *buf)
-{
-	return snprintf(buf, PAGE_SIZE - 2, "%s\n", smt_states[cpu_smt_control]);
-}
-
 static void cpuhp_offline_cpu_device(unsigned int cpu)
 {
 	struct device *dev = get_cpu_device(cpu);
@@ -2100,9 +2087,10 @@ static int cpuhp_smt_enable(void)
 	return ret;
 }
 
+
 static ssize_t
-store_smt_control(struct device *dev, struct device_attribute *attr,
-		  const char *buf, size_t count)
+__store_smt_control(struct device *dev, struct device_attribute *attr,
+		    const char *buf, size_t count)
 {
 	int ctrlval, ret;
 
@@ -2118,9 +2106,6 @@ store_smt_control(struct device *dev, struct device_attribute *attr,
 	if (cpu_smt_control == CPU_SMT_FORCE_DISABLED)
 		return -EPERM;
 
-	if (cpu_smt_control == CPU_SMT_NOT_SUPPORTED)
-		return -ENODEV;
-
 	ret = lock_device_hotplug_sysfs();
 	if (ret)
 		return ret;
@@ -2140,14 +2125,45 @@ store_smt_control(struct device *dev, struct device_attribute *attr,
 	unlock_device_hotplug();
 	return ret ? ret : count;
 }
+
+#else /* !CONFIG_HOTPLUG_SMT */
+static ssize_t
+__store_smt_control(struct device *dev, struct device_attribute *attr,
+		    const char *buf, size_t count)
+{
+	return 0;
+}
+#endif /* CONFIG_HOTPLUG_SMT */
+
+static const char *smt_states[] = {
+	[CPU_SMT_ENABLED]		= "on",
+	[CPU_SMT_DISABLED]		= "off",
+	[CPU_SMT_FORCE_DISABLED]	= "forceoff",
+	[CPU_SMT_NOT_SUPPORTED]		= "notsupported",
+};
+
+static ssize_t
+show_smt_control(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	return snprintf(buf, PAGE_SIZE - 2, "%s\n", smt_states[cpu_smt_control]);
+}
+
+static ssize_t
+store_smt_control(struct device *dev, struct device_attribute *attr,
+		  const char *buf, size_t count)
+{
+
+	if (cpu_smt_control == CPU_SMT_NOT_SUPPORTED)
+		return -ENODEV;
+
+	return __store_smt_control(dev, attr, buf, count);
+}
 static DEVICE_ATTR(control, 0644, show_smt_control, store_smt_control);
 
 static ssize_t
 show_smt_active(struct device *dev, struct device_attribute *attr, char *buf)
 {
-	bool active = topology_max_smt_threads() > 1;
-
-	return snprintf(buf, PAGE_SIZE - 2, "%d\n", active);
+	return snprintf(buf, PAGE_SIZE - 2, "%d\n", sched_smt_active());
 }
 static DEVICE_ATTR(active, 0444, show_smt_active, NULL);
 
@@ -2163,21 +2179,17 @@ static const struct attribute_group cpuhp_smt_attr_group = {
 	NULL
 };
 
-static int __init cpu_smt_state_init(void)
+static int __init cpu_smt_sysfs_init(void)
 {
 	return sysfs_create_group(&cpu_subsys.dev_root->kobj,
 				  &cpuhp_smt_attr_group);
 }
 
-#else
-static inline int cpu_smt_state_init(void) { return 0; }
-#endif
-
 static int __init cpuhp_sysfs_init(void)
 {
 	int cpu, ret;
 
-	ret = cpu_smt_state_init();
+	ret = cpu_smt_sysfs_init();
 	if (ret)
 		return ret;
 
@@ -2198,7 +2210,7 @@ static int __init cpuhp_sysfs_init(void)
 	return 0;
 }
 device_initcall(cpuhp_sysfs_init);
-#endif
+#endif /* CONFIG_SYSFS && CONFIG_HOTPLUG_CPU */
 
 /*
  * cpu_bit_bitmap[] is a special, "compressed" data structure that
-- 
2.17.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] cpu/hotplug: Create SMT sysfs interface for all arches
  2019-03-01 17:42 [PATCH] cpu/hotplug: Create SMT sysfs interface for all arches Josh Poimboeuf
@ 2019-03-06 15:44 ` Thomas Gleixner
  2019-03-24 20:13 ` Thomas Gleixner
  1 sibling, 0 replies; 7+ messages in thread
From: Thomas Gleixner @ 2019-03-06 15:44 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: LKML, x86, Andrea Arcangeli, Waiman Long, Peter Zijlstra,
	Jiri Kosina, Greg KH

Josh,

On Fri, 1 Mar 2019, Josh Poimboeuf wrote:
> Make the /sys/devices/system/cpu/smt/* files available on all arches, so
> user space has a consistent way to detect whether SMT is enabled.
> 
> The 'control' file now shows 'notsupported' for architectures which
> don't yet have CONFIG_HOTPLUG_SMT.

Yes, that makes sense.

<SNIP>

Nice work!. I'll pick it up and queue it for 5.2.

Thanks,

	tglx






^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] cpu/hotplug: Create SMT sysfs interface for all arches
  2019-03-01 17:42 [PATCH] cpu/hotplug: Create SMT sysfs interface for all arches Josh Poimboeuf
  2019-03-06 15:44 ` Thomas Gleixner
@ 2019-03-24 20:13 ` Thomas Gleixner
  2019-03-26 13:32   ` Josh Poimboeuf
  1 sibling, 1 reply; 7+ messages in thread
From: Thomas Gleixner @ 2019-03-24 20:13 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: linux-kernel, x86, Andrea Arcangeli, Waiman Long, Peter Zijlstra,
	Jiri Kosina

On Fri, 1 Mar 2019, Josh Poimboeuf wrote:
> Make the /sys/devices/system/cpu/smt/* files available on all arches, so
> user space has a consistent way to detect whether SMT is enabled.
> 
> The 'control' file now shows 'notsupported' for architectures which
> don't yet have CONFIG_HOTPLUG_SMT.

I'm slowly crawling through my backlog ...

> --- a/Documentation/ABI/testing/sysfs-devices-system-cpu
> +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
> @@ -514,7 +514,8 @@ Description:	Control Symetric Multi Threading (SMT)
>  			 "on"		SMT is enabled
>  			 "off"		SMT is disabled
>  			 "forceoff"	SMT is force disabled. Cannot be changed.
> -			 "notsupported" SMT is not supported by the CPU
> +			 "notsupported" Runtime SMT toggling is not currently
> +					supported for the architecture

Second thoughts. I'm not really convinced that changing the meaning of
notsupported and in fact overloading it, is the right thing to do.
notsupported means now:

  CPU does not support it - OR - architecture does not support it

That's not pretty and we are surely not short of state space. There are
several options for handling this:

 1) Do not expose the state file, just expose the active file

 2) Expose the state file, but return -ENOTSUPP or some other sensible error
    code

 3) Expose the state file and let show return 'notimplemented' which is
    more accurate. That wouldn't even require to expand the state space
    enum. It just can be returned unconditionally.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] cpu/hotplug: Create SMT sysfs interface for all arches
  2019-03-24 20:13 ` Thomas Gleixner
@ 2019-03-26 13:32   ` Josh Poimboeuf
  2019-03-26 13:53     ` Thomas Gleixner
  0 siblings, 1 reply; 7+ messages in thread
From: Josh Poimboeuf @ 2019-03-26 13:32 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-kernel, x86, Andrea Arcangeli, Waiman Long, Peter Zijlstra,
	Jiri Kosina

On Sun, Mar 24, 2019 at 09:13:18PM +0100, Thomas Gleixner wrote:
> On Fri, 1 Mar 2019, Josh Poimboeuf wrote:
> > Make the /sys/devices/system/cpu/smt/* files available on all arches, so
> > user space has a consistent way to detect whether SMT is enabled.
> > 
> > The 'control' file now shows 'notsupported' for architectures which
> > don't yet have CONFIG_HOTPLUG_SMT.
> 
> I'm slowly crawling through my backlog ...
> 
> > --- a/Documentation/ABI/testing/sysfs-devices-system-cpu
> > +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
> > @@ -514,7 +514,8 @@ Description:	Control Symetric Multi Threading (SMT)
> >  			 "on"		SMT is enabled
> >  			 "off"		SMT is disabled
> >  			 "forceoff"	SMT is force disabled. Cannot be changed.
> > -			 "notsupported" SMT is not supported by the CPU
> > +			 "notsupported" Runtime SMT toggling is not currently
> > +					supported for the architecture
> 
> Second thoughts. I'm not really convinced that changing the meaning of
> notsupported and in fact overloading it, is the right thing to do.
> notsupported means now:
> 
>   CPU does not support it - OR - architecture does not support it
> 
> That's not pretty and we are surely not short of state space. There are
> several options for handling this:
> 
>  1) Do not expose the state file, just expose the active file
> 
>  2) Expose the state file, but return -ENOTSUPP or some other sensible error
>     code
> 
>  3) Expose the state file and let show return 'notimplemented' which is
>     more accurate. That wouldn't even require to expand the state space
>     enum. It just can be returned unconditionally.

Makes sense.  I like #3.  I can post another version.

-- 
Josh

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] cpu/hotplug: Create SMT sysfs interface for all arches
  2019-03-26 13:32   ` Josh Poimboeuf
@ 2019-03-26 13:53     ` Thomas Gleixner
  2019-03-26 18:03       ` Josh Poimboeuf
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Gleixner @ 2019-03-26 13:53 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: linux-kernel, x86, Andrea Arcangeli, Waiman Long, Peter Zijlstra,
	Jiri Kosina

On Tue, 26 Mar 2019, Josh Poimboeuf wrote:
> On Sun, Mar 24, 2019 at 09:13:18PM +0100, Thomas Gleixner wrote:
> > Second thoughts. I'm not really convinced that changing the meaning of
> > notsupported and in fact overloading it, is the right thing to do.
> > notsupported means now:
> > 
> >   CPU does not support it - OR - architecture does not support it
> > 
> > That's not pretty and we are surely not short of state space. There are
> > several options for handling this:
> > 
> >  1) Do not expose the state file, just expose the active file
> > 
> >  2) Expose the state file, but return -ENOTSUPP or some other sensible error
> >     code
> > 
> >  3) Expose the state file and let show return 'notimplemented' which is
> >     more accurate. That wouldn't even require to expand the state space
> >     enum. It just can be returned unconditionally.
> 
> Makes sense.  I like #3.  I can post another version.

Yes, please.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] cpu/hotplug: Create SMT sysfs interface for all arches
  2019-03-26 13:53     ` Thomas Gleixner
@ 2019-03-26 18:03       ` Josh Poimboeuf
  2019-03-26 18:34         ` Thomas Gleixner
  0 siblings, 1 reply; 7+ messages in thread
From: Josh Poimboeuf @ 2019-03-26 18:03 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-kernel, x86, Andrea Arcangeli, Waiman Long, Peter Zijlstra,
	Jiri Kosina

On Tue, Mar 26, 2019 at 02:53:04PM +0100, Thomas Gleixner wrote:
> On Tue, 26 Mar 2019, Josh Poimboeuf wrote:
> > On Sun, Mar 24, 2019 at 09:13:18PM +0100, Thomas Gleixner wrote:
> > > Second thoughts. I'm not really convinced that changing the meaning of
> > > notsupported and in fact overloading it, is the right thing to do.
> > > notsupported means now:
> > > 
> > >   CPU does not support it - OR - architecture does not support it
> > > 
> > > That's not pretty and we are surely not short of state space. There are
> > > several options for handling this:
> > > 
> > >  1) Do not expose the state file, just expose the active file
> > > 
> > >  2) Expose the state file, but return -ENOTSUPP or some other sensible error
> > >     code
> > > 
> > >  3) Expose the state file and let show return 'notimplemented' which is
> > >     more accurate. That wouldn't even require to expand the state space
> > >     enum. It just can be returned unconditionally.
> > 
> > Makes sense.  I like #3.  I can post another version.
> 
> Yes, please.

Something like so (on top of the original patch)?

diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
index 4a11cba73085..5eea46fefcb2 100644
--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
@@ -511,11 +511,12 @@ Description:	Control Symetric Multi Threading (SMT)
 		control: Read/write interface to control SMT. Possible
 			 values:
 
-			 "on"		SMT is enabled
-			 "off"		SMT is disabled
-			 "forceoff"	SMT is force disabled. Cannot be changed.
-			 "notsupported" Runtime SMT toggling is not currently
-					supported for the architecture
+			 "on"		  SMT is enabled
+			 "off"		  SMT is disabled
+			 "forceoff"	  SMT is force disabled. Cannot be changed.
+			 "notsupported"   SMT is not supported by the CPU
+			 "notimplemented" SMT runtime toggling is not
+					  implemented for the architecture
 
 			 If control status is "forceoff" or "notsupported" writes
 			 are rejected.
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 517ab1803a22..05a71ee98440 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -2145,7 +2145,11 @@ static const char *smt_states[] = {
 static ssize_t
 show_smt_control(struct device *dev, struct device_attribute *attr, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE - 2, "%s\n", smt_states[cpu_smt_control]);
+	const char *state = IS_ENABLED(CONFIG_HOTPLUG_SMT) ?
+				smt_states[cpu_smt_control] :
+				"notimplemented";
+
+	return snprintf(buf, PAGE_SIZE - 2, "%s\n", state);
 }
 
 static ssize_t

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] cpu/hotplug: Create SMT sysfs interface for all arches
  2019-03-26 18:03       ` Josh Poimboeuf
@ 2019-03-26 18:34         ` Thomas Gleixner
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Gleixner @ 2019-03-26 18:34 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: linux-kernel, x86, Andrea Arcangeli, Waiman Long, Peter Zijlstra,
	Jiri Kosina

On Tue, 26 Mar 2019, Josh Poimboeuf wrote:
> On Tue, Mar 26, 2019 at 02:53:04PM +0100, Thomas Gleixner wrote:
> > > Makes sense.  I like #3.  I can post another version.
> > 
> > Yes, please.
> 
> Something like so (on top of the original patch)?
> 
> diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
> index 4a11cba73085..5eea46fefcb2 100644
> --- a/Documentation/ABI/testing/sysfs-devices-system-cpu
> +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
> @@ -511,11 +511,12 @@ Description:	Control Symetric Multi Threading (SMT)
>  		control: Read/write interface to control SMT. Possible
>  			 values:
>  
> -			 "on"		SMT is enabled
> -			 "off"		SMT is disabled
> -			 "forceoff"	SMT is force disabled. Cannot be changed.
> -			 "notsupported" Runtime SMT toggling is not currently
> -					supported for the architecture
> +			 "on"		  SMT is enabled
> +			 "off"		  SMT is disabled
> +			 "forceoff"	  SMT is force disabled. Cannot be changed.
> +			 "notsupported"   SMT is not supported by the CPU
> +			 "notimplemented" SMT runtime toggling is not
> +					  implemented for the architecture
>  
>  			 If control status is "forceoff" or "notsupported" writes
>  			 are rejected.
> diff --git a/kernel/cpu.c b/kernel/cpu.c
> index 517ab1803a22..05a71ee98440 100644
> --- a/kernel/cpu.c
> +++ b/kernel/cpu.c
> @@ -2145,7 +2145,11 @@ static const char *smt_states[] = {
>  static ssize_t
>  show_smt_control(struct device *dev, struct device_attribute *attr, char *buf)
>  {
> -	return snprintf(buf, PAGE_SIZE - 2, "%s\n", smt_states[cpu_smt_control]);
> +	const char *state = IS_ENABLED(CONFIG_HOTPLUG_SMT) ?
> +				smt_states[cpu_smt_control] :
> +				"notimplemented";
> +
> +	return snprintf(buf, PAGE_SIZE - 2, "%s\n", state);
>  }

Looks good!

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-03-26 18:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-01 17:42 [PATCH] cpu/hotplug: Create SMT sysfs interface for all arches Josh Poimboeuf
2019-03-06 15:44 ` Thomas Gleixner
2019-03-24 20:13 ` Thomas Gleixner
2019-03-26 13:32   ` Josh Poimboeuf
2019-03-26 13:53     ` Thomas Gleixner
2019-03-26 18:03       ` Josh Poimboeuf
2019-03-26 18:34         ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).