[Music]
hello everyone welcome back um and
welcome to our first talk of today's
colonel miniconf
uh andre almeida is a linux kernel
hacker at calabra where he's
investigating how to make game runs
faster and better in a free and open
stack
and today he'll be talking to us about
the current uh the futex2 syscall
and the
different approaches
that
he has been taking so far to overcome
the limitations of the current futex
syscall uh please welcome andre
thank you very much good morning
australia um so yeah i'm andrea ameda
i'm internal developer collabora and i'm
based in brazil there is a place very
far away from australia
but it's a pleasure to be back here
and um yeah today i want to talk about
this project that i have been working
for
quite some time now that is the futex2
but for of course i will explain what is
futex
why
is this
why do we need a new physics
uh what i have done so far and what is
left
so um
futex is a cisco of on linux uh is used
for creating
uh sync primitives uh like mutexes so
for instance bitrate mutex
uses few texts behind to be implemented
and it's something that we uh expose
user space so you can create create
these fast prim chips
and uh and giving that is used by p
threads you you can imagine that is
something that is called very often if
you are using any mood straight
application right now for sure you are
running a thousand few texts you can s
trace your browser to to see the imaging
happening
and uh
so and the the kernel interface is very
very simple is basically a way to sleep
and weak threats
and all the logic needs to be done in
user space
and here is like a
kind of a visual explanation of how the
syscall works
so imagine that this thread over here
is like uh waiting
it got the lock it got the mutex lock
so it's here in user space doing a lot
of work so here we have two threads and
this is the times flows on that
direction here
and this thread is happy in this space
with the lock taken doing a lot of work
and then in the meanwhile this right
here tries to get the lock
but the lock is taken so it needs to
slip
so what we do what bitrate does here it
will issue a few text weight call so you
wait on
user space address this is kind the id
of
the mutexes
so you just wait on uh on this address
here until some something wake you up
and then you go to the kernel you do
some initial um
work and then the kernel call is caddo
so uh the kernel the pro the processor
can do something useful while you are
waiting to get this
uh
lock
free
and at the meanwhile
uh we can uh let's say here that this
user space red finished the work
and that after finishing the work you
want to to give the lock to someone else
and then the user space called uh
do a few text call using the awake
operation so we get back to the kernel
we look up if is there anyone really
waiting at this address and we find
someone you we should wake up call
and then this thread get back to the uh
get back to user space and can finally
do the work so this is a very basic
overview
of what is futex and
this
i said a lot about mutex but this can be
used for barriers semaphores for a lot
of sync primitives
okay
and uh but why do we need a new futex
api so uh along the years developers
have uh
seen some limitations of how uh the
of of the few takes uh cisco uh i will
go on all those limitations in some
units but basically the problem that we
have been we have been facing is that we
we wanted to add new features to the
futex cisco but the futexis call is kind
of
multiplexed and strange
interface i mean look at this uh we have
all those arguments and
they're going uh it needs to be very
generic so documents have strange names
like this is just fall this is a timeout
but sometimes can be evolved two and we
have voltry here so this uh was made to
uh
use a lot of different um operations
you can check the main page for
all the crazy things that it can be done
there and every time
people wanted to add the new uh
operations
the maintainers didn't really wanted to
to get this in the kernel because
it's kind of hard to maintain that
yes it's it's very tricky to to maintain
that code
so uh
and then
i wanted to add a new us
operation to the cisco that is the
ability to wait on multiple full texts
at the same time because on the old
interface we could just want on a single
one
and then they told me hey if you want to
do that you need to develop this
interface for that
and here we are here and now we have
this this project that we call for
texture that is to try to discover how
these new interfaces look like
and and
to get all those new features that we
want on this new interface
so the first of all uh weight on
multiple full taxes as i said before
so uh you basically wait on multiple
taxes and
if some food tax triggers awake you just
wake up
and this
operation can be found on other
operation systems like windows
so this is very similar to
wait for much objects from windows api
and uh
all of these
work has been based on
to be used on stream proton so stream
proton is a compatibility layer that
allows you to run windows games on linux
and
linux didn't have a proper way to do
that
to wait for multiple things at the same
time and
i mean we had we have like event ft that
can be used for that but
uh on a very large number of waiters it
doesn't scale very well
and we find out that few takes sweets
better for that
so we
at the bottom we we call this the this
is called two way to move texas to map
to this windows function and what we saw
is that not always we you can like
increase the frame heater for game but
almost always you can decrease the cpu
utilization
or the kernel load that you need to
to use to to wait for those objects
and thus
usually
we can
decrease the power usage and if it's
like a portable device we can probably
decrease the battery usage
and use better the resource of your
machine
and this
function was merged on the current that
was released
on these
this weekend 5 16.
and uh we
uh basically merged a new syscall for
that so all those new operations they
will come
via uh new cisco's
and few tax return was just the first of
it so you can happily use it right now
and another interesting user case that
people have been wanting to use
on futex is variable sizes because
the current interface can only
use 32-bit values
so
you need to use a pointer
to utter 2-bit
integer
but
a lot of
there are some very interesting user
case that once you use variable size for
taxes and people from the boost library
from the c plus plus liberty boost they
wanted to choose support variable size
for texas so they can create user space
atomic operations on top of that and
also if you have uh
six four bits
for taxes you can like wait on a pointer
value
so these will come with new the new
new syscalls and you'll be able to wait
to operate on those four different sizes
and uh also
a big problem of
futex right now for really big
uh cloud
enterprise machines is the lack of lumen
awareness so
on full text when you get into
when you want to wait on some address
you need to
get on
on a global hash table and you'll be
assigned to a bucket
so for instance here we have a bunch of
threads waiting for different addresses
and each one we get in a different you
can have threads in the different
different buckets
uh but the problem is that uh well in us
if you have a
non-numa machine you have no problem you
have just your hash table there and
everything's fine but you have another
machine this global hash table will be
assigned to a single node
and basically that means that every
other node will have a penalty to
access this hash table
so that means that every fuel text
operation that happens
outside of the cpu will take a little
longer
and uh and yeah
this can have a very strong performance
impact
on some really big machines
so this is like the
a big main point of a few texts and this
is something that we would like to solve
on this new interface
so
basically what is left now is to figure
out the numeral syntax so we can
this i think this is the only piece
remaining to get uh
the new syscalls uh
sent to the melodies you should figure
out how should be these numa syntax so
what we have right now is that you send
you to the operation a flag called futex
number flag
and then
instead of using uh
just a plain user space address you will
point to a stretch where you have here
on the first place
the interior
like the the view text address and then
i think that it can be used to
specify which node you will want to
operate
so the value is just the respective
value of the field text and the hint can
be like
zero to maximum nodes to just so you can
specify which noma node you can operate
on
or you can use just -1 to say that you
want to operate on the current node
so but we're not sure yet if this
makes sense
for
the luma applications the new avengers
so this is like a research step that i
i'm doing right now to and talk to
two people that
needs these user case to to figure out
if this is really a match for what they
are looking for
uh but yeah i think that's it this is
uh the states of futex
so now i can have questions
um
please put your questions if you have
any in the
venulis
questions tab
okay so we have our first question
that is one of the cool things that you
can do with windows wait for much
objects
is wait for a mutex at the same time as
an io result for example is there any
plan to get fuel text notification
through
people
nope there's no such plane right now
because
[Music]
few texts and file descriptors
did work
well in the past
um
well it's kind of
tricky to explain but um
well maybe i can revis revisit this talk
but uh i'm not sure it's like would you
be able to
[Music]
um
wait on the few texts using the file
descriptor
or it's like waiting on
when did you get the
the end of the i o
operation
i'm not sure how would be this um
the syntax
and
so will few texts you support real time
priority awareness
this is something that we we had
sketches as well but because uh
basically the the biggest pain point of
a few takes in real time
is that uh
on the that hash table
you can have a lot of conflicts
and uh
you are you can be sure from the user
space side how many conflicts will have
and each conflict increases your time to
complete the operation
a few things have been proposed proposed
in the past
like
each process would have its own hash
table so in this way you can like re
reduce a lot of your unhash collision
but from
my plumber session this wasn't
a issue or i mean this hasn't been
discussed in the game but yeah it's a
very nice question about
how we can
get this
uh real-time
awareness
but yeah
we don't have any planes right now but
of course this should be
uh disgusted again
um and another question other than
proton do you have other expected use
cases for written only taxes well i know
that some
game engines
wants to use these as well
and the
the boost library
people also told me that they have
some kind of mass locking api that could
benefit from this as well
uh but yeah basically this is a very
common
load pattern for games to
do a bunch of work and wait for
wait for everything to get complete to
go for the next frame stuff like that
so basically it's a round game
are there any performance issues with
the new syscall
no no not really
the new syscall
basically is
kind of a front end for
the current full text code so yeah the
performance is very similar the
performance of this operation is very
similar
of the other few text operations
can we avoid spurious wake ups with few
texts too
um
well
i don't think so as well because
uh
to avoid that you would need to
really have the kernel involved for when
the
uncontained
case you know if you
if the the lock is free we will need to
talk to the kernel anyway
uh but yeah it's this is
uh we can't avoid that with texture it's
not something that we resolve it if we
for design
and yeah importantly
you will need to to wake up the thread
and the thread you need to to fight for
the mutex and it can lose it can get
back to to the kernel and this is really
kind to the design of of how few texts
work
so yeah we can't afford we can't avoid
that
but as far as i know it's
um
spruce wake ups are not like
a very big concern
on the performance side
um
disk text yes
[Music]
if alison is asking if futex will
support pi priority inheritance
we
using the recent added kernel flex
so uh
so far no so far
no one from no one proposed that i use a
case that would mix it
this pneuma winners and this
variable size it
for texas with
pi
so i don't think so
uh yeah well
it seems that people have a lot of
good ideas about what we can do with
footage and basically
this talk is of course is like a
status of how
this project is going on but it's also
for really to listen to
those ideas that uh people
want to have on the api
so yeah thank you very much
i will take all of this xena into
account
uh yeah let's see maybe next year
i will come back with
these all those cool operation netflix
andrew i don't think we have
more questions
i
don't see any more questions so i think
that might be it
um thank you very much andre thank you
for a great talk
thank you um
we will now be going to a break uh the
next talk will be by paul mckenny uh
about uh torturing rcu
and that will be at 11 30 which is in
uh 17 minutes
see you then