From nobody Tue Feb 10 06:44:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.67 as permitted sender) client-ip=209.85.221.67; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f67.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.67 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail(p=none dis=none) header.from=amsat.org ARC-Seal: i=1; a=rsa-sha256; t=1601313345; cv=none; d=zohomail.com; s=zohoarc; b=gnHQN9K2xmlYHmeEzaSYHGPbghzHGRrduxZ+8ve7MfWkJy1GgYrzDK5tSwW9LLnxJ3LuVUjs7JNHitSdzUIYGSFOEB/kHrUAihuJljGS7WU3zKL9OMi51FW2GWP1QzIumj4z8soDkqxIMhKNC76mVUTL5byIMlO4SuDpT7zDr+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601313345; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tEiQnyrePNI+SA5QcWB5N9e6IHcTd69FaWZKVkP2uZM=; b=atj3PFtmzAuymnRmQLOUzgy0jC218HYya6lvYkLub331iYPDSOS2JRU69YkvQdkJBgV6cjHUQlydhXtERVi0iTCK65lqV0GUinTiyl0jpJo1dzhM/A6w3aIc5iZyD03Hnn3wLT3fSBB9tMgVdfje3lHuqVDWvR5BDsNcEVJ3zRY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.67 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by mx.zohomail.com with SMTPS id 1601313345171662.5413517892131; Mon, 28 Sep 2020 10:15:45 -0700 (PDT) Received: by mail-wr1-f67.google.com with SMTP id t10so2234377wrv.1 for ; Mon, 28 Sep 2020 10:15:44 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id z67sm464787wme.41.2020.09.28.10.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 10:15: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=tEiQnyrePNI+SA5QcWB5N9e6IHcTd69FaWZKVkP2uZM=; b=R+Khkhq6C3muXCn8UA/xx8ZuX0GdytX17BoZpEA83SH+ZrjpJ36yP61wvjIYhFA6WE cyHo94UlCKVPD1WuBBXQwhA5N6ez3uzah64J+ncpM8+FSRvnVtGu07dPsU1QyH+JT9FU ddNIgX1bZmAQHoiEFEB8SpYEOoxTuDbfOAKNeek8wUPXzjcaPUtkKVNudNBA2UwOqpz8 nJWRurXXF1DDy5uhrN/K6OAltTuLfsRI/7q+pzCgjTTGHjnDTlfuaqttmXJOhVBWVW3e lWOLe600k6960nqcgAGb+tbY0yVxRRujLMB/U73mG3VjUbL0PueyEpLsv/K1KGiHMwB7 IAlg== 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=tEiQnyrePNI+SA5QcWB5N9e6IHcTd69FaWZKVkP2uZM=; b=J8i8MQTn0kFb7EDwoSY0M8bxpyHLc4gksrziPvHKrtvobT2BsWAAClCzoZuIyXl6PD kXeT8rMtPggvPVg4g3UDhQ7XQ0i3Uj2sOCgc7ULcHV8lmBMQ9mine1BwwwB1oP7solEA QrVsyux7NueJr8EvLfAmt9w9y9hT4hB3rzItG37PZag58Jevu8+kPIZfwHuFKOjjrCbU TPKYk5BBu9Lg7sPhp5e1mZBBfCMgLHsF9XKpEybBySoSOHpi07YS2e6vyHi6xGJ45Y1v Nnz9NDqNWDzxKvv7vcb6bkhkKP+BdtYUY1V/eCtNnq4vnxlDEP8wxxbkxAH9k4v0hKRr 7vXQ== X-Gm-Message-State: AOAM530s1k74RdiNqcn0rHpT0ETyLj5RtfZr7zMDH6Xuh7Hz9mzA6BZs Xli7E5PPwFUGsA7BFcEBS1w= X-Google-Smtp-Source: ABdhPJz8H+WYfCEcF040REWDSx5gl2HXfOX3SOuwGT5J909C4q0wNdhCusE7/uXn0b8x34T4rf0dpg== X-Received: by 2002:adf:d089:: with SMTP id y9mr2705178wrh.234.1601313343215; Mon, 28 Sep 2020 10:15:43 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Aleksandar Rikalo , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Aleksandar Markovic , Wainer dos Santos Moschetta , Richard Henderson , Paul Burton , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Damien Hedde , Jiaxun Yang , Huacai Chen , Cleber Rosa , Marcel Apfelbaum , Huacai Chen , Eduardo Habkost , "Edgar E . Iglesias" , Aurelien Jarno Subject: [PATCH 01/16] hw/core/cpu: Let CPU object have a clock source Date: Mon, 28 Sep 2020 19:15:24 +0200 Message-Id: <20200928171539.788309-2-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200928171539.788309-1-f4bug@amsat.org> References: <20200928171539.788309-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Let CPUState have a clock source (named 'clk') and CPUClass have a clock_update() callback. The clock can be optionally set Using qdev_connect_clock_in() from the Clock API. If the clock changes, the optional clock_update() will be called. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/core/cpu.h | 5 +++++ hw/core/cpu.c | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 6c34798c8b3..6989d90c193 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -31,6 +31,7 @@ #include "qemu/thread.h" #include "qemu/plugin.h" #include "qom/object.h" +#include "hw/clock.h" =20 typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size, void *opaque); @@ -155,6 +156,7 @@ struct TranslationBlock; * @disas_set_info: Setup architecture specific components of disassembly = info * @adjust_watchpoint_address: Perform a target-specific adjustment to an * address before attempting to match it against watchpoints. + * @clock_update: Callback for input clock changes * * Represents a CPU family or model. */ @@ -176,6 +178,7 @@ struct CPUClass { unsigned size, MMUAccessType access_type, int mmu_idx, MemTxAttrs attrs, MemTxResult response, uintptr_t retaddr); + void (*clock_update)(CPUState *cpu); bool (*virtio_is_big_endian)(CPUState *cpu); int (*memory_rw_debug)(CPUState *cpu, vaddr addr, uint8_t *buf, int len, bool is_write); @@ -316,6 +319,7 @@ struct qemu_work_item; * QOM parent. * @nr_cores: Number of cores within this CPU package. * @nr_threads: Number of threads within this CPU. + * @clock: this CPU source clock (an output clock of another device) * @running: #true if CPU is currently running (lockless). * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end; * valid under cpu_list_lock. @@ -400,6 +404,7 @@ struct CPUState { int num_ases; AddressSpace *as; MemoryRegion *memory; + Clock *clock; =20 void *env_ptr; /* CPUArchState */ IcountDecr *icount_decr_ptr; diff --git a/hw/core/cpu.c b/hw/core/cpu.c index c55c09f734c..37fcff3ec64 100644 --- a/hw/core/cpu.c +++ b/hw/core/cpu.c @@ -30,6 +30,7 @@ #include "qemu/qemu-print.h" #include "sysemu/tcg.h" #include "hw/boards.h" +#include "hw/qdev-clock.h" #include "hw/qdev-properties.h" #include "trace/trace-root.h" #include "qemu/plugin.h" @@ -247,6 +248,16 @@ void cpu_reset(CPUState *cpu) trace_guest_cpu_reset(cpu); } =20 +static void cpu_clk_update(void *opaque) +{ + CPUState *cpu =3D opaque; + CPUClass *cc =3D CPU_GET_CLASS(cpu); + + if (cc->clock_update) { + cc->clock_update(cpu); + } +} + static void cpu_common_reset(DeviceState *dev) { CPUState *cpu =3D CPU(dev); @@ -367,6 +378,7 @@ static void cpu_common_initfn(Object *obj) /* the default value is changed by qemu_init_vcpu() for softmmu */ cpu->nr_cores =3D 1; cpu->nr_threads =3D 1; + cpu->clock =3D qdev_init_clock_in(DEVICE(obj), "clk", cpu_clk_update, = cpu); =20 qemu_mutex_init(&cpu->work_mutex); QSIMPLEQ_INIT(&cpu->work_list); --=20 2.26.2