Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ebpfCAT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Teichmann
ebpfCAT
Commits
5c1f8ea6
Commit
5c1f8ea6
authored
2 years ago
by
Martin Teichmann
Browse files
Options
Downloads
Patches
Plain Diff
add some documentation
parent
cf5326c1
No related branches found
No related tags found
1 merge request
!13
fixed point arithmetic for ebpf
Pipeline
#98100
passed
2 years ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ebpfcat/ebpf.rst
+29
-12
29 additions, 12 deletions
ebpfcat/ebpf.rst
with
29 additions
and
12 deletions
ebpfcat/ebpf.rst
+
29
−
12
View file @
5c1f8ea6
...
...
@@ -68,9 +68,9 @@ we cannot use a Python ``if`` statement, as then the code actually does not
get executed, so no code would be generated. So we replace ``if`` statements
by Python ``with`` statements like so::
with self.some_variable > 6 as
cond
:
with self.some_variable > 6 as
Else
:
do_someting
with
cond.
Else
()
:
with Else:
do_something_else
certainly an ``Else`` statement may be omitted if not needed.
...
...
@@ -144,16 +144,33 @@ variables at the same time. So concurrent access may lead to problems. An
exception is the in-place addition operator `+=`, which works under a lock,
but only if the variable is of 4 or 8 bytes size.
Otherwise variables may be declared in all sizes. Additionally, one can mark
which variables are supposed to be written from user space to the EBPF,
as opposed to just being read. The declaration is like so::
Otherwise variables may be declared in all sizes. The declaration is like so::
class MyProgram(EBPF):
array_map = ArrayMap()
a_read_variable = array_map("B") # one byte read-only variable
a_write_variable = array_map("i", write=True) # a read-write integer
the array map has methods to access the variables:
.. autoclass:: ebpfcat.arraymap.ArrayMapAccess
:members:
a_byte_variable = array_map.globalVar("B")
an_integer_variable = array_map.globalVar("i")
those variables can be accessed both from within the ebpf program, as from
outside. Both sides are actually accessing the same memory, so be aware of
race conditions.
Fixed-point arithmetic
~~~~~~~~~~~~~~~~~~~~~~
as a bonus beyond standard ebpf, we support fixed-point values as a type `x`.
Within ebpf they are calculated as per-10000, so a 0.2 is represented as
20000. From outside, the variables seem to be doubles. Vaguely following
Python, all true divisions `/` result in a fixed-point result, while all
floor divisions `//` result in a standard integer. Some examples:
class FixedPoint(EPBF):
array_map = ArrayMap()
fixed_var = array_map.globalVar("x") # declare a fixed-point variable
normal_var = array_map.globalVar("i")
def program(self):
self.fixed_var = 3.5 # automatically converted to fixed
self.normal_var = self.fixed_var # automatically truncated
self.fixed_var = self.normal_var / 5 # keep decimals
self.fixed_var = self.normal_var // 5 # floor division
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment