mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-09 10:34:58 -06:00
PPC: tell the guest about the time base frequency
Our guest systems need to know by how much the timebase increases every second, so there usually is a "timebase-frequency" property in the cpu leaf of the device tree. This property is missing in OpenBIOS. With qemu, Linux's fallback timebase speed and qemu's internal timebase speed match up. With KVM, that is no longer true. The guest is running at the same timebase speed as the host. This leads to massive timing problems. On my test machine, a "sleep 2" takes about 14 seconds with KVM enabled. This patch exports the timebase frequency to OpenBIOS, so it can then put them into the device tree. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
fa0be69a17
commit
dc333cd609
5 changed files with 68 additions and 0 deletions
|
@ -252,3 +252,50 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int read_cpuinfo(const char *field, char *value, int len)
|
||||
{
|
||||
FILE *f;
|
||||
int ret = -1;
|
||||
int field_len = strlen(field);
|
||||
char line[512];
|
||||
|
||||
f = fopen("/proc/cpuinfo", "r");
|
||||
if (!f) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
do {
|
||||
if(!fgets(line, sizeof(line), f)) {
|
||||
break;
|
||||
}
|
||||
if (!strncmp(line, field, field_len)) {
|
||||
strncpy(value, line, len);
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
} while(*line);
|
||||
|
||||
fclose(f);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t kvmppc_get_tbfreq(void)
|
||||
{
|
||||
char line[512];
|
||||
char *ns;
|
||||
uint32_t retval = get_ticks_per_sec();
|
||||
|
||||
if (read_cpuinfo("timebase", line, sizeof(line))) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
if (!(ns = strchr(line, ':'))) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
ns++;
|
||||
|
||||
retval = atoi(ns);
|
||||
return retval;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue