From patchwork Fri Apr 9 09:36:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1464255 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=nbBdZhNU; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FGtMx3f8Tz9sWC for ; Fri, 9 Apr 2021 19:37:49 +1000 (AEST) Received: from localhost ([::1]:46802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUnaF-0000SM-JB for incoming@patchwork.ozlabs.org; Fri, 09 Apr 2021 05:37:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35112) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUnZ7-0007vl-GS for qemu-devel@nongnu.org; Fri, 09 Apr 2021 05:36:38 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:40891) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lUnZ3-0002ap-RI for qemu-devel@nongnu.org; Fri, 09 Apr 2021 05:36:36 -0400 Received: by mail-ej1-x62d.google.com with SMTP id n2so7616835ejy.7 for ; Fri, 09 Apr 2021 02:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2jzT10IDw8GqcAMkVi0ePEkWHtJHIafM5a4hvb/idiU=; b=nbBdZhNU6QpWAf6JVUEAfVtUjh9YH1O45GPqVE3u4nWq3u41YDlCTmSn2KDQ82JBfE dD0AHFzUugEJYgHCMZWrSFLhotwkl8zmC4XOMFKH3V/TCLA8b1fpM7OwaKtx9XyBZXN+ CTBsWK/ce+qfvyf4H/VldUMEHbnPklvrab0roJr3A5MwN37VaBveJAJK+tyLsxPM5B0q lkd3AgF4RoPr7b4mwPvWprIU+kuEZeha/IuNXAJORH5KRS4LbC2mTmPTMC/xmFSdmNcF arIBQREzOuaoGLifQsaY/DbzD0agouvpndYZLTRQGQPNrZRgKjqcOvrMJKgUy9nBAwoc Bi3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=2jzT10IDw8GqcAMkVi0ePEkWHtJHIafM5a4hvb/idiU=; b=kvCKcwG8lc2YNklY7aAVFtZ3afyTwQaXajLBtxWTFDBQPFfkAfEIKi7L3VW494rPoU 68/4A9FSLzihXC42++QvJci4mwGhryf3zmsSZ6jROvpGRKmyxPDxK1SKJw4bg8MSgHhD aKJ4v2QCBVBHCtVf344glGCApsr91iz9xZ/9LGLdm9yLF9KiuWC5wFvSAgWn+UFAJgrB JexVGjhO4jxKFJOHZCxgJ9D3rXUcJzLGQGPImBnH+plO+QMJKMSV8L3OhgieOmmiFuuE pds+e4wsP2xISM5yFXSQQ0Ahdwydb7C+LQkWJ2aB6xlF4G1fw6uLZ+jnAF5LaiX6Om0J P4QA== X-Gm-Message-State: AOAM531YSLHCeiEkrFDeOqe5rMjcfkrjy9LQGpP0Jbqenx2CJ3telP6e uUeJJGMLN5HIJzPellIrZT0YESoezKey0Q== X-Google-Smtp-Source: ABdhPJx457xqYwWe+eGM7e1lKVWCyUhiblYH+B6eeFgD8FjlJqli76ufM3QPp6xxv8MCNXE2ADXubA== X-Received: by 2002:a17:906:fcb2:: with SMTP id qw18mr14803984ejb.434.1617960991097; Fri, 09 Apr 2021 02:36:31 -0700 (PDT) Received: from x1w.redhat.com (17.red-88-21-201.staticip.rima-tde.net. [88.21.201.17]) by smtp.gmail.com with ESMTPSA id r17sm1122048edx.1.2021.04.09.02.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 02:36:30 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH-for-6.1 v2 1/6] target/mips/cpu: Use clock_has_source() instead of clock_get() Date: Fri, 9 Apr 2021 11:36:18 +0200 Message-Id: <20210409093623.2402750-2-f4bug@amsat.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210409093623.2402750-1-f4bug@amsat.org> References: <20210409093623.2402750-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-x62d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Aleksandar Rikalo , Luc Michel , Huacai Chen , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hao Wu , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" clock_get() returns the clock period. With an unconnected clock we get 0. This is not what we want here. Use the API properly by using the clock_has_source() function instead. Fixes: a0713e85bfa ("target/mips/cpu: Allow the CPU to use dynamic frequencies") Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- target/mips/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/mips/cpu.c b/target/mips/cpu.c index dce1e166bde..aa0b00256e6 100644 --- a/target/mips/cpu.c +++ b/target/mips/cpu.c @@ -612,7 +612,7 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp) MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(dev); Error *local_err = NULL; - if (!clock_get(cpu->clock)) { + if (!clock_has_source(cpu->clock)) { #ifndef CONFIG_USER_ONLY if (!qtest_enabled()) { g_autofree char *cpu_freq_str = freq_to_str(CPU_FREQ_HZ_DEFAULT); From patchwork Fri Apr 9 09:36:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1464253 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=SsXF+UgI; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FGtMJ24F0z9sWC for ; Fri, 9 Apr 2021 19:37:15 +1000 (AEST) Received: from localhost ([::1]:44742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUnZh-000837-In for incoming@patchwork.ozlabs.org; Fri, 09 Apr 2021 05:37:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUnZC-0007yn-Dx for qemu-devel@nongnu.org; Fri, 09 Apr 2021 05:36:43 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]:34575) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lUnZ9-0002g8-8I for qemu-devel@nongnu.org; Fri, 09 Apr 2021 05:36:41 -0400 Received: by mail-ed1-x530.google.com with SMTP id ba6so5781490edb.1 for ; Fri, 09 Apr 2021 02:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lxBTXyvbAaGxN3p2AS1o7HgTWI8VLAUHNHXBSFX2Z74=; b=SsXF+UgIizRJlNFOQ2H+y4CGGoClAglnEgI3y/MrRXtsJbHBTLEZrjaWO43gBHPVNh 2+Ir3rN2K10FfnemQBcBxXRK5JeHOoJ+4pBTearUlvZwXZ9HcKDWPB/rUOAc79SWckV9 msJzmfzkRtmbT3Hm339M0gRNN489Gga2K48ygWGKDPtX+tYTqukI+L2BntqNNL3IKwUK Gsd+i0nU/GFOX/vLHOXFyJR94HFx99yOqLdzEVuR4SfP9iXghRObnyc9r3sp5oMxYeLN ZZvy7/q2L5PH/QVFTsuoG5LG2n8qxEuueEmXsIbbbE1tHv2bYzd+kdbwfahYIxPxf8mP bUng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=lxBTXyvbAaGxN3p2AS1o7HgTWI8VLAUHNHXBSFX2Z74=; b=IedF7ZsrZ8kEvuKBAo4gVywTw8/1GjGMhkACnacJnSgsT6CHnu/fiRzmT8vZWCMV28 DjcSb9ijXXW0WbNRSPbwer0NacDIiNsCiaZX/qe4qumzvGVm0H1E3/4sbvdVXROs4zVv 4v5OlAqnXsGeaY97Zngivf1Ui+rH9RcO2TCShu0YAIOAAzL+UHGTNRtCkd9CVo/rweeH Nzb/b+RUsWp+Kk783qHKlt+xbOV0nazdCGeR+Pn9HEC7hw5avpsuXV8nzJasK/Y73S4K Tousf7+fyUPqYrCmo2GKlK27PGIDxfpp6TqH192Zz5gRXH1X67FkjJ4qVnejRZycIb0F H4iw== X-Gm-Message-State: AOAM5302n1hpBeOa1/qzBcn9nXbAq903zl7ptoLl+5R8Dc5VDCvoXplq z3bHgC1uj065h4nXLbtXPgZeccE2TpRAnA== X-Google-Smtp-Source: ABdhPJwSBS3RTHQYhNdbckVP0XM2zHcgPpKtPxo7Znz1G/19SoBlSGgXKGTKiKsHUmhhmJdwNq1Y6w== X-Received: by 2002:a05:6402:51d4:: with SMTP id r20mr16676168edd.112.1617960996372; Fri, 09 Apr 2021 02:36:36 -0700 (PDT) Received: from x1w.redhat.com (17.red-88-21-201.staticip.rima-tde.net. [88.21.201.17]) by smtp.gmail.com with ESMTPSA id t1sm1070337eds.53.2021.04.09.02.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 02:36:35 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH-for-6.1 v2 2/6] target/mips/cpu: Update CP0 clock when CPU clock is propagated Date: Fri, 9 Apr 2021 11:36:19 +0200 Message-Id: <20210409093623.2402750-3-f4bug@amsat.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210409093623.2402750-1-f4bug@amsat.org> References: <20210409093623.2402750-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-x530.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Aleksandar Rikalo , Luc Michel , Huacai Chen , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hao Wu , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Setting the CP0 clock simply on CPU init is incorrect. First because the clock can not be yet propagated. Second because we aimed to support dynamic frequencies in commit a0713e85bfa, so the CPU frequency can be changed *after* init time. The correct way is to register a ClockCallback, which will update the CP0 period when the clock changes. Fixes: a0713e85bfa ("target/mips/cpu: Allow the CPU to use dynamic frequencies") Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- target/mips/cpu.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/target/mips/cpu.c b/target/mips/cpu.c index aa0b00256e6..db93d19c49a 100644 --- a/target/mips/cpu.c +++ b/target/mips/cpu.c @@ -604,6 +604,13 @@ static void mips_cp0_period_set(MIPSCPU *cpu) assert(env->cp0_count_ns); } +static void mips_cpu_clk_update(void *opaque, ClockEvent event) +{ + MIPSCPU *cpu = opaque; + + mips_cp0_period_set(cpu); +} + static void mips_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); @@ -624,7 +631,6 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp) /* Initialize the frequency in case the clock remains unconnected. */ clock_set_hz(cpu->clock, CPU_FREQ_HZ_DEFAULT); } - mips_cp0_period_set(cpu); cpu_exec_realizefn(cs, &local_err); if (local_err != NULL) { @@ -653,7 +659,8 @@ static void mips_cpu_initfn(Object *obj) MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(obj); cpu_set_cpustate_pointers(cpu); - cpu->clock = qdev_init_clock_in(DEVICE(obj), "clk-in", NULL, cpu, 0); + cpu->clock = qdev_init_clock_in(DEVICE(obj), "clk-in", + mips_cpu_clk_update, cpu, ClockUpdate); env->cpu_model = mcc->cpu_def; } From patchwork Fri Apr 9 09:36:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1464256 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=W2X8XMND; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FGtQ411lpz9sW5 for ; Fri, 9 Apr 2021 19:39:40 +1000 (AEST) Received: from localhost ([::1]:51804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUnc2-0002X4-5u for incoming@patchwork.ozlabs.org; Fri, 09 Apr 2021 05:39:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUnZH-00080B-24 for qemu-devel@nongnu.org; Fri, 09 Apr 2021 05:36:47 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]:37660) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lUnZE-0002kK-Tg for qemu-devel@nongnu.org; Fri, 09 Apr 2021 05:36:46 -0400 Received: by mail-ej1-x62e.google.com with SMTP id w3so7634871ejc.4 for ; Fri, 09 Apr 2021 02:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T+4ADdhkVIxyjAgrjisa3QyFRFD4Jv4USEQdTNaJS5Q=; b=W2X8XMNDESoAQWNNcDFUt1MgIH/TxfqP1Y6eOfjXtlWD5oUCyJnPgrMiHTkmKLX0lg rXRG47oWaTn4bu7Y9sActP/lBS2cXAgpzHNUK+IWj41P7xf10pQ3Keodoqfmc9MKj1M9 RUpRtdOpTQvJCzTl0Xh67/CVS74TOv5Y540nq7gqUP9L1lKuyhFQPp7vuvqj0C17a3Gq +7ESkvw/ijmSzMwMKRSZHon8gwKat9UOBAV1HiiyT7NQn9yVo0u4cxybCoM2iY41xi9E aLEWdRuDCg8SOGgTMJ10H5kXwkpQ1SeglcOoVLxrGnirgX/yWsBgtkxB7/hBIPR37CLP F+vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=T+4ADdhkVIxyjAgrjisa3QyFRFD4Jv4USEQdTNaJS5Q=; b=VuOE9AW/zUm5ylQ+WSDjPOL32aZIYdhdB2vOy2e2Ft5TZqStHQPSz74YuYJXd12b6h 88jMsHn1UV/75P0PmcNNzGY6IHDbGNxcxGJwBpDJhc0VKJvCmDMLi1V2ifFHwlO3EjEv i4lcn97DtWNgSmqFfB07wPT1BTRfouRmNk5F7ZaQivbGhxLqWDAvUungY+czrGLOI4CZ uyGRTlKpvYov9kIXcqHRCZKJfjHyUfZ+kBnqxYSMuLpdWdCYfRHcUlH9Iuk6EG6z9C3u HI0rpVnhekQZ0lSy5RA6OAsYqVcnMILHbi5CilvMVMFZ1h6wCDU5MlBWb/A14T51X0RD n3wA== X-Gm-Message-State: AOAM53042giqypnWQlnlKvCfglJsyn3nKqpyhSNtQO2HagPJDT+oy2Kd zh7c+/+sY2Nd/HqXIbEmKXoT7C55VlUhRg== X-Google-Smtp-Source: ABdhPJwLF+rmA11f92HSpvmo0LOqtUCTjFF7xwH1c8BFH65iCN2HyyHYlYfeizKX9yn5QHQBqJ5FEA== X-Received: by 2002:a17:906:49c1:: with SMTP id w1mr15582105ejv.178.1617961001554; Fri, 09 Apr 2021 02:36:41 -0700 (PDT) Received: from x1w.redhat.com (17.red-88-21-201.staticip.rima-tde.net. [88.21.201.17]) by smtp.gmail.com with ESMTPSA id bh14sm940837ejb.104.2021.04.09.02.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 02:36:41 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH-for-6.1 v2 3/6] target/mips/cp0_timer: Add ns_to_count() helper Date: Fri, 9 Apr 2021 11:36:20 +0200 Message-Id: <20210409093623.2402750-4-f4bug@amsat.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210409093623.2402750-1-f4bug@amsat.org> References: <20210409093623.2402750-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-x62e.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Aleksandar Rikalo , Luc Michel , Huacai Chen , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hao Wu , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Factor ns_to_count() out to simplify a bit. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- target/mips/cp0_timer.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/target/mips/cp0_timer.c b/target/mips/cp0_timer.c index 70de95d338f..73355b44b15 100644 --- a/target/mips/cp0_timer.c +++ b/target/mips/cp0_timer.c @@ -27,6 +27,11 @@ #include "sysemu/kvm.h" #include "internal.h" +static uint32_t ns_to_count(CPUMIPSState *env, uint64_t ns) +{ + return ns / env->cp0_count_ns; +} + /* MIPS R4K timer */ static void cpu_mips_timer_update(CPUMIPSState *env) { @@ -34,8 +39,7 @@ static void cpu_mips_timer_update(CPUMIPSState *env) uint32_t wait; now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - wait = env->CP0_Compare - env->CP0_Count - - (uint32_t)(now_ns / env->cp0_count_ns); + wait = env->CP0_Compare - env->CP0_Count - ns_to_count(env, now_ns); next_ns = now_ns + (uint64_t)wait * env->cp0_count_ns; timer_mod(env->timer, next_ns); } @@ -64,7 +68,7 @@ uint32_t cpu_mips_get_count(CPUMIPSState *env) cpu_mips_timer_expire(env); } - return env->CP0_Count + (uint32_t)(now_ns / env->cp0_count_ns); + return env->CP0_Count + ns_to_count(env, now_ns); } } @@ -79,9 +83,8 @@ void cpu_mips_store_count(CPUMIPSState *env, uint32_t count) env->CP0_Count = count; } else { /* Store new count register */ - env->CP0_Count = count - - (uint32_t)(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / - env->cp0_count_ns); + env->CP0_Count = count - ns_to_count(env, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); /* Update timer timer */ cpu_mips_timer_update(env); } @@ -107,8 +110,7 @@ void cpu_mips_start_count(CPUMIPSState *env) void cpu_mips_stop_count(CPUMIPSState *env) { /* Store the current value */ - env->CP0_Count += (uint32_t)(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / - env->cp0_count_ns); + env->CP0_Count += ns_to_count(env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); } static void mips_timer_cb(void *opaque) From patchwork Fri Apr 9 09:36:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1464258 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=iuQRKpON; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FGtRM0Xtvz9sWC for ; Fri, 9 Apr 2021 19:40:47 +1000 (AEST) Received: from localhost ([::1]:53312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUnd7-0003Aj-3t for incoming@patchwork.ozlabs.org; Fri, 09 Apr 2021 05:40:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUnZJ-00085Z-OT for qemu-devel@nongnu.org; Fri, 09 Apr 2021 05:36:49 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:39885) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lUnZI-0002nK-Bl for qemu-devel@nongnu.org; Fri, 09 Apr 2021 05:36:49 -0400 Received: by mail-ej1-x634.google.com with SMTP id v6so6368876ejo.6 for ; Fri, 09 Apr 2021 02:36:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GLOcVdq6UID+RpF1UB80wJ7L4dB9pvnLuoK+9eg5AUA=; b=iuQRKpON7fzy/OMr8h7zhGJheYA7Ps5PEK9OajnkQmkTsT4W7HS1Wd9MyroH1wKEpa njvKXxDQC3fPB+FvVpG/w2cB2q4d+VPZjOtMV4lii/oXDoKL35q0nZHGoiFWY2NK97c4 vLsK23s1gf9PhCIuP0RuzfosGwTP/p6xRxsnZS33NKNI/11ZH/GJqDcGCAb2szFsv9vc 6qOzF8wGui3WNuXuRIne7W2GsjC4nel5+iX7xUqCdhKlpzgEs3U3GEdvGdlx48h33zCo h8LU69qFMP1x8OYnXDxjHQ5ToqdTpK4MWtBETMND6m2LVjArpsDUhw/jvUmH9nHBUJ3G b47A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=GLOcVdq6UID+RpF1UB80wJ7L4dB9pvnLuoK+9eg5AUA=; b=JvMm1EnA9qBRLYkpAnPjphZH+SJAPVBWhfJB/5bfgg/0FX8H4pzZ1MwPzqDajSVu0a RvAUMLztA7WlJcyHK6hAdF/WAS9FvNR0X7gobB9fanF0/jSmmlkX0N36IZnOlBU/S0QI ibFea+qZOI2CL9yOZg0qIrotq8R6QE5A1D7BXTCAZtnZSa2EMyhI//xKiR0vyHJG+MFM vuHr/QeK7t7yDGvnf0q0+V9mm8P8A9FcnqrBU2lcIAXoPHpCdIUJfA9KUFLLNJ3D0Abp jmWU9yreM6Zsr0/m0ZwllO5DNc11PxYW2FxR0idgobo1wXnLj6gIsKKwuzerCEjywsXI 3O5g== X-Gm-Message-State: AOAM531w/BeGdTuvz5naMxICxIuMBkLcPcRIst7ei7TINvTeNiDaAIVX JvMBeXopA3wvsL4me0r+w3uKIvz79iHfdg== X-Google-Smtp-Source: ABdhPJyYBRdhsYdICc3OmXUlrnf+Wub7UJNZytylr5dNT/Madf+UcJhPwVEOH87Sn9kkbo5XIXv+mw== X-Received: by 2002:a17:906:7691:: with SMTP id o17mr15339108ejm.55.1617961006917; Fri, 09 Apr 2021 02:36:46 -0700 (PDT) Received: from x1w.redhat.com (17.red-88-21-201.staticip.rima-tde.net. [88.21.201.17]) by smtp.gmail.com with ESMTPSA id cy5sm1120079edb.46.2021.04.09.02.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 02:36:46 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH-for-6.1 v2 4/6] target/mips/cp0_timer: Add ns_substract_to_count() helper Date: Fri, 9 Apr 2021 11:36:21 +0200 Message-Id: <20210409093623.2402750-5-f4bug@amsat.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210409093623.2402750-1-f4bug@amsat.org> References: <20210409093623.2402750-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-x634.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Aleksandar Rikalo , Luc Michel , Huacai Chen , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hao Wu , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Factor ns_substract_to_count() out to simplify a bit. Signed-off-by: Philippe Mathieu-Daudé --- target/mips/cp0_timer.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/target/mips/cp0_timer.c b/target/mips/cp0_timer.c index 73355b44b15..85f2f85838d 100644 --- a/target/mips/cp0_timer.c +++ b/target/mips/cp0_timer.c @@ -32,6 +32,12 @@ static uint32_t ns_to_count(CPUMIPSState *env, uint64_t ns) return ns / env->cp0_count_ns; } +static uint32_t ns_substract_to_count(CPUMIPSState *env, + uint32_t count, uint64_t ns) +{ + return count - ns_to_count(env, ns); +} + /* MIPS R4K timer */ static void cpu_mips_timer_update(CPUMIPSState *env) { @@ -39,7 +45,7 @@ static void cpu_mips_timer_update(CPUMIPSState *env) uint32_t wait; now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - wait = env->CP0_Compare - env->CP0_Count - ns_to_count(env, now_ns); + wait = ns_substract_to_count(env, env->CP0_Compare - env->CP0_Count, now_ns); next_ns = now_ns + (uint64_t)wait * env->cp0_count_ns; timer_mod(env->timer, next_ns); } @@ -83,8 +89,8 @@ void cpu_mips_store_count(CPUMIPSState *env, uint32_t count) env->CP0_Count = count; } else { /* Store new count register */ - env->CP0_Count = count - ns_to_count(env, - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); + env->CP0_Count = ns_substract_to_count(env, count, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); /* Update timer timer */ cpu_mips_timer_update(env); } From patchwork Fri Apr 9 09:36:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1464257 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=fXONjXNC; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FGtQB42PMz9sWC for ; Fri, 9 Apr 2021 19:39:46 +1000 (AEST) Received: from localhost ([::1]:52348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUnc8-0002m7-KH for incoming@patchwork.ozlabs.org; Fri, 09 Apr 2021 05:39:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUnZP-0008JD-NH for qemu-devel@nongnu.org; Fri, 09 Apr 2021 05:36:55 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]:38883) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lUnZN-0002rC-Rj for qemu-devel@nongnu.org; Fri, 09 Apr 2021 05:36:55 -0400 Received: by mail-ej1-x62b.google.com with SMTP id r12so7640019ejr.5 for ; Fri, 09 Apr 2021 02:36:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QrsQ6titnvPEg2qiFo1iauoMBA2a+w2LknU0pG+NZbE=; b=fXONjXNCPPQSyIraE886aSBPxzjUEGunSCDwO6mVQpGddCchTHGvk/0fEMVzDGxQMT gYtJ/3Faxf8JH2FoEbPGy4cxlObv4ssGgsvNr7HTbV9mdHThzW4a/Lu8yyR6t+jwdmfD KI9dHfQ8MOP3TuovkfkBmv0l/cdxGB33JBIJkkBt7hgBtO5WGnN5uJMFJUudGsEHaX21 fIvMJ8JTTK97/gukZinJO3hM7k9Ud6d1gQMB3xt2B63kHZXsNKhZjLAeC4uWke11kS3e /8lf4t5JEHywENwp4z6M/HV6ixkpUNEDJFRWQU+ROul/HCIiNrI0m1Z587c3c7q7InAd pAsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=QrsQ6titnvPEg2qiFo1iauoMBA2a+w2LknU0pG+NZbE=; b=jrrBCn4X0lXHm4Sr8/OY0m4RGDlS74dC10eFmFp7XCgaDhTOsvGIIrO9Y2bSwbCVvY sl0KmfM0MDsZuZdlICbjgaGhKEFYJIvd27z9AMJeDwRt2nanVNmmpORxkuOQ/GBHtZ+K 3Vyeu9py/cn6FqG2zAd9I2ImJLvtUQvrBFCMzX9VSbr1y6eYGD2pkM0Lt4k616TyCr8M zC0htvxhBnJLtdTb2l0xDXS4l7qX8Nf5e0/lu79r0wj8oNHFL1QNoRFyjQXyprs6eRzx hLNFtyQtiECtorgLnYqHloq/FR3ZTl8jPoBzp2VbohGqC4PbXl0wyvkexY4h46eXNTex ktCw== X-Gm-Message-State: AOAM530u6KmzlpUX15B9cJoRjc/0hvi4T6xEEYoaVK0rtbWE3ZURoBZ3 PnBCTf3418PggfZwXJEBEDH8Eqa1gykJDQ== X-Google-Smtp-Source: ABdhPJwS4mXF5NFBA8feO1iS6BvIiEHY+0Vj252uKymUJD3TG8EaerrH6W1Ji2c+J4aasEkqFVyBSw== X-Received: by 2002:a17:906:c058:: with SMTP id bm24mr15478461ejb.335.1617961012244; Fri, 09 Apr 2021 02:36:52 -0700 (PDT) Received: from x1w.redhat.com (17.red-88-21-201.staticip.rima-tde.net. [88.21.201.17]) by smtp.gmail.com with ESMTPSA id y16sm1068851edc.62.2021.04.09.02.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 02:36:51 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH-for-6.1 v2 5/6] target/mips/cp0_timer: Use new clock_ns_to_ticks() Date: Fri, 9 Apr 2021 11:36:22 +0200 Message-Id: <20210409093623.2402750-6-f4bug@amsat.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210409093623.2402750-1-f4bug@amsat.org> References: <20210409093623.2402750-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-x62b.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Aleksandar Rikalo , Luc Michel , Huacai Chen , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hao Wu , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Use the new clock_ns_to_ticks() function in cp0_timer where appropriate. This allows us to remove CPUMIPSState::cp0_count_ns and mips_cp0_period_set() and mips_cpu_clk_update(). Signed-off-by: Philippe Mathieu-Daudé --- target/mips/cpu.h | 1 - target/mips/cp0_timer.c | 41 ++++++++++++++++++++++++++++++----------- target/mips/cpu.c | 18 +----------------- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/target/mips/cpu.h b/target/mips/cpu.h index 075c24abdad..10f10018b95 100644 --- a/target/mips/cpu.h +++ b/target/mips/cpu.h @@ -1160,7 +1160,6 @@ struct CPUMIPSState { struct MIPSITUState *itu; MemoryRegion *itc_tag; /* ITC Configuration Tags */ target_ulong exception_base; /* ExceptionBase input to the core */ - uint64_t cp0_count_ns; /* CP0_Count clock period (in nanoseconds) */ }; /** diff --git a/target/mips/cp0_timer.c b/target/mips/cp0_timer.c index 85f2f85838d..3b76cc97f6a 100644 --- a/target/mips/cp0_timer.c +++ b/target/mips/cp0_timer.c @@ -27,26 +27,31 @@ #include "sysemu/kvm.h" #include "internal.h" -static uint32_t ns_to_count(CPUMIPSState *env, uint64_t ns) +static uint32_t tick_to_count(MIPSCPU *cpu, uint64_t ticks) { - return ns / env->cp0_count_ns; + return ticks / cpu->cp0_count_rate; } -static uint32_t ns_substract_to_count(CPUMIPSState *env, - uint32_t count, uint64_t ns) +static uint32_t tick_substract_to_count(MIPSCPU *cpu, + uint32_t count, uint64_t ticks) { - return count - ns_to_count(env, ns); + return count - tick_to_count(cpu, ticks); } /* MIPS R4K timer */ static void cpu_mips_timer_update(CPUMIPSState *env) { + MIPSCPU *cpu = env_archcpu(env); uint64_t now_ns, next_ns; uint32_t wait; + uint64_t now_ticks; now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - wait = ns_substract_to_count(env, env->CP0_Compare - env->CP0_Count, now_ns); - next_ns = now_ns + (uint64_t)wait * env->cp0_count_ns; + now_ticks = clock_ns_to_ticks(cpu->clock, now_ns); + wait = tick_substract_to_count(cpu, env->CP0_Compare - env->CP0_Count, + now_ticks); + next_ns = now_ns + (uint64_t)wait * clock_ticks_to_ns(cpu->clock, + cpu->cp0_count_rate); timer_mod(env->timer, next_ns); } @@ -65,6 +70,7 @@ uint32_t cpu_mips_get_count(CPUMIPSState *env) if (env->CP0_Cause & (1 << CP0Ca_DC)) { return env->CP0_Count; } else { + MIPSCPU *cpu = env_archcpu(env); uint64_t now_ns; now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); @@ -74,12 +80,16 @@ uint32_t cpu_mips_get_count(CPUMIPSState *env) cpu_mips_timer_expire(env); } - return env->CP0_Count + ns_to_count(env, now_ns); + return env->CP0_Count + tick_to_count(cpu, + clock_ns_to_ticks(cpu->clock, + now_ns)); } } void cpu_mips_store_count(CPUMIPSState *env, uint32_t count) { + MIPSCPU *cpu = env_archcpu(env); + /* * This gets called from cpu_state_reset(), potentially before timer init. * So env->timer may be NULL, which is also the case with KVM enabled so @@ -88,9 +98,13 @@ void cpu_mips_store_count(CPUMIPSState *env, uint32_t count) if (env->CP0_Cause & (1 << CP0Ca_DC) || !env->timer) { env->CP0_Count = count; } else { + uint64_t cp0_count_ticks; + + cp0_count_ticks = clock_ns_to_ticks(cpu->clock, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); /* Store new count register */ - env->CP0_Count = ns_substract_to_count(env, count, - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); + env->CP0_Count = tick_substract_to_count(cpu, count, cp0_count_ticks); + /* Update timer timer */ cpu_mips_timer_update(env); } @@ -115,8 +129,13 @@ void cpu_mips_start_count(CPUMIPSState *env) void cpu_mips_stop_count(CPUMIPSState *env) { + MIPSCPU *cpu = env_archcpu(env); + uint64_t cp0_count_ticks; + + cp0_count_ticks = clock_ns_to_ticks(cpu->clock, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); /* Store the current value */ - env->CP0_Count += ns_to_count(env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); + env->CP0_Count += tick_to_count(cpu, cp0_count_ticks); } static void mips_timer_cb(void *opaque) diff --git a/target/mips/cpu.c b/target/mips/cpu.c index db93d19c49a..a66caa44bee 100644 --- a/target/mips/cpu.c +++ b/target/mips/cpu.c @@ -595,22 +595,6 @@ static void mips_cpu_disas_set_info(CPUState *s, disassemble_info *info) #define CPU_FREQ_HZ_DEFAULT 200000000 #define CP0_COUNT_RATE_DEFAULT 2 -static void mips_cp0_period_set(MIPSCPU *cpu) -{ - CPUMIPSState *env = &cpu->env; - - env->cp0_count_ns = clock_ticks_to_ns(MIPS_CPU(cpu)->clock, - cpu->cp0_count_rate); - assert(env->cp0_count_ns); -} - -static void mips_cpu_clk_update(void *opaque, ClockEvent event) -{ - MIPSCPU *cpu = opaque; - - mips_cp0_period_set(cpu); -} - static void mips_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); @@ -660,7 +644,7 @@ static void mips_cpu_initfn(Object *obj) cpu_set_cpustate_pointers(cpu); cpu->clock = qdev_init_clock_in(DEVICE(obj), "clk-in", - mips_cpu_clk_update, cpu, ClockUpdate); + NULL, NULL, ClockUpdate); env->cpu_model = mcc->cpu_def; } From patchwork Fri Apr 9 09:36:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1464261 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=nKpx5aSo; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FGtVQ1j3Gz9sWk for ; Fri, 9 Apr 2021 19:43:26 +1000 (AEST) Received: from localhost ([::1]:58872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUnfg-0005d5-9R for incoming@patchwork.ozlabs.org; Fri, 09 Apr 2021 05:43:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35234) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUnZU-0008VO-Am for qemu-devel@nongnu.org; Fri, 09 Apr 2021 05:37:00 -0400 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]:38527) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lUnZS-0002uc-VR for qemu-devel@nongnu.org; Fri, 09 Apr 2021 05:37:00 -0400 Received: by mail-ed1-x52d.google.com with SMTP id m3so5782081edv.5 for ; Fri, 09 Apr 2021 02:36:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PXqnygnDNRvgHqFuhkZNL41NPY6pp82Qlb6Fn+d88n8=; b=nKpx5aSojz4tdZC6/pso6slZDGWhIJIGZOdizPPUjbaPCxfQFlIuVo+t2tQHLPXjTx v3ViF57x0wX3b5ENata9isOhztsm6eqhevpOsxZDlNRbSwlA9LtHp+wcrmxpzs8KlyjN DqzpKmIBrdiMCThGDeS8vN8S8mYEp32CtLt295OBSTDr8anbnPgX8hUvdGt7NE7eTi2B bNw9iFWcB9/McxhYFtdP3vfqnJOt1HYajpKx2NMFISlACa6m8rUn38c1RU60nh4myaJa s4T8P4nv0BtTshUGiHnLhZFCnfh/RSEfQaUeuTcwY8keXTK4Qa7FY2Li/ABvrVIYmzuj OhVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=PXqnygnDNRvgHqFuhkZNL41NPY6pp82Qlb6Fn+d88n8=; b=QS6TSRyUISdWoqf7rVpAIOI8rTLHumJFRQ5cyZ0miMZCkgwN0FcfU9ylQugfKh/we/ AnYWIFmBN6Z01EqA9FEK++vSTgprfqCtANqnDpohfidHWbAjm4zd3D7PGo6y04ii6Slw joJKwI9OBqMkdhieiZ7eBJklO9HSSX+R98RhAeAYOYS6Vcyuyswnz40BYPunnWPppu2W 6CzZW5H78bEE+QXwNt1i8MbG+3zHnqtGSoyRiDiGcPo2yPyvOjaXyYg/2LWpzt5toiA7 hLaE8tAu+jntmQVxF9hC3/iV80bhpQrNbxlF3tt0ghi4AeP/IOjCmgZ17tMgsWnqSj55 PXNQ== X-Gm-Message-State: AOAM533U5k8HeGa+okoqI8CDBMSq6HsyDdCgQ81Q5k2SqQ5Cyty7zwT4 Bv2lQHVWfWHhdbcRRSq1QkdfYWp0TFw+Pg== X-Google-Smtp-Source: ABdhPJytB528ytxgXKFTaaCXEJyVT4c1+lPaEmPqtyhRgd7zEGafjTYY/ICBGrATZXkQZkgekH9pLA== X-Received: by 2002:a05:6402:344e:: with SMTP id l14mr16811382edc.184.1617961017441; Fri, 09 Apr 2021 02:36:57 -0700 (PDT) Received: from x1w.redhat.com (17.red-88-21-201.staticip.rima-tde.net. [88.21.201.17]) by smtp.gmail.com with ESMTPSA id bh14sm941191ejb.104.2021.04.09.02.36.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 02:36:56 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH-for-6.1 v2 6/6] hw/mips/loongson3_virt: Raise CPU clock to 2 GHz Date: Fri, 9 Apr 2021 11:36:23 +0200 Message-Id: <20210409093623.2402750-7-f4bug@amsat.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210409093623.2402750-1-f4bug@amsat.org> References: <20210409093623.2402750-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52d; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-x52d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Aleksandar Rikalo , Luc Michel , Huacai Chen , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hao Wu , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Commit cd3a53b727d ("clock: Add clock_ns_to_ticks() function") removed the limitation of using clock with a frequency of 1 GHz or more. The previous commit converted the MIPS CP0 timer to use this new clock_ns_to_ticks() function. We can now use a clock of 2 GHz with the Loongson3 virt board. Signed-off-by: Philippe Mathieu-Daudé --- hw/mips/loongson3_virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c index b15071defc6..0b72ef8a684 100644 --- a/hw/mips/loongson3_virt.c +++ b/hw/mips/loongson3_virt.c @@ -152,7 +152,7 @@ static const MemoryRegionOps loongson3_pm_ops = { } }; -#define DEF_LOONGSON3_FREQ (800 * 1000 * 1000) +#define DEF_LOONGSON3_FREQ (2000 * 1000 * 1000) static uint64_t get_cpu_freq_hz(void) {