Skip to content

Instantly share code, notes, and snippets.

@achimnol
Created February 6, 2014 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achimnol/8839366 to your computer and use it in GitHub Desktop.
Save achimnol/8839366 to your computer and use it in GitHub Desktop.
10G Storage Network Start-up Script
#!/usr/bin/env python
# This script is written by Seonggu Huh & managed by Joongi Kim @ KAIST ANLAB.
import sys
import os
import subprocess
import time
def execute(cmd):
try:
proc = subprocess.Popen(cmd, shell = True, stdout = subprocess.PIPE)
return proc.communicate()[0]
except:
return None
def get_devices():
devs = []
result = execute('ifconfig -s').split('\n')
for line in result:
if 'eth' in line or 'xge' in line or 'bond' in line:
dev = line.split()[0]
devs.append(dev)
return devs
def get_driver(dev):
result = execute('ethtool -i %s' % (dev)).split('\n')
for line in result:
if 'driver' in line:
return line.split()[-1]
def_ring = {
'e1000e' : {'rx':4096, 'tx':4096},
'igb' : {'rx':4096, 'tx':4096},
'ixgbe' : {'rx':4096, 'tx':4096},
'bonding': {},
}
def_pause = {
'e1000e' : {'autoneg':'off', 'rx':'off', 'tx':'off'},
'igb' : {'autoneg':'off', 'rx':'off', 'tx':'off'},
'ixgbe' : {'autoneg':'off', 'rx':'off', 'tx':'off'},
'bonding': {},
}
def_offload = {
'e1000e' : {'rx':'on', 'tx':'on', 'sg':'on', 'tso':'on', 'gso':'on', 'gro':'on'},
'igb' : {'rx':'on', 'tx':'on', 'sg':'on', 'tso':'on', 'gso':'on', 'gro':'on'},
'ixgbe' : {'rx':'on', 'tx':'on', 'sg':'on', 'tso':'on', 'gso':'on', 'gro':'on', 'lro':'on'},
'bonding': {'tx':'on', 'sg':'on', 'tso':'on', 'gso':'on', 'gro':'on', 'lro':'on'},
}
if "__main__" == __name__:
total_cpu = int(execute('grep processor /proc/cpuinfo | wc -l'))
for dev in get_devices():
driver = get_driver(dev)
for mode in def_ring[driver]:
val = def_ring[driver][mode]
cmd = 'ethtool -G %s %s %d' % (dev, mode, val)
execute(cmd)
for mode in def_pause[driver]:
val = def_pause[driver][mode]
cmd = 'ethtool -A %s %s %s' % (dev, mode, val)
execute(cmd)
for mode in def_offload[driver]:
val = def_offload[driver][mode]
cmd = 'ethtool -K %s %s %s' % (dev, mode, val)
execute(cmd)
cmd = 'grep %s- /proc/interrupts' % (dev)
irq_list = execute(cmd).strip().split('\n')
for line in irq_list:
l = line.strip().split()
if len(l):
irq = int(l[0][:-1])
cpu = int(l[-1].split('-')[-1])
cmd = 'echo %x > /proc/irq/%d/smp_affinity' % (1 << cpu, irq)
execute(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment