VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/PDMAllNetShaper.cpp@ 80317

最後變更 在這個檔案從80317是 80268,由 vboxsync 提交於 6 年 前

VMM: Refactoring VMMAll/* to use VMCC & VMMCPUCC. bugref:9217

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 3.0 KB
 
1/* $Id: PDMAllNetShaper.cpp 80268 2019-08-14 11:25:13Z vboxsync $ */
2/** @file
3 * PDM Network Shaper - Limit network traffic according to bandwidth group settings.
4 */
5
6/*
7 * Copyright (C) 2011-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define VBOX_BUGREF_9217_PART_I
23#define LOG_GROUP LOG_GROUP_NET_SHAPER
24#include <VBox/vmm/pdm.h>
25#include <VBox/log.h>
26#include <iprt/time.h>
27
28#include <VBox/vmm/pdmnetshaper.h>
29#include "PDMNetShaperInternal.h"
30
31
32/**
33 * Obtain bandwidth in a bandwidth group.
34 *
35 * @returns True if bandwidth was allocated, false if not.
36 * @param pFilter Pointer to the filter that allocates bandwidth.
37 * @param cbTransfer Number of bytes to allocate.
38 */
39VMMDECL(bool) PDMNsAllocateBandwidth(PPDMNSFILTER pFilter, size_t cbTransfer)
40{
41 AssertPtrReturn(pFilter, true);
42 if (!VALID_PTR(pFilter->CTX_SUFF(pBwGroup)))
43 return true;
44
45 PPDMNSBWGROUP pBwGroup = ASMAtomicReadPtrT(&pFilter->CTX_SUFF(pBwGroup), PPDMNSBWGROUP);
46 int rc = PDMCritSectEnter(&pBwGroup->Lock, VERR_SEM_BUSY); AssertRC(rc);
47 if (RT_UNLIKELY(rc == VERR_SEM_BUSY))
48 return true;
49
50 bool fAllowed = true;
51 if (pBwGroup->cbPerSecMax)
52 {
53 /* Re-fill the bucket first */
54 uint64_t tsNow = RTTimeSystemNanoTS();
55 uint32_t uTokensAdded = (tsNow - pBwGroup->tsUpdatedLast) * pBwGroup->cbPerSecMax / (1000 * 1000 * 1000);
56 uint32_t uTokens = RT_MIN(pBwGroup->cbBucket, uTokensAdded + pBwGroup->cbTokensLast);
57
58 if (cbTransfer > uTokens)
59 {
60 fAllowed = false;
61 ASMAtomicWriteBool(&pFilter->fChoked, true);
62 }
63 else
64 {
65 pBwGroup->tsUpdatedLast = tsNow;
66 pBwGroup->cbTokensLast = uTokens - (uint32_t)cbTransfer;
67 }
68 Log2(("pdmNsAllocateBandwidth: BwGroup=%#p{%s} cbTransfer=%u uTokens=%u uTokensAdded=%u fAllowed=%RTbool\n",
69 pBwGroup, R3STRING(pBwGroup->pszNameR3), cbTransfer, uTokens, uTokensAdded, fAllowed));
70 }
71 else
72 Log2(("pdmNsAllocateBandwidth: BwGroup=%#p{%s} disabled fAllowed=%RTbool\n",
73 pBwGroup, R3STRING(pBwGroup->pszNameR3), fAllowed));
74
75 rc = PDMCritSectLeave(&pBwGroup->Lock); AssertRC(rc);
76 return fAllowed;
77}
78
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette