From: Avi Kivity <avi@redhat.com>
To: "Denis V. Lunev" <den@parallels.com>
Cc: Konstantin Ozerkov <kozerkov@parallels.com>,
"Denis V. Lunev" <den@openvz.org>, Takashi Iwai <tiwai@suse.de>,
Linus Torvalds <torvalds@linux-foundation.org>,
alsa-devel@alsa-project.org, KVM list <kvm@vger.kernel.org>,
qemu-devel <qemu-devel@nongnu.org>
Subject: Re: Wierd hack to sound/pci/intel8x0.c
Date: Sun, 06 Nov 2011 18:31:42 +0200 [thread overview]
Message-ID: <4EB6B66E.4050408@redhat.com> (raw)
In-Reply-To: <4EB6B285.9050509@parallels.com>
On 11/06/2011 06:15 PM, Denis V. Lunev wrote:
> On 11/6/11 6:51 PM, Avi Kivity wrote:
>> The recently merged 228cf79376f1 ("ALSA: intel8x0: Improve performance
>> in virtual environment") is hacky and somewhat wrong.
>>
>> First, the detection code
>>
>> + if (inside_vm< 0) {
>> + /* detect KVM and Parallels virtual environments */
>> + inside_vm = kvm_para_available();
>> +#if defined(__i386__) || defined(__x86_64__)
>> + inside_vm = inside_vm ||
>> boot_cpu_has(X86_FEATURE_HYPERVISOR);
>> +#endif
>> + }
>> +
>>
>> is incorrect. It detects that you're running in a guest, but that
>> doesn't imply that the device you're accessing is emulated. It may be a
>> host device assigned to the guest; presumably the optimization you apply
>> doesn't work for real devices.
>>
>> Second, the optimization itself looks fishy:
>>
>> spin_lock(&chip->reg_lock);
>> do {
>> civ = igetbyte(chip, ichdev->reg_offset +
>> ICH_REG_OFF_CIV);
>> ptr1 = igetword(chip, ichdev->reg_offset +
>> ichdev->roff_picb);
>> position = ichdev->position;
>> if (ptr1 == 0) {
>> udelay(10);
>> continue;
>> }
>> - if (civ == igetbyte(chip, ichdev->reg_offset +
>> ICH_REG_OFF_CIV)&&
>> - ptr1 == igetword(chip, ichdev->reg_offset +
>> ichdev->roff_picb))
>> + if (civ != igetbyte(chip, ichdev->reg_offset +
>> ICH_REG_OFF_CIV))
>> + continue;
>> + if (chip->inside_vm)
>> + break;
>> + if (ptr1 == igetword(chip, ichdev->reg_offset +
>> ichdev->roff_picb))
>> break;
>> } while (timeout--);
>>
>>
>> Why is the emulated device timing out? Can't the emulation be fixed to
>> behave like real hardware?
>>
>> Last, please copy kvm@vger.kernel.org on such issues.
>>
> The problem is that emulation can not be fixed.
>
> How this is working for real hardware? You get data from real sound
> card register.
> The scheduling is off at the moment thus you can not be re-scheduled.
>
> In the virtual environment the situation is different. Any IO
> emulation is expensive.
> The processor is switched from guest to hypervisor and further to
> emulation process
> takes a lot of time. This time is enough to obtain different value on
> next register read.
> That's why this code is really timed out. Please also note that host
> scheduler also
> plays his games and could schedule out VCPU thread.
>
Note on kvm this is rare, since the guest thread and the emulator thread
are the same.
> The problem could be potentially fixed reducing precision of PICB
> emulation,
> but this results in lower sound quality.
>
> This kludge has been written this way in order not to break legacy
> card for which we
> do not have an access. The code reading PICB/CIV registers second time
> was added
> to fix issues on unknown for now platform and it looks not possible
> how to find/test
> against this platform now. We have checked Windows drivers written by
> Intel/AMD
> (32/64 bit) and MacOS ones. There is no second reading of CIV/PICB
> inside. We
> hope that this is relay needed only for some rare hadware devices.
>
Ok, so if I understand correctly, this loop is a hack for broken
hardware, and this patch basically unhacks it back, assuming that the
emulated (or assigned) hardware is not broken.
> The only thing we can is to improve detection code. Suggestions are
> welcome.
I think it's fine to assume that you're not assigning a 2004 era sound
card to a guest. So I think the code is fine as it is, and can only
suggest to add a comment explaining the mess.
Thanks for explaining.
--
error compiling committee.c: too many arguments to function
next prev parent reply other threads:[~2011-11-06 16:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-06 14:51 Wierd hack to sound/pci/intel8x0.c Avi Kivity
2011-11-06 16:15 ` Denis V. Lunev
2011-11-06 16:31 ` Avi Kivity [this message]
2011-11-06 16:47 ` Takashi Iwai
2011-11-06 16:56 ` Denis V. Lunev
2011-11-06 16:50 ` Denis V. Lunev
2011-11-06 16:33 ` Takashi Iwai
2011-11-07 9:25 ` Gerd Hoffmann
2011-11-07 9:52 ` Konstantin Ozerkov
2011-11-07 10:35 ` Gerd Hoffmann
2011-11-07 10:45 ` Takashi Iwai
2011-11-07 10:44 ` Takashi Iwai
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=4EB6B66E.4050408@redhat.com \
--to=avi@redhat.com \
--cc=alsa-devel@alsa-project.org \
--cc=den@openvz.org \
--cc=den@parallels.com \
--cc=kozerkov@parallels.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
--cc=tiwai@suse.de \
--cc=torvalds@linux-foundation.org \
/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