Skip to content

Instantly share code, notes, and snippets.

@djoreilly
Created January 5, 2017 12:09
Show Gist options
  • Save djoreilly/d036bae5dd9b5fd42d6c0db0faad069d to your computer and use it in GitHub Desktop.
Save djoreilly/d036bae5dd9b5fd42d6c0db0faad069d to your computer and use it in GitHub Desktop.
OVS DPDK helper utils
#!/usr/bin/python
import sys
try:
cpu_nums = [int(n) for n in list(sys.argv[1].split(','))]
except:
print "Print bitmask in bin and hex given a list of zero-indexed numbers"
print "Usage: %s cpu-list" % sys.argv[0]
print "e.g. %s 1,13" % sys.argv[0]
print "Bitmask 10000000000010 in hex is 0x2002"
sys.exit(1)
mask = 0
for n in cpu_nums:
m = 1
m = m << n
mask = mask | m
print "Bitmask {:b} in hex is 0x{:x}".format(mask, mask)
#!/usr/bin/python
import sys
try:
n = int(sys.argv[1], 16)
except:
print "List CPU cores from hex bitmask"
print "Usage: %s bitmask_in_hex" % sys.argv[0]
print "e.g. %s 0x2002" % sys.argv[0]
print "0x2002 is 10000000000010"
print "0 indexed cores: [1, 13]"
sys.exit(1)
print "0x{:x} is {:b}".format(n, n)
i = 0
psr_nums = []
while True:
if n == 0:
break;
if (n & 1) == 1:
psr_nums.append(i)
n = n >> 1
i += 1
print "0 indexed cores: %s" % psr_nums
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment