From patchwork Fri Aug 5 07:33:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 9264855 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EFE346048B for ; Fri, 5 Aug 2016 07:33:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E563E2842D for ; Fri, 5 Aug 2016 07:33:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA2A52842F; Fri, 5 Aug 2016 07:33:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 646DB2842D for ; Fri, 5 Aug 2016 07:33:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755571AbcHEHdh (ORCPT ); Fri, 5 Aug 2016 03:33:37 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:35782 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755208AbcHEHdf (ORCPT ); Fri, 5 Aug 2016 03:33:35 -0400 Received: by mail-pa0-f66.google.com with SMTP id cf3so18820615pad.2 for ; Fri, 05 Aug 2016 00:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KdciyCZgZh9Si5KF2e7+ai33toBZFdVBSsHtFUdQs8Y=; b=mI8wT/+8qh2hcvARuXCagcDeNl5VFKZQxTaZ+UXrTvDsFL3eU+VfIuZnGk8nF39VCn JjxkKmZI3RH2GAZLbGKzp9Ss1VJHF2rNgzWxfxh3QfDvFuZ0wHdSJB+MPCY5PAM3MxoA 2/B25xHnD5fil5LfPRWciRoMpQhpPlvdEBU5yY02qQfL43/R+H93uPFKIifGUz0JjQqs PPPzoYs7aBFmi1N1r7gD3P2zpxYLIAgxLliZWKiInDyfnaDZCUAVvcispmZbHIu8YODQ I/iaQ24MQNwhPdxQDScShwjHuU89JezD/fuNf1HXCJZdnGUqGRQNcR1ZrUGPM6mV2pIS tO8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KdciyCZgZh9Si5KF2e7+ai33toBZFdVBSsHtFUdQs8Y=; b=FU69VWyER0OIw7FLhdgVgVbQxS24JyhF+xOwujEKpm/l+CEzrckMRSbd3nyCtS68nq LfnQeaDERtfltoxqKBW2UWoy3XqfxmhXkflogriiNdQjuBjHUhofDzyzx9VVuF/7jbZ3 v273f5QT3vTmI1xJ4pav4a5avfEuABzF6WRmbQF6E+90E5Z7eXb3WeXOCodCfm699/59 B0h1h+UN7pwInXuimrFowoN4Uj8qq7jpULZ0oU8rxRukUItakiND7tp3AbH7v/lDJ9+l 6PlMQWPYhbqRu2iJsPV8H420UE6aPrmrPTSXRVHIVSUyj18orK5AwHTIdW2E9I7bhdj4 HmWA== X-Gm-Message-State: AEkoousmQhqn76glqvm0IeoqtEJIpw8k7bFPRZpyRLfNwLt7N8ZcDhsBclw/z5mfGPkvLQ== X-Received: by 10.66.82.42 with SMTP id f10mr133925395pay.17.1470382414726; Fri, 05 Aug 2016 00:33:34 -0700 (PDT) Received: from dyn253.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id y2sm25383787pan.31.2016.08.05.00.33.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Aug 2016 00:33:34 -0700 (PDT) From: Suraj Jitindar Singh To: kvm@vger.kernel.org Cc: sjitindarsingh@gmail.com, drjones@redhat.com, pbonzini@redhat.com Subject: [kvm-unit-tests PATCH 3/4] lib/powerpc: Add function to start secondary threads Date: Fri, 5 Aug 2016 17:33:12 +1000 Message-Id: <1470382393-24209-3-git-send-email-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1470382393-24209-1-git-send-email-sjitindarsingh@gmail.com> References: <1470382393-24209-1-git-send-email-sjitindarsingh@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add the lib/powerpc/smp.c file and associated header files as a place to implement generic smp functionality for inclusion in tests. Add a function "get_secondaries" to start stopped threads of a guest at a given function location. Signed-off-by: Suraj Jitindar Singh --- lib/powerpc/asm/smp.h | 8 +++++ lib/powerpc/smp.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/ppc64/asm/smp.h | 1 + powerpc/Makefile.common | 1 + 4 files changed, 96 insertions(+) create mode 100644 lib/powerpc/asm/smp.h create mode 100644 lib/powerpc/smp.c create mode 100644 lib/ppc64/asm/smp.h diff --git a/lib/powerpc/asm/smp.h b/lib/powerpc/asm/smp.h new file mode 100644 index 0000000..c4e3ad8 --- /dev/null +++ b/lib/powerpc/asm/smp.h @@ -0,0 +1,8 @@ +#ifndef _ASMPOWERPC_SMP_H_ +#define _ASMPOWERPC_SMP_H_ + +extern void halt(void); + +extern int get_secondaries(void (* secondary_func)(void)); + +#endif /* _ASMPOWERPC_SMP_H_ */ diff --git a/lib/powerpc/smp.c b/lib/powerpc/smp.c new file mode 100644 index 0000000..1f8922e --- /dev/null +++ b/lib/powerpc/smp.c @@ -0,0 +1,86 @@ +/* + * Secondary cpu support + * + * Copyright 2016 Suraj Jitindar Singh, IBM. + * + * This work is licensed under the terms of the GNU LGPL, version 2. + */ + +#include +#include +#include +#include +#include +#include +#include + +/* + * Start stopped secondary threads at secondary_func + * Returns: 0 on success + * -1 on failure + */ +int get_secondaries(void (* secondary_func)(void)) +{ + int cpu_root_node, cpu_node, query_token, start_token; + int ret, outputs[1], nr_cpu, cpu, lenp; + const struct fdt_property *prop; + u32 *cpus; + + cpu_root_node = fdt_path_offset(dt_fdt(), "/cpus"); + if (cpu_root_node < 0) { + report("cpu root node not found", 0); + return -1; + } + + query_token = rtas_token("query-cpu-stopped-state"); + start_token = rtas_token("start-cpu"); + if (query_token == RTAS_UNKNOWN_SERVICE || + start_token == RTAS_UNKNOWN_SERVICE) { + report("rtas token not found", 0); + return -1; + } + + dt_for_each_subnode(cpu_root_node, cpu_node) { + prop = fdt_get_property(dt_fdt(), cpu_node, "device_type", &lenp); + /* Not a cpu node */ + if (prop == NULL || lenp != 4 || + strncmp((char *)prop->data, "cpu", 4)) + continue; + + /* Get the id array of threads on this cpu */ + prop = fdt_get_property(dt_fdt(), cpu_node, + "ibm,ppc-interrupt-server#s", &lenp); + if (!prop) { + report("ibm,ppc-interrupt-server#s prop not found" + , 0); + return -1; + } + + nr_cpu = lenp >> 2; /* Divide by 4 since 4 bytes per cpu */ + cpus = (u32 *)prop->data; /* Array of valid cpu numbers */ + + /* Iterate over valid cpus to see if they are stopped */ + for (cpu = 0; cpu < nr_cpu; cpu++) { + int cpu_id = fdt32_to_cpu(cpus[cpu]); + /* Query cpu status */ + ret = rtas_call(query_token, 1, 2, outputs, cpu_id); + /* RTAS call failed */ + if (ret) + goto RTAS_FAILED; + /* cpu is stopped, start it */ + if (!*outputs) { + ret = rtas_call(start_token, 3, 1, NULL, cpu_id, + secondary_func, cpu_id); + /* RTAS call failed */ + if (ret) + goto RTAS_FAILED; + } + } + } + + return 0; + +RTAS_FAILED: + report("RTAS call failed", 0); + return -1; +} diff --git a/lib/ppc64/asm/smp.h b/lib/ppc64/asm/smp.h new file mode 100644 index 0000000..67ced75 --- /dev/null +++ b/lib/ppc64/asm/smp.h @@ -0,0 +1 @@ +#include "../../powerpc/asm/smp.h" diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 404194b..677030a 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -37,6 +37,7 @@ cflatobjs += lib/powerpc/setup.o cflatobjs += lib/powerpc/rtas.o cflatobjs += lib/powerpc/processor.o cflatobjs += lib/powerpc/handlers.o +cflatobjs += lib/powerpc/smp.o FLATLIBS = $(libcflat) $(LIBFDT_archive) %.elf: CFLAGS += $(arch_CFLAGS)