Skip to content

Commit d040ed4

Browse files
committed
Change submit_and_wait to take ink_hrtime. Fix test_AIO for io_uring.
update test_AIO to add io_uring config. Fix missing include and submissions metric. refix traffic_via test
1 parent 4164fa3 commit d040ed4

File tree

11 files changed

+135
-19
lines changed

11 files changed

+135
-19
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,4 @@ add_subdirectory(mgmt/utils)
183183
add_subdirectory(mgmt/config)
184184
add_subdirectory(mgmt/rpc)
185185
add_subdirectory(src/traffic_server)
186+
add_subdirectory(src/tests)

iocore/aio/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
add_library(aio)
2020
target_sources(aio PRIVATE AIO.cc Inline.cc)
2121
target_include_directories(aio PRIVATE ${CMAKE_SOURCE_DIR}/iocore/eventsystem ${CMAKE_SOURCE_DIR}/iocore/io_uring)
22+

iocore/aio/sample.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ write_skip 5
1414
chains 1
1515
delete_disks 1
1616
disk_path ./aio.tst
17+
io_uring_queue_entries 32
18+
num_processors 1
1719

iocore/aio/test_AIO.cc

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ int threads_per_disk = 1;
7171
int delete_disks = 0;
7272
int max_size = 0;
7373
int use_lseek = 0;
74+
int num_processors = 0;
75+
#if AIO_MODE == AIO_MODE_IO_URING
76+
int io_uring_queue_entries = 32;
77+
int io_uring_sq_poll_ms = 0;
78+
int io_uring_attach_wq = 0;
79+
int io_uring_wq_bounded = 0;
80+
int io_uring_wq_unbounded = 0;
81+
#endif
7482

7583
int chains = 1;
7684
double seq_read_percent = 0.0;
@@ -210,6 +218,14 @@ dump_summary()
210218
printf("%0.2f total mbytes/sec\n", sr + sw + rr);
211219
printf("----------------------------------------------------------\n");
212220

221+
#if AIO_MODE == AIO_MODE_IO_URING
222+
printf("-----------------\n");
223+
printf("IO_URING results\n");
224+
printf("-----------------\n");
225+
printf("submissions: %lu\n", io_uring_submissions.load());
226+
printf("completions: %lu\n", io_uring_completions.load());
227+
#endif
228+
213229
if (delete_disks) {
214230
for (int i = 0; i < n_disk_path; i++) {
215231
unlink(disk_path[i]);
@@ -375,6 +391,14 @@ read_config(const char *config_filename)
375391
PARAM(chains)
376392
PARAM(threads_per_disk)
377393
PARAM(delete_disks)
394+
PARAM(num_processors)
395+
#if AIO_MODE == AIO_MODE_IO_URING
396+
PARAM(io_uring_queue_entries)
397+
PARAM(io_uring_sq_poll_ms)
398+
PARAM(io_uring_attach_wq)
399+
PARAM(io_uring_wq_bounded)
400+
PARAM(io_uring_wq_unbounded)
401+
#endif
378402
else if (strcmp(field_name, "disk_path") == 0)
379403
{
380404
assert(n_disk_path < MAX_DISK_THREADS);
@@ -405,16 +429,64 @@ read_config(const char *config_filename)
405429
return (1);
406430
}
407431

432+
#if AIO_MODE == AIO_MODE_IO_URING
433+
434+
class IOUringLoopTailHandler : public EThread::LoopTailHandler
435+
{
436+
public:
437+
int
438+
waitForActivity(ink_hrtime timeout) override
439+
{
440+
IOUringContext::local_context()->submit_and_wait(timeout);
441+
442+
return 0;
443+
}
444+
/** Unblock.
445+
446+
This is required to unblock (wake up) the block created by calling @a cb.
447+
*/
448+
void
449+
signalActivity() override
450+
{
451+
}
452+
453+
~IOUringLoopTailHandler() override {}
454+
} uring_handler;
455+
456+
#endif
457+
408458
int
409459
main(int /* argc ATS_UNUSED */, char *argv[])
410460
{
411461
int i;
462+
printf("input file %s\n", argv[1]);
463+
if (!read_config(argv[1])) {
464+
exit(1);
465+
}
466+
if (num_processors == 0) {
467+
num_processors = ink_number_of_processors();
468+
}
469+
printf("Using %d processor threads\n", num_processors);
470+
471+
#if AIO_MODE == AIO_MODE_IO_URING
472+
{
473+
IOUringConfig cfg;
474+
475+
cfg.queue_entries = io_uring_queue_entries;
476+
cfg.sq_poll_ms = io_uring_sq_poll_ms;
477+
cfg.attach_wq = io_uring_attach_wq;
478+
cfg.wq_bounded = io_uring_wq_bounded;
479+
cfg.wq_unbounded = io_uring_wq_unbounded;
480+
481+
IOUringContext::set_config(cfg);
482+
};
483+
#endif
412484

413485
Layout::create();
414486
init_diags("", nullptr);
415487
RecProcessInit();
416488
ink_event_system_init(EVENT_SYSTEM_MODULE_PUBLIC_VERSION);
417-
eventProcessor.start(ink_number_of_processors());
489+
eventProcessor.start(num_processors);
418490

419491
Thread *main_thread = new EThread;
420492
main_thread->set_specific();
@@ -425,14 +497,15 @@ main(int /* argc ATS_UNUSED */, char *argv[])
425497
et->schedule_imm(et->diskHandler);
426498
}
427499
#endif
500+
#if AIO_MODE == AIO_MODE_IO_URING
501+
for (EThread *et : eventProcessor.active_group_threads(ET_NET)) {
502+
et->set_tail_handler(&uring_handler);
503+
}
504+
#endif
428505

429506
RecProcessStart();
430507
ink_aio_init(AIO_MODULE_PUBLIC_VERSION);
431508
ts::Random::seed(time(nullptr));
432-
printf("input file %s\n", argv[1]);
433-
if (!read_config(argv[1])) {
434-
exit(1);
435-
}
436509

437510
max_size = seq_read_size;
438511
if (seq_write_size > max_size) {
@@ -466,7 +539,12 @@ main(int /* argc ATS_UNUSED */, char *argv[])
466539
}
467540

468541
while (!TSSystemState::is_event_system_shut_down()) {
542+
#if AIO_MODE == AIO_MODE_IO_URING
543+
IOUringContext::local_context()->submit_and_wait(1 * HRTIME_SECOND);
544+
#else
469545
sleep(1);
546+
#endif
470547
}
548+
471549
delete main_thread;
472550
}

iocore/io_uring/I_IO_URING.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Linux io_uring helper library
2525

2626
#include <liburing.h>
2727
#include <utility>
28+
#include "tscore/ink_hrtime.h"
2829

2930
struct IOUringConfig {
3031
int queue_entries = 1024;
@@ -63,7 +64,7 @@ class IOUringContext
6364

6465
void submit();
6566
void service();
66-
void submit_and_wait(int ms);
67+
void submit_and_wait(ink_hrtime ms);
6768

6869
int register_eventfd();
6970

iocore/io_uring/io_uring.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Linux io_uring helper library
2626
#include <cstring>
2727
#include <stdexcept>
2828

29+
#include <unistd.h>
30+
2931
#include "I_IO_URING.h"
3032
#include "tscore/ink_hrtime.h"
3133

@@ -76,7 +78,7 @@ IOUringContext::IOUringContext()
7678
IOUringContext::~IOUringContext()
7779
{
7880
if (evfd != -1) {
79-
close(evfd);
81+
::close(evfd);
8082
evfd = -1;
8183
}
8284
io_uring_queue_exit(&ring);
@@ -144,14 +146,14 @@ IOUringContext::service()
144146
}
145147

146148
void
147-
IOUringContext::submit_and_wait(int ms)
149+
IOUringContext::submit_and_wait(ink_hrtime t)
148150
{
149-
ink_hrtime t = ink_hrtime_from_msec(ms);
150151
timespec ts = ink_hrtime_to_timespec(t);
151152
__kernel_timespec timeout = {ts.tv_sec, ts.tv_nsec};
152153
io_uring_cqe *cqe = nullptr;
153154

154-
io_uring_submit_and_wait_timeout(&ring, &cqe, 1, &timeout, nullptr);
155+
int count = io_uring_submit_and_wait_timeout(&ring, &cqe, 1, &timeout, nullptr);
156+
io_uring_submissions.fetch_add(count);
155157
while (cqe) {
156158
handle_cqe(cqe);
157159
io_uring_completions++;

iocore/io_uring/unit_tests/test_diskIO.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <sys/socket.h>
3333
#include <netinet/in.h>
3434
#include <arpa/inet.h>
35+
#include "tscore/ink_hrtime.h"
3536

3637
ts::file::path
3738
temp_prefix(const char *basename)
@@ -137,13 +138,13 @@ TEST_CASE("disk_io", "[io_uring]")
137138
REQUIRE(fd != -1);
138139

139140
io_uring_write(ctx, fd, "hello", 5, [](int result) { REQUIRE(result == 5); });
140-
ctx.submit_and_wait(100);
141+
ctx.submit_and_wait(100 * HRTIME_MSECOND);
141142
io_uring_close(ctx, fd, [&fd](int result) {
142143
REQUIRE(result == 0);
143144
fd = -1;
144145
});
145146

146-
ctx.submit_and_wait(100);
147+
ctx.submit_and_wait(100 * HRTIME_MSECOND);
147148

148149
REQUIRE(fd == -1);
149150

@@ -156,7 +157,7 @@ TEST_CASE("disk_io", "[io_uring]")
156157
REQUIRE("hello"sv == std::string_view(buffer, result));
157158
});
158159

159-
ctx.submit_and_wait(100);
160+
ctx.submit_and_wait(100 * HRTIME_MSECOND);
160161
}
161162

162163
void
@@ -263,7 +264,7 @@ TEST_CASE("net_io", "[io_uring]")
263264
uint64_t completions_before = io_uring_completions;
264265
uint64_t needed = 2;
265266
while ((io_uring_completions - completions_before) < needed) {
266-
ctx.submit_and_wait(1000);
267+
ctx.submit_and_wait(1 * HRTIME_SECOND);
267268
}
268269

269270
REQUIRE(server.clients == 1);

src/tests/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#######################
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor license
4+
# agreements. See the NOTICE file distributed with this work for additional information regarding
5+
# copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software distributed under the License
12+
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13+
# or implied. See the License for the specific language governing permissions and limitations under
14+
# the License.
15+
#
16+
#######################
17+
18+
# This is for tests that depend on multiple libraries where dependency order matters.
19+
20+
add_executable(test_AIO ${CMAKE_SOURCE_DIR}/iocore/aio/test_AIO.cc)
21+
target_include_directories(test_AIO PRIVATE
22+
${IOCORE_INCLUDE_DIRS}
23+
${PROXY_INCLUDE_DIRS}
24+
${CMAKE_SOURCE_DIR}/mgmt
25+
)
26+
target_link_libraries(test_AIO aio inkevent proxy tscore tscpputil)
27+
if (TS_USE_LINUX_IO_URING)
28+
target_link_libraries(test_AIO inkuring uring)
29+
endif (TS_USE_LINUX_IO_URING)

src/traffic_server/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ add_executable(traffic_server
2525
SocksProxy.cc
2626
traffic_server.cc
2727
RpcAdminPubHandlers.cc
28-
${CMAKE_SOURCE_DIR}/src/shared/overridable_txn_vars.cc)
28+
${CMAKE_SOURCE_DIR}/src/shared/overridable_txn_vars.cc
29+
)
2930
target_include_directories(traffic_server PRIVATE
3031
${IOCORE_INCLUDE_DIRS}
3132
${PROXY_INCLUDE_DIRS}

src/traffic_server/traffic_server.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
22472247

22482248
while (!TSSystemState::is_event_system_shut_down()) {
22492249
#if TS_USE_LINUX_IO_URING == 1
2250-
ur->submit_and_wait(1000);
2250+
ur->submit_and_wait(1 * HRTIME_SECOND);
22512251
#else
22522252
sleep(1);
22532253
#endif

0 commit comments

Comments
 (0)