Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
cdf8ac00
Commit
cdf8ac00
authored
May 05, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/Loop: integrate io_uring support
parent
62d0ceab
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
159 additions
and
0 deletions
+159
-0
Loop.cxx
src/event/Loop.cxx
+34
-0
Loop.hxx
src/event/Loop.hxx
+19
-0
UringManager.cxx
src/event/UringManager.cxx
+47
-0
UringManager.hxx
src/event/UringManager.hxx
+50
-0
meson.build
src/event/meson.build
+9
-0
No files found.
src/event/Loop.cxx
View file @
cdf8ac00
...
...
@@ -23,6 +23,12 @@
#include "DeferEvent.hxx"
#include "util/ScopeExit.hxx"
#ifdef HAVE_URING
#include "UringManager.hxx"
#include "util/PrintException.hxx"
#include <stdio.h>
#endif
EventLoop
::
EventLoop
(
ThreadId
_thread
)
:
SocketMonitor
(
*
this
),
/* if this instance is hosted by an EventThread (no ThreadId
...
...
@@ -43,6 +49,25 @@ EventLoop::~EventLoop() noexcept
assert
(
timers
.
empty
());
}
#ifdef HAVE_URING
Uring
::
Queue
*
EventLoop
::
GetUring
()
noexcept
{
if
(
!
uring_initialized
)
{
try
{
uring
=
std
::
make_unique
<
Uring
::
Manager
>
(
*
this
);
}
catch
(...)
{
fprintf
(
stderr
,
"Failed to initialize io_uring: "
);
PrintException
(
std
::
current_exception
());
}
}
return
uring
.
get
();
}
#endif
void
EventLoop
::
Break
()
noexcept
{
...
...
@@ -155,6 +180,15 @@ EventLoop::Run() noexcept
SocketMonitor
::
Schedule
(
SocketMonitor
::
READ
);
AtScopeExit
(
this
)
{
#ifdef HAVE_URING
/* make sure that the Uring::Manager gets destructed
from within the EventThread, or else its
destruction in another thread will cause assertion
failures */
uring
.
reset
();
uring_initialized
=
false
;
#endif
SocketMonitor
::
Cancel
();
};
...
...
src/event/Loop.hxx
View file @
cdf8ac00
...
...
@@ -38,6 +38,12 @@
#include <cassert>
#include <chrono>
#include "io/uring/Features.h"
#ifdef HAVE_URING
#include <memory>
namespace
Uring
{
class
Queue
;
class
Manager
;
}
#endif
/**
* An event loop that polls for events on file/socket descriptors.
*
...
...
@@ -82,6 +88,10 @@ class EventLoop final : SocketMonitor
boost
::
intrusive
::
constant_time_size
<
false
>>
DeferredList
;
DeferredList
deferred
;
#ifdef HAVE_URING
std
::
unique_ptr
<
Uring
::
Manager
>
uring
;
#endif
std
::
chrono
::
steady_clock
::
time_point
now
=
std
::
chrono
::
steady_clock
::
now
();
/**
...
...
@@ -108,6 +118,10 @@ class EventLoop final : SocketMonitor
*/
bool
busy
=
true
;
#ifdef HAVE_URING
bool
uring_initialized
=
false
;
#endif
PollGroup
poll_group
;
PollResult
poll_result
;
...
...
@@ -135,6 +149,11 @@ public:
return
now
;
}
#ifdef HAVE_URING
gcc_pure
Uring
::
Queue
*
GetUring
()
noexcept
;
#endif
/**
* Stop execution of this #EventLoop at the next chance. This
* method is thread-safe and non-blocking: after returning, it
...
...
src/event/UringManager.cxx
0 → 100644
View file @
cdf8ac00
/*
* Copyright 2003-2020 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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 2 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "UringManager.hxx"
#include "util/PrintException.hxx"
namespace
Uring
{
bool
Manager
::
OnSocketReady
(
unsigned
)
noexcept
{
try
{
DispatchCompletions
();
return
true
;
}
catch
(...)
{
PrintException
(
std
::
current_exception
());
return
false
;
}
}
void
Manager
::
OnIdle
()
noexcept
{
try
{
Submit
();
}
catch
(...)
{
PrintException
(
std
::
current_exception
());
}
}
}
// namespace Uring
src/event/UringManager.hxx
0 → 100644
View file @
cdf8ac00
/*
* Copyright 2003-2020 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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 2 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include "SocketMonitor.hxx"
#include "IdleMonitor.hxx"
#include "io/uring/Queue.hxx"
namespace
Uring
{
class
Manager
final
:
public
Queue
,
SocketMonitor
,
IdleMonitor
{
public
:
explicit
Manager
(
EventLoop
&
event_loop
)
:
Queue
(
1024
,
0
),
SocketMonitor
(
SocketDescriptor
::
FromFileDescriptor
(
GetFileDescriptor
()),
event_loop
),
IdleMonitor
(
event_loop
)
{
SocketMonitor
::
ScheduleRead
();
}
void
Push
(
struct
io_uring_sqe
&
sqe
,
Operation
&
operation
)
noexcept
override
{
AddPending
(
sqe
,
operation
);
IdleMonitor
::
Schedule
();
}
private
:
bool
OnSocketReady
(
unsigned
flags
)
noexcept
override
;
void
OnIdle
()
noexcept
override
;
};
}
// namespace Uring
src/event/meson.build
View file @
cdf8ac00
event_sources = []
if uring_dep.found()
event_sources += 'UringManager.cxx'
endif
event = static_library(
'event',
'PollGroupPoll.cxx',
...
...
@@ -15,10 +21,12 @@ event = static_library(
'Call.cxx',
'Thread.cxx',
'Loop.cxx',
event_sources,
include_directories: inc,
dependencies: [
boost_dep,
log_dep,
uring_dep,
],
)
...
...
@@ -29,5 +37,6 @@ event_dep = declare_dependency(
net_dep,
system_dep,
boost_dep,
uring_dep,
],
)
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