Skip to content

Commit 2d6644d

Browse files
author
Jayapal
committed
CLOUDSTACK-2433 Enable rps and rfs in virtual router
1 parent f76bf5b commit 2d6644d

6 files changed

Lines changed: 102 additions & 6 deletions

File tree

‎core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ protected Answer execute(final IpAssocCommand cmd) {
531531
for (IpAddressTO ip : ips) {
532532
result = assignPublicIpAddress(routerName, routerIp, ip.getPublicIp(), ip.isAdd(),
533533
ip.isFirstIP(), ip.isSourceNat(), ip.getVlanId(), ip.getVlanGateway(), ip.getVlanNetmask(),
534-
ip.getVifMacAddress(), 2);
534+
ip.getVifMacAddress(), 2, false);
535535
if (result != null) {
536536
results[i++] = IpAssocAnswer.errorResult;
537537
} else {
@@ -1019,7 +1019,7 @@ public String assignPublicIpAddress(final String vmName,
10191019
final String privateIpAddress, final String publicIpAddress,
10201020
final boolean add, final boolean firstIP, final boolean sourceNat,
10211021
final String vlanId, final String vlanGateway,
1022-
final String vlanNetmask, final String vifMacAddress, int nicNum){
1022+
final String vlanNetmask, final String vifMacAddress, int nicNum, boolean newNic){
10231023

10241024
String args = "";
10251025
if (add) {
@@ -1043,6 +1043,11 @@ public String assignPublicIpAddress(final String vmName,
10431043

10441044
args +=" -g ";
10451045
args += vlanGateway;
1046+
1047+
if (newNic) {
1048+
args += " -n";
1049+
}
1050+
10461051
return routerProxy("ipassoc.sh", privateIpAddress, args);
10471052
}
10481053

‎patches/systemvm/debian/config/etc/init.d/cloud-early-config‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,46 @@ disable_hvc() {
366366
[ -d /proc/xen ] && sed -i 's/^#vc/vc/' /etc/inittab && telinit q
367367
}
368368

369+
enable_rpsrfs() {
370+
local enable=$1
371+
372+
if [ $eanble -eq 0]
373+
then
374+
echo 0 > /etc/rpsrfsenable
375+
return 0
376+
fi
377+
378+
if [ ! -f /sys/class/net/eth0/queues/rx-0/rps_cpus ]
379+
then
380+
echo "rps is not enabled in the kernel"
381+
echo 0 > /etc/rpsrfsenable
382+
return 0
383+
fi
384+
385+
proc=$(cat /proc/cpuinfo | grep "processor" | wc -l)
386+
if [ $proc -le 1 ]
387+
then
388+
echo 0 > /etc/rpsrfsenable
389+
return 0;
390+
fi
391+
392+
echo 1 > /etc/rpsrfsenable
393+
num=1
394+
num=$(($num<<$proc))
395+
num=$(($num-1));
396+
echo $num;
397+
hex=$(printf "%x\n" $num)
398+
echo $hex;
399+
#enable rps
400+
echo $hex > /sys/class/net/eth0/queues/rx-0/rps_cpus
401+
echo $hex > /sys/class/net/eth2/queues/rx-0/rps_cpus
402+
403+
#enble rps
404+
echo 256 > /proc/sys/net/core/rps_sock_flow_entries
405+
echo 256 > /sys/class/net/eth0/queues/rx-0/rps_flow_cnt
406+
echo 256 > /sys/class/net/eth2/queues/rx-0/rps_flow_cnt
407+
}
408+
369409
setup_common() {
370410
init_interfaces $1 $2 $3
371411
if [ -n "$ETH0_IP" ]
@@ -731,6 +771,7 @@ setup_router() {
731771
enable_svc cloud 0
732772
disable_rpfilter_domR
733773
enable_fwding 1
774+
enable_rpsrfs 1
734775
chkconfig nfs-common off
735776
cp /etc/iptables/iptables-router /etc/iptables/rules.v4
736777
#for old templates

‎patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh‎

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ add_first_ip() {
230230
sudo arping -c 1 -I $ethDev -A -U -s $ipNoMask $ipNoMask;
231231
sudo arping -c 1 -I $ethDev -A -U -s $ipNoMask $ipNoMask;
232232
fi
233-
add_routing $1
233+
add_routing $1
234234

235235
return 0
236236
}
@@ -277,7 +277,7 @@ add_an_ip () {
277277
sudo arping -c 1 -I $ethDev -A -U -s $ipNoMask $ipNoMask;
278278
sudo arping -c 1 -I $ethDev -A -U -s $ipNoMask $ipNoMask;
279279
fi
280-
add_routing $1
280+
add_routing $1
281281
return $?
282282

283283
}
@@ -303,11 +303,41 @@ remove_an_ip () {
303303
return 0
304304
}
305305

306+
enable_rpsrfs() {
307+
#enable rps and rfs for this new interface
308+
if [ -f /etc/rpsrfsenable ]
309+
then
310+
enable=$(cat /etc/rpsrfsenable)
311+
if [ $enable -eq 1 ]
312+
then
313+
proc=$(cat /proc/cpuinfo | grep "processor" | wc -l)
314+
if [ $proc -le 1 ]
315+
then
316+
return $status;
317+
fi
318+
319+
num=1
320+
num=$(($num<<$proc))
321+
num=$(($num-1));
322+
echo $num;
323+
hex=$(printf "%x\n" $num)
324+
echo $hex;
325+
#enable rps
326+
echo $hex > /sys/class/net/$ethDev/queues/rx-0/rps_cpus
327+
328+
#enable rfs
329+
echo 256 > /sys/class/net/$ethDev/queues/rx-0/rps_flow_cnt
330+
331+
fi
332+
fi
333+
}
334+
306335
#set -x
307336
sflag=0
308337
lflag=
309338
fflag=
310339
cflag=
340+
nflag=
311341
op=""
312342

313343
is_master=0
@@ -328,7 +358,7 @@ then
328358
if_keep_state=1
329359
fi
330360

331-
while getopts 'sfADa:l:c:g:' OPTION
361+
while getopts 'sfADna:l:c:g:' OPTION
332362
do
333363
case $OPTION in
334364
A) Aflag=1
@@ -350,6 +380,8 @@ do
350380
g) gflag=1
351381
defaultGwIP="$OPTARG"
352382
;;
383+
n) nflag=1
384+
;;
353385
?) usage
354386
unlock_exit 2 $lock $locked
355387
;;
@@ -370,6 +402,13 @@ then
370402
fi
371403

372404

405+
if [ "$Aflag" == "1" ] && [ "$nflag" == "1" ]
406+
then
407+
#enable rps, rfs for the new interface
408+
enable_rpsrfs
409+
410+
fi
411+
373412
if [ "$fflag" == "1" ] && [ "$Aflag" == "1" ]
374413
then
375414
add_first_ip $publicIp &&

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1922,19 +1922,21 @@ public Answer execute(IpAssocCommand cmd) {
19221922
int i = 0;
19231923
String result = null;
19241924
int nicNum = 0;
1925+
boolean newNic = false;
19251926
for (IpAddressTO ip : ips) {
19261927
if (!vlanAllocatedToVM.containsKey(ip.getVlanId())) {
19271928
/* plug a vif into router */
19281929
VifHotPlug(conn, routerName, ip.getVlanId(),
19291930
ip.getVifMacAddress());
19301931
vlanAllocatedToVM.put(ip.getVlanId(), nicPos++);
1932+
newNic = true;
19311933
}
19321934
nicNum = vlanAllocatedToVM.get(ip.getVlanId());
19331935
networkUsage(routerIp, "addVif", "eth" + nicNum);
19341936
result = _virtRouterResource.assignPublicIpAddress(routerName,
19351937
routerIp, ip.getPublicIp(), ip.isAdd(), ip.isFirstIP(),
19361938
ip.isSourceNat(), ip.getVlanId(), ip.getVlanGateway(),
1937-
ip.getVlanNetmask(), ip.getVifMacAddress(), nicNum);
1939+
ip.getVlanNetmask(), ip.getVifMacAddress(), nicNum, newNic);
19381940

19391941
if (result != null) {
19401942
results[i++] = IpAssocAnswer.errorResult;

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,10 @@ protected void assignPublicIpAddress(VirtualMachineMO vmMo, final String vmName,
17691769
args += " -g ";
17701770
args += vlanGateway;
17711771

1772+
if (addVif) {
1773+
args += " -n ";
1774+
}
1775+
17721776
if (s_logger.isDebugEnabled()) {
17731777
s_logger.debug("Run command on domain router " + privateIpAddress + ", /opt/cloud/bin/ipassoc.sh " + args);
17741778
}

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,11 @@ protected void assignPublicIpAddress(Connection conn, String vmName, String priv
23662366
args += " -g ";
23672367
args += vlanGateway;
23682368

2369+
if (addVif) {
2370+
//To indicate this is new interface created
2371+
args += " -n";
2372+
}
2373+
23692374

23702375
String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
23712376
if (result == null || result.isEmpty()) {

0 commit comments

Comments
 (0)