From patchwork Tue Apr 24 09:33:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 154635 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D5355B6EE6 for ; Tue, 24 Apr 2012 19:57:56 +1000 (EST) Received: from localhost ([::1]:59998 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SMc8i-0008Mf-13 for incoming@patchwork.ozlabs.org; Tue, 24 Apr 2012 05:34:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SMc8H-0007cP-Iu for qemu-devel@nongnu.org; Tue, 24 Apr 2012 05:34:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SMc8C-0006Uj-GN for qemu-devel@nongnu.org; Tue, 24 Apr 2012 05:34:01 -0400 Received: from cantor2.suse.de ([195.135.220.15]:45405 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SMc8C-0006UG-7Y for qemu-devel@nongnu.org; Tue, 24 Apr 2012 05:33:56 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 1E02991240; Tue, 24 Apr 2012 11:33:55 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Tue, 24 Apr 2012 11:33:41 +0200 Message-Id: <1335260021-26366-16-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1335260021-26366-1-git-send-email-afaerber@suse.de> References: <1335260021-26366-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: Eduardo Habkost , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Michael Roth Subject: [Qemu-devel] [PATCH v2 15/15] target-i386: Introduce "tsc-frequency" property for X86CPU X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use Hz as unit. Signed-off-by: Andreas Färber Reviewed-by: Eduardo Habkost --- target-i386/cpu.c | 37 ++++++++++++++++++++++++++++++++++++- 1 files changed, 36 insertions(+), 1 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 540b3df..64fd903 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -857,6 +857,37 @@ static void x86_cpuid_set_model_id(Object *obj, const char *model_id, } } +static void x86_cpuid_get_tsc_freq(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + X86CPU *cpu = X86_CPU(obj); + int64_t value; + + value = cpu->env.tsc_khz * 1000; + visit_type_int(v, &value, name, errp); +} + +static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + X86CPU *cpu = X86_CPU(obj); + const int64_t min = 0; + const int64_t max = INT_MAX; + int64_t value; + + visit_type_int(v, &value, name, errp); + if (error_is_set(errp)) { + return; + } + if (value < min || value > max) { + error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "", + name ? name : "null", value, min, max); + return; + } + + cpu->env.tsc_khz = value / 1000; +} + static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) { unsigned int i; @@ -1157,7 +1188,8 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model) env->cpuid_svm_features = def->svm_features; env->cpuid_ext4_features = def->ext4_features; env->cpuid_xlevel2 = def->xlevel2; - env->tsc_khz = def->tsc_khz; + object_property_set_int(OBJECT(cpu), (int64_t)def->tsc_khz * 1000, + "tsc-frequency", &error); if (!kvm_enabled()) { env->cpuid_features &= TCG_FEATURES; env->cpuid_ext_features &= TCG_EXT_FEATURES; @@ -1720,6 +1752,9 @@ static void x86_cpu_initfn(Object *obj) object_property_add_str(obj, "model-id", x86_cpuid_get_model_id, x86_cpuid_set_model_id, NULL); + object_property_add(obj, "tsc-frequency", "int", + x86_cpuid_get_tsc_freq, + x86_cpuid_set_tsc_freq, NULL, NULL, NULL); env->cpuid_apic_id = env->cpu_index; mce_init(cpu);