SUPLibAll.cpp revision 44343529c189705249ab88c40c202a2c581d82b5
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VirtualBox Support Library - All Contexts Code.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Copyright (C) 2006-2014 Oracle Corporation
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * available from http://www.virtualbox.org. This file is free software;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * General Public License (GPL) as published by the Free Software
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * The contents of this file may alternatively be used under the terms
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * of the Common Development and Distribution License Version 1.0
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VirtualBox OSE distribution, in which case the provisions of the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * CDDL are applicable instead of those of the GPL.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * You may elect to license modified versions of this file under the
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * terms and conditions of either the GPL or the CDDL or both.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/*******************************************************************************
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync* Header Files *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync*******************************************************************************/
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync * The slow case for SUPReadTsc where we need to apply deltas.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * Must only be called when deltas are applicable, so please do not call it
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * directly.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * @returns TSC with delta applied.
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync * @remarks May be called with interrupts disabled in ring-0! This is why the
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * ring-0 code doesn't attempt to figure the delta.
cd059a6642b11828bd0ad8b3108f5f7f611d144fvboxsync * @internal
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /** @todo Check out the rdtscp optimization, ASMGetApicId is very expensive. */
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync * Read the TSC and delta.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync int64_t iTscDelta = pGip->aCPUs[pGip->aiCpuFromApicId[idApic]].i64TSCDelta;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * If the delta is valid, apply it.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * The delta needs calculating, call supdrv to get the TSC.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* That didn't work, just return something half useful... */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * Read the TSC and delta.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync uint16_t iGipCpu = (unsigned)iCpuSet < RT_ELEMENTS(pGip->aiCpuFromCpuSetIdx)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync uint8_t idApic = ASMGetApicId(); /** @todo this could probably be eliminated in RC if we really wanted to... */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync uint16_t iGipCpu = (unsigned)idApic < RT_ELEMENTS(pGip->aiCpuFromApicId) /* for the future */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync int64_t iTscDelta = (unsigned)iGipCpu < pGip->cCpus ? pGip->aCPUs[iGipCpu].i64TSCDelta : INT64_MAX;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * If the delta is valid, apply it, otherwise ignore it (really shouldn't
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * happen in these contexts!).
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync AssertMsgFailed(("iCpuSet=%d (%#x) iGipCpu=%#x\n", iCpuSet, iCpuSet, iGipCpu));
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync AssertMsgFailed(("idApic=%#x iGipCpu=%#x\n", idApic, iGipCpu));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync#endif /* RT_ARCH_AMD64 || RT_ARCH_X86 */