From: Pierre Morel <pmorel@linux.ibm.com>
To: qemu-s390x@nongnu.org
Cc: qemu-devel@nongnu.org, borntraeger@de.ibm.com,
pasic@linux.ibm.com, richard.henderson@linaro.org,
david@redhat.com, thuth@redhat.com, cohuck@redhat.com,
mst@redhat.com, pbonzini@redhat.com, kvm@vger.kernel.org,
ehabkost@redhat.com, marcel.apfelbaum@gmail.com,
eblake@redhat.com, armbru@redhat.com, seiden@linux.ibm.com,
nrb@linux.ibm.com, frankja@linux.ibm.com
Subject: [PATCH v8 05/12] s390x/cpu_topology: Adding books to STSI
Date: Mon, 20 Jun 2022 16:03:45 +0200 [thread overview]
Message-ID: <20220620140352.39398-6-pmorel@linux.ibm.com> (raw)
In-Reply-To: <20220620140352.39398-1-pmorel@linux.ibm.com>
Let's add STSI support for the container level 3, books,
and provide the information back to the guest.
Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
---
hw/s390x/cpu-topology.c | 163 +++++++++++++++++++++++++++++---
include/hw/s390x/cpu-topology.h | 20 +++-
include/hw/s390x/sclp.h | 1 +
target/s390x/cpu_topology.c | 53 ++++++++---
4 files changed, 210 insertions(+), 27 deletions(-)
diff --git a/hw/s390x/cpu-topology.c b/hw/s390x/cpu-topology.c
index 0fd6f08084..eba003d498 100644
--- a/hw/s390x/cpu-topology.c
+++ b/hw/s390x/cpu-topology.c
@@ -86,6 +86,38 @@ static S390TopologySocket *s390_create_socket(MachineState *ms,
return socket;
}
+/*
+ * s390_create_book:
+ * @ms: Machine state
+ * @drawer: the drawer on which to create the book
+ * @id: the book id
+ *
+ * returns a pointer to the created S390TopologyBook structure
+ *
+ * On error: return NULL
+ */
+static S390TopologyBook *s390_create_book(MachineState *ms,
+ S390TopologyDrawer *drawer,
+ int id, Error **errp)
+{
+ DeviceState *dev;
+ S390TopologyBook *book;
+
+ if (drawer->bus->num_children >= ms->smp.books) {
+ error_setg(errp, "Unable to create more books.");
+ return NULL;
+ }
+
+ dev = qdev_new(TYPE_S390_TOPOLOGY_BOOK);
+ qdev_realize_and_unref(dev, drawer->bus, &error_fatal);
+
+ book = S390_TOPOLOGY_BOOK(dev);
+ book->book_id = id;
+ drawer->cnt++;
+
+ return book;
+}
+
/*
* s390_get_cores:
* @ms: Machine state
@@ -142,6 +174,34 @@ static S390TopologySocket *s390_get_socket(MachineState *ms,
return s390_create_socket(ms, book, socket_id, errp);
}
+/*
+ * s390_get_book:
+ * @ms: Machine state
+ * @drawer: The drawer to search into
+ * @book_id: the identifier of the book to search for
+ * @errp: Error pointer
+ *
+ * returns a pointer to a S390TopologySocket structure within a drawer having
+ * the specified book_id.
+ * First search if the drawer is already containing the S390TopologySocket
+ * structure and if not create one with this book_id.
+ */
+static S390TopologyBook *s390_get_book(MachineState *ms,
+ S390TopologyDrawer *drawer,
+ int book_id, Error **errp)
+{
+ S390TopologyBook *book;
+ BusChild *kid;
+
+ QTAILQ_FOREACH(kid, &drawer->bus->children, sibling) {
+ book = S390_TOPOLOGY_BOOK(kid->child);
+ if (book->book_id == book_id) {
+ return book;
+ }
+ }
+ return s390_create_book(ms, drawer, book_id, errp);
+}
+
/*
* s390_topology_new_cpu:
* @core_id: the core ID is machine wide
@@ -155,16 +215,23 @@ static S390TopologySocket *s390_get_socket(MachineState *ms,
*/
bool s390_topology_new_cpu(MachineState *ms, int core_id, Error **errp)
{
+ S390TopologyDrawer *drawer;
S390TopologyBook *book;
S390TopologySocket *socket;
S390TopologyCores *cores;
int nb_cores_per_socket;
+ int nb_cores_per_book;
int origin, bit;
- book = s390_get_topology();
+ drawer = s390_get_topology();
nb_cores_per_socket = ms->smp.cores * ms->smp.threads;
+ nb_cores_per_book = ms->smp.sockets * nb_cores_per_socket;
+ book = s390_get_book(ms, drawer, core_id / nb_cores_per_book, errp);
+ if (!book) {
+ return false;
+ }
socket = s390_get_socket(ms, book, core_id / nb_cores_per_socket, errp);
if (!socket) {
return false;
@@ -206,23 +273,23 @@ void s390_topology_setup(MachineState *ms)
DeviceState *dev;
/* Create BOOK bridge device */
- dev = qdev_new(TYPE_S390_TOPOLOGY_BOOK);
+ dev = qdev_new(TYPE_S390_TOPOLOGY_DRAWER);
object_property_add_child(qdev_get_machine(),
- TYPE_S390_TOPOLOGY_BOOK, OBJECT(dev));
+ TYPE_S390_TOPOLOGY_DRAWER, OBJECT(dev));
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
}
-S390TopologyBook *s390_get_topology(void)
+S390TopologyDrawer *s390_get_topology(void)
{
- static S390TopologyBook *book;
+ static S390TopologyDrawer *drawer;
- if (!book) {
- book = S390_TOPOLOGY_BOOK(
- object_resolve_path(TYPE_S390_TOPOLOGY_BOOK, NULL));
- assert(book != NULL);
+ if (!drawer) {
+ drawer = S390_TOPOLOGY_DRAWER(object_resolve_path(
+ TYPE_S390_TOPOLOGY_DRAWER, NULL));
+ assert(drawer != NULL);
}
- return book;
+ return drawer;
}
/* --- CORES Definitions --- */
@@ -365,12 +432,13 @@ static void book_class_init(ObjectClass *oc, void *data)
hc->unplug = qdev_simple_device_unplug_cb;
set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
dc->realize = s390_book_device_realize;
+ dc->bus_type = TYPE_S390_TOPOLOGY_DRAWER_BUS;
dc->desc = "topology book";
}
static const TypeInfo book_info = {
.name = TYPE_S390_TOPOLOGY_BOOK,
- .parent = TYPE_SYS_BUS_DEVICE,
+ .parent = TYPE_DEVICE,
.instance_size = sizeof(S390TopologyBook),
.class_init = book_class_init,
.interfaces = (InterfaceInfo[]) {
@@ -379,6 +447,77 @@ static const TypeInfo book_info = {
}
};
+/* --- DRAWER Definitions --- */
+static Property s390_topology_drawer_properties[] = {
+ DEFINE_PROP_UINT8("drawer_id", S390TopologyDrawer, drawer_id, 0),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static char *drawer_bus_get_dev_path(DeviceState *dev)
+{
+ S390TopologyDrawer *drawer = S390_TOPOLOGY_DRAWER(dev);
+ DeviceState *node = dev->parent_bus->parent;
+ char *id = qdev_get_dev_path(node);
+ char *ret;
+
+ if (id) {
+ ret = g_strdup_printf("%s:%02d", id, drawer->drawer_id);
+ g_free(id);
+ } else {
+ ret = g_strdup_printf("_:%02d", drawer->drawer_id);
+ }
+
+ return ret;
+}
+
+static void drawer_bus_class_init(ObjectClass *oc, void *data)
+{
+ BusClass *k = BUS_CLASS(oc);
+
+ k->get_dev_path = drawer_bus_get_dev_path;
+ k->max_dev = S390_MAX_DRAWERS;
+}
+
+static const TypeInfo drawer_bus_info = {
+ .name = TYPE_S390_TOPOLOGY_DRAWER_BUS,
+ .parent = TYPE_BUS,
+ .instance_size = 0,
+ .class_init = drawer_bus_class_init,
+};
+
+static void s390_drawer_device_realize(DeviceState *dev, Error **errp)
+{
+ S390TopologyDrawer *drawer = S390_TOPOLOGY_DRAWER(dev);
+ BusState *bus;
+
+ bus = qbus_new(TYPE_S390_TOPOLOGY_DRAWER_BUS, dev,
+ TYPE_S390_TOPOLOGY_DRAWER_BUS);
+ qbus_set_hotplug_handler(bus, OBJECT(dev));
+ drawer->bus = bus;
+}
+
+static void drawer_class_init(ObjectClass *oc, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(oc);
+ HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
+
+ hc->unplug = qdev_simple_device_unplug_cb;
+ set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+ dc->realize = s390_drawer_device_realize;
+ device_class_set_props(dc, s390_topology_drawer_properties);
+ dc->desc = "topology drawer";
+}
+
+static const TypeInfo drawer_info = {
+ .name = TYPE_S390_TOPOLOGY_DRAWER,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(S390TopologyDrawer),
+ .class_init = drawer_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_HOTPLUG_HANDLER },
+ { }
+ }
+};
static void topology_register(void)
{
type_register_static(&cpu_cores_info);
@@ -386,6 +525,8 @@ static void topology_register(void)
type_register_static(&socket_info);
type_register_static(&book_bus_info);
type_register_static(&book_info);
+ type_register_static(&drawer_bus_info);
+ type_register_static(&drawer_info);
}
type_init(topology_register);
diff --git a/include/hw/s390x/cpu-topology.h b/include/hw/s390x/cpu-topology.h
index beec61706c..5ffb8cba77 100644
--- a/include/hw/s390x/cpu-topology.h
+++ b/include/hw/s390x/cpu-topology.h
@@ -56,18 +56,30 @@ OBJECT_DECLARE_SIMPLE_TYPE(S390TopologySocket, S390_TOPOLOGY_SOCKET)
#define TYPE_S390_TOPOLOGY_BOOK "topology book"
#define TYPE_S390_TOPOLOGY_BOOK_BUS "book-bus"
struct S390TopologyBook {
- SysBusDevice parent_obj;
+ DeviceState parent_obj;
BusState *bus;
int book_id;
int cnt;
};
typedef struct S390TopologyBook S390TopologyBook;
OBJECT_DECLARE_SIMPLE_TYPE(S390TopologyBook, S390_TOPOLOGY_BOOK)
-#define S390_MAX_BOOKS 1
+#define S390_MAX_BOOKS 4
+
+#define TYPE_S390_TOPOLOGY_DRAWER "topology drawer"
+#define TYPE_S390_TOPOLOGY_DRAWER_BUS "drawer-bus"
+struct S390TopologyDrawer {
+ SysBusDevice parent_obj;
+ BusState *bus;
+ uint8_t drawer_id;
+ int cnt;
+};
+typedef struct S390TopologyDrawer S390TopologyDrawer;
+OBJECT_DECLARE_SIMPLE_TYPE(S390TopologyDrawer, S390_TOPOLOGY_DRAWER)
+#define S390_MAX_DRAWERS 1
-S390TopologyBook *s390_init_topology(void);
+S390TopologyDrawer *s390_init_topology(void);
-S390TopologyBook *s390_get_topology(void);
+S390TopologyDrawer *s390_get_topology(void);
void s390_topology_setup(MachineState *ms);
bool s390_topology_new_cpu(MachineState *ms, int core_id, Error **errp);
diff --git a/include/hw/s390x/sclp.h b/include/hw/s390x/sclp.h
index d3ade40a5a..139d46efa4 100644
--- a/include/hw/s390x/sclp.h
+++ b/include/hw/s390x/sclp.h
@@ -111,6 +111,7 @@ typedef struct CPUEntry {
uint8_t reserved1;
} QEMU_PACKED CPUEntry;
+#define SCLP_READ_SCP_INFO_MNEST 3
#define SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET 128
typedef struct ReadInfo {
SCCBHeader h;
diff --git a/target/s390x/cpu_topology.c b/target/s390x/cpu_topology.c
index 9f656d7e51..d14b2fb25c 100644
--- a/target/s390x/cpu_topology.c
+++ b/target/s390x/cpu_topology.c
@@ -14,6 +14,7 @@
#include "hw/s390x/pv.h"
#include "hw/sysbus.h"
#include "hw/s390x/cpu-topology.h"
+#include "hw/s390x/sclp.h"
static int stsi_15_container(void *p, int nl, int id)
{
@@ -40,7 +41,7 @@ static int stsi_15_cpus(void *p, S390TopologyCores *cd)
}
static int set_socket(const MachineState *ms, void *p,
- S390TopologySocket *socket)
+ S390TopologySocket *socket, int level)
{
BusChild *kid;
int l, len = 0;
@@ -56,24 +57,56 @@ static int set_socket(const MachineState *ms, void *p,
return len;
}
+static int set_book(const MachineState *ms, void *p,
+ S390TopologyBook *book, int level)
+{
+ BusChild *kid;
+ int l, len = 0;
+
+ if (level >= 3) {
+ len += stsi_15_container(p, 2, book->book_id);
+ p += len;
+ }
+
+ QTAILQ_FOREACH_REVERSE(kid, &book->bus->children, sibling) {
+ l = set_socket(ms, p, S390_TOPOLOGY_SOCKET(kid->child), level);
+ p += l;
+ len += l;
+ }
+
+ return len;
+}
+
static void setup_stsi(const MachineState *ms, void *p, int level)
{
- S390TopologyBook *book;
+ S390TopologyDrawer *drawer;
SysIB_151x *sysib;
BusChild *kid;
+ int nb_sockets, nb_books;
int len, l;
sysib = (SysIB_151x *)p;
sysib->mnest = level;
- sysib->mag[TOPOLOGY_NR_MAG2] = ms->smp.sockets;
+ switch (level) {
+ case 2:
+ nb_books = 0;
+ nb_sockets = ms->smp.sockets * ms->smp.books;
+ break;
+ case 3:
+ nb_books = ms->smp.books;
+ nb_sockets = ms->smp.sockets;
+ break;
+ }
+ sysib->mag[TOPOLOGY_NR_MAG3] = nb_books;
+ sysib->mag[TOPOLOGY_NR_MAG2] = nb_sockets;
sysib->mag[TOPOLOGY_NR_MAG1] = ms->smp.cores * ms->smp.threads;
- book = s390_get_topology();
+ drawer = s390_get_topology();
len = sizeof(SysIB_151x);
p += len;
- QTAILQ_FOREACH_REVERSE(kid, &book->bus->children, sibling) {
- l = set_socket(ms, p, S390_TOPOLOGY_SOCKET(kid->child));
+ QTAILQ_FOREACH_REVERSE(kid, &drawer->bus->children, sibling) {
+ l = set_book(ms, p, S390_TOPOLOGY_BOOK(kid->child), level);
p += l;
len += l;
}
@@ -87,18 +120,14 @@ void insert_stsi_15_1_x(S390CPU *cpu, int sel2, __u64 addr, uint8_t ar)
void *p;
int ret;
- /*
- * Until the SCLP STSI Facility reporting the MNEST value is used,
- * a sel2 value of 2 is the only value allowed in STSI 15.1.x.
- */
- if (sel2 != 2) {
+ if (sel2 < 2 || sel2 > SCLP_READ_SCP_INFO_MNEST) {
setcc(cpu, 3);
return;
}
p = g_malloc0(TARGET_PAGE_SIZE);
- setup_stsi(machine, p, 2);
+ setup_stsi(machine, p, sel2);
if (s390_is_pv()) {
ret = s390_cpu_pv_mem_write(cpu, 0, p, TARGET_PAGE_SIZE);
--
2.31.1
next prev parent reply other threads:[~2022-06-20 14:40 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-20 14:03 [PATCH v8 00/12] s390x: CPU Topology Pierre Morel
2022-06-20 14:03 ` [PATCH v8 01/12] Update Linux Headers Pierre Morel
2022-06-20 14:03 ` [PATCH v8 02/12] s390x/cpu_topology: CPU topology objects and structures Pierre Morel
2022-06-27 13:31 ` Janosch Frank
2022-06-28 11:08 ` Pierre Morel
2022-06-29 15:25 ` Pierre Morel
2022-07-04 11:47 ` Janosch Frank
2022-07-04 14:51 ` Pierre Morel
2022-07-12 15:40 ` Janis Schoetterl-Glausch
2022-07-13 14:59 ` Pierre Morel
2022-07-14 10:38 ` Janis Schoetterl-Glausch
2022-07-14 11:25 ` Pierre Morel
2022-07-14 12:50 ` Janis Schoetterl-Glausch
2022-07-14 19:26 ` Pierre Morel
2022-08-23 13:30 ` Thomas Huth
2022-08-23 16:30 ` Pierre Morel
2022-08-23 17:41 ` Pierre Morel
2022-08-24 7:30 ` Thomas Huth
2022-08-24 8:41 ` Pierre Morel
2022-06-20 14:03 ` [PATCH v8 03/12] s390x/cpu_topology: implementating Store Topology System Information Pierre Morel
2022-06-27 14:26 ` Janosch Frank
2022-06-28 11:03 ` Pierre Morel
2022-07-20 19:34 ` Janis Schoetterl-Glausch
2022-07-21 11:23 ` Pierre Morel
2022-06-20 14:03 ` [PATCH v8 04/12] s390x/cpu_topology: Adding books to CPU topology Pierre Morel
2022-06-20 14:03 ` Pierre Morel [this message]
2022-06-20 14:03 ` [PATCH v8 06/12] s390x/cpu_topology: Adding drawers " Pierre Morel
2022-06-20 14:03 ` [PATCH v8 07/12] s390x/cpu_topology: Adding drawers to STSI Pierre Morel
2022-06-20 14:03 ` [PATCH v8 08/12] s390x/cpu_topology: implementing numa for the s390x topology Pierre Morel
2022-07-14 14:57 ` Janis Schoetterl-Glausch
2022-07-14 20:17 ` Pierre Morel
2022-07-15 9:11 ` Janis Schoetterl-Glausch
2022-07-15 13:07 ` Pierre Morel
2022-07-20 17:24 ` Janis Schoetterl-Glausch
2022-07-21 7:58 ` Pierre Morel
2022-07-21 8:16 ` Janis Schoetterl-Glausch
2022-07-21 11:41 ` Pierre Morel
2022-07-22 12:08 ` Janis Schoetterl-Glausch
2022-08-23 16:25 ` Pierre Morel
2022-06-20 14:03 ` [PATCH v8 09/12] target/s390x: interception of PTF instruction Pierre Morel
2022-06-20 14:03 ` [PATCH v8 10/12] s390x/cpu_topology: resetting the Topology-Change-Report Pierre Morel
2022-06-20 14:03 ` [PATCH v8 11/12] s390x/cpu_topology: CPU topology migration Pierre Morel
2022-06-20 14:03 ` [PATCH v8 12/12] s390x/cpu_topology: activating CPU topology Pierre Morel
2022-07-14 18:43 ` [PATCH v8 00/12] s390x: CPU Topology Janis Schoetterl-Glausch
2022-07-14 20:05 ` Pierre Morel
2022-07-15 9:31 ` Janis Schoetterl-Glausch
2022-07-15 13:47 ` Pierre Morel
2022-07-15 18:28 ` Janis Schoetterl-Glausch
2022-07-18 12:32 ` Pierre Morel
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=20220620140352.39398-6-pmorel@linux.ibm.com \
--to=pmorel@linux.ibm.com \
--cc=armbru@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=eblake@redhat.com \
--cc=ehabkost@redhat.com \
--cc=frankja@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=nrb@linux.ibm.com \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=seiden@linux.ibm.com \
--cc=thuth@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.