Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lisa Casino
slapos.core
Commits
fc204fb0
Commit
fc204fb0
authored
Jun 06, 2017
by
Tomáš Peterka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove moved PIDs to exclusive CPUs from the request file
parent
fab6f2fc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
16 deletions
+20
-16
slapos/format.py
slapos/format.py
+13
-11
slapos/tests/slapformat.py
slapos/tests/slapformat.py
+7
-5
No files found.
slapos/format.py
View file @
fc204fb0
...
...
@@ -317,11 +317,6 @@ class CGroupManager(Manager):
We expect PIDs which require own CPU to be found in ~instance/.slapos-cpu-exclusive
"""
request_pid_set
=
set
()
# gather requests from all instances
for
request_file
in
glob
.
iglob
(
os
.
path
.
join
(
self
.
instance_root
,
'*'
,
CGroupManager
.
cpu_exclusive_file
)):
with
open
(
request_file
,
"rt"
)
as
fi
:
request_pid_set
.
update
(
map
(
int
,
fi
.
read
().
split
()))
cpu_list
=
self
.
_cpu_list
()
generic_cpu
=
cpu_list
[
0
]
exclusive_cpu_list
=
cpu_list
[
1
:]
...
...
@@ -339,12 +334,19 @@ class CGroupManager(Manager):
with
open
(
os
.
path
.
join
(
self
.
cpuset_path
,
"cpu"
+
str
(
exclusive_cpu
),
"tasks"
),
"rt"
)
as
fi
:
exclusive_pid_set
.
update
(
map
(
int
,
fi
.
read
().
split
()))
for
request
in
request_pid_set
:
if
request
in
exclusive_pid_set
:
continue
# already exclusive
if
request
not
in
running_pid_set
:
continue
# stale PID which is not running anywhere
self
.
_move_to_exclusive_cpu
(
request
)
for
request_file
in
glob
.
iglob
(
os
.
path
.
join
(
self
.
instance_root
,
'*'
,
CGroupManager
.
cpu_exclusive_file
)):
with
open
(
request_file
,
"rt"
)
as
fi
:
# take such PIDs which are either really running or are not already exclusive
request_pid_list
=
[
int
(
pid
)
for
pid
in
fi
.
read
().
split
()
if
int
(
pid
)
in
running_pid_set
or
int
(
pid
)
not
in
exclusive_pid_set
]
with
open
(
request_file
,
"wt"
)
as
fo
:
fo
.
write
(
""
)
# empty file (we will write back only PIDs which weren't moved)
for
request_pid
in
request_pid_list
:
assigned_cpu
=
self
.
_move_to_exclusive_cpu
(
request_pid
)
if
assigned_cpu
<
0
:
# if no exclusive CPU was assigned - write the PID back and try other time
with
open
(
request_file
,
"at"
)
as
fo
:
fo
.
write
(
str
(
request_pid
)
+
"
\
n
"
)
def
prepare_cpu_space
(
self
):
"""Move all PIDs from the pool of all CPUs into the first exclusive CPU."""
...
...
slapos/tests/slapformat.py
View file @
fc204fb0
...
...
@@ -189,7 +189,7 @@ class CGroupManagerMock(slapos.format.CGroupManager):
cpuset_path
=
"/tmp/cpuset/"
task_write_mode
=
"at"
# append insted of write tasks PIDs for the tests
def
allowed
(
self
):
def
is_
allowed
(
self
):
"""Always allowed."""
return
True
...
...
@@ -734,14 +734,16 @@ class TestComputerWithCGroup(SlapformatMixin):
file_write
(
""
,
os
.
path
.
join
(
CGroupManagerMock
.
cpuset_path
,
"tasks"
))
# test moving tasks from generic core to private core
# request PID 1001 to be moved to its private CPU
file_write
(
"1001
\
n
"
,
os
.
path
.
join
(
self
.
computer
.
partition_list
[
0
].
path
,
CGroupManagerMock
.
cpu_exclusive_file
)
)
request_file_path
=
os
.
path
.
join
(
self
.
computer
.
partition_list
[
0
].
path
,
CGroupManagerMock
.
cpu_exclusive_file
)
file_write
(
"1001
\
n
"
,
request_file_path
)
# let format do the moving
self
.
computer
.
update
()
# test if the moving suceeded into any provate CPUS (id>0)
self
.
assertTrue
(
any
(
"1001"
in
file_content
(
exclusive_task
)
for
exclusive_task
in
glob
.
glob
(
os
.
path
.
join
(
CGroupManagerMock
.
cpuset_path
,
"cpu[1-9]"
,
"tasks"
))))
# slapformat should remove successfully moved PIDs from the .slapos-cpu-exclusive file
self
.
assertEqual
(
""
,
file_content
(
request_file_path
).
strip
())
class
TestPartition
(
SlapformatMixin
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment