-
Notifications
You must be signed in to change notification settings - Fork 17
/
tasks_redirect_generic.sh
executable file
·128 lines (105 loc) · 2.88 KB
/
tasks_redirect_generic.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr//bin/env bash
LAUNCHER="lutris" # replace if not using lutris, ie. "steam"
create_ranges() {
local input=$1
local output_var=$2
IFS=',' read -r -a core_array <<< "$input"
sorted_corenums=($(printf "%s\n" "${core_array[@]}" | sort -n))
local ranges=""
local flr=""
local ceil=""
for n in "${sorted_corenums[@]}"; do
if [[ -z "$flr" ]]; then
flr="$n"
elif (( n - 1 == ceil )); then
ceil="$n"
else
if [[ -n "$ranges" ]]; then
ranges+=","
fi
ranges+="$flr-$ceil"
flr="$n"
fi
ceil="$n"
done
if [[ -n "$flr" ]]; then
if [[ -n "$ranges" ]]; then
ranges+=","
fi
ranges+="$flr-$ceil"
fi
eval "$output_var='$ranges'"
}
read cores0 cores1 < <(lstopo-no-graphics | perl -ne '
if ( /L3/ ) {
chop $result if $result;
$result .= " " if $result;
} elsif ( /\(P#(\d+)\)/ ) {
$result .= "$1,";
}
END {
chop $result;
print $result;
}'
)
create_ranges $cores0 CCX0 2>/dev/null
create_ranges $cores1 CCX1 2>/dev/null
if [[ -z $CCX0 || -z $CCX1 ]]; then
echo "Aborted! Only 1 CCX found."
exit 1
fi
echo "Found core P#s:"
echo -e "\tCCX0: $CCX0"
echo -e "\tCCX1: $CCX1"
echo "Mounting the cpuset filesystem"
if ! [[ -d /dev/cpuset ]]; then
mkdir /dev/cpuset
mount -t cpuset cpuset /dev/cpuset
fi
_prefix=""
if [[ -f /dev/cpuset/cpuset.cpus ]];then
_prefix="cpuset."
fi
if ! [[ -d /dev/cpuset/theUgly ]]; then
echo "Creating theUgly"
mkdir /dev/cpuset/theUgly
fi
echo "Assigning CCX0's cores to theUgly cpu set"
/bin/echo $CCX0 > /dev/cpuset/theUgly/${_prefix}cpus
echo "Giving theUgly memory node 0"
/bin/echo 0 > /dev/cpuset/theUgly/${_prefix}mems
echo "Making theUgly cpu exclusive"
/bin/echo 1 > /dev/cpuset/theUgly/${_prefix}cpu_exclusive
echo "Redirecting all processes to theUgly"
success=0
fail=0
while read p; do
/bin/echo $p > /dev/cpuset/theUgly/tasks && ((success++)) || ((fail++))
done < /dev/cpuset/tasks 2>/dev/null
echo -e "\t$success processes successfully redirected."
echo -e "\t$fail processes failed to redirect."
if ! [[ -d /dev/cpuset/theGood ]]; then
echo "Creating theGood"
mkdir /dev/cpuset/theGood
fi
echo "Assigning CCX1's cores to theGood cpu set"
/bin/echo $CCX1 > /dev/cpuset/theGood/${_prefix}cpus
echo "Giving theGood memory node 0"
/bin/echo 0 > /dev/cpuset/theGood/${_prefix}mems
echo "Making theGood cpu exclusive"
/bin/echo 1 > /dev/cpuset/theGood/${_prefix}cpu_exclusive
read -p "Redirect $LAUNCHER to theGood? y/n: "
if [[ "$REPLY" == "y" ]]; then
success=0
fail=0
while read p; do
/bin/echo $p > /dev/cpuset/theGood/tasks && ((success++)) || ((fail++))
done < <(pgrep $LAUNCHER)
if (( success > 0 )); then
echo -e "\t$success $LAUNCHER process(es) successfully redirected."
elif (( fail > 0 )); then
echo -e "\t$fail $LAUNCHER process(es) failed to redirect."
else
echo -e "\tNo $LAUNCHER processes found."
fi
fi