chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.94k stars 1.22k forks source link

[FAQ]failed to build io_uring file example code, please advise what I am missing #1181

Open gaowayne opened 1 year ago

gaowayne commented 1 year ago

please check below link error

[root@localhost files]# vim blocking_file_copy.cpp 
[root@localhost files]# g++ blocking_file_copy.cpp -lboost_system -lboost_thread -lpthread
/usr/bin/ld: /tmp/ccGRXsMc.o: in function `io_uring_wait_cqe_nr':
blocking_file_copy.cpp:(.text+0x196): undefined reference to `__io_uring_get_cqe'
/usr/bin/ld: /tmp/ccGRXsMc.o: in function `boost::asio::detail::io_uring_service::~io_uring_service()':
blocking_file_copy.cpp:(.text._ZN5boost4asio6detail16io_uring_serviceD2Ev[_ZN5boost4asio6detail16io_uring_serviceD5Ev]+0x40): undefined reference to `io_uring_queue_exit'
/usr/bin/ld: /tmp/ccGRXsMc.o: in function `boost::asio::detail::io_uring_service::notify_fork(boost::asio::execution_context::fork_event)':
blocking_file_copy.cpp:(.text._ZN5boost4asio6detail16io_uring_service11notify_forkENS0_17execution_context10fork_eventE[_ZN5boost4asio6detail16io_uring_service11notify_forkENS0_17execution_context10fork_eventE]+0x394): undefined reference to `io_uring_queue_exit'
/usr/bin/ld: /tmp/ccGRXsMc.o: in function `boost::asio::detail::io_uring_service::init_ring()':
blocking_file_copy.cpp:(.text._ZN5boost4asio6detail16io_uring_service9init_ringEv[_ZN5boost4asio6detail16io_uring_service9init_ringEv]+0x22): undefined reference to `io_uring_queue_init'
/usr/bin/ld: /tmp/ccGRXsMc.o: in function `boost::asio::detail::io_uring_service::get_sqe()':
blocking_file_copy.cpp:(.text._ZN5boost4asio6detail16io_uring_service7get_sqeEv[_ZN5boost4asio6detail16io_uring_service7get_sqeEv]+0x18): undefined reference to `io_uring_get_sqe'
/usr/bin/ld: blocking_file_copy.cpp:(.text._ZN5boost4asio6detail16io_uring_service7get_sqeEv[_ZN5boost4asio6detail16io_uring_service7get_sqeEv]+0x3f): undefined reference to `io_uring_get_sqe'
/usr/bin/ld: /tmp/ccGRXsMc.o: in function `boost::asio::detail::io_uring_service::submit_sqes()':
blocking_file_copy.cpp:(.text._ZN5boost4asio6detail16io_uring_service11submit_sqesEv[_ZN5boost4asio6detail16io_uring_service11submit_sqesEv]+0x26): undefined reference to `io_uring_submit'
collect2: error: ld returned 1 exit status
[root@localhost files]# 
klemens-morgenstern commented 1 year ago

Linking liburing is what you're missing.

pfeatherstone commented 1 year ago

Does io_uring actually provide any performance gains ?

gaowayne commented 1 year ago

Linking liburing is what you're missing.

actually I installed, please check if this is OK

[root@localhost files]# yum install *uring*
Fedora 33 - x86_64                                                                                                                                                                                                                                       12 kB/s | 3.9 kB     00:00    
Fedora Modular 33 - x86_64                                                                                                                                                                                                                               12 kB/s | 3.9 kB     00:00    
Fedora 33 - x86_64 - Updates                                                                                                                                                                                                                            6.3 kB/s | 3.9 kB     00:00    
Fedora Modular 33 - x86_64 - Updates                                                                                                                                                                                                                    1.3 kB/s | 3.8 kB     00:02    
Intel(R) oneAPI repository                                                                                                                                                                                                                              394  B/s | 287  B     00:00    
Intel(R) oneAPI repository                                                                                                                                                                                                                               13 MB/s |  24 MB     00:01    
Package liburing-0.7-3.fc33.x86_64 is already installed.
Package liburing-devel-0.7-3.fc33.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@localhost files]# 
gaowayne commented 1 year ago

Does io_uring actually provide any performance gains ?

I believe it will save CPU, get higher BW with less CPU burning

gaowayne commented 1 year ago

this fix things. g++ blocking_file_copy.cpp -lboost_system -lboost_thread -lpthread -luring

gaowayne commented 1 year ago

@klemens-morgenstern hello man, I run the async copy example, it seg fault as below

the pointer become invalid, is any developer will get this issue and fix it? who I should contact?

[root@localhost files]# gdb async
GNU gdb (GDB) Fedora 10.2-4.fc33
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from async...
(gdb) set args /dev/nvme1n1 /dev/nvme0n1
(gdb) r
Starting program: /mnt/sda/sda5/wayne/boostasio/boost_1_80_0/libs/asio/example/cpp11/files/async /dev/nvme1n1 /dev/nvme0n1
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x000000000040827a in boost::asio::detail::io_uring_service::io_queue::set_result (this=0x1, r=0) at /usr/local/include/boost/asio/detail/io_uring_service.hpp:66
66      void set_result(int r) { task_result_ = static_cast<unsigned>(r); }
(gdb) bt
#0  0x000000000040827a in boost::asio::detail::io_uring_service::io_queue::set_result (this=0x1, r=0) at /usr/local/include/boost/asio/detail/io_uring_service.hpp:66
#1  0x00000000004097f5 in boost::asio::detail::io_uring_service::run (this=0x43e160, usec=-1, ops=...) at /usr/local/include/boost/asio/detail/impl/io_uring_service.ipp:472
#2  0x000000000040b65c in boost::asio::detail::scheduler::do_run_one (this=0x43dfc0, lock=..., this_thread=..., ec=...) at /usr/local/include/boost/asio/detail/impl/scheduler.ipp:476
#3  0x000000000040b16a in boost::asio::detail::scheduler::run (this=0x43dfc0, ec=...) at /usr/local/include/boost/asio/detail/impl/scheduler.ipp:210
#4  0x000000000040bd66 in boost::asio::io_context::run (this=0x7fffffffdf30) at /usr/local/include/boost/asio/impl/io_context.ipp:63
#5  0x0000000000403b22 in main (argc=3, argv=0x7fffffffe058) at async_file_copy.cpp:88
(gdb) info locals
No locals.
(gdb) dt this
Undefined command: "dt".  Try "help".
(gdb) p this
$1 = (boost::asio::detail::io_uring_service::io_queue * const) 0x1
(gdb) p *this
Cannot access memory at address 0x1
(gdb) p this -r
$2 = (boost::asio::detail::io_uring_service::io_queue * const) 0x1
(gdb) .frame 1
Undefined command: ".frame".  Try "help".
(gdb) down
Bottom (innermost) frame selected; you cannot go down.
(gdb) up
#1  0x00000000004097f5 in boost::asio::detail::io_uring_service::run (this=0x43e160, usec=-1, ops=...) at /usr/local/include/boost/asio/detail/impl/io_uring_service.ipp:472
472         io_q->set_result(cqe->res);
(gdb) list
467         --local_ops;
468       }
469       else
470       {
471         io_queue* io_q = static_cast<io_queue*>(ptr);
472         io_q->set_result(cqe->res);
473         ops.push(io_q);
474       }
475     }
476     ::io_uring_cqe_seen(&ring_, cqe);
(gdb) dt io_q
Undefined command: "dt".  Try "help".
(gdb) p io_q
$3 = (boost::asio::detail::io_uring_service::io_queue *) 0x1
(gdb) p ptr
$4 = (void *) 0x1
(gdb) p *cpe
No symbol "cpe" in current context.
(gdb) p *cqe
Cannot access memory at address 0x7ffff79b8000
(gdb) 
gaowayne commented 1 year ago

there is segfault as above now

klemens-morgenstern commented 1 year ago

Can you run it with an address sanitizer?

gaowayne commented 1 year ago

Can you run it with an address sanitizer?

enabled this and O0 -g

[root@localhost files]# g++ -O0 -g -fsanitize=address async_file_copy.cpp -lboost_system -lboost_thread -lpthread -luring -o async
[root@localhost files]# gdb async
GNU gdb (GDB) Fedora 10.2-4.fc33
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from async...
(gdb) set args /dev/nvme1n1 /dev/nvme0n1
(gdb) r
Starting program: /mnt/sda/sda5/wayne/boostasio/boost_1_80_0/libs/asio/example/cpp11/files/async /dev/nvme1n1 /dev/nvme0n1
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00000000004103c6 in boost::asio::detail::io_uring_service::io_queue::set_result (this=0x2, r=0) at /usr/local/include/boost/asio/detail/io_uring_service.hpp:66
66      void set_result(int r) { task_result_ = static_cast<unsigned>(r); }
(gdb) bt
#0  0x00000000004103c6 in boost::asio::detail::io_uring_service::io_queue::set_result (this=0x2, r=0) at /usr/local/include/boost/asio/detail/io_uring_service.hpp:66
#1  0x000000000041313a in boost::asio::detail::io_uring_service::run (this=0x615000000080, usec=-1, ops=...) at /usr/local/include/boost/asio/detail/impl/io_uring_service.ipp:472
#2  0x0000000000417666 in boost::asio::detail::scheduler::do_run_one (this=0x611000000040, lock=..., this_thread=..., ec=...) at /usr/local/include/boost/asio/detail/impl/scheduler.ipp:476
#3  0x0000000000416b03 in boost::asio::detail::scheduler::run (this=0x611000000040, ec=...) at /usr/local/include/boost/asio/detail/impl/scheduler.ipp:210
#4  0x00000000004189e7 in boost::asio::io_context::run (this=0x7fffffffcd60) at /usr/local/include/boost/asio/impl/io_context.ipp:63
#5  0x0000000000405418 in main (argc=3, argv=0x7fffffffe058) at async_file_copy.cpp:88
(gdb) up
#1  0x000000000041313a in boost::asio::detail::io_uring_service::run (this=0x615000000080, usec=-1, ops=...) at /usr/local/include/boost/asio/detail/impl/io_uring_service.ipp:472
472         io_q->set_result(cqe->res);
(gdb) p *io_q
Cannot access memory at address 0x2
(gdb) p io_q
$1 = (boost::asio::detail::io_uring_service::io_queue *) 0x2
(gdb)