-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed and refactored the code #2
Open
freysteinn
wants to merge
6
commits into
xdp-project:master
Choose a base branch
from
freysteinn:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e1a5fe0
Added shebang and keyword arguments
freysteinn f23005b
Split pifo-basic into pifo_fifo and pifo_stfq
freysteinn 7f338c2
Refactored framework and added a FIFO and SRPT
freysteinn 0f1602f
Added scheduling algorithms STFQ and WFQ
freysteinn 145b33d
Added missing older meeting slides
freysteinn 1d341c1
Added the HPFQ scheduler and reference scheduling
freysteinn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,15 @@ | |
# | ||
# pifo-stfq.py | ||
|
||
"""Start-Time Fair Queuing (STFQ) | ||
|
||
This scheduling algorithm is mentioned in the paper "Programmable packet | ||
scheduling at line rate" by Sivaraman, Anirudh, et al. | ||
|
||
It schedules packets by their start time within a flow. It defines the start | ||
time as the finish time of the last enqueued packet within a flow. | ||
""" | ||
|
||
__copyright__ = """ | ||
Copyright (c) 2021 Toke Høiland-Jørgensen <[email protected]> | ||
Copyright (c) 2021 Frey Alfredsson <[email protected]> | ||
|
@@ -26,23 +35,39 @@ | |
""" | ||
|
||
from pifo_lib import Packet, Runner, Pifo | ||
from pifo_lib import SchedulingAlgorithm | ||
|
||
|
||
class Stfq(SchedulingAlgorithm): | ||
"""Start-Time Fair Queuing (STFQ)""" | ||
|
||
class Stfq(Pifo): | ||
def __init__(self): | ||
super().__init__() | ||
self.last_finish = {} | ||
self.virt_time = 0 | ||
self._pifo = Pifo() | ||
|
||
self._last_finish = {} | ||
self._virt_time = 0 | ||
|
||
def get_rank(self, pkt): | ||
flow = pkt.flow | ||
if flow in self.last_finish: | ||
rank = max(self.virt_time, self.last_finish[flow]) | ||
flow_id = pkt.flow | ||
if flow_id in self._last_finish: | ||
rank = max(self._virt_time, self._last_finish[flow_id]) | ||
else: | ||
rank = self.virt_time | ||
self.last_finish[flow] = rank + pkt.length | ||
rank = self._virt_time | ||
self._last_finish[flow_id] = rank + pkt.length | ||
return rank | ||
|
||
def enqueue(self, item): | ||
rank = self.get_rank(item) | ||
self._pifo.enqueue(item, rank) | ||
|
||
def dequeue(self): | ||
return self._pifo.dequeue() | ||
|
||
def dump(self): | ||
self._pifo.dump() | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
pkts = [ | ||
Packet(flow=1, idn=1, length=2), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env python3 | ||
# coding: utf-8 -*- | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
# pifo-wfq.py | ||
|
||
"""Weighted Fair Queueing (WFQ) | ||
|
||
This scheduling algorithm is mentioned in the paper "Programmable packet | ||
scheduling at line rate" by Sivaraman, Anirudh, et al. It schedules flows by | ||
giving them a fraction of the capacity using predefined weights. In our example, | ||
we defined flows with an odd number to get a weight of 50 and even numbers to | ||
get 100. | ||
""" | ||
|
||
__copyright__ = """ | ||
Copyright (c) 2021 Toke Høiland-Jørgensen <[email protected]> | ||
Copyright (c) 2021 Frey Alfredsson <[email protected]> | ||
""" | ||
|
||
__license__ = """ | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
|
||
from pifo_lib import Packet, Runner, Pifo | ||
from pifo_lib import SchedulingAlgorithm | ||
|
||
|
||
class Wfq(SchedulingAlgorithm): | ||
"""Weighted Fair Queueing (WFQ)""" | ||
|
||
def __init__(self): | ||
self._pifo = Pifo() | ||
self._last_finish = {} | ||
self._virt_time = 0 | ||
|
||
def get_rank(self, pkt): | ||
flow = pkt.flow | ||
weight = 50 if flow % 2 == 1 else 100 | ||
if flow in self._last_finish: | ||
rank = max(self._virt_time, self._last_finish[flow]) | ||
else: | ||
rank = self._virt_time | ||
self._last_finish[flow] = rank + pkt.length / weight | ||
return rank | ||
|
||
def enqueue(self, item): | ||
rank = self.get_rank(item) | ||
self._pifo.enqueue(item, rank) | ||
|
||
def dequeue(self): | ||
return self._pifo.dequeue() | ||
|
||
def dump(self): | ||
self._pifo.dump() | ||
|
||
|
||
if __name__ == "__main__": | ||
pkts = [ | ||
Packet(flow=1, idn=1, length=100), | ||
Packet(flow=1, idn=2, length=100), | ||
Packet(flow=1, idn=3, length=100), | ||
Packet(flow=2, idn=1, length=100), | ||
Packet(flow=2, idn=2, length=100), | ||
Packet(flow=2, idn=3, length=100), | ||
] | ||
Runner(pkts, Wfq()).run() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So "WFQ" is really "STFQ + weights", right? So why not just make this a subclass of Stfq (or just straight-up add the weights as an optional feature to the Stfq class itself)? Also, the commit message that adds this is a bit misleading: it says it's "adding" stfq, when it's really just changing the implementation to use the SchedulingAlgorithm class; so better make that a separate commit, then add the weights as a separate thing. (The github review interface is terrible in that it won't let me comment on the commit message, so just sticking that in here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree. It's terrible not to be able to comment on specific commits. Maybe I should also try to make more PR instead to make it more clear.
I agree it's not that much of a change to warrant the new name. I did this because the PIFO paper and examples talk about them separately, even though they look pretty much the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's OK to keep them separate if you think that makes things clearer; but then make the relationship between them explicit; i.e., add an
update_last_finish(flow, rank, pkt)
method to stfq and make WFQ be a subclass of STFQ that only overrides that one method...