From: David Hildenbrand <david@redhat.com>
To: qemu-s390x@nongnu.org, qemu-devel@nongnu.org
Cc: Christian Borntraeger <borntraeger@de.ibm.com>,
Cornelia Huck <cohuck@redhat.com>,
Richard Henderson <rth@twiddle.net>,
Alexander Graf <agraf@suse.de>,
David Hildenbrand <david@redhat.com>
Subject: [Qemu-devel] [PATCH v3 for-2.12 12/14] s390x/tcg: implement extract-CPU-time facility
Date: Fri, 8 Dec 2017 17:02:05 +0100 [thread overview]
Message-ID: <20171208160207.26494-13-david@redhat.com> (raw)
In-Reply-To: <20171208160207.26494-1-david@redhat.com>
It only provides the EXTRACT CPU TIME instruction. We can reuse the stpt
helper, which calculates the CPU timer value.
As the instruction is not privileged, but we don't have a CPU timer
value in case of linux user, we simply reuse cpu_get_host_ticks() to
produce some descending value.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
target/s390x/cpu_models.c | 1 +
target/s390x/helper.h | 2 +-
target/s390x/insn-data.def | 2 ++
target/s390x/misc_helper.c | 21 +++++++++++++++------
target/s390x/translate.c | 31 +++++++++++++++++++++++++++++++
5 files changed, 50 insertions(+), 7 deletions(-)
diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index 94d24e423d..0be037eac1 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -834,6 +834,7 @@ static void add_qemu_cpu_model_features(S390FeatBitmap fbm)
S390_FEAT_STORE_CLOCK_FAST,
S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
S390_FEAT_ETF3_ENH,
+ S390_FEAT_EXTRACT_CPU_TIME,
S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
diff --git a/target/s390x/helper.h b/target/s390x/helper.h
index 102fbdd7b9..2f17b62d3d 100644
--- a/target/s390x/helper.h
+++ b/target/s390x/helper.h
@@ -119,6 +119,7 @@ DEF_HELPER_4(cu24, i32, env, i32, i32, i32)
DEF_HELPER_4(cu41, i32, env, i32, i32, i32)
DEF_HELPER_4(cu42, i32, env, i32, i32, i32)
DEF_HELPER_5(msa, i32, env, i32, i32, i32, i32)
+DEF_HELPER_FLAGS_1(stpt, TCG_CALL_NO_RWG, i64, env)
#ifndef CONFIG_USER_ONLY
DEF_HELPER_3(servc, i32, env, i64, i64)
@@ -130,7 +131,6 @@ DEF_HELPER_FLAGS_2(sckc, TCG_CALL_NO_RWG, void, env, i64)
DEF_HELPER_FLAGS_2(sckpf, TCG_CALL_NO_RWG, void, env, i64)
DEF_HELPER_FLAGS_1(stckc, TCG_CALL_NO_RWG, i64, env)
DEF_HELPER_FLAGS_2(spt, TCG_CALL_NO_RWG, void, env, i64)
-DEF_HELPER_FLAGS_1(stpt, TCG_CALL_NO_RWG, i64, env)
DEF_HELPER_4(stsi, i32, env, i64, i64, i64)
DEF_HELPER_FLAGS_4(lctl, TCG_CALL_NO_WG, void, env, i32, i64, i32)
DEF_HELPER_FLAGS_4(lctlg, TCG_CALL_NO_WG, void, env, i32, i64, i32)
diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def
index 250741330d..11ee43dcbc 100644
--- a/target/s390x/insn-data.def
+++ b/target/s390x/insn-data.def
@@ -369,6 +369,8 @@
C(0xb24f, EAR, RRE, Z, 0, 0, new, r1_32, ear, 0)
/* EXTRACT CPU ATTRIBUTE */
C(0xeb4c, ECAG, RSY_a, GIE, 0, a2, r1, 0, ecag, 0)
+/* EXTRACT CPU TIME */
+ C(0xc801, ECTG, SSF, ECT, 0, 0, 0, 0, ectg, 0)
/* EXTRACT FPC */
C(0xb38c, EFPC, RRE, Z, 0, 0, new, r1_32, efpc, 0)
/* EXTRACT PSW */
diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c
index 7ddade2f0e..86da6aab7e 100644
--- a/target/s390x/misc_helper.c
+++ b/target/s390x/misc_helper.c
@@ -55,6 +55,21 @@ void HELPER(exception)(CPUS390XState *env, uint32_t excp)
cpu_loop_exit(cs);
}
+/* Store CPU Timer (also used for EXTRACT CPU TIME) */
+uint64_t HELPER(stpt)(CPUS390XState *env)
+{
+#if defined(CONFIG_USER_ONLY)
+ /*
+ * Fake a descending CPU timer. We could get negative values here,
+ * but we don't care as it is up to the OS when to process that
+ * interrupt and reset to > 0.
+ */
+ return UINT64_MAX - (uint64_t)cpu_get_host_ticks();
+#else
+ return time2tod(env->cputm - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+#endif
+}
+
#ifndef CONFIG_USER_ONLY
/* SCLP service call */
@@ -178,12 +193,6 @@ void HELPER(spt)(CPUS390XState *env, uint64_t time)
timer_mod(env->cpu_timer, env->cputm);
}
-/* Store CPU Timer */
-uint64_t HELPER(stpt)(CPUS390XState *env)
-{
- return time2tod(env->cputm - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
-}
-
/* Store System Information */
uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0,
uint64_t r0, uint64_t r1)
diff --git a/target/s390x/translate.c b/target/s390x/translate.c
index 83e1df0f48..eede2ed157 100644
--- a/target/s390x/translate.c
+++ b/target/s390x/translate.c
@@ -3917,6 +3917,36 @@ static ExitStatus op_spm(DisasContext *s, DisasOps *o)
return NO_EXIT;
}
+static ExitStatus op_ectg(DisasContext *s, DisasOps *o)
+{
+ int b1 = get_field(s->fields, b1);
+ int d1 = get_field(s->fields, d1);
+ int b2 = get_field(s->fields, b2);
+ int d2 = get_field(s->fields, d2);
+ int r3 = get_field(s->fields, r3);
+ TCGv_i64 tmp = tcg_temp_new_i64();
+
+ /* fetch all operands first */
+ o->in1 = tcg_temp_new_i64();
+ tcg_gen_addi_i64(o->in1, regs[b1], d1);
+ o->in2 = tcg_temp_new_i64();
+ tcg_gen_addi_i64(o->in2, regs[b2], d2);
+ o->addr1 = get_address(s, 0, r3, 0);
+
+ /* load the third operand into r3 before modifying anything */
+ tcg_gen_qemu_ld64(regs[r3], o->addr1, get_mem_index(s));
+
+ /* subtract CPU timer from first operand and store in GR0 */
+ gen_helper_stpt(tmp, cpu_env);
+ tcg_gen_sub_i64(regs[0], o->in1, tmp);
+
+ /* store second operand in GR1 */
+ tcg_gen_mov_i64(regs[1], o->in2);
+
+ tcg_temp_free_i64(tmp);
+ return NO_EXIT;
+}
+
#ifndef CONFIG_USER_ONLY
static ExitStatus op_spka(DisasContext *s, DisasOps *o)
{
@@ -5679,6 +5709,7 @@ enum DisasInsnEnum {
#define FAC_MSA3 S390_FEAT_MSA_EXT_3 /* msa-extension-3 facility */
#define FAC_MSA4 S390_FEAT_MSA_EXT_4 /* msa-extension-4 facility */
#define FAC_MSA5 S390_FEAT_MSA_EXT_5 /* msa-extension-5 facility */
+#define FAC_ECT S390_FEAT_EXTRACT_CPU_TIME
static const DisasInsn insn_info[] = {
#include "insn-data.def"
--
2.14.3
next prev parent reply other threads:[~2017-12-08 16:02 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 01/14] s390x/kvm: factor out build_channel_report_mcic() into cpu.h David Hildenbrand
2017-12-09 2:17 ` Richard Henderson
2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 02/14] s390x/tcg: fix and cleanup mcck injection David Hildenbrand
2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 03/14] s390x/tcg: implement SET CLOCK PROGRAMMABLE FIELD David Hildenbrand
2017-12-09 2:20 ` Richard Henderson
2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 04/14] s390x/tcg: indicate value of TODPR in STCKE David Hildenbrand
2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 05/14] s390x/tcg: wire up STORE CHANNEL REPORT WORD David Hildenbrand
2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 06/14] s390x/tcg: ASI/ASGI/ALSI/ALSGI are atomic with Interlocked-acccess facility 1 David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 07/14] s390x/tcg: implement Interlocked-Access Facility 2 David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 08/14] s390x/tcg: wire up SET ADDRESS LIMIT David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 09/14] s390x/tcg: wire up SET CHANNEL MONITOR David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 10/14] s390x/tcg: Implement STORE CHANNEL PATH STATUS David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 11/14] s390x/tcg: Implement SIGNAL ADAPTER instruction David Hildenbrand
2017-12-08 16:02 ` David Hildenbrand [this message]
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 13/14] s390x/tcg: we already implement the Set-Program-Parameter facility David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 14/14] s390x: change the QEMU cpu model to a stripped down z12 David Hildenbrand
2017-12-08 16:26 ` Cornelia Huck
2017-12-08 16:29 ` David Hildenbrand
2017-12-08 16:34 ` Daniel P. Berrange
2017-12-08 16:39 ` David Hildenbrand
2017-12-08 16:55 ` [Qemu-devel] [PATCH v4 for-2-12] " David Hildenbrand
2017-12-13 13:24 ` [Qemu-devel] [PATCH v1] s390x/cpumodel: make qemu cpu model play with "none" machine David Hildenbrand
2017-12-13 13:34 ` [Qemu-devel] [qemu-s390x] " Christian Borntraeger
2017-12-13 13:38 ` David Hildenbrand
2017-12-13 17:17 ` [Qemu-devel] " Cornelia Huck
2017-12-14 12:18 ` Cornelia Huck
2017-12-13 17:15 ` [Qemu-devel] [PATCH v1] s390x/tcg: don't include z13 features in the qemu model David Hildenbrand
2017-12-13 17:21 ` Cornelia Huck
2017-12-14 12:19 ` Cornelia Huck
2017-12-11 10:13 ` [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions Cornelia Huck
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=20171208160207.26494-13-david@redhat.com \
--to=david@redhat.com \
--cc=agraf@suse.de \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=rth@twiddle.net \
/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;
as well as URLs for NNTP newsgroup(s).