Last change
on this file since 20 was
20,
checked in by tim, 9 years ago
|
major code refactoring, better organizing location of library functions
|
File size:
1.5 KB
|
Rev | Line | |
---|
[20] | 1 | |
---|
| 2 | import multiprocessing |
---|
| 3 | |
---|
| 4 | def setCPUAffinity(): |
---|
| 5 | from ctypes import cdll,c_int,byref |
---|
| 6 | cpus = multiprocessing.cpu_count() |
---|
| 7 | |
---|
| 8 | libc = cdll.LoadLibrary("libc.so.6") |
---|
| 9 | #libc.sched_setaffinity(os.getpid(), 1, ctypes.byref(ctypes.c_int(0x01))) |
---|
| 10 | return libc.sched_setaffinity(0, 4, byref(c_int(0x00000001<<(cpus-1)))) |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | def setTCPTimestamps(enabled=True): |
---|
| 14 | fh = open('/proc/sys/net/ipv4/tcp_timestamps', 'r+b') |
---|
| 15 | ret_val = False |
---|
| 16 | if fh.read(1) == b'1': |
---|
| 17 | ret_val = True |
---|
| 18 | |
---|
| 19 | fh.seek(0) |
---|
| 20 | if enabled: |
---|
| 21 | fh.write(b'1') |
---|
| 22 | else: |
---|
| 23 | fh.write(b'0') |
---|
| 24 | fh.close() |
---|
| 25 | |
---|
| 26 | return ret_val |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | previous_governors = None |
---|
| 30 | def setPowersave(enabled): |
---|
| 31 | global previous_governors |
---|
| 32 | cpus = multiprocessing.cpu_count() |
---|
| 33 | if enabled: |
---|
| 34 | if previous_governors == None: |
---|
| 35 | previous_governors = [b"powersave"]*cpus |
---|
| 36 | new_governors = previous_governors |
---|
| 37 | else: |
---|
| 38 | new_governors = [b"performance"]*cpus |
---|
| 39 | |
---|
| 40 | previous_governors = [] |
---|
| 41 | for c in range(cpus): |
---|
| 42 | fh = open('/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor' % c, 'r+b') |
---|
| 43 | previous_governors.append(fh.read()) |
---|
| 44 | fh.seek(0) |
---|
| 45 | fh.write(new_governors[c]) |
---|
| 46 | fh.close() |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | def setLowLatency(enabled): |
---|
| 50 | fh = open('/proc/sys/net/ipv4/tcp_low_latency', 'r+b') |
---|
| 51 | ret_val = False |
---|
| 52 | if fh.read(1) == b'1': |
---|
| 53 | ret_val = True |
---|
| 54 | |
---|
| 55 | fh.seek(0) |
---|
| 56 | if enabled: |
---|
| 57 | fh.write(b'1') |
---|
| 58 | else: |
---|
| 59 | fh.write(b'0') |
---|
| 60 | fh.close() |
---|
| 61 | |
---|
| 62 | return ret_val |
---|
| 63 | |
---|
Note: See
TracBrowser
for help on using the repository browser.